akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F0(i, n) for (int i = 0; i < n; i++)
#define F1(i, n) for (int i = 1; i < n; i++)
#define Fi(n, a) for (int i = 0; i < n; i++) a[i] = gi()
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define MD 1000000007
int f[104];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(f, 0, sizeof(f));
    int x = gi();
    int n = gi();
    F0(i, n) f[gi()] = 1;
    int b = -300, bm = 1000;
    for (int i = -200; i < 300; i++)
        if (i < 1 || i > 100 || f[i] == 0) {
            int a = abs(x-i);
            if (a < bm) {
                bm = a;
                b = i;
            }
        }

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

    return 0;
}


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

int n, k;
int p[5010], c[5010];
int siz[5010];
long long sum[5010];
long long dp[5001][10000];
int st[5010], it, mar[5010];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &p[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &c[i]);
	if (k < n << 1) {
		long long ans = -1000000000000000;
		for (int j = 0; j < k; ++j) {
			for (int i = 1; i <= n; ++i)
				dp[i][j + 1] = -1000000000000000;
			for (int i = 1; i <= n; ++i) {
				dp[p[i]][j + 1] = max(dp[p[i]][j + 1], max(0ll, dp[i][j]) + c[p[i]]);
				ans = max(ans, dp[p[i]][j + 1]);
			}
		}
		printf("%lld\n", ans);
		return 0;
	}
	for (int j = 0; j < n << 1; ++j) {
		for (int i = 1; i <= n; ++i)
			dp[i][j + 1] = -1000000000000000;
		for (int i = 1; i <= n; ++i)
			dp[p[i]][j + 1] = max(dp[p[i]][j + 1], max(0ll, dp[i][j]) + c[p[i]]);
	}

	long long ans = -1000000000000000;
	for (int i = 1; i <= n; ++i)
		if (!mar[i]) {
			it = 0;
			long long su = 0;
			for (int j = i; !mar[j]; j = p[j])
				mar[j] = i, su += c[j], st[it++] = j;
			int si = it;
			while (it--)
				siz[st[it]] = si, sum[st[it]] = su;
		}
	for (int i = 1; i <= n; ++i)
		if (sum[i] > 0)
			ans = max(ans, dp[i][k % siz[i] + siz[i]] + (k / siz[i] - 1) * sum[i]);
		else
			ans = max(ans, dp[i][min(k, siz[i])]);
	printf("%lld\n", ans);
	return 0;
}



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

