akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 2e5 + 5;
const ll OO = 1e15 + 7;
using namespace std;

int main() {
    IO;
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    ll sum=0;
    rep(i,0,n){
        if(i<k || t[i]!=t[i-k]){
            if(t[i]=='r')
                sum+=p;
            else if(t[i]=='s')
                sum+=r;
            else if(t[i]=='p')
                sum+=s;
        }
        else if(t[i]==t[i-k]){
            t[i]='@';
        }
    }
    cout<<sum;


}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef set<int> set;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000009
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
	return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
	return (x > y) ? y : x;
}


int gcd(int n1, int n2)
{
	if (n2 != 0) return gcd(n2, n1 % n2);
	else return n1;
}
const int mod = 1e9 + 7;
int main()
{	fast;

	int n, m;
	cin >> n >> m;
	string  arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int dp[n][m];
	dp[0][0] = 1;
	int ret = 0;
	for (int i = 0; i < n; i++)
	{	dp[i][0] = 1;
		if (arr[i][0] == '#')
		{
			ret = 1;
		}
		if (ret == 1)
			dp[i][0] = 0;
	}
	ret = 0;
	for (int i = 0; i < m; i++)
	{	dp[0][i] = 1;
		if (arr[0][i] == '#')
			ret = 1;
		if (ret == 1)
			dp[0][i] = 0;
	}
	for (int i = 1; i < n; i++)
	{	for (int j = 1; j < m; j++)
		{	if (arr[i][j] == '#')
				dp[i][j] = 0;
			else
			{	dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;

			}
		}
	}
	cout << dp[n - 1][m - 1];
}





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

long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a;
    x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N; cin >> N;
    if (N == 1) {
        cout << 1 << "\n";
        return 0;
    }
    N *= 2;
    vector<pair<long long, long long>> V;
    vector<long long> R;
    long long M = N;
    for (long long i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            long long cnt = 0, r = 1;
            while (M % i == 0) {
                cnt++; M /= i; r *= i;
            }
            V.emplace_back(i, cnt);
            R.emplace_back(r);
        }
    }
    if (M != 1) V.emplace_back(M, 1), R.emplace_back(M);
    int Sz = R.size();
    long long Ans = N;
    for (int bit = 0; bit < (1 << Sz); bit++) {
        long long C = 1;
        for (int i = 0; i < Sz; i++) {
            if (bit & (1 << i)) C *= R[i];
        }
        long long a, b;
        long long D = N / C;
        extgcd(C, D, a, b); // aC + bD = 1;
        // DC - CD = 0;
        long long X = D + a, Y = C - b;
        // XC - YD = 1
        if (Y <= 0) {
            long long r = (-Y / C);
            X += D * r, Y += C * r;
            if (Y <= 0) X += D, Y += C;
        }
        assert(Y > 0);
        if (X <= 0) continue;
        long long r = min(X / D, Y / C);
        X -= r * D, Y -= r * C;
        if (X <= 0 || Y <= 0) X += D, Y += C;
        assert(X > 0 && Y > 0);
        Ans = min(Ans, Y * D);
    }
    cout << Ans << "\n";
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void  solve(){
    int n,m;
    string a,b;
    cin>>a>>b;
     n = a[0]-'0';
     m = b[0] - '0';
    string s1,s2;
    for(int i=0;i<m;i++) s1 += a;
    for(int i=0;i<n;i++) s2 += b;
    cout<<min(s1,s2);
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

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

int main ()
{
    string str;
    char m[3][3];
    while (cin >> str) {
        for (int i = 0; i < 9; i++) {
            m[i / 3][i % 3] = str[i];
        }

        for (int i = 0; i < 3; i++) {
            if (m[i][0] != 's' && m[i][0] == m[i][1] && m[i][0] == m[i][2]) {
                cout << m[i][0] << endl;
                goto escape;
            }
            if (m[0][i] != 's' && m[0][i] == m[1][i] && m[2][i] == m[0][i]) {
                cout << m[0][i] << endl;
                goto escape;
            }
        }
        if (m[0][0] != 's' && m[0][0] == m[1][1] && m[2][2] == m[0][0]) {
            cout << m[0][0] << endl;
            goto escape;
        }
        if (m[2][0] != 's' && m[2][0] == m[1][1] && m[0][2] == m[2][0]) {
            cout << m[2][0] << endl;
            goto escape;
        }
        cout << "d" << endl;
    escape:;
    }


    return 0;
}

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

int main(){
	
	int n;
	char s[20];
	int runner[3];
	int out=0;
	int score=0;
	int num=0;

	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		out=0;
		score=0;
		num=0;
		for(int j=0;j<3;j++){runner[j]=0;}

		while(out<3){
			scanf("%s",s);
			if(strcmp(s,"OUT")==0){
				out++;
			}else if(strcmp(s,"HIT")==0){
				num++;
				if(num>3){num=3;}
				if(runner[2]==1){
					runner[2]=0;
					score++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[1]=1;
				}
				runner[0]=1;
			}else{//HOMERUN
				score+=(num+1);
				num=0;
				for(int j=0;j<3;j++){
					runner[j]=0;
				}
			}
		}
		printf("%d\n",score);
	}

	return 0;
}


