akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

//deque型の問題、flag管理も重要
int main(){
    string s;
    cin >> s;
    deque<char> dS(s.size());
    for(int i = 0;i < s.size();++i)
        dS[i] = s[i];
    ll N;
    cin >> N;

    int fla=0;

    for(ll i = 0;i < N;i++){
        int query;
        cin >> query;
        if(query == 2){
            int zengo;
            char c1;
            cin >> zengo >> c1;
            --zengo;
            if(fla) zengo = 1 - zengo;
            if(zengo)
                dS.push_back(c1);
            else
                dS.push_front(c1);
        }else{
            fla = 1 - fla;
        }
    }

    if(fla)
        reverse(dS.begin(),dS.end());
    for(auto c:dS)
        cout << c;
    cout << endl;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n;
map<string, int> ma;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        string s;
        cin >> s;
        sort(ALL(s));
        ma[s]++;
    }
    ll res = 0;
    FORALL(it, ma) {
        ll k = it->SE;
        res += k * (k-1) / 2;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	pair<int, int> p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i].first;
		p[i].second=i+1;
	}
	sort(p,p+n);
	for(int i=0;i<n;i++)
	{
		cout<<p[i].second<<" ";
	}
		
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstring> 
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
#include<limits.h>
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

const int limit = 1e5+1;

long long int dp[101][limit];

long long int dfs(int depth,int capacity,int n,long long int w[],long long int v[]){
    // メモ化してたら返す
    if(dp[depth][capacity]>=0) return dp[depth][capacity];

    long long int res;
    if(depth == n){
        // 全て考慮した
        res = 0;  
    } else if(w[depth]>capacity){
        // 入らないので次に行く
        res = dfs(depth+1,capacity,n,w,v);
    } else {
        // 入れる場合と入れない場合の両方試す
        res = max(dfs(depth+1,capacity-w[depth],n,w,v)+v[depth]
                 ,dfs(depth+1,capacity,n,w,v));
    }
    return dp[depth][capacity]=res;
}


int main(){
    int n;
    long long int w[limit],v[limit];

    long long int W;cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    memset(dp,-1,sizeof(dp));

    p(dfs(0,W,n,w,v))
}

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

