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

int ans;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a >= 13) ans = b;
  else if (6 <= a && a <= 12) ans = b / 2;
  else ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int n;
    cin >> n;
    //vector<pair<ll, ll>> V;
    vector<ll> V;
    ll Sa = 0, Sb = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        Sb += b;
        //V.push_back({a, b});
        V.push_back(a + b);
    }

    /*sort(V.begin(), V.end(), [](auto x, auto y) {
        return x.st + x.nd > y.st + y.nd;
    });*/
    sort(V.begin(), V.end(), [](ll a, ll b){
        return a > b;
    });

    ll suma = 0;
    for (int i = 0; i < n; i += 2) {
        suma += V[i];
    }

    cout << suma - Sb << "\n";
}


Measured memory_bytes: 1400
import qualified Data.IntMap as M

main = interact $ unlines . solve . map read . words

solve (n:k:q:xs) = ans where
  m = foldl f M.empty xs
  f m x = M.insertWith (+) x 1 m
  ans = map yesno $ map g [1..n]
  g i = k - (q - M.findWithDefault 0 i m)
  yesno x  = if x > 0 then "Yes" else "No"

Measured memory_bytes: 18172
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    
    def dfs(i):
        enable = False
        if i == N:
            return True
        elif i > N:
            return False
        if S[i:i+7] == "dreamer":
            enable |= dfs(i+7)
        if S[i:i+6] == "eraser":
            enable |= dfs(i+6)
        if S[i:i+5] in ["dream", "erase"]:
            enable |= dfs(i+5)
        return enable
    
    return "YES" if dfs(0) else "NO"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long m;
  cin >> n >> m;
  vector< pair<long long, long long> > v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  int i = 0;
  long long ans = 0;
  while (m > 0) {
    long long cnt = min(m, v[i].second);
    m -= cnt;
    ans += cnt * v[i].first;
    i++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

int main(){
  const int max = 20, min = 0;
  int N;
  std::cin >> N;
  std::vector<std::vector<unsigned long int> > dp(N - 1,std::vector<unsigned long int>(max \
+ 1,0));
  std::vector<int> num(N);

  for(int i = 0; i < N; ++i){
    std::cin >> num[i];
  }
  //１項目を反映                                                                            
  ++dp[0][num[0]];

  for(int i = 0; i < N - 2; ++i){
    for(int j = 0; j < max + 1; ++j){
      //次項を足した場合                                                                    
      if(j + num[i + 1] <= max){
        dp[i + 1][j + num[i + 1]] += dp[i][j];
      }
      //次項を引いた場合                                                                    
      if(j - num[i + 1] >= min){
        dp[i + 1][j - num[i + 1]] += dp[i][j];
      }
    }
  }
  std::cout << dp[N - 2][num[N-1]] << std::endl;
  return 0;
}

Measured memory_bytes: 1228
L=int(input())
S=str(bin(L))[2:][::-1]
N=len(S)
A=[]
for i in range(1,N):
    A.append((i,i+1,0))
    A.append((i,i+1,2**(i-1)))
#print(S)
for i in range(N-1):
    if S[i]=="1":
        L-=2**i
        A.append((i+1,N,L))
print(N,len(A))
for p in A:
    print(p[0],p[1],p[2])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
map<int,vector<int>> mo;
map<int,bool> vis;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a,b;
      cin>>a>>b;
      map<int,int> ma;
      vector<int> cod;
      for(int i=1;i*i<=a;i++)
      {
            if(a%i==0)
            {
                  ma[i]++;
                  ma[a/i]++;
            }
      }
      for(int i=1;i*i<=b;i++)
      {
            if(b%i==0)
            {
                 if(b/i==i)
                 {
                  if(ma[i]) cod.pb(i);
                 }
                 else{
                  if(ma[i]) cod.pb(i);
                  if(ma[b/i]) cod.pb(b/i);
                 }
            }
      }
      sort(all(cod));
      map<int,vector<int>> moo;
      int cnt=0;

      for(auto x:cod)
      {
            // if(x==1)
            // {
            //       cnt++;
            //       continue;
            // }
            // cout<<x<<" ";
            int y=x;
            bool f=false;
            for(int i=2;i*i<=y;i++)
            {
                  if(y%i==0)
                  {
                        f=true;
                        while(y%i==0) y/=i;
                        moo[i].pb(x);
                  }
            }
            if(!f) cnt++;
      }
      cout<<cnt;
}
// I never lose. I either win or I learn

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_V 550
#define INF 1e8
 
struct edge{
    int to,cap,cost,rev;
    edge(int to,int cap,int cost,int rev) :
	to(to),cap(cap),cost(cost),rev(rev) {}
};
 
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
 
