akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
using namespace std;

bool check(multimap<int, int> m);

int main(){
    int n;
    while(cin >>n){
        if(n == 0) break;
        multimap<int, int> m;
        for(int i = 0; i < n; i++){
            int w, limit;
            cin >>w >>limit;
            m.insert( multimap<int, int>::value_type(limit, w) );
        }
        if(check(m)){
            cout <<"Yes";
        } else{
            cout <<"No";
        }
        cout <<endl;
    }
    return 0;
}

bool check(multimap<int, int> m){
    int sum = 0;
    for(multimap<int, int>::iterator it = m.begin(); it != m.end(); it++){
        sum += (*it).second;
        if(sum > (*it).first){
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 0
#include<stdio.h>
#define N 10000
#define Q 500

int search(int);
int S[N];
int n;

int main(){
  int q,T[N],i,j,x,count=0;
  scanf("%d",&n);
  for(i = 0; i< n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++){
    x = search(T[i]);
    if(x >= 0 && x < n ){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

int search(int key){
  int i = 0;
  S[n] = key;
  while(S[i] != key){
    i++;
    if(i ==n){
      return n;
    }
  }
  return i;
}


Measured memory_bytes: 2140
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int NN = H * W;
		int[] row = new int[NN];
		int[] col = new int[NN];
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				row[A[i][j]] = i;
				col[A[i][j]] = j;
			}
		}
		
		int[] sum = new int[NN];
		for(int i=0;i + D<NN;i++){
			sum[i + D] = sum[i] + Math.Abs(col[i] - col[i + D]) + Math.Abs(row[i] - row[i + D]);
		}
		
		List<int> ans = new List<int>();
		for(int i=0;i<Q;i++){
			ans.Add(sum[R[i]] - sum[L[i]]);
		}
		
		Console.WriteLine(String.Join("\n",ans));
		
		
	}
	
	
	
	
	int H,W,D;
	int[][] A;
	int Q;
	int[] L,R;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1]; D = d[2];
		A = new int[H][];
		for(int i=0;i<H;i++) {
			A[i] = ria();
			for(int j=0;j<W;j++) A[i][j]--;
		}
		
		Q = ri();
		L = new int[Q]; R = new int[Q];
		for(int i=0;i<Q;i++){
			d = ria();
			L[i] = d[0] - 1; R[i] = d[1] - 1;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

N = int(input())
A = [int(i) for i in input().split()]
MOD = 10**9 + 7
answer = 1
color = [0]*3

# answer *= A[i]における分岐の数
for i in A:
    answer = (answer * color.count(i)) % MOD
    for j,x in enumerate(color):
        if x == i:
            color[j] += 1
            break

print(answer)

Measured memory_bytes: 13756
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	int n = N * N;
	vector<vector<int>> A(N, vector<int>(N - 1));
	vector<vector<int>> g(n);
	vector<int> indeg(n, 0);
	auto id = [&](int a, int b) -> int {
		return min(a, b) * N + max(a, b);
	};
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			cin >> A[i][j];
			--A[i][j];
			if (j > 0) {
				g[id(i, A[i][j - 1])].push_back(id(i, A[i][j]));
				++indeg[id(i, A[i][j])];
			}
		}
	}

	queue<int> que;
	vector<int> cost(n, -1);
	for (int i = 0; i < n; ++i) {
		if (indeg[i] > 0) { continue; }
		que.push(i);
		cost[i] = 1;
	}

	while (!que.empty()) {
		auto u = que.front(); que.pop();
		for (auto v : g[u]) {
			--indeg[v];
			cost[v] = max(cost[v], cost[u] + 1);
			if (indeg[v] == 0) {
				que.push(v);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (indeg[i] > 0) {
			ans = -1;
			break;
		}
		ans = max(ans, cost[i]);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 55984
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	int A, B;
	cin >> A >> B;
	int count = 0, num = 1;
	while (true) {
		if (num >= B) {
			cout << count;
			return 0;
		}
		num += A - 1;
		count++;
	}
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll N,K;
  cin>>N>>K;
  vector<ll>A(N),F(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cin>>F[i];
  sort(rng(A));
  sort(rng(F));
  reverse(rng(F));
  ll l=-1;
  ll r=pow(10,12);
  ll m;
  while(r-l>1){
    m=(l+r)/2;
    ll c=0;
    for(int i=0;i<N;i++){
      if(A[i]*F[i]>m){
        c+=(A[i]*F[i]-m+F[i]-1)/F[i];
      }
      if(c>K)break;
    }
    if(c>K)l=m;
    else r=m;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas{
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx,maxy;
public:
    ContainChecker(Int minx,Int miny,Int maxx, Int maxy) : minx(minx) , miny(miny) , maxx(maxx), maxy(maxy) {};
    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n, m;
    cin >> n >> m;
    vector<Int> dp(n+1);
    vector<Int> a(n+1);
    REP(m,i){
        Int x;
        cin >> x;
        a.at(x) = 1;
    }
    dp[0] = 1;
    REP(n,i){
        if (a[i] == 0) {
            if (i + 1 <= n) {
                dp[i+1] = (dp[i+1] + dp[i]) % MOD;
            }
            if (i + 2 <= n){
                dp[i+2] = (dp[i+2] + dp[i]) % MOD;
            }
        }
    }
    cout << dp[n] << endl;
}




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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int n,x,y,a[12],b[12],mark[10],temp[12];
bool paichi;

void find_a(int cur)
{
    int i;
    if(paichi)return;
    if(cur > n)
    {
        for(i=1;i<=n;i++)
        {
            if(a[i] != temp[i])
            {
                ++x;
                return;
            }
        }
        paichi=true;
        ++x;
        return;
    }
    for(i=1;i<=n;i++)
    {
        if(mark[i] == 0)
        {
            temp[cur]=i;
            mark[i]=1;
            find_a(cur+1);
            mark[i]=0;
        }
    }
}

void find_b(int cur)
{
    int i;
    if(paichi)return;
    if(cur > n)
    {
        for(i=1;i<=n;i++)
        {
            if(b[i] != temp[i])
            {
                ++y;
                return;
            }
        }
        paichi=true;
        ++y;
        return;
    }
    for(i=1;i<=n;i++)
    {
        if(mark[i] == 0)
        {
            temp[cur]=i;
            mark[i]=1;
            find_b(cur+1);
            mark[i]=0;
        }
    }
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i;
    cin >> n;
    for(i=1;i<=n;i++)cin >> a[i];
    for(i=1;i<=n;i++)cin >> b[i];
    paichi=false;
    find_a(1);
    memset(mark,0,sizeof(mark));
    paichi=false;
    find_b(1);
    cout << abs(x-y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int K, X;
  cin >> K >> X;
  for (int i = X-K+1; i <= X+K-1; ++i) {
    cout << i;
    if (i != X+K-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
n=int(input())
i=0
while(1):
    if n==1:
        break
    n//=2
    i+=1
i=bin(i+1)[2:]
ans=1
mkr=2
for j in i[::-1]:
    if j=="1":
        ans*=mkr
    mkr*=mkr
print(ans-1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
int main(void){
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    
    double S = H * W / 2;
    int ans = 0;
    if(x*2 == W && y*2 == H){
        ans++;
    }
    
    cout << fixed << setprecision(10) << S << " " << ans << endl;
}


Measured memory_bytes: 3236
from heapq import heappush, heappop

# input
X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_list.sort(reverse = True)
b_list.sort(reverse = True)
c_list.sort(reverse = True)

#solve
hq = []
arg_hash = {}
val = a_list[0] + b_list[0] + c_list[0]
heappush(hq, (-val,0,0,0))

for i in range(K):
    ans, a, b, c = heappop(hq)
    print(-ans)

    arg_a = (a+1, b, c)
    arg_b = (a, b+1, c)
    arg_c = (a, b, c+1)

    if a < X-1 and arg_a not in arg_hash:
        arg_hash[arg_a] = 1
        heappush(hq, (-(a_list[a+1]+b_list[b]+c_list[c]),)+arg_a)
    if b < Y-1 and arg_b not in arg_hash:
        arg_hash[arg_b] = 1
        heappush(hq, (-(a_list[a]+b_list[b+1]+c_list[c]),)+arg_b)
    if c < Z-1 and arg_c not in arg_hash:
        arg_hash[arg_c] = 1
        heappush(hq, (-(a_list[a]+b_list[b]+c_list[c+1]),)+arg_c)

Measured memory_bytes: 4764
/*
    Author      : Dinesh Verra
    College     : ABV-IIITM
    Date        : 21/08/2020
*/
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
using namespace std;
typedef long long ll;
// #define ll int
typedef unsigned long long ull;
#define cu continue
#define br break
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define inf INT_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define vpll vector <pll>
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define all(v) v.begin(),v.end()
#define nl cout<<'\n'

template <typename A1>
void prn(A1&& arg)
{
	cout<<arg<<'\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args)
{
	cout<<arg<<' ';
	prn(args...);
}

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


	ll n;
	cin>>n;
	ll a[n],mn=inf;
	for(ll i=0;i<n;i++)
		cin>>a[i];
	mn=a[0];
	ll ans=0;
	for(ll i=1;i<n;i++)
	{
		if(a[i]<=mn)
		{
			ans+=(mn-a[i]);
		}
		else
		{
			mn=a[i];
		}
	}
	prn(ans);
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int S, W;
    cin >> S >> W;
    std::cout << (S <= W ? "unsafe" : "safe") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int x1, y1, x2, y2, x3, y3, x4, y4;
	
	cin >> x1 >> y1 >> x2 >> y2;
	
	int x = x2 - x1, y = y2 - y1;
	
	x3 = x2 - y;
	y3 = y2 + x;
	x4 = x1 - y;
	y4 = y1 + x;
	
	cout << x3 << " " << y3 << " " << x4 << " " << y4;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long int n,ans=0,i,j,k;
    cin>>n;
    long long int a[n+1][n+1];
    bool p[n+1][n+1];
    memset(p,0,sizeof(p));
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    for(k=1;k<=n;k++)      
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j++){
                if(k!=j&&k!=i&&i!=j){
                    if(a[i][j]==a[i][k]+a[k][j])
                        p[i][j]=1;
                    if(a[i][j]>a[i][k]+a[k][j]){
                        cout<<"-1"<<endl;
                        return 0;
                    }
                }
            }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(p[i][j]==0)
                ans+=a[i][j];
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
from itertools import product
n_str = input()
n = int(n_str)
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(["3", "5", "7"], repeat=i)):
        temp_set = set(temp)
        if "3" in temp_set and "5" in temp_set and "7" in temp_set and int("".join(temp)) <= n:
            ans += 1
print(ans)

Measured memory_bytes: 11528
//Date of submission: 14-06-2020

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e9 + 5;
const double E= 1e-9;

//------------------------------------------------------------------------------

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a[6];
    for(ll i=1; i<=5; i++)
    {
        cin>>a[i];
        
    }   
    for(ll i=1; i<=5; i++)
    {
        if(a[i]==0)
        {
            cout<<i;
            break;
        }
    }
    return 0;
}

//------------------------------------------------------------------------------


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

void rect(int n,int m){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if((i+j)%2==0)cout << '#';
            else cout << '.';
        }
        puts("");
    }
}

int main(){
    int n,m;
    
    while(true){
        cin >> n >> m;
        if(!n&&!m) break;
        rect(n,m);
        puts("");
    }
    
    
    return 0;
}

Measured memory_bytes: 1124
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = b[a[0]-1]

for i in range(1, n):
  ans += b[a[i]-1]
  if a[i] - a[i-1] == 1:
    ans += c[a[i-1]-1]

print(ans)

Measured memory_bytes: 3064
#文字列の入力
S = input()
#文字列の入力
T = input()

S_list = list(S)
T_list = list(T)
count = 0
for i in range(len(S_list)):
  if(S_list[i] == T_list[i]):
    count = count + 1
  
if(count == len(S_list)):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 9044
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; i++) {
        if (str[s[i]] != (char)(c[i] + '0')) return false; 
    }
    return true;
}

int main() {
    cin >> N >> M;
    s.resize(M); c.resize(M);
    for (int i = 0; i < M; i++) { cin >> s[i] >> c[i]; s[i]--; }
    for (int i = 0; i <= 999; i++) {
        stringstream s; s << i;
        string str = s.str();
        if (ok(str)) { cout << str << endl; return 0; }
    }
    puts("-1");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int j;
	
	for (i = 1; i <= 9; i++){
		for (j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
	return (0);
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,n,x) for(int i=0;i<n;i+=x)
#define pb push_back
#define ff first
#define ss second 

int main(){	
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  	int n;
  	cin>>n;
  	ll sum=0;
  	int a[n],mn=1e9+5;
  	for(int i=0;i<n;i++)
  	cin>>a[i];
  	sort(a,a+n);
  	int c=2;
  	sum=a[n-1];
  	for(int i=n-2;i>=0;i--)
  	{
  	
  			if((n-c)>2)
  			sum+=2*a[i],c+=2;
  			else
  			{
  				if((n-c)==1)
  				sum+=a[i];
  				else
  				if((n-c)==2)
  				sum+=a[i]*2;
  				break;
			}
			//cout<<c<<" "<<sum<<endl;
	}
  	cout<<sum;
  	
}


Measured memory_bytes: 4432
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
ns = [[] for _ in range(n)]
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
seen = [None]*n
ans = -1
for start in range(n):
    if seen[start]:
        continue
    s = [start]
    seen[start] = True
    val = 0
    while s:
        u = s.pop()
        val += 1
        for v in ns[u]:
            if not seen[v]:
                s.append(v)
                seen[v] = True
    ans = max(ans, val)
print(ans)

Measured memory_bytes: 108180
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<iterator>
using namespace std;

void vp(vector<string> x,int a){
    for(int i=0;i<a-1;i++){
        printf("%s ",x[i].c_str());
    }
    printf("%s\n",x[a-1].c_str());
}

int main(){
    int n;
    string t="Stable", f="Not stable";
    vector<string> str, bub, sel;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        char s[2];
        scanf("%s",&s);
        str.push_back(s);
    }
    copy(str.begin(), str.end(), back_inserter(bub));
    copy(str.begin(), str.end(), back_inserter(sel));
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(bub[j].substr(1)<bub[j-1].substr(1)){
                swap(bub[j],bub[j-1]);
            }
        }
    }

    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(sel[j].substr(1)<sel[minj].substr(1)){
                minj=j;
            }
        }
        swap(sel[i],sel[minj]);
    }
    vp(bub,n);
    printf("%s\n",t.c_str());

    vp(sel,n);
    if(equal(bub.cbegin(),bub.cend(),sel.cbegin())){
        printf("%s\n",t.c_str());
    }else{
        printf("%s\n",f.c_str());
    }
    return 0;
}

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

using namespace std;

int solve(vector<vector<int>>& arr) {
	int n = arr.size();
  	
  	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = arr[0][0];
  	dp[0][1] = arr[0][1];
  	dp[0][2] = arr[0][2];
  	
  	for(int i=1;i<n;i++){
      	dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0];
      	dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + arr[i][1];
      	dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[i][2];
    }

  	return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


int main() {
	int n;
  	cin>>n;
  	vector<vector<int>> arr(n, vector<int>(3));
  	for(int i=0;i<n;i++) {
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
  	cout<<solve(arr);
	return 0;
}





Measured memory_bytes: 11136
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

typedef long long ll;
using namespace std;

int dx[] = {1, 0 ,-1, 0};
int dy[] = {0, 1, 0, -1};
bool dfs(char c, int i, int j, int h, int w, vector<vector<char> > &a){
	if(a[i][j] == c) return true;
	if(a[i][j] != '.') return false;
	a[i][j] = 'Z';
	
	bool res = false;
	for(int k=0;k<4;k++){
		int ny = i+dy[k], nx = j+dx[k];
		if(0 <= nx && nx < w && 0 <= ny && ny < h){
			if(a[ny][nx] != 'Z') res |= dfs(c, ny, nx, h, w, a);
		}
	}
	return res;
}

bool solve(){
	int w, h;
	cin>> w>> h;
	if(w==0 && h==0) return false;
	
	vector<vector<char> > in(h, vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>> in[i][j];
		}
	}
	
	int ansb = 0, answ = 0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(in[i][j] == '.'){
				vector<vector<char> > a;
				a = in;
				bool bb = dfs('B', i, j, h, w, a);
				a = in;
				bool ww = dfs('W', i, j, h, w, a);
				if(bb && !ww) ansb++;
				if(!bb && ww) answ++;
			}
		}
	}
	
	cout<< ansb<< " "<< answ<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);

	while(solve());

	return 0;
}

 

