akhauriyash/Code-Regression huggingface dataset:
/* This Template is property of Pranav Khiste aka desmond_kaneki*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fit(a,b) for(auto it=a;it!=b;it++)
#define vll vector<ll>
#define pb push_back
#define qll queue<ll>
#define p push
#define mp make_pair
#define fst first
#define snd second
#define pll pair<ll,ll>
#define vpll vector<pll>
#define debug(x) cout<<#x<<' '<<x<<endl;
#define endl '\n'
#define SUP LLONG_MAX
#define INF -1000000000000
#define MAX_N 100005
#define test() ll var;  cin>>var; while(var--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fileio freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);  // use cin cout only!!
main()
{
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    priority_queue<ll> A,B,C;
    fi(0,a)
    {
        ll z;
        cin>>z;
        A.push(z);
    }
    fi(0,b)
    {
        ll z;
        cin>>z;
        B.push(z);
    }
    fi(0,c)
    {
        ll z;
        cin>>z;
        C.push(z);
    }
    ll red=0,green=0,col=0,ans=0;
    while(1)
    {
        if(red+green+col==x+y)
            break;
        if(red==x)
        {
            ll z1=-1,z2=-1;
            if(B.size()>0)
            z1=B.top();
            if(C.size()>0)
            z2=C.top();
            if(z1>=z2)
            {
                green++;
                ans+=z1;
                B.pop();
            }
            else
            {
                col++;
                ans+=z2;
                C.pop();
            }
        }
        else if(green==y)
        {
            ll z1=-1,z2=-1;
            if(A.size()>0)
            z1=A.top();
            if(C.size()>0)
            z2=C.top();
            if(z1>=z2)
            {
                red++;
                ans+=z1;
                A.pop();
            }
            else
            {
                col++;
                ans+=z2;
                C.pop();
            }
        }
        else
        {
            ll z1=-1,z2=-1,z3=-1;
            if(A.size()>0)
                z1=A.top();
            if(B.size()>0)
                z2=B.top();
            if(C.size()>0)
                z3=C.top();
            if(z1>z2)
            {
                if(z1>=z3)
                {
                    red++;
                    ans+=z1;
                    A.pop();
                }
                else
                {
                    col++;
                    ans+=z3;
                    C.pop();
                }
            }
            else
            {
                if(z2>=z3)
                {
                    green++;
                    ans+=z2;
                    B.pop();
                }
                else
                {
                    col++;
                    ans+=z3;
                    C.pop();
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3316
#include<iostream>
#include<string>

int main() {
	int ans;
	ans = 0;
	std::string S, T;
	std::cin >> S >> T;
	if (S[0] == T[0]) {
		ans++;
	}
	if (S[1] == T[1]) {
		ans++;
	}
	if (S[2] == T[2]) {
		ans++;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Measured memory_bytes: 6332
n,m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda tup: tup[1])
bridge,ans=-1, 0
for a,b in ab:
    if a <= bridge:
        continue
    else:
        bridge = b - 1
        ans += 1
print(ans)

Measured memory_bytes: 18160
#include <iostream>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;

int main() {
	ll n; cin >> n;
	double x; string u;
	double sum = 0;
	rep(i, 0, n) {
		cin >> x >> u;

		if (u == "JPY") {
			sum += x;
		}
		else {
			sum += x * 380000;
		}
	}

	cout << sum << endl;
	return 0;
}

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

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

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
 
template<class T> inline bool chmin(T &a, T b) { if(a>b){ a=b; return true; }  return false;}
template<class T> inline bool chmax(T &a, T b) { if(a<b){ a=b; return true; }  return false;}

// ll a[100010][3];
// ll dp[110][100010];  // [品物][重さ] としたときの価値の最大値
// ll weight[110], value[110];

const int MAX_N = 100;
const int MAX_W = 100000;

ll N, W;
ll w[MAX_N], v[MAX_N];

// dp[i][w] i時点における、重さがwを超えないように頑張ったときの、価値の最大値
ll dp[MAX_N+1][MAX_W+1];

int main() {
  cin >> N >> W;
  REP(i, N){
    cin >> w[i] >> v[i];
  }
  for(int i=0; i<N; i++){
    for(int sum_w=0; sum_w<=W; sum_w++){

      // i番目を選ぶ場合→i+1番目を更新
      if(sum_w - w[i] >= 0){ // そもそも選べるか？
        chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
      }

      // i番目を選ばない場合
      chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }
  cout << dp[N][W] << endl;
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int n, m;
    cin>>n>>m;
    V<int> cum(n+2, 0);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin>>l>>r;
        cum[l]++;
        cum[r+1]--;
    }
    for (int i = 0; i < n + 2; ++i) {
        cum[i+1]+=cum[i];
    }
    int ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        if(cum[i]==m)ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int N = 1e5;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const LL INFL = 1e15;

int main(){
  int n, m;
  scanf("%d%d", &n, &m);
  LL tot = 0;
  if(n == 1 && m == 1) {
    puts("1");
    return 0;
  }
  if(n > m) swap(n, m);
  if(n == 1) printf("%d\n", m - 2);
  else if(n == 2) printf("0\n");
  else{
    printf("%lld\n", 1LL * (n - 2) * (m - 2));
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
using namespace std;
int main(void){
    string s,s1,s2,s3;
    cin >> s;
    s2 = s[5] + s[6];
    int b = s[5]-'0';
    int c = s[6] -'0';
    int x = 10*b+c;
    if(x <= 4){
        cout << "Heisei" << endl; 
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

double solve(vs& ss)
{
	stack<double> st;
	rep(i,ss.size()){
		if(isdigit(ss[i][ss[i].size()-1]))
			st.push(atof(ss[i].c_str()));
		else{
			double a,b;
			b=st.top();st.pop();
			a=st.top();st.pop();
			
			switch(ss[i][0]){
				case '+':
					st.push(a+b);
					break;
				case '-':
					st.push(a-b);
					break;
				case '*':
					st.push(a*b);
					break;
				case '/':
					st.push(a/b);
					break;
			}
		}
	}
	return st.top();
}

int main()
{
	for(string s;getline(cin,s);){
		istringstream iss(s);
		vs ss;
		for(string s;iss>>s;ss.push_back(s))
			;
		printf("%f\n",solve(ss));
	}
	
	return 0;
}

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

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

  vector<int> a(n);
  int total = 0;
  rep(i, n) {
    cin >> a[i];
    total += a[i];
  }

  sort(a.rbegin(), a.rend());

  rep(i, m) {
    if (4 * m * a[i] < total) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    N,M=map(int,input().split())

    G=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a].append(b)
        G[b].append(a)

    trace=[-1 for i in range(N)]
    GroupN=[]

    for i in range(N):
        stack=[]
        if trace[i]==-1:
            trace[i]=0
            stack.append(i)
        Group_tmp=[]
        while len(stack)>0:
            index=stack.pop()
            Group_tmp.append(index)
            for j in G[index]:
                if trace[j]==-1:
                    trace[j]=0
                    stack.append(j)
        if len(Group_tmp)!=0:
            GroupN.append(len(Group_tmp))

    print(max(GroupN))


if __name__=="__main__":
    main()

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

int n;
long long int l, r, ans;

int main(void){
    // Here your code !
    scanf("%d", &n);

    ans = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d %d", &l, &r);
      ans += r - l + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Text;


class Solver {
  class UnionFind {
    public UnionFind(int _n) {
      n = _n;
      p = new int[n];
      x = new int[n];
      for (int i = 0; i < n; i++) p[i] = -1;
    }

    public int n;
    public int[] p, x;

    public int root(int v) {
      if (p[v] < 0) return v;
      int np = root(p[v]);
      x[v] += x[p[v]];
      return p[v] = np;
    }
    public bool join(int a, int b, int d) {
      if (root(a) == root(b)) {
        return x[b]-x[a] == d;
      }
      d += x[a]-x[b];
      a = root(a); b = root(b);
      if (p[a] > p[b]) {
        swap(ref a, ref b);
        d = -d;
      }
      p[a] += p[b]; p[b] = a;
      x[b] = d;
      return true;
    }
  }

  public void solve() {
    int n = cin.readInt();
    int m = cin.readInt();
    UnionFind uf = new UnionFind(n);
    for (int i = 0; i < m; i++) {
      int l = cin.readInt();
      int r = cin.readInt();
      int d = cin.readInt();
      --l; --r;
      if (!uf.join(l,r,d)) {
        Console.Out.WriteLine("No");
        return;
      }
    }
    Console.Out.WriteLine("Yes");
  }

  public Istream cin = new Istream(Console.OpenStandardInput());
  static public void swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
}


#region Istream
class Istream {
  public Istream(Stream _ins) { ins = _ins;}

  const int BUF_SZ = 1024;
  private Stream ins;
  private byte[] buf = new byte[BUF_SZ];
  private int len, ptr;

  private byte readByte() {
    if (ptr >= len) {
      ptr = 0;
      len = ins.Read(buf, 0, BUF_SZ);
      if (len == 0) return 0;
    }
    return buf[ptr++];
  }
  public char nextChar() {
    byte b;
    do b = readByte(); while (b < 33 && 126 < b);
    return (char)b;
  }
  public string read() {
    var sb = new StringBuilder();
    for (char c = nextChar(); (33 <= c && c <= 126); c = (char)readByte()) sb.Append(c);
    return sb.ToString();
  }
  public string readLine() {
    var sb = new StringBuilder();
    for (char c = nextChar(); (c != '\n' && c != 0); c = (char)readByte()) sb.Append(c);
    return sb.ToString();
  }
  public long readLong() { return long.Parse(read()); }
  public int readInt() { return int.Parse(read()); }
  public double readDouble() { return double.Parse(read()); }
}
#endregion


#region Main
class ReSha {
  static void Main() {
    new Solver().solve();
  }
}
#endregion

Measured memory_bytes: 17760
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
   int arr[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
    }
    int flag=0;
    for(int i=0;i<n-2;i++)
    {
        if(arr[i][0]==arr[i][1] && arr[i+1][0]==arr[i+1][1] && arr[i+2][0]==arr[i+2][1])
        {
            flag=1;
            break;
        }
    }
    if(flag==1) cout<<"Yes";
    else cout<<"No";
}


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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;

int main(){
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b),x(q);
    for(auto & tmp : s) cin>>tmp;
    for(auto & tmp : t) cin>>tmp;
    for(auto & tmp : x) cin>>tmp;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    for(int i=0;i<q;++i){
        auto ss = lower_bound(s.begin(),s.end(),x[i]);
        auto st = lower_bound(t.begin(),t.end(),x[i]);
        int snum = ss - s.begin();
        int tnum = st - t.begin();
        if(snum == 0){
            if(tnum == 0){
                cout << max(*ss,*st) - x[i] << endl;
            }else{
                auto pret = st -1;
                if(tnum != b) cout << min(min(2LL*(x[i]-*pret)+*ss-x[i],max(*ss,*st) - x[i]),2LL*abs(x[i] - *ss)+abs(x[i] - *pret)) << endl;
                else cout << min(abs(x[i] - *ss)*2LL+abs(x[i] - *pret),abs(x[i] - *pret)*2LL+abs(x[i] - *ss)) << endl;
            }
        }
        else if(tnum == 0){
            auto pres = ss - 1;
            if(snum != a)cout << min(min(2LL*(x[i] - *pres)+*st-x[i],max(*ss,*st) - x[i]),2LL*abs(x[i] - *st)+abs(x[i] - *pres)) << endl;
            else cout << min(abs(x[i] - *st)*2LL+abs(x[i] - *pres),abs(x[i] - *pres)*2LL+abs(x[i] - *st)) << endl;
        }
        else if(snum == a){
            if(tnum == b){
                ss--;
                st--;
                cout << x[i] - min(*ss,*st) << endl;
            }else{
                ss--;
               auto pret = st - 1;
               if(tnum != 0)cout << min(min(2LL*(*st - x[i])+x[i] -*ss,x[i] - min(*ss,*pret)),2LL*(x[i] - *ss)+abs(x[i] - *st)) << endl;
               else cout << min(2LL*(*st -x[i])+abs(x[i] - *ss),2LL*(x[i] - *ss)+abs(x[i] - *st)) << endl;
            }
        } else if(tnum == b){
            st--;
            auto pres = ss - 1;
            if(snum != 0)cout << min(min(2LL*(*ss - x[i])+x[i] - *st,x[i] - min(*st,*pres)),2LL*abs(x[i] - *st)+abs(x[i] - *st)) << endl;
            else cout << min(2LL*(*ss -x[i])+abs(x[i] - *st),2LL*(x[i] - *st)+abs(x[i] - *ss)) << endl;
        } else{
            auto pres = ss - 1;
            auto pret = st - 1;
            cout << min(min(abs(x[i] - *ss)+min(abs(*ss - *st), abs(*ss - *pret)),abs(x[i] - *pres) + min(abs(*pres - *pret),abs(*pres - *st))),
                        min(abs(x[i] - *st)+min(abs(*st - *ss), abs(*st - *pres)),abs(x[i] - *pret) + min(abs(*pret - *pres),abs(*pret - *ss)))) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3712
comp='MARCH'
cnt=[0,0,0,0,0]

n=int(input())
for i in range(n):
    word=input()
    for j in range(len(comp)):
        if word[0]==comp[j]: cnt[j]+=1

ans = 0
for i in range(len(cnt)):
    for j in range(i+1, len(cnt)):
        for k in range(j+1, len(cnt)):
            ans += cnt[i]*cnt[j]*cnt[k]
        
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 150;
int n, m, cnt, fa[N], f[N], head[N], to[N << 1], nxt[N << 1], dfn[N], out[N], tim, sum, ans, res;
inline void add(int a, int b){
	to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt;
}
struct Edge {
	int a, b, c;
	inline bool operator < (const Edge &o) const {return c > o.c;}
} e[N];
inline int getfa(int x){
	return x == fa[x] ? x : fa[x] = getfa(fa[x]);
}
bool in[N], vis[N], flag;
int col[N];
inline void dfs(int x){
	if(!flag) vis[x] = true;
	if(x == n) flag = true;
	dfn[x] = ++ tim;
	for(Rint i = head[x];i;i = nxt[i])
		if(to[i] != f[x]){f[to[i]] = x; dfs(to[i]);}
	out[x] = tim;
	if(!flag) vis[x] = false;
}
inline void dfs2(int x, int c){
	col[x] = c;
	for(Rint i = head[x];i;i = nxt[i])
		if(to[i] != f[x] && !vis[to[i]] && !col[to[i]]) dfs2(to[i], c);
}
clock_t st = clock();
int main(){
	srand(20050915);
	scanf("%d%d", &n, &m);
	for(Rint i = 1;i <= m;i ++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c), sum += e[i].c;
	sort(e + 1, e + m + 1);
	while(true){
		res = tim = flag = cnt = 0;
		memset(head, 0, sizeof head);
		memset(vis, 0, sizeof vis);
		memset(in, 0, sizeof in);
		memset(f, 0, sizeof f);
		memset(col, 0, sizeof col);
		for(Rint i = 1;i <= n;i ++) fa[i] = i;
		for(Rint i = 1, j = 1;i <= m && j < n;i ++){
			int fa1 = getfa(e[i].a), fa2 = getfa(e[i].b);
			in[i] = false;
			if(fa1 != fa2){
				in[i] = true; fa[fa1] = fa2;
				add(e[i].a, e[i].b); add(e[i].b, e[i].a); res += e[i].c; ++ j;
			}
		}
		dfs(1);
		for(Rint i = 1, j = 0;i <= m;i ++)
			if(vis[i]) dfs2(i, ++ j);
		for(Rint i = 1;i <= m;i ++) if(!in[i] && col[e[i].a] == col[e[i].b]) res += e[i].c;
		ans = max(ans, res);
		random_shuffle(e + 1, e + m + 1);
		if(clock() - st >= CLOCKS_PER_SEC * 3.9) break;
	}
	printf("%d", sum - ans);
}

Measured memory_bytes: 384
#include <stdio.h>
int n,a,b[100000],c,max,min,mid;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		max=c-1;
		min=0;
		while(min<max)
		{
			mid=(max+min)/2;
			if(b[mid]<a)max=mid;		
			else min=mid+1;
		}
		if(min<c&&b[min]<a)b[min]=a;
		else b[c++]=a;
	}
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
  int a,b;cin>>a>>b;
  cout<<max(a+b,max(a*b,a-b))<<endl;
}

Measured memory_bytes: 3564
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define vb vector<bool>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
typedef pair<ll,bool> P;
int main(void){
    ll N;cin>>N;
    vector<P> A[N];
    REP(i,N){
        ll k;cin>>k;
        REP(j,k){
            ll x;bool y;cin>>x>>y;x--;
            A[i].push_back(make_pair(x,y));
        }
    }
    ll ans=0;
    for(int bit=0;bit<(1<<N);bit++){//正直者の仮定
        ll cnt=0;bool ok=true;
        REP(i,N){
            if(bit&1<<i){//i番目が正直者であると仮定する
                //i番目のヒトの証言
                for(auto r:A[i]){
                    //xijは正直者or不親切なヒト　と　bitが一致するか
                    if(r.second){//xijが正直者だと話して
                        if(bit & 1<<r.first);//仮定したのと一致すればok
                        else{ok=false;break;}
                    }else{
                        if(!(bit & 1<<r.first));
                        else{ok=false;break;}
                    }
                }
                cnt++;
            }
        }
        if(ok)ans=max(ans,cnt);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    char[] a = scanner.next().toCharArray();
    char[] b = scanner.next().toCharArray();
    char[] c = scanner.next().toCharArray();

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      cnt += countDiff(a[i], b[i], c[i]);
    }
    System.out.println(cnt);
  }

  private static int countDiff(char a, char b, char c) {
    if (a > b) return countDiff(b, a, c);
    if (b > c) return countDiff(a, c, b);
    if (a != b) {
      if (b != c) return 2;
      return 1;
    }
    return b != c ? 1 : 0;
  }
}


Measured memory_bytes: 21716
function main(input) {
    const args = input.split('\n');
    const N = args[0],
	  nums = args.slice(1,args.length - 1);

    console.log(nums.filter((n,i) => nums.indexOf(n) === i).length);
}

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


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;

int main(){
    int a,b;
    cin >> a >> b;
    vector<vector<int>> e(100,vector<int>(100));
    rep(i,50){
        rep(j,100) e.at(i).at(j)=0;
    }
    for (int i=50;i<100;i++){
        rep(j,100) e.at(i).at(j)=1;
    }
    int c=1;
    rep(i,25){
        rep(j,50){
            if (c==b) break;
            e.at(i*2).at(j*2)=1;
            c++;
        }
        if (c==b) break;
    }
    c=1;
    for (int i=26;i<50;i++){
        rep(j,50){
            if (c==a) break;
            e.at(i*2).at(j*2)=0;
            c++;
        }
        if (c==a) break;
    }
    cout << 100 << " " << 100 << endl;
    rep(i,100){
        rep(j,100){
            if (e.at(i).at(j)==0) cout << '.';
            else cout << '#';
        }
        cout << endl;
    }
}


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

int main() {
	int n, r;
	while (~scanf("%d%d", &n, &r)) {
		vector<int>a[2], c(n);
		iota(c.begin(), c.end(), 0);
		rep(i, r) {
			a[1] = vector<int>(c.begin(), c.begin() + n / 2);
			a[0] = vector<int>(c.begin() + n / 2, c.end());
			c.clear();
			int t; scanf("%d", &t);
			for (int j = 0; !a[0].empty() || !a[1].empty(); j++) {
				for (int k = 0; !a[j & 1].empty() && k < t; k++) {
					c.push_back(a[j & 1][0]); a[j & 1].erase(a[j & 1].begin());
				}
			}
		}
		printf("%d\n", *c.rbegin());
	}
}

Measured memory_bytes: 3188
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ABC_prac
{
    public class Program
    {
        #region templete

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }
        /// <summary>
        /// 最小公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
        public static void Main(string[] args)
        {
            new Program().Solve();
            Read();
        }

        #endregion

        public void Solve()
        {
            var din = ReadLongs();
            var a = din[0];
            var b = din[1];
            var c = din[2];
            var d = din[3];

            long cnt = 0;
            
            long ncCnt = b/c;//b以下のcの倍数の個数
            long ndCnt = b/d;//b以下のdの倍数の個数
            long ncdCnt = b / Lcm(c, d);//b以下でc,d両方の倍数となる数の個数
            long bCnt = ncCnt + ndCnt - ncdCnt;//b以下でc,dで割り切れるものの個数
            bCnt = b - bCnt;

            long ancCnt = (a - 1) / c;//a-1以下のcの倍数の個数
            long andCnt = (a - 1) / d;//a-1以下のdの倍数の個数
            long ancdCnt = (a - 1) / Lcm(c, d);//a-1以下でc,d両方の倍数となる数の個数
            long aCnt = ancCnt + andCnt - ancdCnt;
            aCnt = (a - 1) - aCnt;

            cnt = bCnt - aCnt;

            WriteLine($"{cnt}");

        }

    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n,dp[1<<21],a[22][22];
int mod = 1e9+7;

int main() {
	scanf("%d",&n);
	memset(dp,0,sizeof(dp));
	dp[0] = 1;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			scanf("%d",&a[i][j]);
		}
	}
	for (int i=0; i<(1<<n); i++) {
		int cb = 0;
		for (int j=0; j<n; j++)
			if (i & (1<<j)) cb++;
		for (int j=0; j<n; j++) {
			if (a[cb][j] == 0) continue;
			if (i & (1<<j)) continue;
			dp[i|(1<<j)] += dp[i];
			dp[i|(1<<j)] %= mod;
		}
	}
	printf("%d\n",dp[(1<<n)-1]);
	return 0;
}


Measured memory_bytes: 8448
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        lv: [i64; n],
    }

    let max_num: i64 = *lv.iter().max().unwrap();
    let other_sum: i64 = lv.iter().sum::<i64>() - max_num;

    let answer = if max_num < other_sum { "Yes" } else { "No" };

    println!("{}", answer);
}


Measured memory_bytes: 4352
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

void solve() {
    int n;
    cin >> n;

    vi a(n);
    cin >> a;

    vll cnt(n+1, 0);
    for (int x : a) {
        cnt[x]++;
    }

    ll ans = 0;
    for (ll i : cnt) {
        if (i > 0) {
            ans += i * (i-1) / 2;
        }
    }

    for (int x : a) {
        ll i = cnt[x];
        cout << ans - i * (i-1) / 2 + (i-1) * (i-2) / 2 << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}


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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

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

}

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 2e5+5;
int arr[N];
int dp[N];
int n, k;
int f(int idx){
	if(idx==n-1){
		return 0;
	}

	if(idx >= n) return 1e10;
	if(dp[idx]!=-1) return dp[idx];
	int ans = 1e10;

	for(int i=idx+1; i <= idx+k and i < n; i++){
		ans = min(ans, abs(arr[i]-arr[idx])+f(i));
	}

	return dp[idx] = ans;
}

void solve()
{
	// int n;
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	rep(i, 0, n) cin >> arr[i];

	cout << f(0) << endl;
}			 

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




Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const int mod = 1e9 + 7;
int n;
int m;
int E[300000 + 10] = {};
int W[300000 + 10] = {};
string str;

int main() {
	cin >> n;
	cin >> str;
	forn(i) {
		int j;
		if (str[i] == 'W') {
			W[i]++;
		}
		if (i != 0) {
			W[i] += W[i - 1];
		}
		j = n - 1 - i;
		if (str[j] == 'E')E[j]++;
		if (j != n - 1)E[j] += E[j + 1];
	}
	int ans = n;
	ans = min(ans, E[1]);
	ans = min(ans, W[n - 2]);
	for (int i = 1; i < n - 1; i++) {
		ans = min(ans, W[i - 1] + E[i + 1]);
	}
	cout << ans << endl;

	return 0;
}


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

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

typedef long long ll;

int main() {
    int n,l;cin>>n>>l;
    int a[n];
    int m = 1000;
    int sum = 0;
    rep(i,n){
        a[i] = l + i;
        sum += a[i];
        if(abs(a[i])<abs(m))m=a[i];
    }
    
    int ans = sum - m;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 55;
int N;
int64_t x[MAX_N], y[MAX_N];

bool ball_exist(int64_t s, int64_t t) {
    for (int i = 1; i <= N; i++) {
        if (x[i] == s && y[i] == t) {
            return true;
        }
    }
    return false;
}

int calc(int64_t p, int64_t q) {
    int ret = 0;
    for (int i = 1; i <= N; i++) {
        if (!ball_exist(x[i] - p, y[i] - q)) {
            ret++;
        }
    }
    return ret;
}

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> x[i] >> y[i];
    }

    int ret = N;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (j != i) {
                ret = std::min(ret, calc(x[i] - x[j], y[i] - y[j]));
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	int n,i,wr=0,rw=0,c;string s;cin>>n>>s;
	for(i=0;i<n;i++) if(s[i]=='R') rw++;c=rw;
	for(i=0;i<n;i++){
		if(s[i]=='R') rw--; else wr++;
		c=min(c,rw+wr-min(wr,rw));
	}cout<<c<<endl;
}


Measured memory_bytes: 3700
sx,sy,tx,ty=map(int,input().split())
dx,dy=tx-sx,ty-sy
s1='U'*dy+'R'*dx+'D'*dy+'L'*dx
s2='LU'+'U'*dy+'R'*dx+'RD'+'RD'+'D'*dy+'L'*dx+'LU'
print(s1+s2)


Measured memory_bytes: 3064
use proconio::{input, fastout};
use proconio::marker::{Bytes, Chars};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        S: Chars,
    }
    let mut cnt = 0;
    let mut ans = 0;

    for s in S {
        if s == 'R' {
            cnt += 1;
            ans = max(ans, cnt);
        } else {
            cnt = 0;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2116
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

int zcomp(vector<int>& a, vector<int>& b) {
	return a[2] < b[2];
}
#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)
#define ZSORT(c) sort((c).begin(),(c).end(),zcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL N;
	cin >> N;
	vector<LL> A(N, 0);
	vector<LL> B(N, 0);
	LL sum = 0;
	REP(i, N) {
		cin >> A[i] >> B[i];
	}
	for (LL i = N - 1; i >= 0; --i) {
		if ((A[i] + sum) % B[i] != 0) {
			sum += B[i] - (A[i] + sum) % B[i];
		}
	}
	cout << sum << endl;

}


Measured memory_bytes: 1792
n, x = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(lambda z: abs(z-x), a))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

g = d[0]
for i in range(1, n):
    g = gcd(g, d[i])
print(g)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main() {
   vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int x=c.at(1).at(0)-c.at(0).at(0);
  int y=c.at(2).at(0)-c.at(1).at(0);
  int p=c.at(1).at(1)-c.at(0).at(1);
  int q=c.at(2).at(1)-c.at(1).at(1);
  int s=c.at(1).at(2)-c.at(0).at(2);
  int t=c.at(2).at(2)-c.at(1).at(2);
  if(p==x&&s==x&&q==y&&t==y){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 3010
string Beta(string s){
    if(s.size()==0)return "#";
    if(s[0]=='a')return "#";
    string res="";
    for(int i=0;i<s.size();i++){
        ll a=0,b=0;
        string cur="";
        for(int j=0;j<s.size();j++){
         if(s[j]=='a'){
             if(a>=i)cur.push_back(s[j]);
             a++;
         }
         if(s[j]=='b'){
             if(b>=i)cur.push_back(s[j]);
             b++;
         }
        }
        //cout<<"#"<<cur<<endl;
     res=max(res,cur);
    }
    //cout<<s<<" "<<res<<endl;
    return res;
}
ll n;
string s;
ll A[N],B[N],C[N];;
int main(){
    cin>>n>>s;
    ll a=0,b=0;
    string q="";
    typedef pair<string,ll> P;
    vector<P> v;
    for(int i=0;i<2*n;i++){
     q.push_back(s[i]);
     if(s[i]=='a'){A[a]=i;a++;}
     if(s[i]=='b'){B[b]=i;b++;}
     if(a==b){
      string res=Beta(q);
      if(res!="#"){
       v.push_back(make_pair(res,-i));   
      }
      q="";   
     }
    }//cout<<"initend"<<endl;
    sort(v.begin(),v.end(),greater<P>());
    for(int i=0;i<n;i++){
     C[A[i]]=B[i];
     C[B[i]]=A[i];
    }
    ll cur=-1;
    string ans="";
    for(auto x:v){
     string str=x.first;
     ll p=-x.second;
     if(p<cur)continue;
      cur=p;
     ans+=str;
    }cur++;
    for(;cur<2*n;){
        for(;cur<2*n;cur++){
         if(s[cur]=='a')break;   
        }
        if(cur==2*n)break;
        ans+="ab";
        cur=C[cur]+1;
    }
    cout<<ans<<endl;
 return  0;   
}

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

int isBool(int n[],int num) {
    for(int i=0;i<4;i++){
        if(n[i]==num)return 1;
    }
    return 0;
}

int main(){
    int n[4];
    for(int i=0;i<4;i++){
        cin>>n[i];
    }
    if(isBool(n,1)==1&&isBool(n,7)==1&&isBool(n,9)==1&&isBool(n,4)==1){
        std::cout<<"YES";
        return 0;
    }
    std::cout << "NO" << '\n';
    return 0;


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n),b(n);
    ll diffa = 0,diffb = 0;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n)cin >> b[i];
    REP(i,n){
        if(a[i] > b[i])diffb+=a[i]-b[i];
        else if(a[i] < b[i])diffa+=(b[i]-a[i])/2;
    }
    cerr << diffa << " " << diffb << endl;
    if(diffa < diffb)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3796
N = int(input())
l = list(map(int, input().split()))
for i in range(N):
    t = l[i]
    j = i-1
    while j >= 0 and l[j] > t:
        l[j+1], l[j] = l[j], l[j+1]
        j -= 1
    print(*l)

Measured memory_bytes: 7968
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <math.h>
using namespace std;

int isprime(int x){
  if (x<2) return 0;
  if (x==2) return 1;
  if (x%2==0) return 0;
  for (int i=3;i<=sqrt(x);i+=2){
    if (x%i==0) return 0;
  }
  return 1;
}

int main(){
  int n,cnt=0,min=100,mind;
  int a[100];
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  for (int i=0;i<n;i++) {
    min = a[i];
    mind = 101;
    for (int j=i;j<n;j++) {
      if (min>a[j]) {
        min = a[j];
        mind = j;
      }
    }
    if(a[i]>a[mind]&&(mind!=101)){
      swap(a[i],a[mind]);
      cnt++;
    }
  }
  for (int i=0;i<n;i++) {
    if (i==(n-1)) {
      cout << a[i] << endl;
    } else { cout << a[i] << " "; }
  }
  cout << cnt <<endl;
}



Measured memory_bytes: 3088
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int a[9999],b[9999],i = 0;
    char op[9999];
    
    for(i = 0;i < 9999;i++){
        cin >>a[i] >>op[i] >>b[i];
        if(op[i] == '?')
            i = 9999;
    }
    
    i = 0;
    
    for(i = 0;i < 9999;i++){
        if(op[i] == '+')
            printf("%d\n",a[i] + b[i]);
        else if(op[i] == '-')
            printf("%d\n",a[i] - b[i]);
        else if(op[i] == '*')
            printf("%d\n",a[i] * b[i]);
        else if(op[i] == '/')
            printf("%1d\n",a[i] / b[i]);
        else if(op[i] == '?')
            i = 9999;
    }
        
    
    return 0;

}



Measured memory_bytes: 3232
#include <stdio.h>
#include <math.h>

int N, R[200200];

int main()
{
	scanf ("%d", &N);
	for (int i = 2, x; i <= N; i++) scanf ("%d", &x), R[x]++;
	for (int i = 1; i <= N; i++) printf ("%d\n", R[i]);

	return 0;
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();

    if(n > k){
        cout << s.substr(0,k) << "..." << endl;
    }else{
        cout << s << endl;
    }

    return 0;
}




Measured memory_bytes: 3596
N=int(input())
count=0
for n in range(1,N+1):
    if 0<n<10:
        count+=1
        continue
    elif 99<n<1000:
        count+=1
        continue
    elif 9999<n<100000:
        count+=1
        continue
    else:
        pass
print(count)


Measured memory_bytes: 2940
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	  	ll n,a[200001],i,j,ans=0;
	  	cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
	  	for(i=0;i<(n-1);i++)
	  	{
	  		for(j=i+1;j<n;j++)
	  		{
	  			ans=ans+(a[i]*a[j]);
	  			}
	  			}
	  	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int N = 200005;

int x[N], cnt[N], cov[N];

int main()
{
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x[i]);
    ++cnt[x[i]];
  }
  int ans = n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= cnt[i]; ++j) {
      if (i - j < 0)
        continue;
      if (cov[i - j] == 0)
        --ans;
      ++cov[i - j];
    }
  }
  while (m--) {
    int u, v;
    scanf("%d %d", &u, &v);
    int change = x[u] - cnt[x[u]];
    if (change >= 0) {
      if (cov[change] == 1)
        ++ans;
      --cov[change];
    }
    --cnt[x[u]];
    x[u] = v;
    ++cnt[x[u]];
    change = x[u] - cnt[x[u]];
    if (change >= 0) {
      if (cov[change] == 0)
        --ans;
      ++cov[change];
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int main()
{
  int n,count=0;
  string s;
  cin>>n;
  if(n%2==1)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cin>>s;
    for(int i=0,j=s.length()/2;i<s.length()/2-1,j<s.length();i++,j++)
    {
      if(s[i]!=s[j])
      {
        count=1;
      }
    }
    if(count==1)
    {
    	cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
  }
  return 0;
}


Measured memory_bytes: 256
c = []
for _ in range(3):
  c.append(list(map(int,input().split())))
  
ans = "Yes"
ans1 = False
ans2 = False
ans3 = False
if c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]:
  ans1 = True
  
if c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]:
  ans2 = True 
   
if c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]:
  ans3 = True  
  
  
if ans1 and ans2 and ans3:
  print("Yes")
  
else:
  print("No")

Measured memory_bytes: 3064