void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}
 
int min_cost_flow(int s,int t,int f){
    int res = 0;
    while(f > 0){
	fill(dist,dist+MAX_V,INF);
	dist[s] = 0;
	bool update = true;
	while(update){
	    update = false;
	    for(int v = 0 ; v < MAX_V ; v++){
		if(dist[v] == INF) continue;
		for(int i = 0 ; i < (int)G[v].size() ; i++){
		    edge &e = G[v][i];
		    if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
			dist[e.to] = dist[v] + e.cost;
			prevv[e.to] = v;
			preve[e.to] = i;
			update = true;
		    }
		}
	    }
	}
     
	if(dist[t] == INF){
	    return -1;
	}
     
	int d = f;
	for(int v = t ; v != s ; v = prevv[v]){
	    d = min(d,G[prevv[v]][preve[v]].cap);
	}
	f -= d;
	res += d * dist[t];
	for(int v = t ; v != s ; v = prevv[v]){
	    edge &e = G[prevv[v]][preve[v]];
	    e.cap -= d;
	    G[v][e.rev].cap += d;
	}
    }
    return res;
}
 
int main(){
    int N;
    while(cin >> N, N){
	for(int i = 0 ; i < MAX_V ; i++){
	    G[i].clear();
	}
	int a,b,w;
	for(int i = 0 ; i < N ; i++){
	    cin >> a >> b >> w;
	    add_edge(a-1,b,1,-w);
	}
	for(int i = 0 ; i < 365 ; i++){
	    add_edge(i,i+1,2,0);
	}
	cout << -min_cost_flow(0,365,2) << endl;
    }
    return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << "\n";
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map( &:to_i )

A = Array.new( N ) do gets end
B = Array.new( M ) do gets end

def match( y, x )
	M.times do |i|
		M.times do|j|
			if A[ y + i ][ x + j ] != B[i][j] then
				return false
			end
		end
	end

	return true
end

( N - M + 1 ).times do |i|
	( N - M + 1 ).times do |j|
		if match( i, j ) then
			puts "Yes"
			exit( 0 )
		end
	end
end

puts "No"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
template<typename T>
class BIT
{
//bit[x]
//manage range of bit[x] is (x & -x)
//
public:
	static const int n = 2*110000;
	T bit[n] = {};
	void add(int a, T w)
	{
		for (int x = a; x <= n; x += x & -x)
		{
			bit[x] += w;
		}
	}
	T sum(int a)
	{
		T ret = 0;
		for (int x = a; x > 0; x -= x & -x)
		{
			ret += bit[x];
		}
		return ret;
	}
 
};
 
int main()
{
	string s;
	cin >> s;
	int hairetsu[2*110000];
	int n = s.size();
	for (int i = 1; i <= n; ++i)
	{
		hairetsu[i] = (s[i-1] == 'B'?1:0);
	}
	long long int ans = 0;
	BIT<long long int> BT;
	for (int i = 1; i <= n; ++i)
	{
		BT.add(i, hairetsu[i]);
		if (hairetsu[i] == 0)
		{
			ans += BT.sum(i);
		}
		// cout << i - BT.sum(hairetsu[i]) << " ";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+5;
ll dp[maxn][maxn];
struct node{
	ll pi,val;
}p[maxn];
bool cmp(node a,node b){
	return a.val<b.val;
}
int main() {
	int n;
	scanf("%d",&n);
	for(int i = 1;i<=n;i++) {scanf("%lld",&p[i].val); p[i].pi = i;}
	sort(p+1,p+1+n,cmp);
    for(int i = 1;i<=n;i++) dp[i][i] = p[1].val*abs(i - p[1].pi);
    for(int i = 2;i<=n;i++){
    	for(int l = 1,r = i;r<=n;r++,l++){
    		dp[l][r] = max(dp[l][r],max(dp[l+1][r]+p[i].val*abs(l-p[i].pi),dp[l][r-1]+p[i].val*abs(p[i].pi - r)));
    	}
    }
    printf("%lld",dp[1][n]);
	return 0;
}

Measured memory_bytes: 26456
N, K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

ans = Float::INFINITY
[*1..N-1].combination(K-1) do |seq|
    bit = Array.new(N, false)
    seq.each { |i| bit[i] = true }
    
    cost = 0
    base = a[0]
    (1..N-1).each do |i|
        if bit[i]
            if base >= a[i]
                cost += base - a[i] + 1
                base += 1
            else
                base = a[i]
            end
        else
            if base < a[i]
                cost += a[i] - base
                base = a[i]
            end
        end
    end
    ans = [ans, cost].min
end
puts ans

Measured memory_bytes: 1916
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<long long>v(N, 0);
    for (int i = 0; i < N; i++) {
        long long a;
        cin >> a;
        v[a]++;
    }
    long long ans = 1;
    for (int i = (N % 2 == 0) ? 1 : 0; i < N; i+=2) {
        if ((i == 0 && v[0] != 1) || (i != 0 && v[i] != 2)) {
            ans = 0;
            break;
        }
        else ans = ans*v[i] % MOD;
    }
    
    cout << ans << endl;

    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c<=(a+b))COUT(c+b);
    else if(c>(a+b))COUT(a+2*b+1);
    else COUT(a+2*b);
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

const char b = 'a'-1;

int n;
string s[50];

ll dp[25][51][51][27];
ll dfs(int d, int l, int r, int a){
    bool all_blank = true;
    for(int i=l; i<r; ++i)if(s[i][d]!=b) all_blank = false;
    if(all_blank) return r-l<=1;

    if(a == 27) return l==r;
    if(l==r) return 1;
    if(dp[d][l][r][a]>=0) return dp[d][l][r][a];

    int cpos = r, bpos = l-1;
    for(int i=l; i<r; ++i){
        if(s[i][d]==b) bpos = max(bpos,i);
        else cpos = min(cpos,i);
    }
    if(cpos < bpos) return 0;

    char c = b+a;
    ll ret = 0;
    for(int i=l; i<=r; ++i){
        (ret += (dfs(d+1,l,i,0)*dfs(d,i,r,a+1))%mod ) %= mod;
        if(i<r){
            if( (s[i][d]!=c && s[i][d]!='?') || (s[i][d]=='?' && c==b) ) break;
        }
    }
    return dp[d][l][r][a] = ret;
}

int main(){
    cin >>n;
    rep(i,n){
        cin >>s[i];
        while(s[i].size()<21) s[i] += b;
    }

    memset(dp,-1,sizeof(dp));
    cout << dfs(0,0,n,0) << endl;
    return 0;
}



Measured memory_bytes: 16964
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
seikaisuu = [0]*N
for answer in A:
    seikaisuu[answer-1] += 1
for x in seikaisuu:
    if K > Q - x:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8640
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,K;
  cin >> N >> K;
  K = ((N*(N-1))/2) - K + 1;
  ll A[N];
  ll minus = 0;
  ll plus = 0;
  ll zero = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      zero++;
    } else if (A[i] < 0){
      minus++;
    } else {
      plus++;
    }
  }
  sort(A,A+N);
  ll left = (-1) * Mod * Mod;
  ll right = Mod * Mod;
  while (right - left > 1) {
    ll mid = (left + right) / 2;
    ll sum = 0;
    if (mid == 0) {
      sum = ((N*(N-1))/2) - (minus * plus);
      if (sum >= K) {
        left = mid;
      } else {
        right = mid;
      }
      continue;
    }
    for (int i = 0; i < N; i++) {
      if (A[i] == 0) {
        if (mid > 0) {
          sum += 0;
        } else {
          sum += N-1;
        }
        continue;
      }
      if (A[i] > 0 && mid > 0) {
        ll s = lower_bound(A,A+N,(mid+A[i]-1)/A[i]) - A;
        sum += N - s;
        if (A[i] >= (mid+A[i]-1)/A[i]) {
          sum--;
        }
      } else if (A[i] < 0 && mid < 0) {\
        ll s = upper_bound(A,A+N,mid/A[i]) - A;
        sum += s;
        if (A[i] < mid/A[i]) {
          sum--;
        }
      } else if (A[i] > 0 && mid < 0) {
        ll s = lower_bound(A,A+N,mid/A[i]) - A;
        sum += N - s;
        if (A[i] >= mid/A[i]) {
          sum--;
        }
      } else {
        ll s = lower_bound(A,A+N,(mid-1)/A[i]) - A;
        sum += s;
        if (A[i] < (mid-1)/A[i]) {
          sum--;
        }
      }
      //cout << sum << " " << A[i] << endl;
    }
    sum /= 2;
    if (sum >= K) {
      left = mid;
    } else {
      right = mid;
    }
    //cout << mid << " " << sum << endl;
  }
  cout << left << endl;
  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



