akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<" "
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  1005;
const ll mod = 1e9 + 7;

using namespace std;
ll dp[N][N];

void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>m;
  char a[n+1][m+1];
  for (ll i = 1; i <=n; ++i)
  {
    fr(j,1,m+1)
  cin>>a[i][j];
  }
  dp[1][1] = 0;
  fr(i,1,n+1)
  {    if(a[1][i]!='#')
    dp[1][i] = 1;
    else break;
  }
   fr(i,1,n+1)
  {    if(a[i][1]!='#')
      dp[i][1] = 1;
    else break;
  }  
  for (int i = 2; i <= n; ++i)
  {
    fr(j,2,m+1)
    {
          if(a[i][j]!='#')
      dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
//    c(dp[i][j]);
    }
   // cout<<"\n";
  }
  
  cout<<dp[n][m]<<" ";
}

signed main(){
 
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 9088
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

struct point {
	int x, y, z;

	point(int x_, int y_, int z_):x(x_), y(y_), z(z_) {}
	point(const point &p):x(p.x), y(p.y), z(p.z) {}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y, z - p.z);
	}
};

struct segment {
	point a, b;

	segment(const point &a_, const point &b_):a(a_), b(b_) {}
	segment(const segment &s):a(s.a), b(s.b) {}
};

struct circle {
	point c;
	int r;

	circle(const point &c_, int r_):c(c_), r(r_) {}
	circle(const circle &c_):c(c_.c), r(c_.r) {}
};

int dot(const point &a, const point &b) {
	return a.x * b.x + a.y * b.y + a.z * b.z;
}

int norm(const point &p) {
	return p.x * p.x + p.y * p.y + p.z * p.z;
}

int dist2(const point &a, const point &b) {
	return norm(a - b);
}

double dist2(const segment &s, const point &p) {
	const int a = dot(s.b - s.a, s.b - s.a);
	const int b = dot(s.b - s.a, s.a - p);
	const int c = dot(s.a - p, s.a - p);
	const double t = -1.0 * b / a;
	if(t < 0) return dist2(s.a, p);
	if(t > 1) return dist2(s.b, p);
	return a * t * t + 2 * b * t + c;
}

bool intersect(const circle &c, const point &p) {
	return dist2(c.c, p) <= c.r * c.r;
}

bool intersect(const circle &c, const segment &s) {
	return dist2(s, c.c) <= c.r * c.r;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.flags(ios::fixed);
	cout.precision(5);

	for(int N, M, R; cin >> N >> M >> R && N;) {
		vector<circle> baloons;
		baloons.reserve(N);
		for(int i = 0; i < N; ++i) {
			int x, y, z, r;
			cin >> x >> y >> z >> r;
			baloons.emplace_back(point(x, y, z), r);
		}

		vector<point> sources;
		vector<int> tb(M);
		sources.reserve(M);
		for(int i = 0; i < M; ++i) {
			int x, y, z;
			cin >> x >> y >> z >> tb[i];
			sources.emplace_back(x, y, z);
		}

		int x, y, z;
		cin >> x >> y >> z;
		point e(x, y, z);

		vector<double> intensity(M);
		for(int i = 0; i < M; ++i) {
			intensity[i] = (double)tb[i] / dist2(e, sources[i]);
		}

		vector<bitset<2000>> removed(M);
		for(int i = 0; i < M; ++i) {
			const segment seg(e, sources[i]);
			for(int j = 0; j < N; ++j) {
				if(intersect(baloons[j], seg) && !(intersect(baloons[j], seg.a) && intersect(baloons[j], seg.b))) {
					removed[i].set(j);
				}
			}
		}

		double ans = 0.0;
		for(int i = 0; i < (1 << M); ++i) {
			double sum = 0.0;
			bitset<2000> bit;
			
			for(int j = 0; j < M; ++j) {
				if(i & (1 << j)) {
					bit |= removed[j];
					sum += intensity[j];
				}
			}

			if(static_cast<int>(bit.count()) <= R) chmax(ans, sum);
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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

int n, t = 0;
string s;

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

	for (int i = 0; i < n - 2; i++)
		if (s.substr(i, 3) == "ABC")
			t++;

	cout << t << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i, j, k, m, n, l, r, c = 0;
    scanf("%d", &n);
    int A[n];
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &k);
    int B[k];
    for(i = 0; i < k; i++) scanf("%d", &B[i]);
    
    for(j = 0; j < k; j++){
         l = 0;
         r = n;
    while (l < r) {
    m = (l + r) / 2;
        if (A[m] == B[j]) c++;
        if (A[m] == B[j]) break;
        if (B[j] < A[m]) r = m;
        else l = m + 1;
    }
    }
    printf("%d\n", c);
    return 0;
    }



Measured memory_bytes: 2320
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[11000];
int main(){
	scanf("%s",in);
	int p=0;
	for(int i=0;in[i];i++){
		if(in[i]=='N')p|=1;
		if(in[i]=='S')p|=2;
		if(in[i]=='W')p|=4;
		if(in[i]=='E')p|=8;
		
	}
	bool ok=true;
	if(p&3){
		if((p&3)!=3)ok=false;
	}
	if(p&12){
		if((p&12)!=12)ok=false;
	}
	if(ok)printf("Yes\n");
	else printf("No\n");
}

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

namespace AtCoderTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] fivt = new string[] { "dream", "erase" };
            string sixt = "eraser";
            string sevt = "dreamer";
            int idx = s.Length;
            bool rst = true;
            while(idx > 0)
            {
                if (idx >= 5 && fivt.Contains(s.Substring(idx - 5, 5)))
                {
                    idx -= 5;
                }
                else if(idx >= 6 && sixt == s.Substring(idx - 6, 6))
                {
                    idx -= 6;
                }
                else if (idx >= 7 && sevt == s.Substring(idx - 7, 7))
                {
                    idx -= 7; 
                }
                else
                {
                    rst = false;
                    break;
                }
            }
            string outRst = rst ? "YES" : "NO";
            Console.WriteLine(outRst);
        }
    }
}


