akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

main()
{
    int n,k;scanf("%d%d",&n,&k);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        ans+=2*min(x,k-x);
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
	int x;
	int max = 1;
	int tmp;
	cin >> x;
	for(int i=2; i< x; i++){
		tmp = i * i;
		while(tmp <= x){
			if(tmp > max) max = tmp;
			tmp *= i;
		}
	}
	cout << max;
}


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


ll knapsack(ll N, ll W, ll val[], ll wt[])
{
	ll maxVal = N * 1000;
	ll dp[N + 1][maxVal + 1];


	for (ll i = 0; i <= maxVal; i++)
		dp[1][i] = INT_MAX;

	dp[1][0] = 0;

	dp[1][val[1]] = wt[1];

	for (ll i = 2; i <= N; i++)
	{
		for (ll v = 0; v <= maxVal; v++)
		{
			dp[i][v] = dp[i - 1][v];	//ith object is not selected

			if (val[i] > v)
				continue;
			dp[i][v] = min(dp[i][v], wt[i] + dp[i - 1][v - val[i]]);	//ith object is selected
		}
	}

	ll ans = 0;

	for (ll x = 0; x <= maxVal; x++) {
		if (dp[N][x] <= W)			//To select max value x s.t dp[N][x] <= W
			ans = x;
	}
	return ans;
}


int main()
{

	ll N, W;

	cin >> N >> W;

	ll val[N + 2], wt[N + 2];

	for (ll i = 1; i <= N; i++)
		cin >> wt[i] >> val[i];

	cout << knapsack(N, W, val, wt);
}

Measured memory_bytes: 81656
#include <cstdio>

using namespace std;

int tbl[100100];
int fact[100100];
int cnt4,cnt2;

bool f () {
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++) {
		scanf("%d",&tbl[i]);
		if (tbl[i]%4==0) fact[i]=4,cnt4++;
		else if (tbl[i]%2==0) fact[i]=2,cnt2++;
		else fact[i]=0;
	}
	int cnt0=n-cnt4-cnt2;
	
	if (cnt4+cnt0==n&&cnt4+1==cnt0) return true;
	if (cnt4<cnt0) return false;
	if (cnt2==n) return true;
	if (cnt2&&cnt4==0) return false;
	return true;
}

int main() {
	printf("%s\n",f()?"Yes":"No");
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes";
			return;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No";
			return;
		}
	}
}

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


Measured memory_bytes: 3640
a, b, c, x, y =  map(int, input().split())
if c * 2  < a + b:
    min_pizza_num = min(x, y)
    if min_pizza_num == x:
        price = b
    else:
        price = a
    first_price = min_pizza_num * 2 * c + abs(x - y) * price
    max_pizza_num = max(x, y)
    second_price = max_pizza_num * 2 * c
    print(min(first_price, second_price))
else:
    print(x * a + y * b)

Measured memory_bytes: 3064
import math

A, B = map(int, input().split())

# 素因数の個数(cnt)は使わないので省いた
def prime_factorize(n):
    res = [] # 結果を格納
    tmp = n # tmpにnをコピーしておく

    for i in range(2, int(math.sqrt(n))+1):
        if tmp % i == 0:
            while tmp % i == 0:
                tmp //= i
            res.append(i)

    # tmpに余った素数の処理
    if tmp != 1:
        res.append(tmp)

    # 何も割れなかったらnは素数なのでそのまま入れておく
    if res == [] and n != 1:
        res.append(n)

    return(res)

A_fac = set(prime_factorize(A))
B_fac = set(prime_factorize(B))

C = A_fac & B_fac
ans = len(C) + 1
print(ans)