string s, t;
void solve(){
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	
	if(s == t.substr(0,n) && s.size() == t.size()-1){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

const int MAX_W = 1000;
const int MAX_N = 1000;
int W,N;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_W + 1];
void solve(){
  fill(dp, dp+W + 1 , 0);
  rep(i,N){
    for(int j = W ; j >= 0 ; j --){
      if(j - w[i] >= 0){
	dp[j] = max(dp[j] , dp[j-w[i]] + v[i]);
      }
    }
  }
  printf("%d\n",dp[W]);
  for(int i = W ; i >= 0 ; i --){
    if(dp[W] != dp[i]){
      printf("%d\n",i+1);
      break;
    }
  }
}

int main(void){
  int i = 0 ;
  while(scanf("%d",&W),W){
    printf("Case %d:\n",++i);
    scanf("%d",&N);
    rep(i,N){
      scanf("%d,%d",&v[i],&w[i]);
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int A,B,C,m,count=0;
    bool flag_A,flag_B,flag_C;
    cin >> A >> B >> C;
    flag_A = false;
    flag_B = false;
    flag_C = false;
    if(A%2==0)  flag_A=true;
    if(B%2==0)  flag_B=true;
    if(C%2==0)  flag_C=true;
    if(flag_A==flag_B&&flag_B==flag_C){
        m = max(A,B);
        m = max(m,C);
        count += (3 * m - A - B - C) / 2;
    }
    else if(flag_A==flag_B){
        A+=1;
        B+=1;
        count++;
        m = max(A,B);
        m = max(m,C);
        count += (3 * m - A - B - C) / 2;
    } 
    else if(flag_B==flag_C){
        B+=1;
        C+=1;
        count++;
        m = max(A,B);
        m = max(m,C);
        count += (3 * m - A - B - C) / 2;
    }
    else if(flag_C==flag_A){
        C+=1;
        A+=1;
        count++;
        m = max(A,B);
        m = max(m,C);
        count += (3 * m - A - B - C) / 2;
    }
    cout << count << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }



int main(){
	int N;
	vector<vector<int>> A(3, vector<int>(3));
	vector<int> b(N);
	rep (i, 3){
		rep(j, 3){
			cin >> A.at(i).at(j);
		}
	}
	cin >> N;
	rep(i, N) cin >> b.at(i);

	
	//int value;
	// Horizonal
	
	rep(i, 3){
		int Yes = 1;
		rep(j, 3){
			auto value = find(b.begin(), b.end(), A.at(i).at(j));
			if (value == b.end()) {
				Yes = 0;
				break;
			}
		}
		if (Yes){
			cout << "Yes" << endl;
			exit(0);
		}
	}
	// Vertical
	rep(i, 3){
		int Yes = 1;
		rep(j, 3){
			auto value = find(b.begin(), b.end(), A.at(j).at(i));
			if (value == b.end()) {
				Yes = 0;
				break;
			}
		}
		if (Yes){
			cout << "Yes" << endl;
			exit(0);
		}
	}

	//
	int Yes = 1;
	rep(i, 3){
		
		auto value = find(b.begin(), b.end(), A.at(i).at(i));
		if (value == b.end()) {
			Yes = 0;
			break;
		}
	}
	
	if (Yes){
		cout << "Yes" << endl;
		exit(0);
	}
	Yes = 1;
	rep(i,3){
		
		auto value = find(b.begin(), b.end(), A.at(i).at(2-i));
		if (value == b.end()) {
			Yes = 0;
			break;
		}
	}
	
	if (Yes){
		cout << "Yes" << endl;
		exit(0);
	}

	cout << "No" << endl;


}

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

int digit_sum(int n) {
	int sum = 0;
	while(n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	int n;
	cin >> n;
	int min = 1000;
	for(int a=1;2*a<=n;a++) {
		int s = digit_sum(a) + digit_sum(n-a);
		if(min > s) min = s;
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int M ,N ;
  cin >> N >> M;
  
  vi A(N);
  rep(i, N) cin >> A[i];
  
  int sum = 0;
  rep(i, N) {
    sum += A[i];
  }
  
  int th = sum / (4 * M);
  int rm = sum % (4 * M) != 0;
  if(rm == 0) {
    th --;
  }
  
  int ct = 0;
  rep(i, N) {
    if(A[i] > th) { ct ++; }
  }
  
  if(ct >= M) {
    fin("Yes");
  } else {
    fin("No"); 
  }
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

ans=0
dic=defaultdict(int)

for i in range(n):
    if i==0:
        dic[n-i-a[n-i-1]]+=1
    else:
        ans+=dic[n-i+a[n-i-1]]
        dic[n-i-a[n-i-1]]+=1
    # print(dic)
print(ans)

Measured memory_bytes: 141168
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0) cout << 1;
  if(b == 0) cout << 2;
  if(c == 0) cout << 3;
  if(d == 0) cout << 4;
  if(e == 0) cout << 5;
  
 return 0; 
}

Measured memory_bytes: 3624
//AnkitCode99
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define all(v) (v.begin(),v.end())
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
using namespace std;
int main()
{
	fast;
 	string s,t;
	cin>>t>>s;
	cout<<s+t<<endl;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){

    string s; int n,k;
    cin >> n >> k >> s ;
    vi p0(n+1,0),p1(n+1,0);
    n = 1;
    for (int i=1,c=1;i<sz(s);i++){
    	if (s[i] != s[i-1]) {
    		p0[n] = c; 
    		p1[n++] = c; 
    		c = 1; 
    	}
    	c += (s[i]==s[i-1]);
    	if (i==sz(s)-1) p0[n] = c;
    	if (i==sz(s)-1) p1[n] = c;
    }
    for (int i=1;i<=n;i++) p0[i] += p0[i-1] ; 
    for (int i=1;i<=n;i++) p1[i] += p1[i-1] ; 
    int ans0=0,ans1=0;
	for (int i=min(k*2+1,n);i<=n;i++){
		if (i&1) 
			ans1 = max(ans1,p1[i]-p1[max(0LL,i-(k*2+1))]);
		else 
			ans1 = max(ans1,p1[i]-p1[max(0LL,i-(k*2))]);
	}
	for (int i=min(k*2,n);i<=n;i++){
		if (i%2==0) 
			ans0 = max(ans0,p0[i]-p0[max(0LL,i-(k*2+1))]);
		else 
			ans0 = max(ans0,p0[i]-p0[max(0LL,i-(k*2))]);
	}
	int ans=0;
	ans = ((s[0]=='0')?ans0:ans1);
	if(ans == 0) ans = n ; 
	cout << ans << endl;
    /// 110011001100
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,len;
char s[100001];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>(s+1),len=unique(s+1,s+1+n)-s-1;
	cout<<len<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 384
import math
A, B, H, M = map(int, input().split())

# 長針
Ax = A * math.sin(M * math.pi / 30)
Ay = A * math.cos(M * math.pi / 30)

# 短針
Bx = B * math.sin(H * math.pi / 6 + M * math.pi / 360)
By = B * math.cos(H * math.pi / 6 + M * math.pi / 360)

#display(Ax, Ay, Bx, By) ####

ans = math.sqrt((Ax - Bx)**2 + (Ay - By)**2)
print(ans)

Measured memory_bytes: 9452
#include <iostream>
#include <vector>

#define REP(_i, _cnt) for(int _i = 0; _i < _cnt; _i++)

using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<ll> a(N), b(N);
  REP(i, N) cin >> a[i];
  REP(i, N) cin >> b[i];

  ll mcnt = 0, pcnt = 0;
  REP(i, N) {
    ll tmp = a[i] - b[i];
    if (tmp < 0) mcnt += -tmp / 2;
    else pcnt += tmp;
  }
  if (mcnt >= pcnt) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	int x, a;
	cin >> x >> a;
	cout << ((x < a)?0:10) << endl;
}


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

int main()
{
    int n; cin>>n;
    string s;
    cout<<0<<endl;
    cin>>s;
    if (s[0]=='V') return 0;
    int x=s[0]%2;
    for(int a=1<<17, res=0; a; a/=2) {
        int t=res+a;
        if (t>=n) continue;
        cout<<t<<endl;
        cin>>s;
        if (s[0]=='V') return 0;
        if (t%2==(x^s[0]%2)) res=t;
    }
}


Measured memory_bytes: 852
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n;
    int f[110][11]={};
    int p[110][12]={};
    cin >> n;
    rep(i,n)
        rep(j,10)
            cin >> f[i][j];
    rep(i,n)
        rep(j,11)
            cin >> p[i][j];

    int res = -1e9;
    for(int j=1;j<(1<<10);j++){
        int tmp = 0;
        for(int i=0;i<n;i++){
            int count = 0;
            for(int k=0;k<10;k++){
                if((1&j>>k)&&f[i][k])count++;
            }
            tmp+=p[i][count];
        }
        res = max(res,tmp);
    }
    cout << res <<endl;
    
    return 0;
}

Measured memory_bytes: 256
class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = float('inf')
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d
H,W = map(int,input().split())
C = []
A = []
WF = WarshallFloyd(10)
for i in range(10):
    C.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        WF.register(i,j,C[i][j],multiple=False)
C = WF.solve()
for i in range(H):
    A.append(list(map(int,input().split())))
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == -1:
            pass
        else:
            ans += C[A[i][j]][1]
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int x,y;
    cin>>x>>y;
    int res = 0;
    if( x == 1 && y == 1 ){
	res += 400000;
    }
    if( x == 1 ){
	res += 300000;
    }
    if( x == 2 ){
	res += 200000;
    }
    if( x == 3 ){
	res += 100000;
    }
    if( y == 1 ){
	res += 300000;
    }
    if( y == 2 ){
	res += 200000;
    }
    if( y == 3 ){
	res += 100000;
    }
    cout<<res<<endl;
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

    vector<int> v(n);

    rep(i, n) cin >> v[i];
    int alice = 0, bob = 0;
    sort(ALL(v), greater<int>());
    rep(i, n)
    {
        i % 2 == 0 ? alice += v[i] : bob += v[i];
    }

    OP(alice - bob);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();
		if(a < 3200) {
		    System.out.println("red");
		} else System.out.println(s);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
void A(void);
void B(void);
void C(void);

int main(void){
    A();
    return 0;
}

void A(void){
    int a,b,c,k;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d %d %d",c,a,b);
}

Measured memory_bytes: 128
#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    par = abs(A[0][0] + A[0][1]) % 2
    for (x, y) in A:
        if abs(x + y) % 2 != par:
            return None

    M = [2 ** i for i in range(31, -1, -1)]
    if par == 0:
        M.append(1)
    S = []

    for x, y in A:
        u = x + y
        v = x - y
        if par == 0:
            u += 1
            v += 1

        s = []
        for i in range(32):
            if u > 0:
                uv = 1
                u -= M[i]
            else:
                uv = -1
                u += M[i]

            if v > 0:
                vv = 1
                v -= M[i]
            else:
                vv = -1
                v += M[i]

            if (uv, vv) == (-1, -1):
                s.append('L')
            elif (uv, vv) == (1, 1):
                s.append('R')
            elif (uv, vv) == (-1, 1):
                s.append('D')
            else:
                s.append('U')

        assert u == 0
        assert v == 0

        if par == 0:
            s.append('L')

        S.append(''.join(s))

    return (M, S)



def main():
    N = int(inp())
    A = []
    for _ in range(N):
        x, y = [int(e) for e in inp().split()]
        A.append((x, y))

    ans = solve(N, A)
    if ans is None:
        print('-1')
        return

    m, s = ans
    print(len(m))
    print(*m)
    for t in s:
        print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.FileStore;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] order;
      StringBuilder result = new StringBuilder(n*4);
      Dictionary dict = new Dictionary(10_000_000);

      for(int i=0; i<n; i++) {
        order = br.readLine().split(" ");
        switch( order[0] ) {
          case "insert" :
            dict.insert(order[1]);
            break;
          case "find" :
            result.append( dict.find(order[1]) ).append("\n");
            break;
        }
      }

      System.out.print(result);
    }
  }
}