Measured memory_bytes: 2032
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, x[100009], y[100009];
vector<pair<int, int> > vech[100009], vecv[100009];
vector<int> vec[100009];
bool vis[100009];
set<int> xx, yy;

void dfs(int cur)
{
	xx.insert(x[cur]);
	yy.insert(y[cur]);
	vis[cur] = true;
	for (int i = 0; i < (int)vec[cur].size(); i++) {
		if (!vis[vec[cur][i]]) {
			dfs(vec[cur][i]);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		vech[y[i]].pb(make_pair(x[i], i));
		vecv[x[i]].pb(make_pair(y[i], i));
	}
	for (int i = 1; i <= 1e5; i++) {
		sort(vech[i].begin(), vech[i].end());
		sort(vecv[i].begin(), vecv[i].end());
	}
	for (int i = 1; i <= 1e5; i++) {
		for (int j = 1; j < (int)vech[i].size(); j++) {
			auto u = vech[i][j], v = vech[i][j - 1];
			vec[u.se].pb(v.se);
			vec[v.se].pb(u.se);
		}
	}
	for (int i = 1; i <= 1e5; i++) {
		for (int j = 1; j < (int)vecv[i].size(); j++) {
			auto u = vecv[i][j], v = vecv[i][j - 1];
			vec[u.se].pb(v.se);
			vec[v.se].pb(u.se);
		}
	}
	long long ans = 0, tmp = 0;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			xx.clear();
			yy.clear();
			dfs(i);
			tmp = xx.size() * 1LL * yy.size();
			ans += tmp;
		}
	}
	ans -= n;
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	int n,A,B,C;
	cin >> n;
	cin >> A >> B >> C;
	vector<int> v;
	for(int i = 0 ; i < n ; i++){
		int in; cin >> in;
		v.push_back(in);
	}
	sort(v.rbegin(),v.rend());
	int price = A , cal = C;
	double maxCal = (double)cal / price;
	
	for(int i = 0 ; i < n ; i++){
		price += B;
		cal   += v[i];
		maxCal = max( maxCal , (double)cal / price ) ;
	}
	cout << (int)(maxCal+1e-10) << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll n,k;cin>>n>>k;
  bool a[n]={false};
  ll hoge,huga;
  for(ll i=0;i<k;i++){
    cin>>hoge;
    for(ll j=0;j<hoge;j++){
      cin>>huga;
      a[huga-1]=true;
    }
  }
  ll ans=0;
  for(ll i=0;i<n;i++)if(!a[i])ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll LL_INF=1e10;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
 // cin>>questions;
 
 while(questions--)
 {
   
  int n;
  cin>>n;
  int k;
  cin>>k;
  vector<ll> v(n);
  forn cin>>v[i];
  for(int i=k;i<n;i++)
  {
            if(v[i]>v[i-k]) puts("Yes");
            else puts("No");
  }
   
   
          
          
          
         
 }
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define PI 3.14159265358979323846264338327
#define NUM 1000000007
#define ss second
#define ff first
using namespace std;

int n,m;
int rt[100001], cnt[100001];
vector <int> diff[100001];
int gp[100001];
int findrt(int x){
	if (rt[x] == x)
		return x;
	return rt[x] = findrt(rt[x]);
}

void go(int x, int g, int p, int dist){
	dist % 2 == 0 ? gp[x] = g * 2 : gp[x] = g * 2 + 1;
	for (int i = 0; i < (int) diff[x].size(); i++)
		if (diff[x][i] != p && gp[diff[x][i]] == -1)
			go(diff[x][i], g, x, dist + 1);
}

