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

using namespace std;

void solve(void)
{
	int n, pa, pb, ga, gb;
	string s;
	cin >> n >> pa >> pb >> ga >> gb >> s;
	if (ga < gb)
	{
		while (pb < gb)
		{
			if (pb + 1 < n && s[pb + 1] == '.' && pb + 2 <= gb)
			{
				pb += 2;
			}
			else if (s[pb] == '.')
			{
				pb += 1;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		while (pa < ga)
		{
			if (pa+1 < n && s[pa+1] == '.' && pa+2<=ga)
			{
				pa += 2;
			}
			else if (s[pa] == '.')
			{
				pa += 1;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;
	}
	else
	{
		while(pa < pb)
		{
			while(1)
			{
				if (pa + 1 < n && s[pa + 1] == '.' && pa + 2 <= ga && pa + 2 != pb)
				{
					pa += 2;
				}
				else if (s[pa] == '.' && pa + 1 != pb)
				{
					pa += 1;
				}
				else if (pa + 2 != pb && pa + 1 != pb && pa != ga)
				{
					cout << "No" << endl;
					return;
				}
				else
				{
					break;
				}
			}
			if (pa > pb)
			{
				break;
			}
			if (s[pb] == '.' && pb + 1 <= gb)
			{
				pb += 1;
			}
			else if (pb + 1 < n && s[pb + 1] == '.' && pb + 2 <= gb)
			{
				pb += 2;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
			//cout << pa << ' ' << pb << endl;
		}
		while (pa < ga)
		{
			if (pa + 1 < n && s[pa + 1] == '.' && pa + 2 <= ga)
			{
				pa += 2;
			}
			else if (s[pa] == '.')
			{
				pa += 1;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		while (pb < gb)
		{
			if (pb + 1 < n && s[pb + 1] == '.' && pb + 2 <= gb)
			{
				pb += 2;
			}
			else if (s[pb] == '.')
			{
				pb += 1;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
 
inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
 
char ch[10001];
 
int main()
{
	scanf("%s",ch+1);
	for ( int i=1;i<=strlen(ch+1);i++ )
		if(ch[i]=='7') 
			return printf("Yes\n"),0;
	printf("No\n");
	return 0;
}

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

typedef long long ll;

using namespace std;

int main(){

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=a*c;
    ans=max(a*d,max(b*c,max(b*d,ans)));

    cout<<ans<<endl;
   
    
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<ll> data;

  UnionFind(ll n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  ll root(ll x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(ll x, ll y){
    ll rx=root(x);
    ll ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(ll x, ll y){
    return root(x)==root(y);
  }

  ll size(ll x){
    return -data[root(x)];
  }
};

int main(){
  ll n, m;cin>>n>>m;
  vector<ll> a(m), b(m);
  rep(i, m)cin>>a[i]>>b[i];
  UnionFind uf(n);
  ll unc=n*(n-1)/2;
  vector<ll>results;
  rrep(i, m){
    results.push_back(unc);
    if(!uf.same(a[i], b[i])){
      unc -= (ll)uf.size(a[i])*(ll)uf.size(b[i]);
      uf.unite(a[i], b[i]);
    }
  }
  rrep(i, m)cout<<results[i]<<endl;

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N, M; cin >> N >> M;
	vector<set<int>> vs(N);
	vector<int> P(M), Y(M);
	for(int i = 0; i < M; i++) {
		cin >> P[i] >> Y[i];
		P[i]--;
		vs[P[i]].insert(Y[i]);
	}
	map<pair<int, int>, int> m;
	for(int i = 0; i < N; i++) {
		int rank = 1;
		for(auto u: vs[i]) {
			pair<int, int> p = make_pair(i + 1, u);
			m[p] = rank;
			rank++;
		}
	}
	for(int i = 0; i < M; i++) {
		P[i]++;
		string S = to_string(P[i]);
		reverse(S.begin(), S.end());
		while(S.size() < 6) S += "0";
		reverse(S.begin(), S.end());
		pair<int, int> q = make_pair(P[i], Y[i]);
		string T = to_string(m[q]);
		reverse(T.begin(), T.end());
		while(T.size() < 6) T += "0";
		reverse(T.begin(), T.end());
		cout << S + T << endl;
	}
	return 0;
}


Measured memory_bytes: 19636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll s;
int a, b, c, d;

int main() {
	scanf("%lld", &s);
	// 定一顶点在(0, 0), 构造向量(a, b)和(c, d)
	// 叉积求面积: s = ad - bc
	a = d = (int)sqrt(s);
	while(s > 1ll * a * d) {
		if(a < d) a++;
		else d++;
	}
	ll chk = 1ll * a * d - s;
	for(int i = 1; i <= sqrt(chk); i++) {
		if(!(chk % i)) {
			if(i <= 1e9 && chk / i <= 1e9) {
				b = i;
				c = chk / i;
				break;
			}
		}
	}
	printf("0 0 %d %d %d %d\n", a, b, c, d);
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
  	if (s[i] != t[i]) ans += 1;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N,M,K;
    cin>>N>>M>>K;
    COMinit(N,MODA);
    ll sum=0;
    rep(i,K+1){
        ll x=(M*powerup(M-1,N-1-i,MODA))%MODA;
        x=COM(N-1,i,MODA)*x%MODA;
        sum=(sum+x)%MODA;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    string t = s;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == '0' && s[i + 1] == '0')
            s[i + 1] = '1';
        if (s[i] == '1' && s[i + 1] == '1')
            s[i + 1] = '0';
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] != t[i])
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
  int n;
  int a[100001];
  int b;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> b;
    a[i]=b-1;
  }
  int k=0;
  int cnt=0;
  bool flag = true;
  bool c[100001]={false};

while(flag){
  if(c[a[k]]){
    cout << "-1" << endl;
      return 0;
    }
  else if(a[k]!=1){
    c[a[k]]=true;
    k = a[k];
    cnt++;
  }else if(a[k]==1){
    cout << cnt+1 << endl;
    return 0;
  }
  }
}


Measured memory_bytes: 768
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


vector<int>list(200005, 0);

signed main() {
	int n, m;
	double sum = 0;
	vector<double>list;

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		double num;
		cin >> num;
		sum += num;
		list.push_back(num);
	}

	double boda = sum / (4 * m), cnt = 0;

	for (int i = 0; i < n; i++) {
		if (boda > list[i]) {

		}
		else {
			cnt++;
		}
	}

	if (cnt >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N;
    cin >> N;
    vector<ll> H(N);
    ll pre = -INF_I;
    rep(i, N) cin >> H[i];
    //
    --H[0];
    rep(i, N-1)
    {
        if (H[i] < H[i + 1])
        {
            --H[i+1];
        }
    }
    bool okay = true;
    rep(i, N - 1)
    {
        if (H[i] > H[i + 1])
        {
            okay = false;
        }
    }
    yes(okay);
    //
    return 0;
}

Measured memory_bytes: 3960
l=[0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
for i in range(int(input()),0,-1):
  if l[i]==1:print(i);break

Measured memory_bytes: 9696
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define ANS(ans) cout<<(ans)<<endl




int main() {

	string s2, t;
	cin >> s2 >> t;
	int ns = s2.size();
	int nt = t.size();
	string s;
	

	for (int i = ns - nt; i >= 0; i--) {
		int flag = 0;
		s = s2;
		REP(j, nt) {
			if (s2[i + j] == '?' || s2[i + j] == t[j]) {
				s[i + j] = t[j];
				flag++;
			}
			else {
				break;
			}
		}
		if (flag == nt) {
			REP(k, ns) {
				if (s[k] == '?') {
					s[k] = 'a';
				}
			}
			ANS(s);
			return 0;
		}
	}
	ANS("UNRESTORABLE");
	return 0;



	


	
}



Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())
def func(i: int, a: int, b: int, c: int):
    if i == K:
        return (a < b and b < c)
    if func(i + 1, a * 2, b, c):
        return True
    if func(i + 1, a, b * 2, c):
        return True
    if func(i + 1, a, b, c * 2):
        return True
    return False
    
if func(0, A, B, C):
    print('Yes')
else:
    print('No')

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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  
  int sum1 = a+b;
  int sum2 = b+c;
  int sum3 = c+a;
  
  int ans = min({sum1,sum2,sum3});
  
  cout <<ans<< endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [0 for _ in range(N+2)]
for i in range(N+1):
    B[i+1] = B[i]+A[i]
dp = [[0 for _ in range(N+2)] for _ in range(N+2)]
for i in range(N):
    dp[i][i+2] = A[i]+A[i+1]
for k in range(3,N+1):
    for i in range(1,N-k+2):
        dp[i][i+k] = dp[i][i+1]+dp[i+1][i+k]
        for j in range(i+2,i+k):
            dp[i][i+k] = min(dp[i][i+k],dp[i][j]+dp[j][i+k])
        dp[i][i+k] += B[i+k]-B[i]
print(dp[1][N+1])

Measured memory_bytes: 43964
s = int(input())
a = []
a.append(0)
a.append(s)
i = 1
k = 0
while k == 0:
    if a[i] % 2 == 0:
        a.append(a[i] / 2)
    else:
        a.append(3 * a[i] + 1)
    i += 1
    for j in range(1, i):
        if a[j] == a[i]:
            print(i)
            k = 1
            break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
int a[105];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]%2==0)
        {
            if(!(a[i]%3==0||a[i]%5==0))
            {
                cout<<"DENIED";
                return 0;
            }
        }
    }
    cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include <stack>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

int main() {
	string oper;
	string tree_1,tree_2;
	while (cin >> oper >> tree_1 >> tree_2) {
		vector<char> result;
		stack<char> balance;
		if (oper == "i") { // intersection
			auto itr_1 = tree_1.begin();
			auto itr_2 = tree_2.begin();
			while (itr_1 != tree_1.end()) {
				if ((*itr_1 == ',' || *itr_1 == ')') && *itr_2 == '(') {
					result.push_back(*itr_1);
					balance.push('(');
					++itr_2;
					while (!balance.empty()) {
						if (*itr_2 == '(') {
							balance.push('(');
						}
						else if (*itr_2 == ')') {
							balance.pop();
						}
						++itr_2;
					}
				}
				else if (*itr_1 == '(' && (*itr_2 == ',' || *itr_2 == ')')) {
					result.push_back(*itr_2);
					balance.push('(');
					++itr_1;
					while (!balance.empty()) {
						if (*itr_1 == '(') {
							balance.push('(');
						}
						else if (*itr_1 == ')') {
							balance.pop();
						}
						++itr_1;
					}
				}
				else { // *itr_1 == *itr_2
					result.push_back(*itr_1);
				}
				++itr_1;
				++itr_2;
			}
		}
		else { // union
			auto itr_1 = tree_1.begin();
			auto itr_2 = tree_2.begin();
			while (itr_1 != tree_1.end()) {
				if ((*itr_1 == ',' || *itr_1 == ')') && *itr_2 == '(') {
					result.push_back('(');
					balance.push('(');
					++itr_2;
					while (!balance.empty()) {
						result.push_back(*itr_2);
						if (*itr_2 == '(') {
							balance.push('(');
						}
						else if (*itr_2 == ')') {
							balance.pop();
						}
						++itr_2;
					}
					result.push_back(*itr_1);
				}
				else if (*itr_1 == '(' && (*itr_2 == ',' || *itr_2 == ')')) {
					result.push_back('(');
					balance.push('(');
					++itr_1;
					while (!balance.empty()) {
						result.push_back(*itr_1);
						if (*itr_1 == '(') {
							balance.push('(');
						}
						else if (*itr_1 == ')') {
							balance.pop();
						}
						++itr_1;
					}
					result.push_back(*itr_2);
				}
				else { // *itr_1 == *itr_2
					result.push_back(*itr_1);
				}
				++itr_1;
				++itr_2;
			}
		}
		for (auto itr = result.begin();itr != result.end();++itr) {
			cout << *itr;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3048
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var array = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = array[0];
        var M = (int)array[1];
        var scores = new List<Score>();
        for (int i = 0; i < N; i++)
        {
            var line = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var s = new Score(line[0], line[1], line[2]);
            scores.Add(s);
        }
        var values = new List<long>();
        values.Add(scores.Select(x => x.Sum(true, true, true)).OrderByDescending(x=>x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(true, true, false)).OrderByDescending(x=>x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(true, false, true)).OrderByDescending(x => x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(true, false, false)).OrderByDescending(x => x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(false, true, true)).OrderByDescending(x => x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(false, true, false)).OrderByDescending(x => x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(false, false, true)).OrderByDescending(x => x).Take(M).Sum());
        values.Add(scores.Select(x => x.Sum(false, false, false)).OrderByDescending(x => x).Take(M).Sum());
        WriteLine(values.Max());
    }
    public struct Score
    {
        public Score(long x, long y, long z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public long X, Y, Z;
        public long Sum(bool x, bool y, bool z)
        {
            return (x?X:-X) + (y ? Y : -Y) + (z ? Z : -Z);
        }
    }
}


Measured memory_bytes: 13536
#include <iostream>
using namespace std;
int n,i,a[100002],b,c,m,j;
int main(){
  for(cin>>n;i<n;i++){
    cin>>b>>c;
    for(j=b;j<=c;j++)a[j]++;
  }
  for(i=0;i<n+2;i++)if(a[i]+1>=i)m=i;
  cout<<m-1<<endl;
}

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

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N, "");
    for (int i = 0; i < N; ++i){
        cin >> S[i];
    }

    sort(S.begin(), S.end());
    for (int i = 0; i < N; ++i){
        cout << S[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

struct FL
{
	int first, last;
};

int main()
{
	int N, Q;
	std::string s;
	std::vector<std::pair<char, char>> td;

	std::deque<FL> fallpos; // 最終的に落下するゴーレムの現在位置の範囲

	std::cin >> N >> Q;
	std::cin >> s;
	for (int i = 0; i < Q; ++i) {
		std::string t, d;
		std::cin >> t >> d;
		td.push_back({t[0], d[0]});
	}

	for (int q = Q-1; q >= 0; --q) {
		std::deque<FL> nextfallpos;
		char t = td[q].first;
		char d = td[q].second;
		if (d == 'L') {
			if (s[0] == t)
				nextfallpos.push_back({0, 1});
			for (auto it = fallpos.begin(), end = fallpos.end(); it != end; ++it) {
				auto pos = *it;
				if (s[pos.first] == t)
					++pos.first;
				if (pos.last < N && s[pos.last] == t)
					++pos.last;
				if (!nextfallpos.empty() && nextfallpos.rbegin()->last == pos.first)
					nextfallpos.rbegin()->last = pos.last;
				else
					nextfallpos.push_back(pos);
			}
		} else {
			if (s[N-1] == t) {
				nextfallpos.push_front({N-1, N});
			}
			for (auto it = fallpos.rbegin(), end = fallpos.rend(); it != end; ++it) {
				auto pos = *it;
				if (s[pos.last-1] == t)
					--pos.last;
				if (pos.first > 0 && s[pos.first-1] == t)
					--pos.first;
				if (!nextfallpos.empty() && nextfallpos.begin()->first == pos.last)
					nextfallpos.begin()->first = pos.first;
				else
					nextfallpos.push_front(pos);
			}
		}
		fallpos = std::move(nextfallpos);
	}

	int fallen = 0;
	for (auto& pos: fallpos) {
		fallen += pos.last - pos.first;
	}
	std::cout << (N-fallen) << "\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
int SosuIndex[100];
int Soinsu[100];
int c=1;
void Sosu(int N){
    int b=0;
    for(int n=3;n<=N;n++){
        b=0;
        for(int i=0;i<c;i++){
            if(n%SosuIndex[i]==0)b++;
        }
        if(b==0){SosuIndex[c]=n;c++;}
    }
}
int main(void){
    SosuIndex[0]=2;
    long N,cou1=0,cou2=0,x=0,y=0,z=0,q=0;
    scanf("%ld",&N);
    Sosu(N);
    for(int i=0;i<100;i++){Soinsu[i]=0;}
    for(int i=0;i<c;i++){
        for(int j=2;j<=N;j++){
            int J=j;
            while(J%SosuIndex[i]==0 && J!=0){
                Soinsu[i]++;
                J/=SosuIndex[i];
            }
        }
    }
    for(int i=0;i<c;i++){
        if(Soinsu[i]>=14)cou1++;
        if(Soinsu[i]<14 && Soinsu[i]>=4)cou2++;
    }
    if(cou1>=2 || (cou1>=1 && cou2>=1))
        x=cou2*cou1+(cou1)*(cou1-1);
    cou1=0;cou2=0;
    
    for(int i=0;i<c;i++){
        if(Soinsu[i]>=24)cou1++;
        if(Soinsu[i]<24 && Soinsu[i]>=2)cou2++;
    }
    if(cou1>=2 || (cou1>=1 && cou2>=1))
        y=cou2*cou1+(cou1)*(cou1-1);
    cou1=0;cou2=0;
    
    for(int i=0;i<c;i++){if(Soinsu[i]>=74)cou1++;}
    z=cou1;
    cou1=0;cou2=0;
    
    for(int i=0;i<c;i++){
        if(Soinsu[i]>=4)cou1++;
        if(Soinsu[i]<4 && Soinsu[i]>=2)cou2++;
    }
    if(cou1>=3 || (cou1>=2 && cou2>=1))
        q=cou2*(cou1)*(cou1-1)/2+(cou1)*(cou1-1)*(cou1-2)/2;
    cou1=0;cou2=0;
    
    long p=x+y+z+q;
    printf("%ld\n",p);
    return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
   string s;cin>>s;
   ll re=s.size();
   REP(i,s.size())
   {
       if(s[i]==s[i+1])
       {
           re--;
           i+=2;
       }
   }
   cout<<re<<endl;
}

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


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef priority_queue<ll> pqmaxi;  //push(xx) top->maxi,pop();
const int mod=1e9+7;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> TP;
typedef pair<int,ll> pll;
typedef pair<ll,pll> edge;
template<class T> inline bool chmin(T& a,T b){if(a>b){ a=b; return 1;} return 0;}
const ll maxi=1ll<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,s;cin>>n>>m>>s;
  vector<vector<edge>> g(n,vector<edge>());
  for(int i=0;i<m;i++){
    ll u,v,a,b;cin>>u>>v>>a>>b;
    --u;--v;
    g[u].push_back(edge(v,pll(a,b)));
    g[v].push_back(edge(u,pll(a,b)));
  }
  vector<ll> c(n),d(n);
  rep(i,n) cin>>c[i]>>d[i];
  if(s>2500)s=2500;
  vector<vector<ll>> dp(n,vector<ll>(2501,maxi));
  priority_queue<pair<ll,pll>,vector<pair<ll,pll>>,greater<pair<ll,pll>>> que;
  dp[0][s]=0;
  que.push(make_pair(0,pll(0,s)));
  while(!que.empty()){
    auto p=que.top();que.pop();
    ll time=p.first;
    int v=p.second.first;
    ll s=p.second.second;
    if(time>dp[v][s])continue;
    if(s+c[v]<=2500){
      ll ns=s+c[v];
      ll ntime =time+d[v];
      if(chmin(dp[v][ns],ntime))que.push(make_pair(ntime,pll(v,ns)));
    }
    for(auto e:g[v]){
      if(s<e.second.first)continue;
      int nv=e.first;
      ll ns=s-e.second.first;
      ll ntime=time+e.second.second;
      if(chmin(dp[nv][ns],ntime))que.push(make_pair(ntime,pll(nv,ns)));
    }
  }
  for(int v=1;v<n;v++){
    ll res=maxi;
    for(int s=0;s<=2500;s++)chmin(res,dp[v][s]);
    cout<<res<<endl;
  }
  return 0;
  }


Measured memory_bytes: 7252
#include "bits/stdc++.h"

#define MOD 1000000007
#define pb push_back
#define all(v) (v.begin(), v.end());
#define ff first
#define ss second
#define db(x) cerr << #x << " = "  << x << '\n'
#define ooo cerr << "---------------------\n"

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> iil;

void goooooo()
{
	int x;
	cin >> x;
	if(x == 1)
		cout << "Hello World";
	else
	{
		int l, r;
		cin >> l >> r;
		cout << l + r << '\n';
	}
}

int main()
{
	int abcdefghijklmnopqrstuvwxyz = 1;
//	cin >> abcdefghijklmnopqrstuvwxyz;
	for(;abcdefghijklmnopqrstuvwxyz;abcdefghijklmnopqrstuvwxyz --)
		goooooo();
	getchar();
	getchar();
}

Measured memory_bytes: 256
// (N * (L + (L + N - 1))) / 2
// (N * (2 * L + N - 1)) / 2
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int N, L;
        N = Integer.parseInt (arr[0]);
        L = Integer.parseInt (arr[1]);
        int ans = (N * (2 * L + N - 1)) / 2;
        if (0 < L)
            ans -= L;
        else if (L + N - 1 < 0)
            ans -= L + N - 1;
        System.out.println (ans);
        return;
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N, A, B;
	cin >> N >> A >> B;
	vector<int32> res;
	int32 now = N;
	while(N >= A){
		res.push_back(A);
		N-=A;
	}
	if(N)
		res.push_back(N);
	if(res[0] < A || res.size() > B || now-res[0]+1 < B){
		cout << -1 << endl;
		return 0;
	}
	int32 in = res.size()-1;
	while(res.size() < B){
		if(res.size()+res[in]-1 <= B){
			REP(i, res[in]-1)
				res.push_back(1);
			res[in] = 1;
		}else{
			int32 cnt = B-res.size();
			res[in] -= B-res.size();
			REP(i, cnt){
				res.push_back(1);
			}
		}
		in--;
	}
	REP(i, res.size()){
		now -= res[i];
		FOR(j, 1, res[i]+1){
			cout << now+j << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 3568
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#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 <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

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

    int n;
    cin >> n;
    LL res_t, res_a;
    cin >> res_t >> res_a;

    for( int i = 1; i < n; ++i ) {
        LL t, a;
        cin >> t >> a;

        LL tmp_t, tmp_a;
        tmp_t = ( res_t + t - 1 ) / t;
        tmp_a = ( res_a + a - 1 ) / a;
        if( tmp_t < tmp_a ) {
            res_t = tmp_a * t;
            res_a = tmp_a * a;

        } else {
            res_t = tmp_t * t;
            res_a = tmp_t * a;

        }
    }
    cout << res_t + res_a << endl;
    return 0;
}



Measured memory_bytes: 256
N = gets.to_i
xx, yy, tt = 0, 0, 0
N.times do
    t, x, y = gets.split.map(&:to_i)
    d = (x - xx).abs + (y - yy).abs
    dt = (t - tt)
    if d <= dt && d % 2 == dt % 2
        xx, yy, tt = x, y, t
    else
        puts 'No'
        exit
    end
end
puts 'Yes'

Measured memory_bytes: 1788
#include<stdio.h>

int main()
{
	int N;
	int A[200000];
	int i, j;
	int tmp, max, min;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	max = A[1] - A[0];
	min = A[0];
	for (i = 1; i < N; i++) {
		tmp = A[i] - min;
		max = tmp > max ? tmp : max;
		min = min < A[i] ? min : A[i];
	}

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

	return 0;
}


Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
int S;
int main(void){
    IN(N)
    FT(1,N+1)S+=to_string(k).size()%2;
    printf("%d\n",S);
    return 0;
}


Measured memory_bytes: 256
// AOJ 0551
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<functional>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

typedef pair<int,int> P;

const int NMAX = 1e5 + 8;
int N, L, ice[NMAX], ans[NMAX];
vector<P> table;

int solve() {
  sort(table.begin(), table.end(), greater<pair<int,int> >());
  for (int x = 0; x < N; x++) {
    int i = table[x].second;
    ans[i] = max(ans[i-1], ans[i+1]) + (L - ice[i]);
  }

  int a = 0;
  for (int i = 1; i <= N; i++) {
    a = max(a, ans[i]);
  }

  return a;
}

int main() {
  cin >> N >> L;
  for (int i = 1; i <= N; i++) {
    cin >> ice[i];
    table.push_back(P(ice[i], i));
  }

  cout << solve() << endl;
}

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

int main(void)
{
    int a,i,count = 0,we = 0;
    char b[100];
    scanf("%d%s",&a,b);
    for (i = 0; i < strlen(b); i++) {
        if (b[i] == 'I') {
            count++;
        }else{
            count--;
        }
        if (we < count) {
            we = count;
        }
    }
    printf("%d\n",we);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<math.h>

using namespace std;


int main()
{
	
	int K,N;
	cin >> N >> K;
	int p[N];
	for(int i = 0; i < N; i++){
		cin >> p[i];
	}
	
	sort(p, p + N);	
	
	int ans = 0;
	for(int i = 0; i < K; i++){
		ans += p[i];
	}
	
	cout << ans << endl;
	return 0;

}

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

int main() {
    int N;
    cin >> N;
    int T;
    int A;
    cin >> T >> A;
    int H[1000];
    for(int i = 0; i < N ; i++) {
        cin >> H[i];
    }
    double min = 100000;
    int result = 1;
    for(int i = 0; i < N; i++) {
        if(min > abs(A - (T - 0.006*H[i]))) {
            min = abs(A - (T - 0.006*H[i]));
            result = i + 1;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
s = list(input())

if s[k-1] == 'A': s[k-1] = 'a'
elif s[k-1] == 'B': s[k-1] = 'b'
elif s[k-1] == 'C': s[k-1] = 'c'

for i in range(n):
    print(s[i], end='')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
   int main()
{
    int n,t=0,f=0;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        t++;
        if(a[f]==2)
            break;
        else
            f=a[f]-1;
    }
    if(t<n)cout<<t;
    else cout<<-1;
    return 0;
   }

Measured memory_bytes: 4024
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int m = Integer.parseInt(sc.next());

            List<Integer> rei = new ArrayList<>();
            List<Integer> ren = new ArrayList<>();

            for(int i = 0; i < a; i++){
                rei.add(Integer.parseInt(sc.next()));
            }

            for(int i = 0; i < b; i++){
                ren.add(Integer.parseInt(sc.next()));
            }

            int min = Collections.min(rei) + Collections.min(ren);

            for(int i = 0; i < m; i++){
                int sum = 0;
                sum += rei.get(Integer.parseInt(sc.next()) - 1); 
                sum += ren.get(Integer.parseInt(sc.next()) - 1);
                sum -= Integer.parseInt(sc.next());
                if(sum < min) min = sum;
            }

            System.out.println(min);
            

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 97320
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll Rec(ll i);

vector <ll> Edges[100100];

ll Dp[100100];

int main()
{
    memset(Dp,-1,sizeof(Dp));

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

    while(m--)
    {
        ll x,y; scanf("%I64d%I64d",&x,&y);

        Edges[x].push_back(y);
    }

    ll Max = 0;

    for(ll i=1;i<=n;i++)    Max = max( Max , Rec(i) );

    cout<<Max;
}

ll Rec(ll i)
{
    if(Dp[i]+1) return Dp[i];

    ll Res = 0;

    for(ll j=0;j<Edges[i].size();j++)   Res = max( Res , 1 + Rec(Edges[i][j]) );

    return Dp[i] = Res;
}


Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define rel(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
	int R,G,B,N,ans=0,tmp;
	int i=0,j=0,k=0;
	
	cin >> R >> G >> B >> N;

	rep(i,0,(N/R)){
		rep(j,0,(N/G)){
				if((N-i*R-j*G)%B==0 && 0 <= (N-i*R-j*G)/B && (N-i*R-j*G)/B <= N/B){
					ans++;
				}
		}
	}

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int d[N],f[N],color[N],time;

int n,M[N][N];
int color[N],d[N],f[N],time;

void dfs(void);
void visit(int u);

int main()
{
  int u,v,k,i,j;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = 0;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

void dfs()
{
  int u;
  for(u = 0;u < n;u++) color[u] = WHITE;
  time = 0;

  for(u = 0;u < n;u++){
    if(color[u] == WHITE) visit(u);
  }
  for(u = 0;u < n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

void visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v = 0;v < n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}
    
      
  



Measured memory_bytes: 2148
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using namespace std;

int pow_mod(int a, int b, int p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

int factorial_mod(int a, int p) {
	if (!a)return 1;
	else return a * factorial_mod(a - 1, p) % p;
}

int sum_digit(int N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

int N;

int main(){
	scanf("%d", &N);
	int sum = sum_digit(N);
	if (N%sum == 0)printf("Yes");
	else printf("No");
	return 0;
}

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

double det(double a, double b, double c, double d, double e, double f, double g, double h, double i){
	double delta;
	double m[3][3] = {{a, b, c},{d, e, f},{g, h, i}};
	delta = m[0][0]*m[1][1]*m[2][2];
	delta += m[2][0]*m[0][1]*m[1][2];
	delta += m[0][2]*m[1][0]*m[2][1];
	delta -= m[0][2]*m[1][1]*m[2][0];
	delta -= m[0][0]*m[1][2]*m[2][1];
	delta -= m[2][2]*m[0][1]*m[1][0];
	return delta;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		double x1, y1, x2, y2, x3, y3, x, y, r;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double d0 = det(x1, y1, 1, x2, y2, 1, x3, y3, 1);
		double d1 = det((-((x1*x1)+(y1*y1))), y1, 1, (-((x2*x2)+(y2*y2))), y2, 1, (-((x3*x3)+(y3*y3))), y3, 1);
		double d2 = det(x1, (-((x1*x1)+(y1*y1))), 1, x2, (-((x2*x2)+(y2*y2))), 1, x3, (-((x3*x3)+(y3*y3))), 1);
		double d3 = det(x1, y1, (-((x1*x1)+(y1*y1))), x2, y2, (-((x2*x2)+(y2*y2))), x3, y3, (-((x3*x3)+(y3*y3))));
		double l, m, n;
		l = d1 / d0;
		m = d2 / d0;
		n = d3 / d0;
		x = -(l / 2);
		y = -(m / 2);
		r = sqrt((l*l + m*m - (4*n)) / 4);
		printf("%.3f %.3f %.3f\n", x, y, r);
	}
	return 0;
}

Measured memory_bytes: 1240
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())

d = defaultdict(lambda : defaultdict(int))

for i in range(3):
    s = list(input())
    for j in range(n):
        d[j][s[j]] += 1
ans = 0
for i in range(n):
    mx = max(d[i], key=d[i].get)
    for j in d[i]:
        if mx != j:
            ans += d[i][j]
print(ans)

Measured memory_bytes: 7744
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) a[i] = sc.nextInt();
		int DP[] = new int[n];
		DP[0] = 0;
		DP[1] = Math.abs(a[0] - a[1]);
		for (int i = 2; i < n; i++) {
			DP[i] = Math.min(DP[i - 1] + Math.abs(a[i] - a[i - 1]), DP[i - 2] + Math.abs(a[i] - a[i - 2]));
		}
		System.out.print(DP[n - 1]);
	}

}


Measured memory_bytes: 50224
#include <iostream>

using namespace std;

class Insertionsort
{
 public:
  void solve( int n, int a[] );
};

void Insertionsort::solve( int n, int a[] )
{
  int key;
  
  for( int i = 0; i < n - 1; i++ )
    {
      cout << a[i] << " ";
    }
  cout << a[n-1] << endl;
      
  for( int j = 1; j < n; j++ )
    {
      key = a[j];
      int k = j - 1;
      while((k >= 0) && (a[k] > key))
        {
          a[k+1] = a[k];
          k--;
        }
      a[k+1] = key;
        
      for( int i = 0; i < n - 1; i++ )
        {
          cout << a[i] << " ";
        }
      cout << a[n-1] << endl;
    }
  
}

int main( void )
{
  int n;
  int a[100];

  Insertionsort *InsertionSort = new Insertionsort();

  cin >> n;
  for( int i = 0; i < n; i++ )
    {
      cin >> a[i];
    }
  
  InsertionSort -> solve( n, a );

  delete InsertionSort;

  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  //全てのマスの情報を格納する配列
  //黒#の場所を0とする。
  //スタート地点としてキューに入れる。
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int, int>> q;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        dist[i][j] = 0;
        pair<int, int> p;
        p.first = i;
        p.second = j;
        q.push(p);
      }
    }
  }

  //黒#から各白.への移動距離を求める
  //黒からの移動は(x,y)が(+1,0)(-1,0)(0,+1)(0,-1)の4方向
  vector<int> x(4), y(4);
  x = {1, -1, 0, 0};
  y = {0, 0, 1, -1};
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (int xy = 0; xy < 4; xy++) {
      int i = p.first + x[xy];
      int j = p.second + y[xy];
      //負座標および、マスを超える座標は存在しないので飛ばす。
      if (i < 0 || j < 0 || i >= h || j >= w) continue;
      //距離既知の場合も飛ばす。
      if (dist[i][j] != -1) continue;
      //初場所なら移動距離を格納する。移動前から+1
      dist[i][j] = dist[p.first][p.second] + 1;
      //移動し、記録した座標をキューに入れる。
      pair<int,int> pp;
      pp.first = i;
      pp.second = j;
      q.push(pp);
    }
  }
  int ans = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 13456
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

#define ll long long

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
vector<P> connect[100005];
long long cost[100005];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N, W;
	cin >> N >> W;

	vector<int> v0[4];
	ll w1 = 0;
	for (int i = 0; i < N;++i) {
		int w, v;
		cin >> w >> v;
		if (i == 0)w1 = w;
		w -= w1;
		v0[w].emplace_back(v);
	}

	for (int i = 0; i < 4;++i) {
		sort(v0[i].begin(), v0[i].end());
		v0[i].emplace_back(0);
		reverse(v0[i].begin(), v0[i].end());
		for (int j = 1; j < v0[i].size();++j) {
			v0[i][j] += v0[i][j - 1];
		}
	}

	int ans = 0;
	for (ll i = 0; i < v0[0].size();++i ) {
		for (ll j = 0; j < v0[1].size(); ++j) {
			for (ll k = 0; k < v0[2].size(); ++k) {
				for (ll l = 0; l < v0[3].size(); ++l) {
					if((w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l) <= W){
						ans = max(ans, (v0[0][i] + v0[1][j] + v0[2][k] + v0[3][l]));
					}
				}
			}
		}
	}
	cout << ans << endl;
}

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

//順列を入力し、条件を満たす数を計算するクラス
class OrdinaryNumber{
    vector<int> seq;
    int quantity;
    void func0();
    void func1(vector<int> vec);
public:
    OrdinaryNumber(vector<int> seq0);
    void print();
};

OrdinaryNumber::OrdinaryNumber(vector<int> seq0){
    seq = seq0;
    quantity = 0;
    func0();
}

//順列から3つの数字を取り出し、真ん中の数値が2番めに小さいか検証
void OrdinaryNumber::func0(){
    for(int i = 0; i < seq.size() - 2; i++){
        //順列からp_i-1, p_i, p_i+1を取り出す
        vector<int> seqof3;
        for(int j = 0; j < 3; j++){
            seqof3.push_back(seq[i + j]);
        }
        //p_i-1, p_i, p_i+1が条件を満たす場合はquantity++
        func1(seqof3);
    }
}

//p_i-1, p_i, p_i+1が条件を満たす場合はquantity++
void OrdinaryNumber::func1(vector<int> vec){
    //p_i-1, p_i, p_i+1を昇順にソートしたものを格納
    vector<int> sortedVec = vec;
    sort(sortedVec.begin(), sortedVec.end());
    //p_iとソートした順列の真ん中の数値を比較
    if(vec[1] == sortedVec[1]) {
        quantity++;
    }
}

//条件を満たす数を出力
void OrdinaryNumber::print(){
    cout << quantity << endl;
}

int main(void){
    int number; //順序の要素数
    vector<int> vec; //順序を格納する配列
    cin >> number; //要素数を入力
    
    //要素数に応じた回数分入力し、配列に要素を追加
    for(int i = 0; i < number; i++){
        int value;
        cin >> value;
        vec.push_back(value);
    }
    
    //順列を入力し、条件を満たす数を計算するクラス
    OrdinaryNumber ono(vec);
    //計算結果を出力
    ono.print();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N, K;
	int x[101];
	cin >> N >> K;
	REP(i, 0, N) cin >> x[i];

	int ans = 0;
	REP(i, 0, N) {
		ans += (2 * min(x[i], abs(K - x[i])));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from decimal import *
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print(math.ceil(h*w/2))


main()


Measured memory_bytes: 60140