class Dictionary {
  boolean[] dict;

  public Dictionary(int size) {
    dict = new boolean[size];
  }

  public void insert(String str) {
    int key   = getKey(str);
    dict[key] = true;
  }
  public String find(String ref) {
    int key = getKey(ref);

    return isExist(key) ? "yes" : "no";
  }
  private int getKey(String str) {
    int len = str.length();
    int ret = 0;
    StringBuilder buf = new StringBuilder(12);
    for(int i=0; i<len; i++ ) {
      buf.append( str1ToInt(str.substring(i,i+1)) );
    }
    ret = Integer.parseInt(buf.toString(), 5);

    return ret;
  }
  private boolean isExist(int key) {

    return dict[key];
  }
  private int str1ToInt(String s1) {

    switch( s1 ) {
      case "A" :
        return 1;
      case "C" :
        return 2;
      case "G" :
        return 3;
      case "T" :
        return 4;
      default :
        return -1;
    }

  }
}


Measured memory_bytes: 237772
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 200010
using namespace std;
int n,con,h[N<<1],in[N],Rt,f[N];
struct edge
{
	int to,ne;
}e[N<<1];
int read()
{
	int x=0,f=1; 
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1; 
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0'; 
		ch=getchar();
	}
	return x*f;
}
void add(int u,int v)
{
	e[++con].to=v;
	e[con].ne=h[u];
	h[u]=con;
}
void dfs(int rt,int pr,int x)
{
	vector<int>v; 
	v.clear();
	for(int i=h[rt];i;i=e[i].ne)
	if(e[i].to!=pr) 
	{
		dfs(e[i].to,rt,x);
		v.push_back(f[e[i].to]);
	}
	if(!(v.size()&1)) 
		v.push_back(0);
	sort(v.begin(),v.end());
	int l=0,r=v.size()-1,rs=n+1;
	while(l<=r)
	{
		int mid=(l+r)>>1,fg=1;
		for(int i=0,j=v.size()-1;i<j;i++,j--)
		{
			if(i==mid) 
				i++; 
			if(j==mid) 
				j--;
			fg&=(v[i]+v[j])<=x;
		}
		if(fg) 
			
		r=mid-1,rs=v[mid];
		else l=mid+1;
	}
	f[rt]=rs+1;
}
bool check(int x)
{
	dfs(Rt,0,x); 
	return f[Rt]<=x+1;
}
int main()
{
	n=read(); 
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		add(u,v);
		in[u]++;
		add(v,u);
		in[v]++;
	}
	int cnt=0; 
	for(int i=1;i<=n;i++) 
		cnt+=in[i]&1,Rt=in[i]==1?i:Rt;
	int l=0,r=n,ans=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) 
			r=mid-1,ans=mid;
		else 
			l=mid+1;
	}
	cout<<(cnt+1)/2<<" "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll H, W, N; cin >> H >> W >> N;
    map<pair<ll, ll>, ll> mp;

    for(int i=0; i<N; i++){
        ll a, b; cin >> a >> b;
        for(int j=max(1LL, a-2); j<=min(a, H-2); j++) for(int k=max(1LL, b-2); k<=min(b, W-2); k++) mp[{j, k}]++;
    }

    vector<ll> ans(10, 0);
    ans[0] = (H-2)*(W-2)-mp.size();
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) ans[itr->second]++;

    for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;

}

