akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;


const int gmax_n = 100000;

int par[gmax_n]; //親
int kRank[gmax_n];//木の深さ

void init(int n){
    rep(i,n){
        par[i] = i;
        kRank[i] = 0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(kRank[x] < kRank[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(kRank[x] == kRank[y]) kRank[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

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


    vector<vector<int>> v(m + 1); //ls[i] : iの言語を話せる人の番号
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int l;
            cin >> l;
            v[l].emplace_back(i);
        }
    }

    range(i,1,m + 1){
        /*
        show(i)
        rep(j,v[i].size()){
            cout << v[i][j] << endl;
        }
        cout << endl;
        */
        if(v[i].size() <= 1) continue;
        rep(j,v[i].size() - 1){
            unite(v[i][j], v[i][j + 1]);
        }
    }

    int cnt = 0;
    rep(i,n) if(par[i] == i) cnt++;
    //rep(i,n) { debug(par[i]) }
    if(cnt > 1) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  map<ll, pair<int, ll>, greater<ll> > mp; // val, (i, num)
  mp[0] = make_pair(-1, 1);
  rep(i, N) {
    ll a;
    cin >> a;
    if(!mp.count(a)) {
      mp[a] = make_pair(i, 1);
    } else {
      mp[a].second++;
      mp[a].first = min(mp[a].first, i);
    }
  }
  vector<ll> ans(N);
  for(auto itr=mp.begin(); itr!=mp.end();) {
    ll tmp = itr->first;
    int i = (itr->second).first;
    ll num = (itr->second).second;
    itr++;
    ll tmp2 = itr->first;
    int i2 = (itr->second).first;
    ans[i] += (tmp - tmp2) * num;
    if(i2 == -1) break;
    (itr->second).first = min((itr->second).first, i);
    (itr->second).second += num;
  }
  for(auto a: ans)
    cout << a << endl;
  return 0;
}



Measured memory_bytes: 8064
#include <stdio.h>
int main() {
	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	if (b - a >= 2 * k) {
		for (int i = 0; i < k; i++) {
			printf("%d\n", a + i);
		}
		for (int i = k - 1; i >= 0; i--) {
			printf("%d\n", b - i);
		}
	} else {
		for (int i = a; i <= b; i++) {
			printf("%d\n", i);
		}
	}

	return 0;
}

Measured memory_bytes: 128
n = int(input())
num_list = [ int(v) for v in input().split() ]
num_list2 = sorted(num_list)



a, b = num_list2[n//2-1], num_list2[n//2]

if a == b:
	for i in range(n):
		print(a)
else:
	for i in num_list:
		if i < b:
			print(b)
		else:
			print(a)

Measured memory_bytes: 25620
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int m,n,obj[200];
int dp[180000];
int p3[12];

int f(int mask){
	int& res = dp[mask];
	if(res!=-1)return res;
	res = INF;

	int d[12];
	rep(i,m)d[i] = mask/p3[i]%3;

	int hit = 0;
	rep(i,n){
		int ok = 1;
		rep(j,m)if(d[j]!=2 && d[j] != (obj[i]>>j&1)){
			ok = 0;break;
		}
		if(ok)hit++;
		if(hit>1)break;
	}

	if(hit <= 1)return res = 0;
	rep(i,m)if(d[i] == 2){
		res = min(res, 1 + max(f(mask - 2 * p3[i]), f(mask - 1 * p3[i])));
	}

	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	p3[0] = 1;
	rep(i,11)p3[i+1] = p3[i] * 3;
	while(cin>>m>>n && m){
		rep(i,n){
			string s;
			cin>>s;
			obj[i] = 0;
			rep(j,m)obj[i] |= (s[j] - '0')<<j;
		}
		memset(dp,-1,sizeof(dp));
		cout<<f(p3[m]-1)<<endl;
	}
}

Measured memory_bytes: 1920
def main():
  import sys
  input=sys.stdin.readline
  h,w,k=map(int,input().split())
  H=range(h)
  W=range(w)
  dp=[[[0]*w for j in H] for i in range(4)]
  for _ in range(k):
    r,c,v=map(int,input().split())
    dp[0][r-1][c-1]=v
  if dp[0][0][0]!=0:
    dp[1][0][0]=dp[0][0][0]
    dp[0][0][0]=0
  for y in H:
    for x in W:
      v=dp[0][y][x]
      dp[0][y][x]=0
      for i in range(4):
        if 0<x:
          if dp[i][y][x]<dp[i][y][x-1]:
            dp[i][y][x]=dp[i][y][x-1]
          if 0<i and v!=0 and dp[i][y][x]<dp[i-1][y][x-1]+v:
            dp[i][y][x]=dp[i-1][y][x-1]+v
        if 0<y:
          if dp[0][y][x]<dp[i][y-1][x]:
            dp[0][y][x]=dp[i][y-1][x]
          if v!=0 and dp[1][y][x]<dp[i][y-1][x]+v:
            dp[1][y][x]=dp[i][y-1][x]+v
  print(max([dp[i][h-1][w-1] for i in range(4)]))
main()

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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);

  int i = 0;
  int cnt = 1;
  while (true) {
    if (a.at(i) == -1) {
      cnt = -1;
      break;
    } else if (a.at(i) == 2) {
      break;
    }

    int _i = a.at(i);
    a.at(i) = -1;
    i = _i-1;
    cnt += 1;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	double r,S,l,ex; 
	scanf ("%lf",&r);
	ex=3.141592653589793;
	S=ex*r*r;
	l=2*ex*r;
	printf ("%lf %lf\n",S,l);
	return 0;
}
//(???,_??????)???????????????????????????!!

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  vector<int>l(N);
  for (int i = 0; i < N; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += l.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  char c;
  cin>>c;
  if(c>='a')
    deb("a")
  else
    deb("A")
}

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

# define ll long long
ll mod=pow(10,9)+7;

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

    int a,b,c,k;
    cin>>a>>b>>c>>k;

    if(a>=b){
        while(a>=b){
            b*=2;
            k--;
        }
    }
    if(b>=c){
        while(b>=c){
            c*=2;
            k--;
        }
    }
    if(k<0)
        cout<<"No";
    else
        cout<<"Yes";
}


Measured memory_bytes: 3684
def readints(): return map(int,input().split())

N, T = readints()
a = list(readints())

mdiff = 0
mi = 1145141919
for i in range(N):
    mi = min(mi, a[i])
    mdiff = max(mdiff, a[i] - mi)

mi = 1145141919
ans = 0
for i in range(N):
    mi = min(mi, a[i])
    ans += (a[i] - mi == mdiff)

print(ans)

Measured memory_bytes: 14252
// C - Half and Half
// https://beta.atcoder.jp/contests/abc095/tasks/arc096_a
//

#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;


long long solve(int A, int B, int C, int X, int Y);

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

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    long long ans = solve(A, B, C, X, Y);
    cout << ans << endl;
}


