akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 40+7;
int pre[MAXN];
int in[MAXN];
struct node{
	int parent;
	int left;
	int right;
};
node tree[MAXN];
vector<int> v;
void post(int root){
	if(root == -1) return;
	post(tree[root].left);
	post(tree[root].right);
	v.push_back(root);
}
int buildTree(int parent, int l1, int r1, int l2, int r2){
	if(l1 > r1 || l2 > r2) return -1;
	int root = pre[l1];
	tree[root].parent = parent;
	int p;
	for(int i = l2; i <= r2; i++){
		if(in[i] == root){
			p = i;
			break;
		}
	}
	tree[root].left = buildTree(root, l1+1, l1+p-l2, l2, p-1);
	tree[root].right = buildTree(root, l1+p-l2+1, r1, p+1, r2);
	return root;
	
}
int main(){
	int n;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		scanf("%d", &pre[i]);
	}
	
	for(int i = 0; i < n; i++){
		scanf("%d", &in[i]);
	}
	
	int r = buildTree(-1, 0, n-1, 0, n-1);
	post(r);
	for(int i = 0; i < v.size(); i++){
		if(i!=0) printf(" ");
		printf("%d", v[i]);
	}
	printf("\n");
	
	return 0;
} 


Measured memory_bytes: 3280
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf (ll)2e18
#define EPS 1e-12
#define mod 1000000007LL
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;

	vector<string> res;

	if (a + b + c == 2) {
		vector<string> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}

		for (int i = 0; i < n; i++) {
			if (s[i] == "AB") {
				if (a == 2 || (a == 1 && b == 0)) {
					res.push_back("B");
					a--;
					b++;
				}
				else if (b == 2 || (a == 0 && b == 1)) {
					res.push_back("A");
					a++;
					b--;
				}
				else {
					if (i + 1 == n || s[i + 1] != "BC") {
						res.push_back("A");
						a++;
						b--;
					}
					else {
						res.push_back("B");
						a--;
						b++;
					}
				}
			}
			else if (s[i] == "AC") {
				if (a == 2 || (a == 1 && c == 0)) {
					res.push_back("C");
					a--;
					c++;
				}
				else if (c == 2 || (a == 0 && c == 1)) {
					res.push_back("A");
					a++;
					c--;
				}
				else {
					if (i + 1 == n || s[i + 1] != "BC") {
						res.push_back("A");
						a++;
						c--;
					}
					else {
						res.push_back("C");
						a--;
						c++;
					}
				}
			}
			else {
				if (b == 2 || (b == 1 && c == 0)) {
					res.push_back("C");
					b--;
					c++;
				}
				else if (c == 2 || (b == 0 && c == 1)) {
					res.push_back("B");
					b++;
					c--;
				}
				else {
					if (i + 1 == n || s[i + 1] != "AC") {
						res.push_back("B");
						b++;
						c--;
					}
					else {
						res.push_back("C");
						b--;
						c++;
					}
				}
			}

			if (a < 0 || b < 0 || c < 0) {
				cout << "No";
				return;
			}
		}

		cout << "Yes\n";
		for (int i = 0; i < n; i++)
			cout << res[i] << '\n';
		return;
	}

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AB") {
			if (a <= b) {
				a++;
				b--;
				res.push_back("A");
			}
			else {
				a--;
				b++;
				res.push_back("B");
			}
		}
		else if (s == "AC"){
			if (a <= c) {
				a++;
				c--;
				res.push_back("A");
			}
			else {
				a--;
				c++;
				res.push_back("C");
			}
		}
		else {
			if (b <= c) {
				b++;
				c--;
				res.push_back("B");
			}
			else {
				b--;
				c++;
				res.push_back("C");
			}
		}

		if (a < 0 || b < 0 || c < 0) {
			cout << "No";
			return;
		}
	}

	cout << "Yes\n";
	for (int i = 0; i < n; i++)
		cout << res[i] << '\n';
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	fore(t, 0, q)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 10560
#include <iostream>

using namespace std;