int main(){
	ios::sync_with_stdio(0);	
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		rt[i] = i;
		cnt[i] = 1;
		gp[i] = -1;
	}
	int x[100001], y[100001], z[100001];
	for (int i = 0; i < m; i++){
		cin >> x[i] >> y[i] >> z[i];
		if (z[i] % 2 == 0){
			int a = findrt(x[i]);
			int b = findrt(y[i]);
			if (a != b){
				if (b < a)
					swap(a, b);
				rt[x[i]] = rt[y[i]] = rt[b] = a;
				cnt[a] += cnt[b];
				cnt[b] = 0;
			}			
		}
	}
	for (int i = 0; i < m; i++)
		if (z[i] % 2 != 0){
			int a = findrt(x[i]);
			int b = findrt(y[i]);
			diff[a].push_back(b);
			diff[b].push_back(a);
		}
	
	int g = 0, ans = 0;
	for (int i = 1; i <= n; i++)
		if (gp[i] == -1 && cnt[i] > 0){
			ans++;
			go(i, g, -1, 0);
			g++;
		}
	cout << ans <<"\n";
		
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int count=0;
    rep(i,3){
        if(s[i]=='o'){
            count += 1;
        }
    }
    cout << 700 + count*100 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  int i;
  if(a<b){
    for(i=0;i<b;i++){
    	printf("%d",a);	
    }
  }
  else{
    for(i=0;i<a;i++){
    	printf("%d",b);	
    }
  }
  
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

n, q = map(int,input().split())
s = list(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i],r[i] = map(int,input().split())

aclist = []

cnt = 0
for i in range(n):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
        aclist.append(cnt)
    else:
        aclist.append(cnt)

for i in range(q):
    print(aclist[r[i]-1] - aclist[l[i]-1])


Measured memory_bytes: 14844
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};


template<class T> class SegmentTree {
    public:
    typedef function<T(T, T)> F;
    size_t n;
    vector<T> data;
    T def;  // 単位元
    T initial_value;    // 初期値
    F update_func;  // 更新用関数
    F find_func;  //クエリ用関数

    SegmentTree(size_t _n, T def, T initial_value, F update_func, F find_func)
        : def(def), initial_value(initial_value), update_func(update_func), find_func(find_func) {
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2*n-1, initial_value);
    }

    void update(size_t i, T x) {
        i += n-1;
        data[i] = update_func(data[i], x);
        while(i) {
            i = (i-1) / 2;
            data[i] = find_func(data[2*i+1], data[2*i+2]);
        }
    }

    T find(size_t s, size_t t, size_t k, size_t kl, size_t kr) {
        if(kr <= s || t <= kl) return initial_value;
        if(s <= kl && kr <= t) return data[k];
        size_t kc = (kl+kr) / 2;
        T vl = find(s, t, 2*k+1, kl, kc);
        T vr = find(s, t, 2*k+2, kc, kr);
        return find_func(vl, vr);
    }

    T find(size_t s, size_t t) {
        return find(s, t, 0, 0, n);
    }
};

int main() {
    unsigned int n, q, com, x, y;
    cin >> n >> q;
    SegmentTree<unsigned int> tree(
        n, 0u, (1u << 31) - 1, 
        [](unsigned int a, unsigned int b) { return b; }, 
        [](unsigned int a, unsigned int b) { return min(a, b); }
    );

    while(q--) {
        cin >> com >> x >> y;
        if(com) {
            cout << tree.find(x, y+1) << endl;
        } else {
            tree.update(x, y);
        }
    }
    
}


Measured memory_bytes: 3828
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int min = 0;
        List<Integer> list = new ArrayList();
        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            int j = 400;
            while (value >= j && j <= 3200) {
                j += 400;
            }
            if (value < 3200) {
                if (!list.contains(j)) {
                    min++;
                    list.add(j);
                }
            } else {
                list.add(value);
            }
        }
        System.out.println((min == 0 ? 1 : min) + " " + list.size());
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0)
    {
        cout << (a + b) / 2;
    }
    else
    {
        cout << "IMPOSSIBLE";
    }

    return 0;
}


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

typedef long long ll;