Measured memory_bytes: 4184
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    H, W, K = MI()
    G = np.array([])
    for h in range(H):
        l = LS()
        for i in range(W):
            if l[i] == '#':
                l[i] = 1
            else:
                l[i] = 0
        G = np.append(G, l)
    G = G.reshape((H, W))

    ret = 0
    for x in product((0, 1), repeat=W):
        dX = G * x  # 列方向に 1 or 0 を掛ける
        for y in product((0, 1), repeat=H):
            s = (dX.T * y).sum()
            if s == K:
                ret += 1
    print(ret)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 27148
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]


A.sort()
B.sort()
C.sort()

import bisect
ans = 0

a2b = []
c2b = []
for b in B:
    i = N - bisect.bisect_right(C, b)

    #例えば，C＝「13344」のとき，b=3とする，n=5なので，2になってほしい
    #bisect.bisect_right(C, b)＝3になるので，c＿bisect＝N-bisect.bisect_right(B, c)

    #例えば，C＝「133344」のとき，b=3とする，n=6なので，2になってほしい
    #bisect.bisect_right(C, b)＝4になるので，c＿bisect＝N-bisect.bisect_right(B, c)=2
    
    j = bisect.bisect_left(A, b)
    #例えば，A＝「13344」のとき，b=3とする，n=5なので，1になってほしい
    #bisect.bisect_left(A, b)＝1になるので，c＿bisect＝bisect.bisect_left(A, b)
    
    
    #例えば，A＝「113344」のとき，b=3とする，n=6なので，2になってほしい
    #bisect.bisect_left(A, b)＝2になるので，c＿bisect＝bisect.bisect_left(A, b)
    ans += i*j
    #print(i,j,i*j)
print(ans)

Measured memory_bytes: 23644
import sys
K,A,B = map(int,input().split())

if (A >= B-1):
    print(K+1)
    sys.exit()
    
K2 = K
count = 1
while(K2 > 0):
    if count < A and K2 > (A-count):
        K2 -= (A-count)
        count = A
    else:
        if K2 >=2:
            nn = int(K2/2)
            K2 -= 2 * nn
            count += (B-A) * nn
            
        elif K2 == 1:
            count += 1
            K2 -= 1
        
        