int main()
{
	int num;
	int * numP;
	int counter = 0;
	cin >> num;
	numP = new int[num + 1];
	for (int i = 1; i <= num; ++i)
		cin >> numP[i];
	for (int i = 1; i <= num; ++i)
	{
		if (numP[numP[i]] == i)
		{
			++counter;
		}
			
	}
	cout << counter / 2 << endl;
	delete[] numP;
	return 0;
}

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


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

	long long res = 0;

	priority_queue<int> pq;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		pq.push(a);
	}
	for (int i = 0; i < m; ++i) {
		int current = pq.top();
		pq.pop();
		pq.push(current / 2);
	}
	while (!pq.empty()) {
		res += pq.top();
		pq.pop();
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int a,b,k,ans;
	scanf("%d%d%d",&a,&b,&k);
	ans=a;
	if(ans>b) ans=b;
	while(k--){
		for(;ans>0;ans--){
			if(a%ans==0&&b%ans==0) break;
		}
		ans--;
	}
	ans++;
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
const int N = 1e6 + 7 ;
using namespace std;

int n,m;
int u,v;
int ans[N] = {0};
vector<int> s[N];

void bfs(){
	queue<int> q;
	q.push(1);
	ans[1] = 1;
	while(!q.empty()){
		int tmp = q.front();
		q.pop();
		for(auto w : s[tmp]){
			if(ans[w] == 0){
				ans[w] = tmp;
				q.push(w);
			}
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0; i< m; i++){
		cin >> u >> v;
		s[v].push_back(u);
		s[u].push_back(v);
	}
	bfs();
	for(int i = 1; i<=n; i++){
		if(ans[i] == 0){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes" << endl;
	for(int i = 2; i<= n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 31580
MOD = 1000000007
H, W, K = map(int, input().split())
table = [[0, 0, 0] for i in range(9)]

for i in range(2 ** (W-1)):
    n = [i & 2**j for j in range(8)]
    
    for i in range(7):
        if n[i] and n[i+1]:
            break
    else:
        i = 0
        while i < W:
            if not n[i]:
                table[i+1][1] += 1
                i += 1
            else:
                table[i+1][2] += 1
                table[i+2][0] += 1
                i += 2
    
dp = [[0 for i in range(W+2)] for j in range(H+1)]
dp[0][1] = 1

for i in range(1, H+1):
    for j in range(1, W+1):
        a = dp[i-1][j-1] * table[j][0]
        b = dp[i-1][j] * table[j][1]
        c = dp[i-1][j+1] * table[j][2]
        dp[i][j] = (a+b+c) % MOD
            
print(dp[H][K])

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    
    ll n,m;
    cin >> n >> m;

    cout << (n * (n -1))/2 + (m*(m-1))/2<< endl;


    return 0;
}

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

int main() {
	string s;
	cin >> s;

	s.push_back('<');

	int sz = s.size();
	int cnt_L = 0, cnt_R = 0;
	long long ans = 0;
	for (int i = 0; i < sz; ++i) {
		if (s[i] == '<') cnt_L++;
		else cnt_R++;
		if (s[i] == '>' && s[i + 1] == '<') {
			ans += (long long)max(cnt_L, cnt_R) * (max(cnt_L, cnt_R) + 1) / 2;
			ans += (long long)min(cnt_L, cnt_R) * (min(cnt_L, cnt_R) - 1) / 2;
			cnt_L = 0;
			cnt_R = 0;
		}
	}

	s.pop_back();
	s = '>' + s;
	int cnt = 0;
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == '<') cnt++;
		else {
			ans += (long long)cnt * (cnt + 1) / 2;
			break;
		}
	}

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


Measured memory_bytes: 4188
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi A(n);
	REP(i,n)cin >> A[i];
	so(ALL(A));
	cout << A[n-1] - A[0] << endl;
	return 0;
}

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

long long int N, T, i, minv = 1000000000, maxg = 0, tow;
long long int a[100000];

int main(){
    scanf("%lld%lld", &N, &T);
    for(; i < N; i++){
        scanf("%lld", a + i);
        if(a[i] <= minv){
            minv = a[i];
        }
        if(maxg < a[i] - minv){
            maxg = a[i] - minv;
            tow = 1;
        }else if( maxg == a[i] - minv) tow++;
    }
    cout << tow << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#define INF (1 << 25)
using namespace std;

int main(){
    int cost[128][128],time[128][128];
    int n,m,q,a,b,c,d,s,g,r;
    while(cin >> n >> m,n||m){
        for(int i=0;i<128;i++){
            for(int j=0;j<128;j++){
                cost[i][j] = INF; time[i][j] = INF;
            }
        }
        for(int i=0;i<n;i++){
            cin >> a >> b >> c >> d;
            cost[a][b] = c; cost[b][a] = c;
            time[a][b] = d; time[b][a] = d;
        }
        for(int i=1;i<=m;i++){
            for(int j=1;j<=m;j++){
                for(int k=1;k<=m;k++){
                    cost[j][k] = min(cost[j][k],cost[j][i] + cost[i][k]);
                    time[j][k] = min(time[j][k],time[j][i] + time[i][k]);
                }
            }
        }
        cin >> q;
        while(q--){
            cin >> s >> g >> r;
            cout << ((r == 0)? cost[s][g] : time[s][g]) << endl;
        }
    }
}

Measured memory_bytes: 1284
N = int(input())
s = list(input())
t = list(input())

tmp=0
for i in range(N):
    for j in range(N):
        if(s[j]==t[i]):
            for k in range(N-1,j,-1):
                tmp=0
                if(s[k]!=t[k-j]):
                    tmp=1
                    break
            if(tmp==0):
                print(N+j)
                exit()
print(N*2)


Measured memory_bytes: 38512
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define dpr(x) cerr << #x << ": " << x << endl;
#define dprc(c)            \
  do {                     \
    cerr << #c << ":";     \
    for (auto &_i : (c)) { \
      cerr << " " << _i;   \
    }                      \
    cerr << endl;          \
  } while (0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int>    vi;
typedef vector<vi>     vvi;
int                    INF = 1e9 + 7;
#define all(c) (c).begin(), (c).end()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define rtr(i, c) for (auto i = (c).rbegin(); i != (c).rend(); i++)
#define rep(i, b) for (auto i = 0; i < (b); i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int N, M, Q;
  cin >> N >> M >> Q;
  vvi G(N + 2, vi(N + 2, 0));

  rep(i, M)
  {
    int l, r;
    scanf("%d %d", &l, &r);
    G[l][r]++;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      G[i][j] += G[i][j - 1];
    }
  }

  for (int i = N; i > 0; i--) {
    for (int j = 1; j <= N; j++) {
      G[i][j] += G[i + 1][j];
    }
  }

  rep(i, Q)
  {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", G[l][r]);
  }

  return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;
public 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();
if(a < b){
if(b < c){
System.out.printf("%d %d %d\n", a, b, c);
}else if(c < a){
System.out.printf("%d %d %d\n", c, a, b);
}else{
System.out.printf("%d %d %d\n", a, c, b);
}
}else if(b < a){
if(a < c){
System.out.printf("%d %d %d\n", b, a, c);
}else if(c < b){
System.out.printf("%d %d %d\n", c, b, a);
}else{
System.out.printf("%d %d %d\n", b, c, a);
}
}
}
}


Measured memory_bytes: 26216
N = int(input())
if N % 2 == 1:
    print(0)
else:
    N_copy = N
    N_copy //= 2
    count_5 = 0
    count_2 = 0
    while N_copy > 0:
        N_copy //= 5
        count_5 += N_copy
    while N > 0:
        N //= 2
        count_2 += N
    print(min(count_2, count_5))

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  int a[N];
  FOR(i,0,N) cin >> a[i];
  int ans = 1e9;
  int r = 0;
  map<int, int> mp;
  // [l, r)の和をみる
  FOR(l,0,N) {
    while(r < N && mp.size() < K) {
      if(a[r] <= K) mp[a[r]]++;
      r++;
    }
    if(mp.size() == K) ans = min(ans, r - l);
    if(a[l] <= K) {
      mp[a[l]]--;
      if(mp[a[l]] == 0) {
        mp.erase(a[l]);
      }
    }
  }
  cout << (ans != 1e9 ? ans : 0) << endl;
}


Measured memory_bytes: 8168
until (n = $<.gets.to_i).zero?
  ary = $<.gets.split.map(&:to_i)
  ohajiki = 32
  loop do
    ohajiki -= (ohajiki - 1) % 5
    puts ohajiki
    a = ary.first
    if ohajiki <= a
      ohajiki = 0
    else
      ohajiki -= a
    end
    puts ohajiki
    break if ohajiki.zero?
    ary.rotate!
  end
end


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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define mt make_tuple
#define int long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;


int N, X[1009], Y[1009], H[1009];
vector< tuple < int , int , int > > v;

 main() {
	cin >> N;
	tuple < int , int , int > G = mt ( -1 , -1 , -1 ) ;
	for (int i = 1; i <= N; i++)
    {
		cin >> X[i] >> Y[i] >> H[i];
		if ( H[i] >= 1)
		G = mt (X[i], Y[i], H[i]);
	}
    for (int j = 0; j <= 100; j++)
	 {
	   for (int i = 0; i <= 100; i++) {
			int V = get<2> (G) + abs ( get<0> (G) - i) + abs(get<1>(G) - j);
            V = max(V, 0LL);
            bool flag = true;

			for (int k = 1; k <= N; k++)
            {
				int VV = V - abs( X[k] - i) - abs ( Y[k] - j );
                VV = max(VV, 0LL);
				if (H[k] != VV)
                    flag = false;
			}
			if (flag == true)
                v.push_back(make_tuple(i, j, V));
		}
	}
//	if (vec.size() == 1)
    		cout << get<0> ( v[0] ) << " " << get<1> ( v[0] ) << " " << get<2> (v[0]) << endl;

}



Measured memory_bytes: 256
n = gets.to_i
s = gets.chop

non = 0
rs = 0
gs = 0
bs = 0
1.upto(n) { |i|
  a = s[i-1]
  rs += 1 if (a == 'R')
  gs += 1 if (a == 'G')
  bs += 1 if (a == 'B')
  i.upto(n) { |k|
    if (i+k) % 2 == 0
      j = (i+k) / 2
      b = s[j-1]
      c = s[k-1]
      if (a != b) and (b != c) and (c != a)
        non += 1
      end
    end
  }
}

puts rs*gs*bs - non


Measured memory_bytes: 14380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
#define M 200005
#define lowbit(x) x&-x
struct point{
	int x,y;
}A[M];
bool cmpx(point a,point b){
	return a.x<b.x;
}
void add_mod(ll &a,ll b){
	a=(a+b+mod)%mod;
}
int n,X[M],Y[M],C[M];
ll pre[M]={1},ans;
void add(int x,int a){
	while(x<M)C[x]+=a,x+=lowbit(x);
}
int query(int x){
	int res=0;
	while(x)res+=C[x],x-=lowbit(x);
	return res;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]*2%mod;
	ans=n*(pre[n]-1)%mod;
	for(int i=1;i<=n;++i)scanf("%d%d",&A[i].x,&A[i].y),X[i]=A[i].x,Y[i]=A[i].y;
	sort(X+1,X+n+1);sort(Y+1,Y+n+1);
	for(int i=1;i<=n;++i){
		A[i].x=lower_bound(X+1,X+n+1,A[i].x)-X;
		add_mod(ans,-pre[A[i].x-1]+1);add_mod(ans,-pre[n-A[i].x]+1);
		A[i].y=lower_bound(Y+1,Y+n+1,A[i].y)-Y;
		add_mod(ans,-pre[A[i].y-1]+1);add_mod(ans,-pre[n-A[i].y]+1);
	}
	sort(A+1,A+n+1,cmpx);
	for(int i=1;i<=n;++i){
		int p=query(A[i].y);
		add_mod(ans,pre[p]-1);
		add_mod(ans,pre[i-1-p]-1);
		add(A[i].y,1);
	}
	memset(C,0,sizeof C);
	for(int i=n;i>=1;--i){
		int p=query(A[i].y);
		add_mod(ans,pre[p]-1);
		add_mod(ans,pre[n-i-p]-1);
		add(A[i].y,1);
	}
	cout<<ans;
	return 0;
}
//我只爱章若楠！！！！！
//章若楠太美了！！！！
//我爱章若楠！！！！！ 