int main() {
  string s;
  int a[20] = {0};

  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    a[i] = s[i] - '0';
  }

  int n = s.size() - 1;
  ll ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    ll t = a[0];
    for (int j = n - 1; j >= 0; j--) {
      if (i & (1 << j)) {
        ans += t;
        t = a[n-j];
      }
      else {
        t = t*10 + a[n-j];
      }
    }
    ans += t;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int* a = new int[N];
    for(int i = 0;i < N;i++)
        cin >> a[i];
    int max = 0;
    for(int i = 0;i < N;i++){
        for(int j = i;j < N;j++){
            if(i != j && max < abs(a[i]-a[j]))
                max = abs(a[i]-a[j]);
        }
    }
    cout << max;
}


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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100005;

int main() {
  ll h, w;
  scanf("%lld %lld", &h, &w);
  if(min(h, w) == 1){
    printf("1\n");
  }
  else
    printf("%lld\n", (h * w + 1) / 2);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int saiki(int a,int b,int c){
    if(!a&&!b) return 0;
    if(c&1)return saiki(a>>1,b>>1,c>>1);
    if(b&1)return saiki(c>>1,b>>1,a>>1) + saiki((a|b|c)>>1,0,0)+1;
    if(a&1)return saiki(a>>1,b>>1,c>>1) + 2*saiki((a|b|c)>>1,0,0)+2;
}

int main(){
    while(true){
	int n,m;
	cin >> n >> m;
	if(n == 0 && m == 0 ) break;
	int cup[3];
	memset(cup,0,sizeof(cup));
	REP(i,3){
	    int t;
	    cin >> t;
	    REP(j,t){
		int temp;
		cin >> temp;
		cup[i] |= 1<<(temp-1);
	    }
	}
	    int ans = min(saiki(cup[0],cup[1],cup[2]),saiki(cup[2],cup[1],cup[0]));
	    cout << (ans>m ? -1 : ans) << endl;
    }
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        ///////////////////////////////////////////////////
        int n = in.nextInt();
        int k = in.nextInt();
        String[] hate = new String[k];
        for (int i = 0; i < k; i++) {
            hate[i] = in.next();
        }
        for (int i = n; ; i++) {
            String b = Integer.toString(i);
            boolean flag = true;
            for (String m : hate) {
                if (b.contains(m)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.println(b);
                return;
            }
        }


        ////////////////////////////////
//        out.println();
//        out.flush();
    }

    static class Scanner {
        StringTokenizer tokenizer;
        BufferedReader reader;

        public Scanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return reader.readLine();
        }

        public boolean ready() throws IOException {
            return reader.ready();
        }
    }
}






Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	int a,b;
	cin>>a>>b;
	int c=a-b+1;
	if(a<=0&&b>=0) cout<<"Zero"<<endl;
	else if(a<0&&b<0)
	{
		if(c%2==0) cout<<"Positive"<<endl;
		else cout<<"Negative"<<endl;
	}
	else cout<<"Positive"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int w[6]={2,3,5,12,10,15};
int m[6];
int main()
{
	m[5]=(int)850*3*0.88; m[4]=(int)380*5*0.8; m[3]=(int)550*4*0.85;
	m[2]=850; m[1]=550; m[0]=380;
	int W;
	while(1)
	{
		cin >> W ; if(!W) break;
		W/=100;
		int dp[1500][51]={0};
		int pnt=0;
		for(int i=0;i<6;i++)
		{
			if(w[i]>W) continue;
			else if(dp[pnt][w[i]]==0 || dp[pnt][w[i]]>m[i]) dp[pnt][w[i]]=m[i];
			for(int k=0;k<(int)W/w[i];k++)
			{
				for(int j=0;j<=W;j++)
				{
					if(dp[pnt][j]>0 && (dp[pnt+1][j]>dp[pnt][j] || dp[pnt+1][j]==0))
						dp[pnt+1][j]=dp[pnt][j];
					if(dp[pnt][j]>0 && j+w[i]<=W && (dp[pnt+1][j+w[i]]>dp[pnt][j]+m[i] || dp[pnt+1][j+w[i]]==0))
						dp[pnt+1][j+w[i]]=dp[pnt][j]+m[i];
				}
				pnt++;
			}
		}
		cout << dp[pnt][W] << endl;
	}
}

Measured memory_bytes: 1464
#include "bits/stdc++.h"
using namespace std;

