akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int N,K;
    cin >> N >> K;
    
    ll V[50];
    for(int i=0; i<N; i++){
        cin >> V[i];
    }
    
    ll ans=0;
    for(int i=0; i<=min(N,K); i++){
        for(int j=0; j<=min(N-i,K-i); j++){
            
            
            ll jewel[50]={};
            int cnt=0;
            for(int l=0; l<i; l++,cnt++){
                jewel[cnt]=V[l];
            }
            for(int r=0; r<j; r++,cnt++){
                jewel[cnt]=V[N-1-r];
            }
            
            sort(jewel,jewel+50);
            
            ll temp=0;
            //残りK-i-j回の操作
            for(int t=0; t<K-i-j; t++){
                if(jewel[t]<0){
                    jewel[t]=0;
                }
            }
            
            for(int t=0; t<50; t++){
                temp+=jewel[t];
            }
            ans=max(ans,temp);
            
            
        }
    }
    


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


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

ll gcd(ll m,ll n){
	if(m < n)return gcd(n,m);
  	if(n == 0)return m;
  	return gcd(n,m%n);
}

ll lcm(ll m,ll n){
  	ll g = gcd(m,n);
	return (m/g)*n;
}



int main(){
	
  	int N;
  	cin >> N;
	ll ans = 1LL;
  	ll c;
  	for(int i = 0; i < N ; i++){

        	cin >> c;
          	ans = lcm(ans,c);
        
      	
    }
  	cout << ans << endl;
  	return 0;
	
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]
Inf = 10 ** 10

last_date = []
for i in 1..26 do
  last_date.push(0)
end

def try(lines,last_date,bias,final)
  satis = 0
  for i in 1..D do
    max_satis = - Inf
    best_contest = 0
    for k in 1..26 do
      now_satis = 0
      now_satis += lines[i+1][k-1]
      now_satis += lines[1][k-1] * (i - last_date[k-1]) * bias
      if now_satis > max_satis then
        max_satis = now_satis
        best_contest = k
      end
    end
    satis += max_satis
    last_date[best_contest-1] = i
    if final then
      puts best_contest
    end
  end
  return satis
end

# Normal Case: bias = 1
bias = 0.0
best_bias = 0.0
best_satis = - Inf
200.times do |num|
  current_satis = try(lines,last_date,bias,false)
  if current_satis < best_satis then
    best_satis = current_satis
    best_bias = bias
  end
  bias += 0.01
end
try(lines,last_date,best_bias,true)

Measured memory_bytes: 14192
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int h,w,ans=0;
vvc c;