Measured memory_bytes: 56448
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    char str[3]={0};
    long a,b;
    scanf("%ld%s%ld", &a, str, &b);

    if(str[0]=='+') {
        printf("%ld\n", a+b);
    }
    else {
        printf("%ld\n", a-b);
    }

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Card {
    string mark;
    int num;
};

void BubbleSort(vector<Card> &src) {
    for (size_t i = 0; i < src.size(); i++) {
        for (size_t j = src.size() - 1; j > i; --j) {
            if (src.at(j).num < src.at(j - 1).num) {
                Card temp = src.at(j);
                src.at(j) = src.at(j - 1);
                src.at(j - 1) = temp;
            }
        }
    }
}

void SelectionSort(vector<Card> &src) {
    for (size_t i = 0; i <= src.size() - 1; i++) {
        size_t minj = i;
        for (size_t j = i; j <= src.size() - 1; j++) {
            if (src.at(j).num < src.at(minj).num) {
                minj = j;
            }
        }
        Card temp = src.at(i);
        src.at(i) = src.at(minj);
        src.at(minj) = temp;
    }
}

auto trace = [&](vector<struct Card> vi) {
    for (size_t i = 0; i < vi.size(); i++) {
        cout << vi.at(i).mark << vi.at(i).num;
        cout << ((i != vi.size() - 1) ? " " : "\n");
    }
};

