akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 1e6 + 5;
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    a *= 60;
    a += b;
    c *= 60;
    c += d;
    c -= a;
    c -= e;
    cout << max(c,0) << '\n';
}

Measured memory_bytes: 3652
my ($n, $m) = split(/\s+/, <>);
my (@h) = (0, split(/\s+/, <>));
my (@op);
for (1..$n) { $op[$_] = []; }
for (1..$m) {
    my ($a, $b) = split(/\s+/, <>);
    push @{$op[$a]}, $b;
    push @{$op[$b]}, $a;
}

sub is_top {
    my ($i) = @_;
    my $is_top = 1;
    #print "i=$i, ", @{$op[$i]}, "\n";
    for (@{$op[$i]}) {
	#print "$_,";
	$is_top = 0 if ($h[$i] <= $h[$_]);
    }
    #print "\n";
    return $is_top;
}

my $num = 0;
for my $i (1..$n) {
    $num++ if is_top($i);
}
print $num, "\n";

Measured memory_bytes: 47388
#include <iostream>
#include <string>
#include <cassert>

char search_min_char(std::string const & s) {
  for (char const c : "abcdefghijklmnopqrstuvwxyz") {
    if (s.find(c) < s.size()) {
      continue;
    } else {
      return c;
    }
  }

  assert(false);
}

char carry(std::string const & s, char b) {
  while (s.find(b) < s.size()) b+=1;
  return b;
}

void judge_carry(std::string const & s, char c) {
  if (s == "z") {
    std::cout << "-1" << std::endl;
    return;
  } else {
    std::string const substr(s.substr(0, s.size()-1));
    char b(s.back());
    if (b < c) {
      std::cout << substr << carry(substr, b+1) << std::endl;
    } else {
      judge_carry(substr, b);
    }
  }
}

int main() {
  std::string S;

  std::cin >> S;

  if (S.size() < 26) {
    std::cout << S << search_min_char(S) << std::endl;
  } else {
    judge_carry(S.substr(0, S.size()-1), S.back());
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using ll_t = long long;
const int MAXN = 2000;
const int P = (int)1e9 + 7;

int a[MAXN];

ll_t solve(int n, int k) {
  int x = 0, y = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) ++x;
      else if (a[i] < a[j]) ++y;
    }
  }
  ll_t res = (ll_t)k * (k + 1) / 2 % P * x + 
             (ll_t)k * (k - 1) / 2 % P * y;
  return res % P;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  std::cout << solve(n, k) << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const LL INF=1<<30;
int s[7000][7000];

int main(){
    int n,m;cin >> n >> m;
    vector<int> x(n),y(n);
    vector<P> p;
    int ss=1000;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        p.pb({x[i],y[i]});
    }
    sort(ALL(x));
    sort(ALL(y));
    for (int i = 0; i < n; i++) {
        s[ss+lower_bound(ALL(x),p[i].fs)-x.begin()][ss+lower_bound(ALL(y),p[i].sc)-y.begin()]++;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            s[ss+j+1][ss+i]+=s[ss+j][ss+i];
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            s[ss+i][ss+j+1]+=s[ss+i][ss+j];
        }
    }
    for (int i = 0; i < m; i++) {
        int a,b,c,d;cin >> a >> b >> c >> d;
        a=lower_bound(ALL(x),a)-x.begin();
        b=lower_bound(ALL(y),b)-y.begin();
        c=upper_bound(ALL(x),c)-x.begin()-1;
        d=upper_bound(ALL(y),d)-y.begin()-1;
        cout << s[ss+c][ss+d]-s[ss+a-1][ss+d]-s[ss+c][ss+b-1]+s[ss+a-1][ss+b-1] << endl;
    }
    return 0;
}




Measured memory_bytes: 120944
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>