Measured memory_bytes: 5760
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
void solve() {
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    cout << max(x * y, a * b) << endl;
}
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, h[100100], dp[100100];

int abss(int A){
    if(A < 0)return -A;
    return A;
}

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> h[i];
        dp[i] = INFL;
    }
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abss(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abss(h[i + 2] - h[i]));
    }
    cout << dp[N - 1] << endl;


    return 0;
}

/*


*/

Measured memory_bytes: 1792
n, l = map(int, input().split())
list1 = []
for i in range(1, n+1):
    list1.append(l + i - 1)
if min(list1) > 0:
    print(sum(list1) - list1[0]) 
elif max(list1) < 0:
    print(sum(list1) - list1[n-1])
else:
    print(sum(list1)) 

Measured memory_bytes: 3060
//Fast IO + Debug Template
#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define pb push_back
#define gl(x) getline(cin,x)
#define gc(x) cin.get(x)
#define sz(x) (int)(x.size())
#define al(x) (x).begin(),(x).end()
#define ms(a, b) memset(a,b,sizeof(a))
#define sp ' '
#define nl '\n'
#define f first
#define s second
#define lsb(x) ((x)&(-x))
#define mp make_pair
#define m(x, y) (x + y) / 2
#define MOD 1000000007
#define gcd(x,y) __gcd(m,n);
#define perm(x) next_permutation(x.begin(), x.end());
#define bs(x,z) binary_search(x.begin(),x.end(),z);
#define lb(x,z) lower_bound(x.begin(),x.end(),z);
#define ub(x,z) upper_bound(x.begin(),x.end(),z);
#define nl '\n'


