akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int N;
  cin >> N;
  map<int,int> a;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    a[A[i]]++;
  }

  int cnt = 0;
  for(auto x:a){
    if(x.second%2==1){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main(){
    int n, T, t, min = 10000, c, count = 0;
    cin >> n >> T;
    for (int i = 0; i < n; i++){
        cin >> c >> t; 
        if (t <= T){
            if (c < min){
                min = c;
            }
        }else{
            count++;
        }
    }
    if (count == n){
        cout << "TLE" << endl;
    }else{
        cout << min << endl;
    }

}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

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

	bool swi[10][11];
	for(int i = 0; i < m; i++) {
		for(int j = 1; j <= n; j++) {
			swi[i][j] = false;
		}
	}

	rep(i, m) {
		int k;
		cin >> k;
		rep(j, k) {
			int s;
			cin >> s;
			swi[i][s] = true;
		}
	}

	int p[10];
	rep(i, m) cin >> p[i];

	int ans = 0;
	for(int i = 0; i < (1 << n); i++) {
		bool swi_t[11];
		int t = i;
		for(int j = 1; j <= n; j++) {
			if(t % 2 == 0) swi_t[j] = false;
			else swi_t[j] = true;
			t /= 2;
		}
		bool f = true;
		for(int j = 0; j < m; j++) {
			int count = 0;
			for(int k = 1; k <= n; k++) {
				if(swi[j][k] && swi_t[k]) {
					count++;
				}
			}
			if(count % 2 != p[j]) {
				f = false;
			}
		}
		if(f) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<fstream>
using namespace std;
int main(void){
    string moji;
   while(true){
       cin >> moji;
       if(cin.eof()==true)break;
       int ioi, joi, count;
       count = moji.length();
       joi=0;
       ioi=0;
       for(int i=0;i<count-2;i++){
           if(moji[i]=='I'&&moji[i+1]=='O'&&moji[i+2]=='I')ioi++;
           else if(moji[i]=='J'&&moji[i+1]=='O'&&moji[i+2]=='I')joi++;
       }
       cout << joi << endl << ioi << endl;
   }
}



Measured memory_bytes: 3168
#include<iostream>
#include<cstdlib>
#define MAX 10

using namespace std;

struct datum {
	char name;
	int win;
	int lose;
};

datum data[MAX];

int compare ( const void * a, const void * b ) {
	const datum x = *((datum*)a);
	const datum y = *((datum*)b);

	if ( x.win == y.win )
		return x.lose - y.lose;
	return y.win - x.win;
}

int main () {

	while ( true ) {
		int n;
		cin >> n;
		if ( n == 0 )
			break;
		for ( int i=0; i<n; i++ ) {
			cin >> data[i].name;
			int win, lose;
			win = 0;
			lose = 0;
			int now;
			for ( int j=0; j<n-1; j++ ) {
				cin >> now ;
				if ( now == 0 )
					win++;
				if ( now == 1 )
					lose++;
			}
			data[i].win = win;
			data[i].lose = lose;
		}

		qsort ( data, n, sizeof(datum), compare);

		for ( int i=0; i<n; i++ ) {
			cout << data[i].name << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ye;
	ye=0;
	cin>>n;
	char s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(s[i]=='Y'){
			ye++;
		}
	}
	if(ye==0){
		cout<<"Three"<<endl;
	}
	else{
		cout<<"Four"<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
typedef pair<pi,int> ppii;
#define F first
#define S second
#define PB push_back
const int N=1e2+10;
bool cmp(ppii a,ppii b){
    if(a.F.F==b.F.F){
        if(a.F.S==b.F.S)return a.S>b.S;
        return a.F.S<b.F.S;
    }
    return a.F.F>b.F.F;
}
int main(){
    int m,t,p,q,a,b,c,d,add[N][N];
    ppii ans[N];
    while(true){
        scanf("%d%d%d%d",&m,&t,&p,&q);
        if(m==0&&q==0&&t==0&&p==0)return 0;
        for(int i=1;i<=t;i++)for(int j=1;j<=q;j++)add[i][j]=0;
        for(int i=1;i<=t;i++)ans[i]={{0,0},i};
        while(q--){
            scanf("%d%d%d%d",&a,&b,&c,&d);
            if(d!=0)add[b][c]+=20;
            else {
                ans[b].F.S+=add[b][c]+a;
                ans[b].F.F++;
            }
        }
        sort(ans+1,ans+1+t,cmp);
        printf("%d",ans[1].S);
        for(int i=2;i<=t;i++){
            if(ans[i].F==ans[i-1].F)printf("=");
            else printf(",");
            printf("%d",ans[i].S);
        }
        printf("\n");    
    }
}


Measured memory_bytes: 2664
#include <bits/stdc++.h>
#define MAX_N 100000
#define MAX_C 30
using namespace std;
int n, m, s[MAX_N+5], t[MAX_N+5], c[MAX_N+5], ss[MAX_N+5], tt[MAX_N+5], cc[MAX_N+5];
int cnt, r[MAX_N+5], pos[MAX_N+5], id[MAX_N+5];
bool cmp(const int &a, const int &b) {return ss[a] == ss[b] ? tt[a] < tt[b] : ss[a] < ss[b];}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)	scanf("%d%d%d", ss+i, tt+i, cc+i), id[i] = i;
	sort(id+1, id+n+1, cmp);
	for (int i = 1; i <= n; i++)	s[i] = ss[id[i]], t[i] = tt[id[i]], c[i] = cc[id[i]];
	for (int i = 1; i <= n; i++) {
		int cur = -1;
		for (int j = 1; j <= cnt; j++) {
			if ((c[i] != pos[j] && r[j] < s[i] && r[j] > r[cur]))	cur = j;
			if ((c[i] == pos[j] && r[j] <= s[i] && r[j] > r[cur]))	cur = j;
		}
		if (~cur)	r[cur] = t[i], pos[cur] = c[i];
		else	r[++cnt] = t[i], pos[cnt] = c[i];
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 2944
S = input()
#S = map(int, list(S))
listed_S = list(S)

like = 999
for i in range(len(listed_S)-2):
    three =  [listed_S[i], listed_S[i+1], listed_S[i+2]]
    moji = int(''.join(three))
    dif = abs(753-moji)
    
    if dif<like:
        like = dif

print(like)
    

Measured memory_bytes: 2940
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
big = 44
stand = 2 ** big
width = 2 ** (big-1)
if sum(a) <= k:
  print(0)
else:
  while True:
    tmp = []
    for i in range(n):
       tmp.append(max(0,a[i]-stand//b[i]))
    if width == 0:
      if sum(tmp) <= k:
        print(stand)
      else:
        print(stand+1)
      break
    if sum(tmp) <= k:
      stand -= width
      width //= 2
    else:
      stand += width
      width //= 2
    #print(stand,tmp)

Measured memory_bytes: 120416
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int n;

int main(void)
{
	cin >> n;
	map<int, int>dic, cop;
	for (int i = 0; i < n; ++i)
	{
		int a; cin >> a;
		dic[a]++;
	}
	cop = dic;
	int ans = 0;
	for (auto a : dic)
	{
		int index = a.first;
		int sum = cop[index] + cop[index + 1] + cop[index + 2];
		ans = max(ans,sum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7680
def main():
    from collections import defaultdict
    N = int(input())
    A = [0] * N
    cumsum = 0
    dic = defaultdict(int)
    zero = 0
    for i, a in enumerate([int(x) for x in input().split()]):
        cumsum += a
        dic[cumsum] += 1
        A[i] = cumsum

    ans = zero * (zero + 1) // 2
    for a, b in dic.items():
        if a == 0:
            ans += b * (b + 1) // 2
        else:
            ans += b * (b - 1) // 2
    
    print(ans)

if __name__ == '__main__':
    main()

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

void solve()
{
	int x,n;
	cin>>x>>n;
	set<int> p;
	for (int i = 0; i < n; ++i)
	{
		int k;
		cin>>k;
		p.insert(k);
	}
	if(p.find(x)==p.end())
	{
		cout<<x<<endl;
		return;
	}
	int i = 1;
	while(1)
	{
		if(p.find(x-i)==p.end())
		{
			cout<<x-i<<endl;
			return;
		}
		else if(p.find(x+i)==p.end())
		{
			cout<<x+i<<endl;
			return;
		}
		i++;
	}
}

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

Measured memory_bytes: 3604
N=int(input())
l=list(map(int,input().split()))
s_1=sum(l)
n=len(l)

for i in range(n-1):
  if l[i]>l[i+1]:
    l[i+1]=l[i]
s_2=sum(l)

print(s_2-s_1)

Measured memory_bytes: 32244
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for (int i=0;i<3;i++){
    if (s[i]=='1'){
      s[i]='9';
    }
    else {
      s[i]='1';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;

int main() {
    cin >> n;
    vector<pair<pair<string, int>, int>> r(n);
    rep(i, n) {
        cin >> r[i].first.first >> r[i].first.second;
        r[i].first.second *= -1;
        r[i].second = i;
    }
    sort(all(r));
    for (auto a : r) {
        cout << a.second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vector<ll> p(N);
  REP(i, N) cin >> p[i];
  sort(p.begin(), p.end());
  ll ans = 0;
  REP(i, N) ans += p[i];
  ans -= p[N-1]/2;

  cout << ans << "\n";

  return 0;
}

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

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    vi s(q);
    rep(i, q) cin >> s[i];

    vector<bool> ans(q, false);
    rep(i, 1 << n)
    {
        int temp = 0;
        rep(j, n)
        {
            if (i >> j & 1)
            {
                temp += a[j];
            }
        }
        rep(j, q) if (s[j] == temp) ans[j] = true;
    }
    rep(i, q) {
        if(ans[i]) cout << "yes" << endl; 
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 3168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i;
	int p_a, p_z;
	int length;
	char string[262144];

	fgets(string, sizeof(string), stdin);
	length = strlen(string);

	p_a = -1;
	for(i = 0; i < length - 1; i += 1) {
		if(string[i] == 'A') {
			p_a = i;
			break;
		}
	}
	p_z = -1;
	for(i = length- 1; i > -1; i -= 1) {
		if(string[i] == 'Z') {
			p_z = i;
			break;
		}
	}
	printf("%d\n", p_z - p_a + 1);

	return 0;
}


Measured memory_bytes: 2212
#include <iostream>
#define ll long long
using namespace std;
ll max(ll a,ll b){
	return a>b?a:b;
}
ll min(ll a,ll b){
	return a<b?a:b;
}
int main(){
	ll n,x,y;
	cin>>n;
	ll tx=0,ty=0;
	for(ll i=0;i<n;i++){
		cin>>x>>y;
		if( (x<tx)  && (y>=ty) ){
			ll temp=tx/x;
			if(temp*x!=tx)
				temp++;
			x=x*temp;
			y=y*temp;
		}
		else if( (y<ty) && (x>=tx)){
			ll temp=ty/y;
			if(temp*y!=ty)
				temp++;
			x=x*temp;
			y=y*temp;
		}
		else if( (y<ty) && (x<tx)){//两个都不过 
			ll temp1=tx/x;
			if(temp1*x!=tx)
				temp1++;
				
			ll temp2=ty/y;
			if(temp2*y!=ty)
				temp2++;
			ll temp_min=min(temp1,temp2);
			ll temp_max=max(temp1,temp2);
			if(temp_min*x>=tx && temp_min*y>=ty){
				x=x*temp_min;
				y=y*temp_min;
			}	
			else{
				x=x*temp_max;
				y=y*temp_max;
			}	
		}
		tx=x;ty=y;
	}
	cout<<tx+ty<<endl;
	return 0;
}

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

using namespace std;

#define f first 
#define s second 
#define mp make_pair
#define pb push_back

typedef long long ll;

const int mod=1e9+7;
const int INF=INT_MAX;



int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a+b,min(b+c,c+a)) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

ans = [[0] * W for _ in range(H)]

dx = [-1, 0, 1, 1, 1, 0, -1, -1]
dy = [-1, -1, -1, 0, 1, 1, 1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = 0
        for nx, ny in zip(dx, dy):
            x, y = w + nx, h + ny
            if x < 0 or x >= W or y < 0 or y >= H:
                continue
            if S[y][x] == '#':
                cnt += 1
        S[h][w] = str(cnt)

[print("".join(S[i])) for i in range(H)]

Measured memory_bytes: 3800
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()

if x[-1] < y[0]:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[201];
	char temp[201];
	int i, j;
	
	while (scanf("%[^\n]", str) != EOF){
		getchar();
		
		i = 0;
		
		while (str[i] != '\0'){
			if (str[i] != '@'){
				printf("%c", str[i]);
			}
			else {
				for (j = 0; j < str[i + 1] - '0'; j++){
					printf("%c", str[i + 2]);
				}
				i += 2;
			}
			i++;
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<long long, long long> P;


void solve()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	int minusCount = 0;
	long long absMin = 1e10;
	long long ans = 0;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		absMin = min(absMin, abs(A[i]));
		ans += abs(A[i]);
		if (A[i] < 0)
		{
			++minusCount;
		}
	}
	if (minusCount % 2 == 0)
	{
		cout << ans << endl;
	}
	else
	{
		cout << ans - 2 * absMin << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1152
MOD = 10**9+7
S = input()
LenS = len(S)
DP = [[0] * 13 for _ in range(LenS+1)]

c = S[0]
if c == '?':
    for i in range(10):
        DP[1][i] = 1
else:
    n = int(c)
    DP[1][n] = 1

for i in range(2,LenS+1):
    c = S[i-1]
    if c == '?':
        for n in range(10):
            for j in range(13):
                k = (10*j+n) % 13
                DP[i][k] += DP[i-1][j] 
                DP[i][k] %= MOD
    else:
        n = int(c)  
        for j in range(13):
            k = (10*j+n) % 13
            DP[i][k] = DP[i-1][j] 
            DP[i][k] %= MOD

print(DP[LenS][5])


Measured memory_bytes: 61916
n = int(input())
b_list = list(map(int,input().split()))

a_list = [0]*n
a_list[0] = b_list[0]
k = 0
while k <= n-2:
  if a_list[k] > b_list[k]:
    a_list[k] = b_list[k]
  a_list[k+1] = b_list[k]
  k += 1
print(sum(a_list))

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n) cin >> a[i];
	map<int, int> ma; rep(i, n) ma[a[i]]++;

	ll sum = 0;
	for (auto u : ma) {
		ll num = u.second;
		sum += num * (num - 1) / 2;
	}

	rep(i, n) {
		ll num = ma[a[i]];
		cout << sum - (num * (num - 1) / 2) + ((num - 1) * (num - 2) / 2) << endl;
	}
	return 0;
}


Measured memory_bytes: 9600
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
for i in range(N):
  eat = A[i]-1 #0index
  ans += B[eat]
  if i>= 1 and A[i] == A[i-1]+1:
    #print(eat)
    ans += C[eat-1]
print(ans)

Measured memory_bytes: 9196
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    grid = [list("." + input()) for _ in range(H)]

    dp = [[f_inf] * (W + 1) for _ in range(H)]
    dp[0][0] = 0

    for h in range(H):
        for w in range(W + 1):
            if w == 0:
                if h != 0:
                    continue
                next_h, next_w = h, w + 1
                if grid[h][w] == "." and grid[next_h][next_w] == "#":
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                elif grid[h][w] == "." and grid[next_h][next_w] == "#":
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                else:
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
            else:
                for dh, dw in [(1, 0), (0, 1)]:
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1:
                        continue
                    if grid[h][w] == "." and grid[next_h][next_w] == "#":
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                    elif grid[h][w] == "." and grid[next_h][next_w] == "#":
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                    else:
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
    print(dp[-1][-1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9436
#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>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, K;
        cin >> N >> K;
        vector<Int> H(N);
        for (int i = 0; i < N; ++i) cin >> H[i];
        sort(H.rbegin(), H.rend());

        Int sum = accumulate(all(H), 0ll);
        for (int i = 0; i < K && i < N; ++i) {
            sum -= H[i];
        }

        cout << sum << endl;


    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) {
        cout << c;
    } else if (a == c) {
        cout << b;
    } else {
        cout << a;
    }
}


Measured memory_bytes: 256
n,k=[int(i) for i in input().split()]
r,s,p=[int(i) for i in input().split()]
hand=input()
ans=0
for i in range(k):
  free=True
  j=i
  while j<n:
    if free==True or hand[j-k]!=hand[j]:
      if hand[j]=='r':
        ans+=p
      elif hand[j]=='s':
        ans+=r
      else:
        ans+=s
      free=False
    else:
      free=True
    j+=k
print(ans)

Measured memory_bytes: 3316
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import bisect
# import numpy as np
# from scipy.special import comb


INF = 1001001001001


def main():

    A, B, C, X, Y = map(int, input().split())
    ab_max = 2 * max(X, Y)

    ans = INF
    for i in range(0, ab_max + 1, 2):
        a_num = max(0, X - i // 2)
        b_num = max(0, Y - i // 2)
        price = A * a_num + B * b_num + C * i
        #print(a_num, b_num, i, price)
        ans = min(ans, price)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int K=M;
  vb.resize(N + 1);
  vb[0] = 0;
  rep(i, 0, N - 1) { vb[i + 1] = vb[i] + va[i]; }
  priority_queue<int> pq;

  vi wa;
  rep(i, 0, N - 1) {
    // vb[i] ~ vb[i+K]

    if (i + K  <=  N) {
      pq.push(vb[i+K] - vb[i]);
    }
  }
  int ansp = pq.top();
  double ans = (double)(ansp + (double)K)/(2.0);
  cout<<ans<<endl;

}
signed main() {
  cout<<fixed<<setprecision(12);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
vector<long long int> adj[200001];
bool vis[200001];
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7

#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));

string cmp(string a,string b){
    int n=a.size(),m=b.size();
    if(n>m) return(a);
    if(m>n) return(b);
    for(int i=0;i<n;i++){
        if(a[i]==b[i]) continue;
        if((a[i]-'0')>(b[i]-'0')) return(a);
        else return(b);
    }
    return(a);
}
string ss="0123456789";
int main(){
    IO
    int n,m;
    cin>>n>>m;
    int mat[]={0,2,5,5,4,5,6,3,7,6};
    int arr[m];
    for(int i=0;i<m;i++) cin>>arr[i];
    sort(arr,arr+m);
    map<int,string> mp;
    //for(int i=0;i<=n;i++) mp[i]="";
    /*
    for(int i=0;i<m;i++){
        string s=mp[mat[arr[i]]];
        string p="";
        p+=ss[arr[i]];
        //cout<<s<<" "<<p<<endl;
        mp[mat[arr[i]]]=cmp(p,s);
    }
    */

    for(int i=0;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i-mat[arr[j]]<0) continue;
            string s=mp[i-mat[arr[j]]];
            string p=mp[i];
            if(s=="" && i!=mat[arr[j]]) continue;
            s+=ss[arr[j]];
            sort(s.rbegin(),s.rend());
            mp[i]=cmp(s,p);
            /*
            cout<<"i is "<< i<<" ";
            cout<<"j is "<<j<<" ";
            cout<<" mat[arr["<<j<<"]] is "<<mat[arr[j]]<<" ";
            cout<<"mp["<<i<<"] is "<<mp[i]<<"\n";
            */
        }

    }
    /*
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<mp[i]<<"\n";
    }
    */
    cout<<mp[n];
    return(0);
}

Measured memory_bytes: 26112
def convert_1d_to_2d(a):
    return [a[i:i+1] for i in range(0,len(a),1)]
n=int(input())
a=convert_1d_to_2d(list(map(int,input().split())))
for i in range(n):
    a[i].append(i+1)
a=sorted(a,key=lambda x:x[0])
for i in range(n):
    print(a[i][1],end=' ')

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

vector<int> a(4);
char op[3],ansop[3];

void dfs(int,int);

int main(){

    string s;
    cin>>s;
    for(int i=0;i<4;i++){
        a[i]=s[i]-'0';
    }

    dfs(0,0);
    for(int i=0;i<3;i++){
        cout<<a[i]<<ansop[i];
    }
    cout<<a[3]<<"=7"<<endl;


    return 0;
}

void dfs(int i,int sum){
    if(i==0) sum=a[i];
    if(i==3){
        if(sum==7){
            for(int j=0;j<3;j++){
                ansop[j]=op[j];
            }
        }
        return;
    }
    op[i]='+';
    dfs(i+1,sum+a[i+1]);
    op[i]='-';
    dfs(i+1,sum-a[i+1]);

    return;
}

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

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

    vector<ll> ai(n);
    vector<ll> di(n);
    for (int i = 0; i < n; i++) {
        cin >> ai.at(i);
    }
    for (int i = 0; i < n-1; i++) {
        di.at(i) = ai.at(i+1) - ai.at(i);
    }
    di.at(n-1) = k -ai.at(n-1) + ai.at(0);
    ll dmax = 0;

    for (ll i: di) dmax = max(i, dmax);
    cout << k - dmax << endl;

    return 0;
}

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

ll MAX = 1e18 + 5;

ll arr[410];
ll dp[410][410] = {0};

ll sum(int l, int r) {
    ll s = 0;
    for(int i = l; i <= r; i++) {
        s += arr[i];
    }
    return s;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t != 0) {
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> arr[i];
        }
        for(int len = 2; len <= n; len++) {
            for(int i = 0; i <= n-len; i++) {
                int j = i + len - 1;
                dp[i][j] = MAX;
                ll s = sum(i, j);
                for(int k = i; k < j; k++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
                }
            }
        }
        // for(int i = 0; i < n; i++) {
        //     for(int j = 0; j < n; j++) {
        //         cout << "(" << dp[i][j] << ", " << ind[i][j] << ") ";
        //     }
        //     cout << "\n";
        // }
        cout << dp[0][n-1] << "\n";
	    t--;
	}
	return 0;
}


Measured memory_bytes: 1536
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
// #define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

vector<int> prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        //we will try to shorten the match string length until we revert to the beginning of match (index 1)
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
void solve(){

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        int a;
        cin >> a;

        if(a&1 && i&1)ans++;
    }
    cout << ans << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

ll A, B, C, u, v, x, y, t, a, b, ans;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>A>>B>>C;
	if (A&B&C&1) kill(min({A*B, B*C, A*C}))
	kill(0)
	
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n,m;
    ll t[110],p[110],x[110];
    cin>>n;
    rep(i,n) cin>>t[i];
    cin>>m;
    rep(i,m) cin>>p[i]>>x[i];
    rep(i,m){
        ll ans=x[i];
        rep(j,n){
            if(j==p[i]-1) continue;
            ans+=t[j];
        }
        cout<<ans<<endl;

    }
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define show(x) cout << x << endl;
#define pb push_back
#define pair make_pair
const ll mod = 1000000007;

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

    vvl G(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
    }

    ll sv, tv;
    cin >> sv >> tv;
    sv--;  tv--;

    vvl dist(n, vl(3, -1));  // dist[i][j] : 移動距離がmod3でjとなる頂点svから頂点iまでの最短距離
    queue<pll> Q;

    dist[sv][0] = 0;
    Q.push(pair(sv, 0));
    while(!Q.empty()) {
        ll v = Q.front().first;
        ll c = Q.front().second;
        Q.pop();
        for(auto u : G[v]) {
            ll nc = (c + 1)%3;
            if(dist[u][nc] != -1) {
                continue;
            }
            dist[u][nc] = dist[v][c] + 1;
            Q.push(pair(u, nc));
        }
    }
    
    ll ans = dist[tv][0];
    if(ans != -1) {
        ans /= 3;
    }
    
    cout << ans << endl;
    return 0;
}

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

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

int calc_left(int x, int y, int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

int calc_comb_count(int x, int y, int z) {
  if (x == y) {
    if (y == z) {
      return 1;
    } else {
      return 3;
    }
  } else {
    if (y == z) {
      return 3;
    } else {
      return 6;
    }
  }
}

vector<int> solve(int N) {
  int x_max = sqrt(N / 6);
  vector<int> retv(N, 0);

  for (int x = 1; x <= x_max; x++) {
    bool is_y_excced = false;
    int y = x;
    while (!is_y_excced) {
      bool is_z_excced = false;
      int z = y;
      while (!is_z_excced) {
        int lhs = calc_left(x, y, z);
        if (lhs > N) {
          is_z_excced = true;
          if (y == z) {
            is_y_excced = true;
          }
        } else {
          retv[lhs - 1] += calc_comb_count(x, y, z);
          z++;
        }
      }
      y++;
    }
  }
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  // main procedure
  vector<int> ans = solve(N);

  // output
  for (int n = 1; n <= N; n++) {
    cout << ans[n - 1] << endl;
  }

  return 0;
}

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,K;
    cin>>N>>K;
    map<int,int> dic;

    for(int i = 0;i < K;i++) {
        int d;
        cin>>d;
        for(int j = 0;j < d;j++) {
            int a;
            cin>>a;
            dic[a]++;
        }
    }

    cout<<N-dic.size()<<endl;

    return 0;
}





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

int main(){
    string s; cin >> s;
    if(s.substr(0, 4) > "2019") {
        cout << "TBD" << endl;
        return 0;
    }
    if(s.substr(5, 2) > "04") {
        cout << "TBD" << endl;
        return 0;
    }
    cout << "Heisei" << endl;
}
   

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

int main() {
  int n;
  string s;
  
  cin >> n >> s;
  
  int ans=0,num=0;
  for(int i; i<n; i++){
    if(s.at(i)=='I'){
      num+=1;
    }
    else{
      num-=1;
    }
    if(ans<num){
      ans=num;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Abc173
{
    class C
    {
        public static void Main()
        {
            var hwk = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            var h = hwk[0];
            var w = hwk[1];
            var k = hwk[2];

            var matrix = new int[h][];

            for (int y = 0; y < h; y++)
                matrix[y] = Console.ReadLine().ToCharArray().Select(c => c == '#' ? 1 : 0).ToArray();
            int blackN = matrix.Aggregate(0, (acc, array) => acc += array.Sum());
            int diff = blackN - k;

            if (diff < 0)
            {
                Console.WriteLine(0);
                return;
            }

            int count = 0;


            int yfoot = (1 << h) - 1;
            int xfoot = (1 << w) - 1;
            for (int y = 0; y <= yfoot; y++)
            {
                int n = diff;
                var selectedY = new List<int>();
                int yy = y;
                for (int yi = 0; yi < h; yi++)
                {
                    if ((yy & 1) != 0)
                    {
                        n -= matrix[yi].Sum();
                        selectedY.Add(yi);
                    }
                    yy >>= 1;
                }
                if (n < 0)
                    continue;

                for (int x = 0; x <= xfoot; x++)
                {
                    int m = n;
                    int xx = x;
                    for (int xi = 0; xi < w; xi++)
                    {
                        if ((xx & 1) != 0)
                        {
                            for (int yi = 0; yi < h; yi++)
                            {
                                if (selectedY.Contains(yi))
                                    continue;
                                m -= matrix[yi][xi];
                            }
                        }
                        xx >>= 1;
                    }
                    if (m == 0)
                        count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

int main() {
  int a, b, c, x, y;

  cin >> a >> b >> c >> x >> y;

  c *= 2;

  int ans = INT_MAX;

  for (int i = 0; i <= max(x, y); i++) {
    ans = min(ans, i * c + max(0, (x - i) * a) + max(0, (y - i) * b));
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        String[] a = new String[count];
        String[] b = new String[count];
        for (int i = 0; i < count; i++) {
            String tmp = sc.next();
            a[i] = tmp;
            b[i] = tmp;
        }
        a = bubbleSort(a);
        printArray(a);
        System.out.println("Stable");
        b = selectionSort(b);
        printArray(b);
        if (Arrays.equals(a, b)) {
            System.out.println("Stable");
        } else {
            System.out.println("Not stable");
        }
    }

    private static String[] bubbleSort(String[] a) {
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = 1; i < a.length; i++) {
                if (a[i - 1].charAt(1) > a[i].charAt(1)) {
                    String tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                }
            }
        }
        return a;
    }

    private static void printArray(String[] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);
            if (i != array.length - 1) {
                sb.append(" ");
            }
        }
        System.out.println(sb);
    }

    private static String[] selectionSort(String[] a) {
        for (int i = 0; i < a.length; i++) {
            int min = i;
            for (int j = i; j < a.length; j++) {
                if (a[j].charAt(1) < a[min].charAt(1)) {
                    min = j;
                }
            }
            if (i != min) {
                String tmp = a[i];
                a[i] = a[min];
                a[min] = tmp;
            }
        }
        return a;
    }
}

Measured memory_bytes: 26304
#include <stdio.h>
#include <stdlib.h>
#define N 44

void fibonacci(int *, int);

int main() {
  int f[N];
  int n;

  scanf("%d", &n);

  fibonacci(f, n);
  printf("%d\n", f[n]);
  
  return 0;
}

void fibonacci(int *f, int n) {
  int i;
  f[0] = 1;
  f[1] = 1;
  for(i = 2; i <= n; i++) {
    f[i] = f[i - 2] + f[i - 1];
  }
}




Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[200010];
    rep(i, N) cin >> A[i];
    sort(A, A + N, greater<int>());
    ll ans = 0;
    priority_queue<int> que;
    rep(i, N) {
        if(que.size()) {ans += que.top(); que.pop();}
        if(i != 0) que.push(A[i]); 
        que.push(A[i]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 5064
#include "bits/stdc++.h"

using namespace std;

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

  vector<pair<int, int>> work(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    work[i] = {a, b};
  }

  sort(begin(work), end(work),[](const auto& l, const auto& r) {
    if (l.first < r.first) return true;
    if (l.first > r.first) return false;
    if (l.second > r.second) return true;
    if (l.second < r.second) return false;

    return false;
  });

  long long ans = 0;
  priority_queue<int> pq;
  int cur_idx = 0;
  for (int i = 0; i <= m; i++) {
    while (cur_idx < n && work[cur_idx].first <= i) {
      pq.emplace(work[cur_idx].second);
      cur_idx++;
    }
    
    if (pq.empty()) continue;

    const auto opt = pq.top();
    pq.pop();
    ans += opt;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1660
#include<stdio.h>
int N,i,x;
int main()
{
	scanf("%d",&N);
	for(i=1;i<=N;i++)
	{
		x=i;
		if(x%3==0)printf(" %d",i);
		else
		{
			for(;x&&x%10!=3;)
				x/=10;
			if(x%10==3)
				printf(" %d",i);
		}
	}
	puts("");
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>

int main() {
	int s;
	std::cin >> s;
	int sec, min, hour;
	sec = s % 60;
	s = s / 60;
	min = s % 60;
	hour = s / 60;
	std::cout << hour << ":" << min << ":" << sec << std::endl;
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k;
	cin >> k;
	vector<ll> a(k);
	rep(i,k) cin >> a[i];
	reverse(a.begin(), a.end());
	int p = 0;
	if(a[0] != 2){
		cout << -1 << endl;
		return 0;
	}
	ll mi = 2, mx = 2;
	rep(p,k){
		if(((mx / a[p] + 1) * a[p] - 1 < mi) || ((mi + a[p] - 1) / a[p] * a[p] > mx)){
			cout << -1 << endl;
			return 0;
		}
		mi = (mi + a[p] - 1) / a[p] * a[p];
		mx = (mx / a[p] + 1) * a[p] - 1;
	}
	cout << mi << " " << mx << endl;
	return 0;
}


Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, T;
vector<pair<int, int>> dishes;
int cache[3001][3001];

int dp(int index, int time) {
  if (index == N || time < 0) {
    return 0;
  }

  if (cache[index][time] == -1) {
    cache[index][time] = max(dp(index + 1, time), dp(index + 1, time - dishes[index].first) + dishes[index].second);
  }

  return cache[index][time];
}

int solve() {
  sort(dishes.begin(), dishes.end());

  return dp(0, T - 1);
}

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

  dishes = vector<pair<int, int>>(N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < T; ++j) {
      cache[i][j] = -1;
    }
  }

  for (int i = 0; i < N; ++i) {
    cin >> dishes[i].first >> dishes[i].second;
  }

  cout << solve() << endl;

  return 0;
}


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

#define lo long long
#define ulo unsigned long long
using namespace std;

lo n,a,b,c,d,sel;
int main()
{
    cin>>n>>a>>b>>c>>d;
    sel=b-a;
    sel=abs(sel);

    lo tamb=(n-1)*(d-c);
    lo mini1=(n-1)*c;

    for (int i=0;i<n;i++)
    {
        lo mini=mini1-(c+d)*i;
        lo maxi=mini+tamb;
        if (mini<=sel && sel<=maxi)
        {
            cout<<"YES\n";
            return 0;
        }
    }

    cout<<"NO\n";

    return 0;
}


Measured memory_bytes: 256
N=gets
A=gets.split.map(&:to_i)
A.sort!
pos,neg=A.partition{|i| i>=0}
if neg.size==0
  puts pos.inject(:+)-pos[0]*2
	temp=pos.shift
	while pos.size>1
		a=pos.pop
		puts "#{temp} #{a}"
    temp-=a
  end
	a=pos.pop
	puts "#{a} #{temp}"
	temp=a-temp
elsif pos.size==0
  puts -(neg.inject(:+)-neg[-1]*2)
	temp=neg.pop
	while neg.size>0
		a=neg.shift
		puts "#{temp} #{a}"
    temp-=a
  end
else
  puts pos.inject(:+)-neg.inject(:+)
	temp=neg.pop
	while pos.size>1
		a=pos.pop
		puts "#{temp} #{a}"
    temp-=a
  end
	a=pos.pop
	puts "#{a} #{temp}"
	temp=a-temp
	while neg.size>0
		a=neg.shift
		puts "#{temp} #{a}"
		temp-=a
  end
end

Measured memory_bytes: 13440