int main(){
	cin>>h>>w;
	c=vvc(w,vc(h));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>c[j][i];
	for(int i=0;i<w-1;i++){
		vvi cost(h+1,vi(h+1));
		vi dp(h+1);
		for(int j=1;j<=h;j++) for(int k=1;k<=h;k++){
			cost[j][k]=cost[j-1][k-1]+(c[i][j-1]==c[i+1][k-1]);
		}
		for(int j=1;j<=h;j++) for(int k=1;k<=h;k++){
			dp[k]=min(dp[k],dp[k-1])+cost[j][k];
		}
		ans+=dp[h];
	}
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, u, v;
    cin >> n >> u >> v;
    u--, v--;
    vector<vector<ll>> g(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].eb(b);
        g[b].eb(a);
    }
    vector<bool> t_seen(n);
    vl t_d(n);
    auto rec = [&](auto &&f, ll now, ll d) -> void {
        t_seen[now] = true;
        t_d[now] = d;
        each(e, g[now]) {
            if (t_seen[e]) continue;
            f(f, e, d + 1);
        }
    };
    rec(rec, u, 0);
    vector<bool> a_seen(n);
    vl a_d(n);
    auto rec2 = [&](auto &&f, ll now, ll d) -> void {
        a_seen[now] = true;
        a_d[now] = d;
        each(e, g[now]) {
            if (a_seen[e]) continue;
            f(f, e, d + 1);
        }
    };
    rec2(rec2, v, 0);

    ll d_max = 0;
    ll dis = v;
    rep(i, n) {
        if (t_d[i] < a_d[i]) {
            if (a_d[i] >= d_max) {
                d_max = a_d[i];
                dis = i;
            }
        }
    }
    cout << d_max - 1 << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 15464
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i,j,k,cnt=0,flag=0;
    int n=s.length();
    sort(s.begin(),s.end());
    for(i=0;i<n;i++)
    {
        cnt=1;
        for(j=i+1;j<n;j++)
        {
            if(s[i]==s[j])
                cnt++;
            else
                break;
        }
        if(cnt%2!=0)
        {
            flag=1;
            break;
        }
        i=j-1;

    }
    if(flag==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3608
S = input()

stack = []

for s in S[::-1]:
    stack.append(s)
    n = len(stack)
    if n == 5 and (stack == ['e', 's', 'a', 'r', 'e'] or stack == ['m', 'a', 'e', 'r', 'd']):
        stack = []
    elif n == 6 and stack == ['r', 'e', 's', 'a', 'r', 'e']:
        stack = []
    elif n == 7 and stack == ['r', 'e', 'm', 'a', 'e', 'r', 'd']:
        stack = []
    elif n == 8:
        print('NO')
        break
else:
    print('YES')


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

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

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, M;
    cin >> N >> M;
    vector<Pll> shops(N);
    for (int i = 0; i < N; i++) {
        cin >> shops[i].first >> shops[i].second;
    }

    sort(shops.begin(), shops.end());

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll num = min(shops[i].second, M);
        ans += shops[i].first * num;
        M -= num;
    }

    cout << ans << endl;

    return 0;
}

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

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

    bool ng = true;
    for(int i = a; i <= b; ++i)
    {
        if(i % k == 0) ng = false;
    }

    cout << (ng ? "NG" : "OK") << "\n";
    return 0;
}

Measured memory_bytes: 3624
/*input
2 3 3
*/
/**
    Author: Kristopher Paul
    Date Created: 29-12-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//Uncomment for File I/O
/*
#define cin fin
#define cout fout

ifstream fin("cowmbat.in");
ofstream fout("cowmbat.out");
*/

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int a,b,k;
    cin >> a >> b >> k;
    if(a >= k){
        cout << a-k << " " << b << endl;
    }else{
        k -= a;
        b -= k;
        remax(b,0LL);
        cout << "0 " << b << endl; 
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int H,A;
    cin>>H>>A;
    if(H%A==0)cout<<H/A<<endl;
    else cout<<(H/A)+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15){
		cout<<"+"<<endl;
	}else if(a*b==15){
		cout<<"*"<<endl;
	}else{
		cout<<"x"<<endl;
	}
	return 0;
}

Measured memory_bytes: 768
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()

t, a = invr()

H = inlist()
avg = []

for h in H:
    temp = t - h * 0.006
    d = abs(a-temp)
    avg.append(d)
indx = 0
for i in range(n):
    if avg[i] < avg[indx]:
        indx = i
print(indx+1)


Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const long long maxa = 1e6 + 1;
vector<long long> spf(maxa + 1, 0);
vector<bool> can(maxa + 1, true);

int main() {

	iota(spf.begin(), spf.end(), 0);

	for (long long i = 2; i * i <= maxa; i++) {
		if (spf[i] == i) {
			for (long long j = i * i; j <= maxa; j += i) if (spf[j] == j) spf[j] = i;
		}
	}

	long long n; cin >> n;
	long long gd = 0;
	vector<long long> a(n); for (long long i = 0; i <= n - 1; i++) cin >> a[i], gd = gcd(gd, a[i]);

	bool is_setwise = (gd == 1);
	bool is_pairwise = true;


	for (long long i = 0; i <= n - 1; i++) {
		long long x = a[i];
		vector<int> s;

		while (x != 1) {
			s.push_back(spf[x]);
			x /= spf[x];
		}

		vector<int> ss = s;
		sort(ss.begin(), ss.end());

		assert(s == ss);

		s.resize(distance(s.begin(), unique(s.begin(), s.end())));

		for (auto pfac : s) {
			if (can[pfac] == false) {
				is_pairwise = false;
				break;
			}
			can[pfac] = false;
		}


		if (!is_pairwise) break;
	}

	if (is_pairwise) cout << "pairwise coprime";
	else if (is_setwise) cout << "setwise coprime";
	else cout << "not coprime";


	return 0;
}