void sc(){}template<class T,class...A>void sc(T&t,A&...a){cin>>t,sc(a...);}
void pr(){}template<class T,class...A>void pr(T t,A...a){cout<<t,pr(a...);}
typedef long long ll;
typedef pair<int, int> pi;
//weighted (with adjList[])
typedef vector<pi> vii;
//unweighted (with adjList[])
typedef vector<int> vi;
typedef double db;
typedef long double ld;


const int INF = 0x3f3f3f3f;
const int NINF = -INF;
int TC, a, b, c;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	cin >> a; cin >> b; cin >> c;
	int time = 0;
	while (a > 0){
		a -= b;
		time += c;
		
	}
	cout << time << endl;
	
	debug();
return 0;
	}


Measured memory_bytes: 3612
#include <stdio.h>
int main(){
  int x,y,n,k;
  int count=0;
  scanf("%d%d%d%d",&n,&k,&x,&y);
  if(n>k){
    for(int i=0;i<k;i++){
      count=count+x;
    }
    for(int j=k;j<n;j++){
      count+=y;
    }
  }
  else {
    for(int i=0;i<n;i++){
      count+=x;
    }
  }
  printf("%d\n",count);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
main(){
  int N,f_x;
  cin >> N;
  for(int N_x=N;N_x>0;N_x /= 10){
    f_x += (N_x % 10);
  }
  
  if(N%f_x==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,q;
    cin >> n >> q;
    queue<pair<string,int>> que;
    for(int i=0;i<n;i++){
        string s;
        int t;
        cin >> s >> t;
        que.push(make_pair(s,t));
    }
    long long ans=0;
    while(!que.empty()){
        int time=que.front().second;
        string name=que.front().first;
        que.pop();
        if(time>q){
            ans+=q;
            time-=q;
            que.push(make_pair(name,time));
        }
        else{
            ans+=time;
            cout << name << " " << ans << endl;
        }
    }
}


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

using namespace std;

long long n;

int main() {
	scanf("%lld", &n);
	if (n % 2)
		puts("0");
	else {
		long long ans = 0;
		for (long long i = 10; ; i *= 5) {
			ans += n / i;
			if (i > n / 5)
				break;
		}
		printf("%lld\n", ans);
	}
}

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

int main() {
    int n;
    double m,s=0;
    cin>>n>>m;
    vector<double> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        s+=(0.0+v[i]);
    }
    s/=4.0*m;
    sort(v.begin(),v.end(),greater<double>());
    for(int i=0;i<m;i++){
        if(v[i]<s){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
long a,b,c;o;
main(A){
	b=c=-1e18;
	for(scanf("%*d");~scanf("%c%d ",&o,&A);)
		b=o%3?a+=A,fmax(b-A,c+=A):(a=fmax(a-A,c=b+A));
	printf("%ld",a);
}

Measured memory_bytes: 128
N = int(input())
if N == 1:
  print(0)
  import sys
  sys.exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
insu = factorization(N)
sum = 0
for i in insu:
  k = i[1]
  tmp = 0
  while True:
    if tmp*(tmp+1)/2 <= k and k < (tmp+2)*(tmp+1)/2:
      break
    tmp += 1
  sum += tmp
    
print(sum)

Measured memory_bytes: 9504
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" <<endl;
        return 0;
    }else{
        int a,b;
        cin >> a >> b;
        cout << a+b <<endl;
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

#include <atcoder/all>
using namespace atcoder;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  dsu uf(n);
  rep(_, q) {
    int t, a, b;
    cin >> t >> a >> b;
    if (t)
      cout << uf.same(a, b) << '\n';
    else
      uf.merge(a, b);
  }
  return 0;
}

Measured memory_bytes: 3816
#include<stdio.h>

int main(){
  int i,n,x;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    x=i;
    if(x%3==0){
      printf(" %d",i);
      continue;
    }
    while(1){
      if(x%10==3){
        printf(" %d",i);
        break;
      }
      x/=10;
      if(x==0) break;
      

    }
    

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


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int a,b; std::cin >> a >> b;

    if(a>0){
        std::cout << "Positive" << "\n";
        return 0;
    }

    if(a<=0 && 0<=b){
        std::cout << "Zero" << "\n";
        return 0;
    }

    if(b<0){
        if(abs(a-b)%2){
            std::cout << "Positive" << "\n";
        }else{
            std::cout << "Negative" << "\n";
        }
        return 0;
    }
}

Measured memory_bytes: 3588
import sys

def solve():
    input = sys.stdin.readline
    A, B, C, X, Y = map(int, input().split())
    C *= 2
    minCost = A * X + B * Y
    minCost = min(minCost, C * max(X, Y))
    if X >= Y: minCost = min(minCost, A * (X - Y) + C * Y)
    else: minCost = min(minCost, B * (Y - X) + C * X)
    print(minCost)


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.*;

public class Main {
	Scanner sc;
	int N, Q;
	Node[] nodes;
	
	static class Node {
		List<Node> connected = new ArrayList<>();
		int p;
		void connect(Node n) {
			connected.add(n);
		}
		void addForLeaf(Node root) {
			for (Node n : connected) {
				if (n == root) continue;
				n.p += p;
				n.addForLeaf(this);
			}
		}
	}
	
	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		N = sc.nextInt();
		Q = sc.nextInt();
		nodes = new Node[N];
		for (int i = 0; i < N; i++) nodes[i] = new Node();
		
		for (int i = 0; i < N-1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			nodes[a-1].connect(nodes[b-1]);
			nodes[b-1].connect(nodes[a-1]);
		}
		for (int i = 0; i < Q; i++) nodes[sc.nextInt()-1].p += sc.nextInt();
		
		nodes[0].addForLeaf(null);
		
		System.out.println(Arrays.stream(nodes).map(n -> String.valueOf(n.p)).collect(Collectors.joining(" ")));
		System.out.flush();
	}

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

}

Measured memory_bytes: 206708
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int popcount(int n)
{
    int count = 0;
    while (n > 0)
    {
        if (n % 2 == 1)
        {
            count++;
        }
        n /= 2;
    }
    return count;
}

int f(int n)
{
    if (n == 0)
    {
        return 0;
    }
    return 1 + f(n % popcount(n));
}

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

    int n;
    cin >> n;
    string x;
    cin >> x;

    const int init_popcount = count(x.begin(), x.end(), '1');
    vector<int> mod_p1(n + 1, 1), mod_m1(n + 1, 1);

    // init_popcount + 1 / init_popcount - 1 で (10 ** i) を割った余りを計算する

    for (int i = 1; i <= n; i++)
    {
        mod_p1[i] = (mod_p1[i - 1] * 2) % (init_popcount + 1);
        if (init_popcount > 1)
        {
            mod_m1[i] = (mod_m1[i - 1] * 2) % (init_popcount - 1);
        }
    }

    int init_mod_p1 = 0;
    int init_mod_m1 = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (x[n - 1 - i] == '1')
        {
            init_mod_p1 += mod_p1[i];
            init_mod_p1 %= (init_popcount + 1);

            if (init_popcount > 1)
            {
                init_mod_m1 += mod_m1[i];
                init_mod_m1 %= (init_popcount - 1);
            }
        }
    }

    for (int i = n - 1; i >= 0; i--)
    {
        if (x[n - 1 - i] == '1')
        {
            const auto mod = init_popcount - 1;
            if (mod == 0)
            {
                cout << 0 << endl;
            }
            else
            {
                const auto init = (init_mod_m1 + (mod - mod_m1[i])) % mod;
                cout << (1 + f(init)) << endl;
            }
        }
        else
        {
            const auto mod = init_popcount + 1;
            const auto init = (init_mod_p1 + mod_p1[i]) % mod;
            cout << (1 + f(init)) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007


int main() {
	int n, k;
	cin >> n >> k;
	int num = 1;
	for (int i = 0; i < n; i++) {
		num = min(num * 2, num + k);
	}
	cout << num;
	return 0;
}

Measured memory_bytes: 256
fun main() {
    val (n, m) = nextTwoInts()
    println(n * (n - 1) / 2 + m * (m - 1) / 2)
}

val scanner = java.util.Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextList() = readLine()!!.split(" ")
fun nextTwoInts() = Pair(nextInt(), nextInt())
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

fun main(args: Array<String>) = main()

Measured memory_bytes: 29592
N, W = map(int, input().split())
goods = [list(map(int, input().split())) for i in range(N)]
dp = [0 for i in range(W+1)]
for i in range(N):
    for j in range(goods[i][1], W+1):
        dp[j] = max(dp[j-goods[i][1]] + goods[i][0], dp[j])
print(dp[W])


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

int GCD(int a, int b){
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    else return GCD(b, a % b);
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    vector<int> left(N + 1), right(N + 1);
    left[0] = A[0]; right[N] = A[N - 1];
    for(int i = 0; i < N; i++){
        left[i + 1] = GCD(left[i], A[i]);
    }
    for(int i = N - 1; i >= 0; i--){
        right[i] = GCD(right[i + 1], A[i]);
    }

    int ans = 1;
    for(int i = 1; i < N - 1; i++){
        int gcd = GCD(left[i], right[i + 1]);
        ans = max(ans, gcd);
    }
    ans = max(ans, max(left[N - 1], right[1]));

    /*
    for(auto e : left){
        cout << e << " ";
    }
    cout << endl;
    for(auto e : right){
        cout << e << " ";
    }
    cout << endl;
    */

    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb emplace_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii; 
typedef vector<int> vi; 
typedef pair<string, int> Psi; 
typedef pair<ll, ll> Pll;

int main(){
	int N;
	cin >> N;
	int A,B;
	cin >> A >> B;
	int a,b;
	a = b = 0;
	rep(i,N){
		char x;
		cin >> x;
		if(x == 'a'){
			if(a+b < A+B){
				++a;
				puts("Yes");
			}
			else{
				puts("No");
			}
		}
		else if(x == 'b'){
			if(a+b < A+B && b < B){
				++b;
				puts("Yes");
			}
			else{
				puts("No");
			}
		}
		else{
			puts("No");
		}
	}
	return 0;
}



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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

lint gcd(lint a, lint b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b)
{
    return (a  / gcd(a, b))*b;
}

int main()
{
    lint n;cin >> n;
    lint ans=1;
    REP(i,n){
        lint t;
        cin >> t;
        ans =lcm(ans, t);
    }
    cout << ans << "\n";
    return 0;
}

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

int res[100001];
bool check[100001];
vector <pair<int,int>> edge[100001];

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

	int n,a,b;

	cin >> n;

	for(int i=0;i<n-1;i++)
	{
		cin >> a >> b;
		edge[a].push_back(make_pair(b,i));
		edge[b].push_back(make_pair(a,i));
	}

	int Max = 1;
	memset(res,-1,sizeof(res));
	queue <int> que;
	que.push(1);

	while(!que.empty())
	{
		int now = que.front();
		que.pop();
		int color = 1;
		memset(check,false,sizeof(check));
		for(auto it : edge[now])
		{
			if(res[it.second]!=-1)
			{
				check[res[it.second]] = true;
			}
		}

		while(1)
		{
			if(check[color]==false)
			{
				break;
			}
			color++;
		}

		for(auto it : edge[now])
		{
			if(res[it.second]==-1)
			{
				check[color] = true;
				res[it.second] = color;
				while(1)
				{
					if(check[color]==false)
					{
						break;
					}
					color++;
				}
				que.push(it.first);
			}
		}
	}

	//cout << Max << '\n';
	for(int i=0;i<n-1;i++)
	{
		Max = max(res[i],Max);
		//cout << res[i] << '\n';
	}

	cout << Max << '\n';
	for(int i=0;i<n-1;i++)
	{
		//Max = max(res[i],Max);
		cout << res[i] << '\n';
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

#define ipow(a,b)+0.5 (int)pow(a,b)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define pll pair<ll,ll>

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }

const ld EPS = ld(1e-9);
const ld PI = ld(3.141592653589);
ll x;
class Task
{
public:
    void solve(istream& in,ostream& out)
    {
          in>>x;
          ll c=(-1+sqrt(1+8*x))/2;

          ll ans=0;

          for(ll i=c-3;i<=c+5;i++)
          {
                if(n(i)>=x && i>=0)
                {
                     ans=i;
                     break;
                }
          }

          out<<ans<<endl;
    }

    ll n(ll a)
    {
         return (a*(a+1))/2;
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}





Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()

l = 0
count = 0

ans = 0
for r in range(N):
    if S[r] == '0':
        if r == 0 or S[r - 1] == '1':
            count += 1
    if count > K:
        while S[l] == '1':
            l += 1
        while S[l] == '0':
            l += 1
        count -= 1
    ans = max(ans, r - l + 1)

print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

int r,g,b ;

int main(void){

    scanf ("%d%d%d",&r,&g,&b) ;
    
    if ( (10*g+b)%4==0 ){
        printf ("YES\n") ;
    
    } else {
        printf ("NO\n") ;
        
    }
    
    return 0 ;
    
}

Measured memory_bytes: 128
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner();
        try (final FastWriter writer = new FastWriter()) {
            int N = scanner.nextInt();
            boolean ok = true;
            for (int i = 0; i < N; i++) {
                int j = scanner.nextInt();
                if (j % 2 == 0) {
                    if (j % 3 > 0 && j % 5 > 0) ok = false;
                }
            }
            if (ok) writer.println("APPROVED");
            else writer.println("DENIED");
        }
    }
}

class FastWriter extends PrintWriter {
    public FastWriter() {
        super(new BufferedOutputStream(System.out));
    }

    public static void main(final String[] args) {
        try (final FastWriter w = new FastWriter()) {
            w.println(32);
        }
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}



Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
 
using lnt = long long;
using Real = long double;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)
 
#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
 
constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;
 
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N, A[100000]; cin >> N;
	map<lnt, lnt> mp;
	REP(i, N) {
		cin >> A[i];
		mp[A[i]]++;
	}
	vector<lnt> vec;
	for(auto i : mp){
		if(i.second >= 2){
			vec.eb(i.first);
		}
		if(i.second >= 4){
			vec.eb(i.first);
		}
	}
	sort(vec.rbegin(), vec.rend());
	if(vec.size() < 2){
		cout << 0 << ln;
	} else {
		cout << vec[0] * vec[1] << ln;
	}
}

Measured memory_bytes: 10532
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (mut x,mut y,mut z) = get!(usize, usize, usize);
    std::mem::swap(&mut x, &mut y);
    std::mem::swap(&mut x, &mut z);
    println!("{} {} {}", x,y,z);
}


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

int main(){
	int count=0,b=0,w=0;
	string S;
	cin >> S;
	for(int i=0;i<S.length();i++){
		if(S[i]=='B'){
			if(w==1){
				count++;
				w=0;
			}
			b=1;
		}
		else if(S[i]=='W'){
			if(b==1){
				count++;
				b=0;
			}
			w=1;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>
using namespace std;

int main() {
    int X, Y;

    cin >> X >> Y;

    if (X == Y) {
        cout << -1 << endl;
    } else if (X < Y) {
        cout << X << endl;
    } else {
        // X > Y
        if (X % Y == 0) {
            cout << -1 << endl;
        } else {
            cout << X << endl;
        }
    }
}

Measured memory_bytes: 256
n = input()
No753 = ['3','5','7']
for i in range(len(n)-1):
    No753_plus = []
    for no753 in No753:
        No753_plus += ['3' + no753]
        No753_plus += ['5' + no753]
        No753_plus += ['7' + no753]
    No753 += No753_plus
No75 = ['5','7']
for i in range(len(n)-1):
    No75_plus = []
    for no75 in No75:
        No75_plus += ['5' + no75]
        No75_plus += ['7' + no75]
    No75 += No75_plus
No53 = ['3','5']
for i in range(len(n)-1):
    No53_plus = []
    for no53 in No53:
        No53_plus += ['3' + no53]
        No53_plus += ['5' + no53]
    No53 += No53_plus
No37 = ['3','7']
for i in range(len(n)-1):
    No37_plus = []
    for no37 in No37:
        No37_plus += ['3' + no37]
        No37_plus += ['7' + no37]
    No37 += No37_plus
No753 = set(No753)-(set(No75)|set(No53)|set(No37))
count = 0
for no753 in No753:
    if int(no753) <= int(n):
        count += 1
print(count)

Measured memory_bytes: 23412
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

long long A[99999];
long long y[99999];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    long long y1minusyn = A[0];
    for(int i = 1; i < N - 1; i++){
        if(i % 2 == 1){
            y1minusyn -= A[i];
        } else {
            y1minusyn += A[i];
        }
    }
    y[0] = A[N - 1] + y1minusyn;
    for(int i = 1; i < N; i++){
        y[i] = 2 * A[i - 1] - y[i - 1];
    }
    for(int i = 0; i < N; i++){
        if(i != N - 1){
            cout << y[i] << " ";
        } else {
            cout << y[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void){
	int n, a;
	cin >> n >> a;
	while (n - 500>=0) {
		n -= 500;
	}
	if (a >= n) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256