long long solve(int A, int B, int C, int X, int Y) {
    if (A + B <= 2 * C)
        return A * X + B * Y;

    int m = min(X, Y);
    long long ans = 2 * m * C;

    Y -= m;
    if (2 * C < B)
        ans += 2 * C * Y;
    else
        ans += B * Y;

    X -= m;
    if (2 * C < A)
        ans += 2 * C * X;
    else
        ans += A * X;

    return ans;
}


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

long long a[100010];

int main(void){
	int n;
	long long h=0, w=0, ans=0;
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];

	sort(a, a+n);
	reverse(a, a+n);

	for(int i=0; i<n; i++){
		if(a[i]==a[i+1]){
			if(h==0) h = a[i];
			else w = a[i];
			i++;
		}
		ans = h*w;
		if(ans>0) break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string>
using namespace std;

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

    double sum = 0;
    for(int i = 0; i < n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY"){
            sum += x;
        }
        else{
            sum += (380000 * x);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
auto comp = [&] (const int& x, const int& y) {
  return a[x] > a[y];
};
struct Value {
  vector<int> idx;
  Value () {}
  void merge (const Value& v) {
    if (idx.empty()) {
      idx.insert(idx.begin(), v.idx.begin(), v.idx.end());
      return;
    }
    for (int i : v.idx) idx.push_back(i);
    sort(idx.begin(), idx.end());
    idx.erase(unique(idx.begin(), idx.end()), idx.end());
    sort(idx.begin(), idx.end(), comp);
    if ((int) idx.size() > 2) idx.resize(2);
  }
  int get () {
    int res = 0;
    for (int i : idx) res += a[i];
    return res;
  }
};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  a.resize(1 << n);
  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
  }
  vector<Value> dp(1 << n);
  for (int i = 0; i < (1 << n); i++) dp[i].idx.push_back(i);
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) dp[mask].merge(dp[mask ^ (1 << i)]);
    }
  }
  int ans = dp[0].get();
  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, dp[i].get());
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll t(string s){
    ll hh = stoi(s.substr(0,2));
    ll mm = stoi(s.substr(3,2));
    ll ss = stoi(s.substr(6,2));
    return hh*3600 + mm*60 + ss;
}