auto is_stable = [&](vector<struct Card> v1, vector<struct Card> v2) {
    for (size_t i = 0; i < v1.size(); i++) {
        if (v1.at(i).mark != v2.at(i).mark) {
            return false;
        }
    }
    return true;
};

int main() {
    vector<Card> for_bubble;
    vector<Card> for_selection;

    int n;
    cin >> n;
    while (n--) {
        string input;
        cin >> input;

        Card card;
        card.mark = input[0];
        card.num = input[1] - '0';

        for_bubble.push_back(card);
        for_selection.push_back(card);
    }

    BubbleSort(for_bubble);
    SelectionSort(for_selection);

    trace(for_bubble);
    cout << "Stable" << endl;

    trace(for_selection);
    if (is_stable(for_bubble, for_selection)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}




Measured memory_bytes: 3144
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Os")
*/
 
#include <bits/stdc++.h>
//#include <windows.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
    /*
const int MAX_MEM = 1e8;
int mpos=0;
char mem[MAX_MEM];
inline void * operator new(size_t n){
	char *res = mem + mpos;
	mpos += n;
	assert(mpos <= MAX_MEM);
	return (void *)res;
}
 
inline void operator delete(void *){}
    */

const int N = 2e5 + 13;
const ll mod = 1e9 + 7;
    
int n, m;
int g[3][N];

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

	cin >> n >> m;
	g[1][1] = 1;
	for(int i = 1;i <= n;i++){	
		g[2][i] = 1;
	}

	for(int i = 1;i <= m;i++){
		int x, y;
		cin >> x >> y;
		if(g[1][x] == 1){
			g[1][y] = 1; 
		}

		g[2][x] -= 1;
		g[2][y] += 1;

		if(g[2][x] == 0){
			g[1][x] = 0;	
		}
	}

	int cnt = 0;
	for(int i = 1;i <= n;i++){
		if(g[1][i] == 1){
			cnt++;
		}
	}
	cout << cnt;
	
	return 0;
}