Measured memory_bytes: 3064
fn main() {
    let (n,m) = { 
        let s = rv::<usize>();
        (s[0],s[1])
    };
    let s = rl();
    let s = s.trim_right().as_bytes();
    let mut p=n;
    let mut a = Vec::new();
    while p>0 {
        let mut q = if p<m {0} else {p-m};
        while s[q]!=b'0' {q+=1;}
        if q==p {
            a.clear();
            a.push("-1".to_string());
            break;
        }
        a.push((p-q).to_string());
        p=q;
    }
    a.reverse();
    println!("{}",a.join(" "));
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int s = 0;
  rep(i,n) s ^= a[i];
  rep(i,n) a[i] ^= s;
  rep(i,n) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

void dfs(int now,int N,vector<bool> &v,vector<vector<int>> &g){
	for(int i=0;i<N;i++){
		if(now==i)continue;
		if(g[now][i]==1 && v[i]==0){
			v[i] = 1;
			dfs(i,N,v,g);
		}
	}
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M,ans = 0;
	cin >> N >> M;
	vector<int> a(M),b(M);
	rep(i,M){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	for(int i=0;i<M;i++){
		//i番目の辺を除いた状態で各頂点から全ての頂点にいけるかどうかを調べる
		vector<vector<int>> g(N,vector<int>(N,-1));
		vector<bool> v(N);
		rep(j,M){
			if(i==j)continue;
			g[a[j]][b[j]]=1;
			g[b[j]][a[j]]=1;
		}
		v[0] = 1;
		dfs(0,N,v,g);
		bool ok = 1;
		for(int i=0;i<N;i++){
			if(v[i]==0)ok = 0;
		}
		if(ok)ans++;
	}
	cout << M - ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
sc = []
for _ in range(M):
    sc.append(list(map(int, input().split())))

keta = [-1]*N
flag = 0
for i in range(M):
    for j in range(1,N+1):
        #print(i,j,sc[i][0], keta)
        if sc[i][0] == j:
            if keta[j-1] == -1:
                keta[j-1] = sc[i][1]
            elif keta[j-1] == sc[i][1]:
                continue
            else:
                flag = 1
                break
    if flag == 1:
        print(-1)
        break

ans = 0
if flag == 0:
    if N == 3 and keta[0] == 0:
        print(-1)
    elif N == 2 and keta[0] == 0:
        print(-1)
    elif N == 3:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        if keta[2] == -1:
            keta[2] = 0
        print(keta[0]*100+keta[1]*10+keta[2])
    elif N == 2:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        print(keta[0]*10+keta[1])
    elif N == 1:
        if keta[0] == -1:
            keta[0] = 0
        print(keta[0])

#print(keta)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>

#define maxn 200010
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
typedef long long ll;
std::pair<int, int> a[maxn];
#define fir first
#define sec second
int main()
{
	int n, maxx = 0, minn = 0x7fffffff;
	ll ans = ~0ULL >> 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &a[i].fir, &a[i].sec);
		a[i].fir > a[i].sec ? std::swap(a[i].fir, a[i].sec), 1 : 0;
		cmax(maxx, a[i].sec);
		cmin(minn, a[i].fir);
	}
	int rmin = minn, rmax = 0, bmin = 0x7fffffff, bmax = maxx;
	for (int i = 1; i <= n; ++i)
	{
		cmax(rmax, a[i].fir);
		cmin(bmin, a[i].sec);
	}
//	printf("%d %d %d %d\n", rmin, rmax, bmin, bmax);
	cmin(ans, 1ll * (rmax - rmin) * (bmax - bmin));

	std::sort(a + 1, a + n + 1);
	rmax = maxx;
	int bbmin = 0x7fffffff; bmin = 0x7fffffff; bmax = a[n].fir;
	for (int i = 1; i < n; ++i)
	{
		bmin = a[i + 1].fir;
		cmin(bbmin, a[i].sec);
		cmax(bmax, a[i].sec);
		cmin(ans, 1ll * (rmax - rmin) * (bmax - std::min(bmin, bbmin)));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
D,N=map(int,input().split())
if D==0:
  if N==100:
    print(101)
  else:
    print(N)
elif D==1:
  if N==100:
    print(10100)
  else:
    print(100*N)
else:
  if N==100:
    print(1010000)
  else:
    print(10000*N)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
const int maxn=200000+5;
typedef long long ll;

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

    if(k>n*(n-1)/2-(n-1))
    {
        cout<<-1;
        return 0;
    }

    cout<<n*(n-1)/2-(n-1)-k+n-1<<endl;
    for(int i=2;i<=n;++i)
    {
        cout<<1<<" "<<i<<endl;
    }

    int t=n*(n-1)/2-(n-1)-k;

    for(int i=2;i<n&&t;++i)
    {
        for(int j=i+1;j<=n&&t;++j)
        {
            cout<<i<<" "<<j<<endl;
            --t;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int a = in.nextInt();
		int b = in.nextInt();
		int c = a + b;

		if (c <= 9) {
			System.out.println(c);
		} else {
			System.out.println("error");
		}

	}
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

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

    int ans = 0;
    if (k <= a)
    {
        ans = k;
    }
    else
    {
        if (k - a <= b)
        {
            ans = a;
        }
        else
        {
            ans = a - (k-a-b);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
	int n, count = 0;
	char s[60];
	scanf("%d",&n);
	scanf("%s", s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			count++;
		}
	}
	printf("%d",count);
	
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    double X;
    X = (double)N / 1.08;
    if(floor(ceil( X ) * 1.08) == N){
        cout << (int)ceil(X) << endl;
    }
    else{
      if(floor(floor(X) *1.08) == N){
        cout << (int)floor(X) << endl;
      }
      else{
        cout << ":(" << endl;
    }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    
    int K, X;
    cin >> K >> X;
    for (int i = X - (K - 1); i <= X + (K - 1); i++)
    {
        if (i == X - (K - 1))
        {
            cout << i;
        } else {
            cout << " " << i;
        }
    }


    return 0;

}


Measured memory_bytes: 256
s = input()
count = 0
if len(set(s)) == 1:
    print(0)
    exit()
left = 0
right = len(s) - 1

ans = 0
while True:
    if (s[left] == 'x' and s[right] == 'x') or s[left] == s[right]:
        left += 1
        right -= 1
    elif s[left] == 'x' and s[right] != 'x':
        ans += 1
        left += 1
    elif s[left] != 'x' and s[right] == 'x':
        ans += 1
        right -= 1
    elif s[left] != 'x' and s[right] != 'x' and s[left] != s[right]:
        print(-1)
        exit()
    if right <= left:
        break
print(ans)


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

const int INF = 1001001001;

int main()
{
    int n,m;
    int a,b;
    vector<int> to[100005];
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> q;
    vector<int> dist(n,INF);
    vector<int> pre(n,-1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty())
    {
        int v = q.front();q.pop();
        for(int u:to[v])
        {
            if(dist[u] != INF)continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,n)
    {
        if(i == 0)continue;
        int ans = pre[i];
        ++ ans;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 10496
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;




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

	int H, W, K;
	cin >> H >> W >> K;
	vector<string> S(H);
	REP(i, H) cin >> S[i];
	vector<vector<int>> sum(H + 1, vector<int>(W + 1));
	REP(i, H) {
		REP(j, W) {
			sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + S[i][j] - '0';
		}
	}
	int res = INT_MAX;
	for (int bit = 0;bit < 1 << (H - 1);++bit) {
		int g = 0;
		vector<int> group(H);
		for (int i = 0;i < H;++i) {
			group[i] = g;
			if (bit >> i & 1) {
				++g;
			}
		}
		int num = g;
		int i = 0, j = 0;
		while (j < W) {
			int l = j + 1;
			while (l <= W) {
				i = 0;
				bool add = false;
				for (int x = 0;x <= g;++x) {
					int k = upper_bound(group.begin(), group.end(), x) - group.begin();
					if (sum[k][l] - sum[i][l] - sum[k][j] + sum[i][j] > K) {
						--l;
						add = true;
						break;
					}
					i = k;
				}
				if (add) {
					if (l == j) {
						num = INT_MAX;
						break;
					}
					j = l;
					++num;
					break;
				}
				if (l == W) {
					res = min(res, num);
					j = l;
					break;
				}
				++l;
			}
			if (num == INT_MAX) break;
		}	
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 384
import scala.collection.mutable
import scala.io.StdIn
object Main extends App {
  val N = StdIn.readLine().toInt
  val diametersCount = mutable.Map.empty[Int,Int]
  for (i <- 0 until N; diameter = StdIn.readLine().toInt) {
    if (diametersCount.contains(diameter)) {
      val beforeCount = diametersCount(diameter)
      diametersCount += (diameter -> (beforeCount + 1))
    } else {
      diametersCount += (diameter -> 1)
    }
  }
  println(diametersCount.size)
}


Measured memory_bytes: 25500
#include<iostream>
#include<string>
#include <numeric>
using namespace std;
string s;
int main() {
    cin >> s;
    int cnt=0;
    for(int i=0; i<s.size(); ++i){
        if(s[i]=='1') cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn = 22;
ll n = 0;
int len = 0;
int num[maxn];

int dp[maxn];
int vis[maxn];

int dfs(int l, int d) {
    if (l == -1) return 0;
    if (vis[l] && !d) return dp[l];
    int m = d?num[l]:9;
    int ret = 0;
    for (int i = 0; i <= m; i++) {
        ret = max(ret, i+dfs(l-1, d&(i==m)));
    }
    if (!d) {
        vis[l] = 1; dp[l] = ret;
    }
    return ret;
}

int main() {
    cin >> n;
    while (n) {
        num[len++] = n%10;
        n /= 10;
    }
    int ans = dfs(len-1, 1);
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    vector <string> s(3);
    cin >> s[0] >> s[1] >> s[2];

    for(int i = 0; i < 3; i++)
    {
        cout << (char) toupper(s[i][0]);
    }
    cout << endl;
    return 0;  

}

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

int main(){
	long long N, R;
	cin >> N >> R;
	while (cin){
		if (N < 10) R = R + 100*(10-N);
		cout << R << "\n";
		cin >> N >> R;
	}
	return 0;
}

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

typedef long long ll;

ll oddSolve(ll a) {
    return (a + 1) / 2 % 2;
}

ll solve(ll a) {
    if (a % 2 == 1) {
        return oddSolve(a);
    } else {
        return oddSolve(a + 1) ^ (a + 1);
    }
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll res = solve(B) ^ solve(A - 1);
    cout << res << endl;
}

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

ll n, r;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

int main(){
	n = read(), r = read();
	if (n < 10) r += (10 - n) * 100;
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a, b, m;
    ll x, y, c;
    ll mina = INF, minb = INF, minsum = INF;
    cin >> a >> b >> m;

    vector<ll> va(a + 1), vb(b + 1);

    for (int i = 1; i <= a; i++)
    {
        cin >> va[i];

        mina = min(mina, va[i]);
    }

    for (int i = 1; i <= b; i++)
    {
        cin >> vb[i];
        minb = min(minb, vb[i]);
    }

    for (int i = 0; i < m; i++)
    {
        cin >> x >> y >> c;

        minsum = min(minsum, va[x] + vb[y] - c);
    }

    cout << min(minsum, mina + minb) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

bool check(const vector<long long> &A, const vector<long long> &B, long long N, long long M, long long x, long long &cnt, long long &sm){
    cnt = 0;
    sm = 0;
    REP(i, N){
        long long rem = x - A[i];
        int pos = lower_bound(A.begin(), A.end(), rem) - A.begin();
        sm += B[N] - B[pos] + A[i] * (N-pos);
        cnt += N - pos;
    }
    if(cnt >= M) return true;
    return false;
}

int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> A(N);
    vector<long long> B(N+1);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    REP(i, N) B[i+1] = B[i] + A[i];

    long long lb = 0;
    long long mx = *max_element(A.begin(), A.end());
    long long ub = 2*mx+1;
    long long cnt, sm;
    while(ub - lb > 1){
        long long mid = (lb + ub) / 2;
        if(check(A, B, N, M, mid, cnt, sm)) lb = mid;
        else ub = mid;
    }
    check(A, B, N, M, lb, cnt, sm);
    long long ans = sm - (cnt-M) * lb;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp = scanner.nextLine().split(" ");
		int a = Integer.parseInt(temp[0]);
		int b = Integer.parseInt(temp[1]);
		StringBuilder sbA = new StringBuilder();
		StringBuilder sbB = new StringBuilder();

		for(int i = 0; i < b ; i++) {

			sbA.append(String.valueOf(a));

		}
		for(int i = 0; i < a ; i++) {

			sbB.append(String.valueOf(b));

		}

		if(a <= b) {

			System.out.println(sbA.toString());

		}else {

			System.out.println(sbB.toString());

		}
	}
}

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

using namespace std;

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

  vector<int> vw(n);
  for (int i = 0; i < n; ++i) {
    cin >> vw[i];
  }

  int ans = -1;
  for (int i = 0; i < n; ++i) {
    int s1 = 0, s2 = 0, threshold = i;
    for (int j = 0; j < n; ++j) {
      if (j <= threshold) {
        s1 += vw[j];
      } else {
        s2 += vw[j];
      }
    }

    int diff = abs(s1 - s2);
    ans = ans < 0 ? diff : min(ans, diff);
  }

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

Measured memory_bytes: 256
class IntSegmentTree(n: Int) {
    private var size = 1

    init {
        while (size < n) {
            size *= 2
        }
    }

    private val segTree = IntArray(size * 2 - 1) { 0 }

    fun update(x: Int, value: Int) {
        var tmp = x + size - 1

        segTree[tmp] = value
        while (tmp > 0) {
            tmp = (tmp - 1) / 2
            segTree[tmp] = segTree[2 * tmp + 1] + segTree[2 * tmp + 2]
        }
    }

    fun getSum(a: Int, b: Int, k: Int = 0, l: Int = 0, r: Int = size): Int {
        if (r <= a || b <= l) {
            return 0
        }
        if (a <= l && r <= b) {
            return segTree[k]
        }

        val vl = getSum(a, b, 2 * k + 1, l, (l + r) / 2)
        val vr = getSum(a, b, 2 * k + 2, (l + r) / 2, r)

        return vl + vr
    }
}

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val S = readInputLine().toCharArray()
    val Q = readInputLine().toInt()

    val segTree = Array(26) { IntSegmentTree(N) }

    for (i in 0 until N) {
        segTree[S[i] - 'a'].update(i, 1)
    }

    for (i in 0 until Q) {
        val (q, p1, p2) = readInputLine().split(" ")
        if (q == "1") {
            val index = p1.toInt() - 1
            val ch = p2.first()

            segTree[S[index] - 'a'].update(index, 0)
            segTree[ch - 'a'].update(index, 1)
            S[index] = ch
        } else {
            val l = p1.toInt() - 1
            val r = p2.toInt() - 1

            var cnt = 0
            for (k in 0 until 26) {
                if (segTree[k].getSum(l, r + 1) != 0) {
                    cnt++
                }
            }

            println(cnt)
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 180004
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 998244353;
int p2(int a) {
	if (a == 0)return 1;
	int res = p2(a / 2);
	res = (res*res) % MOD;
	if (a % 2 == 1)res = (res * 2) % MOD;
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	int a, b, c;
	map<pair<int, int>, int> mp;
	map<pair<int, int>, int> kakutei;
	pair<int, int> p;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--;
		b--;
		if (a > b)swap(a, b);
		p.first = a; p.second = b;
		if (mp.count(p) == 0) {
			mp[p] = c;
		}
		else {
			kakutei[p] = (mp[p] + c) % 2;
		}
	}
	int t = N - 3;
	int num = t*(t + 1) / 2;

	for (auto m : kakutei) {
		if (m.first.second - m.first.first >= 3) {
			if (m.second == 1) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	for (auto m : mp) {
		if (m.first.second - m.first.first >= 3) {
			num--;
		}
	}
	int res = p2(num);
	//cerr << res << " " << num << endl;

	vector<vector<int> > dp(N, vector<int>(2, 0));
	p.first = 0; p.second = 0;
	if (mp.count(p) == 0) {
		dp[0][0] = 1;
		dp[0][1] = 1;
	}
	else {
		dp[0][mp[p]] = 1;
	}
	mp[make_pair(N - 2, N)] = 0;
	int tpr;
	int tmn;
	int tmx;
	for (int i = 1; i < N; i++) {
		int mn = 0;
		int mx = 1;
		int pr = 1;
		p.first = i; p.second = i;

		if (mp.count(p) == 0) {
		}
		else {
			t = mp[p];
			mn = max(mn, t);
			mx = min(mx, t);
		}

		p.first = i - 1; p.second = i + 1;
		if (mp.count(p) == 0) {
			pr *= 2;
		}
		else {
			if (kakutei.count(p) == 0) {
				//pr *= 1;
			}
			else {
				t = kakutei[p];
				mn = max(mn, t);
				mx = min(mx, t);
			}
		}

		tpr = pr;
		tmn = mn;
		tmx = mx;
		for (int from = 0; from < 2; from++) {
			if (dp[i - 1][from] != 0) {
				pr = tpr;
				mn = tmn;
				mx = tmx;
				p.first = i - 1; p.second = i;
				if (mp.count(p) == 0) {
					pr *= 2;
				}
				else {
					if (kakutei.count(p) == 0) {
						//pr *= 1;
					}
					else {
						t = (from + kakutei[p]) % 2;
						mn = max(mn, t);
						mx = min(mx, t);
					}
				}


				for (int to = mn; to <= mx; to++) {
					dp[i][to] = (dp[i][to] + ((pr * dp[i - 1][from]) % MOD)) % MOD;
				}
			}
		}
	}
	res = (((dp[N - 1][0] + dp[N - 1][1]) % MOD) * res) % MOD;
	cout << res << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;cin>>a>>b>>c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 200010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int pre[maxn],deg[maxn];
queue<int>q;
int a[maxn],vis[maxn];
int book[maxn];
int head[maxn],nxt[maxn],to[maxn],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
int cnt;
int main()
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        pre[i]=read();
        add(pre[i],i);
        deg[pre[i]]++;
    }
    for(int i=1;i<=n;i++)
      if(!deg[i])  q.push(i);
    while(q.size())
    {
        int now=q.front();
        book[now]=1;
        cnt++;
        q.pop();
        deg[pre[now]]--;
        if(!deg[pre[now]])  q.push(pre[now]);
        for(int i=head[now];i;i=nxt[i])  vis[a[to[i]]]=now;
        while(vis[a[now]]==now)  a[now]++;
    }
    if((n-cnt)%2==0)
    {
        puts("POSSIBLE");
        return 0;
    }
    int las=-1;
    for(int i=1;i<=n;i++)
    {
        if(book[i])  continue;
        for(int j=head[i];j;j=nxt[j])
          if(book[to[j]])  vis[a[to[j]]]=i;
        int tmp=0;
        while(vis[tmp]==i)  tmp++;
        if(las==-1)  las=tmp;
        else{
            if(las!=tmp)
            {
                puts("POSSIBLE");
                return 0;
            }
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 6784
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>ch;
	if(ch=='a'||ch=='i'||ch=='u'||ch=='e'||ch=='o'){
		cout<<"vowel";
	}else{cout<<"consonant";}



	cout<<endl;
} 


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

using namespace std;

int n, ar[1000001];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        scanf("%d", &ar[i]);

    sort(ar + 1, ar + n + 1, greater<int>());

    int a = 1, b = 1;
    while(ar[b] >= a)
    {
        b++;
        a++;
    }
    b--;
    a--;

    int t1 = 1, t2 = 1;

    if((ar[b] - a) % 2 == 1)
        t1 = 0;

    int q = 0;
    for(int i = 1; i <= n; i++)
        if(ar[i] >= a)
            q++;

    if((q - a) % 2 == 1)
        t2 = 0;

    if(t2 + t1 != 2)
    {
        cout << "First" << endl;
    }else
    {
        cout << "Second" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int a,b,c,d,e,f;
    double x,y;
    while (std::cin >> a >> b >> c >> d >> e >> f) {
        int delta = (a * e) - (b * d);
        x = (e * c + -b * f) / (double) delta + 0;
        y = (-d * c + a * f) / (double) delta + 0;
        std::printf("%.3f %.3f\n", x, y);
    }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	int x, a;
	cin >> x >> a;
	if(x < a) cout << 0 << endl;
	else cout << 10 << endl;
}


Measured memory_bytes: 256
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      match split_on_char ' ' (read_line ()) with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | ["find"; n] -> print_endline (if find (int_of_string n) t then "yes" else "no"); read (i + 1) t
      | _ -> print t; read (i + 1) t in
  read 0 (create ())

Measured memory_bytes: 27124
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;
const int M           	= 1e9 + 7;

ll dp[N];
int main(){
	
	ll n;
	cin>>n;

	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}	

	dp[n-1] = a[n-1];
	for(ll i=n-2;i>=0;i--){
		dp[i]  = dp[i+1] + a[i];
		dp[i] %= M;
	}
	ll sum = 0;
	for(ll i=0;i<n-1;i++)
		sum += (dp[i+1]*a[i]),
		sum %= M;

	cout<<sum<<endl;
	

	return 0;
}

Measured memory_bytes: 6764
#include <stdio.h>


int main()
{
	int N, D;
	scanf("%d %d", &N, &D);
	if (N % (2 * D + 1) == 0) {
		printf("%d\n", (N / (2 * D + 1)));
	}
	else {
		printf("%d\n", (N / (2 * D + 1)) + 1);
	}
    return 0;
}

Measured memory_bytes: 128
import random
import time

start = time.time()
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]


def main():
    best_ans = []
    best_score = 0
    last_day = [-1] * 26
    for d in range(365):
        d_ans = -1
        d_score = -float('inf')
        d_last_day = [-1] * 26
        for t in range(26):
            d_tmp_score = 0
            d_tmp_score += S[d][t]
            d_tmp_last_day = last_day[:]
            d_tmp_last_day[t] = d
            for c, ld in zip(C, d_tmp_last_day):
                d_tmp_score -= c * (d - ld)

            if d_tmp_score > d_score:
                d_ans = t
                d_score = d_tmp_score
                d_last_day = d_tmp_last_day[:]

        best_ans.append(d_ans)
        best_score += d_score
        last_day = d_last_day[:]

    #print(best_score)
    for a in best_ans:
        print(a + 1)


def calc_score(T):
    score = 0
    last_day = [-1] * 26
    for d in range(D):
        t = T[d % 26]
        score += S[d][t]
        last_day[t] = d
        for c, ld in zip(C, last_day):
            score -= c * (d - ld)
    return score


if __name__ == "__main__":
    main()


Measured memory_bytes: 84192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		if (s.substring(2, 3).equals(s.substring(3, 4)) && s.substring(4, 5).equals(s.substring(5, 6))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


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

ll n;
ll a[100005];

int main(){
    cin >> n;
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    ll memo=1e9;
    ll ans;
    ll m=a[n-1];
    if(m%2==1){
        for(ll i=0;i<n;i++){
            if(memo>min(abs(m/2-a[i]),abs(m/2+1-a[i]))){
                memo=min(abs(m/2-a[i]),abs(m/2+1-a[i]));
                ans=a[i];
            }
        }
    }
    else{
        for(ll i=0;i<n;i++){
            if(memo>abs(m/2-a[i])){
                memo=abs(m/2-a[i]);
                ans=a[i];
            }
        }
    }
    cout << a[n-1] << " " << ans << endl;
}


Measured memory_bytes: 4336
#include<stdio.h>
#include<algorithm>
using namespace std;
int x[100000];
int d[100000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int dn;
	scanf("%d",&dn);
	for(int di=0;di<dn;di++){
		int n,k;
		int i,j;
		scanf("%d %d",&n,&k);
		for(i=0;i<n;i++)scanf("%d",&x[i]);
		int ans=x[n-1]-x[0];
		for(i=0;i<n-1;i++)d[i]=x[i+1]-x[i];
		sort(d,d+n-1);
		for(i=n-2;i>=max(0,n-k);i--)ans-=d[i];
		printf("%d\n",ans);
	}
	return 0;
}

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

ll gcd(ll a, ll b) {return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll f(ll n, int x, int y){
  ll res = n;
  res -= n/x;
  res -= n/y;
  res += n/lcm(x,y);
  return res;
}


int main(){
  ll A,B;
  int C,D;
  cin >> A >> B >> C >> D;
  ll ans = f(B,C,D)-f(A-1,C,D); 
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    x, y, a, b, c = list(map(int, input().strip().split()))
    p = sorted(list(map(int, input().strip().split())), reverse=True)[:x]
    q = sorted(list(map(int, input().strip().split())), reverse=True)[:y]
    r = sorted(list(map(int, input().strip().split())), reverse=True)
    print(sum(sorted(p + q + r, reverse=True)[:x+y]))

if __name__ == '__main__':
    main()

   

Measured memory_bytes: 98344
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int water[31],sugar[3001];
  rep(i,31)water[i]=0;
  rep(i,3001)sugar[i]=0;
  rep(x,31){
  for(int i=0;i*b<=x;i++){
    int s=x-b*i;
    if(s%a==0)water[x]=1;
    }
    }
  rep(x,3001){
  for(int i=0;i*d<=x;i++){
    int s=x-d*i;
    if(s%c==0)sugar[x]=1;
    }
    }
  int wans=10000,sans=0,g=f/100;
  REP(i,1,g)
  if(water[i])wans=i*100;
  REP(i,1,g){
    if(water[i]==1){
      int smax=min(e*i,f-100*i);
      for(int j=smax;j>=0;j--){
        if(sugar[j]==1){
          if(sans*(j+100*i)<j*(wans+sans)){
            wans=100*i;
            sans=j;
            break;
            }
          }
        }
      }
    }
  cout<<wans+sans<<" "<<sans<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int A=0;
    int B=0;
    int C=0;
    int X=0;
    int ok=0;
    
    cin>>A;
    cin>>B;
    cin>>C;
    cin>>X;
    
    int a[100][100][100];
    int x=0;
    int y=0;
    int z=0;
    
    for(x=0;x<A+1;x++){
        for(y=0;y<B+1;y++){
            for(z=0;z<C+1;z++){
            //cout<<x<<y<<z<<endl;
            if(X==500*x+100*y+50*z){
                ok++;
            }
            }
            
        }
        
    }
    
    cout<<ok<<endl;
    
}

Measured memory_bytes: 256
/* ****AWARE**** */
#include<bits/stdc++.h>
#include <limits.h> 
#define cut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair< ll, ll>
#define vi          vector< ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(  ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp13       make_pair
using namespace std; 
#define MAX  3000000000
#define MODULO 2
using namespace std;   
#define hell 1000000007 
#define hell1 30000000000000000
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define mysizeof(i) (char*)(&i+1)-(char *)(&i);
ll T;

void solve()
{ long long int a=-1,b=-1,c=-1,w,i,j,ans=0,ans1,ans2;
  string s,t;
  cin>>s>>t;
  int n=s.size(),m=t.size();
  ll dp[n+1][m+1];
 // ll mp[max(n,m)+1];
  for(i=0;i<=n;i++)
  {
  	for(j=0;j<=m;j++)
  	{
  		if(i==0 || j==0)
  		{
  			dp[i][j]=0;
  			continue;
  		}
  		if(s[i-1]!=t[j-1])
  		{
  			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

  		}
  		else
  		{
  			dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
  		}
  	}
  }
  i=n;j=m;
  if(dp[n][m]==0)
  {
  	cout<<"";
  	return ;
  }

  string st=s;
  ll  k=dp[n][m]-1;
  while(i!=0 && j!=0)
  {
  	if(s[i-1]!=t[j-1])
  		{
  			if(dp[i-1][j]<dp[i][j-1])
  			 j--;
  			else
  			 i--;

  		}
  		else
  		{
  			 if(dp[i-1][j-1]+1 > max(dp[i-1][j],dp[i][j-1]))
  			 { 
                i--;
                j--;
                st[k]=s[i];
                k--;
  			 }
  			 else
               {
                  if(dp[i-1][j]<dp[i][j-1])
  			        j--;
  			      else
  			       i--;
               }
  			
  		}
  }
  cout<<st.substr(0,dp[n][m]);
  
}
           
int main(){ 
cut; 
ll t; 
//cin>>t;
//T=t;
 t=1;
while(t--)
solve();
return 0;
}
     


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    i64 n, t, s, e;
    cin >> n >> t >> s >> e;
    --s, --e;
    vector<vector<pair<i64,i64>>> edges(n);
    vector<vector<pair<i64,i64>>> childs(n);

    vector<i64> w(n - 1);
    vector<i64> not_back(n - 1);

    vector<i64> a(n - 1), b(n - 1);
    for(i64 i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i] >> w[i];
        --a[i], --b[i];
        edges[a[i]].emplace_back(b[i], i);
        edges[b[i]].emplace_back(a[i], i);
    }

    vector<i64> flag(n, 0);
    function<bool(i64)> f = [&](i64 x){
        bool fl = (x == e);
        for(auto& to : edges[x]){
            if(flag[to.first])
                continue;
            flag[to.first] = true;
            bool res = f(to.first);
            not_back[to.second] = res;
            fl |= res;
            childs[x].emplace_back(to);
        }
        sort(childs[x].begin(), childs[x].end(), [&](auto x, auto y){
            if(not_back[x.second])
                return false;
            if(not_back[y.second])
                return true;
            return w[x.second] > w[y.second];
        });
        return fl;
    };
    flag[s] = 1;
    f(s);

    function<i64(i64)> g = [&](i64 x){
        i64 vis_cnt = (x != s);
        for(auto& to : childs[x]){
            i64 res = g(to.first);
            i64 use_cnt = not_back[to.second] ? vis_cnt : res + vis_cnt;
            if(w[to.second] <= t * use_cnt){
                cout << "No" << endl;
                exit(0);
            }
            ++vis_cnt;
        }
        return vis_cnt;
    };
    g(s);


    cout << "Yes" << endl;

}



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

#define ll long long int
#define pd push_back
#define mp make_pair
#define mod 1000000007
#define MAX 100001

ll power(ll a,ll b){ll ans=1;while(b>0){if(b&1){ans = (ans*a);}b>>=1;a=a*a;}return ans;}
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}

int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   // cout << fixed << setprecision(10);
   ll n;
   cin>>n;
   ll arr[n+1]={0};
   arr[0]=0;
   for(ll i=1;i<=n;i++){
       cin>>arr[i];
   }
   ll sub[n+1]={0};
   ll add[n+1]={0};
   sub[0]=0;
   add[0]=0;
   for(ll i=1;i<=n;i++){
       sub[i]=arr[i]-i;
       add[i]=arr[i]+i;
   }
   map<ll,ll> mp1;
   map<ll,ll> mp2;
   for(ll i=1;i<=n;i++){
       mp1[add[i]]++;
       if(sub[i]<=0){
           mp2[abs(sub[i])]++;
       }
   }
   ll ans=0;
   for(auto it=mp2.begin();it!=mp2.end();it++){
       ll p=it->first;
       ll cnt=it->second;
       if(mp1[p] > 0){
           ll ct=mp1[p];
           ans += (cnt*ct);
       }
   }
   cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27172
s = input()
t = input()
d = {}
for si, ti in zip(s, t):
    if si in d:
        if d[si] != ti:
            print('No')
            exit()
    else:
        d[si] = ti
l = len(set(d.values()))
print('Yes' if len(d) == l else 'No')

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int w,h,n;cin>>w>>h>>n;
    vector<int>V[w];
    vector<int>Max(w,0);
    int x,y;
    rep(i,n){
        cin>>x>>y;
        V[x].push_back(y);
    }
    rep(i,w){
        int ma=0;
        rep(j,V[i].size()){
            ma=max(ma,V[i][j]);
        }
        Max[i]=ma;
    }
    rep(i,w-1){
        Max[w-2-i]=max(Max[w-i-1],Max[w-2-i]);
    }
    int ans=INF;
    rep(i,w-1){
        ans=min(ans,i+Max[i+1]);
    }
    ans=min(ans,w-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
//const ll INF64 = 9223372036854775807ll;
const ll INF64 = 9223372036854775ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;
int main(){
    ll x,y;
    std::cin >> x>>y;
    int ans=0;
    while(x<=y){
        ans++;
        x+=x;
    }
    std::cout << ans << std::endl;
    
}

Measured memory_bytes: 256
S = input()
T = input()

flag = 0
if S == T:
    flag = 1

for i in range(100):
    s = S[-1]
    S = S[0:len(S)-1]
    S = s + S
    if S == T:
        flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")

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

long long nCr(long long n, long long r); 
long long modinv(long long a, long long m);

int main(){
    long long S, S_n, ans = 0, n_l;
    double d_S, n;
    std::cin >> S;
    d_S = (double)S;

    n = 1.0;//1分割
    while(d_S/n >= 3.0){
        n_l = (long long)round(n);
        S_n = S - 3 * n_l; //分割分の3を確保
        ans = (ans + nCr(S_n + n_l -1, n_l-1))%1000000007;
        n = n + 1.0; //分割数を更新
    }

    if(ans < 0){
        ans = ans + 1000000007;
    }
    std::cout << ans;

}

long long nCr(long long n, long long r){
    long long ans;
    long long bunbo = 1, bunshi = 1;
    for(long long i = 0; i < r; i++){
        bunshi = (bunshi * (n-i))%1000000007;
        bunbo = (bunbo * (r-i))%1000000007;
    }
    ans = bunshi * modinv(bunbo, 1000000007);
    ans = ans%1000000007;
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if ((x+r >W || y+r >H)){
        cout << "No" << endl;
        return 0;
    }
    else if(x<r || y<r){
        cout << "No" << endl;
        return 0;
    }
    else{
        cout << "Yes" << endl;
        return 0;
    }
}


Measured memory_bytes: 3092
#include<stdio.h>
int main(void){
    int a,n,max,min;
    long long int sum;
    max = -1000000;
    min = 1000000;
    sum = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        if(a<min) min=a;
        if(a>max) max=a;
        sum= sum+a;
    }
    printf("%d %d %lld\n",min,max,sum);
    
    return 0;
}
/*
#include <stdio.h>
int main(void){
	int a,i,max,mini,n;
	long long int sum;
	max=-1000000;
	mini=1000000;
	sum=0;
	scanf("%d",&n);

	for (i=1 ; i<=n ; i=i+1){
		scanf("%d",&a);
		if(mini>a) mini=a;
		if(max<a) max=a;
		sum=sum+a;
	}
	printf("%d %d %lld\n",mini,max,sum);
	return 0;
}
*/



Measured memory_bytes: 2144
s=raw_input()
K=int(raw_input())
ozp1=123



ls=list(s)
for i in range(len(ls)):
    nowwork=ozp1-ord(ls[i])
    if i==len(ls)-1:
        K%=26
        #print K,nowwork
        ls[i]=chr(ord(ls[i])+K)
        if ord(ls[i])>ord("z"):
            zu=ord(ls[i])-ord("z")-1
            #print zu
            ls[i]=chr(ord("a")+zu)
    if K==0:
        break

    if ls[i]=="a":
        continue
    if nowwork<=K and (len(ls)-1!=i):
        K-=nowwork
        ls[i]="a"

print "".join(ls)


Measured memory_bytes: 15984