int main(){
	int n,w;
	cin >> n >> w;
	
	vector<P> goods(n);
	rep(i,n){
		int x,y;
		cin >> x >> y;
		goods[i].first = x;
		goods[i].second = y;
	}
	
	
	vector<vector<ll>> dp(n+1,vector<ll>(w+1));
	rep(i,n){
		rep(j,w+1){
			if(j-goods[i].first >= 0){
				dp[i+1][j] = max( dp[i][j], goods[i].second + dp[i][j-goods[i].first] );
			}
			else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>

void trace(int A[], int N)
{
  int i;
  for(i = 0;i < N; i++)
    {
      if(i > 0) printf(" ");
      printf("%d",A[i]);
    }
  printf("\n");
}
void insertionSort(int A[],int N)
{
  int j,i,v;
  for(i = 1; i < N; i++)
    {
      v = A[i];
      j = i - 1;
      while(j >= 0 && A[j] > v)
	{
	  A[j+1] = A[j];
	  j--;
	}
      A[j+1] = v;
      trace(A,N);
    }
}

int main()
{
  int N,i,j;
  int A[100];
  scanf("%d",&N);
  for(i = 0; i < N; i++)
    scanf("%d",&A[i]);
  trace(A,N);
  insertionSort(A,N);
  return 0;
}



Measured memory_bytes: 2104
fun main(args: Array<String>) {
    val (a, b, c) = readInputLine().split(" ").map { it.toInt() }
    
    val mod = a % b
    
    for (i in 0..100) {
        if ((mod * i) % b == c) {
            println("YES")
            return
        }
    }
    println("NO")
}

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


Measured memory_bytes: 37880
//
// Created by Hideaki Imamura on 2020-03-15.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

string s, t;

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

    int n = s.length();
    int m = t.length();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string res = "";
    int i = n, j = m;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i-1][j]) {
            --i;
        } else if (dp[i][j] == dp[i][j-1]) {
            --j;
        } else {
            res = s[i-1] + res;
            --i;
            --j;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i=(a);i<(b);i++)
#define per(i,a,b) for(register int i=(b);i>=(a);i--)
#define For(i,a,b) for(register int i=(a);i<=(b);i++)
#define Forenska(it,c) for(register __typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long LL;
typedef pair<int,int> Pair;
typedef vector<int> vec;
const long double PI=3.14159265358979323846264338327950288;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const int MAX_N=100005;
int L[MAX_N],R[MAX_N];
int N,K;
vec G[MAX_N];
int id[MAX_N];
bool res=true;
void DFS(int v=1,int p=-1)
{
	rep(i,0,G[v].size())
	{
		int to=G[v][i];
		if(to==p)continue;
  		DFS(to,v);
  		if(L[to]<-INF/2)continue;
		if(L[v]<-INF/2)
		{
			L[v]=L[to]-1;
			R[v]=R[to]+1;
		}
		else if(abs(L[v])%2==abs(L[to])%2)
		{
			res=false;
			return;
		}
		L[v]=max(L[v],L[to]-1);
		R[v]=min(R[v],R[to]+1);
	}
	if(L[v]>R[v])
	{
		res=false;
	}
}
void DFS2(int v=1,int p=-1)
{
	if(v==1 && id[v]==-1)
	{
		id[v]=L[v];
	}
	rep(i,0,G[v].size())
	{
		int to=G[v][i];
		if(to==p)continue;
		if(id[to]==-1)
		{
			if(L[to]<=id[v]-1 && id[v]-1<=R[to])id[to]=id[v]-1;
			else id[to]=id[v]+1;
		}
		DFS2(to,v);
	}
}
int main()
{
	cin>>N;
//	rep(i,0,N)
	For(i,1,N)
	{
		L[i]=-INF;
		R[i]=INF;
		id[i]=-1;
	}
	rep(i,0,N-1)
	{
		int a,b;
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	cin>>K;
	rep(i,0,K)
	{
		int v,p;
		cin>>v>>p;
		id[v]=L[v]=R[v]=p;
	}
	DFS();
	if(res)
	{
		puts("Yes");
		DFS2();
        For(i,1,N)cout<<id[i]<<endl;
	}
	else puts("No");
	return 0;
}


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<bool> possible(n);
    possible[0] = true;
    vector<int> cur_cnt(n, 1);
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        if(!cur_cnt[x]) continue;
        if(possible[x]) {
            if(cur_cnt[x] > 1) possible[y] = true;
            else possible[x] = false, possible[y] = true;
        }
        cur_cnt[x]--;
        cur_cnt[y]++;
    }
    int ans = 0;
    for(bool x : possible) ans += x;
    cout << ans << endl;
}