int imos[100000];
void solve(int n){
    FOR(i,0,100000)imos[i] = 0;
    FOR(i,0,n){
        string s1,s2;
        cin >> s1 >> s2;
        ll S,T;
        S = t(s1);
        T = t(s2);
        imos[S] += 1;
        imos[T] -= 1;
    }
    FOR(i,1,100000)imos[i] += imos[i-1];
    cout << *max_element(imos,imos+100000) << endl;
}

signed main(){
    int n;
    while(cin >> n){
        if(n == 0)break;
        solve(n);
    }
}


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

int main(){
	bool flag = false;
	string s, p;
	cin >> s >> p;
	int a = s.size();
	s += s;
	for(int i=0;i<a;i++){
		if(s[i] == p[0]){
			for(int j=0;j<p.size();j++){
				if(s[i+j] != p[j]) break;
				if(j==p.size()-1) flag = true;
			}
		}
		if(flag) break;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int A, B,ans;
    cin >> A >> B;
    ans = ((1 + (B - A))*(B - A) / 2) - B;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
cnt = 0
for i in d:
    cnt += d[i]*(d[i]-1)//2
for i in range(n):
    print(cnt-d[a[i]]*(d[a[i]]-1)//2+(d[a[i]]-1)*(d[a[i]]-2)//2)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector <pair <int, int>> ba(m);
    rep (i, m) cin >> ba[i].second >> ba[i].first;
    sort(ba.begin(), ba.end());

    int ans = 0, st = 0;
    for (auto & i : ba) {
        if (st <= i.second) {
            ans++;
            st = i.first;
        }
    }

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

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int bobo[27] = {};
int main() {
	string w;
	cin >> w;
	REP(i, w.length()) {
		bobo[w[i] - 'a']++;
	}
	REP(i, 26) {
		if (bobo[i] % 2 == 1) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    lint n, m;
    scanf("%lld%lld", &n, &m);
    if(n < m) swap(n, m);
    if(n == 1) printf("%d\n", 1);
    else if(m == 1) printf("%lld\n", n-2);
    else printf("%lld\n", (n-2)*(m-2));
}

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

int main() {
	int h, w;
	string a[100];

	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> a[i];

	for (int i = 0; i < h+2; i++) {
		if (i == 0 || i == h + 1) {
			for (int j = 0; j < w + 2; j++)cout << "#";
			cout << endl;
		}
		else cout << "#" << a[i-1] << "#" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1 << 28;

vector<int> G[100000];
int X[100000];
int l[100000];
int r[100000];

bool dfs1(int v, int p, int mod) {
	if(X[v] != INF && X[v] % 2 != mod) return false;
	for(auto c : G[v]) {
		if(c == p) continue;
		if(!dfs1(c, v, 1 - mod)) return false;
	}
	return true;
}

bool dfs2(int v, int p) {
	for(auto c : G[v]) {
		if(c == p) continue;
		if(!dfs2(c, v)) return false;
		l[v] = max(l[v], l[c] - 1);
		r[v] = min(r[v], r[c] + 1);
		if(l[v] > r[v]) return false;
	}
	return true;
}

void dfs3(int v, int p) {
	for(auto c : G[v]) {
		if(c == p) continue;
		if(l[c] <= X[v] + 1 && X[v] + 1 <= r[c]) X[c] = X[v] + 1;
		if(l[c] <= X[v] - 1 && X[v] - 1 <= r[c]) X[c] = X[v] - 1;
		assert(X[c] != INF);
		dfs3(c, v);
	}
}

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

	int N, K;
	cin >> N;
	for(int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	cin >> K;
	fill(X, X + N, INF);
	fill(l, l + N, -INF);
	fill(r, r + N, INF);

	int root = -1;
	for(int i = 0; i < K; i++) {
		int V;
		cin >> V;
		V--;
		cin >> X[V];
		l[V] = r[V] = X[V];
		if(root == -1) root = V;
	}

	if(!dfs1(root, -1, X[root] % 2)) {
		cout << "No" << endl;
		return 0;
	}

	if(!dfs2(root, -1)) {
		cout << "No" << endl;
		return 0;
	}

	dfs3(root, -1);

	cout << "Yes" << endl;
	for(int i = 0; i < N; i++) {
		cout << X[i] << endl;
	}
}

Measured memory_bytes: 13824
def solve(n,s,lst):
    if n == 0 and s == 0:
        #print("Complete!")
        return(1)
    elif n==0 or len(lst)==0 or s < lst[0]:
        return(0)
    else:
        return(solve(n-1,s-lst[0],lst[1:]) + solve(n,s,lst[1:]))

if __name__ == "__main__":
    while True:
        n, s = map(int, input().split())

        if n==0 and s==0: 
            break
        print(solve(n,s,list(range(10))))
            
        if n==0 and s==0:
            break

Measured memory_bytes: 7596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N, F, b, cnt;
set<int> a;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> b;
        if (b >= 3200)
            F++;
        else
            a.insert(b / 400);
    }
    cnt = a.size();
    cout << max(1, cnt) << " " << cnt + F;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

bool dp[112][11234];
int s[110];
int main(){
  int n;
  cin>>n;
  rep(i,n)cin>>s[i];

  dp[0][0]=1;
  int ans=0;
  rep(i,n){
    rep(j,11234){
      dp[i+1][j]|=dp[i][j];
      if(j>=s[i]){
        if(dp[i][j-s[i]]){
          dp[i+1][j]=true;
          if(j%10!=0)ans=max(ans,j);
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val (oniPos, oniPerSecond) = readLine()!!.split(" ").map { it.toLong() }
    val (nigePos, nigePerSecond) = readLine()!!.split(" ").map { it.toLong() }
    val time = readLine()!!.toLong()

    if (oniPos <= nigePos) {
        if (oniPos + oniPerSecond * time < nigePos + nigePerSecond * time) {
            println("NO")
        } else {
            println("YES")
        }
    } else {
        if (oniPos + oniPerSecond * time * -1 <= nigePos + nigePerSecond * time * -1) {
            println("YES")
        } else {
            println("NO")
        }
    }
}

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

// void func(ll a, ll b, ll c, ll k, string& res){
// 	if(res=="Yes") return;
// 	if(k==0){
// 		if(c>b && b>a) res="Yes";
// 		return;
// 	}
// 	func(a*2, b, c, k-1, res);
// 	func(a, b*2, c, k-1, res);
// 	func(a,b,c*2, k-1, res);
// }
int main() {
	ll a, b, c, k;
	cin>>a>>b>>c>>k;
	string res="No";
	
	// func(a, b, c, k, res);
	// cout<<res<<endl;
	
	while(true){
		if(c>b && b>a) {res="Yes"; break;}
		if(k<=0) break;
		while(b<=a && k>0){
			b=b*2;
			k--;
		}
		while(c<=b && k>0){
			c=c*2;
			k--;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3592
#include <iostream>

int main(void)
{
	double v;
	while(std::cin >> v)
	{
		double t = v/9.8;
		double y = 4.9*t*t;
		std::cout << (int)(y/5.0+1)+1 << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1224
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut c: Chars,
    }

    let mut ans = 0;

    let mut l = 0;
    let mut r = n - 1;
    while r as i64 - l as i64 > 0 {
        if c[l] == 'R' {
            l += 1;
        }
        if c[r] == 'W' {
            r -= 1;
        }
        if c[l] == 'W' && c[r] == 'R' {
            ans += 1;
            c[l] = 'R';
            c[r] = 'W';
            l += 1;
            r -= 1;
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 3088
N, M = map(int,input().split())
 
A=[]
B=[]
 
for i in range(N):
    a=input()
    A.append(a)
    
for j in range(M):
    b=input()
    B.append(b)


res = 'No'
    
for p in range(N-M+1):
    for q in range(N-M+1):
        # check
        C = 0
        for r in range(M):
            if B[r] == A[p+r][q:(q+M)]:
                C=C+1
            if C==M:
                res = 'Yes'
                            
print(res)
                

Measured memory_bytes: 3316
#include<stdio.h>
int main(){
   int n;
   scanf("%d",&n);
   int a[n];
   for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
   }
   int x=0;
  for(int i=0;i<n;i++){
     if(a[i]%2==0){
        if(a[i]%3==0 ||a[i]%5==0){
         
           x++;
        }else{
           x-=100;
        }
     }
  }

  if(x<0){
      printf("DENIED");

  }else{
  printf("APPROVED");
  }
  return 0;
}


Measured memory_bytes: 1688
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {

	int N,M,ans=0,j;

	cin >> N;

	vector<string>s(N);
	vector<int>X(N);

	for (int i = 0; i < N; i++)
		cin >> s[i];

	cin >> M;

	vector<string>t(M);

	for (int i = 0; i < M; i++)
		cin >> t[i];

	for (j = 0; j < N; j++) {

		for (int i = 0; i < M; i++) {

			if (s[j] == t[i])
				X[j]--;

		}

		for (int i = 0; i < N; i++) {

			if (s[j] == s[i])
				X[j]++;

		}

		if (ans < X[j])
			ans = X[j];

	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, p = 1000000007, z;
int f[1000020];
int v[1000020];
int main() {
	cin >> n;
	f[0] = v[0] = v[1] = 1;
	for (int i = 2; i <= 1000000; i++) {
		v[i] = (long long)v[p % i] * (p - p / i) % p;
	}
	for (int i = 1; i <= 1000000; i++) {
		f[i] = (long long)f[i - 1] * i % p;
		v[i] = (long long)v[i - 1] * v[i] % p;
	}
	for (int i = (n + 1) / 2; i < n; i++) {
		z = (z + (long long)f[i] * f[i - 1] % p * v[2 * i - n]) % p;
	}
	cout << (f[n] + p - z) % p << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x>=r)&&(x<=W-r)&&(y>=r)&&(y<=H-r)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>

using namespace std;

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long x, ans;
  if (n < b) {
    x = n;
    ans = (a * x) / b - a * (x / b);
  } else {
    long long tmp, k;
    k = 1;
    x = b - 1;
    ans = (a * x) / b - a * (x / b);
    do {
      k++;
      x = k * b - 1 <= n ? k * b - 1 : n;
      tmp = (a * x) / b - a * (x / b);
      if (tmp <= ans) {
        break;
      } else {
        ans = tmp;
      }
    } while (x < n);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
dish = [0]*5
dish = [list(input()) for i in range(len(dish))]
time = 0
sumtime = 0

dish_sort = sorted(dish, key=lambda x:x[-1],reverse=True)
dish_sort = [''.join(dish_sort[i]) for i in range(len(dish))]
dish_sort = [int(i) for i in dish_sort]
dish1 = [i for i in dish_sort if i%10==0]
dish2 = [i for i in dish_sort if not i%10==0]
dish3 = dish1 + dish2

if len(dish2)==0:
    dish2.append(dish3[-1])
for i in range(len(dish3)-1):
    while dish3[i] > time:
        time += 10
    sumtime += time
    time = 0
print(sumtime+dish2[-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));
/// lcm(a,b)=a/gcd(a,b)*b (handle overflow)

bool sortinrev1(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second>b.second);
    else return (a.first > b.first);
}
bool sortinrev2(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second<b.second);
    else return (a.first > b.first);
}
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};


int main()
{
    /*int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)cout<<"Yes\n";
    else cout<<"No\n";*/
    string s,t;
    cin>>s>>t;
    int ans=10000000;
    for(int i=0;i<=s.size()-t.size();i++){
        int k=0,cnt=0;
        for(int j=i;j<i+t.size() && i+t.size()-1<s.size();j++){
            if(s[j]!=t[k])cnt++;
            k++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
	return 0;
}

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

int main(void){
  int N;
  scanf("%d",&N);
  char S[N];
  scanf("%s",S);
  if(N%2){
    printf("No\n");
    return 0;
  }
  int n;
  int flag = 0;
  for(n = 0;n < N/2 ;n++){
    if(S[n]!=S[n+N/2]) flag++;
  }

  if(flag==0) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define EREP(i,n) for(int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1
 
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#define BEG cout<<"D::";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#define BEG {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000000000;
 
 
    ll N,a[500000];
    ll f[500000],b[500000];
    ll ans=-INF;
    ll front,back;
    ll cnt=0;
    priority_queue<ll ,vector<ll>, greater<ll> > F;
    priority_queue<ll> B;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,3*N){
      cin>>a[i];
      if(i<N){
        F.push(a[i]);
        front+=a[i];
      }
    }
    FOR(i,N-1,N*2){
 
    if(N-1!=i){
        F.push(a[i]);
        front+=a[i];
        front-=F.top();
        F.pop();
    }
      f[cnt]=front;
      cnt++;
    }
    cnt=0;
    for(int i=N*3-1;N<=i;i--){
      if(i>=2*N){
        B.push(a[i]);
        back+=a[i];
        if(i==2*N){
            b[cnt]=back;
            cnt++;
        }
      }else{
        back+=a[i];
        B.push(a[i]);
        back-=B.top();
        B.pop();
        b[cnt]=back;
        cnt++;
      }
    }
    REP(i,cnt){
      ans=max(ans,(f[i]-b[cnt-i-1]));
    }
    cout << ans << endl;
 
    return 0;
}
 
//ABC 062 D-3N Numbers

Measured memory_bytes: 12148
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    string S, T; cin >> S >> T;
    int N = S.size();

    string ans = "Yes";
    map<char, char> from, to;
    REP(i,N) {        
        if ((to.count(S[i])>0 && to[S[i]]!=T[i])
            || (from.count(T[i])>0 && from[T[i]]!=S[i])) {
            ans = "No";
            break;
        }

        to[S[i]] = T[i];
        from[T[i]] = S[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 916
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
void solve(){


}
ll dp[5009][5009];
int p[5009];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	int a,b;cin>>a>>b;
	vi v;
	repA(i,1,n){
		int x;cin>>x;
		fill(p);
		trav(j,v) if(j>x) p[j]++;
		repA(j,1,n) p[j]+=p[j-1];
		rep(j,x) dp[i][j] = dp[i-1][j];
		repA(j,x,n) {
			dp[i][j] = dp[i-1][j]+b;
			dp[i][j] = min(dp[i][j],dp[i-1][x-1]+1ll*p[j]*a);
		}
		v.pb(x);
	}
	cout<<dp[n][n];
	
	
	
	
	return 0;
}



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


int main() {
ll N;
cin >> N;
string s;
while(N != 0) {
  N--;
    int a = N%26;
    s.push_back(char(a+97));
    N /= 26;
}
reverse(s.begin(),s.end());
cout << s << endl;

return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h.begin(),h.end());
    int ans=10000000000;
    for(int i=0;i<n-k+1;i++)ans=min(ans,h[i+k-1]-h[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3


def read_h(typ=int):
    return map(typ, input().split())


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    n = input()
    s = sum([int(d) for d in n])

    if int(n) % s == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    a, b, c = mi()
    k = ii()
    cnt = 0
    while b <= a:
        cnt += 1
        b *= 2
    while c <= b:
        cnt += 1
        c *= 2
    if k < cnt:
        print(no)
    else:
        print(yes)


main()


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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"

typedef long long ll;
typedef unsigned long long llu;

int main()
{
    FastRead
    string s;

    bool flag=false,ribbon=false;

    cin>>s;

    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='A')
            flag = true;
        else
            ribbon = true;
    }

    if(flag and ribbon)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    ll n,x,m;
    cin >> n >> x >> m;
    map<ll,ll> mp;
    vector<ll> mod;
    for(int i = 0;i < n;i++){
        mp[x]++;
        if(mp[x] >= 2){
            ll sit = 0;
            ll res = 0;
            for(int j = 0;j < mod.size();j++){
                if(mod[j] == x){
                    sit = j;
                    break;
                }
                res += mod[j];
            }
            ll kaisuu = n - sit;
            ll roop = 0;
            for(int j = sit;j < mod.size();j++)roop += mod[j];
            res += roop * (kaisuu / (mod.size() - sit));
            kaisuu %= (mod.size() - sit);//はしたの個数
            for(int j = sit;j < sit + kaisuu;j++)res += mod[j];
            cout << res << endl;
            return 0;
        }
        mod.push_back(x);
        if(i == n - 1){
            ll res = 0;
            for(int j = 0;j < n;j++)res += mod[j];
            cout << res << endl;
            return 0;
        }
        x *= x;
        x %= m;
    }
}

Measured memory_bytes: 6764
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int dp[100005][3];

int main(void)
{
    int vacation_length;
    vector<int> swim_happiness;
    vector<int> insect_happiness;
    vector<int> homework_happiness;

    cin >> vacation_length;

    for(int i = 0; i < vacation_length; i++){
        int swim, insect, homework;
        cin >> swim >> insect >> homework;
        swim_happiness.push_back(swim);
        insect_happiness.push_back(insect);
        homework_happiness.push_back(homework);
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for(int i = 0; i <= vacation_length; i++){
        for(int j = 0; j < 3; j++){
            // go swimming
            if(j == 0){
                // sum when previous action was catching insect
                const int prev_insect_sum = dp[i][1] + swim_happiness[i];
                // sum when previous action was homework
                const int prev_homework_sum = dp[i][2] + swim_happiness[i]; 
                dp[i + 1][0] = max(prev_insect_sum, prev_homework_sum);
            // go catching insects
            }else if(j == 1){
                const int prev_swim_sum = dp[i][0] + insect_happiness[i];
                const int prev_homework_sum = dp[i][2] + insect_happiness[i]; 
                dp[i + 1][1] = max(prev_swim_sum, prev_homework_sum);
            // do homework
            }else{
                const int prev_swim_sum = dp[i][0] + homework_happiness[i];
                const int prev_insect_sum = dp[i][1] + homework_happiness[i]; 
                dp[i + 1][2] = max(prev_swim_sum, prev_insect_sum);
            }
        }
    }

    cout << max(max(dp[vacation_length][0], dp[vacation_length][1]), dp[vacation_length][2]) << endl;

    return 0;
}

Measured memory_bytes: 2796
import bisect

N,Q = (int(x) for x in input().split())

stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]

stop_arr_ind = list(range(N))
stop_arr_ind.sort(key=lambda x:stop_arr[x][2])
# stop_arr.sort(key=lambda x:x[2], reverse=True)
ans_arr = [-1]*Q
skip_arr = [-1]*(Q+1)

def update_skip(skip_arr, x):
    if skip_arr[x] == -1:
        return x
    x_dest = update_skip(skip_arr, skip_arr[x])
    skip_arr[x] = x_dest
    return x_dest

for i in stop_arr_ind:
    s,t,x = stop_arr[i]
    q_start = bisect.bisect_left(Q_arr, s-x)
    q_stop = bisect.bisect_left(Q_arr, t-x)
    l = q_start
    while l < q_stop:
        if skip_arr[l] == -1:
            skip_arr[l] = q_stop
            ans_arr[l] = x
            l += 1
        else:
            l = update_skip(skip_arr, l)

print(*ans_arr, sep="\n")


Measured memory_bytes: 64932
import itertools
N, M, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]
l = list(range(1, M+1))
ans = 0
for v in itertools.combinations_with_replacement(l, N):
    A = sorted(list(v))
    cost = 0
    for i in range(Q):
        if A[query[i][1]-1] - A[query[i][0]-1] == query[i][2]:
            cost += query[i][3]
    ans = max(ans, cost)
print(ans)

Measured memory_bytes: 73804
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

typedef long long int ll;


int h, w;
string a[128];
int cnt[26];

int main(void){
	cin >> h >> w;
	for(int i=0;i<h;i++){
		cin >> a[i];
		for(int j=0;j<w;j++){
			cnt[a[i][j] - 'a']++;
		}
	}

	int c2 = 0, c1 = (h%2)*(w%2);
	if (h%2) c2 += w/2;
	if (w%2) c2 += h/2;
	//cerr << "c2 c1 = " << c2  << " " << c1 << endl;

	int r21 = 0, r42 = 0;
	for(int i=0;i<26;i++){
		if (cnt[i]%2==1){
			r21++; cnt[i]--;
		}
		if (cnt[i]%4==2) r42++;
	}
	bool ans = true;
	/*
	if (h>1 && w>1){
		if (r21 > 1) ans = false;
		else if (r21 == 1 && (h%2==0 || w%2==0)) ans = false;
		else if (r42 > 2) ans = false;
		else if (r42 == 2 && (h%2==0 && w%2==0)) ans = false;
	}else if (h==1 && w==1){
	}else{
		if (r21 > 1) ans = false;
	}*/
	if (r21 > 1) ans = false;
	else if (r21 == 1 && c1==0) ans = false;
	else if (r42 > c2) ans = false;

	cout << (ans ? "Yes" : "No") << endl;





	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 250
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,mod,mx[MN*2+5],mx2[MN*2+5],f[MN*2+5][MN+5],ans,S[MN*2+5],num;
inline void R(int&x,int y){(x+=y)>=mod?x-=mod:0;}
inline int OP(int x){return (x&1)?mod-1:1;}
int main()
{
    n=read();mod=read();
    for(int i=0;i<2*n;++i) mx[i]=int(sqrt(4*n*n-i*i)+1e-9);
    --mx[0];
    for(int i=0;i<=n;++i) mx2[i]=int(sqrt(n*n-i*i-1)+1e-9);
    for(int i=2*n-1,j=n;i>n||j>=0;)
        if(j<0||(i>n&&mx[i]<=mx2[j])) S[++num]=i--;
        else S[++num]=j--;
    for(int t=0;t<=n+1;++t)
    {
        int k=0;memset(f,0,sizeof(f));f[0][0]=1;
        for(int i=1;i<=num;S[i++]>n?++k:0) for(int j=0;j<=t;++j) if(f[i-1][j])
        {
            if(S[i]>n)
            {
                if(mx[S[i]]>=j+k) R(f[i][j],1LL*f[i-1][j]*(mx[S[i]]-(j+k)+1)%mod);
            }
            else
            {
                if(mx2[S[i]]>=j+k) R(f[i][j+1],1LL*f[i-1][j]*(mx2[S[i]]-(j+k)+1)%mod);
                if(mx[S[i]]-(2*n-S[i]-1+(t-j))>=0) R(f[i][j],1LL*f[i-1][j]*(mx[S[i]]-(2*n-S[i]-1+(t-j))+1)%mod);
            }
        }
        ans=(ans+1LL*OP(t)*f[num][t])%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 768
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    j = i-1
    key = a[i]
    #print(key)
    while 0 <= j and key < a[j]:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = key
    print(" ".join(map(str,a)))


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

int main(){
    int n, x, t;
    cin >> n >> x >> t;
    if(n%x==0){
        cout << n/x*t << endl;
    }
    else{
        cout << (n/x+1)*t << endl;
    }
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    int ans = 0;
    vector<int> v(n), c(n);
    inc(i, 0, n) cin >> v[i];
    inc(i, 0, n) cin >> c[i];
    inc(i, 0, n){
        ans += max(v[i]-c[i], 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,p[20001],a;
    cin>>n;
    rep(i,n) cin>>a,p[a-1]=i;
    rep(i,n) cout<<(i+1)*(n+1)<<" ";
    cout<<endl;
    rep(i,n) cout<<(n-i)*(n+1)+p[i]<<" ";
}

Measured memory_bytes: 640
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 110;

int a[MR];

int main()
{
	int N;
	scanf("%d", &N);
	REP(i, N)
		scanf("%d", &a[i]);

	int res = 0;
	for (int i = 0; i < N;)
	{
		int j = i + 1;
		while (j < N && a[j] == a[i])j++;
		res += (j - i) / 2;

		i = j;
	}

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

	return 0;
}

Measured memory_bytes: 256