int main(int argc, char *argv[])
{
    int a, b;
    int ans = -1;

    std::cin >> a >> b;

    for (int x = 1; x < 10000; x++) {
        int c = x * 8 / 100;
        int d = x * 10 / 100;
        if (c == a && d == b) {
            ans = x;
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


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

	ull cnt = 0;

	while(a%2==0 && c%2==0  && b%2==0){
        ll d = a,e = b,f = c;
        
        a = e/2 + f/2;
        b = d/2 + f/2;
        c = d/2 + e/2;
        
        cnt++;
        if(cnt > 1000000){
            cout << -1 << endl;
            return 0;
        }
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
int1 = lambda x: int(x) - 1
N, A, B, C, D = map(int1, input().split())
S = input()

if "##" not in S[A:B+1] and "##" not in S[C:D+1]:
    if C > D and "..." not in S[B-1:D+2]:
        print("No")
    else:
        print("Yes")
else:
    print("No")


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define lar(a, b) ((a>b) ? (a):(b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    vector<p> cnt;
    p pir;
    pir = make_pair(-1, 0);
    cnt.push_back(pir);
    
    ll n, i, tmp, atmp, ans=0, tmp2;
    cin >> n;
    ll a[n];
    for(i=0; i<n; i++)
        cin >> a[i];
    sort(a, a+n);
    
    for(i=0; i<n; i++) {
        tmp=1;
        atmp=a[i];
        while(a[i]==a[i+1]) {
            tmp++;
            i++;
        }
        pir = make_pair(atmp, tmp);
        cnt.push_back(pir);
    }
    
    pir = make_pair(-1, 0);
    cnt.push_back(pir);
    
    for(i=1; i<cnt.size()-1; i++) {
        tmp2=cnt[i].second;
        if(cnt[i-1].first==cnt[i].first-1)
            tmp2+=cnt[i-1].second;
        if(cnt[i+1].first==cnt[i].first+1)
            tmp2+=cnt[i+1].second;
        
        ans = lar(ans, tmp2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int N;
  cin >> N;
  bool ans = 0;
  FOR(i,0,100)FOR(j,0,100)if(N == 4*i+7*j)ans = 1;
  cout << (ans ? "Yes" : "No") << endl;
}


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

int main(){
    double n;
    cin >> n;
    for (double i = 0; i < 50000;i++)
    {
        if(floor(i*1.08) == n)
        {
            cout << i;
            return 0;
        }
    }
    cout<<":(";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, m;
    cin >> n >> m;
    vs32 a(m), c(m, 0);
    int b;
    rep (i, m)
    {
        cin >> a[i] >> b;
        int temp;
        rep (j, b)
        {
            cin >> temp;
            --temp;
            c[i] |= 1 << temp;
        }
    }

    vector< vs32 > dp(m + 1, vs32(1 << n, 1e9));
    rep (i, m + 1) dp[i][0] = 0;

    rep (i, m)
    {
        rep (j, 1 << n)
        {
            dp[i + 1][j] = MIN(dp[i][j], dp[i][j & ~c[i]] + a[i]);
        }
    }

    int ans;
    if (dp[m][(1 << n) - 1] == 1e9)
    {
        ans = -1;
    }
    else
    {
        ans = dp[m][(1 << n) - 1];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 16384
def dist(a, b):
    return min(
        abs(a - b),
        abs(a - x) + 1 + abs(y - b),
        abs(a - y) + 1 + abs(x - b)
    )


n, x, y = map(int, input().split())
x -= 1
y -= 1

d = [0] * n

for j in range(n):
    for i in range(j):
        d[dist(i, j)] += 1

it = iter(d)
next(it)

print(*it, sep='\n')


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> as(n+1), bs(n);
    for (auto& a: as) {
        cin >> a;
    }
    for (auto& b: bs) {
        cin >> b;
    }
    long long total = 0;
    for (int i = n-1; i >= 0; --i) {
        long long first_attack = min(as[i+1], bs[i]);
        total += first_attack;
        as[i+1] -= first_attack;
        bs[i] -= first_attack;
        
        long long second_attack = min(as[i], bs[i]);
        total += second_attack;
        bs[i] -= second_attack;
        as[i] -= second_attack;
    }
    cout << total << endl;
    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n; cin >> n, n;){
        map<string, set<string> > s;

        string group1;
        rep(i, n){
            string in; cin >> in;

            int pos = in.find(':');
            string group = in.substr(0, pos++);
            if(!i) group1 = group;

            int z;
            while((z = in.find(',', pos)) != -1){
                string member = in.substr(pos, z - pos);
                s[group].insert(member);

                pos = z + 1;
            }
            s[group].insert(in.substr(pos, in.size() - 1 - pos));
        }

        rep(i, n){
            set<string> next = s[group1];
            each(itr, s[group1]){
                string mem = *itr;
                if(mem.size() > 20) continue;
                if(s.find(mem) != s.end()){
                    each(jtr, s[mem]){
                        next.insert(*jtr);
                    }
                    next.erase(mem);
                }
            }
            s[group1] = next;
        }

        cout << s[group1].size() << endl;
    }

	return 0;
}

Measured memory_bytes: 1420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
	int N, Y;
	cin >> N >> Y;
	int ans[3] = {-1, -1, -1};
	for(int i = 0; i <= N; i++){
		for(int j = 0; i+j <= N; j++){
			if(10000*i+5000*j+1000*(N-i-j) == Y){
				ans[0] = i;
				ans[1] = j;
				ans[2] = N-i-j;
				break;
			}
		}
		if(ans[0] != -1){
			break;
		}
	}
	cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n";
}


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

int n;
int a[10];


bool dfs(int i, int left, int right) {
    if (i == 9) return a[i] > left || a[i] > right;
    if (a[i] > left && dfs(i+1, a[i], right)) return true;
    if (a[i] > right && dfs(i+1, left, a[i])) return true;
    return false;
}

void solve() {
    if (dfs(0,0,0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}


Measured memory_bytes: 3020
#include <iostream>

using namespace std;

int main(void) {
  int N, M, T;
  int a[100] = {};
  cin >> N >> M >> T;

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

  int t_study = T - M;

  int diff = M;
  for(int j = 0; j < N-1; j++) {
    diff = a[j+1] - a[j];
    if(diff < 2*M) {
      t_study = t_study - diff;
    } else {
      t_study = t_study - 2*M;
    }
  }

  diff = T - a[N-1];
  if(diff < M) {
    t_study = t_study - diff;
  } else {
    t_study = t_study - M;
  }

  cout << t_study << '\n';

  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

double dp[301][301][301];

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

	vec_i v(4, 0);
	rep(i,n){
		int x;
		cin >> x;
		v[x]++;
	}

	rep(i,n+1) rep(j, n+1) rep(k, n+1) dp[i][j][k] = -1;
	dp[0][0][0] = 0;
	rep(i, n+1){
		rep(j, n+1){
			rep(k, n+1){
				double d = i + j + k;
				double next = n;
				if(d == 0)
					continue;
				if(i > 0)
					next += dp[i-1][j+1][k]*i;
				if(j > 0)
					next += dp[i][j-1][k+1]*j;
				if(k > 0)
					next += dp[i][j][k-1]*k;
				dp[i][j][k] = next/d;
			}
		}
	}
	cout << fixed << setprecision(12) << dp[v[3]][v[2]][v[1]] << endl;
}

Measured memory_bytes: 213248
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int n,m;cin>>n>>m;
  int k[10];vector<int> v[10];int p[10];
  rep(i,m){
    cin>>k[i];
    rep(j,k[i]){
      int s;cin>>s;v[i].push_back(s);
    }
  }
  rep(i,m)cin>>p[i];
  int ans = 0;
  rep(i,1<<n){
    bool counted = true;
    rep(j,m){
      int cnt = 0;  
      rep(l,k[j]){
        if(i & (1<<(v[j][l]-1)))cnt++;
      }
      //if(i == 3)cout << cnt << " " << p[j] << endl;
      if(cnt % 2 != p[j]){
        counted = false;break;
      }
    }
    if(counted)ans++;
  }
  cout << ans << endl;
}


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

bool f(int n) {
  int digit = 0;
  while (n) {
    n = n / 10;
    digit++;
  }

  return (digit % 2 == 1);
}

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (f(i)) { ans++; }
  }

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll num=a[0]-1;
    for(int i=1;i<n;i++){
    	if(a[i]<num){
    		cout << "No" <<endl;
    		return 0;
    	}else if(a[i]>num){
    		num=a[i]-1;
    	}
    }
    cout <<"Yes"<<endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,g; cin>>r>>g;
    cout<<g*2-r<<endl;
    return 0;
}


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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536


typedef long long ll;
typedef string str;

 
ll power (ll a, ll b){
    ll ans=1;
    while(b){
        if (b & 1) ans*=a;
        a*=a;
        b/=2;
    }
    return ans;
}

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

long long nCr(int n,int r){
    if(n==r) return 1;
    else if (r==0) return 1;
    else return nCr(n-1,r-1)+nCr(n-1,r);
}

int sdigit(int x){
    int ans=0;
    while(x){
        ans+=x%10;
        x/=10;
    }
    return ans;
}

int bs(int a[],int b,int l,int r){
    int mid=l + (r-l)/2;
    if(l>r) return -1;
    if(a[mid]==b||l==r)	return mid;
    if(a[mid]>b)	return bs(a,b,l,mid-1);
    else return bs(a,b,mid+1,r);
}

long long  gcd(int a,int b){
    if (b==0) return a;
    return gcd(b,a%b);
}

void solve(){ 
    int n;
    cin >> n;
    int dp[3]={0};
    int h[3];
    for (int i=0;i<n;i++){
        for (int j=0;j<3;j++){
            cin >> h[j];
        }
        for (int j=0;j<3;j++){
            h[j]+=max(dp[(j+1)%3],dp[(j+2)%3]);
        }
        for (int j=0;j<3;j++){
            dp[j]= h[j];
        }        
    }
    cout << max({dp[0],dp[1],dp[2]});

    
}     


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
    solve();
    }
}



Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int ans = 0;
    if (C <= A + B + 1) {
      ans = B + C;
    } else {
      ans = B + (A + B + 1);
    }
    System.out.println(ans);
  }
}

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

using Lint=long long;

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

        Lint ans=a[0]-1;
        int mx=1;
        for(int i=1;i<N;i++){
                if(a[i]%(mx+1)!=0){
                        ans+=a[i]/(mx+1);
                }else if(a[i]==mx+1){
                        mx=mx+1;
                }else{
                        ans+=1+(a[i]-(mx+2))/(mx+1);
                }
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int a, int b){
    return b==0 ? a : gcd(b, a%b);
}
int main(){
    int x,y;
    cin >> x >> y;
    cout << (x+1) + (y+1) - 1 - gcd(x,y) << endl;
}


Measured memory_bytes: 3096
n_str = input()
n_int = int(n_str)
# 1 ~ 50000
# 桁数が奇数= 1桁, 3桁, 5桁
# 1 ~ 9, 100 ~ 999,10000 ~ 99999の90909個しかないので全探索いけるか?
exs_list = []
for i in range(1, 100000):
    if len(str(i)) % 2 == 1:
        exs_list.append(i)

exs = {i: i for i in exs_list}

n_s = []
ans = 0
for i in range(1, n_int + 1):
    if len(str(i)) % 2 == 0:
        continue
    if i in exs:
        ans += 1

print(ans)







Measured memory_bytes: 51968
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		double x = 1;
		double h = 1;
		while(x!=0&&h!=0){
			x = Double.parseDouble(br.readLine());
			h = Double.parseDouble(br.readLine());
			double h2 = Math.sqrt((x/2)*(x/2)+h*h);
			System.out.println((x!=0)?x*x+ (h2*x)*2:"");
		}
	}
}