Measured memory_bytes: 1024
S=gets.chomp
T=gets.chomp
N=S.length
map=Hash.new

N.times do |i|
  if map[S[i]] && map[S[i]] != T[i]
    puts "No"
    exit
  end
  map[S[i]]=T[i]
end

if map.length != map.values.uniq.length
  puts "No"
else
  puts "Yes"
end  

Measured memory_bytes: 2624
#include<stdio.h>
#include <sysexits.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int j,N,tmp,sum,x[20],i,mod[5],s[5],k;
   if(scanf("%d",&N)>1){
    exit(0);
  }
  for(i=0;i<N;i++){
    if(scanf("%d",&x[i])>1){
    exit(0);
  }
  }
  sum=1;
  for(i=1;i<N;i++){
    // printf("a");
    for(j=i;j>0;j--){
      //      printf("a");
      if(x[i]>=x[i-j]){
        //printf("a");
      if(j==1){
       sum=sum+1;
      }
    }
    else{
      break;
    }
    }
  }
  //  printf("%d",N);
  printf("%d",sum);
  return 0;
}


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

int main() {
	int X;
	cin >> X;
	for (int i = 1; i < 9; i++) {
		if (200 * i + 200<= X && X < 200 * i + 400) {
			cout << 9 - i << endl;
			break;
		}
	}
}