Measured memory_bytes: 1428
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k
ai bi

n a b 10^5
k b1+...+bn

*** use ll!!! ***
 */
typedef pair<int,int> P;
int n;
ll k;
P ps[100000];

int main(){
  cin>>n>>k;
  
  REP(i,n){
    int a,b;
    cin>>a>>b;
    ps[i] = P(a,b);
  }

  sort(ps, ps+n);

  int i;
  ll cnt=0;  
  for(i=0; i<n; i++){
    cnt += ps[i].second;
    if(cnt >= k){
      cout<<ps[i].first<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int r;
  cin>>r;
  cout<<3*r*r<<endl;
  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  bool h = true;

  if (T.size()-S.size() == 1){
    rep(i, S.size()) {
      if(S[i] != T[i]) h =false;
    }
  }
  else h =false;

  if(h) cout << "Yes" << endl;
  else   cout << "No" << endl;
}


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

rank = [0]*(n+1)
for i in range(1, n+1):
    rank[a[i-1]] = i

ans = ""
for r in rank[1:]:
    if ans != "":
        ans += " "
    ans += str(r)

print(ans)


Measured memory_bytes: 14008
#include <iostream>
#include <vector>
#include <bitset>
#include <numeric>

int solve(int N, const std::vector<int> &A)
{
	static std::bitset<4000001> bits;
	bits[0] = true;
	for (int a : A) { bits |= (bits << a); }
	int sum = std::accumulate(A.begin(), A.end(), 0);
	for (int i = (sum + 1) / 2; true; ++i)
	{
		if (bits[i]) { return i; }
	}
}

int main()
{
	int N;
	std::cin >> N;
	static std::vector<int> A(N);
	for (int i = 0; i < N; ++i) { std::cin >> A[i]; }
	std::cout << solve(N, A);
	return 0;
}


Measured memory_bytes: 1792
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc :: VU.Vector Int -> VU.Vector Int
calc as = do
  let n = VU.length as
  let base = VU.generate (n + 1) (\x -> 0)
  let ds = VU.imap (\i a -> (max 0 $ i - a, 1)) as VU.++ VU.imap (\i a -> (min n $ i + a + 1, -1)) as
  VU.postscanl' (+) 0 (VU.init (VU.accumulate (+) base ds))

judge :: VU.Vector Int -> Int -> Int -> VU.Vector Int
judge as n 0 = as
judge as n k
  | VU.all (== n) as = as
  | otherwise = judge (calc as) n (k -1)

main = do
  [n, k] <- getIntList
  as <- getIntList
  let as' = VU.fromList as
  let as'' = judge as' n k
  mapM_ putStr (map (\x -> show x ++ " ") (VU.toList as''))


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

typedef long long LL;

const int N=1000,M=5000,INF=(1<<30)-1;

int n,x[N+9];
struct side{
  int y,next;
}e[N+9];
int lin[N+9],cs;

void Ins(int x,int y){e[++cs].y=y;e[cs].next=lin[x];lin[x]=cs;}

void into(){
  scanf("%d",&n);
  for (int i=2;i<=n;++i){
  	int x;
  	scanf("%d",&x);
  	Ins(x,i);
  }
  for (int i=1;i<=n;++i)
    scanf("%d",&x[i]);
}

int dp[N+9],dp0[M+9];

void Dfs_dp(int k,int fa){
  for (int i=lin[k];i;i=e[i].next)
    if (e[i].y^fa) Dfs_dp(e[i].y,k);
  dp[k]=INF;
  for (int i=0;i<=x[k];++i) dp0[i]=INF;
  dp0[0]=0;
  for (int i=lin[k];i;i=e[i].next)
    if (e[i].y^fa)
	  for (int j=x[k];j>=0;--j){
	  	int t=INF;
	  	if (j>=x[e[i].y]) t=min(t,dp0[j-x[e[i].y]]+dp[e[i].y]);
	  	if (j>=dp[e[i].y]) t=min(t,dp0[j-dp[e[i].y]]+x[e[i].y]);
	  	dp0[j]=t;
      }
  for (int i=0;i<=x[k];++i) dp[k]=min(dp[k],dp0[i]);
}

void work(){
  Dfs_dp(1,0);
}

void outo(){
  puts(dp[1]==INF?"IMPOSSIBLE":"POSSIBLE");
}

int main(){
  into();
  work();
  outo();
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// Udhar kya dekh rha h idhar dekh le
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string s;
	cin >> s;
	int ans = 0 ;
	for (int i = 0; i < s.length(); i++) {
		ans = (ans * 10 + (s[i] - '0') % 9) % 9;
	}
	if (ans == 0) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 3772
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    int n;
    cin >> n;
    ll a[n],b[n];
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    ll cnt=0;
    for(int i=n-1; i>=0; i--){
        a[i]+=cnt;
        if(a[i] % b[i]){
            if(a[i]/b[i]){
                cnt+=b[i]-a[i]%b[i];
            }else{
                cnt+=b[i]-a[i];
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

 class Main {
	static int ar[][];
	static int nodes;
	static String color[];
	static int lastCount;
	static int parent[];
	static int breaker;
	static String ans="";
	static void doDfs(int i)
	{
		int source = i;
		color[source] = "grey";
		for(int ii = 0; ii<nodes; ii++)
		{
			if(ar[i][ii]==1)
			{
				if(color[ii]=="grey")
				{
					lastCount = ii;
					breaker = 1;
					parent[ii] = source;
					break;
				}
				else if(color[ii]=="white")
				{
					parent[ii] = source;
					doDfs(ii);
				}
			}
		}
		color[source] = "black";
		
	}
	static void printPath(int a)
	{
		int source = parent[a];
		if(source==lastCount)
		{
			System.out.println(ans+lastCount);
		}
		else
		{
			ans = ans+source+" ";
			//System.out.println("Inside");
			printPath(source);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		nodes = sc.nextInt();
		int edges = sc.nextInt();
		ar =new int[nodes][nodes];
		for(int i = 0; i<edges; i++)
		{
			int a = sc.nextInt();
			int b = sc.nextInt();
			ar[a][b] = 1;
		}
		color=new String[nodes];
		parent = new int[nodes];
		for(int i =0; i<color.length; i++)
		{
			color[i] = "white";
		}
		for(int i = 0; i<color.length; i++)
		{
			if(color[i]=="white")
			{
				doDfs(i);
				if(breaker ==1)
				{
					break;
				}
			}
		}
		if(breaker==1)
		{
			System.out.println("1");
			//printPath(lastCount);
		}
		else
		{
			System.out.println("0");
		}
		

	}

}



Measured memory_bytes: 31664
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define pii pair<int,int>
#define prec(n) fixed<<setprecision(n)
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n;cin>>n;
    vector<string> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        sort(all(v[i]));
    }
    sort(all(v));
    int ans=0;
    for(int i=0;i<n-1;i++){
        int cnt=1;
        while(i+1<n && v[i]==v[i+1]){
            cnt++;
            i++;
        }
        ans+=(cnt*(cnt-1)/2);
    }
    cout<<ans;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=5030;
const ll inf=1e9+800;
const ll mod=1e9+7;

ll tav[maxn];
map<pii,ll> ml;

ll f(ll n,ll k){
    if(n<0)return 0;
    if(k==0){
        return min(2,n)+1;
    }
    if((1LL<<k)<=(n+1)/4){
        return tav[k+1];
    }
    if(ml.count(mp(n,k))){
        return ml[mp(n,k)];
    }
    ll ans=0;
    ans+=f(n,k-1);
    ans+=f(n-(1LL<<k),k-1);
    ans+=f(n-(2LL<<k),k-1);
    ans%=mod;
    ml[mp(n,k)]=ans;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);    
    tav[0]=1;
    for(ll i=1;i<maxn;i++){
        tav[i]=(tav[i-1]*3)%mod;
    }
    ll n;
    cin>>n;
    cout<<f(n,60);
}
































Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var points = createLongTuppleList(N);

			if (N==1) {
				Console.WriteLine(1);
				return;
			}

			var gaps = new Dictionary<string, long>();
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					if (i==j) {
						continue;
					}
					var gx = points[i].Item1 - points[j].Item1;
					var gy = points[i].Item2 - points[j].Item2;
					var gap = gx + "_" + gy;

					if (gaps.ContainsKey(gap)) {
						gaps[gap]++;
					}
					else {
						gaps.Add(gap, 1);
					}

				}
			}
			//答えの出力
			var ans = N-gaps.Select(x=>x.Value).Max();
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


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

using namespace std;
const double  eps  = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
//点p和多边形的关系
int jud(vector<Point> G,Point p){
    int n = G.size();
    bool x=0;
    for(int i=0;i<n;i++){
        Point a=G[i]-p,b=G[(i+1)%n]-p;
        if(abs(cross(a,b))<eps && dot(a,b)<eps) return 1;
        if(a.y>b.y) swap(a,b);
        if(a.y<eps&&eps<b.y&&cross(a,b)>eps) x=!x;
    }
    return (x?2:0);
}
vector<Point> Polygon;
int main(){
    int n;
    scanf("%d",&n);
    double x,y;
    for(int i=0;i<n;i++){
        scanf("%lf %lf",&x,&y);
        Polygon.push_back({x,y});
    }
    int q;
    Point que;
    scanf("%d",&q);
    while(q--){
        scanf("%lf %lf",&que.x,&que.y);
        int ans=jud(Polygon,que);
        // cout<<(int)Polygon.size()<<endl;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3236
n=int(input())
a=list(map(int,input().split()))
d=[0]
for i in range(1,n+1):
  d.append(a[i-1]*2-d[-1])
t=d[-1]/2
d=[t]
for i in range(1,n+1):
  d.append(a[i-1]*2-d[-1])
print(" ".join(map(lambda x:str(int(x)),d[:-1])))


Measured memory_bytes: 108692
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    string s;
    cin>>n>>s;
    if(n%2){
        cout<<"No";
        exit(0);
    }
    for(ll i=0;i<n/2;i++)
    if(s[i]!=s[i+n/2]){
        cout<<"No";
        exit(0);
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int x, y;
	scanf("%d %d", &x, &y);
	while (x != 0 || y != 0) {
		if (x > y) {
			printf("%d %d\n",y,x);
		}
		else {
			printf("%d %d\n", x, y);
		}
		scanf("%d %d", &x, &y);
	}
}



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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int x,y;
    bool a=true,b=true;
    int g[] = {4,6,9,11};
    cin >> x >> y;
    if(x == 2 || y == 2){
        cout << "No" << endl;
        return 0;
    }
    if(x == g[0] || x == g[1] || x == g[2] || x == g[3]){
        a = false;
    }
    if(y == g[0] || y == g[1] || y == g[2] || y == g[3]){
        b = false;
    }

    if(a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    int i;
    int card[4][13]={{}};
    cin >> n;
    char a;
    int b;
    for(i=0;i<n;i++) {
        cin >> a >> b;
        switch(a){
            case 'S':
                card[0][b-1]=1;
                break;
            case 'H':
                card[1][b-1]=1;
                break;
            case 'C':
                card[2][b-1]=1;
                break;
            case 'D':
                card[3][b-1]=1;
                break;
        }
    }
    for(i=0;i<52;i++) {
        switch(i/13){
            case 0:
                if(card[0][i%13]==0) cout << "S " << i+1 << endl;
                break;
            case 1:
                if(card[1][i%13]==0) cout << "H " << i%13+1 << endl;
                break;
            case 2:
                if(card[2][i%13]==0) cout << "C " << i%13+1 << endl;
                break;
            case 3:
                if(card[3][i%13]==0) cout << "D " << i%13+1 << endl;
                break;
        }
    }

    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int t=max(a,c),q=min(b,d);
    if(t<=q){
        cout << min(b,d)-max(a,c) << endl;
    }
    else cout << 0 << endl;



    return 0;
}


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


int a[100005];
int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=1;i<=q;i++)
        {
            int t;
            cin>>t;
            a[t]++;
        }
    for(int i=1;i<=n;i++)
        if(k-q+a[i]<=0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}
/*
10
16 7
15 15
12 14
2 5
3 9
1 10
14 14
4 6
*/


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}

const int MAXN = 305;
const int oo = 0x3f3f3f3f;

int N;
pr a[MAXN], b[MAXN];

struct edge {
	int y, next;
}e[MAXN * MAXN];

int LINK[MAXN], len = 0, nxt[MAXN], pre[MAXN];
bool vis[MAXN];

inline void ins(int x, int y){
	e[++len].next = LINK[x]; LINK[x] = len;
	e[len].y = y;
}

bool DFS(int node){
	Auto (i, node) if (!vis[e[i].y]) {
		vis[e[i].y] = 1;
		if (!pre[e[i].y] || DFS(pre[e[i].y])) {
			nxt[node] = e[i].y;
			pre[e[i].y] = node;
			return 1;
		}
	}
	return 0;
}

int main(){
	scanf("%d", &N);
	up (i, 1, N) scanf("%d%d", &a[i].fi, &a[i].se);
	up (i, 1, N) scanf("%d%d", &b[i].fi, &b[i].se);
	int ans = 0;
	up (i, 1, N) up (j, 1, N) if (a[i].fi < b[j].fi && a[i].se < b[j].se) 
		ins(i, j);
	up (i, 1, N) if (!nxt[i]) {
		memset(vis + 1, 0, sizeof(vis[0]) * N);
		ans += DFS(i);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

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

using namespace std;

int vx[] = {1,0,-1,0}, vy[] = {0,1,0,-1};

int main(){
	int N;
	while(cin >> N, N){
		int n, d;
		int mx[2]={}, my[2]={};
		int table[205][2] = {};
		rep(i,N-1){
			cin >> n >> d;
			table[i+1][0] = table[n][0] + vx[d];
			table[i+1][1] = table[n][1] + vy[d];
			mx[0] = min(mx[0], table[i+1][0]);
			mx[1] = max(mx[1], table[i+1][0]);
			my[0] = min(my[0], table[i+1][1]);
			my[1] = max(my[1], table[i+1][1]);
		}
		cout << mx[1] - mx[0] + 1 << " ";
		cout << my[1] - my[0] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)

{
    string s, s1;
    cin>>s;
    //cout<<s<<endl;
    if(!s.compare("Sunny")){
        s1 =  "Cloudy";
    }
    else if(!s.compare("Cloudy")){
        s1 = "Rainy";
    }
    else
        s1 = "Sunny";
    cout<<s1<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
	int N;
	int B[100];
	cin >> N;
	rep(i, N - 1)cin >> B[i];
	B[N - 1] = B[N - 2];

	int A[100] = {};
	rep(i, N) {
		if (i == 0)
			A[0] = B[0];
		else
			A[i] = min(B[i], B[i - 1]);
	}
	int sum = 0;
	rep(i, N)sum += A[i];
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long int k, a, b;
    cin >> k >> a >> b;

    if (k + 1 > a + ((k - (a - 1))/2)*(b - a) + (k - (a - 1)) % 2){
        cout << k + 1 << endl;
    }else {
        cout << a + ((k - (a - 1))/2)*(b - a) + (k - (a - 1)) % 2 << endl;
    }
    return 0;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>d(n);
	int sum=0;
	for(int i=0; i<n; i++)cin>>d[i];
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			sum+=d[i]*d[j];
		}
	}	
	cout<<sum<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int n;
    cin>>n;

    vector<int> vec(n);
    int cur = 0;
    if(n%2 == 0){
        int f = vec.size()/2;
        int s = vec.size()/2-1;
        while(true){

            if(cur++ < n){
                cin>>vec[f++];
            }
            else{
                break;
            }

            if(cur++ < n){
                cin>>vec[s--];
            }
            else{
                break;
            }
        }

    }
    else{
        int f = vec.size()/2;
        int s = vec.size()/2+1;

        while(true){
            if(cur++ < n){
                cin>>vec[f--];
            }
            else{
                break;
            }

            if(cur++ < n){
                cin>>vec[s++];
            }
            else{
                break;
            }
        }
    }

    stringstream ss;
    for(int i = 0; i < vec.size()-1; ++i){
        ss<<vec[i]<<" ";
    }

    ss<<vec.back();

    cout<<ss.str()<<endl;

    return 0;
}

Measured memory_bytes: 7044
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int> a(n+1,0);
  rep(i,m){
    int in;cin>>in;
    a[in]++;
  }
  rep(i,n)a[i+1] += a[i];

  int ans = min(a[x],a[n]-a[x]);
  print(ans);
  return 0;
}


Measured memory_bytes: 256