Measured memory_bytes: 16916
import math
N = int(input())
ans = [0]*(N+1)
owari = math.sqrt(N)
owari = math.ceil(owari)
for x in range(1, owari):
    a = x*x
    for y in range(1, owari):
        b = y*y
        c = x*y
        for z in range(1, owari):
            hantei = z*(z+x+y)+a+b+c
            if hantei > N:
                break
            ans[hantei] += 1

for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 9348
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace  std;

int main()
{
    int a;
    cin >> a;
    vector<int> b(a);
    for(int i = 0; i < a;i++)
    cin >> b[i];
    
    sort(b.begin(),b.end());
    
    int ans = 0;
    for(int i = 0;i<a-1;i++)
    ans += b[i];
    
    ans += b[a-1]/2;
    
    cout << ans << endl;
     
}


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

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3, y3, x4, y4;
	x3 = x2 - y2 + y1;
	y3 = y2 + x2 - x1;
	x4 = x3 - y3 + y2;
	y4 = y3 + x3 - x2;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll h,w,m;
 	cin>>h>>w>>m;
 	ll r[h+1]={0};
 	ll c[w+1]={0};
 	set<pll>tar;
 	set<pll>cols;
 	for(ll i=0;i<m;i++)
 	{
 		ll x,y;
 		cin>>x>>y;
 		tar.insert({x,y});
 		r[x]++;
 		c[y]++;
 	}
 	for(ll i=1;i<=w;i++)
 	{
 		if(c[i]>0)
 		{
 			cols.insert({-1LL*c[i],i});
 		}
 	}
	ll mx=0; 
 	for(ll i=1;i<=h;i++)
 	{
 		for(pll x:cols)
 		{
 			ll val = r[i]+x.first*-1LL;
 			if(val<mx)
 				break;
 			if(tar.find({i,x.second})!=tar.end())
 			{
 				val--;
 				mx=max(mx,val);
 			}
 			else
 			{
 				mx=max(mx,val);
 				break;
 			}
 		}
 	}
 	cout<<mx<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> coordinates(N);

    int P = 0;
    for(auto &coordinate : coordinates) {
        cin >> coordinate;
        P += coordinate;
    }
    P /= N;

    int answer_1 = 0, answer_2 = 0;
    for(auto coordinate : coordinates) {
        int tmp = coordinate - P;
        answer_1 += tmp*tmp;
        tmp -= 1;
        answer_2 += tmp*tmp;
    }

    cout << (answer_1 < answer_2 ? answer_1 : answer_2) << endl;

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int N;
 int H,W,a,b;
 int ans=0;
 cin>>N>>H>>W;
 for(int i=0; i<N; i++){
  cin>>a>>b;
  if(a-H>=0 && b-W>=0)ans++;
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
# 选择排序
def selection_sort(arr):
    swap_cnt = 0
    for i in range(0, len(arr)):
        min_index = i
        for j in range(i + 1, len(arr)):
            if arr[min_index] > arr[j]:
                min_index = j
        if min_index != i:
            arr[i], arr[min_index] = arr[min_index], arr[i]
            swap_cnt += 1
    return swap_cnt

if __name__ == '__main__':
    N = int(input())
    arr = list(map(int, input().split()))
    cnt = selection_sort(arr)
    print(' '.join(map(str, arr)))
    print(cnt)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X;
  int ans = 1;
  
  cin >> N >> X;
  vector<int> l(N);
  
  for (int i = 0; i < N; ++i) {
    cin >> l[i];
  }

  int p = 0;
  for(int i = 0; i < N; ++i){
    p += l[i];
    if (p <= X) ++ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
class BiOp {
public:
	P operator()(P a, P b) const {
		return min(a, b);
	}
};

template<typename T, typename BiOp>
struct SegmentTree {
	vector<T> data;
	T e;
	BiOp op;
	int size;

	SegmentTree(int n, T e, BiOp op) : e(e), op(op) {
		size = 1;
		while (size < n) size *= 2;
		data.resize(2 * size - 1);
		for (int i = 0; i < 2 * size - 1; i++) data[i] = e;
	}

	void update(int k, T v) {
		k += size - 1;
		data[k] = v;
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = op(data[k * 2 + 1], data[k * 2 + 2]);
		}
	}

	T query(int a, int b, int k, int l, int r) const {
		if (b <= l || r <= a) return e;
		if (a <= l && r <= b) return data[k];
		return op(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}

	T query(int a, int b) {
		return query(a, b, 0, 0, size);
	}

	T get(int i) {
		return data[i + size - 1];
	}
};
int main() {
	int N, M;
	cin >> N >> M;
	string S;
	cin >> S;
	SegmentTree<P, BiOp> seg(N + 1, P(1 << 30, -1), BiOp());
	seg.update(N, P(0, N));
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '1') continue;
		P e = seg.query(i + 1, min(i + M, N) + 1);
		seg.update(i, P(min(e.first + 1, 1LL << 30), i));
	}
	P e = seg.get(0);
	if (e.first == (1 << 30)) {
		cout << -1 << endl;
		return 0;
	}
	int pos = 0;
	while (pos < N) {
		P e = seg.query(pos + 1, min(pos + M, N) + 1);
		cout << e.second - pos << " ";
		pos = e.second;
	}
	cout << endl;
}