int main() {
 
	int n;
	cin >> n;
	int arr[n];
	for (int i=0; i<n; i++) {
		cin >> arr[i];
	}
	
	int sm = 0;
	int last = 0;
	
	for (int i=0; i<n; i++) {
		if (arr[i] > last) {
			sm += arr[i] - last;
		}
		last = arr[i];
	}
	
	cout << sm << endl;
	
}


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

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;

  vector<int> cities(n + 1);
  vector<int> savers(n);
  for (int i = 0; i < n + 1; i++) cin >> cities[i];
  for (int i = 0; i < n; i++) cin >> savers[i];
  
  unsigned long long ans = 0;
  auto defeat = [&](int &saver, int &city, int cnt) {
    ans += cnt;
    saver -= cnt;
    city -= cnt;
  };

  for (int i = n - 1; i >= 0; i--) {
    defeat(savers[i], cities[i + 1], min(cities[i + 1], savers[i]));
    defeat(savers[i], cities[i], min(cities[i], savers[i]));
  }

  cout << ans << "\n";
  
  return 0;
}

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

using namespace std;

int N, ap[300], ap2[300];
char sir[300];
string ans;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n", &N);
for (int i='a'; i<='z'; i++)
    ap[i] = 80;
for (int i=1; i<=N; i++)
{
    memset (ap2, 0, sizeof (ap2));
    scanf ("%s", sir + 1);
    int l = strlen (sir + 1);
    for (int j=1; j<=l; j++)
        ap2[sir[j]] ++;
    for (int i='a'; i<='z'; i++)
        if (ap2[i] < ap[i]) ap[i] = ap2[i];
}
for (int i='a'; i<='z'; i++)
    while (ap[i] --)
        ans.push_back (i);
printf ("%s\n", ans.c_str ());
return 0;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      HashSet<Integer> set = new HashSet<Integer>();
      for(int i = 0; i < N; i++){
        int A = nextInt();
        if(set.contains(A)){
          set.remove(A);
        }else{
          set.add(A);
        }
      }
      myout(set.size());
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 51808
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


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

	int A[200000], B[200000];
	rep(i, N) cin >> A[i];
	rep(i, M) cin >> B[i];

	int p = 0, q = -1;
	ll kari = 0;
	rep(i, M) {
		if (kari + B[i] <= K) {
			kari += B[i];
			q = i;
		}
		else break;
	}
	int kotae = q + 1;

	for (; p < N; p++) {
		kari += A[p];
		while (kari > K && q >= 0) {
			kari -= B[q];
			q--;
		}
		if(kari <= K) chmax(kotae, p + q + 2);
	}
	co(kotae);




	Would you please return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
const int N = 2e5 + 87;
int y[N], i2y[N];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a, b;
        cin >> a >> b;
        y[a] = b;
        i2y[i] = b;
    }
    set<int> st;
    dsu d(n + 1);
    for (int x = 1; x <= n; ++x) {
        int mn = y[x];
        while (st.size() && *st.begin() < y[x]) {
            mn = min(mn, *st.begin());
            d.merge(y[x], *st.begin());
            st.erase(st.begin());
        }
        st.insert(mn);
    }
    for (int i = 1; i <= n; ++i)
        cout << d.size(i2y[i]) << '\n';
}


Measured memory_bytes: 10648
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  string formarS,latterS;
  for(int i = 0; i < S.size(); i++){
    char c = S.at(i);
    if(i < (S.size() - 1)/2)
      formarS.push_back(c);
    else if(i > (S.size() - 1) /2)
      latterS.push_back(c);
  }
  //cout << latterS <<endl;
  string s,fS,lS;
  s = S;
  reverse(S.begin(), S.end());
  fS = formarS;
  reverse(formarS.begin(),formarS.end());
  lS = latterS;
  reverse(latterS.begin(),latterS.end());
  
  if(s == S and fS == formarS and lS == latterS)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;



int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = s;
    reverse(all(t));
    map<pair<string, string>, ll> mae;
    map<pair<string, string>, ll> ushiro;
    rep(i,1ll<<n){
        string x, y;
        rep(j,n){
            if ((i>>j)&1){
                x += s[j];
            }
            else{
                y += s[j];
            }
        }
        mae[mp(x, y)]++;
    }
    rep(i,1ll<<n){
        string x, y;
        rep(j,n){
            if ((i>>j)&1){
                x += t[j];
            }
            else{
                y += t[j];
            }
        }
        ushiro[mp(x, y)]++;
    }
    ll ans = 0;
    for(auto p:mae){
        //cout << p.F.F << " " << p.F.S << " " << p.S << " " << ushiro[p.F] << endl;
        ans += p.S * ushiro[p.F];
    } 
    cout << ans << endl;
}   


