akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };




int main() {
	int a, b;
	cin >> a >> b;

	vector<int>s;
	s.pb(2*a-1);
	s.pb(2 * b-1);
	s.pb(a + b);
	sort(all(s));
	cout << s[2] << endl;

	return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> now = a;
    while(true){
        vector<ll> imos(n + 1, 0);
        for(ll i = 0; i < n; i++){
            imos[max(0LL, i - now[i])]++;
            imos[min(n - 1, i + now[i]) + 1]--;
        }
        for(ll i = 0; i < n; i++){
            if(i > 0) imos[i] += imos[i - 1];
        }

        k--;

        if(now == imos || k == 0){
            for(ll i = 0; i < n; i++){
                cout << imos[i] << " ";
            }
            cout << endl;
            return 0;
        } else {
            now = imos;
        }

    }
}


Measured memory_bytes: 9540
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

/*
    A xor B = C
    C xor A = B

    a, b
    0~b(A)と0~a-1(B)のxorを計算して
    A xor B = C(a~bのxor)

    0からのxorを計算するときに、0と1は1, 2と３は1という法則を使うと楽
*/

ll solve(ll a){
    ll cnt = (a+1)/2;
    ll ans = cnt % 2;
    if(a%2==0) ans ^= a;
    return ans;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans;
    ans = solve(b) ^ solve(a-1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"

class TOPO{//out is tsort's return.
	public:
	vvi G;
	vi out;
	vector<bool>V;
	vi indeg;
	int n;
	TOPO(int size){
		n=size;
		G=vvi(n);
		out=vi(0);
		V=vector<bool>(n);
		indeg=vi(n);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
	}
	vi ans;
	void bfs(int s){
		queue<int>q;
		q.push(s);
		V[s]=true;
		while(!q.empty()){
			int u=q.front();q.pop();
			out.pb(u);
			rep(i,G[u].size()){
				int v=G[u][i];
				indeg[v]--;
				if(indeg[v]==0&&!V[v]){
					ans[v]=u+1;
					V[v]=true;
					q.push(v);
				}
			}
		}
	}
	vi tsort(){
		ans=vi(n);
		rep(i,n)indeg[i]=0;
		rep(i,n)rep(j,G[i].size()){
			int v=G[i][j];
			indeg[v]++;
		}
		rep(i,n)if(indeg[i]==0&&!V[i])bfs(i);
		return ans;
//		rep(i,n)cout<<out[i]<<endl;
	}
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	TOPO tp(n);
	rep(i,n+m-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		tp.add_edge(a,b);
	}
	vi out=tp.tsort();
	rep(i,n)cout<<out[i]<<endl;
}


Measured memory_bytes: 10228
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ld long double
 
using namespace std;
 
 
const int N = 2e5 + 123;
const int MAXN = 1e5 + 12;
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;


ll n, a[N], mx[21][N], len[N], pw[30], Lmx[N], Lmn[N], Rmx[N], Rmn[N];


ll get(ll l, ll r) {
    ll ln = r - l + 1;
    ll x = len[ln];
    return max(mx[x][l], mx[x][r + 1 - pw[x]]);
}

 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mx[0][i] = a[i];
        Lmx[i] = 0;
        Rmn[i] = n + 1;
    }
    ll t = 1;
    for (int i = 0; i <= 20; i++) {
        pw[i] = t;
        t *= 2;
    }
    ll cur = 0;
    for (int i = 1; i <= n; i++) {
        while (pw[cur + 1] <= i)
            cur++;
        len[i] = cur;
    }
    for (int j = 1; j <= 20; j++) {
        for (int i = 1; i <= n; i++) {
            if (pw[j] + i - 1 > n)
                break;
            mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + pw[j - 1]]);    
        }
    }
    for (int i = 1; i <= n; i++) {
        ll L, R, M;
        L = 1, R = i - 1;
        while (L <= R) {
            M = (L + R) / 2;
            if (get(M, i) == a[i])
                R = M - 1;
            else {
                Lmx[i] = max(Lmx[i], M);
                L = M + 1;
            }
        }
        if (Lmx[i] == 0)
            continue;
        Lmn[i] = Lmx[i];
        L = 1; R = Lmx[i] - 1;
        while (L <= R) {
            M = (L + R) / 2;
            if (get(M, Lmx[i] - 1) < a[i]) {
                Lmn[i] = min(Lmn[i], M);
                R = M - 1;
            } else
                L = M + 1;
        }
    }
    for (int i = n; i >= 1; i--) {
        ll L, R, M;
        L = i + 1, R = n;
        while (L <= R) {
            M = (L + R) / 2;
            if (get(i, M) == a[i])
                L = M + 1;
            else {
                Rmn[i] = min(Rmn[i], M);
                R = M - 1;
            }
        }
        if (Rmn[i] == n + 1)
            continue;
        L = Rmn[i] + 1; R = n;
        Rmx[i] = Rmn[i];
        while (L <= R) {
            M = (L + R) / 2;
            if (get(Rmn[i] + 1, M) < a[i]) {
                Rmx[i] = max(Rmx[i], M);
                L = M + 1;
            } else
                R = M - 1;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (Lmx[i] != 0)
            ans += a[i] * (Lmx[i] - Lmn[i] + 1) * (Rmn[i] - i);
        if (Rmn[i] != n + 1)
            ans += a[i] * (Rmx[i] - Rmn[i] + 1) * (i - Lmx[i]);
    }
    cout << ans;
    return 0;
}

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