Measured memory_bytes: 4736
#include <stdio.h>

int main(int argc, char *argv[])
{
    for( int i = 0; i < 9; i++ ){
        for( int j = 0; j < 9; j++ ){
             printf("%dx%d=%d\n", i+1, j+1, (i+1) * (j+1) );
        }
    }
    return 0;
}

Measured memory_bytes: 2652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    ll l = 0, r = s.length()-1;
    while(true){
        if(r < l)break;
        if(s[l] == 'x'){l++; continue;}
        if(s[r] == 'x'){r--; continue;}
        if(s[l] == s[r]){
            l++; r--;
            continue;
        }else{
           // cout << s[l] << " " << s[r] << endl;
            cout << -1 << endl;
            return 0;
        }
    }
    ll cnt = 0;
    l = 0; r= s.length() -1;
    while(true){
        if(r <= l)break;
        if(s[l] == s[r]){
            l++; r--; continue;
        }else{
            cnt++;
            if(s[l] == 'x'){
                l++;
            }else{
                r--;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
def main():
    A,B,C = list(map(int, input().split(' ')))
    K = int(input())
    
    P=[A,B,C]
    for k in range(K):
        if not (P[1] >P[0]):
            P[1] = P[1] * 2
        elif not (P[2] >P[1]):
            P[2] = P[2] * 2
            
    if P[0] < P[1] < P[2]:
        print('Yes')
    else:
        print('No')
        
        
    
    

main()

Measured memory_bytes: 61760
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<61;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

map<ll, ll> mm;

ll f(ll n, ll a, ll b, ll c, ll d) {
	if (n == 0) return 0;
	auto it = mm.find(n);
	if (it != mm.end()) return it->se;
	
	ll res = longINF;
	if ((double)n * d < longINF) res = n * d;
	
	int pv[] = {2, 3, 5};
	ll cost[] = {a, b, c};
	for (int i = 0; i < 3; ++i) {
		for (int t = 0; t < 2; ++t) {
			ll nex = t == 0 ? n / pv[i] : (n + pv[i] - 1) / pv[i];
			if (n == nex) continue;
			ll pre = nex * pv[i];
			ll nc = abs(pre - n) * d + f(nex, a, b, c, d);
			if ((double)abs(pre - nex) * d + nc < longINF) chmin(res, abs(pre - nex) * d + nc);
			if ((double)cost[i] + nc < longINF) chmin(res, cost[i] + nc);
		}
	}
	
	return mm[n] = res;
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		mm.clear();
		ll N, A, B, C, D;
		cin >> N >> A >> B >> C >> D;
		cout << f(N, A, B, C, D) << endl;

	}
	return 0;
}


Measured memory_bytes: 4492
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

int main() {
	int n, r;
	scanf( "%d%d", &n, &r );
	if( n >= 10 )
		printf( "%d", r );
	else
		printf( "%d", r + 100 * ( 10 - n ) );
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int w[105],v[105];
int w1[105],w2[105],w3[105],w4[105];
int x1,x2,x3,x4;
int cnt1=1,cnt2=1,cnt3=1,cnt4=1;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,W;
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
		if(w[i]==w[0])
		{
			w1[cnt1++]=v[i];
		}
		if(w[i]==w[0]+1)
		{
			w2[cnt2++]=v[i];
		}
		if(w[i]==w[0]+2)
		{
			w3[cnt3++]=v[i];
		}
		if(w[i]==w[0]+3)
		{
			w4[cnt4++]=v[i];
		}
	}
	sort(w1+1,w1+cnt1,cmp);
	sort(w2+1,w2+cnt2,cmp);
	sort(w3+1,w3+cnt3,cmp);
	sort(w4+1,w4+cnt4,cmp);
	for(int i=2;i<cnt1;i++) w1[i]+=w1[i-1];
	for(int i=2;i<cnt2;i++) w2[i]+=w2[i-1];
	for(int i=2;i<cnt3;i++) w3[i]+=w3[i-1];
	for(int i=2;i<cnt4;i++) w4[i]+=w4[i-1];
	x1=w[0],x2=x1+1,x3=x2+1,x4=x3+1;
//	cout<<cnt1<<" "<<cnt2<<" "<<cnt
	int ma=-1;
	for(int i1=0;i1<=cnt1;i1++)
	{
		for(int i2=0;i2<=cnt2;i2++)
		{
			for(int i3=0;i3<=cnt3;i3++)
			{
				for(int i4=0;i4<=cnt4;i4++)
				{
					if(1ll*i1*x1+1ll*i2*x2+1ll*i3*x3+1ll*i4*x4>1ll*W) continue;
					ma=max(w1[i1]+w2[i2]+w3[i3]+w4[i4],ma);
				}
			}
		}
	}
	cout<<ma;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define INF (1 << 30) - 1

bool cmp(P p, P q){
  return p.first * (q.second + 1) > q.first * (p.second + 1);
}

vector<ll> dp(33, INF);

int main(){
  ll n, T;
  cin >> n >> T;

  vector<ll> b;
  vector<P> a_b;
  for(int i = 0; i < n; ++i){
    ll a_, b_;
    cin >> a_ >> b_;
    if(a_ == 0)b.push_back(b_ + 1);
    else a_b.push_back(P(a_, b_));
  }

  sort(a_b.begin(), a_b.end(), cmp);
  sort(b.begin(), b.end());

  dp[0] = 0;
  for(auto p : a_b){
    ll a = p.first;
    ll b = p.second;
    for(int i = 32; i > 0; --i){
      if(dp[i - 1] > T)continue;
      dp[i] = min(dp[i], (a + 1) * dp[i - 1] + a + b + 1);
    }
  }

  ll count = 0;
  for(int i = 32; i >= 0; --i){
    ll cur = dp[i];
    if(cur > T)continue;
    ll tmp_count = i;
    for(int j = 0; j < b.size(); ++j){
      if(cur + b[j] > T)break;
      cur += b[j];
      ++tmp_count;
    }
    if(count < tmp_count){
      count = tmp_count;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 6256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> ab[n];
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }

  for(int i=0;i<ab[0].size();i++){
    int c=ab[0][i];
    for(int j=0;j<ab[c].size();j++){
      if(ab[c][j]==n-1){
        cout<<"POSSIBLE"<<endl;
        return 0;
      }
    }
  }

  cout<<"IMPOSSIBLE"<<endl;

  return 0;
}


Measured memory_bytes: 12016
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 入力フェーズ
        string[] input = Console.ReadLine().Split(' ');
        long K = int.Parse(input[0]);
        long A = int.Parse(input[1]);
        long B = int.Parse(input[2]);

        long ret = 0;
        // A, Bの損益分岐点
        if(A+2 >= B)
        {
          // ビスケットの交換に２ターン使って２以上増えないから叩くだけでOK
          //Console.WriteLine("損益分岐　だめ");
          ret = K + 1;
        }
        else
        {
          if(K<=A)
          {
            // ビスケットの交換枚数に届かない/戻すターンがないから叩くだけ
            //Console.WriteLine("叩くだけ");
            ret = K + 1;
          }
          else
          {
            // A-1ターン後、B-A枚ずつ増えて行く
            if((K-A)%2 == 0)
            {
              // 最後に一回ビスケットの交換をする
              //Console.WriteLine("最後に叩く");
              ret = A + (K-A)/2 * (B-A) + 1;
            }else
            {
              // ビスケットの交換だけでちょうど終わる
              //Console.WriteLine("交換でぴったり");
              ret = A + (K-A+1)/2*(B-A);
            }
          }
        }
    // 出力
        Console.WriteLine(ret);
    }
		class myClass{ //自作クラス
			public int ID {set; get;}
			public long Point {set; get;}
		}

		static private long myMethod(int args)
		{
			// 自作メソッド
			long ret = 0;

			return ret;
		}
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int c[] = {3, 5, 7};

void search(int sum, int mask, int now, int len, vector<int>& a) {
  if (now == len) {
    if (mask == 7) a.push_back(sum);
    return;
  }
  for (int i = 0; i < 3; ++i) {
    search(sum * 10 + c[i], mask | (1 << i), now + 1, len, a);
  }
}

int main() {
  vector<int> a;
  for (int k = 3; k < 10; ++k) {
    search(0, 0, 0, k, a);
  }
  int n, ret = 0;
  cin >> n;
  for (auto& it : a) {
    if (it <= n) ++ret;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
#include<tuple>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

struct Node {
	int sx, tx, sy, ty;
	Node() { sx = LLINF; tx = -LLINF; sy = LLINF; ty = -LLINF; }
	Node(int sx1, int tx1, int sy1, int ty1) { sx = sx1, tx = tx1, sy = sy1, ty = ty1; }
};

using V = Node;
#define def Node()

template<int NV> struct SegTree { //[l,r)
	V comp(V& l, V& r) {
		return Node(min(l.sx, r.sx), max(l.tx, r.tx), min(l.sy, r.sy), max(l.ty, r.ty));
	};

	vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
	V get(int x, int y, int l = 0, int r = NV, int k = 1) {
		if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
		auto a = get(x, y, l, (l + r) / 2, k * 2);
		auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
		return comp(a, b);
	}
	void update(int i, V v) {
		i += NV; val[i] = v;
		while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
	}
	V operator[](int x) { return get(x, x + 1); }
};

int N, d;
SegTree<1 << 18> st;

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

	cin >> N >> d;
	VI bv(N);
	vector<tuple<int, int, int> >points(N);
	REP(i, N) {
		int x, y, b;
		cin >> x >> y >> b;
		points[i] = make_tuple(b, x, y);
		bv[i] = b;
	}
	SORT(points);
	SORT(bv);
	
	REP(i, N) {
		int x, y, b;
		tie(b, x, y) = points[i];
		st.update(i, Node(x, x, y, y));
	}
	int ans = 0;
	REP(i, N) {
		int L = i;
		int R = UB(bv, bv[i] + d)-bv.begin();
		auto no = st.get(L, R);

		int sx = no.sx;
		int tx = no.tx;
		int sy = no.sy;
		int ty = no.ty;
		ans = max(ans, (tx - sx)*(ty - sy));

	}

	cout << ans << endl;

	return 0;

}





Measured memory_bytes: 25568
#include<iostream>

using namespace std;

int main(void)
{
	int h,w;
	cin >> h >> w;
	char a[102][102];
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin >> a[i-1][j-1];
	
	for(int i=0;i<=h+1;i++)
	{
		for(int j=0;j<=w+1;j++)
		{
			cout << (i==0 or j==0 or i==h+1 or j==w+1 ? '#':a[i-1][j-1]);
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
K = int(input())
def calc(a, b):
    if a < 0:
        t = calc(-a, b)
        return (-t[0], t[1])
    if b < 0:
        t = calc(a, -b)
        return (t[0], -t[1])
    if a > b:
        t = calc(b, a)
        return (t[1], t[0])
    if a + b >= 2*K:
        return (a, b-K)
    if a + b == K:
        return (0, 0)
    r = K - (a + b)//2
    return (-r, b-K+a+r)

X, Y = map(int, input().split())
if K % 2 == 0 and (X+Y) % 2:
    print(-1)
else:
    ANS = []
    while X or Y:
        ANS.append((X, Y))
        X, Y = calc(X, Y)
    print(len(ANS))
    for ans in ANS[::-1]:
        print(*ans)


Measured memory_bytes: 61508
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

ll GCD(ll a, ll b) {
  if(a < b) return GCD(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,X;
    cin>>N>>X;
    vll x(N);
    for(ll i=0;i<N;i++)cin>>x[i];
    
    if(N==1){
        cout<<abs(X-x[0])<<endl;
        return 0;
    }
    
    ll ans=GCD(abs(X-x[0]),abs(X-x[1]));
    for(ll i=2;i<N;i++){
        ans=GCD(ans,abs(X-x[i]));
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <algorithm>
using namespace std;

int H, W, M;
int HH[300005], WW[300005];

pair<int, int> DH[300005], DW[300005];
set<pair<int, int>> B;

int bom(int h, int w) {
  return DH[h].first + DW[w].first - (B.count(make_pair(DH[h].second, DW[w].second)) > 0 ? 1 : 0);
}

void solve() {
  for (int i = 0; i < H; i++) { DH[i] = make_pair(0, i); }
  for (int i = 0; i < W; i++) { DW[i] = make_pair(0, i); }

  for (int m = 0; m < M; m++) { DH[HH[m]].first++; }
  for (int m = 0; m < M; m++) { DW[WW[m]].first++; }

  sort(DH, DH+H, greater<pair<int, int>>());
  sort(DW, DW+H, greater<pair<int, int>>());
  // for (int i = 0; i < H; i++) { printf("DH[%d] = (%d, %d)\n", i, DH[i].first, DH[i].second); }
  // for (int i = 0; i < W; i++) { printf("DW[%d] = (%d, %d)\n", i, DW[i].first, DW[i].second); }

  int mh = 0, mw = 0;
  int s = bom(0, 0);
  for (int h = 0; h < H; h++) {
    if (bom(h, 0) >= s - 1) {
      mh = h;
    } else {
      break;
    }
  }
  for (int w = 0; w < W; w++) {
    if (bom(0, w) >= s - 1) {
      mw = w;
    } else {
      break;
    }
  }

  int ans = -1;
  for (int h = 0; h <= mh; h++) {
    ans = max(ans, bom(h, 0));
  }
  for (int w = 0; w <= mw; w++) {
    ans = max(ans, bom(0, w));
  }

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

int main() {
  scanf("%d %d %d", &H, &W, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d", HH+i, WW+i);
    HH[i]--; WW[i]--;
    B.insert(make_pair(HH[i], WW[i]));
  }
  solve();
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1e9 + 7
#define INF 999999999
#define fk first
#define sv second

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

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  int n;
  cin >> n;

  int m = 1;
  while (m <= n) {
    m *= 2;
  }

  cout << m / 2 << endl;

}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int d;
  cin >> d;
  d-=25;
  cout << "Christmas";
  for(int i=0;i<-d;i++){
    cout << " Eve";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<queue>
#include<cstdlib>
using namespace std;

queue<char> qu;
void loop (char n, char c);
void reset();

int main(){
    string input;
    while(cin >>input){
        reset();
        for(int i = 0; i < input.size(); i++){
            if(input[i] == '@'){
                loop(input[i + 1], input[i + 2]);
                i += 2;
            } else{
                qu.push(input[i]);
            }
        }
        for(int i = 0; qu.empty() != 1 ; i++){
            cout <<qu.front();
            qu.pop();
        }
        cout <<endl;
    }
    return 0;
}

void loop(char n, char c){
    int num = n - '0';
    for(int i = 0; i < num; i++){
        qu.push(c);
    }
}

void reset(){
    while(!qu.empty()){
        qu.pop();
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

void solve_A(){
    string s;
    cin >> s;
    if(s[0] != s[1] || s[1] != s[2]) cout  << "Yes";
    else cout << "No";

}

int main(void){
    solve_A();
    
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n,d,x;
	cin>>n>>d;
	x = ceil((db)n/(2*d+1));
	cout<<x<<nw;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
#define NMAX 393
#define max(a,b) ((a) > (b) ? (a) : (b))

int main(void ){
  int i, j, n, m, s, l, p, w, dp[NMAX+1], phrase[NMAX], ans[NMAX];
  scanf("%d", &n);
  memset(phrase, 0, sizeof(phrase));
  memset(dp, 0, sizeof(dp));
  for(i = 0; i < n; i++){
    scanf("%d %d %d", &s, &l, &p);
    for(j = s; j <= l; j++) phrase[j-1] = max(phrase[j-1], p);
  }
  for(i = 1; i <= NMAX; i++) {
    if(phrase[i-1]){
      for(j = i; j <= NMAX; j++) {
        dp[j] = max(dp[j], dp[j-i] + phrase[i-1]);
      }
    }
  }
  scanf("%d", &m);
  for(i = 0; i < m; i++){
    scanf("%d", &w);
    if(!dp[w]){
      printf("-1\n");
      return 0;
    }
    ans[i] = dp[w];
  }
  for(i = 0; i < m; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 2104