akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif 
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// �t��
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}
 
// �K��
std::vector<int>fact;
void mod_fact(int n, int m){
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%m;
	}
}
 
// nCk mod p
int mod_nCr(int n, int k, int m){
	if(n<k)return 0;
	return fact[n]*mod_inverse(fact[k]*fact[n-k]%m,m)%m;
}

int n,m;

int ans;
signed main(){
	
    cin>>n>>m;
    mod_fact(n,MOD);
    int n2=n,m2=m;
    int cnt=0,cnt1=0,cnt2=0;
    while(true){
        if(m2-2<0 || n2-1<0 || n2==m2*2)break;
        n2-=1;m2-=2;
        cnt++;
        cnt1++;
    }
    while(true){
        if(n2-2<0 || m2-1<0 || m2==n2*2)break;
        n2-=2;m2-=1;
        cnt++;
        cnt2++;
    }
    //cout<<n2<<" "<<m2;
    if(n2!=0 || m2!=0){
        cout<<0<<endl;
    }
    else{
        ans=mod_nCr(cnt,cnt1,MOD);
        cout<<ans<<endl;
    }
	
}

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

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = 102, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int n, totW;
pair<int, int> a[N];
ll dp[(int) 1e5 + 2];

class EKnapsack2 {
public:
    void init() {
        clr(dp,0);
    }


