akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }
  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i,n){ cin>>p[i]; p[i]--; }
  UnionFind uf(n);
  rep(i,m){
    int x,y; cin>>x>>y; x--; y--;
    uf.unite(x,y);
  }
  int ans=0;
  rep(i,n){
    if(uf.check(i,p[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a, b, c, x, y;
    cin >> a>> b >> c >> x >> y;
    int ans;
    if(2 * c >= a + b){
        ans = x * a + y * b;
    }else{
        ans = min(2 * c * max(x, y), min(x, y) * c * 2 + abs(x - y) * ((y < x) ? a : b));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ff first
#define ss second
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define Pqi priority_queue<int>
#define Pqg priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define TC(x) while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main()
{
  IOS
  LL x;
  cin >> x;
  LL ans = 0;
  ans = (x / 500) * 1000;
  x %= 500;
  if(x >= 5) ans += (x / 5) * 5; 
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

const llong C = 1000000000000000000;

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;
  
  int cnt = 0;
  vector<llong> s(n);
  REP(i,n){
    cin >> s[i];
    if(s[i] == 0) cnt = -1;
  }
  if(cnt == -1){
    cout << 0 << endl;
    return 0;
  }

  llong prod = 1;
  REP(i,n){
    if(s[i] <= C / prod){
      prod *= s[i];
    }else{
      cout << -1 << endl;
      return 0;
    }
  }

  if(prod <= C){
    cout << prod << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}



Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
LL dp[55][2505][55];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    dp[0][0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            for(int x=0;x<=n;x++){
                if(dp[i-1][j][x] == 0) continue;
                dp[i][j+2*x][x] = (dp[i][j+2*x][x] + (2*x+1)*dp[i-1][j][x])%mod;
                if(x-1 >= 0) dp[i][j+2*x][x-1] = (dp[i][j+2*x][x-1] + x*x*dp[i-1][j][x])%mod;
                dp[i][j+2*x][x+1] = (dp[i][j+2*x][x+1] + dp[i-1][j][x])%mod;
            }
        }
    }
    printf("%lld\n", dp[n][k][0]);
}

Measured memory_bytes: 53504
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[300000];
long long b[300000] = {0};
void half(int st, int n, long long *c){
    if(n==2){
        c[0] = a[st];
        c[1] = a[st+1];
        c[2] = a[st];
        c[3] = a[st+1];
        return;
    }
    int p = st;
    int q = st+n-2;
    long long s = b[st+n]-b[st];
    while(p<q){
        int mi = (p+q+1)/2;
        if( (b[mi+1] - b[st])*2 > s){
            q = mi-1;
        }
        else{
            p = mi;
        }
    }
    c[0] = b[p+1]-b[st];
    c[1] = b[st+n]-b[p+1];
    if(p+1<st+n-1){
        ++p;
    }
    c[2] = b[p+1]-b[st];
    c[3] = b[st+n]-b[p+1];
}

int main(){
    int n;
    cin>>n;
    b[0] = 0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        b[i+1] = b[i] + a[i];
    }
    long long mi = -1;
    
    for(int i=2;i<n-1;++i){
        long long c1[2][2];
        long long c2[2][2];
        half(0,i, &c1[0][0]);
        half(i,n-i, &c2[0][0]);
        for(int j=0;j<2;++j){
            for(int k=0;k<2;++k){
                long long tmp = max(max(c1[j][0],c1[j][1]),max(c2[k][0],c2[k][1])) - min(min(c1[j][0],c1[j][1]),min(c2[k][0],c2[k][1]));
                if(mi<0 || tmp<mi){
                    mi = tmp;
                }
            }
        }
    }
    cout<<mi<<endl;
    return 0;
}


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

int pat;
string eq;

bool value(char x){
    if(x == 'T')return true;
    if(x == 'F')return false;
    return pat & (1 << (x - 'a'));
}

bool eval(int left, int right){
    if(left + 1 == right)return value(eq[left]);
    if(eq[left] == '-')return !eval(left + 1, right);
    int s = 0;
    for(int i = left + 1;i < right - 1;i++){
	if(eq[i] == '(')s++;
	if(eq[i] == ')')s--;
	if(s != 0)continue;
	if(eq[i] == '*'){
	    return eval(left + 1, i) & eval(i + 1, right - 1);
	}
	if(eq[i] == '+'){
	    return eval(left + 1, i) | eval(i + 1, right - 1);
	}
	if(eq[i] == '-' && eq[i + 1] == '>'){
	    return (!eval(left + 1, i)) | eval(i + 2, right - 1);
	}
    }
}


int main(){
    while(true){
	cin >> eq;
	if(eq == "#")return 0;
	int center = 0;
	bool equal = true;
	while(eq[center] != '=')center++;
	for(int i = 0;i < (1 << 11);i++){
	    pat = i;
	    if(eval(0, center) != eval(center + 1, eq.size())){
		equal = false;
		break;
	    }
	}
	if(equal)
	    cout << "YES" << endl;
	else
	    cout << "NO" << endl;
    }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
void takahasi(int &x, int &y){
    if(x%2 ==1){
        x -= 1;
        x /= 2;
        y += x;
    }
    else{
        x /= 2;
        y += x;
    }
}
void aoki(int &x, int&y){
    if(y%2 ==1){
        y -= 1;
        y /= 2;
        x += y;
    }
    else{
        y /=2;
        x += y;
    }
    
}
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    for(int i=1; i<k+1 ; i++){
        if(i%2 == 1){
            takahasi(a,b);
        }
    else{
        aoki(a,b);
    }
    }
    cout << a << " " << b <<endl;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	ll a,b;
	cin>>s>>t>>a>>b;
	string u;
	cin>>u;
	if(u==s){
		a--;
	}
	if(u==t){
		b--;
	}
	cout << a<<" "<<b;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <string>
    typedef long long ll;
     
    using namespace std;
    int main(){
    	int N;
        string S;
        cin >> N;
        cin >> S;
        int x = 0;
        int ans = 0;
        for (int i = 0; i < N; i++) {
        	if (S[i] == 'I') {
        		x++;
        	}
        	else {
        		x--;
        	}
        	if (x > ans) {
        		ans = x;
        	}
        } 
        cout << ans << endl;
    }

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
N = sum(a)

s = 1
S = 1
if a[0] > 1 or (a[0] >= 1 and len(a) > 1):
    S = -1
else:
    for i in range(1,n+1):
        if a[i] > 2*s:
            S = -1
            break
        if s*2 <= N:
            S += s*2
            s += s - a[i]
        else:
            S += N
            s += N - s - a[i]
        N -= a[i]
print(S)

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


using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


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

    /*set<pair<int, int>> losing;
    losing.insert(mp(0, 0));
    for (int sum = 1; sum<=20; sum++)
    {
        for (int x = 0; x<=sum; x++)
        {
            int y = sum-x;
            bool check = false;
            for (int i = 1; i<=x/2; i++) if (losing.count(mp(x-2*i, y+i))) check = true;
            for (int i = 1; i<=y/2; i++) if (losing.count(mp(x+i, y-2*i))) check = true;
            if (!check) losing.insert(mp(x, y));
        }
    }

    for (auto it: losing) cout<<it.first<<' '<<it.second<<endl;*/

    ll x, y;
    cin>>x>>y;
    if (abs(x-y)<=1) cout<<"Brown";
    else cout<<"Alice";

}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

c = [LIST() for _ in range(3)]

a = [-1, -1, -1]
b = [-1, -1, -1]
a[0] = 0
for i in range(3):
	for j in range(3):
		if a[j] != -1:
			b[i] = c[i][j] - a[j]
		else:
			a[j] = c[i][j] - b[i]
		
for i in range(3):
	for j in range(3):
		if a[j] + b[i] != c[i][j]:
			print("No")
			sys.exit()
else:
	print("Yes")


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6;
char s[M];
int a[M];
int main()
{
	int n, j;
	cin >> n;
	scanf("%s", s + 1);
	int left, right = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == 'W')
			a[i] = 1;
		else
			a[i] = 0;
		right += a[i];
	}
	left = 0;
	right = right - a[1];
	int min = 1e7, cnt;
	
	//   i == 1
	cnt = (n - 1) - right;
	if (cnt < min)
	{
		min = cnt;
		j = 1;
	}
	//    2 <= i <= n - 1
	for (int i = 2; i <= n - 1; ++i)
	{
		left += a[i - 1];
		right -= a[i];
		cnt = (n - i) - right + left;
		if (cnt < min)
		{
			min = cnt;
			j = i;
//			printf("r = %d, l = %d\n", right, left);
		}
	}
	// i == n
	left += a[n - 1];
	cnt = left;
	if (cnt < min)
	{
		min = cnt;
		j = n;
	}
		
	cout << min << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> canw;
    int k = 6;
    while(k <= 100000){
        canw.push_back(k);
        k *= 6;
    }
    k = 9;
    while(k <= 100000){
        canw.push_back(k);
        k *= 9;
    }

    vector<int> dp(100001);
    for (int i = 1; i < dp.size(); ++i) {
        dp[i] = i;
    }
    for (int i = 0; i < canw.size(); ++i) {
        for (int j = canw[i]; j < dp.size(); ++j) {
            dp[j] = min(dp[j], dp[j-canw[i]] + 1);
        }
    }
    int n;
    cin >> n;
    cout << dp[n] << '\n';

}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    
    ans = 20
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            a = str(i)
            b = str(N // i)
            ans = min(ans, max(len(a), len(b)))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long

ll n,k;

ll t[111111];

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


	rep(i,n){
		int a,b;
		cin>>a>>b;
		t[a]+=b;
	}


	ll sum=0,ans;

	rep(i,11111111111){
		sum+=t[i];
		if(sum>=k){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, n1; cin >> n >> n1;
    bool arr[n];
    memset(arr, false, sizeof(arr));
    bool res = false;
    for(int i=0;i<n1; i++){
        int x, y; cin >> x >> y;
        if(x == 1){
            if(arr[y]) res = true;
            arr[y] = true;
        }
        else if(y == n){
            if(arr[x]) res = true;
            arr[x] = true;
        }
    }
    if(res) cout << "POSSIBLE"<< endl;
    else cout << "IMPOSSIBLE"<< endl;


    return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

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

int par[MAX_N];
int myrank[MAX_N];

void init(int n)
{
  for (int i = 0; i < n; i++) {
    par[i] = i;
    myrank[i] = 0;
  }
}

int find(int x)
{
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (myrank[x] < myrank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(myrank[x] == myrank[y]) myrank[x]++;
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

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

  P x[MAX_N];
  P y[MAX_N];
  for (int i = 0; i < N; i++) {
    int x_, y_;
    cin >> x_ >> y_;
    x[i] = make_pair(x_, i);
    y[i] = make_pair(y_, i);
  }
  sort(x, x + N);
  sort(y, y + N);

  pair<int, P> dis[MAX_N * 2];

  for (int i = 0; i < N - 1; i++) {
    dis[i] = make_pair(x[i+1].first - x[i].first, make_pair(x[i+1].second, x[i].second));
  }
  for (int i = 0; i < N - 1; i++) {
    dis[N - 1 + i] = make_pair(y[i+1].first - y[i].first, make_pair(y[i+1].second, y[i].second));
  }

  sort(dis, dis + 2*(N-1));

  int ans = 0;
  for (int i = 0; i < 2*(N-1); i++) {
    int d = dis[i].first, l = dis[i].second.first, r = dis[i].second.second;
    if (!same(l, r)) {
      ans += d;
      unite(l, r);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

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

		int S = scanner.nextInt();
		int W = scanner.nextInt();

		if(W >= S) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35788
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n-- )
  {
    set<string> lis;
    char s[ 128 ], *p, *e;

    scanf ( " %s", s );
    e = s + strlen ( s );
    for ( p = s; p != e; ++p )
    {
      string h ( s, p - s );
      string t ( p, e - p );

      lis.insert ( h + t );
      lis.insert ( t + h );
      reverse ( t.begin ( ), t.end ( ) );
      lis.insert ( h + t );
      lis.insert ( t + h );
      reverse ( h.begin ( ), h.end ( ) );
      reverse ( t.begin ( ), t.end ( ) );
      lis.insert ( h + t );
      lis.insert ( t + h );
      reverse ( t.begin ( ), t.end ( ) );
      lis.insert ( h + t );
      lis.insert ( t + h );
    }

    printf ( "%zu\n", lis.size ( ) );
  }

  return ( 0 );
}

Measured memory_bytes: 908
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N, K;
    cin >> N >> K;

    set<int> s;
    REP(i, K) {
        int d;
        cin >> d;
        s.insert(d);
    }

    int ans = N;
    while (true) {
        string str = to_string(ans);

        bool ok = true;
        REP(i, str.size()) {
            char c = str[i];
            if (s.count(c - '0') > 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            break;
        }
        ans++;
    }

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


Measured memory_bytes: 256
x=[]
y=[]
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:break
    else:
        x=[int(input()) for i in range(n)]
        if len(x)<k:
            pass
        else:
            s=sum(x[0:k])
            y.append(s)
            for i in range(0,n-k):
                s=s-x[i]+x[i+k]
                y.append(s)
            print(max(y))


Measured memory_bytes: 11712
#include <iostream>
#include <string>
#include <vector>

using namespace std;

main(){
    int size, queries;
    cin >> size >> queries;
    vector<int> g(size,0);
    int A, B;
    while(queries--){
        cin >> A >> B;
        g[A] +=1;
        g[B] +=1;
    }
    bool possible = true;
    for(int i=0;i<size;++i){
        if(g[i]%2==1){
            cout << "NO" << endl;
            possible = false;
            break;
        }
    }
    if(possible) cout << "YES" << endl;
}

Measured memory_bytes: 640
n = int(input())

w = [[0 for i in range(2)]for i in range(n)]

ans = "Yes"
total = 0
for i in range(n):
    a,b = map(int, input().split())
    w[i][0] = b
    w[i][1] = -a

w.sort()

for i in range(n):
    total += -1*w[i][1]
    #print(total, w[i][0])
    if total > w[i][0]:
        ans = "No"
        break

print(ans)



Measured memory_bytes: 40156
import sys
input = sys.stdin.readline

# up_list = []
# down_list = []


def count_scan(s):
    max_min = 0
    compare = 0
    for c in s:
        if c == '(':
            compare += 1
        elif c == ')':
            compare -= 1
            max_min = min(max_min, compare)
    return min(max_min, compare), compare


def key(lst):
    m, c = lst
    if c > 0:
        return 1, m
    else:
        return -1, c - m


def main():
    n = int(input())
    lst = [input() for _ in range(n)]

    # up_list.sort(key=lambda x: x[1], reverse=True)
    # down_list.sort(key=lambda x: x[1], reverse=False)
    txt = 'No'
    ans = 0
    # print(lst)
    # print(sorted([count_scan(lst) for i in lst],
                #  reverse=True,
                #  key=key))
    for max_min, c in sorted([count_scan(s) for s in lst],
                             reverse=True,
                             key=key):
        # print(f"{max_min = }, {c = }, {ans = }")
        if max_min + ans < 0:
            break
        ans += c
    else:
        if ans == 0:
            txt = 'Yes'

    print(txt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 234948
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  vi H(N);
  rep(i,0,N) cin>>H[i];
  vi dp(N);
  dp[1]=abs(H[1]-H[0]);
  rep(i,2,N){
    dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]));
  }
  cout<<dp[N-1]<<endl;
  }


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K;
    cin >> N >> K;
    int dp[114514][2]={};
    vector<int> A,B;
    A.push_back(0);
    for(int i=1;i*i<=N;i++){
        if(i!=N/i){
            A.push_back(i);
        }
        A.push_back(N/i);
    }
    sort(A.begin(),A.end());
    REP(i,A.size()-1){
        B.push_back(A[i+1]-A[i]);
    }
    /*REP(i,B.size()){
        cout << B[i] << " ";
    }cout << endl;*/
    
    for(int i=0;i<B.size();i++){
        dp[i][0]=1;
        dp[i][1]=0;
    }
    REP(l,K-1){
        vector<int> C;
        REP(i,B.size()){
            C.push_back(dp[i][0]*B[i]);
        }
        reverse(C.begin(),C.end());
        dp[B.size()][1]=0;
        RREP(i,B.size()){
            dp[i][1]=dp[i+1][1]+C[i];
            dp[i][1]%=MOD;
        }
        
        REP(i,B.size()){
            dp[i][0]=dp[i][1];
            dp[i][1]=0;
        }
        /*
        REP(i,B.size()){
            cout << C[i] << " ";
        }cout << "    ";
        REP(i,B.size()){
            cout << dp[i][0] << " ";
        }cout << endl;*/
    }
    int Ans=0;
    REP(i,B.size()){
        Ans+=dp[i][0]*B[i];
        Ans%=MOD;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


template< typename T >
struct SegmentTree{
    private:
        int n;
        vector<T> segMax;
        vector<T> segAdd;
 
    public:
        SegmentTree(int sz){
            n = 1;
            while(n < sz) n *= 2;
            segMax.resize(2*n-1, 0);
            segAdd.resize(2*n-1, 0);
        }
 
        void add(int a, int b, T x, int k, int l, int r) {
            if (r <= a || b <= l) return;
            if (a <= l && r <= b){
                segAdd[k] += x;
                segAdd[k] %= mod;
                return;
            }
            add(a, b, x, k * 2 + 1, l, (l + r) / 2);
            add(a, b, x, k * 2 + 2, (l + r) / 2, r);
            segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2])%mod;
        }
 
        void add(int a,int b, T x) {
            add(a, b, x, 0, 0, n);
        }
 
        T getMax(int a, int b, int k, int l, int r) {
            if (r <= a || b <= l) return 0;
            if (a <= l && r <= b) return (segMax[k] + segAdd[k])%mod;
            T left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
            T right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
            return (max(left, right) + segAdd[k])%mod;
        }
 
        T getMax(int a,int b){
            return getMax(a, b, 0, 0, n);
        }
};


int main(){
    LL n,k;cin >> n >> k;
    vector<P> v(k);
    for (int i = 0; i < k; i++) {
        cin >> v[i].fs >> v[i].sc;
    }
    SegmentTree<LL> seg(n + 1);
    seg.add(1,2,1);
    for (int i = 1; i < n; i++) {
        LL t = seg.getMax(i, i + 1);
        for (int j = 0; j < k; j++) {
            int l = i + v[j].fs, r = min(n + 1, i + v[j].sc + 1);
            seg.add(l, r, t);
        }
    }
    cout << seg.getMax(n, n + 1) << endl;
    return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef long long ll;

const int maxn = 5e3 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  cin >> n;
  #define pii pair<int,int>
  vector<pair<pii,int> > group1, group2;
  int sum = 0;

  for (int i = 0; i < n; ++i){
    string s; cin >> s;
    int mi1 = 0, mi2 = 0, t1 = 0, t2 = 0;

    for (int j = 0; j < sz(s); ++j) t1 = t1 + (s[j] == '(' ? 1 : -1), mi1 = min(mi1, t1);
    for (int j = sz(s) - 1; j >= 0; --j) t2 = t2 + (s[j] == '(' ? -1 : 1), mi2 = min(mi2, t2);

    if (t1 >= 0) group1.push_back(mp(mp(t1, -mi1), i + 1) );
    else group2.push_back(mp(mp(t2, -mi2), i + 1) );
    sum += t1;
  }
  if (sum != 0){
    cout << "No";
    return 0;
  }

  vector<int> ansgr1, ansgr2;

  int cur;

  sort(All(group1), [&](pair<pii, int> x, pair<pii, int> y){
    return x.first.second < y.first.second;
  });

  cur = 0;
  for (int i = 0; i < (int)group1.size(); ++i){
    int t = group1[i].first.first, cost = group1[i].first.second, pos = group1[i].second;
    if (cur < cost){
      cout << "No"; return 0;
    }
    ansgr1.push_back(pos);
    cur += t;
  }

  sort(All(group2), [&](pair<pii, int> x, pair<pii, int> y){
    return x.first.second < y.first.second;
  });

  cur = 0;
  for (int i = 0; i < (int)group2.size(); ++i){
    int t = group2[i].first.first, cost = group2[i].first.second, pos = group2[i].second;
    if (cur < cost){
      cout << "No"; return 0;
    }
    ansgr2.push_back(pos);
    cur += t;
  }
  reverse(ansgr2.begin(), ansgr2.end());
  cout << "Yes\n";
//  for (auto p : ansgr1) cout << p <<' '; for (auto p : ansgr2) cout << p <<' ';
}




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

int main()
{
 ll int a,b;
  cin>>a>>b;
 ll int n=b-a+1;
  ll int ans=INT_MAX;
 ll int m=a%2019;
 ll int ma=b%2019;
  if(abs(a-b)>=2019)
  {
  cout<<"0"<<endl;
  return 0;
  }
  for(ll int i=a;i<=b-1;i++)
  {
    for(ll int j=i+1;j<=b;j++)
    {
      ans=min(ans,(i*j)%2019);    
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<tuple<string,int,int>> restaurants;
    rep(i,n) {
        string s;
        int p;
        cin >> s >> p;
        restaurants.emplace_back(s, -p, i+1);
    }
    sort(ALL(restaurants));
    rep(i,n){
        int ans = get<2>(restaurants[i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  for(int i=0;i<m;i++) {
    cin >> a[i] >> b[i];
  }
  
  int ans;
  int _n=1;
  int _m=n;
  for(int i=0;i<m;i++) {
    if(_n<a[i]) {
      _n = a[i];
    }
    if(_m>b[i]) {
      _m = b[i];
    }
  }
  ans = _m-_n+1;
  if(ans<0) {
    ans=0;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int a=0,b=0,c=0;
	for(int i = 0 ; i < 3 ; i++)
	{
		if(s[i] == 'a')
			a++;
		if(s[i] == 'b')
			b++;
		if(s[i] == 'c')
			c++;
	}
	if(a == 1 && b == 1 && c == 1)
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

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

ll fac[MAX_N];
ll inv[MAX_N];

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll inv_(ll a) {
	return mod_pow(a, mod - 2);
}

ll C_(int a, int b) { //assume a >= b
	return fac[a] * inv_(fac[b]) % mod * inv_(fac[a - b]) % mod;
}


int N, M;

void solve() {
	cin >> N >> M;
	fac[0] = 1; fac[1] = 1;
	inv[1] = 1;
	rep(i, 2, 100001) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
	}
	if(abs(N - M) > 1) cout << "0\n";
	else {
		if(abs(M - N) == 1) {
			cout << fac[M] * fac[N] % mod << "\n";
		}
		else {
			cout << 2 * fac[M] * fac[N] % mod << "\n";
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
from pprint import pprint as pp
N, K = map(int, input().split())
An = list(map(int, input().split()))

bin_cnt = [[0 for _ in range(N)] for _ in range(40)]

for i in range(N):
    tmp = An[i]
    for j in range(40):
        bin_cnt[j][i] = tmp%2
        tmp = tmp//2

X = 0
for j in sorted(range(40),reverse=True):
    if sum(bin_cnt[j]) < N - sum(bin_cnt[j]):
        X += 2**j
    if X > K:
        X -= 2**j

ans = 0
# pp(bin_cnt)
# print(X)
for A in An:
    ans += X^A

print(ans)


Measured memory_bytes: 39976
import java.util.Scanner;

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



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

using namespace std;

int main( int argc, char** argv ){

	int N,K;

	cin >> N >> K;

	if( N >= K ){
		if(N%2 == 0){

			if( N / 2 >= K ){
				cout << "YES";
			}else{
				cout << "NO";
			}

		}else{
			if( (N+1)/2 >= K){
				cout << "YES";
			}else{
				cout << "NO";
			}
		}
	}else{
		cout << "NO";
	}



	return 0;
}

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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, k;
  cin >> n >> k;
  int a = n / k;
  int b = 0;
  if(k % 2 == 0){
    b = a + (n % k >= k / 2 ? 1 : 0);
  }
  ll res = 1LL * a * a * a + 1LL * b * b * b;
  cout << res;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define VMAX 999999999
typedef struct{
  int n;
  char c;
}member;
void quickSort(member *,int,int);
int partition(member *,int,int);
void swap(member *,member *);
void merge(member *,int,int,int);
void mergeSort(member *,int,int);
int main(){
  int i,n,flag=0;
  member *A,*B;
  scanf("%d",&n);
  A = (member *)malloc(n * sizeof(member));
  B = (member *)malloc(n * sizeof(member));
  
  for(i=0;i<n;i++){
    scanf(" %c",&A[i].c);
    scanf("%d",&A[i].n);
  }
  for(i=0;i<n;i++){
    B[i].c=A[i].c;
    B[i].n=A[i].n;
  }
  
  quickSort(A,0,n-1);
  mergeSort(B,0,n);
  

  for(i=0;i<n;i++){
    if(!(A[i].c==B[i].c && A[i].n==B[i].n)){
      flag = 1;
      break;
    }
  }


  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].n);
  }
  free(A);
  free(B);

  return 0;
}

void quickSort(member *A,int p,int r){
  int q;
  if(p < r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}
int partition(member *A,int p,int r){
  int i,j;
  member x;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].n <= x.n){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

void swap(member *x,member *y){
  member r;
  r=*x;
  *x=*y;
  *y=r;
}


void merge(member *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  member *L,*R;
  static int count;
  n1 = mid - left;
  n2 = right - mid;
  L = (member *)malloc((n1+1) * sizeof(member));
  R = (member *)malloc((n2+1) * sizeof(member));
  for(i=0;i<n1;i++){
    L[i].n=A[left+i].n;
    L[i].c=A[left+i].c;
  }
  for(i=0;i<n2;i++){
    R[i].n=A[mid+i].n;
    R[i].c=A[mid+i].c;
  }
  L[n1].n=2147483647;
  R[n2].n=2147483647;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i].n<=R[j].n){
      A[k].n=L[i].n;
      A[k].c=L[i].c;
      i++;
    }
    else{
      A[k].n=R[j].n;
      A[k].c=R[j].c;
      j++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(member *A,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <string> 
#include <set> 
#include <map>
#include <algorithm>
#include <bits/stdc++.h> 
using namespace std;
void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 
int main()
{
     string s;
     cin >> s;
     
     int n = s.size();
     string take;
     string take2;
     string rev = s;
     reverse(s.begin(), s.end());
     
     if(rev == s) {
     	take = s.substr(0, (n - 1) / 2);
     
     	
     	int mid = (n + 3) / 2;
     	
     	take2 = s.substr(mid - 1, n);
     
     	string rev1 = take;
     	reverse(take.begin(), take.end());
     	string rev2 = take2;
     	reverse(take2.begin(), take2.end());
     	if(take == rev1 && take2 == rev2) {
     		cout << "Yes" << "\n";
     		return 0;
     	} else {
     		cout << "No" << "\n";
     		return 0;
     	}
     } else {
     	cout << "No" << "\n";
     	return 0;
     }
     
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL q, h, s, d;
LL n;
LL one,two,four,eight,ans;
int main () {
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	n <<= 2;
	one = q;
	two = min(h, one * 2);
	four = min(s, two * 2);
	eight = min(d, four * 2);
	ans += ( n>>3 ) * eight;
	n %= 8,ans += ( n>>2 ) * four;
	n %= 4,ans += ( n>>1 ) * two;
	n %= 2,ans += n * one;
	printf("%lld\n",ans);
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if(b<=c || d<=a) cout << 0 << endl;
  else{
    cout << min(b,d) - max(a,c) << endl;

  }

  return 0;

}


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

// definition of BubbleSort
void Bubble_sort(vector<string> &a, int b){
    for(int i = 0; i < b; i++){
        for(int j = b - 1; j > i; j--){
            if(a[j][1] < a[j - 1][1])
            swap(a[j],a[j - 1]);
        }
    }
    for(int i = 0; i < b; i++){
        if( i < b - 1)
        cout << a[i] << " ";
        if(i == b - 1)
        cout << a[i] << endl;
    }
     cout << "Stable" << endl;
}

// definition of SelectionSort
void Selection_sort(vector<string> &d,vector<string> &f,int e){
    bool ans2 = true;
        for(int i = 0; i < e; i++){
            int minj = i;
            for(int j = i; j < e; j++){
                if(d[j][1] < d[minj][1]){
                    minj = j;
                }
            }
                if(minj != i)
                swap(d[i],d[minj]);
            
        }  
        for(int i = 0; i < e; i++){
            if(i < e- 1)
            cout << d[i] << " ";
            if(i  == e - 1)
            cout << d[i] << endl; 
            if(d[i] != f[i])
            ans2 = false;          
}
if(ans2) cout << "Stable" << endl;
else
{
    cout << "Not stable" << endl;
}
}
int main(){
    int N;
    bool ans = true;
    cin >> N;
    vector<string> C(N),C2(N);
    for(int i = 0; i < N; i++){
        cin >> C[i];
        C2[i] = C[i];
    }
  Bubble_sort(C,N);
  Selection_sort(C2,C,N);
}


Measured memory_bytes: 3212
using System;

namespace _153232
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int a = 0;
            for(int i = 0; i < 3; i++)
            {
                if (S[i] == T[i]) { a++; }
            }
            Console.WriteLine(a);
        }
    }
}

Measured memory_bytes: 11092
import numpy as np
n, m, q = map(int, input().split())
train = np.zeros((n, n), dtype=int)
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    train[l][r] += 1

# 累積和
for i in range(n):
    np.add.accumulate(train[i], out=train[i])
np.add.accumulate(train, out=train)
train=train.tolist()

ans = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    a = train[y][y]
    if x != 0:
        a -= train[x-1][y]
    ans.append(a)

print(*ans, sep="\n")


Measured memory_bytes: 27792
#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;
  cin >> n;

  int h[n+1];
  for (int i = 1; i <= n; i++) cin >> h[i];

  int max_count = 0;
  int count = 0;
  for (int i = n ; i > 1 ; i--) {
      if (h[i] <= h[i-1]) {
        count++;
        max_count = max(max_count, count);
      } else {
        count = 0;
      }
  }
  cout << max_count;


  return 0;
}

Measured memory_bytes: 640
// atcoder/diverta2019/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<string> v(n);
    cin >> v;

    lli cnt = 0;
    each (s, v) {
      for (int i = 0; i + 1 < s.size(); ++i) {
        cnt += (s[i] == 'A' && s[i + 1] == 'B');
      }
      s = string("") + s.front() + s.back();
    }

    int BA = 0;
    int _A = 0;
    int B_ = 0;
    each (s, v) {
      if (s == "BA") ++BA;
      else {
        B_ += (s[0] == 'B');
        _A += (s[1] == 'A');
      }
    }

    int x = min(BA, B_);
    cnt += x;
    BA -= x;

    int y = min(_A, BA);
    cnt += y;
    BA -= y;

    cnt += min(_A, B_);
    if (x || y) {
      cnt += BA;
    } else {
      cnt += max(0, BA - 1);
    }

    cout << cnt << endl;
  }

  return 0;
}


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	int d = 0,e = 0,f = 0;
	int ok = 0;
	while(true){
		if(ok == 0){
			if(d == a.size()){
				cout << 'A' << endl;
				break;
			}

			if(a[d] == 'b')ok = 1;
			else if(a[d] == 'c')ok = 2;

			d++;
		}
		else if(ok == 1){
			if(e == b.size()){
				cout << 'B' << endl;
				break;
			}

			if(b[e] == 'a')ok = 0;
			else if(b[e] == 'c')ok = 2;

			e++;
		}
		else{
			if(f == c.size()){
				cout << 'C' << endl;
				break;
			}
			
			if(c[f] == 'a')ok = 0;
			else if(c[f] == 'b')ok = 1;

			f++;
		}
	}
	return 0; 
}

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> M(N);
  for (int i = 0; i < N; i++){
    cin >> M.at(i);
    X -= M.at(i);
  }
  //cout << "#" << X << "#" << endl;
  sort(M.begin(), M.end());
  //cout << "#" << M.at(1) << endl;
  int Y = X / M.at(0);
  cout << N + Y << endl;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,ans=0,mina=1000000,a;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a;
		if(a<=mina){
			ans++;
		}
		mina = min(mina,a);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let N = get!(i64);
    let (S, P): (Vec<_>, Vec<_>) = get!(String, i64; N).into_iter().unzip();

    let mut iSP = (1..(N + 1))
        .zip(S.iter().zip(P.iter()))
        .collect::<Vec<_>>();
    iSP.sort_by_key(|&(_, (s, p))| (s, -p));

    // 出力
    for (i, _) in iSP {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define px(x) cout << x << endl
#define pfi(x) printf("%d\n", x)
#define pfs(x) printf("%s\n", x)
#define sfi(x) scanf("%d", &x)
#define sfs(x) scanf("%s", x)




int main(int argc, char const *argv[])
{   
   
    int n;
    cin >> n;
        
    string s;
    int t;
    int sum = 0;
    vector<pair<string,int>> vec;


    for(int i=0; i<n; i++){
        cin >> s >> t;
        vec.pb(mp(s,t));
        sum += t;
    }

    string x;
    cin >> x;
    int len = vec.size();
    int nsum = 0;

    for(int i=0; i<len; i++){
        if(vec[i].first == x){
            nsum += vec[i].second;
            break;
        }else{
            nsum += vec[i].second;
            //cout << nsum << " " << endl;
        }
    }

    cout << sum-nsum << endl;
























    return 0;
}

Measured memory_bytes: 256