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

using namespace std;

int main()
{

   int n,k,x,y,s;
   cin>>n>>k>>x>>y;
   if(n>k){x=k*x;}
   else{x=n*x; }
   if(n>k){y=(n-k)*y;}
   else{y=0; }
   s=x+y;
   cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans = max(a*c, a*d);
    ans = max(ans, b*c);
    ans = max(b*d, ans);
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
    int n, m; cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {cin >> a[i];sum += a[i];}
    sort(all(a),greater<int>());
    if(a[m-1] >= (double)sum/double(4*m))cout << "Yes" << endl;
    else cout << "No" << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define trav(i,c) for(auto& i:(c))
#define all(c) begin(c), end(c)
#define sz(c) (int)c.size()

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
const ll inf = 1e9;

constexpr pii unit = {INT_MAX, INT_MIN};
struct Tree {
	typedef pii T;
	T f(T a, T b) { return {min(a.first, b.first), max(a.second, b.second)}; } // (any associative fn)
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void update(int pos, T val) {
		for (s[pos += n] = val; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}
};


int main () {
	cin.tie(0);
	cin.sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vi p(n);
  trav(i,p) cin >> i;
  vi str(n,1);
  rep(i,1,n) if(p[i] > p[i-1])
    str[i] = str[i-1]+1;
  auto un = [&](int e) { return str[e] >= k; };
  Tree t(n);
  rep(i,0,n) t.update(i,{p[i],p[i]});
  int unch = 0;
  int ans = 0;
  rep(e,k-1,n) {
    int s = e-k+1;
    if (un(e)) {
      ++unch;
      continue;
    }
    if (s == 0) {
      ++ans;
      continue;
    }
    int mn, mx;
    tie(mn, mx) = t.query(s,e);
    if (!(p[s-1] < mn && mx < p[e])) {
      ++ans;
    }
  }
  ans += (unch != 0);
  cout << ans << endl;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int H,W;
char s[60][60];

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

int bfs(int y,int x){
  int d[60][60];
  bool used[60][60];

  d[1][1]=1;
  used[1][1]=true;

  queue<P>q;
  q.push(P(1,1));
  while(!q.empty()){
    P p=q.front();q.pop();
    int ny=p.first,nx=p.second;
    for(int t=0;t<4;t++){
      int ty=ny+dy[t],tx=nx+dx[t];
      if(ty<1||H<ty||tx<1||W<tx||used[ty][tx])continue;
      if(s[ty][tx]=='#')continue;
        d[ty][tx]=d[ny][nx]+1;
        used[ty][tx]=true;
        q.push(P(ty,tx));
        if(ty==H&&tx==W)return d[H][W];
    }
  }
  return 0;
}

signed main(){
  cin>>H>>W;
  int cont=0;
  for(int h=1;h<=H;h++){
    for(int w=1;w<=W;w++){
      cin>>s[h][w];
      if(s[h][w]=='#')cont++;
    }
  }

  int score=bfs(1,1);
  if(score==0){
    cout<<-1<<endl;
  }else{
    cout<<H*W-cont-score<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}

int main()
{
    ll h;
    ll ans = 0;
    int i = 0;
    scanf("%lld", &h);
    if(h == 1){
        printf("1\n");
        return 0;
    }
    while(1){
        h /= 2;
        i++;
        if(h == 1) break;
    }
    printf("%lld\n", (ll)powl(2, i+1) - 1);
    return 0;
}


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

int n;
ll mod,pw[N],S[N][N],C[N][N],ans;

ll power(ll x,ll y,ll mo) {
	ll ret=1;
	for (;y;y>>=1,x=x*x%mo)
		if (y&1) ret=ret*x%mo;
	return ret;
}

int main()
{
	scanf("%d%lld",&n,&mod);
	pw[0]=1; for (int i=1;i<=n;i++) pw[i]=pw[i-1]*2%mod;
	for (int i=0;i<=n;i++) {
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	S[1][1]=1;
	for (int i=2;i<=n+1;i++)
		for (int j=1;j<=i;j++)
			S[i][j]=(S[i-1][j]*j+S[i-1][j-1])%mod;
	for (int i=0;i<=n;i++) {
		ll sum=0;
		for (int j=0;j<=i;j++) sum=(sum+power(pw[n-i],j,mod)*S[i+1][j+1])%mod;
		if (i&1) ans=(ans-sum*C[n][i]%mod*power(2,power(2,n-i,mod-1),mod)%mod+mod)%mod;
		else ans=(ans+sum*C[n][i]%mod*power(2,power(2,n-i,mod-1),mod)%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 140032
while true
  a,op,b = gets.chomp.split(" ")

  case op
  when "+"
    puts "#{a.to_i+b.to_i}"
  when "-"
    puts "#{a.to_i-b.to_i}"
  when "*"
    puts "#{a.to_i*b.to_i}"
  when "/"
    puts "#{(a.to_i/b.to_i).floor}"
  when "?"
    break
  end
end

Measured memory_bytes: 8640
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] A = new int[4];
		for (int i = 0; i < N; i++) {
			A[sc.nextInt()]++;
		}
		double[][][] dp = new double[301][301][301];
		for (int i = 0; i <= N; i++) {
			for (int j = 0; i + j <= N; j++) {
				for (int k = 0; i + j + k <= N; k++) {
					int any = i + j + k;
					double ratio = 1.0 * N / any;
					if (i > 0) {
						dp[i][j][k] += (dp[i - 1][j + 1][k] + ratio) * i / any;
					}
					if (j > 0) {
						dp[i][j][k] += (dp[i][j - 1][k + 1] + ratio) * j / any;
					}
					if (k > 0) {
						dp[i][j][k] += (dp[i][j][k - 1] + ratio) * k / any;
					}
				}
			}
		}
		System.out.printf("%.10f\n", dp[A[3]][A[2]][A[1]]);
	}
}

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

int main() {
    int N;  cin >> N;
    int ans = 10000000;
    for (int i = 0; i < N; ++i) {
        int a;  cin >> a;
        int cnt = 0;
        while (a % 2 == 0) {
            a /= 2;
            ++cnt;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <iostream>

int main() {
    using namespace std;
    int a, b, x;
    cin >> a >> b >> x;
    if (x - a < 0) {
        cout << "NO" << endl;
    } else if (x - a <= b) {
        cout << "YES" << endl;
    } else if (x - a > b) {
        cout << "NO" << endl;
    }
}

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

typedef long long ll;
using namespace std;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000005;
const ll INFLL = 1000000000000000002ll;
const ll MOD = 1000000007;

inline ll min(ll a, ll b, ll c){return min(min(a,b),c);}
inline ll min(ll a, ll b, ll c, ll d){return min(min(min(a,b),c),d);}
inline ll max(ll a, ll b, ll c){return max(max(a,b),c);}
inline ll max(ll a, ll b, ll c, ll d){return max(max(max(a,b),c),d);}

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

int N, A[100005], B[100005];
multiset<int> L;
multiset<int,greater<int>> R;

ll solve(int t)
{
    L.clear(), R.clear();
    f(i,1,N) L.insert(B[i]);
    f(i,1,N) R.insert(A[i]);
    int x = 0;
    ll ret = 0;
    f(times,1,N)
    {
        if(t == 0)
        {
            int nx = *L.begin();
            L.erase(L.begin());
            //cout << x << "->" << nx << "\n";
            if(nx < x) ret += x-nx;
            x = min(x, nx);
        }
        else
        {
            int nx = *R.begin();
            R.erase(R.begin());
            //cout << x << "->" << nx << "\n";
            if(nx > x) ret += nx-x;
            x = max(x, nx);
        }

        t ^= 1;
    }
    return ret + abs(x);
}

int main()
{
    cin >> N;
    f(i,1,N) cin >> A[i] >> B[i];
    ll ans = solve(0);
    ll ans2 = solve(1);
    cout << max(ans, ans2);
}


Measured memory_bytes: 10368
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

void solve()
{
	double x = 0;
	double y = 0;
	int a, b;
	double angle = 90;
	while(scanf("%d,%d", &a, &b))
	{
		if(a == 0 && b == 0)
		{
			break;
		}
		x += a * cos(angle / 180 * M_PI);
		y += a * sin(angle / 180 * M_PI);
		angle -= b;
	}
	cout << (int)x << endl;
	cout << (int)y << endl;
}

int main()
{
	solve();
	return(0);
}

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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int b, a;
  cin >> b >> a;
  if ((b <= 0 && 0 <= a) || b == 0 || a == 0) {
    cout << "Zero\n";
  } else if (a < 0) {
    if ((a - b) % 2 == 1) {
      cout << "Positive\n";
    } else {
      cout << "Negative\n";
    }
  } else {
    cout << "Positive\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
int f[305][305];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, k; cin >> h >> w >> k;
    vector<string> v(h);
    rep(i,h) cin >> v[i];

    vector<int> S[305];
    rep(i,h) rep(j,w) if(v[i][j]=='#') S[i].push_back(j);
    
    int now = 1;
    rep(i,h) {
        rep(j,w) {
            if(S[i].size()==0) continue;
            f[i][j] = now;
            if(now==k) continue;
            if(v[i][j]=='#') {
                if(S[i][S[i].size()-1]>j) now++;
            }
            if(j==w-1) {
                now++;
            }
        }
    }
    rep(i,h-1) {
        rep(j,w) {
            if(S[i+1].size()==0) {
                f[i+1][j] = f[i][j];
            }
        }
    }


    for(int i = h-1; i >= 1; i--) {
        rep(j,w) {
            if(S[i-1].size()==0) {
                f[i-1][j] = f[i][j];
            }
        }
    }
    
    rep(i,h) {
        rep(j,w) {
            cout << f[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
using namespace std;
long long f[4010];
long long a[4010][4010];
int main()
{
	long long n,m;
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%lld",&f[i]),f[n+i]=f[i];
	for (int i=1;i<=n*2;i++)
	{
		long long k=2e9;
		for (int j=i;j<=n*2;j++)
		{
			k=min(k,f[j]);
			a[i][j]=k;
		}
	}
	long long maxn=1e14;
	for (int l=1;l<=n;l++)
	{
		long long ans=(l-1)*m;
		if (ans>maxn) continue;
		for (int i=1;i<=n;i++)
		{
			long long k=a[i][(i+l-1)];
			ans+=k;
		}
		maxn=min(ans,maxn);
	}
	printf("%lld\n",maxn);
}

Measured memory_bytes: 125184
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define vl vector
using namespace std;
int main()
{
    ll n,a,b,i,j;
    string s;
    cin>>s>>n;
    list<char> li;
    ll count=0;
    bool rev=false;
    for(i=0;i<s.size();i++) li.pb(s[i]);
    for(i=0;i<n;i++)
    {
        cin>>a;
        if(a==1)
        {
            count++;
            rev=!rev;
        }
        else
        {
            char c;
            cin>>b>>c;
            if(rev)
            {
                if(b==1) li.pb(c);
                else li.pf(c);
            }
            else
            {
                if(b==1) li.pf(c);
                else li.pb(c);
            }
        }
    }
    if(count%2) reverse(li.begin(),li.end());
    for(auto itr=li.begin();itr!=li.end();itr++) cout<<*itr;
    
}

Measured memory_bytes: 9984
#include<iostream>
#include<cstdio>
using namespace std;
int a[33] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int k;
	cin >> k;
	cout << a[k];
	return 0;
} 

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

int main() {
  int N;
  cin >> N;
  string s;
  s = to_string(N);
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '7') {
      cout << "Yes" << endl;
      break;
    }
    if (i == s.size() - 1) {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3700
#include<cstdio>
#include<algorithm>
bool cmp(int x,int y){
	return x>y;
}
int n,now,a[100100];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1,cmp);
	for(now=1;a[now]>=now;now++);
	now--;
	if((a[now]-now)%2==0){
		int j;
		for(j=0;a[now+j]>=now;j++);
		if(j&1){
			puts("Second");
			return 0;
		}
	}
	puts("First");
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	long[] A = new long[N];
      	long[] B = new long[N];
      	for(int i = 0; i < N; i++){
          	A[i] = sc.nextInt();
          	B[i] = sc.nextInt();
        }
      	long ans = 0;
      	for(int i = N-1; i >= 0; i--){
        	if ((A[i] + ans) % B[i] == 0){
            }else{
              ans += B[i] - ((A[i] + ans) % B[i]);
            }
        }
     	System.out.println(ans);
	}
}


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

int main() {
    int A = 0, B = 0;
    int N;
    cin >> N ;
    int a[N];
    for(int i = 0; i < N ; i++) {
        cin >> a[i];
    }
   
    sort(a, a+N, greater<int>()); // 大きい順にソート

    for(int i = 0; i < N ; i++) {
        if(i % 2 == 0) {
            A += a[i];
        }
        else {
            B += a[i];
        }
    }
    cout << A - B << endl;   
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str):
    if(S.count(S[0]) == 2 and S.count(S[1]) == 2 and S.count(S[2]) == 2 and S.count(S[3]) == 2):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main(){
	int n;
	cin>>n;
	vector<int> vo(n/2),ve(n/2);
	for (int i = 0; i < n; i++) {
		if (i%2==0) {
			cin>>ve[i/2];
		}else {
			cin>>vo[i/2];
		}
	}
	//出現頻度の測定
	unordered_map<int,int> ume,umo;
	for (int i = 0; i < n/2; i++) {
		ume[ve[i]]++;
		umo[vo[i]]++;
	}
	//最頻値の計算
	unordered_map<int,int>::iterator eitr1,eitr2;
	int em=0,es=0;
	for (auto itr = ume.begin(); itr !=ume.end(); itr++) {
		if ((*itr).second>=em) {
			eitr1=itr;
			em=(*itr).second;
		}
	}
	for (auto itr = ume.begin(); itr !=ume.end(); itr++) {
		if (itr==eitr1) {
			continue;
		}
		if ((*itr).second>=es) {
			eitr2=itr;
			es=(*itr).second;
		}
	}
	unordered_map<int,int>::iterator oitr1,oitr2;
	int om=0,os=0;
	for (auto itr = umo.begin(); itr !=umo.end(); itr++) {
		if ((*itr).second>=om) {
			oitr1=itr;
			om=(*itr).second;
		}
	}
	for (auto itr = umo.begin(); itr !=umo.end(); itr++) {
		if (itr==oitr1) {
			continue;
		}
		if ((*itr).second>=os) {
			oitr2=itr;
			os=(*itr).second;
		}
	}
	int ans;
	if ((*eitr1).first!=(*oitr1).first) {
		ans=n-em-om;
	}else {
		ans=min(n-em-os,n-om-es);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define MOD 1000000007LL
#define N 2123

using namespace std;

int n;

ll dp[N][N], ans;

struct child {
    ll value;
    int idx;
} children[N];

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;

    for(int i=1; i <= n; ++i) {
        cin >> children[i].value;
        children[i].idx = i;
    }

    sort(children + 1, children + 1 + n, [](child a, child b){ return a.value > b.value;});

    for(int i=1; i <= n; ++i) {
        for(int j=1; j <= i; ++j) {
            dp[j][i - j] = max(dp[j][i - j], dp[j - 1][i - j] + ((abs(children[i].idx - j) * children[i].value)));
            dp[i - j][j] = max(dp[i - j][j], dp[i - j][j - 1] + ((abs(n - j + 1 - children[i].idx) * children[i].value)));
        }
    }

    for(int i=1; i <= n; ++i) {
        ans = max(ans,dp[i][n - i]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 26696
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

static const int N = 100000;
const int NIL = -1;

int n, m;
vector<int> G[N];
int color[N];

void dfs(int r, int c){
	queue<int> q; q.push(r);
	color[r] = c;

	while (!q.empty()) {
		int u = q.front(); q.pop();

		for (int i = 0; i < G[u].size(); ++i)
		{
			int v = G[u][i];
			if (color[v] == NIL){
				color[v] = c;
				q.push(v);
			}
		}
	}
}

void assignColor(){
	int id = 1;
	for (int i = 0; i < n; ++i) color[i] = NIL;
	for (int i = 0; i < n; ++i) {
		if (color[i] == NIL) dfs(i, id++);
	}
}


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

	for (int i = 0; i < m; ++i)
	{
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	assignColor();
	int q; cin >> q;
	for (int i = 0; i < q; ++i)
	{
		int s, t; cin >> s >> t;
		cout << ((color[s] == color[t]) ? "yes" : "no") << endl;
	}

	return 0;
}

Measured memory_bytes: 8916
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include <ctype.h>
#include <cctype>
#include <cstdio>


int main(int argc, char const *argv[]) {
  std::string S;

  std::cin >> S;

  int flag = 1;

  std::string A, C;
  A = "A";
  C = "C";
  if(S[0] != A[0]){
    flag = 0;
  }

  int count_c = 0;
  int pos = 0;
  for (size_t i = 2; i < S.size() - 1; i++) {
    if(S[i] == C[0]){
      count_c++;
      pos = i;
    }
  }

  if(count_c != 1){
    flag = 0;
  }

  std::string T ;
  T.append(S);
  // std::cout << T << '\n';
  std::transform(T.begin(), T.end(), T.begin(), ::toupper);
  // std::cout << T << '\n';

  if (pos != 0) {
    for (size_t i = 0; i < S.size(); i++) {
      if (i != 0) {
        if(i != pos){

          if(T[i] == S[i]){
            flag = 0;
          }
        }
      }
    }
  }

  if (flag == 0) {
    std::cout << "WA" << '\n';
  }else{
    std::cout << "AC" << '\n';
  }
  // std::cout << flag << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool a=0,b=0,c=0;
    for(int i=0;i<s.size();i++)
        if(s[i]=='a')
            a=1;
        else if(s[i]=='b')
            b=1;
        else
            c=1;
    if(a&&b&&c)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
string st;
int ll,gss,pd;
int main()
{
cin>>st;
ll=st.size();
for(int i=0; i<ll; i++)
{
	if(st[i]=='S')pd++;
	if(st[i]=='T'&&pd>=1)
	{
	gss+=2,pd--;
	}
}
cout<<ll-gss<<endl;
return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b,temp=0;
    cin>>a>>b;
    if(a==b)
    temp=1;
    else if(a==2 || b==2)
    temp=0;
    else if(a==4 || a==6 || a==9 || a==11)
    {
        if(b==4 || b==6 || b==9 || b==11)
        temp=1;
    }
    else
    {
        if(b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12 )
        temp=1;
    }
    if(temp)
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}

Measured memory_bytes: 256
/*

tags: [树形DP] [DFS] 

题解：
任取一个非叶子节点，经过它的路径有两种：
1. 经过它的一个儿子。
2. 经过它的两个儿子。

对于点i, 设它的儿子的权值和为sum，儿子中权值最大的为mx，设有x条第2️种路径经过点i。

那么 a[i] - x = sum - 2 * x;

解得：x = sum - a[i];

若能找到合法解，那么 a[i] >= x >= 0， 

*/

#include <iostream>
#include <vector>
using namespace std;
const int N = 111111;
vector<int> a[N];
long long cnt[N];

long long dfs(int v, int p = -1) 
{
    if (a[v].size() == 1) 
    {
        return cnt[v];
    }
    long long mx = 0;
    long long sum = 0;
    for (int i=0;i<a[v].size();i++) 
    { 
        int x = a[v][i];
        if (x == p) continue; 
        long long mn = dfs(x, v); 
        mx = max(mx, mn); sum += mn; 
    }
    int num_sm = (sum - max(sum % 2, 2 * mx - sum)) / 2;
    if (sum - num_sm <= cnt[v] && sum >= cnt[v]) 
        return sum - 2 * (sum - cnt[v]); 
    else {
        puts("NO");
        exit(0);
    }
}
 
int main() 
{ 
    int n; cin >> n; 
    for (int i = 0; i < n; ++i) cin >> cnt[i];
    for (int i = 0; i < n - 1; ++i) 
    { 
        int u, v;  cin >> u >> v; --u, --v; 
        a[u].push_back(v); a[v].push_back(u); 
    }
    int root = 0;
    if (n == 2) 
    {
        if (cnt[0] == cnt[1]) puts("YES"); 
        else puts("NO"); return 0;
    }
    while (a[root].size() == 1) ++root;
    if (dfs(root)) puts("NO"); 
    else puts("YES");
}


Measured memory_bytes: 13440
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

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

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

ll modpow (ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

    ll N, K;
    cin >> N >> K;

    COMinit();

    // cout << COM(K-1, 0) << "\n";

    for (ll i = 1; i <= K; i++) {
        // if (i == 1) cout << N-K+1 << "\n";
         {
            cout << COM(K-1, i-1) * COM(N-K+1, i) % MOD << "\n";
        }
    }

}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll q, h, s, d;
ll n;

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
































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

void solve()
{
	ll k;
	cin>>k;
    ll s=7%k;
    for(ll i=1;i<1e8;i++)
    {
        if(s==0)
        {
            cout<<i;
            return;
        }
        else
            s=(s*10+7)%k;
            
    }
    cout<<"-1";
	return;
}
int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int A, B, C;
	bool a = false;
	cin >> A >> B;
	for(int C = 1; C <= 3; C++){
		if(A * B * C % 2 == 1){
			cout << "Yes" << endl;
			a = true;
			break;
		}
	}
	if(a == false){
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int arr[5],c=-1;
    for(int i=0;i<5;i++){
        cin>>arr[i];
    }
    for(int i=0;i<5;i++){
        if(arr[i]==0){
            c = i;
            break;
        }
    }
    cout<<c+1<<endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];
    for(int i=0; i<N; i++) if((X[i] + Y[i] + X[0] + Y[0]) % 2){
        cout << -1 << endl;
        return 0;
    }

    vector<int64_t> D;
    for(int d=31; d>=0; d--) D.push_back(1LL<<d);
    if((X[0] + Y[0]) % 2 == 0) D.push_back(1);

    cout << D.size() << endl;
    for(int64_t d : D) cout << d << " ";
    cout << endl;

    for(int i=0; i<N; i++){
        int64_t x = X[i] + Y[i];
        int64_t y = X[i] - Y[i];
        string ans;
        for(int64_t d : D){
            if(x >= 0 && y >= 0){
                x -= d;
                y -= d;
                ans.push_back('R');
            }else if(x >= 0){
                x -= d;
                y += d;
                ans.push_back('U');
            }else if(y >= 0){
                x += d;
                y -= d;
                ans.push_back('D');
            }else{
                x += d;
                y += d;
                ans.push_back('L');
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
using namespace std;
using ll=long long;


int main(){
	int n,h[100],ans=0;

	cin>>n;
	h[0]=0;
	for(int i=1;i<=n;i++)cin>>h[i];

	for(int i=1;i<=n;i++)
		if(h[i-1]<h[i])ans+=h[i]-h[i-1];
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n,k;
int c[201010];
vector<int> v;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        c[a]++;
    }
    for(int i=1;i<=n;i++){
        if(c[i]){
            v.push_back(c[i]);
        }
    }
    sort(v.begin(),v.end());
    int ans = 0;
    for(int i=0;i<int(v.size()) - k;i++){
        ans+=v[i];
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);

  for (int i = 0; i < n; ++i) {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  for (int px = 0; px <= 100; ++px) {
    for (int py = 0; py <= 100; ++py) {
      int ph = -1;
      for (int i = 0; i < n; ++i) {
        if (h.at(i) > 0) {
          int tmp = h.at(i) + abs(px - x.at(i)) + abs(py - y.at(i));
          if (ph == -1) {
            ph = tmp;
          } else {
            if (ph != tmp) {
              ph = -2;
              break;
            }
          }
        }
      }
      if (ph == -2) continue;

      for (int i = 0; i < n; ++i) {
        if (h.at(i) == 0) {
          int d = abs(py - y.at(i)) + abs(px - x.at(i));
          if (ph > d) {
            ph = -2;
            break;
          }
        }
      }
      if (ph == -2) continue;

      cout << px << " " << py << " " << ph << endl;
    }
  }
}

Measured memory_bytes: 256
import std;

void main() {
    int n, k; scan(n, k);
    auto s = new int[n];
    foreach (_; 0..k) {
        read;
        foreach (e; readints) s[e-1]++;
    }
    auto ans = s.count!"a == 0";
    writeln(ans);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 3868
#include<stdio.h>

int main( ){

  int s,t,u;
  scanf("%d%d%d",&s,&t,&u);

        if(s<=t&&t<=u){printf("%d %d %d\n",s,t,u);
  }else if(s<=u&&u<=t){printf("%d %d %d\n",s,u,t);
  }else if(t<=s&&s<=u){printf("%d %d %d\n",t,s,u);
  }else if(t<=u&&u<=s){printf("%d %d %d\n",t,u,s);
  }else if(u<=t&&t<=s){printf("%d %d %d\n",u,t,s);
  }else if(u<=s&&s<=t){printf("%d %d %d\n",u,s,t);
  }
 
  return 0;
}

Measured memory_bytes: 596
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main(){
    long n,s=0,m;
    cin>>n;
    m = n;
    bool t = false;
    while(n>=10){
        if((n%10>0)and(n>10)){
            t = true;
        }
        n=(n-n%10)/10;
    }
    if((t == false)and(n==1)){
        cout<<10;
        return 0;
    }
    n=m;
    while(n>0){
        s=s+n%10;
        n=(n-n%10)/10;
    }
    cout<<s;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

public class FindingMissingCards
{
    //?????????????????????????????????????????????????¶??????????????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i;
        int count;
        string[] buffer;
        List<int> resultList = new List<int> {
            1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
            27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52
        };
        /*---??£?¨???¨---*/

        /*????????°?????\??????????????????????????????????????????*/
        count = int.Parse(Console.ReadLine());

        string[,] inputCardList = new string[count, 2];
        for (i = 0; i < count; i++){
            buffer = Console.ReadLine().Split(' ');
            inputCardList[i,0] = buffer[0];
            inputCardList[i,1] = buffer[1];
        }

        /*?????¨???????????????????????¢???*/
        for(i = 0; i < count; i++){
            //S???0,H???13,C???26,D???39??¨??????
            switch (inputCardList[i,0]){
                case "S":
                    resultList.Remove(int.Parse(inputCardList[i,1]));
                    break;
                case "H":
                    resultList.Remove(13 + int.Parse(inputCardList[i, 1]));
                    break;
                case "C":
                    resultList.Remove(26 + int.Parse(inputCardList[i, 1]));
                    break;
                case "D":
                    resultList.Remove(39 + int.Parse(inputCardList[i, 1]));
                    break;
            }
        }

        /*????????????????????????????????????????????????????????????????????§????????????????????????*/
        for (i = 0; i < resultList.Count; i++){
            switch((resultList[i] - 1) / 13) {
                case 0:
                    Console.WriteLine("S {0}", resultList[i] );
                    break;
                case 1:
                    Console.WriteLine("H {0}", resultList[i] - 13);
                    break;
                case 2:
                    Console.WriteLine("C {0}", resultList[i] % 26);
                    break;
                case 3:
                    Console.WriteLine("D {0}", resultList[i] % 39);
                    break;
            }

        }
    }
}

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

int n, m;
vector<vector<int>> g;
vector<bool> visited;

void dfs(int i) {
    if(visited[i]) return;
    visited[i] = true;
    for(auto j : g[i]){
        dfs(j);
    }
}

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

    int cnt = 0;
    for(int i=0;i<m;i++){
        g.clear();
        g.resize(n);

        // 枝i以外からなるグラフ(隣接リストg)をつくる
        for(int j=0;j<m;j++){
            if(i == j) continue;
            g[a[j]].push_back(b[j]);
            g[b[j]].push_back(a[j]);
        }

        // 連結性判定
        visited.clear();
        visited.resize(n, false);
        dfs(0);  // 探索
        for(int i=0;i<n;i++){
            if(visited[i] == false){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
# 入力
a = int(input())

# 定義
answer = 0

# 処理
for i in range(1, a + 1):
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        answer += i

# 出力
print(answer)


Measured memory_bytes: 9104
#include <iostream>
#include <map>
#include <string>

using namespace std;

const string abc = "abcdefghijklmnopqrstuvwxyz ";
map<char, int> mp;
string S;

bool search(int sn)
{
    int i;
    bool ans;

    i = abc.find(S[sn]);
    while (i < 26)
    {
        if (mp[abc[i + 1]] == 1)
        {
            return false;
        }
        i++;
    }

    return true;
}

char a(int sn)
{
    int i;
    bool ans;

    i = abc.find(S[sn]);
    while (i < 26)
    {
        if (mp[abc[i + 1]] == 1)
        {
            return abc[i + 1];
        }
        i++;
    }
}

int main()
{
    int i;
    for (i = 0; i <= 26; i++)
    {
        mp[abc[i]] = 0;
    }

    cin >> S;

    if (S == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
        return 0;
    }
    else if (S.length() == 26)
    {
        i = 25;
        while (search(i))
        {
            mp[S[i]] = 1;

            i--;
        }

        S[i] = a(i);

        while (S.length() > i + 1)
            S.pop_back();
    }
    else
    {
        for (i = 0; i < S.length(); i++)
        {
            mp[S[i]] = 1;
        }

        i = 0;
        while (mp[abc[i]] == 1)
            i++;

        S.push_back(abc[i]);
    }

    cout << S << endl;

    return 0;
}

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

int main(){
	int n,k,a[100000];
	cin >> n >> k;
	for (int i = 0; i < k; ++i){
		cin >> a[i];
	}

	int b,c;
	for (int i = n; i < 1000000 ; ++i){
		b=i;
		bool flag=true;
		while(b!=0){
			c=b%10;
			for (int i = 0; i < k; ++i){
				if(c==a[i])
					flag=false;
			}
			b/=10;
		}
		if(flag){
			cout<<i<<endl;
			return 0;
		}
	}


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001],dp[100001];
int solve(int n,int k)
{
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
    {
        int c;
        int d=INT_MAX;
        for(int j=max(0,i-k);j<i;j++)
        {
            c=dp[j]+abs(a[i]-a[j]);
            d=min(c,d);
        }
        dp[i]=d;
    }
    return dp[n-1];
}
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    cout << solve(n,k) << endl;
}

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

using namespace std;
typedef pair<double, string> pds;

const double eps = 1e-10;

bool comp(const pds &a, const pds &b) {
  if (abs(a.first - b.first) > eps) return a.first - b.first > eps;
  return a.second < b.second;
}

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<pds> L(n);
    for (int i = 0; i < n; i++) {
      int p, a, b, c, d, e, f, s, m;
      cin >> L[i].second >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      L[i].first = (double)(f * s * m - p) / (a + b + c + (d + e) * m);
    }
    sort(L.begin(), L.end(), comp);

    for (int i = 0; i < n; i++) {
      cout << L[i].second << endl;
    }
    cout << "#\n";
  }

  return 0;
}


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

class Program
{
    static int N;
    static int M;
    static int[] A;
    static int[] B;

    static void Main()
    {
        int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = inp[0];
        M = inp[1];
        A = new int[M];
        B = new int[M];
        for (int i = 0; i < M; i++)
        {
            inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            A[i] = inp[0] - 1;
            B[i] = inp[1] - 1;
        }

        long[] ans = new long[M];
        ans[M - 1] = (long)N * (N - 1) / 2;

        UF uf = new UF(N);
        for (int i = M - 1; i > 0; i--)
        {
            long a = uf.siz[uf.Root(A[i])];
            long b = uf.siz[uf.Root(B[i])];
            if (uf.Unite(A[i], B[i]))
            {
                ans[i - 1] = ans[i] - (a * b);
                continue;
            }
            ans[i - 1] = ans[i];
        }

        foreach (var i in ans)
            Console.WriteLine(i);
    }
}

namespace UnionFind
{
    class UF
    {
        private int[] 親; //親[i] : iの親の番号
        public int[] siz;
        public int size;

        public UF(int N) //コンストラクタ、すべてが根として初期化
        {
            親 = new int[N];
            for (int i = 0; i < N; i++)
                親[i] = i;
            size = N;
            siz = new int[N];
            for (int i = 0; i < N; i++)
                siz[i] = 1;
        }

        public int Root(int x) //xの属する木の根を返す
        {
            if (親[x] == x) return x;
            return 親[x] = Root(親[x]);
        }

        public bool Unite(int x, int y) //xとyの木を統合
        {
            int rx = Root(x);
            int ry = Root(y);
            if (rx == ry) return false;
            親[rx] = ry;
            size--;
            int t = siz[rx];
            siz[rx] += siz[ry];
            siz[ry] += t;
            return true;
        }

        public bool Same(int x, int y) //xとyが同じ木に属するかどうかを返す
        {
            return Root(x) == Root(y);
        }
    }
}

Measured memory_bytes: 21056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
const ll MOD=998244353;
const double pi=3.1415926;
ll n,k;
void solve()
{
    double p=0,unit=1.0/n;
    for(ll i=1;i<=n;i++)
    {
        if(i>=k)
        {
            p+=unit;
        }
        else
        {
            double now=unit;
            ll nowscore=i;
            while(nowscore<k)
            {
                nowscore*=2;
                now*=0.5;
            }
            p+=now;
        }
    }
    printf("%.12f\n",p);
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);

    while(~scanf("%lld %lld",&n,&k))
    {

        solve();
    }
}
/*
100
3
1 1
1
4
1 1 1
1 1
1
*/


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      
      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 2) {
        for(; arr[1]+2 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 2) {
        for(; arr[0]+2 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      bfs(t);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        System.out.println(cur.step);
        return;
      }

      if(cur.e[0] < cur.e[1] && cur.e[0] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
        que.peekLast().step = cur.step + 1;
      }

      if(cur.e[0] < cur.e[2] && cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[0] && cur.e[2] < cur.e[0]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      }
      
    }
  }

  class Tuple3 {
    int[] e;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      step = 0;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	int ans=0;
	for(int i=0;i<v.size();i++)
		if(v[i]>m[v[i]]) ans+=m[v[i]];
		else if(v[i]<m[v[i]]) ans+=m[v[i]]-v[i];
	
	cout<<ans;
	return 0; 
}

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

int main() {
	int H, W;
	cin >> H >> W;
	char S[H][W];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> S[i][j];
		}
	}

	int shift[3] = {-1, 0, 1};
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				int cnt = 0;
				for (int k = 0; k < 3; k++) {
					for (int l = 0; l < 3; l++) {
						if (shift[k] == 0 && shift[l] == 0) continue;
						
						int x = i + shift[k], y = j + shift[l];
						if (x < 0 || y < 0) continue;
						else if (x >= H || y >= W) continue;

						if (S[x][y] == '#') cnt++;
					}
				}
				S[i][j] = cnt + '0';
			}
			else continue;
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << S[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char s[10];
	int i;
	scanf("%s", s);
	if (s[0] == 'R') {
		if (s[1] == 'R') {
			if (s[2] == 'R') {
				i = 3;
			}
			else {
				i = 2;
			}
		}
		else {
			i = 1;
		}
	}
	else {
		if (s[1] == 'R') {
			if (s[2] == 'R') {
				i = 2;
			}
			else {
				i = 1;
			}
		}
		else {
			if (s[2] == 'R') {
				i = 1;
			}
			else {
				i = 0;
			}
		}
		}
	printf("%d",i);
	return 0;
}


Measured memory_bytes: 1736
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

const INF = 1 << 60

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		G[i] = make([]int, N)
		for j := 0; j < N; j++ {
			G[i][j] = sc.nextInt()
		}
	}
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = INF
	}
	seen := make([]bool, N)
	d[0] = 0
	ans := 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			if !seen[i] && d[i] < minCost {
				minCost = d[i]
				cur = i
			}
		}
		if minCost == INF {
			break
		}
		seen[cur] = true
		ans += d[cur]
		for i := 0; i < N; i++ {
			cost := G[cur][i]
			if cost != -1 && cost < d[i] {
				d[i] = cost
			}
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}



Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; ++i) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  for(int i=0; i<N; ++i){
    for(int j=i+1; j<N; ++j){
      for(int k=j+1; k<N; ++k){
        if(L[k]>=L[i]+L[j]) break;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long

int main(){
  string s;
  cin>>s;
  int l=0,r=s.size()-1;
  while(s[l]!='A') l++;
  while(s[r]!='Z') r--;
  cout<<r-l+1<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll costa = 0;
  ll costb = 0;

  rep(i, n) {
    if (a[i] < b[i]) costa += (b[i] - a[i]) / 2;  // 余裕が減る回数
    if (a[i] > b[i]) costb += a[i] - b[i];        // 余裕が増える回数
  }
  if (costb <= costa) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3764
c = []
3.times{c << gets.split.map(&:to_i)}

if c[0][0] - c[1][0] == c[0][1] - c[1][1] &&
   c[1][1] - c[2][1] == c[1][2] - c[2][2] &&
   c[2][2] - c[0][2] == c[2][0] - c[0][0]
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788