akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	int n;
	int ans = 0;

	scanf("%d", &n);

	while (n) {
		if (n % 10 == 2) {
			ans = ans + 1;
		}

		n = n / 10;
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
char S[10101];
st,sz;
N;
main(){
  read(0,S,10101);
  if(S[1]==10)st=2,N=S[0]-'0';
  else st=3,N=(S[0]-'0')*10+S[1]-'0';
  sz=st;
  for(;S[sz]!=10;)
  {
    S[sz]+=N;
    if(S[sz]>90)S[sz]-=26;
    sz++;
  }
  write(1,S+st,sz-st);
}

Measured memory_bytes: 128
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	ll n, d;
	cin >> n >> d;
	VLL x(n);
	VLL y(n);
	REP(i, n) { cin >> x[i] >> y[i]; }
	VLL dist(n);
	REP(i, n) { dist[i] = square(x[i]) + square(y[i]); }
	int result = 0;
	REP(i, n) { result += dist[i] <= square(d) ? 1 : 0; }
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 7944
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    auto check=[&](int x) {
        ll cnt = 0;
        rep(i,N) {
            cnt += (A[i]-1)/x;
        }
        return cnt <= K;
    };

    int ok = *max_element(all(A));
    int ng = 0;
    while (ok-ng>1) {
        int mid = (ok+ng)/2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << ln;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
#define rep(i, n) for(ll i = 0; i < (n); i++)
int main() {
  ll H,W,cnt=0,dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
  cin>>H>>W;
  vector<string> v(H);
  rep(i,H) cin>>v[i];
  vector<vector<ll>> w(H,vector<ll>(W,-1));
  rep(i,H) rep(j,W) if(v[i][j]=='#') w[i][j]=-2,cnt++;
  queue<pint> que;
  que.push(pint(0,0));
  w[0][0]=0;
  while(!que.empty()){
    auto c=que.front();que.pop();
    rep(i,4){
      ll ny=c.first+dy[i];
      ll nx=c.second+dx[i];
      if(nx<0 || ny<0 || W<=nx || H<=ny) continue;
      if(w[ny][nx]==-1){
        w[ny][nx]=w[c.first][c.second]+1;
        que.push(pint(ny,nx));
      }
    }
  }
  if(w[H-1][W-1]==-1) cout<<-1<<endl;
  else cout<<W*H-cnt-(w[H-1][W-1]+1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main() {
string s;
getline(cin,s);
int x=s.length();
int i=0;
int sum=0;
while(i<x){
    sum+=s[i]-'0';
    if(sum%9==0){
        sum=0;
    }
    i++;
}
if(sum%9==0){
    cout<<"Yes";
}else{
cout<<"No";
}
//cout<<ans;
        return 0;
}


Measured memory_bytes: 3748
def solve(S):
    mod = 10**9+7
    dp = [0] * (S+1)
    dp[0] = 1

    for i in range(3, S+1):
        dp[i] = dp[i-1] + dp[i-3]
        dp[i] %= mod

    return dp[S]


if __name__ == "__main__":
    S = int(input())

    print(solve(S))


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int n,a,b; cin >> n >> a >> b;
    cout << min(a*n, b) << 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 int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ll = long long;

string gen(string &s, string &a, string &b) {
    int N = s.size();
    int M = a.size();
    string ret;
    for (int idx = 0; idx < N;) {
        if (idx < N - M + 1 && s.substr(idx, M) == a) {
            ret += b;
            idx += M;
        } else {
            ret += s[idx];
            idx++;
        }
    }
    return move(ret);
}

string goal;
int ans;
string A[11], B[11];
int N;
void dfs(string &now, int cnt) {
    if (now == goal) {
        ans = min(ans, cnt);
        return;
    }
    if (cnt >= 9 || cnt >= ans) return;
    REP(i, N) {
        string tmp = gen(now, A[i], B[i]);
        if (tmp != now) {
            dfs(tmp, cnt + 1);
            // cerr << now << " " << A[i] << " " << B[i] << " -> " << tmp << endl;
        }
    }
}

bool solve() {
    cin >> N;
    if (N == 0) return false;
    REP(i, N) cin >> A[i] >> B[i];
    string now;
    cin >> now;
    cin >> goal;
    ans = 1e9;
    dfs(now, 0);
    if (ans < 1e9)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return true;
}

signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

const int D = 60;
int to[D][200005];

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

  ll n,k; cin >> n >> k;
  rep(i, n) {
    cin >> to[0][i];
    --to[0][i];
  }

  rep(i, D - 1) {
    rep(j, n) {
      to[i + 1][j] = to[i][to[i][j]];
    }
  }

  int v = 0;
  for(int i = D - 1; i >= 0; --i) {
    ll l = 1ll << i;
    if(k >= l) {
      v = to[i][v];
      k -= l;
    }
  }

  cout << v + 1 << endl;
}


Measured memory_bytes: 50516
#include <bits/stdc++.h>
using namespace std;
int n,m,sum;
int t[101],p[101],x[101];
int main(){
	cin>>n;
	for(register int i=1;i<=n;i++){
		cin>>t[i];
		sum+=t[i];
	}
	cin>>m;
	for(register int i=1;i<=m;i++){
		cin>>p[i]>>x[i];
		cout<<sum-(t[p[i]]-x[i])<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto K = RD;
	auto p = RDA;

	long ans;
	p.sort();
	foreach (i; 0..K)
	{
		ans += p[i];
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2776
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0;

signed main(){
    string s,t,u;
    cin>>s>>t;
    a=s.size();b=t.size();c=b;
    rep(i,a-b+1){
        u=s.substr(i,b);
        d=0;
        rep(j,b){
            if(u[j]!=t[j])d++;
        }
        if (c>d)
        {
            c=d;
        }
    }
    print(c);
   
}


Measured memory_bytes: 3136
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long 
#define int ll
//#define slld(t) scanf("%lld",&t)
// #define sd(t) scanf("%d",&t)
// #define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define pdd pair<double , double>
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N    200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
#define s3   1.73205080757          // square root 3
const  int inf = (int)1e18+10 ;
const int MAX= 100;

 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set S;

int powmod(int x , int y){
	int res = 1;
	while(y > 0){
		if(y%2==1)
			res = (res*x)%mod;
		x = (x*x)%mod;
		y/=2;
	}
	return res;
}
int mul(int x , int y){
	return (x*y)%mod;
}
int a[N + 10] = {0};
void pre(){
	a[1] = 1;
	for(int i = 2 ; i*i <= N ; i++){
		   if(a[i] == 0){
		   	   for(int j = i*i ; j <= N ; j+=i)
		   	   	  a[j] = 1;
		   }
	}
}
int dp[N][3] = {{0}};
signed main(){
  fast;
 
 
  int n , k , r , s , p;
  string t;
  cin >> n >> k ;
  cin >> r >> s >> p;
  int cost[] = {r , s , p};
  cin >> t;
  for(int i = 0 ; i < n ; i++)
  	   if(t[i] == 'r') t[i] = '0';
  	   else if(t[i] == 's') t[i] = '1';
  	   else t[i] = '2';
  int ans = 0 , tot = 0;
  for(int i = 0 ; i < k ; i++){
        if(t[i] == '0'){
        	   dp[i][0] = 0;
        	   dp[i][1] = 0;
        	   dp[i][2] = p;
        }
         else if(t[i] == '1'){
        	   dp[i][0] = r;
        	   dp[i][1] = 0;
        	   dp[i][2] = 0;
        } 
        else if(t[i] == '2'){
        	   dp[i][0] = 0;
        	   dp[i][1] = s;
        	   dp[i][2] = 0;
        }
        ans = max({dp[i][0] , dp[i][1] , dp[i][2]});
  	   for(int j = i + k ; j < n ; j += k){
  	   	      int  f = (int)(t[j] - '0');
               for(int e = 0 ; e < 3 ; e++){
               	     if(e == (f+2)%3){
               	     	  dp[j][e] = cost[e] + max(dp[j-k][(e + 2)%3] , dp[j-k][(e+1)%3]);
               	     }
               	     else{
               	     	     dp[j][e] = max(dp[j-k][(e + 2)%3] , dp[j-k][(e+1)%3]);
               	     }

               }
               ans -= max({dp[j-k][0] , dp[j-k][1] , dp[j-k][2]});
               ans += max({dp[j][0] , dp[j][1] , dp[j][2]});
  	   }
      tot += ans;
  }
  cout << tot << endl;

 }

Measured memory_bytes: 4560
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    ll all_sum=0;
    rep(i,0,n){
        cin>>a[i];
        all_sum+=a[i];
    }
    ll mini=LINF;
    ll tmp=0;
    rep(i,0,n-1){
        tmp+=a[i];
        mini=min(mini,abs(all_sum-2*tmp));
        // debug(abs(all_sum-2*tmp));
    }
    cout<<mini<<endl;
}

Measured memory_bytes: 1920
import java.util.Scanner;

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

        long H = sc.nextLong();

        int attackTimesForOne = 0;

        for (int n = 0;; n++) {
            if (Math.pow(2, n) > H) {
                attackTimesForOne = n;
                break;
            }
        }

        System.out.println((long) Math.pow(2, attackTimesForOne) - 1);
    }

}


Measured memory_bytes: 21588
n = int(input())
for i in range(n):
    r,t = map(int,input().split())
    if t % 30 == 0:
        if r % 100 == 0:
            print(int((t / 30) * 5 + r / 100))
        else:
            print(int((t / 30) * 5 + 1 + int((r - 100) / 100)),int((t / 30) * 5 + int((r - 100) / 100) + 2))
    else:
        if r % 100 == 0:
            print(int(int(t / 30) * 5 + 1 + int((r - 100) / 100)),int(int(t / 30) * 5 + int((r - 100) / 100) + 6))
        else:
            print(int(int((t) / 30) * 5 + 1 + int((r - 100) / 100)),int(int((t) / 30) * 5 + int((r - 100) / 100) + 2),end = " ")
            print(int(int((t) / 30) * 5 + 6 + int((r - 100) / 100)),int(int((t) / 30)* 5 + int((r - 100) / 100) + 7))
            

Measured memory_bytes: 7704
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    priority_queue<ll> Q;
    int n, m; cin >> n >> m;
    loop (n, i) {
        ll a; cin >> a;
        Q.push(a);
    }
    loop (m, i) {
        ll v = Q.top(); Q.pop();
        Q.push(v / 2);
    }
    ll ans = 0;
    while (!Q.empty()) {
        ans += Q.top();
        Q.pop();
    }
    cout << ans << endl;
    return 0;
}



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

struct Node{
	bool done;
	int cost;
};

int main() {
	// your code goes here
	int w, h;
	while(cin >> w >> h, w){
		int vmaze[30][30] = {};
		int hmaze[30][30] = {};
		Node node[30][30];
		for(int i=0; i<w; i++){
			for(int j=0; j<h; j++){
				node[i][j].done = false;
				node[i][j].cost = 900;
			}
		}
		for(int i=0; i<2*h-1; i++){
			if(i%2 == 0){
				for(int j=0; j<w-1; j++){
					cin >> vmaze[j][i/2];
				}
			}
			else {
				for(int j=0; j<w; j++){
					cin >> hmaze[j][i/2];
				}
			}
		}
		node[0][0].cost = 0;
		while(1){
			int di = -1, dj = -1;
			for(int i=0; i<w; i++){
				for(int j=0; j<h; j++){
					if(node[i][j].done == true) continue;
					if(node[i][j].cost == 900) continue;
					if(di < 0 || node[i][j].cost < node[di][dj].cost){
						di = i; dj = j;
					}
				}
			}
			if(di == -1) break;
			node[di][dj].done = true;
			
			// cout << di << " " << dj << " " << node[di][dj].cost << endl;
			
			if(dj>0 && hmaze[di][dj-1]==0){
				node[di][dj-1].cost = min(node[di][dj-1].cost, node[di][dj].cost + 1);
			}
			if(dj<h-1 && hmaze[di][dj]==0){
				node[di][dj+1].cost = min(node[di][dj+1].cost, node[di][dj].cost + 1);
			}
			if(di>0 && vmaze[di-1][dj]==0){
				node[di-1][dj].cost = min(node[di-1][dj].cost, node[di][dj].cost + 1);
			}
			if(di<w-1 && vmaze[di][dj]==0){
				node[di+1][dj].cost = min(node[di+1][dj].cost, node[di][dj].cost + 1);
			}
		}
		cout << (node[w-1][h-1].cost==900?0:node[w-1][h-1].cost+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const ll INF = 10000000000;
int main() {
    int n;
    cin >> n;
    ll a[n + 1];
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sum /= 2;
    ll ans[n + 1];
    ans[1] = sum;
    for (int i = 2; i <= n - 1; i += 2) {
        ans[1] -= a[i];
    }
    for (int i = 2; i <= n; i++) {
        ans[i] = a[i - 1] - ans[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i]*2 << " ";
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
int main(){
    fast_io

    int n;
    cin>>n;
    vector<vector<int>> G(n);
    vector<P> vp;
    for(int i=1;i<n;i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a, b);
    }
    int K=0;
    map<P,int> I;
    vector<int> cs(n,0); //color of edge between its parent

    vector<int> used(n, 0);
    queue<int> que;
    used[0]=1;
    que.emplace(0);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        if(K<(int)G[v].size()) K=G[v].size();
        int cur=1;
        for(int u: G[v]){
            if(used[u]) continue;
            if(cur == cs[v]) cur++;
            cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
            used[u]=1;
            que.emplace(u);
        }
    }

    cout<<K<<endl;
    for(auto p:vp) cout<<I[p]<<endl;
    return 0;
}

Measured memory_bytes: 20088
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


h, w = LI()
a = [list(S()) for _ in range(h)]
ans = [[a[j][i] for i in range(w)] for j in range(h)]
# is_white_line = [[False for _ in range(w)] for __ in range(h)]
# is_white_row = [[False for _ in range(h)] for __ in range(w)]

for i in range(h):
    is_white = True
    for j in range(w):
        if a[i][j] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        ans[i] = [False] * w

for i in range(w):
    is_white = True
    for j in range(h):
        if a[j][i] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        for j in range(h):
            # ans[i].pop(j)
            ans[j][i] = False

for i in range(w):
    is_white = True
    for j in range(h):
        if a[j][i] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        for j in range(h):
            # ans[i].pop(j)
            ans[j][i] = False
res = ''
for i in range(h):
    if not(any(ans[i])):
        continue
    for j in range(w):
        if ans[i][j]:
            res += ans[i][j]
    res += '\n'
print(res.rstrip('\n'))


Measured memory_bytes: 9460
n = int(input())
ans = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(n):
	s = input()
	ans[s]+=1

print(f"AC x {ans['AC']}")
print(f"WA x {ans['WA']}")
print(f"TLE x {ans['TLE']}")
print(f"RE x {ans['RE']}")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    vector<int>a(3);
    cin >> a;
    sort(RALL(a));
    if (a[0] == a[1] and a[1] == a[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
import Control.Monad (unless)

collatz :: Integral a => a -> [a]
collatz = takeWhile (> 0) . iterate f
    where
        f 1 = 0
        f x
            | even x = div x 2
            | otherwise = 3 * x + 1

main :: IO ()
main = do
    n <- readLn
    unless (n == 0) $ do
        print $ subtract 1 $ length $ collatz n
        main

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  rep(i,n){
    ll b; cin>>b;
    a[i]-=b;
  }
  vsort(a);
  
  ll cnt=0;
  ll sum=0;
  rep(i,n){
    if(a[i]<0){
      sum+=-a[i];
      cnt++;
    }
    else break;
  }
  
  if(sum<=0){
    cout<<0<<endl;
    return 0;
  }
  
  rrep(i,n){
    if(a[i]>0){
      sum-=a[i];
      cnt++;
      if(sum<=0){
        cout<<cnt<<endl;
        return 0;
      }
    }
    else break;
  }
  
  cout<<-1<<endl;
  
}

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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 1e3+1 , W = 2e4+5;
vector < vector < int > > v(N , vector < int > (3));
long long dp[W][N];
bool compare(vector < int > &v1 , vector < int > &v2)
{
	return (v1[0] + v1[1] < v2[0] + v2[1]);
}
int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n ; cin >> n ;
	for(int i = 1 ; i <= n ; ++i)
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	sort(v.begin()+1 , v.begin()+n+1 , compare);
	for(int i = 0 ; i < W ; ++i)
	{
		for(int j = 1 ; j <= n ; ++j)
		{
			dp[i][j] = max(dp[i][j] , dp[i][j-1]);
			if(v[j][1] >= i && v[j][0] + i < W)
			{
				dp[i+v[j][0]][j] = max(dp[i+v[j][0]][j] , dp[i][j-1] + v[j][2]);
			}
		}
	}
	long long ans = INT_MIN;
	for(int i = 1 ; i < W ; ++i)
		ans = max(dp[i][n] , ans);
	cout << ans;

	return 0;
}

Measured memory_bytes: 156800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n,t,s,m;
  bool judge=true;
  
  cin>>n>>t;
  s=m=t;
  
  rep(i,n){
    int w;
    cin>>t>>w;
    s += t-w;
    if(m<s)m=s;
    if(s<0){judge=false;break;}
  }
  if(judge)cout<<m<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 1160
#include <stdio.h>

int dice3 (int *, int *);

int main (void) {
    int n;
    int faces1[6], faces2[6];

    scanf ("%d", &n);
    for (int i=0; i<6; i++) scanf ("%d", faces1+i);
    for (int i=0; i<n-1; i++) {
        for (int j=0; j<6; j++) scanf ("%d", faces2+j);
        if (dice3(faces1, faces2)) {
            printf ("No\n");
            return 0;
        }
    }

    printf ("Yes\n");
    return 0;
}


int dice3 (int *faces1, int *faces2) {
    int top;
    int sheet[6][7] = {{2, 3, 5, 4, 2, 3, 5},
                       {1, 4, 6, 3, 1, 4, 6},
                       {1, 2, 6, 5, 1, 2, 6},
                       {1, 5, 6, 2, 1, 5, 6},
                       {1, 3, 6, 4, 1, 3, 6},
                       {2, 4, 5, 3, 2, 4, 5}};
    
    for (int i=0; i<6; i++) {
        if (faces1[0]==faces2[i] && faces1[5]==faces2[5-i]) {
            top = i+1;
            for (int j=0; j<4; j++) {
                if (faces1[1]==faces2[sheet[top-1][j]-1]) {
                    for (int k=0; k<4; k++) {
                        if (faces1[sheet[0][k]-1]!=faces2[sheet[top-1][j+k]-1]) break;
                        if (k==3) return 1;
                    }
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll inf=2e18;
const int mod=998244353;
int n,k;
struct seg{
    int l,r;
}a[11];
bool operator<(seg a,seg b){
    return a.l<b.l;
}
int dp[maxn];
int sum[maxn];

int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++){
        scanf("%d%d",&a[i].l,&a[i].r);
    }
    sort(a+1,a+1+k);
    dp[1]=1;sum[1]=1;

    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            int pre=max(i-a[j].r-1,0);
            if(i-a[j].l>pre)
                dp[i]=(dp[i]+(sum[i-a[j].l]-sum[pre]+mod)%mod)%mod;
        }
        sum[i]=(sum[i-1]+dp[i])%mod;
    }
    printf("%d\n",dp[n]);


    return 0;
}


Measured memory_bytes: 5304
#define IO std::ios::sync_with_stdio(false);
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,k;
int a[10005];
int main(){
	IO;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>k;
		for(int j=1;j<=k;j++){
			int x;
			cin>>x;
			a[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){
		if(a[i]==n)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
	fast;
    ///#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll int n;
    cin>>n;
    ll int i;
    map<string,ll int> mp;
    for(i=1;i<=n;i++)
    {
    	string s;
    	cin>>s;
    	mp[s]=-1;
    }
    cout<<mp.size()<<endl;
}

Measured memory_bytes: 19204
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lynmisakura
 */

#include <iostream>
#include <fstream>

/*
 *  author : lynmisakura
 *  stay hungry, stay foolish, stay home.
 */
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;

class DLunlunNumber {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int k;cin >> k;
        queue<long long> Q;
        for (int i = 1; i < 10; ++i) {
            Q.push(i);
        }
        for(int i = 0;i < k - 1;i++){
            ll x = Q.front();Q.pop();
            //if(i < 10)cerr << x << endl;
            ll d = x % 10;
            x *= 10;
            if(d != 0)Q.push(x + d - 1);
            Q.push(x + d);
            if(d != 9)Q.push(x + d + 1);
        }
        long long ans = Q.front();
        cout << ans << endl;
	}
};


int main() {
	DLunlunNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
def main():
	n = list(str(input()))
	n_s = sorted(n)
	if n_s[0] == n_s[1] and n_s[2] == n_s[3] and n_s[1] != n_s[2]:
		print("Yes")
	else:
		print("No")

 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve() {
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }


int main() {

	long N, K; cin >> N >> K;
	long sum = 0;
	vector<long> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; sum += A[i]; }
	//求める値は総和の約数 -> まずこれを列挙する。

	set<long, greater<long>> div;

	for (int i = 1; i * i <= sum; i++) {
		if (sum % i != 0) continue;
		div.insert(i);
		div.insert(sum / i);
	}

	for (long e : div) {
		//eが答えを満たすのか判定する
		bool flag = false;
		vector<long> M(N); for (int i = 0; i < N; i++) M[i] = A[i] % e;
		sort(M.begin(), M.end());
		vector<long> cumulM(N); cumulM[0] = M[0]; for (int i = 1; i < N; i++) cumulM[i] = cumulM[i - 1] + M[i];

		for (int i = 0; i < N; i++) if (max((N - i - 1) * e - (cumulM[N - 1] - cumulM[i]) ,cumulM[i]) <= K) flag = true;
        
		if (flag) { cout << e << endl; return 0; }

	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]) cnt++;
    }
    cout << cnt;
    return 0;
}


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

int N, M, val[100000], gaps[100000], minMoves;
int main(){
  std::cin >> N >> M;
  for(int i = 0; i < M; ++i){
    std::cin >> val[i];
  }
  std::sort(val, val+M);
  for(int i = 0; i < M-1; ++i){
    gaps[i] = val[i+1] - val[i];
    //std::cout << "Gaps: " << gaps[i] << '\n';
  }
  
  std::sort(gaps, gaps+M);
  minMoves = val[M-1] - val[0];
  for(int i = 0; i < (N-1<M?N-1:M); ++i){
    minMoves -= gaps[M-i-1];
  }
 
  std::cout << minMoves;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
int a,b;
while(1)
{
scanf("%d%d",&a,&b);
if(a==b&&a==0)
return 0;
if(a>b)
printf("%d %d\n",b,a);
else
 printf("%d %d\n",a,b);
}
}


Measured memory_bytes: 2028
#include<iostream>
using namespace std;
int main()
{
	int n;
	int a,b,c;
	int x,y,z;
	int count=0;
	cin>>a>>b>>c;
	while(1)
	{
		if(a%2==1||b%2==1||c%2==1)
		break;
		x=(b+c)/2;
		y=(a+c)/2;
		z=(a+b)/2;
		count++;
		if(x%2==1||y%2==1||z%2==1)
		break;
		a=x;
		b=y;
		c=c;
		if(count>10000)
		break;
	}
	if(count<10000)
	cout<<count;
	else cout<<"-1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	if(s.size() < 26){
		for(char i = 'a'; i <= 'z'; i++){
			if(count(s.begin(), s.end(), i) == 0){
				s.push_back(i);
				break;
			}
		}
	} else {
	string t;
	while(!s.empty()){
		bool found = false;
		for(auto & c : t) if(c > s.back()){
			s.back() = c;
			found = true;
			break;
		}
		if(found) break;
		t.push_back(s.back()); s.pop_back();
	}
	}
	if(s.empty()) cout << -1 << endl;
	else cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H, W, h, w;
		H = sc.nextInt();
		W = sc.nextInt();
		h = sc.nextInt();
		w = sc.nextInt();
 
		while (h > 0) {
			h--;
			H--;
		}
 
		while (w > 0) {
			w--;
			W--;
		}
 
		int ans = H*W;
		if (ans < 0) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}
	}
 
}

Measured memory_bytes: 35576
#include<iostream>
#include<algorithm>
#include<list>
#include<vector>
#include<fstream>
using namespace std;
    
#define NUM 10000
list<int> inl[NUM];

void dump(list<int> l){
    list<int>::iterator it = l.begin();
    while(it!=l.end()){
        if(it!=l.begin()) cout << " ";
        cout << *it;
        it++;
    }
    cout << endl;
}
int main(){

    int n, q, order, t;
    cin >> n >> q;
    for(int i=0;i<q;i++){
        cin >> order >> t;
        switch (order)
        {
        case 0:
            int num;
            cin >> num;
            inl[t].push_back(num);
            break;
        case 1:
            dump(inl[t]);
            break;
        case 2:
            int s;
            cin >> s;
            inl[s].splice(inl[s].end(),inl[t]);
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 34484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  if (c - a - b <= 0) {
    cout << "No" << endl;
  }
  else {
    if (4 * a * b < (c - a - b) * (c - a - b)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
s=input()
k=int(input())
ans=0
cnt=1
add=False
lead=1
if len(s)==1:
  print(k//2)
  exit()
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    lead+=1
  else:
    break
if len(s)%2 != 0 and s.count(s[0])==len(s):
  print((len(s)*k)//2)
  exit()
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    cnt+=1
  else:
    ans+=cnt//2
    cnt=1
  if s[0] == s[-1] and lead%2!=0 and cnt%2==1 and i == (len(s)-1):
    ans+=cnt//2
    add=True
  elif i == (len(s)-1):
    ans+=cnt//2
if add:
  print((ans*k)+1*(k-1))
else:
  print(ans*k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b;cin>>a>>b;a--;
    ll mn=max((ll)-1e6,b-a);
    ll mx=min((ll)1e6,b+a);
    for(int i=mn;i<=mx;i++)cout<<i<<" ";
}


Measured memory_bytes: 256
q, h, s, d = map(int, input().split())
n = int(input())

x = min(4 * q, 2 * h, s)

if n % 2 == 0:
    print(min(x * n, n // 2 * d))
elif 2 * x < d:
    print(x * n)
else:
    print(d * (n // 2) + x)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	private static int[] ar = {1,0,0};

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));

    	String[] s;
    	while(sc.hasNext()){
    		s = sc.next().split(",");
    		swap(s[0],s[1]);
    	}

    	System.out.println(get_place());
	}

    private static void swap(String a_str,String b_str){
    	int a   = chg(a_str);
    	int b   = chg(b_str);
    	ar[b]   = ar[a] - ar[b];
    	ar[a]  -= ar[b];
    	ar[b]  += ar[a];
    }

    private static int chg(String s){
    	int ret = -1;
    	if(s.equals("A")){ret = 0;}
    	if(s.equals("B")){ret = 1;}
    	if(s.equals("C")){ret = 2;}
    	return ret;
    }

    private static char get_place(){
    	char ret = 'Z';
    	for(int i=0;i<ar.length;i++){
    		if(ar[i] == 1){
    			switch (i){
    				case 0: ret = 'A';
    				        break;
    				case 1: ret = 'B';
    				        break;
    				case 2: ret = 'C';
    			}
    		}
    	}
    	return ret;
    }
}

Measured memory_bytes: 17136
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4){
        if(s[i] == '+') ++ans;
        else --ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int64_t q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  q *= 4;
  h *= 2;
  cout << n / 2 * min({2 * q, 2 * h, 2 * s, d}) + n % 2 * min({q, h, s}) << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int n,m;
    cin>>n>>m;
    Graph G;
    G.assign(n,vector<int>());
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    que.push(0);
    vector<int> depth(n,-1);
    depth[0]=0;
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int n:G[v]){
            if(depth[n]!=-1) continue;
            que.push(n);
            depth[n]=v;
        }
    }
    
    for(int i=0;i<n;++i){
        if(depth[i]==-1){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    for(int i=1;i<n;++i){
        cout<<++depth[i]<<endl;
    }
}

Measured memory_bytes: 10148
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll x, y;
const int MAX = 1000010;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin >> x >> y;
    if (x > y) swap(x, y);

    ll k = 0;
    while (x <= y && x > 0) {
        if (y == 2 * x) break;
        if (y > 2 * x) {
            cout << 0 << endl;
            return 0;
        }
        x--; y++; k++;
    }
    // cout << k << endl;

    COMinit();
    cout << COM(x, k) << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll n,m;cin>>n>>m;
    ll a[n];rep(i,0,n)cin>>a[i];
    ll b[m],c[m];
    vector<pll> v;
    rep(i,0,m){
        cin>>b[i]>>c[i];
        v.push_back(make_pair(c[i],b[i]));
    }
    sort(a,a+n);
    sort(v.begin(),v.end(),greater<pll>());
    vector<ll> w;
    ll now=0;
    ll num=0;
    rep(i,0,n){
        now++;
        w.push_back(v[num].first);
        if(now==v[num].second){
            num++;
            now=0;
        }
        if(num==v.size())break;
    }
    rep(i,0,n){
        if(i==w.size())break;
        a[i]=max(a[i],w[i]);
    }
    ll ans=0;
    rep(i,0,n)ans+=a[i];
    cout<<ans<<endl;
    
}


Measured memory_bytes: 6000