Measured memory_bytes: 3568
#include<stdio.h>
int main()
{
	int a,b,c;
	
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
		a^=b;
		b^=a;
		a^=b;
	}
	if(b>c){
		b^=c;
		c^=b;
		b^=c;
	}
	
	printf("%d\n",a+b);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    long tm; int a,b,c,d;

    scanf("%ld", &tm);
    a=tm/3600;
    d=tm % 3600;
    b=d / 60;
    d %= 60;
    c=d;
    printf("%d:%d:%d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    REP(i,n){
        cin >> l[i];
    }
    SORT(l);
    int lall = 0;
    REP(i,n-1){
        lall += l[i];
    }
    if(lall>l.back()){
        put("Yes");
    }else{
        put("No");
    }
    
    return 0;
}


Measured memory_bytes: 256
// AOJ
// ALDS1_2_B Selection Sort

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N, i, j;
	cin >> N;
	int A[N];
	for (i=0; i<N; i++) {
		cin >> A[i];
	}

	int minj;
	int cnt = 0;
	for (i=0; i<N; i++) { 
		minj = i;
		for (j=i; j<N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		swap(A[i],A[minj]);
		if (i!= minj) cnt++;
	}
	for (i=0; i<N; i++) {
		cout << A[i];
		if (i!=N-1) {
			cout << " ";
		}
	}
	cout << endl;
	cout << cnt << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









int n,d,c[30],msk,msk2,res,sz,mn;
vector<int>v;





void solve()
{
	for(int i=0;i<=12;i++)c[i]=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>d;
		c[d]++;
	}
	if(n>24||c[0]>0)
	{
		cout<<"0\n";
		return;
	}
	msk=1;
	for(int i=0;i<=12;i++)
	{
		if(c[i]>=3)
		{
			cout<<"0\n";
			return;
		}
		else if(c[i]==2)
		{
			msk|=1<<i;
			msk|=1<<((24-i)%24);
			c[i]=0;
		}
		else if(c[i]==1)v.pb(i);
	}
	res=0;
	sz=v.size();
	for(int i=0;i<(1<<sz);i++)
	{
		msk2=msk;
		for(int j=1,k=0;j<(1<<sz);j<<=1,k++)
		{
			if(i&j)
			{
				msk2|=1<<v[k];
			}
			else
			{
				msk2|=1<<((24-v[k])%24);
			}
		}
		mn=30;
		for(int j=0;j<=24;j++)
		{
			if((1<<j)&msk2)
			{
				for(int k=j+1;k<=24;k++)
				{
					if((1<<k)&msk2)
					{
						d=abs(j-k);
						d=min(d,24-d);
						mn=min(mn,d);
					}
				}
			}
		}
		res=max(res,mn);
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

int main()
{
  string S;
  cin >> S;
  string result = "Good";

  if (S[0] == S[1]) {
    result = "Bad";
  }
  if (S[1] == S[2]) {
    result = "Bad";
  }
  if (S[2] == S[3]) {
    result = "Bad";
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H, W, i, j;

  while(1){
    scanf("%d %d\n", &H, &W);

    if(H == 0 && W == 0)
      break;

    for(i = 0; i < W; i++){
      printf("#");
    }
    printf("\n");

    for(i = 0; i < H - 2; i++){
      printf("#");
      for(j = 0; j < W - 2; j++){
        printf(".");
      }
      printf("#\n");
    }

    for(i = 0; i < W; i++){
      printf("#");
    }
    printf("\n\n");
  }
  return 0;
}

Measured memory_bytes: 592