Measured memory_bytes: 108288
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

bool dp1[5050][5050], dp2[5050][5050];
int a[5050];
signed main() {
	int N, K; cin >> N >> K;
	REP(i, N)cin >> a[i];
	m0(dp1[0]); dp1[0][0] = 1;
	REP(i, N) {
		REP(j, K + 1) {
			dp1[i + 1][j] = dp1[i][j];
			if (j - a[i] >= 0 && j - a[i] <= K) {
				if (dp1[i][j - a[i]])dp1[i + 1][j] = true;
			}
		}
	}
	m0(dp2[N]); dp2[N][0] = 1;
	for (int i = N; i > 0; i--) {
		REP(j, K + 1) {
			dp2[i - 1][j] = dp2[i][j];
			if (j - a[i-1] >= 0 && j - a[i-1] <= K) {
				if (dp2[i][j - a[i-1]])dp2[i-1][j] = true;
			}
		}
	}
	int ans = N;
	 
	REP(i, N) {
		//[K-a[i],K)
		int l = max((ll)0, K - a[i]), r = K;
		int cons = l;
		//左から何も取らない場合
		FOR(j, l, r) {
			if (dp2[i + 1][j]) {
				ans--; goto END;
			}
		}
		//print("x");
		//左の和がxになる場合
		REP(x, K) {
			//pe(x);
			if (x >= K)goto END;
			if (dp1[i][x]) {
				if (K - a[i] <= x && x < K) {
					ans--; goto END;
				}

				int L = max((ll)0, cons - x);
				int R = min(l, max((ll)0, r - x));
				FOR(j,L,R) {
					if (dp2[i+1][j]) {
						l = L;
						//print(j);
						ans--; goto END;
					}
				}
				l = L;
			}
			//cout << endl;
		}
		
	END:;
	}
	print(ans);
}


Measured memory_bytes: 49792
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <string>
using namespace std;


int main() {
  long long A;
  string B;
  cin >> A >> B;

  int b100 = B[0] - '0';
  int b10 = B[2] - '0';
  int b1 = B[3] - '0';

  long long b = b100 * 100 + b10 * 10 + b1;

  cout << A * b / 100 << endl;
  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b == 15) cout << '+' << endl;
    else if(a*b == 15) cout << '*' << endl;
    else cout << 'x' << endl;
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            int key = sc.nextInt();
            if (map.containsKey(key)) {
                map.put(key, map.get(key) + 1);
            } else {
                map.put(key, 1);
            }
            if (map.get(key) > max) {
                max = map.get(key);
            }

            if (map.containsKey(key - 1)) {
                map.put(key - 1, map.get(key - 1) + 1);
            } else {
                map.put(key - 1, 1);
            }
            if (map.get(key - 1) > max) {
                max = map.get(key - 1);
            }

            if (map.containsKey(key + 1)) {
                map.put(key + 1, map.get(key + 1) + 1);
            } else {
                map.put(key + 1, 1);
            }
            if (map.get(key + 1) > max) {
                max = map.get(key + 1);
            }
        }
        System.out.println(max);
    }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			int c = sc.nextInt();
			if (h==0) {
				break;
			}
			int[][] col = new int[h][w];
			for(int i=0;i<h;i++) {
				for(int j=0;j<w;j++) {
					col[i][j] = sc.nextInt();
				}
			}
			int[][] temp = new int[h][w];
			int[] p = {1,1,1,1,c};
			int ans = 0;
			do {
				for(int i=0;i<h;i++) {
					for(int j=0;j<w;j++) {
						temp[i][j] = col[i][j];
					}
				}
				UnionFind uf = new UnionFind(h*w);
				for(int i=0;i<6;i++) {
					for(int j=0;j<h-1;j++) {
						for(int k=0;k<w;k++) {
							if (temp[j][k] == temp[j+1][k]) {
								uf.union(j*w+k, (j+1)*w+k);
							}
						}
					}
					for(int j=0;j<h;j++) {
						for(int k=0;k<w-1;k++) {
							if (temp[j][k] == temp[j][k+1]) {
								uf.union(j*w+k, j*w+k+1);
							}
						}
					}
					if (i==5) {
						break;
					}
					for(int j=0;j<h*w;j++) {
						if (uf.isConnected(0, j)) {
							temp[j/w][j%w] = p[i];
						}
					}
				}
				ans = Math.max(ans,uf.size(0));
			} while(next(p));
			System.out.println(ans);
		}
	}

	static boolean next(int[] p) {
		long num = 0;
		for(int i=3;i>=0;i--) {
			num*=6;
			num+=(p[i]-1);
		}
		num+=1;
		//System.out.println(num);
		if (num >= 6*6*6*6) {
			return false;
		}
		for(int i=0;i<4;i++) {
			p[i] = (int) (num%6+1);
			num/=6;
		}
		return true;
	}
}
class UnionFind {
	private int[] data;
	public UnionFind(int size) {
		data = new int[size];
		Arrays.fill(data, -1);
	}
	public void union(int x,int y) {
		x = root(x);
		y = root(y);
		if (x!=y) {
			if (data[y] < data[x]) {
				int tmp = y;
				y = x;
				x = tmp;
			}
			data[x] += data[y];
			data[y] = x;
		}
	}
	public boolean isConnected(int x,int y) {
		return root(x)==root(y);
	}
	private int root(int x) {
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}
	public int size(int x) {
		return -data[root(x)];
	}
	public String toString() {
		return Arrays.toString(data);
	}
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

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