print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n, i, j, marknum, number, card[4][13] = {0};
	char mark;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		scanf("%*c%c %d", &mark, &number);
		switch (mark){
		case 'S':
			marknum = 0;
			break;
		case 'H':
			marknum = 1;
			break;
		case 'C':
			marknum = 2;
			break;
		case 'D':
			marknum = 3;
			break;
		}
		card[marknum][number - 1] = 1;
	}
		
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (card[i][j] == 0) {
				switch (i) {
				case 0:
					mark = 'S';
					break;
				case 1:
					mark = 'H';
					break;
				case 2:
					mark = 'C';
					break;
				case 3:
					mark = 'D';
					break;
				}
				printf("%c %d\n", mark, j + 1);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
     
    #define MAX_K 5000
    #define MAX_Q 5000
     
    int d[MAX_K];
     
    void cnt_j(int d[], int k){
    	int n, x, m;
    	int d_moded[MAX_K];
    	int i, quo_k, rem_k;
    	long long cnt_not_j = 0;
    	long long max_a;
     
    	scanf("%d %d %d", &n, &x, &m);
     
    	max_a = x;
    	quo_k = (n-1) / k;
    	rem_k = (n-1) % k;
    	for(i=0; i<k; i++){
    		d_moded[i] = d[i] % m;
    		if(d_moded[i] == 0){
    			cnt_not_j += quo_k + (i < rem_k);
    		}
    		max_a += (long long)d_moded[i]*(quo_k + (i < rem_k));
    	}
     
    	cnt_not_j += max_a/m - x/m;
    	printf("%lld\n", n-1-cnt_not_j);
    }
     
    int main(){
    	int k, q;
    	int i;
     
    	scanf("%d %d", &k, &q);
    	for(i=0; i<k; i++){
    		scanf("%d", d+i);
    	}
    	for(i=0; i<q; i++){
    		cnt_j(d, k);
    	}
     
    	return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    LL n, k, q;
    cin >> n >> k >> q;
    vector<LL> a(n+1);
    for(int i = 0; i < q; ++i) {
        int x; cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; ++i) cout << (k-q+a[i] > 0?"Yes":"No") << "\n";
    
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
map<int,int>t;
int n,a,s;
main(){
    cin>>n;
    while(cin>>a){
        s+=t[a]*-2+1;
        t[a]=!t[a];
    }
    cout<<s<<endl;
    return 0;
}

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

using namespace std;

int maxlcs(string s1, string s2, int k)
{
	if (s1.empty() || s2.empty())
		return 0;
	vector<vector<vector<int>>> ans(s1.size() + 1, vector<vector<int>>(s2.size() + 1, vector<int>(k + 1)));
	for (int i = 0; i <= s1.size(); ++i)
		for (int j = 0; j <= s2.size(); ++j)
			for (int l = 0; l <= k; ++l)
			{
				if (i < s1.size())
					ans[i + 1][j][l] = max(ans[i + 1][j][l], ans[i][j][l]);
				if (j < s2.size())
					ans[i][j + 1][l] = max(ans[i][j + 1][l], ans[i][j][l]);
				if (l < k)
					ans[i][j][l + 1] = max(ans[i][j][l + 1], ans[i][j][l]);
				if (i < s1.size() && j < s2.size())
				{
					if (s1[i] == s2[j])
						ans[i + 1][j + 1][l] = max(ans[i + 1][j + 1][l], ans[i][j][l] + 1);
					else if (l < k)
						ans[i + 1][j + 1][l + 1] = max(ans[i + 1][j + 1][l + 1], ans[i][j][l] + 1);
				}
			}
	return ans.back().back().back();
}

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int k;
	cin >> k;
	vector<vector<vector<int>>> dp(s.size() + 1, vector<vector<int>>(s.size() + 1, vector<int>(k + 1)));
	int n = s.size();
	for (int i = 0; i < n; ++i)
		dp[i][i + 1][0] = 1;
	for (int len = 0; len <= n; ++len)
		for (int i = 0; i + len <= n; ++i)
		{
			int j = i + len;
			for (int l = 0; l <= k; ++l)
			{
				if (j < n)
					dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i][j][l]);
				if (i > 0)
					dp[i - 1][j][l] = max(dp[i - 1][j][l], dp[i][j][l]);
				if (l < k)
					dp[i][j][l + 1] = max(dp[i][j][l + 1], dp[i][j][l]);
				if (i > 0 && j < n)
				{
					if (s[i - 1] == s[j])
						dp[i - 1][j + 1][l] = max(dp[i - 1][j + 1][l], dp[i][j][l] + 2);
					else if (l < k)
						dp[i - 1][j + 1][l + 1] = max(dp[i - 1][j + 1][l + 1], dp[i][j][l] + 2);
				}
			}
		}
	cout << dp[0].back().back() << '\n';
}


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

point = 0
before = 10**10

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

print(point)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

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

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) X(N), Y(N);
    FOR(i, 0, N)
        cin >> X[i] >> Y[i];

    double ret = 0;
    FOR(i, 0, N)
        FOR(j, 0, i) {
            double dx = X[j] - X[i];
            double dy = Y[j] - Y[i];
            ret += sqrt(dx * dx + dy * dy);
        }

    ret = 2.0 / N * ret;
    cout << fixed << setprecision(7) << ret << endl;

    return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100100;
const long double PI = acos(-1);
int prime[maxn] = {};

void sieve(){
    prime[0] = prime[1] = true;
    for (int i=2; i<maxn; i++){
        if (!prime[i]){
            for(int j=i+i; j<maxn; j+=i){
                prime[j] = true;
            }
        }
    }
}
 