Measured memory_bytes: 3728
// 4_abc144_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a, b, x;
    cin >> a >> b >> x;
    double v = a * a * b;
    double c, theta;

    if(x > v / 2){
        c = 2 * (a * a * b - x) / (a * a);
        theta = atan(c / a);
    }else{
        c = 2 * x / (a * b);
        theta = atan(b / c);
    }
    cout << setprecision(15) << theta * 180 / M_PI << 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> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	int k;
	
	cin >> n >> k;
	
	int ans = 0;
	
	for(int i = 0; i < n; ++i) {
		int x;
		
		cin >> x;
		
		ans += 2*min(x , abs(k - x));
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> a(n); cin >> a;
    sort(all(a));
    const ll N = a.back();
    vector<P> v;
    rep(i, n) {
        if (a[i] >= N) continue;
        v.pb(P(min(N-a[i], a[i]), a[i]));
    }
    sort(all(v), greater<P>());
    const ll R = v[0].second;
    cout << N << " " << R << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using Matrix = std::vector<std::vector<long long>>;

int main() {
    long long L, A, B, M;
    std::cin >> L >> A >> B >> M;

    std::vector<long long> C(19);
    long long p = 1;
    for (int d = 1; d < 19; d++) {
        p *= 10;
        if (p - 1 < A)
            continue;
        C[d] = std::min(L, (p - 1 - A) / B + 1);
    }

    auto mul = [&M](Matrix& m1, Matrix& m2) {
        Matrix res(3, std::vector<long long>(3));
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                for (int k = 0; k < 3; k++) {
                    res[i][j] += m1[i][k] * m2[k][j] % M;
                    res[i][j] %= M;
                }
        return res;
    };

    auto pow = [&mul](Matrix& m, long long n) {
        Matrix res = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
        for (; n; n >>= 1) {
            if (n & 1)
                res = mul(res, m);
            m = mul(m, m);
        }
        return res;
    };

    std::vector<long long> ans = {0, A % M, 1};
    p = 1;
    for (int d = 1; d < 19; d++) {
        p = p * 10 % M;
        Matrix m = {{p, 0, 0}, {1, 1, 0}, {0, B % M, 1}};
        m = pow(m, C[d] - C[d - 1]);
        std::vector<long long> res = {0, 0, 0};
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++) {
                res[i] += ans[j] * m[j][i] % M;
                res[i] %= M;
            }
        ans = res;
    }

    std::cout << ans[0] << "\n";
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
S=list(input())
tab=0
tb=0
for x in S:
  if x==('a'):
    if tab<A+B:
      print('Yes')
      tab+=1
    else:
      print('No')
  
  if x==('b'):
    if tb<B and tab<A+B:
      print('Yes')
      tab+=1
      tb+=1
    else:
      print('No')
      
  if x==('c'):
    print('No')

Measured memory_bytes: 4708
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define N 200011
using namespace std;
struct apple{
	int v,nxt;
}edge[N*4];
int indexx[N],n,dp[N],tot;
void addedge(int x,int y){
	edge[++tot].v=y;
	edge[tot].nxt=indexx[x];
	indexx[x]=tot;
}
void dfs(int u,int fa){
	int t=indexx[u],vv;
	while(t){
		vv=edge[t].v;
		if(vv!=fa){
			dfs(vv,u);
			dp[u]^=(dp[vv]+1);
		}
		t=edge[t].nxt;
	}
}
int main(){
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	dfs(1,0);
	if(dp[1]) printf("Alice\n");
	else printf("Bob\n");
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#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(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int start = H1*60 + M1;
    int end = H2*60 + M2;
    cout << end - start - K << endl;
    return 0;
}

Measured memory_bytes: 3632
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	x := readInt()

	for i := -1000; i <= 1000; i++ {
		for j := -1000; j <= 1000; j++ {
			if math.Pow(float64(i), 5)-math.Pow(float64(j), 5) == float64(x) {
				fmt.Printf("%d %d", i, j)
				return
			}
		}
	}
}


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

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

  vector<int> w(N + 1);
  vector<int> v(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }

  vector<vector<long long>> dp(N + 1, vector<long long>(W + 1));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[N][W] << endl;

}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
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 switch_index(char s) {
    if (s == 'a') {
        return 0;
    } else if (s == 'b') {
        return 1;
    } else {
        return 2;
    }
}
int main()
{
    string A, B, C;
    cin >> A >> B >> C;
    char v = '-';
    int a_index = 0;
    int a_size = A.size();
    int b_index = 0;
    int b_size = B.size();
    int c_index = 0;
    int c_size = C.size();
    int next = 0;
    while (true) {
        if (next == 0) {
            if (a_index == a_size) {
                v = 'A';
                break;
            }
            next = switch_index(A[a_index]);
            a_index++;
        } else if (next == 1) {
            if (b_index == b_size) {
                v = 'B';
                break;
            }
            next = switch_index(B[b_index]);
            b_index++;
        } else {
            if (c_index == c_size) {
                v = 'C';
                break;
            }
            next = switch_index(C[c_index]);
            c_index++;
        }
    }

    cout << v << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

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

int top=0;
int cnt=0;
if(a%2==b%2 && b%2==c%2){
    top=max(a,max(b,c));
    while(top>a){
        a+=2;
        cnt++;
    }
    while(top>b){
        b+=2;
        cnt++;
    }
    while(top>c){
        c+=2;
        cnt++;
    }
}
else if(a%2==b%2){
    a+=1;
    b+=1;
    cnt++;
     top=max(a,max(b,c));
    while(top>a){
        a+=2;
        cnt++;
    }
    while(top>b){
        b+=2;
        cnt++;
    }
    while(top>c){
        c+=2;
        cnt++;
    }
}
else if(a%2==c%2){
    a+=1;
    c+=1;
    cnt++;
     top=max(a,max(b,c));
    while(top>a){
        a+=2;
        cnt++;
    }
    while(top>b){
        b+=2;
        cnt++;
    }
    while(top>c){
        c+=2;
        cnt++;
    }
}
else {
    b+=1;
    c+=1;
    cnt++;
     top=max(a,max(b,c));
    while(top>a){
        a+=2;
        cnt++;
    }
    while(top>b){
        b+=2;
        cnt++;
    }
    while(top>c){
        c+=2;
        cnt++;
    }
}
cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 256
import itertools
seq = ('M', 'A', 'R', 'C', 'H')
li = list(itertools.combinations(seq, 3))
MARCH = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H':0}
N = int(input())
for i in range(N):
    top = input()[0]
    if top in 'MARCH':
        MARCH[top] += 1
ans = 0
for i in li:
    tmp = 1
    for j in i:
        tmp *= MARCH[j]
    ans += tmp
print(ans)

Measured memory_bytes: 3064
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b,c] <- getInts
  ; let result = junban (a,b,c)
  ; putStrLn result
  }