int main()
{
	ll S;
	cin >> S;
	if (S == ll(1e18))
	{
		cout << "0 0 0 1000000000 1000000000 0" << endl;
		return 0;
	}
	ll H = 1000000000;
	ll W = S / H + ll(1);
	ll a = S % 1000000000;
	cout << "1 0 0 " << H << " " << W << " " << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
//const long long mod = 1000000007;
//const long long mod = 998244353;

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	std::vector<int>* p = new std::vector<int>[N];
	for (int i = 0; i < M; i++) {
		int s, t;
		scanf("%d %d", &s, &t);
		p[s - 1].push_back(t - 1);
	}
	double*P = new double[N];
	for (int i = 0; i < N; i++)P[i] = 0;
	P[0] = 1;
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < p[i].size(); j++) {
			P[p[i][j]] += P[i] / p[i].size();
		}
	}
	double*E = new double[N];
	E[N - 1] = 0;
	double best = N;
	for (int i = N - 2; i >= 0; i--) {
		double sum = 0;
		for (int j = 0; j < p[i].size(); j++) {
			sum += E[p[i][j]];
		}
		E[i] = sum / p[i].size() + 1;
		if (p[i].size() == 1)continue;
		for (int j = 0; j < p[i].size(); j++) {
			double d = (sum - E[p[i][j]]) / (p[i].size() - 1) + 1 - E[i];
			if (best > d*P[i])best = d * P[i];
		}
	}
	if (best < 0) {
		printf("%f", E[0] + best);
	}
	else {
		printf("%f", E[0]);
	}
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
vector <ll> vec;
ll n, s;
bool cmp(ll x, ll y)
{
	return x > y;
}
ll f(ll b, ll n)
{
	if (n < b) return n;
	return f(b, n / b) + n % b;
}
int main()
{
	cin >> n >> s;
	if (n < s)
	{
		cout << -1 << endl;
		return 0;
	}
	if (n == s)
	{
		cout << n + 1 << endl;
		return 0;
	}
	for (ll i = 2; i * i <= n; i++)
	{
		if(f(i,n) == s)
		{
			cout << i << endl;
			return 0;
		}
	}
	ll y = n - s;
	for (ll j = 1; j * j <= y; j++)
		if (y % j == 0)
			vec.push_back(j), vec.push_back(y / j);
	sort(vec.begin(), vec.end(), cmp);
	for (ll j = 0; j < vec.size(); j++)
	{
		ll b = y / vec[j] + 1;
		if (f(b, n) == s)
		{
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
bool visit[MAXN];

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    vector<pii> V1;
    for (int i = 0; i < N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        V1.push_back(make_pair(b, a));
    }
    sort(V1.rbegin(), V1.rend());
    LL sum = 0, ans = 0, cnt = 0;
    vector<int> V2;
    for (int i = 0; i < K; i++) {
        sum += V1[i].first;
        if (visit[V1[i].second]) V2.push_back(V1[i].first);
        else cnt++;
        visit[V1[i].second] = 1;
    }
    for (int i = K; i < N; i++) {
        ans = max(ans, sum + cnt * cnt);
        int cur = V1[i].second;
        if (visit[cur] || V2.empty()) continue;
        visit[cur] = 1;
        sum = sum - V2.back() + V1[i].first;
        V2.pop_back();
        cnt++;
    }
    ans = max(ans, sum + cnt * cnt);
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

#define vi vector<int>
#define pb push_back
#define lli long long int
#define INF 1000000001

void solve() {
	int n, k;
	cin >> n >> k;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr + 0, arr + n);
	int sum = 0;
	for (int i = 0; i < k; i++)sum += arr[i];

	cout << sum << endl;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--) {
	solve();

	// }



	return 0;

}

Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main ()
{
  long long n;
  cin >> n;
  long ans=0;
  long now=1;
  for(long i=0;i<n;i++){
    long bric; cin>>bric;
    if(bric != now) ans++;
    else if(bric == now) now++;
  }
  if(ans==n){
    cout << -1 << endl;
  }else{cout << ans << endl;}
 return 0;
}

Measured memory_bytes: 256
x,k,d = map(int,input().split())
ch = k%2
ans = abs(x)
cnt = 0
while True:
    if x == 0:
        if (cnt%2) == ch:
            print(0)
            break
        else:
            print(abs(d))
            break
    if x > 0:
        if x//d > k:
            print(x-k*d)
            break
        cnt += x//d
        x -= d*(x//d)
        xx = x - d
        if cnt%2 == ch:
            print(abs(x))
        else:
            print(abs(xx))
        break
    elif x < 0:
        if abs(x)//d > k:
            print(abs(x+k*d))
            break
        cnt += abs(x)//d
        x += d*(abs(x)//d)
        xx = x + d
        if cnt%2 == ch:
            print(abs(x))
        else:
            print(abs(xx))
        break

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

int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    deque<char> dq(S.size());

    for(int i = 0; i < S.size(); i++) {
        dq[i] = S[i];
    }

    vector<int> T(Q);
    vector<int> F(Q);
    vector<char> C(Q);
    for(int i = 0; i < Q; i++) {
        cin >> T[i];
        if(T[i] == 2) { cin >> F[i] >> C[i]; }
    }
    int flag = 0;
    for(int i = 0; i < Q; i++) {
        if(T[i] == 1) { flag = 1 - flag; }
        else if(T[i] == 2 && F[i] == 1) {
           if(flag == 1) { dq.push_back(C[i]); }
           else{ dq.push_front(C[i]); } 
        }
        else if(T[i] == 2 && F[i] == 2) {
            if(flag == 1) { dq.push_front(C[i]); }
            else{ dq.push_back(C[i]); }
        }
    }

    if(flag == 1) reverse(dq.begin(),dq.end());
    for(int i = 0; i < dq.size(); i++) {
        cout << dq[i];
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define inf 1e17
#define MAX_SIZE 1000005 

void pr(int arr[], int size) 
{ for (ll i=0; i < size; i++) {printf("%d ", arr[i]); }cout << endl;}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  ll a , b , n;
  cin >> a >> b >> n;
  ll x;
  if(n < b){
      x = n;
  }
  else{
      x = b - 1;
  }
  ll p = a*x;
  p /= b;
  ll q = x / b;
  q *= a;
  cout << p - q << endl;
  return 0;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int[] H)
        {
            var items = new int[N][];
            for (int i = 0; i < N; ++i) { items[i] = new[] { H[i], i }; }
            int count = 0;
            while (true)
            {
                items = items.OrderByDescending(i => i[0]).ThenBy(i => i[1]).ToArray();
                if (items[0][0] == 0) { break; }
                ++count;
                --items[0][0];
                for (int i = 1; i < N && items[i][0] > items[0][0]; ++i)
                {
                    --items[i][0];
                    if (items[i][1] > items[i - 1][1] + 1) { ++count; }
                }
            }
            return count;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] H = ReadInts();
            Console.WriteLine(Solve(N, H));
        }
    }
}


Measured memory_bytes: 11476
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n,d;
string k;
ll dp[10003][103][2];



int main() {
	cin >> k;
	cin >> d;
	ll goukei = 0;
	dp[0][0][0] = 1;
	rep(i, 0, k.size()) {
		n = ll(k[i]) - ll('0');
		goukei += n; goukei %= d;
		dp[i + 1][goukei][0] = 1;
	}
	rep(i, 0, k.size()) {
		n = ll(k[i]) - ll('0');
		rep(j, 0, d) {
			rep(l, 0, n) {
				dp[i + 1][(j + l) % d][1] += dp[i][j][0];
				dp[i + 1][(j + l) % d][1] %= MOD;
			}
			rep(l, 0, 10) {
				dp[i + 1][(j + l) % d][1] += dp[i][j][1];
				dp[i + 1][(j + l) % d][1] %= MOD;
			}

		}
	}
	printf("%lld\n", (MOD + (dp[k.size()][0][0] + dp[k.size()][0][1]) % MOD - 1) % MOD);
}

Measured memory_bytes: 16384
import sys

input = sys.stdin.readline


def main():
    s = input().rstrip()
    N = len(s)
    ans = ""

    for i in range(N):
        if s[i] == "B":
            ans = ans[:-1]
        else:
            ans += s[i]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
using namespace std;


using vc = vector<char>;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void process(const string& t) {
}

int main() {
  int t, n;
  string s;
  int x, y;
  int ans = 0;
  int k;
  while (cin >> n >> k) {
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < k; ++i)
      ans += v[i];
    cout << ans << endl;

  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int X,Y;
 cin >> X >> Y;
 if(X*4 >= Y and Y/2 >= X and Y%2 == 0){
  cout << "Yes" << endl;
 }else{
  cout << "No" << endl;
 }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  string S;
  cin >> S;
  int l = S.size();
  REP(i, l){
    cout << 'x';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#define LL long long
using namespace std;
const int maxn = 1e3 + 10;

struct node
{
	LL x, y;
}q[maxn];
int n;
LL b[40];
char ANS[40];
int main()
{
	scanf("%d", &n);
	int c = 0;
	for(int i = 1; i <= n; i ++)
	{
		scanf("%lld %lld", &q[i].x, &q[i].y);
		if((q[i].x + q[i].y) % 2 == 0)
			c --;
		else
			c ++;
	}
	if(abs(c) != n)
	{
		cout << -1;
		return 0;
	}
	int cnt = 32;
	if(c < 0)
		b[33] = 1, cnt ++;
	b[1] = 1;
	for(LL i = 2, temp = 1; i <= 32; i ++)
	{
		temp *= 2;
		b[i] = temp;
	}
	cout << cnt << endl;
	for(int i = 1; i <= cnt; i ++)
		cout << b[i] << " ";
	cout << endl;
	for(int i = 1; i <= n; i ++)
	{
		if(c < 0)
			ANS[cnt] = 'R', q[i].x --;
		for(int j = 32; j >= 1; j --)
		{
			if(abs(q[i].x) >= abs(q[i].y))
			{
				if(q[i].x > 0)
					ANS[j] = 'R', q[i].x -= b[j];
				else
					ANS[j] = 'L', q[i].x += b[j];
			}
			else
			{
				if(q[i].y > 0)
					ANS[j] = 'U', q[i].y -= b[j];
				else
					ANS[j] = 'D', q[i].y += b[j];
			}
		}
		for(int j = 1; j <= cnt; j ++)
			cout << ANS[j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
   long long  X, Y, A, B ,C;
   cin >> X >> Y >> A >> B >> C;
   vector<long long> p(A);
   vector<long long> q(B);
   vector<long long> r(C);
   for(int i = 0; i < A; i++) cin >> p[i];
   for(int i = 0; i < B; i++) cin >> q[i];
   for(int i = 0; i < C; i++) cin >> r[i];
   sort(p.begin(), p.end());
   sort(q.begin(), q.end());
   sort(r.begin(), r.end());
   reverse(r.begin(), r.end());
   reverse(p.begin(), p.end());
   reverse(q.begin(), q.end());
   priority_queue<long long> s;
   for(int i = 0; i < X; i++) s.push(p[i]);
   for(int i = 0; i < Y; i++) s.push(q[i]);
   for(int i = 0; i < C; i++) s.push(r[i]);
   long long ans = 0;
   for(int i = 0; i < X + Y; i++){
       ans += s.top();
       s.pop();
   }
   cout << ans << endl;
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int N;cin>>N;
  int W[N+10];
  int sum_w=0;
  REP(i,N) {
    cin>>W[i];
    sum_w+=W[i];
  }
  int res=sum_w;
  for(int j=1;j<N+1;++j) {
    int s1 = accumulate(W,W+j,0);
    int s2 = sum_w - accumulate(W,W+j,0);
    res = min(res,abs(s1-s2));
  }
  pr(res);
  return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 7;
const LL LINF = INF * INF;

int n, k;
int a[107];
char dp[100007];

char get(int x)
{
	if (dp[x] != -1)
		return dp[x];
	
	bool ok = 0;
	FOR(i, 0, n)
		if (x >= a[i] && !get(x - a[i]))
			ok = 1;
	
	return dp[x] = ok;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n >> k;
	FOR(i, 0, n)
		cin >> a[i];

	FILL(dp, -1);
	if (get(k))
		cout << "First" << endl;
	else
		cout << "Second" << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int M,K;
  cin>>M>>K;
  if(M==0){
    if(K==0) cout<<"0 0"<<endl;
    else cout<<-1<<endl;
  }else if(M==1){
    if(K==0) cout<<"0 0 1 1"<<endl;
    else cout<<-1<<endl;
  }else if(K<pow(2,M)){
    ll c=0;
    while(c<pow(2,M)){
      if(c!=K) cout<<c<<" ";
      c++;
    }
    cout<<K<<" ";
    while(c>0){
      c--;
      if(c!=K) cout<<c<<" ";
    }
    cout<<K<<" "<<endl;;
  }else cout<<-1<<endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> c(n), p(n);
    rep(i,n) cin >> p.at(i);
    rep(i,n) cin >> c.at(i);
    rep(i,n) p.at(i)--;
    ll ans = -1e18;
    rep(start,n) {
        int pos = start;
        vector<int> vt;
        ll total = 0;
        while (true) {
            pos = p.at(pos);
            vt.push_back(c.at(pos));
            total += c.at(pos);
            if (pos == start) break;
        }
        int cycle = vt.size();
        ll now = 0;
        rep(i,cycle) {
            now += vt.at(i);
            ll s = now;
            // 1周しない分が i+1 step
            if (k < i+1) break;
            if (total > 0) {
                ll e = (k-i-1)/cycle;
                s += total * e;
            }
            ans = max(ans, s);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3680
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
  int n,d;
  cin >> n >> d;
  int a,b;
  int count = 0;
  rep1(i, n){
    cin >> a >> b;
    if(sqrt(pow(a,2) + pow(b,2)) <= d){
      count += 1;
    }
  }
  cout << count;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define TP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define int long long
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int d[101][101];
bool used[101];

int N, T, F, M, S, G;
int freezer[101];

int memo[101][101][101];

int dfs(int depth, int from, int t)
{
    if (~memo[depth][from][t]) return memo[depth][from][t];

    int mi = inf;

    rep(i, F) {
        int frzr = freezer[i];

        if (used[frzr] || d[from][frzr] > T) continue;

        int cost = d[from][frzr];

        if (d[from][frzr] > t) {
            cost += d[from][frzr] - t;
        }

        if (d[frzr][G] <= T) {
            int now_t = max(t - d[from][frzr], 0ll);
            int heal = max(d[frzr][G] - now_t, 0ll);
            chmin(mi, cost + heal + d[frzr][G]);
        } else {
            used[frzr] = true;

            chmin(mi, cost + dfs(depth + 1, frzr, max(t - d[from][frzr], 0ll)));

            used[frzr] = false;
        }
    }

    return memo[depth][from][t] = mi;
}

signed main()
{
    int cnt = 0;
    while (cin >> N >> T >> F >> M >> S >> G, N || T || F || M || S || G) {
        memset(memo, -1, sizeof(memo));
        rep(i, F) cin >> freezer[i];

        rep(i, N) rep(j, N) d[i][j] = i == j ? 0 : inf;

        rep(i, M) {
            int x, y, t;
            cin >> x >> y >> t;
            d[x][y] = d[y][x] = t;
        }

        rep(k, N) {
            rep(i, N) {
                rep(j, N) {
                    chmin(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        if (d[S][G] <= T) {
            cout << d[S][G] << endl;
        } else {
            int a = dfs(0, S, T);

            if (a == inf) cout << "Help!\n";
            else cout << a << endl;
        }
    }
}

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

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

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

  int keta = n%10;
  if(keta==2||keta==4||keta==5||keta==7||keta==9) cout << "hon";
  else if(keta==3) cout << "bon";
  else cout << "pon";
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.max(a * b, c * d));
		sc.close();
	}
}

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

int main(){

	string s, c = "01"; 
	int cont0 = 0, cont1 = 0;
	cin >> s;
	
	for(auto i : s){

		if (i==c[0]) cont0++;
		else cont1++;
	}
	printf("%d\n", 2*min(cont0,cont1));
	return 0;
}


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

int main() {
  int A,B,C,D ;
  cin >> A >> B >> C >> D ;
  int L = A + B ;
  int R = C + D ;
  if (L > R) {
    cout << "Left" << endl ;
  }
  if (L == R) {
    cout << "Balanced" << endl ;
  }
  if (L < R) {
    cout << "Right" << endl ;
  }
}

Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	cout<<(n*n-n)/2<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n+1), b(n+1);
    a[0] = 0;
    for(int i = 1; i <= n; i++){
        std::cin >> a[i];
    }

    for(int i = n; i > 0; i--){
        int cnt = 0;
        for(int j = i; j <= n; j += i){
            if(b[j] == 1) cnt++;
        }
        cnt = cnt % 2;
        if(cnt != a[i]) b[i] = 1;
    }
    int zcnt = 0;
    for(int i = 1; i <= n; i++){
        if(b[i] == 1){
            zcnt++;
        }
    }
    std::cout << zcnt << std::endl;
    for(int i = 1; i <= n; i++){
        if(b[i] == 1){
            std::cout << i << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 4728
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

S = input()

S = S.replace('apple', '1145141919')
S = S.replace('peach', 'apple')
S = S.replace('1145141919', 'peach')

print(S)



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

int main(void){
    int n;
    string s;
    cin >> n >> s;
    int a[26] = {};
    for(int i = 0;i < n;i++)a[s[i]-'a']++;
    long long ans = 1;
    for(int i = 0;i < 26;i++){
        if(a[i] == 0)continue;
        ans = ans * (a[i]+1) % 1000000007;
    }
    cout << ans - 1;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string A, B;
    cin >> A >> B;
    
    if(A.length() > B.length()){
        cout << "GREATER" << endl;
    }else if(A.length() < B.length()){
        cout << "LESS" << endl;
    }else{
        if(A == B){
            cout << "EQUAL" << endl;
        }else{
            for(ll i = 0; i < A.length(); i++){
                if(A[i] > B[i]){
                    cout << "GREATER" << endl;
                    return 0;
                }
                if(A[i] < B[i]){
                    cout << "LESS" << endl;
                    return 0;
                }
            }
        }
    }
     
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int S;
struct Combination{
    int MAX_N;
    int MOD;
    int *fac, *finv, *inv;
    Combination(int max_n,int MOD): MAX_N(max_n+1),MOD(MOD){ //make table
        fac = new int[MAX_N];finv = new int[MAX_N];inv = new int[MAX_N];
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for (int i = 2; i < MAX_N; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    int COM(int n,int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    void free_COM(){
        delete[] fac;
        delete[] finv;
        delete[] inv;
    }
    
};

signed main(){
    scanf("%lld",&S);
    int ans=0;
    Combination comb(S,mod);
    for(int i=1;i<=S;i++){
        int wakeru=S-3*i;
        if(wakeru<0)break;
        if(wakeru==0){ans+=1;continue;}
        //wakeru個をiのグループに分ける(0このグループがあっても良い)
        //wakeruこのoとi-1個の×を並べる並べ方
        int sans=comb.COM(wakeru+i-1,i-1);
        ans+=sans;
        ans%=mod;
    }
    printf("%lld\n",ans%mod);
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
    string s,d,f;
cin>>s>>d>>f;
cout <<(char)((int)s[0]-32)<<(char)((int)d[0]-32)<<(char)((int)f[0]-32);
}



Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	double A, B;
	double aMin, bMin, result;
	boolean enable = true;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		A = Double.parseDouble(tokens[0]);
		B = Double.parseDouble(tokens[1]);

		aMin = Math.floor(A / 0.08);
		if (aMin * 0.08 < A) {
			aMin += 1.0;
		}
		bMin = Math.floor(B / 0.1);
		if (bMin * 0.1 < B) {
			bMin += 1.0;
		}
		enable = check();

	}

	boolean check() {
		if ((int) Math.floor(aMin * 0.08) != (int) A) {
			return false;
		}
		if ((int) Math.floor(bMin * 0.1) != (int) B) {
			return false;
		}
		return true;

	}

	void calc() {
		if (!enable) {
			return;
		}
		result = Math.max(aMin, bMin);
		aMin = result;
		bMin = result;
		enable = check();
	}

	void showResult() {
		if (enable) {
			System.out.println((int) result);
		} else {
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main() {
	int k, s;
	cin >> k >> s;
	int count = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			
				if (z >= 0 && k>=z) {
					count++;
				
			     }
		}
	}
	cout << count << endl;
	return 0;
}

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

const int maxn=20010;
int a[maxn],b[maxn];
int n,c[maxn],d[maxn];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		c[x]=i;
	}
	for (int i=2;i<=n;i++)
		d[i]=c[i]-c[i-1];
	for (int i=2;i<=n;i++)
	{
		if (d[i]<=0)
		{
			a[i]=1;
			b[i]=d[i]-a[i];
		}	else
		{
			b[i]=-1;
			a[i]=d[i]-b[i];
		}
	}
	for (int i=2;i<=n;i++)
	{
		a[i]=a[i]+a[i-1];
		b[i]=b[i]+b[i-1];
	}
	int minx=0;
	for (int i=1;i<=n;i++)
		minx=min(minx,min(a[i],b[i]));
	if (minx<=0)
	{
		for (int i=1;i<=n;i++)
		{
			a[i]+=-minx+1;
			b[i]+=-minx+1;
		}
	}
	for (int i=1;i<n;i++)	printf("%d ",a[i]);
	printf("%d\n",a[n]);
	for (int i=1;i<n;i++)	printf("%d ",b[i]);
	printf("%d\n",b[n]);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=100000000;
const int MAX_N=200000;
int main(){
  int N,K; cin>>N>>K;
  int A[MAX_N];
  for(int i=0;i<MAX_N;i++)
    A[i]=0;
  for(int i=0;i<N;i++){
    int a; cin>>a;
    A[a]++;
  }
  for(int i=0;i<MAX_N;i++)
    if(A[i]==0) A[i]=INF;
  sort(A,A+MAX_N);
  int type_num=0;
  for(int i=0;i<MAX_N;i++){
    if(A[i]==INF) break;
    type_num++;
  }
  int res=0;
  if(type_num>K){
    for(int i=0;i<type_num-K;i++)
      res+=A[i];
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1024
import bisect
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    N = int(input())
    A = deque([int(input())])
    for k in range(N-1):
        t = int(input())
        if A[0] >= t:
            A.appendleft(t)
        else:
            A[bisect.bisect_left(A,t)-1] = t
    print(len(A))

if __name__ == '__main__':
    main()


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

using namespace std;

using LL = long long;

string s;
int K;

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

    cin >> s >> K;

    if (s[0] != s.back() ) {
        int ans = 0;
        for (int i = 0; i < (int)s.size(); ) {
            int nxtI = i + 1;
            while (nxtI < (int)s.size() && s[nxtI] == s[i]) ++nxtI;
            ans += (nxtI - i) / 2;
            i = nxtI;
        }
        cout << (LL)ans * K;
    }
    else {
        bool full = 1;
        for (int i = 0; i < (int)s.size(); ++i) if (s[i] != s[0]) full = 0;
        if (full) {
            cout << (LL)s.size() * K / 2;
        }
        else {
            int l = 0;
            while (s[l] == s[0]) ++l;
            int r = (int)s.size();
            while (s[r - 1] == s[0]) --r;

            int ans = 0;
            for (int i = l; i < r; ) {
                int nxtI = i + 1;
                while (nxtI < r && s[nxtI] == s[i]) ++nxtI;
                ans += (nxtI - i) / 2;
                i = nxtI;
            }

            cout << (LL)ans * K + l / 2 + ( (int)s.size() - r) / 2 + (LL)(l + (int)s.size() - r) / 2 * (K - 1);
        }
    }

    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
	vint P(A), Q(B), R(C); cin >> P >> Q >> R;
	sort(rbegin(P), rend(P));
	sort(rbegin(Q), rend(Q));
	sort(rbegin(R), rend(R));
	
	priority_queue<int, vector<int>, greater<int>> que;
	ll sum = 0;
	for (int i = 0; i < X; i++) {
		que.push(P[i]);
		sum += P[i];
	}
	for (int i = 0; i < Y; i++) {
		que.push(Q[i]);
		sum += Q[i];
	}
	for (int i = 0; i < C; i++) {
		if (!que.empty() && que.top() < R[i]) {
			sum -= que.top();
			sum += R[i];
			que.pop();
		}
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main() {
  int K, S;
  cin >> K >> S;

  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      int tmp = S - (i + j);
      if (0 <= tmp && tmp <= K) {
        ++ans;
      }
    }
  }

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


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

auto chmin = [](auto&& l, auto r) { return r < l ? l = r, 1 : 0; };

constexpr long long inf = 1e10;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  long long t;
  cin >> n >> t;
  vector<long long> a(n), b(n);
  vector<int> idx, zero;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    if (a[i] == 0) {
      zero.push_back(i);
    } else {
      idx.push_back(i);
    }
  }
  sort(begin(idx), end(idx), [&](int i, int j) {
    return (b[i] + 1) * a[j] < (b[j] + 1) * a[i];
  });
  sort(begin(zero), end(zero), [&](int i, int j) {
    return b[i] < b[j];
  });
  vector<long long> dp(33, inf);
  dp[0] = 0;
  for (int i : idx) {
    auto ndp = dp;
    for (int x = 0; x < 32; ++x) {
      if (dp[x] < inf) {
        chmin(ndp[x + 1], dp[x] + 1 + a[i] * (dp[x] + 1) + b[i]);
      }
    }
    swap(dp, ndp);
  }
  int res = 0;
  for (int x = 0; x < 33; ++x) {
    if (dp[x] <= t) {
      int cur = x;
      long long rest = t - dp[x];
      for (int i : zero) {
        if (rest >= b[i] + 1) {
          rest -= b[i] + 1;
          ++cur;
        }
      }
      res = max(res, cur);
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 4600
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n - 1):
    if p[i] == i + 1:
        p[i], p[i + 1] = p[i + 1], p[i]
        count += 1
if p[n - 1] == n:
    count += 1
print(count)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 int mod = 1000000007;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll k; cin>>k;
    string s; cin>>s;
    ll n = sz(s);

    vector<mint> as, bs;
    as.push_back(1);
    bs.push_back(1);
    rep(i, 1e6 + 100) {
        as.push_back(as.back() * 25);
        bs.push_back(bs.back() * 26);
    }

    combination comb(2 * 1e6 + 100);
    mint ans = 0;
    rep(i, k + 1) {
        mint c = comb(n + i - 1, n - 1);
        c *= as[i];
        c *= bs[k - i];
        ans += c;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 51916
#include <iostream>
using namespace std;
int main(){
  string s;                                   
  cin >> s;
  if(s=="Sunny") cout << "Cloudy" << "\n";
  else if(s=="Cloudy") cout << "Rainy" << "\n";    
  else cout << "Sunny" << "\n";
  return 0;
}

Measured memory_bytes: 3508
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;


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

	int total = 0;
			
			if (a + b <= 2 * c) {
				total = a * x + b * y;
			}
			
			if (a+b>2*c) {
				if (x >= y) {
					if (2 * x * c<= 2 * c * y + a * (x - y)) {
						total = 2 * x * c;
					}
					else {
						total = 2 * c * y + a * (x - y);
					}
				}
				else if (x < y) {
					if (2 * c * y <= 2 * c * x + b * (y - x)) {
						total = 2 * c * y;
					}
					else {
						total = 2 * c * x + b * (y - x);
					}
				}
			}
		
			cout << total << endl;

	return 0;
}


Measured memory_bytes: 3624