Measured memory_bytes: 19028
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<string>
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;

int main()
{
	fr
	ll n,k;
	cin>>n;
	cin>>k;
	ll a[n+1],dp[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(ll i=2;i<n;i++)
	{
		ll t=dp[i-1]+abs(a[i]-a[i-1]);
		for(ll j=2;j<=k && i>=j ;j++)
		{
			 
			
			if(t>(dp[i-j]+abs(a[i]-a[i-j])))
			   {
			      t=dp[i-j]+abs(a[i]-a[i-j]);
			     }
		}
		dp[i]=t;
	}
	cout<<dp[n-1]<<endl;
}
	

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int L;
	while (cin >> L, L) 
	{
		ll sum = 0,ans=0;
		bool flag = false;
		for (int i = 0; i < 12; i++)
		{
			int M, N;
			cin >> M >> N;
			sum += M - N;
			if (sum >= L && !flag)
			{
				ans = i + 1;
				flag = true;
			}
		}
		if (!flag)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int mod = 1e9 + 7;
const int N = 4010;
int n, m, k, dep, ans;
int f[N][N];

bool check(int x, int y) {
	if(x > n || y > m) return 0;
	if(x % (k - 1) != n % (k - 1) || y % (k - 1) != m % (k - 1)) return 0;
	return 1;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	dep = (n + m - 1) / (k - 1), f[0][0] = 1;
	rep(i, 0, dep - 1) rep(j, 0, n + m)
		if(f[i][j]) {
			rep(h, 0, k - 1) f[i + 1][j + h] = (f[i + 1][j + h] + f[i][j]) % mod;
		}
	rep(i, 0, dep - 1) rep(j, 0, n + m)
		rep(h, 1, k - 1)
			if(check((k - 1) * i + k - j - h, j + h)) ans = (ans + f[i][j]) % mod;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int N;
bool kankei[21][21];
ll dp[1 << 21];//dp[i][j]: i番目(1-idx 0は初期条件で計算上の便宜)の男のマッチングまでして、女がjのようなbitの余り方をしてる
//bitが立ってると、マッチング済、そうでなければ使用可能

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> kankei[i][j];
		}
	}
	dp[0] = 1;

	for (int i = 1; i < (1 << N); i++) {
		int bitcnt = 0;
		for (int j = 0; j < N; j++)if (i & (1 << j))bitcnt++;
		for (int j = 0; j < N; j++) {
			if (kankei[bitcnt - 1][j] && (i & (1 << j))) {
				dp[i] += dp[i - (1 << j)];
				dp[i] %= MOD;
			}
		}
	}

	cout << dp[(1 << N) - 1] << endl;

	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(){int n;
cin>>n;
vector<int> vec(n);
for(int i=0;i<n;i++){
  cin>>vec.at(i);
}
 sort(vec.begin(), vec.end());
 int sum=9999999;
 for(int i=vec.at(0);i<vec.at(n-1)+1;i++){
   int s=0;
   for(int j=0;j<n;j++){
     s+=(i-vec.at(j))*(i-vec.at(j));
     
   }
   if(sum>s){
     sum=s;
   }
 }
 cout<<sum<<endl;
}  


Measured memory_bytes: 3632
#include <iostream>
#define m 1000000000
using namespace std;
int main(){
	long long S;
	cin >> S;
	long long A = (S + m - 1) / m;
	long long B = A * m - S;
	cout << "0 0 " << A << ' ' << B << ' ' << 1 << ' ' << m << endl;
}

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

//[begin, end)がcolor
struct Range{
	int begin, end, color;
};

int main(){
	int n;
	while(std::cin >> n, n){
		std::stack<Range> rs;
		int c;
		std::cin >> c;
		rs.push({0, 1, c});

		for(int i=1;i<n;i++){
			std::cin >> c;

			if(i%2 == 0){
				Range r = rs.top();
				if(c != r.color){
					rs.push({i, i+1, c});
				}else{
					r.end++;
					rs.pop(); rs.push(r);
				}
			}else{
				Range r = rs.top();
				if(c != r.color){
					rs.pop();
					if(!rs.empty()){
						Range pr = rs.top();
						if(c == pr.color){
							rs.pop();
							r.begin = pr.begin;
						}
					}
					r.end++;
					r.color = c;
					rs.push(r);
				}else{
					r.end++;
					rs.pop();rs.push(r);
				}
			}
		}

		int s = 0;
		while(!rs.empty()){
			Range r = rs.top();rs.pop();
			if(r.color == 0){
				s += r.end - r.begin;
			}
		}

		std::cout << s << std::endl;
	}
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    char c; cin >> c;
    c++;
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 3628
inf = float('inf')


def calc(mask):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (mask >> (2 * j)) & 3
        if idx == 3: continue
        t[idx] += l[j]
        cost += 10

    if 0 in t[:3]:
        return inf

    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
    return cost


def dfs(cur, mask):
    # l[cur]をa,b,c,未使用のいずれかにあてがう

    # base case
    if cur == n:
        return calc(mask)

    res = inf
    for i in range(4):
        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


n, *goal = map(int, input().split())
l = [int(input()) for _ in range(n)]

print(dfs(0, 0))


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

int main(){
    int h,w;
    cin>>h>>w;
    string s[52];
    for(int i=0;i<w+2;i++){
        s[0][i]=s[h+1][i]='.';
    }
    for(int i=1;i<=h;i++){
        cin>>s[i];
        s[i]='.'+s[i]+'.';
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int cnt=0;
            if(s[i][j]=='.'){
                if(s[i-1][j-1]=='#')cnt++;
                if(s[i-1][j]=='#')cnt++;
                if(s[i-1][j+1]=='#')cnt++;
                if(s[i][j-1]=='#')cnt++;
                if(s[i][j+1]=='#')cnt++;
                if(s[i+1][j-1]=='#')cnt++;
                if(s[i+1][j]=='#')cnt++;
                if(s[i+1][j+1]=='#')cnt++;
                s[i][j]='0'+cnt;
            }
        }
    }
    for(int i=1;i<=h;i++){
        cout<<s[i].substr(1,w)<<endl;
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, s.size() - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
  }
  cout << ans << endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
typedef pair<li, li> PI;

li a[100100];
map<li, li>cnt;

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	li res = 0;
	for (auto item : cnt) {
		if (item.second % 2 > 0) {
			res++;
		}
	}
	cout << res << endl;

	return 0;
}

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

int A[200005];
int mod = 1e9 + 7;

int main()
{
	int n;
	scanf("%d",&n);
	long long sum=0,ans=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&A[i]);
		sum+=A[i];
	}		
	for(int i=1;i<=n-1;++i)
	{
		sum-=A[i];
		ans+=sum % mod*A[i]%mod;
		ans%=mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(a, b);
    cout << (a + b) % 24 << endl;

    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

#define KI_MAX 114514

int ki[KI_MAX];

void ki_init(void) {
	int i;
	for (i = 0; i < KI_MAX; i++) ki[i] = -1;
}

int ki_root(int n) {
	if (ki[n] < 0) return n;
	return ki[n] = ki_root(ki[n]);
}

int ki_size(int n) {
	return -ki[ki_root(n)];
}

void ki_merge(int a, int b) {
	int ar = ki_root(a);
	int br = ki_root(b);
	if (ar != br) {
		int as = ki_size(ar);
		int bs = ki_size(br);
		if (as <= bs) {
			ki[br] += ki[ar];
			ki[ar] = br;
		} else {
			ki[ar] += ki[br];
			ki[br] = ar;
		}
	}
}

int main(void) {
	int N, M;
	int i;
	int mamegu = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	ki_init();
	for (i = 0; i < M; i++) {
		int A, B;
		if (scanf("%d%d", &A, &B) != 2) return 1;
		ki_merge(A, B);
	}
	for (i = 2; i <= N; i++) {
		if (ki_root(1) != ki_root(i)) {
			mamegu++;
			ki_merge(1, i);
		}
	}
	printf("%d\n", mamegu);
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  vector<int> a(3);
  for(int i=0; i<3; i++){
    cin >> a[i];
  }
  int ans = 1e9;
  chmin(ans,a[0]+a[1]);
  chmin(ans,a[1]+a[2]);
  chmin(ans,a[2]+a[0]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    ll x, y;
    cin >> x >> y;
    int cnt = 1;
    while (y >= 2 * x) {
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderD
{
    private static int n;
    private static List<Tuple<int, long>>[] to;
    private static long[] d;

    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        int blue = k;
        int red = n - k;
        int mod = 1000000007;

        for (int i = 1; i <= k; i++)
        {
            long answer = Combination(red + 1, i, mod) * Combination(blue - 1, i - 1, mod) % mod;
            Console.WriteLine(answer);
        }
    }

    // Comnibation（mod版）
    private static long Combination(int a, int b, int c)
    {
        long numerator = 1;
        long denominator = 1;
        for (int i = 1; i <= b; i++)
        {
            numerator = Mul(numerator, a - i + 1, c);
            denominator = Mul(denominator, i, c);
        }
        return Div(numerator, denominator, c);
    }

    // 掛け算（mod版）
    private static long Mul(long a, long b, long c)
    {
        return ((a % c) * (b % c)) % c;
    }

    // 割り算（mod版）
    private static long Div(long a, long b, long c)
    {
        return Mul(a, Pow(b, c - 2, c), c);
    }

    // べき乗（mod版）
    private static long Pow(long a, long b, long c)
    {
        if (b == 0)
        {
            return 1;
        }
        else if (b == 1)
        {
            return a % c;
        }
        else if (b % 2 == 0)
        {
            long d = Pow(a, b / 2, c);
            return d * d % c;
        }
        else
        {
            return a * Pow(a, b - 1, c) % c;
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

vector<int> create_eratos(int n) {
  vector<int> isprime(n+1, 1);
  isprime[0] = 0;
  isprime[1] = 0;

  for (int i = 2; i * i <= n; i++) {
    if (isprime[i]) {
      int j = i + i;
      while (j <= n) {
        isprime[j] = 0;
        j = j + i;
      }
    }
  }
  return isprime;
}

vector<int> create_prime_list(int n) {
  vector<int> eratos = create_eratos(n);
  vector<int> result;
  result.reserve(n);
  for (int i = 1; i <=n; i++) {
    if (eratos[i]) {
      result.push_back(i);
    }
  }
  return result;
}

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

  int n;
  cin >> n;

  vector<int> prime_numbers = create_prime_list(55555);

  vector<int> ans;
  for (auto& x : prime_numbers) {
    if (x % 5 == 1) ans.push_back(x);
    if (ans.size() == n) break;
  }

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

  return 0;
}


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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int a[N], dp[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k, i, j;
	cin>>n>>k;
	for(i=0; i<n; i++){
		cin>>a[i];
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	for(i=1; i<n; i++){
		for(j=max(0, i-k); j<i; j++){
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	
	public static void main(String[] args) throws Exception {
		
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        
        String boxstr[] = line.split(" ");
        int[] box = new int[2];
        box[0] = Integer.parseInt(boxstr[0]);
        box[1] = Integer.parseInt(boxstr[1])/1000;
        
        int[] gift = {-1,-1,-1};
        
        
        
      outside: for(int i=box[0];i+1>0;i--){
       // 	System.out.println("Hi" + i);
        	if(i*10==box[1] && i == box[0]){
        		gift[0] =i;
        		gift[1] =0;
        		gift[2] =0;
        		break outside;

        	}else if(i*10 <box[1]){
            //	System.out.println("Change" + i);
            	for(int j=box[0]-i;j+1>0;j--){
              //  	System.out.println("Hii" + j);
                	if(i*10+j*5==box[1] &&i + j == box[0]){
                		gift[0]=i;
                		gift[1] =j;
                		gift[2] =0;
                		break outside;
                		
                	}else if(i*10+j*5 <box[1]){
                    //	System.out.println("Change" + i);
                    	for(int h=box[0]-i-j;h+1>0;h--){
                     // 	System.out.println("Hee" + h);
                        	if(i*10+j*5+h==box[1] && i + j + h == box[0]){
                        		gift[0]=i;
                        		gift[1] =j;
                        		gift[2] =h;
                        		
                        		break outside;
                    	}
                	}
                	}
        		
        	}
        }
        
        
        
        
        
           }
        for(int i=0;i<3;i++){
        	System.out.print(gift[i]+" ");
        }
        
        
        
        


	}
	}
	

	

Measured memory_bytes: 23380
import java.util.Scanner;
public class Main{
    public static void main(String[] args) throws Exception {
         
        Scanner sc = new Scanner(System.in);
        
        String W = sc.next();
        int count = 0;
        W = W.toUpperCase();
        
        
        while(true){
            String T = sc.next();
            if( T.equals( "END_OF_TEXT" ) )
                break;
            T = T.toUpperCase();
            if( T.equals(W))
                count++;
        }
        System.out.println(count);
        sc.close();
    }
}



Measured memory_bytes: 26276
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

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

int main(){

  int N;
  string S1, S2;

  cin >> N >> S1 >> S2;

  for (int i=0; i<N; i++){
    cout<< S1.at(i) << S2.at(i);
  }
  cout << endl;
}


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

N, M = map(int, input().split())

S = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))

def check_S(state, S, P):
    for s, p in zip(S, P):
        count = 0
        for si in s[1:]:
            if state[si-1] == '1':
                count += 1 
        if count%2 != p:
            return False
    return True

ans = 0
for i in range(2**N):
    state = list(format(i, '0'+format(N)+'b'))
    if check_S(state, S, P):
        ans += 1
print(ans)
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m,k,ans=0;
    cin>>n>>m>>k;
    string s[n];
    rep(i,0,n)  
        cin>>s[i];
    rep(i,0,(1<<n))
    {
        rep(j,0,(1<<m))
        {
            ll ct=0;
            rep(r,0,n)
            {
                if(i&(1<<r))
                    continue;
                rep(c,0,m)
                {
                    if(j&(1<<c))
                        continue;
                    if(s[r][c]=='#')
                        ct++;
                }
            }
            if(ct==k)
                ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3656
def main():
    n = int(input())
    a = [input() for _ in [0]*n]
    b = []
    for i in a:
        j = i.find(".")
        if j == -1:
            b.append(int(i)*10**9)
        else:
            k = 10-len(i)+j
            i = i.replace(".", "")
            b.append(int(i)*10**k)
    d = dict()
    for i in b:
        cnt_a = 0
        while(True):
            if i % 2 != 0:
                break
            cnt_a += 1
            i //= 2
        cnt_b = 0
        while(True):
            if i % 5 != 0:
                break
            cnt_b += 1
            i //= 5
        if (cnt_a, cnt_b) in d:
            d[(cnt_a, cnt_b)] += 1
        else:
            d[(cnt_a, cnt_b)] = 1
    ans = 0
    for i in range(50):
        for j in range(20):
            if (i, j) not in d:
                continue
            temp1 = d[(i, j)]
            for k in range(50):
                for l in range(20):
                    if (k, l) not in d:
                        continue
                    temp2 = d[(k, l)]
                    if i+k >= 18 and j+l >= 18:
                        if i == k and j == l:
                            ans += temp1*(temp2-1)
                        else:
                            ans += temp1*temp2

    print(ans//2)


main()


Measured memory_bytes: 100028
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){
  ll c=max(a,b),d=min(a,b);
  ll r=c%d;
  while(r>0){
    c=d;
    d=r;
    r=c%d;
  }
  return d;
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
int main(){
  ll n;cin>>n;
  ll now=0;cin>>now;
  for(int i=0;i<n-1;i++){
    ll a;cin>>a;
    now=lcm(now,a);
  }
  cout<<now<<endl;
}


Measured memory_bytes: 256
import Data.Bool
import Data.Maybe
import Data.List

main = putStrLn . solve . lines =<< getContents

solve :: [String] -> String
solve [s,t] = maybe "UNRESTORABLE" (rpl s t) $ rfnd s t (length s - length t)

rpl s t i = f ++ t ++ b
    where
        f = map rpl' $ take i s
        b = map rpl' $ drop (length t + i) s

rpl' '?' = 'a'
rpl' x = x

rfnd s t i
    | i < 0 = Nothing
    | otherwise = bool (rfnd s t (i-1)) (return i) $ isMatched s' t
    where
        s' = drop i s

isMatched s t = and $ zipWith (\s' t' -> s' == '?' || s' == t') s t


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll a, b, x; cin >> a >> b >> x;
  ll ans1 = b / x;
  ll ans2 = 0;
  if(a != 0) ans2 = (a - 1) / x;
  else {
    ans2 = 0;
    ans1++;
  }
  ll ans = ans1 - ans2;
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        string s = string.Join("", Console.ReadLine().Reverse());
        string[] key = new string[] { "dream", "dreamer", "erase", "eraser" }.Select(x => string.Join("", x.Reverse())).ToArray();
        int index = 0;

        while (true)
        {
            if (s.Length == index) break;
            if (s.Length < index + 5) goto end;
            string ss = s.Substring(index, 5);
            if (ss == key[0] || ss == key[2])
            {
                index += 5;
                continue;
            }
            if (s.Length < index + 6) goto end;
            ss = s.Substring(index, 6);
            if (ss == key[3])
            {
                index += 6;
                continue;
            }
            if (s.Length < index + 7) goto end;
            ss = s.Substring(index, 7);
            if (ss == key[1])
            {
                index += 7;
                continue;
            }
            end:;
            Console.WriteLine("NO");
            return;
        }
        Console.WriteLine("YES");
    }
}

Measured memory_bytes: 16480
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	A, B, C, D, E, F := getInt(), getInt(), getInt(), getInt(), getInt(), getInt()

	alim := F / (100 * A)
	blim := F / (100 * B)

	suger := (F * E) / 100
	clim := suger / C
	dlim := suger / D

	max := float64(-1)
	maxw := 0
	maxs := 0

	for a := 0; a <= alim; a++ {
		for b := 0; b <= blim; b++ {
			for c := 0; c <= clim; c++ {
				for d := 0; d <= dlim; d++ {
					w := a*A + b*B
					s := c*C + d*D
					f := w*100 + s
					if f == 0 {
						continue
					}
					rate := float64(s*100) / float64(s+w)
					//out(w, f, s, (s*1000)/(s+w))
					if f <= F && s <= E*w && max < rate {
						max = rate
						maxw = w * 100
						maxs = s
					}
				}
			}
		}
	}

	if E == 0 {
		out(A*100, 0)
	} else {
		out(maxw+maxs, maxs)
	}
}


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

int width(pair<int, int> a) { return max(0, a.second - a.first); }

pair<int, int> unite(pair<int, int> a, pair<int, int> b) {
  return make_pair(max(a.first, b.first), min(a.second, b.second));
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (auto& e : v) {
    cin >> e.first >> e.second;
    e.second++;
  }
  sort(v.begin(), v.end());

  vector<pair<int, int>> s{v[0], v[1]};
  for (int i = 2; i < n; i++) {
    vector<pair<int, vector<pair<int, int>>>> t{
        {width(unite(s[0], v[i])) + width(s[1]), {unite(s[0], v[i]), s[1]}},
        {width(s[0]) + width(unite(s[1], v[i])), {s[0], unite(s[1], v[i])}},
        {width(unite(s[0], s[1])) + width(v[i]), {unite(s[0], s[1]), v[i]}},
    };
    s = max_element(t.rbegin(), t.rend())->second;
  }
  cout << width(s[0]) + width(s[1]) << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin >> a >> b;
	int soc=a;
	int cnt=1;
	while(soc<b){
		soc-=1;
		soc+=a;
		cnt++;
	}
	if(b==1){
		cnt=0;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    a109(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a109(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    println(if (args[0].split(" ").map { it.toInt() }.all { it % 2 == 1 }) "Yes" else "No")
}

Measured memory_bytes: 38212
k, s = map(int,input().split())
# print(k)
# print(s)

# 組み合わせをカウントする変数
count = 0

# 変数の初期化
x = 0
y = 0
z = 0

for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count += 1

print(count)


Measured memory_bytes: 8976
// Vicfred
// https://atcoder.jp/contests/abc158/tasks/abc158_d
import std.algorithm;
import std.array;
import std.stdio;
import std.conv;
import std.string;
import std.container;

void main() {
    string s = readln.chomp;
    int q = readln.chomp.to!int;

    int[] t = new int[q];
    int[] f = new int[q];
    char[] c = new char[q];

    foreach(i; 0..q) {
        string[] line = readln.split.map!(to!string).array;
        t[i] = to!int(line[0]);
        if(t[i] == 2) {
            f[i] = to!int(line[1]);
            c[i] = to!char(line[2]);
        }
    }

    auto str = DList!char();
    foreach(ch; s)
        str.insertBack(ch);

    bool reversed = false;

    for(int i = 0; i < q; ++i) {
        if(t[i] == 1) {
            reversed = !reversed;
        } else if(f[i] == 1) {
            if(!reversed)
                str.insertFront(c[i]);
            else
                str.insertBack(c[i]);
        } else {
            if(!reversed)
                str.insertBack(c[i]);
            else
                str.insertFront(c[i]);
        }
    }

    if(reversed)
        str[].reverse;
    foreach(ch; str)
        ch.write;
    writeln;
}



Measured memory_bytes: 15896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using p = pair<int,int>;

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> p(N);
  rep(i, N)
  {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  
  int sum = 0;
  rep(i, K)
  {
    sum += p.at(i);
  }
  cout << sum;
 }

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

using namespace std;

int main()
{
    string S;
    cin >> S;
    int n = S.size() - 1;
    long long int sum = 0;

    for (int bit = 0; bit < (1 << n); bit++)
    {
        long long n_t = S.at(0) - '0';
        for (int i = 0; i < n; i++)
        {
            if ((1 << i) & bit)
            {
                sum += n_t;
                n_t = S.at(i + 1) - '0';
            }
            else
                n_t = n_t * 10 + (S.at(i + 1) - '0');
        }
        sum += n_t;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
//#define scanf_s scanf
#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 101
#define _MAX 81
int main(void)
{
	char str[MAX];
	while (gets_s(str) != NULL) {
		for (int i = 0; str[i] != '\0'; ++i) {
			if (str[i] == '@') {
				for (int j = 0; j < str[i + 1] - '0'; ++j) {
					printf("%c", str[i + 2]);
				}
				i += 2;
			}
			else {
				printf("%c", str[i]);
			}
		}
		printf("\n");
	}
}

Measured memory_bytes: 1080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, m = 2;
  cin >> n;

  vector<vector<int> > a(m, vector<int>(n));
  rep(i, m) rep(j, n) cin >> a[i][j];

  vector<vector<int> > dp(m, vector<int>(n));
  dp[0][0] = a[0][0];
  rep(i, m) rep(j, n) {
    if (i - 1 >= 0) chmax(dp[i][j], dp[i - 1][j] + a[i][j]);
    if (j - 1 >= 0) chmax(dp[i][j], dp[i][j - 1] + a[i][j]);
  }
  cout << dp[m - 1][n - 1] << endl;
  // rep(i, m) cout << dp[i] << endl;
}


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

using namespace std;

void Main() {
    long long H;
    cin >> H;

    long long ans = 1;
    while (H > 0) {
        H /= 2;
        ans *= 2;
    }
    ans -= 1;
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3632