junban :: (Int, Int, Int) -> String
junban (x,y,z)
  | x < y && y < z = "Yes"
  | otherwise      = "No"

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N;
    cin >> N;
    if(N%10 == 3){
        cout << "bon" << endl;
        return 0;
    }
    int a[] = {2,4,5,7,9};
    rep(i,5){
        if(N%10 == a[i]){
            cout << "hon" << endl;
            return 0;
        }
    }
    cout << "pon" << endl;
}

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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  long a, b;
  cin >> a >> b;
  bitset<32> x(a), y(b);
  cout << (x & y) << "\n";
  cout << (x | y) << "\n";
  cout << (x ^ y) << "\n";
  return 0;
}



Measured memory_bytes: 3188
fun main(args: Array<String>) {
    var k = readLine()!!.toInt()
    var (a, b) = readLine()!!.split(" ").map{it.toInt()}
    for (i in a..b) {
        if (i%k == 0) {
            println("OK")
            return
        }
    }
    println("NG")
    return
}

Measured memory_bytes: 36236
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>
#include<map>
using namespace std;
int B[100010];
int main() {
	int N;
	cin >> N;
	int a ;
	for (int i = 0; i < N; i++) {
		cin >> a;
		
		B[a]++;
		if(a!=0)B[a - 1]++;
		B[a + 1]++;

	}
	int Y = 0;
	for (int i = 0; i < 100010; i++) {
		if (Y < B[i]) {
			Y = B[i];
		}
	}

	cout << Y << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {

	long long input,data;
	long long max=-1000001, min=1000001, sum=0;

	cin >> input;

	const int num=input;

	for (int i = 0; i < num; i++) {
		cin >> data;

		if (data > max) {
			max = data;
		}

		if (data < min) {
			min = data;
		}

		sum += data;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;

}

Measured memory_bytes: 3096
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n;
	cin>>n;
	if(n<1200)cout<<"ABC";
	else if(n>=1200&&n<2800)cout<<"ARC";
	else cout<<"AGC";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <utility>

using namespace std;
typedef pair<int, int> pii;

int main(){
	const char COLOR[] = "RGB";
	int N;
	cin >> N;
	vector<pii> stamps(N);
	for(int i = 0; i < N; ++i){ cin >> stamps[i].first >> stamps[i].second; }
	string goal;
	for(int i = 0; i < 4; ++i){
		string line;
		cin >> line;
		goal += line;
	}
	set<string> maskset;
	for(int i = 0; i < N; ++i){
		for(int y = 1 - stamps[i].first; y < 4; ++y){
			for(int x = 1 - stamps[i].second; x < 4; ++x){
				string mask = "................";
				for(int j = 0; j < stamps[i].first; ++j){
					if(y + j < 0){ continue; }
					if(y + j >= 4){ break; }
					for(int k = 0; k < stamps[i].second; ++k){
						if(x + k < 0){ continue; }
						if(x + k >= 4){ break; }
						mask[(y + j) * 4 + (x + k)] = '-';
					}
				}
				maskset.insert(mask);
			}
		}
	}
	vector<string> masks;
	masks.reserve(maskset.size());
	for(set<string>::iterator it = maskset.begin(); it != maskset.end(); ++it){
		masks.push_back(*it);
	}
	set<string> passed_front;
	stack<string> q0, q1;
	stack<string> *cur_front = &q0, *next_front = &q1;
	cur_front->push(goal);
	passed_front.insert(goal);
	int answer = 0;
	while(true){
		while(!cur_front->empty()){
			string &s = cur_front->top();
			string z;
			for(vector<string>::iterator it = masks.begin(); it != masks.end(); ++it){
				z = s;
				char c = '.';
				for(int i = 0; i < 16; ++i){
					if((*it)[i] == '.' || s[i] == '.'){ continue; }
					if(c == '.'){
						c = s[i];
					}else if(c != s[i]){
						c = '.';
						break;
					}
				}
				if(c == '.'){ continue; }
				for(int i = 0; i < 16; ++i){
					if((*it)[i] != '.'){ z[i] = '.'; }
				}
				if(passed_front.find(z) == passed_front.end()){
					if(z == "................"){
						cout << answer + 1 << endl;
						return 0;
					}
					passed_front.insert(z);
					next_front->push(z);
				}
			}
			cur_front->pop();
		}
		swap(cur_front, next_front);
		++answer;
	}
	return 0;
}

Measured memory_bytes: 5188
from collections import defaultdict, deque

h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
ans = 0
directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(h):
    for j in range(w):
        if tizu[i][j] == "#":
            continue
        check = [[False for _ in range(w)] for _ in range(h)]
        check[i][j] = True
        queue = deque()
        queue.append([i, j])
        queue.append(0)
        while queue:
            pos = queue.popleft()
            ans_sub = queue.popleft()
            for dh, dw in directions:
                nh = pos[0] + dh
                nw = pos[1] + dw
                if nh == -1 or nh == h or nw == -1 or nw == w:
                    continue
                if tizu[nh][nw] == "#":
                    continue
                if check[nh][nw]:
                    continue
                check[nh][nw] = True
                queue.append([nh, nw])
                queue.append(ans_sub + 1)
        ans = max(ans, ans_sub)
print(ans)

Measured memory_bytes: 9356
m=9e9
r=range
h,*s=open(0)
h,w,k=map(int,h.split())
for i in r(512):
 t=[j+1for j in r(h)if i>>j&1]+[h];l=len(t);v=1;c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v-=f
  if f:c=u
 if g<1:m=min(m,l-v)
print(m)

Measured memory_bytes: 51800
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main(void) {
	long long n, m;

	scanf("%lld %lld", &n, &m);

	if (n == 1 && m == 1)printf("1");
	else if (n == 1) printf("%lld", m - 2);
	else if (m == 1)printf("%lld", n - 2);
	else {
		printf("%lld", (n - 2) * (m - 2));
	}
	return 0;
}


Measured memory_bytes: 128
n = int(input())

a = []

for i in range(n):
    a.append([int(input()), i])
    
a = sorted(a, key = lambda x:x[0])
ans = 0

for i in range(n):
    if i % 2 == 1 and (a[i][1] - i) % 2 == 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 22112
#include <stdio.h>

int main(int argc, char** argv)
{
	int i, j, k, b, f, r, v, total;

	unsigned char ar[4][3][10] = { { { 0 } } };
	scanf("%d", &total);

	for (i = 0; i < total; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		ar[b - 1][f - 1][r - 1] += v;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				int out = ar[i][j][k];
				if (ar[i][j][k] < 0) {
					out = 0;
				}
				else if (ar[i][j][k] > 9) {
					out = 9;
				}
				printf(" %d", out);
			}
			printf("\n");
		}

		if (i < 3) {
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
N, Y = map(int, input().split())
ans = [-1,-1,-1]
for x in range(N+1):
  for y in range(N+1):
    z = N-x-y
    if z < 0: continue

    if (10000*x + 5000*y + 1000*z) == Y: 
      ans[0]= x
      ans[1]= y
      ans[2]= z
      break
    else: continue

if ans[0]==-1:print("-1 -1 -1")
else:
  print("{} {} {}".format(ans[0],ans[1],ans[2]))




Measured memory_bytes: 41708
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	ll n, q;
	cin >> n >> q;

	vector<ll> s(n), t(n), x(n), d(q);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld %lld %lld", &s[i], &t[i], &x[i]);
	}
	for (int i = 0; i < q; i++)
	{
		scanf("%lld", &d[i]);
	}

	vector<pair<pll, ll> > events;//(時刻，座標，フラグ)
	set<ll> cannot_use;

	for (int i = 0; i < n; i++)
	{
		events.push_back(make_pair(make_pair(s[i] - x[i], x[i]), 1));
		events.push_back(make_pair(make_pair(t[i] - x[i], x[i]), 0));
	}

	sort(events.begin(), events.end());

	int idx = 0;
	int siz = events.size();

	for (int i = 0; i < q; i++)
	{
		while (idx < siz && events[idx].first.first <= d[i]) {

			if (events[idx].second == 1) {
				//工事の開始
				cannot_use.insert(events[idx].first.second);
			}
			else
			{
				//工事の終了
				cannot_use.erase(events[idx].first.second);
			}
			idx++;
		}
		if (cannot_use.empty()) {
			cout << "-1" << endl;
		}
		else
		{
			cout << *cannot_use.begin() << '\n';
		}
	}
	

	return 0;
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}


template<typename T>
T gcd(T m,T n){
    if (m < n) return gcd(n,m);
    T t;
    while (n>0){
        t = m % n;
        m = n;
        n = t;
    }
    return m;
}

int m,n;

int main(){
    int i,j,k;
    
    int a,b,c,d,x,y,g;
    
    cin >> a>>b>>c>>d;
    
    x=abs(c-a);
    y=abs(d-b);
    
    g=gcd(x,y);
    
    if (x!=0 && y!=0)
        cout << (x/g+y/g-1)*g << endl;
    else
        cout << (x+y+1) << endl;
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin >> n;
	int a;
	cin >> a;
	for (int i = 0; i < n - 1; i++) {
		int num;
		cin >> num;
		a = gcd(a, num);
	}
	cout << a << '\n';
	
	return 0;
}


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

let create () = Nil

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

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

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

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

let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then begin
      match split (read_line ()) ' ' with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | _ -> (print t; read (i + 1) t)
    end
  in
  read 0 (create ())

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

using namespace std;

const int N = 2e5+7;
const int MOD = 1e9+7;

template <int _MOD> struct Mint
{
    int v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int _v) { this->v = _v; return *this; }
    Mint operator = (const long long _v) { this->v = static_cast<int>(_v%_MOD); return *this; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) { return Mint(v+b.v); }
    Mint operator - (const Mint &b) { return Mint(v-b.v); }
    Mint operator * (const Mint &b) { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) { return Mint(b.inv()*v); }
    Mint operator += (const Mint &b) { return *this = *this+b; }
    Mint operator -= (const Mint &b) { return *this = *this-b; }
    Mint operator *= (const Mint &b) { return *this = *this*b; }
    Mint operator /= (const Mint &b) { return *this = *this/b; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const { return pow(_MOD-2); }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;

int n;
mint pow2[N];
vector<int> e[N], son[N];

int dfs(int u, int fa)
{
    int fi = -1, sum = 0;
    for (int i = 0, v; i < (int)e[u].size(); ++i) {
        v = e[u][i];
        if (v == fa) {
            fi = i;
            continue;
        }
        son[u][i] = dfs(v, u);
        sum += son[u][i];
    }
    if (fi != -1) son[u][fi] = n-1-sum;
    return sum+1;
}

int main()
{
    cin >> n;
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    pow2[0] = 1;
    for (int i = 1; i <= n; ++i) {
        son[i].resize(e[i].size(), 0);
        pow2[i] = pow2[i-1]*2;
    }
    dfs(1, 0);
    mint res = 0;
    for (int i = 1; i <= n; ++i) {
        mint mul = 1;
        for (int j : son[i]) {
            mul *= pow2[j];
            res -= pow2[j];
        }
        res += mul+(int)son[i].size()-1;
    }
    cout << res/pow2[n] << endl;
    return 0;
}

Measured memory_bytes: 36224
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int a = (h>w?h:w);
  int res = 0;
  while(n > 0){
    n -= a;
    res++;
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  vector<int> c(n);
  for(int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    c[a - 1]++;
    c[b - 1]++;
  }
  for(int i = 0; i < n; i++) {
    if(c[i] & 1) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define sf1(a); scanf("%d",&a);
#define sf2(a,b); scanf("%d %d",&a, &b);
#define sf3(a,b,c); scanf("%d %d %d",&a, &b,&c);
#define sf4(a,b,c,d); scanf("%d %d %d %d",&a, &b,&c,&d);
#define pf1(a); printf("%d\n",a);
#define pf2(a,b); printf("%d %d\n",a,b);
#define pf3(a,b,c); printf("%d %d %d\n",a,b,c);
#define pf4(a,b,c,d); printf("%d %d %d %d\n",a,b,c,d);

using namespace std;

int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1') cout<<"9";
        else cout<<"1";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

def comb(n, r, M):
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % M
        y = y * (i + 1) % M
    return x * pow(y, M - 2, M)
M = 10 ** 9 + 7
print((pow(2, n, M) - comb(n, a, M) - comb(n, b, M) - 1) % M)

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

#include <stdio.h>

int n;
int a[3][10000];
int max=0;

void dfs(int x,int y,int sum){
	
//	printf("%d %d %d\n",x,y,sum);
	
	if(x>1 || y>n) return ;
	
	if(x==1 && y>=n){
		
		if(sum>max){
			max=sum;
		}
		
		return ;
	}
	
	dfs(x,y+1,sum+a[x][y]);
	dfs(x+1,y,sum+a[x][y]);
	
}

int main(){
	


	scanf("%d",&n);
	
	for(int i=0;i<2;i++){
		
		for(int j=0;j<n;j++){
			
			scanf("%d",&a[i][j]);
			
		}
		
	}
	
	dfs(0,0,0);
	
	printf("%d",max);
	
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  vector<ll> dp(n+1);
  dp[0] = 1000;
  for (int k = 1; k <= n; k++) {
    dp[k] = 0;
    for (int i = 0; i < k-1; i++) {
      int m = 99999;
      for (int j = i+1; j < k; j++) {
        m = min(m, a[j]);
      }
      dp[k] = max(dp[k], dp[i]/m*a[k]+dp[i]%m);
    }
  }
  ll ans = 0;
  rep(i,n+1) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    ll n,m;
    cin >> n >> m;

    if(n == 1 && m == 1){
        cout << 1 << endl;
        return 0;
    }
    if(n == 1 || m == 1){
        cout << n+m-3 << endl;
        return 0;
    }
    cout << (n-2)*(m-2) << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
read = sys.stdin.read

N, *ab = map(int, read().split())
graph = [[] for _ in range(N + 1)]

for a, b in zip(*[iter(ab)] * 2):
    graph[a].append(b)

color = [0] * (N + 1)
queue = deque([1])

while queue:
    V = queue.popleft()
    number = 1
    for v in graph[V]:
        if number == color[V]:
            number += 1
        color[v] = number
        queue.append(v)
        number += 1

print(max(color))
for a, b in zip(*[iter(ab)] * 2):
    print(color[b])

Measured memory_bytes: 25900
from sys import stdin

yyyy, mm, dd = list(map(int, stdin.readline().rstrip().split("/")))

isHeisei = False

if yyyy <= 2019:
    if mm <= 4:
        if dd <= 30:
            isHeisei = True

if isHeisei:
    print("Heisei")
else:
    print("TBD")


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------
int32_t main()
{
	FIO;
	//c_p_c();
//--------------------------------------------------


	int n;
	cin >> n;
	mk(arr, n, int);
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	vector<int> dp(n, 1e9 + 5);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= i + 2; j++)
		{
			if (j < n)
			{
				dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
			}

		}

	}

	cout << dp[n - 1] << endl;



}



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

int main(void)
{
    short int A,B,C,D;
    cin>>A>>B>>C>>D;
    while(A!=0 || C!=0)
    {

        C = C-B;
        A = A-D;
        if(C<=0)
        {
            cout<<"Yes"<<endl;
            break;
        }
        else if(A<=0)
        {
            cout<<"No"<<endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3588