int main(void) {
	int a[7] = { 0 }, n, m;
	for (int i = 0; i < 7; i++) {
		cin >> n >> m;
		a[i]=n - m;
	}
	for (int i = 0; i < 7; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int n, m;
vi t;

int main()
{
	cin >> n;
	t.resize(n);
	REP(i, n)
		cin >> t[i];

	int s = accumulate(ALL(t), 0);

	cin >> m;
	REP(_i, m)
	{
		int p, x;
		cin >> p >> x;

		cout << s - t[p - 1] + x << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int> arr(n);
    multiset<int> ms;
    for(auto &x:arr)
        cin>>x, ms.insert(x);
    for(auto x:arr)
    {
        ms.erase(ms.find(x));
        cout<<*ms.rbegin()<<endl;
        ms.insert(x);
    }
    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int dp(vector<pair<int,int> > &m, vector<int> &memo, int nowh){
    if (nowh <= 0)
    {
        return 0 ;
    }
    
    if (memo.at(nowh) > -1)
    {
        return memo.at(nowh) ;
    }

    int64_t nowmin = 1000000000;
    for (size_t i = 0; i < m.size(); i++)
    {
        int64_t judge = dp(m, memo, nowh - m.at(i).first) + m.at(i).second ;
        if (judge < nowmin)
        {
            nowmin = judge ;
        }
        
    }
    memo.at(nowh) = nowmin ;
    return nowmin ;
}

int main(){
    int h , n ;
    cin >> h >> n ;
    vector<pair<int,int> > m(n,pair<int,int>(0,0)) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> m.at(i).first >> m.at(i).second ;
    }
    vector<int> memo(h+1,-1) ;

    int64_t ans = dp(m, memo, h) ;

    cout << ans << endl ;
    
}

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

struct Card {char suit, value;};

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

void selectionsort(struct Card a[],int n)           //insertionsortの実装ミス
{
    int minv = -1;
    
    for(int i = 0;i<n;i++)
    {   minv = i;
        int temp = -1;
        for(int j = i;j<n;j++)
        {
            if(a[j].value<a[minv].value)
            {
                minv = j;
            }
        }

        swap(a[i],a[minv]);
        
    }
}

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

    return true;

}

void print(struct Card a[],int n)
{
    for(int i = 0;i<n;i++){
    if(i>0)
    {
        cout << " ";
    }
    cout << a[i].suit << a[i].value;

    }

    cout << endl;

}



int main()
{
    Card c1[100],c2[100];
    int n;
    char ch;

    cin >> n;
    for(int i = 0;i<n;i++)
    {
        cin >> c1[i].suit >> c1[i].value;
    }

    for(int i = 0;i<n;i++)
    {
        c2[i] = c1[i];
    }

    bubblesort(c1,n);
    selectionsort(c2,n);

    print(c1,n);
    cout << "Stable" << endl;
    print(c2,n);
    if(isStable(c2,c1,n)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;

}


Measured memory_bytes: 3140
n,c=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
acumr=[0,arr[0][1]-arr[0][0]]
acuml=[0,arr[-1][1]-(c-arr[-1][0])]
for i in range(1,n):
  acumr.append(acumr[-1]+arr[i][1]-(arr[i][0]-arr[i-1][0]))
  acuml.append(acuml[-1]+arr[-(i+1)][1]-(arr[-i][0]-arr[-(i+1)][0]))
maxr=[0]
maxl=[0]
for i in range(1,n+1):
  maxr.append(max(maxr[-1],acumr[i]))
  maxl.append(max(maxl[-1],acuml[i]))
ans=0
for i in range(1,n+1):
  tmp1=acumr[i]
  tmp2=acuml[i]
  if arr[i-1][0]<maxl[n-i]:
    tmp1+=maxl[n-i]-arr[i-1][0]
  if c-arr[-i][0]<maxr[n-i]:
    tmp2+=maxr[n-i]-(c-arr[-i][0])
  ans=max(ans,tmp1)
  ans=max(ans,tmp2)
print(ans)

Measured memory_bytes: 38164
#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

typedef pair<string,int>P;

int main()
{
	queue<P>q;
	int n,time;
	scanf("%d%d",&n,&time);
	for(int i=0;i<n;i++){
		string name;
		int times;
		cin>>name>>times;
		q.push(make_pair(name,times));
	}
	int ans=0;
	while(!q.empty()){
		P u=q.front();
		q.pop();
		int test=min(u.second,time);
		u.second-=test;
		ans+=test;
		if(u.second==0){
			cout<<u.first<<" "<<ans<<endl;
		}else{
			q.push(u);
		}
	}
	return 0;
}


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

int N;
bool full;

vector<vector<int>> prod(const vector<vector<int>>& a, const vector<vector<int>>& b) {
	vector<vector<int>> res(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				res[i][k] ^= b[i][j] & a[j][k];
			}
		}
	}
	return res;
}

vector<vector<int>> Pow(vector<vector<int>> a, int x) {
	vector<vector<int>> res(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		res[i][i] = 1;
	}
	while (x) {
		if (x & 1) {
			res = prod(res, a);
		}
		a = prod(a, a);
		x >>= 1;
	}
	return res;
}

vector<int> solve(vector<vector<int>>& a, vector<int> v) {
	full = true;
	for (int i = 0; i < N; i++) {
		int id = -1;
		for (int j = i; j < N; j++) {
			if (a[j][i]) {
				id = j;
				break;
			}
		}
		if (id == -1) {
			full = false;
			continue;
		}
		if (id != i) {
			swap(a[i], a[id]);
			swap(v[i], v[id]);
		}
		for (int j = i + 1; j < N; j++) {
			if (a[j][i]) {
				for (int k = i; k < N; k++) {
					a[j][k] ^= a[i][k];
				}
				v[j] ^= v[i];
			}
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (a[i][i] == 0) continue;
		for (int j = 0; j < i; j++) {
			if (a[j][i]) {
				for (int k = i; k < N; k++) {
					a[j][k] ^= a[i][k];
				}
				v[j] ^= v[i];
			}
		}
	}
	return v;
}

int main()
{
	int T;
	cin >> N;
	vector<vector<int>> a(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	cin >> T;
	a = Pow(a, T);
	v = solve(a, v);
	if (!full) {
		bool none = false;
		for (int i = 0; i < N; i++) {
			bool flag = true;
			for (int j = 0; j < N; j++) {
				if (a[i][j]) {
					flag = false;
					break;
				}
			}
			if (flag && v[i]) {
				none = true;
				break;
			}
		}
		cout << (none ? "none" : "ambiguous") << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		cout << v[i] << " \n"[i + 1 == N];
	}
	return 0;
}

Measured memory_bytes: 4448
#include <stdio.h>
#include <math.h>

int  c = 0;
int *merge(int *, int, int, int);
int *mergesort(int *, int, int);


int main(){
  int n, s[500002], left, right, i;
  int *t;

  scanf("%d" ,&n);
  for(i = 0; i < n; i++) scanf("%d" ,&s[i]);

  left = 0;
  right = n;

  t = mergesort(s, left, right);

  for(i = 0; i < n - 1; i++) printf("%d " ,t[i]);
  printf("%d\n%d\n" ,t[i] ,c);  

  return 0;
}


int *merge(int *s, int left, int mid, int right){
  int le[250001], ri[250001], n1, n2, i, j, k;

  n1 = mid - left;
  n2 = right - mid;
  
  for(i = 0; i <  n1; i++) le[i] = s[left + i];
  for(i = 0; i <  n2; i++) ri[i] = s[mid + i];

  le[n1] = pow(10, 9) + 1;
  ri[n2] = pow(10, 9) + 1;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    if(le[i] <= ri[j]){
      s[k] = le[i];
      i++;
      c++;
    }
    else{
      s[k] = ri[j];
      j++;
      c++;
    }    
  }

  return s;
}

int *mergesort(int *s, int left, int right){
  int mid;
  int *t;

  if(left + 1 < right){
    mid = (left + right)/2;
    mergesort(s, left, mid);
    mergesort(s, mid, right);
    t = merge(s, left, mid, right);
    return t;
  }
}

Measured memory_bytes: 4504
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-7;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

ld getans(ld l,ld r, int b,ld c) {
	if (b == 0||abs(r-l)<eps) {
		return (1-l)*(r - l);
	}
	ld aa = getans(l,(1-c)*l+c*r, b - 1, c);
	ld ab = getans((1 - c)*l + c*r,r, b - 1, c);
	return aa + ab;
}
ld get() {
	int m, n, x; cin >> m >> n >> x;
	ld c = (ld(m)) / (m + n);
	x = min(x, 40);
	return getans(0,1, x, c);
}

int main() {
	ld a = get();
	ld b = get();
	cout << setprecision(10) << fixed << a*b << endl;
	return 0;
}

Measured memory_bytes: 3252
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > p(N);
  for (size_t i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(), p.end());
  // debug(p[0].first);
  int r = 0;
  int ans = 0;
  for (size_t i = 0; i < N; i++) {
    if (r < M) {
      ans += (M - r) < p[i].second ? (M - r)*p[i].first : p[i].second*p[i].first;
      r += (M - r) < p[i].second ? (M - r) : p[i].second;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
}

Measured memory_bytes: 90304
n = int(input())
a = list(map(int,input().split()))
wild_cnt = 0
colors = []
for i in a:
  if 1 <= i <= 399:
    colors.append("g")
  elif 400 <= i <= 799:
    colors.append("br")
  elif 800 <= i <= 1199:
    colors.append("gr")
  elif 1200 <= i <= 1599:
    colors.append("wa")
  elif 1600 <= i <= 1999:
    colors.append("bl")
  elif 2000 <= i <= 2399:
    colors.append("y")
  elif 2400 <= i <= 2799:
    colors.append("o")
  elif 2800 <= i <= 3199:
    colors.append("r")
  elif 3200 <= i:
    wild_cnt += 1
# 3200以上しか存在しない場合
if len(set(colors)) == 0:
  print(str(1) + " " + str(min(n,wild_cnt)))
else:
  print(str(len(set(colors)))+ " " +str(min(n,len(set(colors)) + wild_cnt)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll power(ll x,ll y)
{
    ll res=1;
  
    while(y>0)
    {
        if(y&1)
            res=res*x;
        res%=mod;
        y=y>>1;
        x=x*x;
        x%=mod;
    } 
    return res; 
}
ll inv(ll x)
{
    return power(x,mod-2);
}
void solve()
{
    ll n;
    cin>>n;
    ll ans=power(10,n);
    ans-=power(9,n);
    ans-=power(9,n);
    ans+=power(8,n);
    ans%=mod;
    ans+=mod;
    ans%=mod;
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 3624
s = list(str(input()))
for i in range(len(s)):
    s.pop()
    if len(s)%2 == 1:
        continue
    t = s[0:len(s)//2]
    u = s[len(s)//2:]
    t = ''.join(t)
    u = ''.join(u)
    if t == u:
        print(len(s))
        exit()


Measured memory_bytes: 61612
#include<iostream>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
int main(){
	int x;
	cin>>x;
	if(x==1)cout<<1<<' '<<0<<'\n';
	else{
		vector<int> v;
		v.push_back(1);
		for(int i=2;i<=sqrt(x);i++)if(x%i==0)v.push_back(i),v.push_back(x/i);
		long long a,b;
		for(int i=0;i<v.size();i++){
			for(int j=-5000;j<=5000;j++){
				a=j;b=j-v[i];
				//cout<<a<<' '<<b<<'\n';
				if(a*a*a*a*a-b*b*b*b*b==x){
					cout<<a<<' '<<b<<'\n';return 0;
				}
			}
		}
	}
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  string s;
  cin>>s;
  int q;
  cin>>q;
  int h,n;
  string p;
  string before="",after="";
  int k=0;
  for(int i=0;i<q;i++){
    cin>>h;
    if(h==1){
      k++;
    }
    if(h==2){
      cin>>n;
      cin>>p;
      if(n==1){
        if(k%2==0){
          before=p+before;
        }
        if(k%2==1){
          after=after+p;
        }
      }
      if(n==2){
        if(k%2==0){
          after=after+p;
        }
        if(k%2==1){
          before=p+before;
        }
      }
    }
  }
  if(k%2==1){
    reverse(s.begin(),s.end());
    reverse(before.begin(),before.end());
    reverse(after.begin(),after.end());
    /*cout<<before<<endl;
    cout<<after<<endl;*/
    s=after+s+before;
  }
  else{
    s=before+s+after;
  }
  cout<<s<<endl;    
}

Measured memory_bytes: 1320
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
n, m = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
    a = list(map(int, input().split()))    
    k[i] = a[0]
    s.append(a[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
    bit = format(i, "01024b")[::-1]
    on = True
    for j in range(m):
        cnt = 0
        for k in s[j]:
            if bit[k - 1] == "1":
                cnt += 1
        if cnt % 2 != p[j]:
            on = False
            break
    if on:
        ans += 1

print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  // aとbの積が偶数か奇数か
  if ((a*b)%2 == 0) {
    cout << "Even" << endl;
  }
  else {
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 200005
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

char s[300005] ;
int w[300005] , e[300005] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    scanf("%s",s+1) ;

    for(i=1 ; i<=n ; i++)
    {
        w[i] = w[i-1] ;
        if( s[i]=='W' ) w[i] += 1 ;
    }
    for(i=n ;i>=1 ; i--)
    {
        e[i] = e[i+1] ;
        if( s[i]=='E' ) e[i] += 1 ;
    }
    int ans = 200000 ;

    for(i=1 ; i<=n ;i++) ans = min( ans , w[i-1] + e[i+1] ) ;
//for(i=1 ; i<=n ;i++) printf("%d %d\n",w[i],e[i]) ;

    cout<<ans<<endl ;

    return 0 ;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int n,a[200001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n;i>0;i-=2)cout<<a[i]<<" ";
    for(int i=(n%2==0?1:2);i<=n-1;i+=2)cout<<a[i]<<" ";
}


Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int w,a,b ;
    scanf ("%d%d%d",&w,&a,&b) ;
    if (a+w<b){
        printf ("%d\n",b-(a+w)) ;
    } else if (b+w<a){
        printf ("%d\n",a-(b+w)) ;
    } else {
        printf ("0\n") ;
    }
    return 0 ;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a < c && c < b) || (a>c && c>b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define f first
#define s second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a)); sort(all(c));
    int res=0;

    rep(i,n){
        int up=lower_bound(all(a),b[i])-a.begin();
        int down=c.end()-upper_bound(all(c),b[i]);
        res+=up*down;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
 
 
using namespace std;
 
#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;
 
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod = 1e9+9;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}
 
//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1
 
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main(){

	#ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    string s,t;
    cin>>s>>t;
    set<char> s1;
    set<char> s2;
    int a[26][2] = {0};
    vector<vector<int> >  v(26);
    fill(a,-1);
    for(int i=0;i<t.size();i++){
    	s1.insert(t[i]);
    }
    for(int i=0;i<s.size();i++){
    	s2.insert(s[i]);
    }
    int flag = 1;
    for(auto it : s1){
    	if(s2.find(it)==s2.end()){
    		flag = 0;
    		break;
    	}
    }
    if(flag){
    	for(int i=0;i<s.size();i++){
    		v[s[i]-'a'].pb(i);
    	}

    	ll id = -1;
    	ll cnt = 0;
    	for(int i=0;i<t.size();i++){
    		vector<int> :: iterator it = upper_bound(all(v[t[i]-'a']),id);
    		if(it == v[t[i]-'a'].end()){
    			cnt ++;
    			id = v[t[i]-'a'][0];
    		} else {
    			id = *it;
    		}
    		//cout << id << "\n";
    	}

    	ll o = s.size();
    	ll ans = cnt*o + id + 1;
    	cout << ans << "\n";
    } else {
    	cout << "-1\n";
    }
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(4*i+7*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200003],n;
vector<pair<int,int> >built;
void in(int x,int num){
	if(!built.empty()&&x==built.back().first)built.back().second+=num;
	else built.push_back(make_pair(x,num)); 
}
int l(){
	int cnt=0;
	for(int i=0;i<built.size();i++)cnt+=built[i].second;
	return cnt; 
} 
bool check(int num){
	built.clear();
	for(int i=0;i<n;i++){
		int cur=l();
		if(cur<a[i])
			in(0,a[i]-cur);
		else{
			while(cur-built.back().second>=a[i])cur-=built.back().second,built.pop_back();
			built.back().second=a[i]-(cur-built.back().second);
			while(!built.empty()&&built.back().first==num-1)built.pop_back();
			if(built.empty())return 0;
			int en=built.back().first+1;
			built.back().second--;
			if(built.back().second==0)built.pop_back();
			in(en,1);
			in(0,a[i]-l());
		}
	}
	return 1;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int l=0,r=n;
	while(r>l+1){
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid;
	}
	cout<<r;
}

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

using ll = long long;
#define f first
#define s second
#define pb push_back
ll N, W;
vector<ll> w, v;
ll dp[(int)1e5+5]; //[value][#ofitemspassed]
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> N >> W;
    w.resize(N+2); v.resize(N+1);
    ll sV = 0;
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
        sV+=v[i];
    }
    for(ll i = 0; i <= sV; i++){
        dp[i] = 1e15;
    }
    dp[0] = 0;
    for(ll i= 1; i <= N; i++){
        for(int j = sV; j >= v[i]; j--){
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
            //cout << dp[j] << ' ' << dp[j-v[i]] + w[i] << '\n';
        }
    }
    //cout << dp[1];
    int ans =0;
    for(ll i = 0; i <= sV; i++){
        if(dp[i] <= W){
            ans = i;
        }
    }
    cout << ans ;
}

Measured memory_bytes: 1024
import sys
from math import sqrt
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    ans=0
    for i in range(1,int(sqrt(M))+1):
        if M%i==0:
            if M//i>=N:
                ans=max(ans,i)
            if i>=N:
                ans=max(ans,M//i)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import copy

n = int(input())
c = list(map(int, input().split()))  # 複数数値入力(リスト格納)
ans = False
for i in range(0,n-1):
    for j in range(i, n):
        flg = False
        # ここでiとjを入れ替えたものをつくり、昇順ならbreak
        li = copy.copy(c)
        li[j], li[i] = li[i], li[j]

        for k in range(1, n+1):
            if li[k-1] != k:
                flg = True
                break
        
        if not flg:
            ans = True 

if(ans):
    print("YES")
else:
    print("NO")
        

Measured memory_bytes: 3444
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 2;

vector<int> prime[N];

void prime_factorization() {
    for (int i = 2; i < N; ++i) {
        if (prime[i].empty()) {
            for (int j = i; j < N; j += i) {
                prime[j].emplace_back(i);
            }
        }
    }
}

void test() {
    prime_factorization();
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1; i < n; ++i) {
        int cur = i;
        long long div = 1;
        for (auto &x: prime[i]) {
            int cnt = 0;
            while (cur % x == 0) {
                ++cnt;
                cur /= x;
            }
            div = div * (cnt + 1);
        }
        ans += div;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


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

#define int long long
#define P(x) {if (debug) cout << x << endl;} 
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple

using namespace std;

template<class T> ostream& operator<<(ostream& os, V<T> v) {
F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}

const bool debug = 1;

string next_s(string s) {
	for(char c = 'a'; c <= 'z'; c++) {
    	bool ok = true;
    	for(char x : s) {
    		if(x == c) ok = false;
    	}
    	if(ok) {
    		return s+c;
    	}
    }
    
    vector <char> seen;
    
	for(int i= 25; i>=0; i--) {
	
		for(char x : seen) {
			if(x > s[i]) {
				string t;
				for(int j = 0; j < i; j++) {
					t+= s[j];
				}
				t+= (char) (x) ;
				return t;
			}

		}
	
		seen.pb(s[i]);
		
	}
    
    return "-1";
}

signed main () {
    string x;
    cin >> x;
    
    cout << next_s(x) << endl;
   /* x = "";
    for(int i = 0; i < 50; i++) {
    	cout << x << endl;
    	x = next_s(x);
    }*/
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    friendly = list(map(int, input().split()))
 
    friendly.sort()
 
    ans = friendly[-1]
    
    FLAG = True
    index = N - 2
    
    
    for i in range(N - 2):
        if (FLAG):
            ans += friendly[index]
            FLAG = False
        else:
            ans += friendly[index]
            FLAG = True
            index -= 1
    
        
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 31624
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int n;
    string s;
    map<string , int> m;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> s;
        m[s]++;
    }
    
    int max = 0;
    for( auto i = m.begin(); i != m.end() ; ++i ) {
        if (max < i->second) {
            max = i->second;
        }
    }
    
    vector<string> vv;
    for( auto i = m.begin(); i != m.end() ; ++i ) {
        if (max == i->second) {
            vv.push_back(i->first);
        }
    }
    sort(vv.begin(), vv.end());
    for (int i = 0; i < (int)vv.size(); i++) {
        cout << vv[i] << endl;
    }
            
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) (y) < 0 || h <= (y) || (x) < 0 || w <= (x)
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    cout << n * n << "\n";
}


Measured memory_bytes: 256
x = []
for i in range(3):
    x.append(list(map(int, input().split())))

A = x[0][1]-x[0][0]
B = x[1][1]-x[1][0]
C = x[2][1]-x[2][0]
D = x[0][2]-x[0][1]
E = x[1][2]-x[1][1]
F = x[2][2]-x[2][1]
G = x[1][0]-x[0][0]
H = x[1][1]-x[0][1]
I = x[1][2]-x[0][2]
J = x[2][0]-x[1][0]
K = x[2][1]-x[1][1]
L = x[2][2]-x[1][2]
    
cond1 = bool(A == B and B == C)
cond2 = bool(D == E and E == F)
cond3 = bool(G == H and H == I)
cond4 = bool(J == K and K == L)

if cond1 and cond2 and cond3 and cond4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let x: i32 = read();
    if x >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int n,A[10],B[10],fac[15];
char s[55];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=1;i<=n;i++) scanf("%d",&B[i]);
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i;
	int cev=0,cev2=0;
	for(int i=1;i<=n;i++){
		int say=0;
		for(int j=i+1;j<=n;j++){
			if(A[i]>A[j]) say++;
		}
		cev+=fac[n-i]*say;
	}
	//
	for(int i=1;i<=n;i++){
		int say=0;
		for(int j=i+1;j<=n;j++){
			if(B[i]>B[j]) say++;
		}
		cev2+=fac[n-i]*say;
	}
	//
	cev++;
	cev2++;
	printf("%d",abs(cev-cev2));
	return 0;
}






Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var x = o.a();
  var y = o.a();
  var z = o.a();
  var k = o.a();
  var a = o.l().concat(-1e15).sort((a,b)=>b-a);
  var b = o.l().concat(-1e15).sort((a,b)=>b-a);
  var c = o.l().concat(-1e15).sort((a,b)=>b-a);
  var ans = [];
  var u = [[a[1]+b[0]+c[0],1,0,0],[a[0]+b[1]+c[0],0,1,0],[a[0]+b[0]+c[1],0,0,1]];
  var set = new Set();
  ans[0] = a[0]+b[0]+c[0];
  set.add(f(0,0,0));
  for(var i = 1; i < k; i++){
    u.sort((a,b)=>a[0]-b[0]);
    var t = u.pop();
    ans[i] = t[0];
    set.add(f(t[1],t[2],t[3]));
    if((t[2] === 0 || set.has(f(t[1]+1,t[2]-1,t[3])))
    && (t[3] === 0 || set.has(f(t[1]+1,t[2],t[3]-1)))){
      u.push([a[t[1]+1]+b[t[2]]+c[t[3]],t[1]+1,t[2],t[3]]);
    }
    if((t[1] === 0 || set.has(f(t[1]-1,t[2]+1,t[3])))
    && (t[3] === 0 || set.has(f(t[1],t[2]+1,t[3]-1)))){
      u.push([a[t[1]]+b[t[2]+1]+c[t[3]],t[1],t[2]+1,t[3]]);
    }
    if((t[1] === 0 || set.has(f(t[1]-1,t[2],t[3]+1)))
    && (t[2] === 0 || set.has(f(t[1],t[2]-1,t[3]+1)))){
      u.push([a[t[1]]+b[t[2]]+c[t[3]+1],t[1],t[2],t[3]+1]);
    }
  }
  return ans.join("\n");
}
function f(a,b,c){
  return a+","+b+","+c;
}

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

int main(){
    int n,k,r,s,p;
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    int ans=0;
    string str = "";
    for(int i=0;i<k;i++){
        if(t[i]=='r'){
            str += "p";
            ans += p;
        }else if(t[i]=='s'){
            str += "r";
            ans += r;
        }else{
            str+= "s";
            ans += s;
        }
    }
    for(int i=k;i<n;i++){
        /*if(t[i]=='r' && t[i-k]=='p'){
            str += "r";
        }else if(t[i]== 's' && t[i-k]=='r'){
            str += "s";
        }else if(t[i]=='p' && t[i-k]=='s'){
            str+= "p";
        }*/
        if(t[i]=='r' && str[i-k]=='p'){
            str += "a";
        }else if(t[i]== 's' && str[i-k]=='r'){
            str += "a";
        }else if(t[i]=='p' && str[i-k]=='s'){
            str+= "a";
        }else if(t[i]=='r'){
            str += "p";
            ans += p;
        }else if(t[i]=='s'){
            str += "r";
            ans += r;
        }else{
            str+= "s";
            ans += s;
        }
    }
    cout << ans << endl;
    //cout << str << endl;
}

Measured memory_bytes: 640