    void solve(istream &cin, ostream &cout) {
        init();
        int n, totW;
        cin >> n >> totW;
        for(int i  =0;i<n;i++){
            int w , v;
            cin >> w >> v;
            for(int j = totW; j >= w;j--)
                dp[j] = max(dp[j],dp[j-w]+v);
        }
        cout << *max_element(dp,dp+totW+1) << el;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	EKnapsack2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
n,m,x = map(int,input().split())
a = list(map(int,input().split()))

cost = 0
for i in range(0,x):
    if i in a:
        cost += 1
cost2 = 0
for i in range(x+1,n+1):
    if i in a:
        cost2 +=1
print(min(cost,cost2))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

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

int main(void) {
	int n, ans=10000000;
	cin >> n;
	rep(i, n + 1) {
		int tmp = 0;
		int a = i, b = n - i;
		while (a) {
			tmp += (a % 6);
			a /= 6;
		}
		while (b) {
			tmp += (b % 9);
			b /= 9;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}



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

int N, M, a[100000], b[100000];
pair<int, int> itv[100000];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < M; i++) {
    itv[i].first = b[i];
    itv[i].second = a[i];
  }
  sort(itv, itv + M);
  int ans = 0, isl = 0;
  for (int i = 0; i < M; i++) {
    if (isl <= itv[i].second) {
      ans++;
      isl = itv[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
H = [int(i) for i in input().split()]

flag = True
ans = 0
times = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        times += 1
    else:
        flag = False
        ans = max(ans, times)
        times = 0

ans = max(ans, times)

print(ans)


Measured memory_bytes: 14252
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
char s[10];
scanf("%s", s);
if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
else printf("No\n");
}

Measured memory_bytes: 128
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008
#include <iostream>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; 
	while (cin >> n) {
		int ans = 0;
		for (int a = 0; a <= 9;a++) {
			for (int b = 0; b <= 9; b++) {
				for (int c = 0; c <= 9; c++) {
					for (int d = 0; d <= 9; d++) {
						if (a + b + c + d == n)ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

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

int f(int n) {
	if (n % 2 == 0)return n / 2;
	else return 3 * n + 1;
}

int main() {
	int s;
	cin >> s;
	set<int>st;
	int prev, before;
	for (int i = 1; i <= 1000000; i++) {
		if (i == 1) {
			st.insert(s);
			prev = s;
		} else {
			before = st.size();
			st.insert(f(prev));
			if (before == st.size()) {
				cout << i << endl;
				return 0;
			}
			prev = f(prev);
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>
 
using namespace std;
 
const int MOD = 1000000007;
 
inline int sub(int a, int b)
{ 
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
 
int main()
{ 
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
 
  int N, K;
 
  std::cin >> N >> K;
 
  vector<vector<int>> dp = vector<vector<int>>(N+1, vector<int>(K+1, 0));
  vector<vector<int>> prefix = dp;
  prefix[0] = vector<int>(K+1, 1);
 
  for (int i = 1; i <= N; ++i)
  { 
    int kid;
    cin >> kid;
 
    for (int sum = 0; sum <= K; ++sum)
    { 
      int R = min(kid, sum);
 
      dp[i][sum] = sub(prefix[i - 1][sum], (sum - R > 0 ? prefix[i - 1][sum - R - 1] : 0));
      prefix[i][sum] = (dp[i][sum] + (sum > 0 ? prefix[i][sum - 1] : 0)) % MOD;
    }
  }
 
  std::cout << dp[N][K];
 
  return 0;
}

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

const int MOD=1e9+7;

long long power(long long x, long long y){
	long long ret=1;
	while(y){
		if(y&1) ret=ret*x%MOD;
		y>>=1;
		x=x*x%MOD;
	}
	return ret;
}

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

	int x,y;
	cin >> x >> y;
	int n = x+y;
	if(n%3){
		cout << 0 << endl;
		return 0;
	}
	if(x>y*2 || y>x*2){
		cout << 0 << endl;
		return 0;
	}
	n/=3;
	int a = y-n;
	int b = x-n;
	long long ans=1,div=1;
	for(int i=2;i<=a+b;i++)
		ans=ans*i%MOD;
	for(int i=2;i<=a;i++)
		div=div*i%MOD;
	ans=ans*power(div,MOD-2)%MOD;
	div=1;
	for(int i=2;i<=b;i++)
		div=div*i%MOD;
	ans=ans*power(div,MOD-2)%MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    ios;
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            for(ll k=1;k<=n;k++)
            {
                sum+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3700
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define ll long long

using namespace std;

int main() {
  int a,b,c; cin>>a>>b>>c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

const int N=305;
const int M=305;

int main(void)
{
	int n ,m;
	
	while(scanf(" %d %d ", &n ,&m))
	{    
	     if(n == 0 && m == 0 )
	     {
	     	break;
		 }
		for( int j = 0 ; j < m ; j++ )
		{
			printf("#");		
		}
		printf("\n");
	    for(int i = 0 ; i<n-2 ; i++)
	    { 
	        printf("#");
	    	for(int j = 0 ; j < m-2 ; j++ )
	    	{
	    		printf(".");
	    		
			}
			printf("#");
			printf("\n");
		}
		for(int j = 0 ; j < m ; j++ )
		{
			printf("#");		
		}
		printf("\n");
		printf("\n");
     } 
     return 0;	
 }


Measured memory_bytes: 2568
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long  i = 0; i < (long long)(n); i++)






int main() {
	
	int a, b;
	cin >> a >> b;
	string s = "Yes";
	if (a*500<b) {
		s = "No";
	}
	cout << s<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> food(m);
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int a;
            cin >> a;
            food[a-1]++;
        }
    }
    int ans=0;
    for(int i=0;i<m;i++){
        if(food[i]==n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


using namespace std;


int main() {
	int N;
	cin >> N;

	vector<int> W(N);
	vector<int> Left(N);
	vector<int> Right(N);
	vector<int> Diff(N);
	
	for (int i = 0; i < N; i++)
		cin >> W[i];

	Left[0] = W[0];
	Right[N - 1] = W[N-1];

	for (int i = 1; i < N; i++)
		Left[i] = Left[i-1] + W[i];

	for (int i = N-2; i >= 0; i--)
		Right[i] = Right[i+1] + W[i];

	for (int i = 0; i < N-1; i++) {
		Diff[i] = abs(Left[i] - Right[i+1]);
	}

	int j;
	for (j= 0; j < N - 1; j++) {
		if (Diff[j] < Diff[j + 1])
			break;
	}
	cout << Diff[j] << endl;
	return 0;
}


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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int X, Y, Z ,K;
  cin >> X >> Y >> Z >> K;

  VI A(X), B(Y), C(Z);
  REP(i, X) cin >> A.at(i);
  REP(i, Y) cin >> B.at(i);
  REP(i, Z) cin >> C.at(i);

  SORT(A);
  SORT(B);
  SORT(C);
  REV(A);
  REV(B);
  REV(C);

  VI table;

  REP(i, min(K, X)){
    REP(j, min(K, Y)){
      table.pb(A.at(i)+B.at(j));
    }
  }

  SORT(table);
  REV(table);

  VI ans;
  int size=table.size();

  REP(i, min(K, size)){
    REP(j, min(K, Z)){
      ans.pb(table.at(i)+C.at(j));
    }
  }

  SORT(ans);
  REV(ans);

  REP(i, K) cout << ans.at(i) << endl;
  return 0;
}


Measured memory_bytes: 43368
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}
// 本体
constexpr ll MAXN  = 2e6 + 5;
ll fact[MAXN + 1]  = {};
ll ifact[MAXN + 1] = {};
void init_fact(ll n, ll mod) {
	fact[0] = ifact[0] = 1;
	for (int i = 0; i < n; i++) {
		fact[i + 1]	 = ((i + 1) * fact[i]) % mod;
		ifact[i + 1] = powm(fact[i + 1], mod - 2, mod);
	}
}

ll nci_m(ll n, ll i, ll mod) {
	return fact[n] * ifact[i] % mod * ifact[n - i] % mod;
}

ll pow25[2145141];
ll pow26[2145141];

int main() {
	IOS();
	ll k;
	string s;
	cin >> k >> s;
	ll n = s.size();
	pow25[0] = pow26[0] = 1;
	for (int i = 0; i < k;i++) {
		pow25[i + 1] = pow25[i] * 25 % MOD;
		pow26[i + 1] = pow26[i] * 26 % MOD;
	}
	init_fact(k + n, MOD);
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ll tmp = (nci_m(n + i - 1, n - 1, MOD) * pow25[i]) % MOD * pow26[k - i] % MOD;
		ans += tmp;
		ans %= MOD;
	}
	dump(ans);
}

Measured memory_bytes: 51260
#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;

int n;
ll a[200000];
ll s[200000];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    s[0] = a[0];
    for (int i = 1; i < n; i++) s[i] = a[i]+s[i-1];
    ll ans = MOD*MOD;
    for (int i = 2; i < n-1; i++) {
        ll mi = MOD*MOD, ma = -MOD*MOD;
        ll sum = s[i-1];
        int ind = lower_bound(s, s+i, (sum+1)/2) - s;
        if (ind == 0) {
            ma = max(ma, s[ind]);
            mi = min(mi, sum-s[ind]);
        } else if (ind == i) {
            ma = max(ma, sum-s[ind-1]);
            mi = min(mi, s[ind-1]);
        } else {
            if (s[ind] > sum-s[ind-1]) {
                ma = max(ma, sum-s[ind-1]);
                mi = min(mi, s[ind-1]);
            } else {
                ma = max(ma, s[ind]);
                mi = min(mi, sum-s[ind]);
            }
        }
        
        sum = s[n-1]-s[i-1];
        ind = lower_bound(s+i, s+n, (sum+1)/2+s[i-1]) - s;
        if (ind == i) {
            ma = max(ma, s[ind]-s[i-1]);
            mi = min(mi, sum-(s[ind]-s[i-1]));
        } else if (ind == n) {
            ma = max(ma, sum-(s[ind-1]-s[i-1]));
            mi = min(mi, s[ind-1]-s[i-1]);
        } else {
            if (s[ind]-s[i-1] > sum-(s[ind-1]-s[i-1])) {
                ma = max(ma, sum-(s[ind-1]-s[i-1]));
                mi = min(mi, s[ind-1]-s[i-1]);
            } else {
                ma = max(ma, s[ind]-s[i-1]);
                mi = min(mi, sum-(s[ind]-s[i-1]));
            }
        }
        
        ans = min(ans, ma-mi);
    }
    cout << ans << endl;
}
































Measured memory_bytes: 3328
n, m = gets.chomp.split(" ").map(&:to_i)

a = Array.new
for i in 1..n
    a << gets.chomp.split(" ").map(&:to_i)
end

b = Array.new
for i in 1..m
    b << gets.to_i
end

for i in 0..n - 1
    value = 0
    for j in 0..m - 1
        value += (a[i][j] * b[j])
    end
    puts value
end


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

#define ll long long
#define ld long double

#define all(x) x.begin(),x.end()

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin>>s>>s;
    
    cout<<"A"<<s[0]<<"C\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  string str[n];

  for(int i = 0; i < n; i++) {
    cin >> str[i];
    if(i > 0) {
      if(str[i-1][str[i-1].length()-1] == str[i][0]){
        for(int j = 0; j < i; j++) {
          if(str[j] == str[i]){
		  cout << "No";
	  	  return 0;
	  }
        }
      } else {
	      cout << "No";
	      return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
result = {
    "AC": 0,
    "WA": 0,
    "TLE": 0,
    "RE": 0
}
for i in range(N):
    x = input()
    result[x] += 1

for key, val in result.items():
    print(f"{key} x {result[key]}")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

ll n, k;
ll ans = 0;
//12012
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> k;
    for(ll b = k + 1; b <= n; b++){
    	ans += (n / b) * (b - k);
    	int t = n % b;
    	if(t == 0) continue;
    	ans += max(t - k + 1, 0LL);
    	if(k == 0) ans--;
    	//cout << ans << endl;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
map <pair<int,int>,int> cnt;
pair <int,int> p[202020];
int rt[202020];
int getr(int x)
{
	if(x==rt[x])
		return x;
	rt[x]=getr(rt[x]);
	return rt[x];
}
int main()
{
	int n,m1,m2,x,y;
	scanf("%d%d%d",&n,&m1,&m2);
	for(int i=1;i<=n;i++)
		rt[i]=i;
	for(int i=1;i<=m1;i++)
	{
		scanf("%d%d",&x,&y);
		rt[getr(x)]=getr(y);
	}
	for(int i=1;i<=n;i++)
		p[i].first=getr(i);
	for(int i=1;i<=n;i++)
		rt[i]=i;
	for(int i=1;i<=m2;i++)
	{
		scanf("%d%d",&x,&y);
		rt[getr(x)]=getr(y);
	}
	for(int i=1;i<=n;i++)
		p[i].second=getr(i);
	cnt.clear();
	for(int i=1;i<=n;i++)
		cnt[p[i]]++;
	for(int i=1;i<=n;i++)
		printf("%d ",cnt[p[i]]);
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define mod(d) d%1000000007
#define loop(i,s,e) for(ll i=s;i<e;i++)
#define vll vector<ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int N=2e6+3;
ll dp[N];


ll solve(ll n,ll x, ll k,ll* A){
	if(x>=n)return INT_MAX;
	if(x==n-1)return 0;
	if(dp[x]!=-1)return dp[x];
	ll cost=INT_MAX;

	for(int i=1;i<k+1 && i<n;i++){
		ll ans=0;
		ans+=abs(A[x+i]-A[x]);
		ans+=solve(n,x+i,k,A);
        cost=min(ans,cost);
	}

	return dp[x]=cost;
}

int main(){


	ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n,k;
	cin>>n>>k;

	memset(dp,-1,sizeof(dp));

	ll* A = new ll[n];
	loop(i,0,n)cin>>A[i];
	cout<<solve(n,0,k,A);
}

Measured memory_bytes: 24448
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const llint mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
int main(void){
	int i,j;
	int imos[100001];
	imos[0]=0;imos[1]=0;
	for(i=2;i<=100000;i++){imos[i]=1;}
	for(i=2;i<=100000;i++){
		if(imos[i]==0){continue;}
		for(j=i+i;j<=100000;j+=i){imos[j]=0;}
	}
	for(i=100000;i>=2;i--){imos[i]*=imos[(i+1)/2];}
	for(i=1;i<=100000;i++){imos[i]+=imos[i-1];}
	int q;cin>>q;
	while(q--){
		int l,r;cin>>l>>r;
		cout<<imos[r]-imos[l-1]<<endl;
	}
	
	RE;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define pii pair<int, int>
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, x, n) for(int i = x; i <= n; ++i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
 
const int inf = 1e9 + 1;
const ll modw = 1e9 + 7;
 
using namespace std;

int dp[N][3];
int a[N], b[N], c[N];

int main()
{
	barnarnar
	int n;
	cin >> n;
	forn(i, n)
	{
	    cin >> a[i] >> b[i] >> c[i];
	}
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    forr(i, 1, n - 1)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    return 0;
}









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

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  
  float As = A/0.08;
  float Ab = (A+1)/0.08;
  float Bs = B/0.1;
  float Bb = (B+1)/0.1;
  
  unordered_set<int> candidate;
  for (int i = (int)ceil(As); i < (int)ceil(Ab); i++){
    candidate.emplace(i);
  }
  
  for (int i = (int)ceil(Bs); i < (int)ceil(Bb); i++){
    if (candidate.find(i) != candidate.end()){
      cout << i;
      return 0;
    }
  }
  
  cout << -1;
  return 0;
}

Measured memory_bytes: 256
k,n=map(int,input().split())
l=list(map(int,input().split()))
d=0;j=l[0]
p=l[1:];p.append(j)
for s,f in zip(l,p):
    d=max(d,(f-s) if f>=s else k+f-s)
print(k-d)

Measured memory_bytes: 26444
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int m1 = sc.nextInt();
        int d1 = sc.nextInt();
        int m2 = sc.nextInt();
        int d2 = sc.nextInt();

        System.out.println(m1 != m2 ? "1" : "0");

    }
}


Measured memory_bytes: 23016
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> ACset = new HashSet<>();
		//Set<Integer> WAset = new HashSet<>();
		Map<Integer, Integer> waMap = new HashMap<>();
		int ac = 0;
		int wa = 0;
		int waCount = 0;
		
		for(int i = 0; i < M; i++) {
			int num = sc.nextInt();
			String value = sc.next();
			if(value.equals("AC")) {
				if(!ACset.contains(num)) {
					ac++;
					ACset.add(num);
					if(waMap.containsKey(num)) {
						wa += waMap.get(num);
					}
				}
			}else {
				if(waMap.containsKey(num)) {
					waCount = waMap.get(num);
					waMap.put(num, ++waCount);
				}else {
					waCount = 1;
					waMap.put(num, waCount);
				}
			}
		}

		System.out.println(ac + " " + wa);			
		sc.close();
	}
	
}

Measured memory_bytes: 66160
#include<bits/stdc++.h>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define N 100005
#define ll long long
using namespace std;
int a,b,c;
int main(){
    //freopen("A.inp","r",stdin);
  //  freopen("A.out","w",stdout);
    cin>>a>>b>>c;
    if (a+b==c) {cout<<b+c;exit(0);}
    if (a+b<c) {cout<<a+2*b+1; exit(0);}
    cout<<b+c;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;

int main(void) {
	int n, l[1000], r[1000], sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
		sum += r[i] - l[i] + 1;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
/*input
5

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 101

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(ll a, ll b) {a += b; if (a < 0) a += mod; return a;}
inline int sub(ll a, ll b) {a -= b; if (a < 0) a += mod; return a;}
inline int mul(ll a, ll b) {return (a * 1ll * b) % mod;}
inline int pwr(ll x, ll y) {
    int ans = 1 % mod;
    while (y) {
        if (y & 1) ans = mul(ans, x);
        x = mul(x, x);
        y >>= 1;
    }
    return ans;
}
inline int inv(int a) {return pwr(a, mod - 2);}


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

    int n;
    cin >> n;
    int sum = (n * (n - 1)) / 2;
    set <PII> s;
    int x = 1;
    int even = (n % 2 == 0);
    for (int i = n; i >= 1; i--) {
        if (i == n) {
            for (int j = 1 + even ; j <= n - 1; j++) {
                int u = min(i, j);
                int v = max(i, j);
                s.insert({u, v});
            }
            x += even;
        }
        else {
            for (int j = 1; j <= n; j++) {
                if (j == x or j == i) continue;
                int u = min(i, j);
                int v = max(i, j);
                s.insert({u, v});
            }
            x++;
        }
    }
    cout << s.size() << endl;
    for (auto it : s) {
        cout << it.first << " " << it.second << endl;
    }


    return 0;
}


Measured memory_bytes: 512
def resolve():
    N=int(input())
    c=1
    cc=0
    A=[int(i) for i in input().split()]
    for i in A:
        if c==i:
            c+=1
        else:
            cc+=1
    print(cc if cc!=N else -1)



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 77516
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.begin(), v.end(),std::greater<ll>() )

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;
    size_t k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < y; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < z; ++i) {
        cin >> c[i];
    }
    SORT(a);
    SORT(b);
    SORT(c);
    vector<ll> ab, E, ans;
    for (int i = 0; i < x; ++i) {
        for (int j = 0; j < y; ++j) {
            ab.push_back(a[i] + b[j]);
        }
    }
    RSORT(ab);
    int count = 0;
    for (size_t i = 0; i < min(k,(size_t)x*y); ++i) {
        E.push_back(ab[i]);
    }
    for (size_t i = 0; i < min(k, (size_t)x*y); ++i) {
        for (int j = 0; j < z; ++j) {
            ans.push_back(E[i] + c[j]);
        }
    }
    RSORT(ans);
    for (size_t i = 0; i <k; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N+1, 0);
    vector<ll> B(M+1, 0);
    for(int i=1;i<=N;i++){
        cin >> A[i];
        A[i] += A[i-1];
    }
    for(int i=1;i<=M;i++){
        cin >> B[i];
        B[i] += B[i-1];
    }
    ll res = 0;
    for(ll i=0;i<=N;i++){
        if(A[i] > K) break;
        auto itr = upper_bound(B.begin(), B.end(), K - A[i]);
        auto n = i + distance(B.begin(), itr) - 1;
        res = max(res, n);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define par pair<pair<int,int>, int>
#define f first
#define s second

int n,k,q,a[N],x;
int main() {
	scanf("%d%d%d",&n,&k,&q);
    for(int i=0; i<q; i++) {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=n;i++) printf("%s\n",(k-q+a[i]<=0?"No":"Yes"));
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int cnt = 0;
        int sum = 0;
        for(int a=0;a<=A;a++){
            for(int b=0;b<=B;b++){
                for(int c=0;c<=C;c++){
                    sum = 500*a+100*b+50*c;
                    if(sum==X){cnt++;}
                    sum = 0;
                }
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,t;
    cin>>a>>b>>t;
    cout<<((t/a)*b)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int slen,tlen;
  string s,t;
  cin>>s;
  slen=s.size();
  char a=s[0];
  t+=a;
  for(int i=1;i<slen;i++)
    if(s[i]!=a)a=s[i],t+=a;
  tlen=t.size();
  if(tlen%2==0){
    if(t[0]=='x')t=t.substr(1,tlen-1);
    if(t[tlen-1]=='x')t=t.substr(0,tlen-1);
    tlen--;
  }
  char c=t[tlen/2];
  int f=0;
  for(int i=1;i<=50;i+=4)
    if(tlen==i)f=1;
  if(f)cout<<c<<endl;
  else{
    if(c=='o')cout<<'x'<<endl;
    else cout<<'o'<<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
//
//  abc114_a.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/12/02.
//

#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin>>x;
    
    if(x==7||x==5||x==3) cout<<"YES"<<endl;
    else    cout<<"NO"<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int Q;
  string s, t, u;
  cin >> s >> Q;

  int a, b;
  string c;
  bool flag = true;
  REP(_, Q){
    cin >> a;
    if(a == 1){
      flag = !flag;
    }else{
      cin >> b >> c;
      if(flag){
        if(b == 1) t += c;
        else u += c;
      }else{
        if(b == 2) t += c;
        else u += c;
      }
    }
  }

  reverse(ALL(t));
  s = t+s+u;
  if(flag == false) reverse(ALL(s));
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int input1, input2;
  cin >> input1 >> input2;

  if((input1 /2)*2 == input1 || (input2 /2)*2 == input2) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int N = 100;
const int INF = (1 << 21);

int n, M[N][N];
int d[N]; //距離で訪問状態を管理する

void bfs(int s) {
    queue<int> q;
    q.push(s);

    for(int i = 0; i < n; i++)
        d[i] = INF;

    d[s] = 0;
    
    int u;
    while (!q.empty()) {
        u = q.front();
        q.pop();

        for(int v = 0; v < n; v++) {
            if (M[u][v] == 0) continue;
            if (d[v] != INF) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for(int i = 0; i < n; i++) {
        cout << i+1 << " "  << ( (d[i] == INF) ? (-1) :d[i]) << endl;
    }
}

int main() {

    int u, k, v;

    cin >> n;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
    
int main(){ 
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < (int) s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
if n % 2 ==1:
    n = n+1
a = n // 2
b = []
for i in range(1, a):
    x = 2*i+1
    c = []
    for j in range(1, x+1):
        if x % j == 0:
            c.append(j)
    if len(c) == 8:
        b.append(x)
print(len(b))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


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

  int h,w;
  int a[510][510];

  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
    }
  }

  int i=0,j=0;
  vector<PP> ans;
 
  while(true){
    int ni=i,nj=j;
    if(i%2==0){
      if(nj==w-1) ni++;
      else nj++;
    }else{
      if(nj==0) ni++;
      else nj--;
    }
    //cout<<i<<' '<<j<<' '<<a[i][j]<<endl;
    if(!(0<=ni&&ni<h&&0<=nj&&nj<w)){
 
      break;
    }

    if(a[i][j]%2){
      ans.PB(PP(P(i+1,j+1),P(ni+1,nj+1)));
      a[i][j]--;
      a[ni][nj]++;
    }
    i=ni;
    j=nj;
  }


  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    P x=ans[i].F,y=ans[i].S;
    cout<<x.F<<' '<<x.S<<' '<<y.F<<' '<<y.S<<endl;
  }
  


}

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

int main(){
  string s;
  cin >> s;
  int count = 0;
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  for(int i = 2; i < s.size() - 1; i++){
    if(s[i] == 'C'){
      count++;
    }
  }
  if(count != 1){
    cout << "WA" << endl;
    return 0;
  }
  for(int i = 0; i < s.size(); i++){
    if(s[i] != 'A' && s[i] != 'C' && s[i] >= 65 && s[i] <= 90){
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
  return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,z,w;
    cin>>n>>z>>w;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    if(n==1){
        cout<<abs(vec[0]-w)<<endl;
      	return 0;
    }
    cout<<max(abs(vec[n-1]-w),abs(vec[n-2]-vec[n-1]))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    if (n & 1) cout << 0 << '\n';
    else {
        ll cur = 2;
        while (cur*5 <= n) {
            cur *= 5;
            ans += n/cur;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
      
        // flag
        boolean flag = false;

		// argumentの取得
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
	    //int y = sc.nextInt();
      
        // 総当たり
        out_of_loop:
        for (int i=1; i < 10; i ++) {
          for (int j = 1; j < 10; j++) {
            if ( x == (i * j)) {
              System.out.println("Yes");
              flag = true;
              break out_of_loop;
            } else {
              // do nothing
            }
          }
        }
      
        if (flag == false) {
          System.out.println("No");
        }
	} 
}

Measured memory_bytes: 23636
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=200005,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f; 
int depth[maxn],visit[maxn],head[maxn],son[maxn];
bool connect[maxn];
int num;
int b,w,n;

struct Edge{
	int to,pre;
};
Edge edge[maxn*2];

void addedge(int from,int to) {
	edge[num].to=to;
	edge[num].pre=head[from];
	head[from]=num++;
	edge[num].to=from;
	edge[num].pre=head[to];
	head[to]=num++;
}

void dfs(int now,int step) {
	visit[now]=1;
	depth[now]=step;
	son[now]=1;
	if (now==n) connect[now]=1;
	for (int i=head[now];i!=-1;i=edge[i].pre) {
		int to=edge[i].to;
		if (!visit[to]) {
			dfs(to,step+1);
			son[now]+=son[to];
			connect[now]=connect[now]|connect[to];
		}
	}
}

void dfs2(int now) {
	visit[now]=1;
	bool IsBlack;
	int p;
	if (depth[now]<=depth[n]/2) IsBlack=1; else IsBlack=0;
	for (int i=head[now];i!=-1;i=edge[i].pre) {
		int to=edge[i].to;
		if (!visit[to]&&connect[to]) {
			dfs2(to);
			p=to;
		}
	}
	if (now!=n&&now!=1) 
		if (IsBlack) {
			b+=son[now]-son[p];
		} else w+=son[now]-son[p];
}

int main() {
	int i,j,k,x,y;
	mem0(visit);
	mem0(son);
	mem0(connect);
	num=0;
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for (i=1;i<n;i++) {
		scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	dfs(1,0);
	int r;
	for (int i=head[1];i!=-1;i=edge[i].pre) {
		if (connect[edge[i].to]) {
			r=edge[i].to;
			break;
		}
	}
	b=n-son[r];
	w=son[n];
	mem0(visit);
	dfs2(1);
	if (b>w) printf("Fennec"); else printf("Snuke");
	return 0;
}

Measured memory_bytes: 12160
#include <stdio.h>
#include <stdlib.h>

int sum;
int ans;
int n;
int l[205];

int minv = 1 << 30;

int main()
{
    scanf("%d", &n);
    scanf("%d", &l[0]);

    for (int i = 1; i <= n; i++) {
        l[i] = l[0] + i - 1;

        sum += l[i];
    }

    for (int i = 1; i <= n; i++) {
        int tmp = 0;
        for (int j = 1; j <= n; j++) {
            if (j == i) continue;
            tmp += l[j];
        }

        if (abs(sum - tmp) < minv) {
            minv = abs(sum - tmp);
            ans = tmp;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
import heapq
k = int(input())
run_list = [i for i in range(1,10)]
heapq.heapify(run_list)
result = 0
for i in range(k):
  result = heapq.heappop(run_list)
  if result % 10 ==0:
    new_1 = result * 10
    new_2 = result * 10 + 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  elif result % 10 ==9:
    new_1 = result * 10 + 8
    new_2 = result * 10 + 9
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  else:
    new_1 = result * 10 + (result % 10)
    new_2 = result * 10 + (result % 10) + 1
    new_3 = result * 10 + (result % 10) - 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
    heapq.heappush(run_list, new_3)
print(result)

Measured memory_bytes: 11708
//#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 3e5, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, dp[maxn][5][3];
string s;
inline void add(int &i, int j) {
	(i += j) %= mod;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> s;n = s.size();
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++) {
		if(s[i] != '1') {
			for(int x = 0; x < 5; x++)
				for(int y = 0; y < 3; y++)
					add(dp[i+1][x][y==1?2:1], dp[i][x][y]);
		}
		if(s[i] != '0') {
			add(dp[i+1][1][0], dp[i][0][0]);
			add(dp[i+1][0][0], dp[i][0][1]);
			add(dp[i+1][0][1], dp[i][0][2]);
			add(dp[i+1][2][0], dp[i][1][0]);
			add(dp[i+1][1][0], dp[i][1][1]);
			add(dp[i+1][1][1], dp[i][1][2]);
			add(dp[i+1][3][0], dp[i][2][0]);
			add(dp[i+1][2][0], dp[i][2][1]);
			add(dp[i+1][2][1], dp[i][2][2]);
			add(dp[i+1][4][0], dp[i][3][0]);
			add(dp[i+1][3][0], dp[i][3][1]);
			add(dp[i+1][3][1], dp[i][3][2]);
			add(dp[i+1][4][0], dp[i][4][0]);
			add(dp[i+1][4][1], dp[i][4][1]);
			add(dp[i+1][4][2], dp[i][4][2]);
		}
	}
	int ans = 0;
			for(int x = 0; x < 5; x++)
				for(int y = 0; y < 3; y++)
					if(x>y) (ans += dp[n][x][y])%=mod;
	cout << ans;
}


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

def get_shortest_distance(field,locations,current_HP):
	is_visit = [[False for _ in range(len(field[0]))] for __ in range(len(field))]
	frontier = set()
	frontier.add(locations[current_HP-1])
	for step in range(10**10):
		for cx,cy in frontier:
			if (cx,cy)==locations[current_HP]: return step
			is_visit[cx][cy]=True
		next_frontier = set()
		for cx,cy in list(frontier):
			for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
				nx = cx+dx
				ny = cy+dy
				if not (0<=nx<len(field)):		continue
				if not (0<=ny<len(field[nx])):	continue
				if field[nx][ny]=='X':			continue
				if is_visit[nx][ny]: 			continue
				next_frontier.add((nx,ny))
#		assert len(next_frontier)!=0,(current_HP,is_visit,frontier)
		frontier = next_frontier
#	assert True,('the goal is not reachable')

def solve(field,locations):
	total_step=0
	for current_HP in range(1,len(locations)):
		total_step += get_shortest_distance(field,locations,current_HP)
	return total_step

def main():
	line=input().strip()
	H,W,N=list(map(int,line.split(' ')))
	field,locations=list(),dict()
	for i in range(H):
		field.append(list(input().strip()))
		for j,x in enumerate(field[-1]):
			if x=='S':
				locations[0] = (i,j,)
			if x.isdigit():
				x = int(x)
				field[-1][j] = x
				locations[x] = (i,j,)
	print(solve(field,locations))

if __name__=='__main__':
	main()

Measured memory_bytes: 25388
#include <stdio.h>
#include <string.h>

int X, Y;
int resolve(int x, int y)
{
  if ( x<=0 )
    return y==0;
  if ( y==(x*2) )
    return 1;
  return resolve(x-1, y-4);
}
int main()
{
  scanf("%d %d", &X, &Y);
  if ( (Y%2)!=0 )
    printf("No\n");
  else
    printf(resolve(X, Y)? "Yes\n": "No\n");
  return 0;
}

Measured memory_bytes: 1728