int main (){
    sieve();
    int n;

    cin >> n;
    while (prime[n]) n++;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  P p[100000];
  rep(i, m){
    int a, b;
    cin >> a >> b;
    p[i] = P(b, a);
  }
  sort(p, p + m);
  
  int last = -1;
  int ans = 0;
  
  rep(i, m){
    if(p[i].second > last){
      ans++;
      last = p[i].first - 1;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using lint = long long;
using pi = pair<int, int>;

const int MAXN = 205, MAXM = 205;
struct bpm{
	vector<int> gph[MAXN];
	int dis[MAXN], l[MAXN], r[MAXM], vis[MAXN];
	void clear(){ for(int i=0; i<MAXN; i++) gph[i].clear();	}
	void add_edge(int l, int r){ gph[l].push_back(r); }
	bool bfs(int n){
		queue<int> que;
		bool ok = 0;
		memset(dis, 0, sizeof(dis));
		for(int i=0; i<n; i++){
			if(l[i] == -1 && !dis[i]){
				que.push(i);
				dis[i] = 1;
			}
		}
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(auto &i : gph[x]){
				if(r[i] == -1) ok = 1;
				else if(!dis[r[i]]){
					dis[r[i]] = dis[x] + 1;
					que.push(r[i]);
				}
			}
		}
		return ok;
	}
	bool dfs(int x){
		for(auto &i : gph[x]){
			if(r[i] == -1 || (!vis[r[i]] && dis[r[i]] == dis[x] + 1 && dfs(r[i]))){
				vis[r[i]] = 1; l[x] = i; r[i] = x;
				return 1;
			}
		}
		return 0;
	}
	int match(int n){
		memset(l, -1, sizeof(l));
		memset(r, -1, sizeof(r));
		int ret = 0;
		while(bfs(n)){
			memset(vis, 0, sizeof(vis));
			for(int i=0; i<n; i++) if(l[i] == -1 && dfs(i)) ret++;
		}
		return ret;
	} 
}bpm;

int n, a[MAXN];
map<int, int> mp;

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

int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		int x; cin >> x;
		mp[x] ^= 1;
		mp[x + 1] ^= 1;
	}
	vector<int> l, r;
	for(auto &i : mp){
		if(i.second){
			if(i.first & 1) l.push_back(i.first);
			else r.push_back(i.first);
		}
	}
	for(int i=0; i<l.size(); i++){
		for(int j=0; j<r.size(); j++){
			if(isprime(abs(r[j] - l[i]))){
				bpm.add_edge(i, j);
			}
		}
	}
	int m = bpm.match(l.size());
	int ans = 1e8;
	for(int i=0; i<=m; i++){
		int ll = l.size() - i;
		int rl = r.size() - i;
		ans = min(ans, i + (ll / 2 + rl / 2) * 2 + (ll % 2) * 3);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define true 1;
#define false 0;
struct Card{
  char match;
  char value;
};

void bubble(struct Card A[],int n)
{
  struct Card t;
  int i;
  int j;
  
  for( i = 0 ; i < n ; i++ ){
    for( j = n - 1; j >= i; j-- ){
      if( A[j].value < A[j-1].value ){
        t = A[j];
	A[j] = A[j-1];
	A[j-1] = t;
      }
    }
  }
}

void select(struct Card A[], int n )
{
  struct Card t;
  int i;
  int j;
  int min=0;
  
  for( i = 0 ; i < n; i++ ){
    min = i;
    for( j = i ; j < n ; j++ ){
      if(A[j].value < A[min].value ) min = j;
    }
    t = A[i];
    A[i] = A[min];
    A[min] = t;
  }
}

void print(struct Card A[], int n)
{
  int i;
  
  for( i = 0 ; i < n ; i++ ){
    if( i > 0 )printf(" ");
    printf("%c%d",A[i].match,A[i].value);
  }
  printf("\n");
}

int stable( struct Card c1[],struct Card c2[],int n )
{
  int i;
  
  for( i = 0 ; i < n; i++ ){
    if( c1[i].match != c2[i].match )return false;
  }
  return true;
}

int main(){
  struct Card c1[100],c2[100];
  int n;
  char moji;
  int i;

  scanf("%d",&n);
  for( i = 0 ; i < n; i++ ){
    scanf(" %c%d",&c1[i].match,&c1[i].value);
  }
  for( i = 0 ; i < n ; i++ )c2[i] = c1[i];

  bubble(c1,n);
  select(c2,n);

  print(c1,n);
  printf("Stable\n");
  print(c2,n);
  if( stable(c1,c2,n)){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}
  
  



Measured memory_bytes: 2112
def main(argv)
  n = gets.chomp.to_i
  h = gets.chomp.split(' ').map(&:to_i)
  
  dp = [0] * (n + 1)
  n.times do |i|
    if h[i] > dp[i] then
      dp[i + 1] = h[i] - 1
    else
      dp[i + 1] = h[i]
    end
  end
  
  dp.shift
  
  f = true
  
  (n - 1).times do |i|
    if dp[i] > dp[i + 1] then
      f = false
      break
    end
  end
  
  puts (f ? 'Yes' : 'No')
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 10500
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

int main() {
	string str, key; cin >> str >> key;
	str += str;
	bool ans = false;
	for (int i = 0; i < str.size(); ++i) {
		bool f = true;
		for (int j = 0; j < key.size(); ++j) {
			if (i + j >= str.size()) {
				f = false;
				break;
			}
			if (str[i+j] != key[j]) {
				f = false;
				break;
			}
		}
		if (f) {
			ans = true;
			break;
		}
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
/*
int main(){
    int n;
	cin >> n;
    if(n >= 0 && n < 100){
		cout << "00" << endl;
    } else if(n >= 100 && n <= 5000){
		if((int)n/100<10){
			cout << "0" << n/100 << endl;
		} else{
			cout << n/100 << endl;
		}
    } else if(n >= 6000 && n<=30000){
		cout << (n/1000)+50 << endl;
    } else if(n >= 35000 && n<=70000){
	    cout <<  (n/1000-30)/5+80 << endl;
    } else if(n > 70000){
		cout << 89 << endl;
    }
	
    return 0;
}*/

int main(){
	int n;
	int hoge[100];
	int sum=0;
	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> hoge[i];
	}
	for(int i=0; i<n; ++i){
		for(int j=n-1; j>i ;--j){
			if(hoge[j] < hoge[j-1]){
				int tmp = hoge[j];
				hoge[j] = hoge[j-1];
				hoge[j-1] = tmp;
				++sum;
			}
		}
	}
	for(int i=0; i<n; ++i){
		if(i+1 != n)
			cout << hoge[i] << " ";
		else 
			cout << hoge[i] << endl;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
	uint64_t H;
	cin >> H;
	uint64_t m = 0;
	for(uint64_t i=0u;i<64;++i){
		if(((H >> (63 - i)) & 1u)){
			m = 63 - i;
			break;
		}
	}

	cout << (((uint64_t)1 << (m+(uint64_t)1u)) - (uint64_t)1u);
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

using llint = long long;

const int MAXN = 1e5+5;
const int MOD = 1e9+7;

vector<int> G[MAXN];
int parent[MAXN];
bool solved[MAXN][2];
int mem[MAXN][2];
int n, x, y;

void dfs1(int x, int p) {
  parent[x] = p;
  for (int i: G[x]) {
    if (i == p) continue;
    dfs1(i, x);
  }
}

int dp(int x, bool black) {
  if (G[x].size() == 0) return 1 + !black;
  if (parent[x] != -1 && G[x].size() == 1) return 1 + (black == 0);
  int &ret = mem[x][black];
  if (solved[x][black]) return ret;
  solved[x][black] = 1;

  int wh = 1;
  int bl = black == 0;
  for (int i: G[x]) {
    if (parent[x] == i) continue;
    wh = ((llint)wh * dp(i, 0)) % MOD;
    if (black == 0) bl = ((llint)bl * dp(i, 1)) % MOD;
  }

  return ret = (wh + bl) % MOD;
}


int main() {
  scanf("%d", &n);
  for (int i = 0; i < n-1; ++i) {
    scanf("%d%d", &x, &y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  dfs1(0, -1);
  printf("%d\n", dp(0, 0));
  return 0;
}


Measured memory_bytes: 14080
n=int(input())
l=list(map(int,input().split()))

# n==100
cnt=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a=l[i]
            b=l[j]
            c=l[k]
            if a==b or b==c or c==a:
                continue
            if abs(b-c)<a<b+c:
                cnt+=1
print(cnt)

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n;
    cin >> n;
    vector<tuple<string,int,int>> a;
    for(int i=1;i<=n;i++){
        string s;
        int p;
        cin >> s >> p;
        p=-p;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        cout << get<2>(a[i]) << endl;
    }
    
    return 0;
}











Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
P = [int(i)-1 for i in input().split()]
C = [int(i) for i in input().split()]
def f(s):
    tmp = s
    circle_length = 0
    circle_score = 0
    for i in range(1, N+1):
        tmp = P[tmp]
        circle_length += 1
        circle_score += C[tmp]
        if s == tmp:
            return (True, circle_length, circle_score)
        if i == K:
            return (False, K, -10**10)

def f1(s, circle_length):
    tmp = s
    max_score = -10**10
    tmp_score = 0
    for i in range(1, circle_length+1):
        tmp = P[tmp]
        tmp_score += C[tmp]
        if max_score < tmp_score:
            max_score = tmp_score
        if tmp_score < 0:
            return max_score
        if i == K:
            return max_score
    return max_score

def f2(s, circle_length, circle_score):
    max_score = (K//circle_length) * circle_score
    tmp = s
    tmp_score = 0
    for i in range(1, (circle_length)+1):
        tmp = P[tmp]
        tmp_score += C[tmp]
        score = ((K-i)//circle_length) * circle_score + tmp_score
        if max_score < score:
            max_score = score
        if tmp_score < 0:
            return max_score
        if i == K:
            return max_score
    return max_score

tot_max = -10**10
for i in range(N):
    is_circle, circle_length, circle_score = f(i)
    max_score = f1(i, circle_length)
    if is_circle and circle_score > 0:
        max_score2 = f2(i, circle_length, circle_score)
        if max_score2 > max_score:
            max_score = max_score2
    if max_score > tot_max:
        tot_max = max_score
print(tot_max)


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

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    vector<int> base(3,0);
    int res=0;
    int out=0;
    while(out!=3){
      string s;
      cin>>s;
      if(s=="HIT"){
	res+=base[2];
	base[2]=base[1];
	base[1]=base[0];
	base[0]=1;
      }
      if(s=="OUT"){
	out++;
      }
      if(s=="HOMERUN"){
	res+=base[0]+base[1]+base[2]+1;
	for(int i=0;i<3;i++) base[i]=0;
      }

    }
    cout<<res<<endl;

  }
  return 0;
}

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

int main(){
    while(true){
        int a,b;
        cin >>a>>b;
        if(a==0 && b==0)break;
        if(a>b){
            int t=b;
            b=a;
            a=t;
        }
        cout << a<<" "<<b<<endl;
    }
return 0;
}


Measured memory_bytes: 2976
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<ll> vx,vy;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    vx.pb(a);
    vy.pb(b);
  } 
  vector<ll> v;
  rep(i,0,n){
    v.pb(i);
  }
  ll p = 0;
  double sum = 0;
  do{
    double c = 0.;
    rep(i,0,v.sz-1){
      ll x1 = vx[v[i]];
      ll y1 = vy[v[i]];
      ll x2 = vx[v[i+1]];
      ll y2 = vy[v[i+1]];
      c += pow((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2),0.5);
    }
    p++;
    sum += c;
  }while(next_permutation(all(v)));
  printf("%20.20f\n",sum/p);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  ll n,d;
  cin >> n >> d;
  d=d*d;
  int ans=0;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    if(a*a+b*b<=d)ans++;
  }
  cout << ans << endl;
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n;

int main(){
	cin >> n;
	
	cout << n/3 << endl;
	
	return 0;
}

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

using namespace std;

int main(){
  
  int a,b,c,d;
  
  cin>>a;
  
  b=a/100;
  c=a/10-b*10;
  d=a-b*100-c*10;
  
  cout<<b+c+d<<endl;
  
}
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int n, m, q;    cin >> n >> m >> q;
    vector<vector<ll>> sum(n+1, vector<ll>(n+1, 0));
    REP(i, m){
        int a, b;   cin >> a >> b;
        sum[a][b] += 1;
    }
    REP(i, n+1){
        REP(j, n) sum[i][j+1] += sum[i][j];
    }
    while(0<q--){
        int a, b;   cin >> a >> b;
        ll res=0;
        FOR(i, a, b+1) res += sum[i][b]-sum[i][i-1];
        cout << res << endl;
    }
    // REP(i, n+1){
    //     REP(j, n+1) cout << sum[i][j] << ' ';
    //     cout << endl;
    // }
}

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

const int MAXN = 1e3 + 5;
const int MAXK = 1e4 + 5;
ll dp[MAXK];
ll a[MAXN];
ll b[MAXN];
int n,m;

ll solve(int h)
{
    if(h <= 0)
        return 0;
   
   ll &ret = dp[h];
   if(ret != -1)
       return ret;
       
       
   ll best = 1e17;
  for(int i = 0 ; i < n ; i++)
      {
          ll ret = solve(h - a[i]);
              best = min(best,ret + b[i]);
      }
      
      ret = best;
      return ret;
      
      
       
       
}

int main() {
  
  cin >> m >> n;
  for(int i = 0 ; i < n ; i++)
  {
      cin >> a[i] >> b[i];
  }
  memset(dp,-1,sizeof(dp));
  cout << solve(m);
  
}

Measured memory_bytes: 896
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


A = [int(x) for x in input().split()]
A.sort()
print(A[2]*10+A[1]+A[0])


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N;
	cin >>N;
	ll S=0;
	vector<ll> A;
	A.push_back(N);
	// Divisor of N
	for (ll i=2; i*i<=N; i++)
		if (0==N%i) {
			A.push_back(i);
			if (N!=i*i)
				A.push_back(N/i);
		}
	// Sort(A); // Not Required
	Rep0(i, A.size()) {
		ll KK=A.at(i);
		ll NN=N;
		while (NN>=KK)
			if (0==NN%KK)
				NN/=KK;
			else
				NN%=KK;
		if (1==NN)
			S++;
	}
	// Divisor of N-1
	ll NN=N-1;
	vector<ll> B;
	if (NN>1)
		B.push_back(NN);
	for (ll i=2; i*i<=NN; i++)
		if (0==NN%i) {
			B.push_back(i);
			if (NN!=i*i)
				B.push_back(NN/i);
		}
	// Sort(B);// Not required
	S +=B.size();
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 384
// luogu-judger-enable-o2
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
char n;
int main()
{
	cin>>n;
	if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u')
	cout<<"vowel";
	else cout<<"consonant";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	string S;
	int r=0,b=0;
	cin>>S;
	int N=sz(S);
	rep(i,N){
		if(S[i]=='0')r++;
		if(S[i]=='1')b++;
	}
	cout<<2*min(r,b)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

ll dp[108000][13];


int main(void) {
    string s;
    cin>>s;
    dp[0][0]=1;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int d=0;d<10;d++){
                    (dp[i+1][(j*10+d)%13]+=dp[i][j])%=MOD;
                }
            }
            else{
                int d=s[i]-'0';
                (dp[i+1][(j*10+d)%13]+=dp[i][j])%=MOD;
            }
        }

    }
    cout<<dp[s.size()][5]<<endl;
}

Measured memory_bytes: 10752
#include <map>
#include <list>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,x,a[105],sum;
int main()
{
	fast; 
	cin>>n>>x;
	for (int i=1;i<=n;i++)
	   cin>>a[i],sum+=a[i];
	sort(a,a+n+1);
	cout<<(x-sum)/a[1]+n;
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int A[10];
		for(int j = 0; j < 10; j++){
			cin >> A[j];
		}
		int B[10] = {0}, C[10] = {0};
		int bIndex = 0, cIndex = 0;
		bool isYes = true;
		for(int j = 0; j < 10; j++){
			if(bIndex == 0){
				B[bIndex] = A[j];
				bIndex++;
			}else if(B[bIndex - 1] < A[j]){
				B[bIndex] = A[j];
				bIndex++;
			}else if(cIndex == 0){
				C[cIndex] = A[j];
				cIndex++;
			}else if(C[cIndex - 1] < A[j]){
				C[cIndex] = A[j];
				cIndex++;
			}else{
				isYes = false;
				break;
			}
		}
		if(isYes){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3036
n = int(input())
a = [int(x) for x in input().split()]

from collections import defaultdict
d = defaultdict(int)

for i in a:
    d[i] += 1
cnt = 0

for i in d.keys():
    if d[i]-i>0:
        cnt += d[i]-i
    elif i == d[i]:
        pass
    else:
        cnt += d[i]
print(cnt)


Measured memory_bytes: 68776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

int N, M;
vector<int> length, parent;

int calcLength(const vector<vector<int>> &edges, int current)
{
  if (length[current] != -1)
    return length[current];
  int longest = -1;
  for (const int &fr : edges[current])
  {
    int len = calcLength(edges, fr) + 1;
    if (longest < len)
    {
      longest = len;
      parent[current] = fr;
      length[current] = longest;
    }
  }
  return longest;
}

int main(int argc, char const *argv[])
{
  cin >> N >> M;
  parent.resize(N + 1, -1);
  length.resize(N + 1, -1);
  vector<vector<int>> edges(N + 1); // [to, fr]
  for (int i = 0, l = N + M - 1; i < l; ++i)
  {
    int fr, to;
    cin >> fr >> to;
    edges[to].push_back(fr);
  }

  int root;
  for (int to = 1; to <= N; ++to)
  {
    auto &fr = edges[to];
    if (fr.size() == 0)
    {
      root = to;
      break;
    }
  }

  parent[root] = 0;
  length[root] = 0;
  for (int i = 1; i <= N; ++i)
  {
    calcLength(edges, i);
  }

  for (int i = 1; i <= N; ++i)
  {
    cout << parent[i] << '\n';
  }
  cout.flush();
}


Measured memory_bytes: 9984
#include<stdio.h>
 
int main(){
    int w = 0;
    int m = 1150;
    int t;
    while(scanf("%d", &w) != -1){
        if(w == -1){
            break;
        }else if(w > 30){
            t = w - 30;
            m += 10 * 125 + 10 * 140 + t * 160;
        }else if(w > 20){
            t = w - 20;
            m += 10 * 125 + t *140;
        }else if(w > 10){
            t = w - 10;
            m += t * 125;
        }
    printf("%d\n", 4280 - m);
    m = 1150;
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <set>

using namespace std;

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

const ll mod = 1000000007;

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

  int t;
  cin >> t;
  vector<int> n(t);
  vector<vector<ll> > k(t), l(t), r(t);
  for (int i = 0; i < t; i++) {
    cin >> n[i];
    k[i] = vector<ll>(n[i]);
    l[i] = vector<ll>(n[i]);
    r[i] = vector<ll>(n[i]);
    for (int j = 0; j < n[i]; j++) cin >> k[i][j] >> l[i][j] >> r[i][j];
  }

  vector<ll> ans(t);
  for (int i = 0; i < t; i++) {
    vector<pair<ll, ll> > forward, backward;
    for (int j = 0; j < n[i]; j++) {
      if (l[i][j] > r[i][j]) forward.push_back(pair<ll, ll>(k[i][j], l[i][j] - r[i][j]));
      else if (l[i][j] < r[i][j]) backward.push_back(pair<ll, ll>(n[i] - k[i][j], r[i][j] - l[i][j]));
      ans[i] += max(l[i][j], r[i][j]);
    }

    sort(forward.begin(), forward.end());
    multiset<ll> forwardPlaced;
    int forwardCount = 0;
    for (auto &x: forward) {
      if (forwardCount < x.first) {
        forwardPlaced.insert(x.second);
        forwardCount++;
      }
      else if (!forwardPlaced.empty()) {
        if (x.second <= *(forwardPlaced.begin())) {
          ans[i] -= x.second;
        }
        else {
          ans[i] -= *(forwardPlaced.begin());
          forwardPlaced.erase(forwardPlaced.find(*(forwardPlaced.begin())));
          forwardPlaced.insert(x.second);
        }
      }
      else {
        ans[i] -= x.second;
      }
    }

    sort(backward.begin(), backward.end());
    multiset<ll> backwardPlaced;
    int backwardCount = 0;
    for (auto &x: backward) {
      if (backwardCount < x.first) {
        backwardPlaced.insert(x.second);
        backwardCount++;
      }
      else if (!backwardPlaced.empty()) {
        if (x.second <= *(backwardPlaced.begin())) {
          ans[i] -= x.second;
        }
        else {
          ans[i] -= *(backwardPlaced.begin());
          backwardPlaced.erase(backwardPlaced.find(*(backwardPlaced.begin())));
          backwardPlaced.insert(x.second);
        }
      }
      else {
        ans[i] -= x.second;
      }
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 20188
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	int H,W,flag=0,i,j;
	char s[52][52];
	for (i = 0; i < 52; ++i){
		for (j = 0; j < 52; ++j){
			s[i][j]='1';
		}
	}
	cin >> H;
	cin >> W;
	for (i = 1; i <= H; ++i){
		for (j = 1; j <= W; ++j){
			cin >> s[i][j];
		}
	}
	for (i = 1; i <= H; ++i){
		for (j = 1; j <= W; ++j){
			if((s[i][j]=='#') && (s[i+1][j]!='#') && (s[i][j+1]!='#') && (s[i-1][j]!='#') && (s[i][j-1]!='#')){
				flag=1;
			}
		}
	}
	if(flag==1){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <algorithm>
#include <string>

typedef long long ll;

bool checksecondValue(std::pair<ll,ll> lhs, std::pair<ll,ll> rhs)
{
    return lhs.second < rhs.second;
}

int main()
{

    ll N;
    std::cin >> N;

    std::vector<std::pair<ll, ll>> works;
    works.resize(N);

    for(int i=0; i<N; ++i)
        std::cin >> works[i].first >> works[i].second;

    std::sort(works.begin(), works.end(), checksecondValue);

    ll time=0;
    for(int i=0; i<N; ++i)
    {
        time += works[i].first;
        if(time>works[i].second)
        {
            std::cout <<"No"<<std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}






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

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int inf = INT_MAX;
const LL INF = LLONG_MAX;

template <typename T> inline int chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch - '0');
	return sum * fl;
}

const int mod = 1e9 + 7;
const int bit = 16, maxn = (1 << bit) + 5;

int N, M;
int A[maxn];

namespace MATH
{
	int fac[maxn], ifac[maxn];

	inline int Pow (int a, int b, int ans = 1)
	{
		for (; b; b >>= 1, a = (LL)a * a %mod) if (b & 1) ans = (LL)a * ans %mod;
		return ans;
	}

	inline void init (int x)
	{
		fac[0] = ifac[0] = 1;
		for (int i = 1; i <= x; ++i) fac[i] = (LL)fac[i - 1] * i %mod;
		ifac[x] = Pow (fac[x], mod - 2);
		for (int i = x - 1; i >= 1; --i) ifac[i] = (LL)ifac[i + 1] * (i + 1) %mod;
	}

	inline int binom (int a, int b)
	{
		if (a < 0 || b < 0 || a < b) return 0;
		return (LL)fac[a] * ifac[b] %mod * ifac[a - b] %mod;
	}
}
using namespace MATH;

int F[bit + 1][maxn]; //F[i][S] : 考虑完前 i 大的限制数，至少有 S 这些段非法的方案数

inline void add (int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

inline void solve ()
{
	MATH :: init (1 << N);
	sort (A + 1, A + M + 1);

	F[0][0] = 1;
	for (int i = 1; i <= M; ++i) //考虑完前 i 大的限制数
	{
		int v = A[M - i + 1];
		for (int j = 0; j < (1 << N); ++j) if (F[i - 1][j])
		{
			add (F[i][j], F[i - 1][j]);
			for (int k = 0; k < N; ++k) if (((j >> k) & 1) == 0)
			{
				add (F[i][j | (1 << k)], (LL)F[i - 1][j] * fac[1 << k] % mod 
						* binom ((1 << N) - v - j, (1 << k) - 1) % mod);
			}
		}
	}

	int Ans = 0;
	for (int i = 0; i < (1 << N); ++i) if (F[M][i])
	{
		F[M][i] = (LL)F[M][i] * fac[(1 << N) - i - 1] % mod;

		int cnt = __builtin_popcount (i);
		add (Ans, (cnt & 1) ? mod - F[M][i] : F[M][i]);
	}

	Ans = (LL)Ans * (1 << N) % mod;
	printf ("%d\n", Ans);
}

inline void input ()
{
	N = read<int>(), M = read<int>();
	for (int i = 1; i <= M; ++i) A[i] = read<int>();
}

int main ()
{


	input ();
    solve ();

    return 0;
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=0;i<=10000;++i)
		if(i*8/100==a&&i/10==b){
			cout<<i<<endl;
			return 0;
		}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
  
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        String s = buf.readLine();
        int x = Integer.parseInt(s);
        int ruijou = x * x * x;
        System.out.println(ruijou);
    }
}

Measured memory_bytes: 24120
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	double num1,num2,num3,max,m;
	num1=a+b;
	num2=a-b;
	num3=a*b;
	if(num1>num2){
		m=num1;
	}else{
		m=num2;
	}
	if(m>num3){
		max=m;
	}else{
		max=num3;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
//Author- Vaibhav Singh


#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
*/
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  /*
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}*/
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}

/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
*/
/*
bool is_prime(ll n){
    for(ll i = 2;i*i<=n;i++){
        if(n%i == 0) return false;
    }
    return true;
}
*/

       int main()
       {
    fast
     
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll i,j,k;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                ll p=i*i+j*j+k*k+i*j+j*k+i*k;
                m[p]++;
            }
        }
    }
      
      
      fo(i,n)
      {
          o(m[i])
      }
      
      

re}


Measured memory_bytes: 5996