	int n, m;
	cin >> n >> m;

	vector<ll> x(n), y(n), z(n);
	fori(i, 0, n) {
		cin >> x[i] >> y[i] >> z[i];
	}

	ll ans = -1e18;
	for(int i = -1; i <= 1; i += 2) {
		for(int j = -1; j <= 1; j += 2) {
			for(int k = -1; k <= 1; k += 2) {
				vector<ll> all;
				fori(a, 0, n) {
					all.push_back(x[a] * i + y[a] * j + z[a] * k);
				}
				sort(all.begin(), all.end(), greater<ll>());
				ll now = 0;
				fori(a, 0, m) {
					now += all[a];
				}
				ans = max(ans, now);
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
/*
   ?????\??????????????¢?????´?????????

   1 insertionSort(A, N) // N??????????´??????????0-?????????????????????A
   2   for i ??? 1 ?????? N-1 ?????§
   3     v = A[i]
   4     j = i - 1
   5     while j >= 0 ?????? A[j] > v
   6       A[j+1] = A[j]
   7       j--
   8     A[j+1] = v
 */

#include <iostream>
#include <cstdlib>
#include <vector>

void insertionSort(std::vector<int> A, int N);
void print(std::vector<int> A, int N);

int main(void) {
    int N;
    std::cin >> N;
    std::vector<int> A(N, 0);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    insertionSort(A, N);

    return EXIT_SUCCESS;
}

void insertionSort(std::vector<int> A, int N) {
    int v;
    int j;
    print(A, N);
    for (int i = 1; i <= N - 1; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
            A[j + 1] = v;
        }
        print(A, N);
    }
}

void print(std::vector<int> A, int N) {
    for (int i = 0; i < N - 1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N - 1] << std::endl;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    map<int, int> m;
    int n;
    cin >> n;
    int a;
    rep(i, n) {
        cin >> a;
        m[a]++;
    }
    int cnt = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->first > it->second) {
            cnt += it->second;
        }
        else if (it->first < it->second) {
            cnt += it->second - it->first;
        }
    }
    cout << cnt << endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll W, H;
vector <pair<ll, bool>> P;

int main(){
  cin >> W >> H;
  for (int i = 0; i < W; i++){
    ll A; cin >> A;
    P.push_back({A, false});
  }
  for (int i = 0; i < H; i++){
    ll A; cin >> A;
    P.push_back({A, true});
  }
  sort(P.begin(), P.end());

  ll ans = 0, F = H + 1, T = W + 1;
  for (int i = 0; i < H + W; i++){
    if (P[i].se == false){
      ans += P[i].fi * F; T--;
    }else{
      ans += P[i].fi * T; F--;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
template <typename T> T max(T a, T b) {return a>b?a:b;}
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))

const double eps = (double)1e-6;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll arr[maxn];
ll big[maxn], small[maxn];

ll fac[maxn];

/* 计算fac[], fac[n]为n的阶乘 */
void calfac() {
    fac[0] = fac[1] = 1;
    for (ll i = 2; i < maxn; i++) fac[i] = (fac[i-1] * i) % mod;
}

/* 求 ax + by = gcd(a,b) 的解 x,y */
ll exgcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    ll r = exgcd(b, a%b, x, y);  //调用后, x和y的值就会变成x2,y2
    ll x2 = x, y2 = y;  //先保存x2,y2的值
    x = y2;
    y = x2 - (a/b)*y2;
    return r;  // r就是 gcd(a,b)
}

/* 求a关于 mod b的 multiplicative inverse x */
/* ax = 1 (mod b) */
ll getinv(ll a, ll b) {
    ll x,y;
    exgcd(a,b,x,y);
    return (x + b) % b;  //防止出现负数
}

/* 计算 C(n,r), 本质上计算 (n!/r!/(n-r)!) % mod */
ll comb(ll n, ll r) {
    return ((fac[n] * getinv(fac[r], mod)) % mod * getinv(fac[n-r], mod)) % mod;
}

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

    ll n,k; cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    sort(arr+1, arr+n+1);
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    calfac();

    small[0] = big[0] = 0;
    for (int i = 1; i <= n; i++) {
        small[i] = (arr[i] + small[i-1]) % mod;
        big[i] = (big[i-1] + arr[n-i+1]) % mod;
    }

    ll ans = 0;
    for (ll len = n-2; len >= k-2; len--) {
        ll cnt = n-1-len;
        // cout << "now len is " << len << " , k-2 is " << k-2 << endl;
        ll tmp = big[cnt] - small[cnt];
        if (tmp < 0) tmp = tmp - (tmp/mod)*mod;
        while (tmp < mod) tmp += mod;
        ans = ( ans + (tmp * comb(len, k-2)) % mod ) % mod;
    }
    if (ans < 0) ans += mod;
    cout << ans << endl;

}

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

using namespace std;

struct xyz {
    int num;    //要素の値
    int cnt;    //要素の個数
};

int main()
{
    //入力
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    //xに0,2,4...番目のデータを、yに1,3,5...番目のデータを入れる
    vector<int> x;
    vector<int> y;
    for(int i = 0; i < n; i += 2) {
        x.push_back(v[i]);
    }
    for(int i = 1; i < n; i += 2) {
        y.push_back(v[i]);
    }
    
    //x,yをソート
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    //x,yの重複している値とその要素の個数をそれぞれax,ayに格納する
    vector<xyz> ax;
    vector<xyz> ay;
    if(x.size() == 1) {
        xyz tmp = {x[0], 1};
        ax.push_back(tmp);
    }
    else {
        for(int i = 0; i < x.size() - 1; i++) {
            int cnt = 1;
            while(x[i] == x[i + 1]) {
                cnt++;
                i++;
            }
            xyz tmp = {x[i], cnt};
            ax.push_back(tmp);
        }
    }
    
    if(y.size() == 1) {
        xyz tmp = {y[0], 1};
        ay.push_back(tmp);
    }
    else {
        for(int i = 0; i < y.size() - 1; i++) {
            int cnt = 1;
            while(y[i] == y[i + 1]) {
                cnt++;
                i++;
            }
            xyz tmp = {y[i], cnt};
            ay.push_back(tmp);
        }
    }
    
    //ax,ayを個数が多い順にソート
    sort(ax.begin(), ax.end(), [](const xyz &c, const xyz &d){return c.cnt > d.cnt;});
    sort(ay.begin(), ay.end(), [](const xyz &c, const xyz &d){return c.cnt > d.cnt;});
    
    //もし最頻値が同じ場合は、ax[1],ay[1]のうち頻出度の高い値を採用
    if(ax[0].num == ay[0].num) {
        if(ax.size() == 1 && ay.size() == 1) {
            cout << n / 2;
        }
        else if(ax.size() == 1) {
            cout << x.size() - ax[0].cnt + y.size() - ay[1].cnt;
        }
        else if(ay.size() == 1) {
            cout << x.size() - ax[1].cnt + y.size() - ay[0].cnt;
        }
        else {
            if(ax[1].cnt > ay[1].cnt) {
                cout << x.size() - ax[1].cnt + y.size() - ay[0].cnt;
            }
            else {
                cout << x.size() - ax[0].cnt + y.size() - ay[1].cnt;
            }
        }
    }
    else {
        cout << x.size() - ax[0].cnt + y.size() - ay[0].cnt;
    }
    
    return 0;
}


Measured memory_bytes: 2168