akhauriyash/Code-Regression huggingface dataset:
s = input()

if 'C' in s and 'F' in s:
    c_index = s.index('C')
    f_index = s.rindex('F')
    if c_index < f_index:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 9076
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int gcd(int a, int b){ //最大公約数
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
int main(){
  int n;
  cin >> n;
  int len = 1000000 + 1;
  vi a(n), d(len);
  rep(i, n){
    cin >> a[i];
    d[a[i]]++;
  }
  bool ok = true;
  for(int i = 2; i < len; i++){
    int cnt = 0;
    for(int j = i; j < len; j += i) cnt += d[j];
    if(cnt > 1){
      ok = false;
      break;
    }
    if(!ok) break;
  }
  if(ok){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  rep(i, n - 1) g = gcd(g, a[i + 1]);
  if(g == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
}

Measured memory_bytes: 11156
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut a:usize = read!();
    let mut b:usize = read!();
    let mut c:usize = read!();
    let mut k:usize = 0;
    if a==b {
        k+=1;
    }
    if a==c {
        k+=1;
    }
    if b==c {
        k+=1;
    }
    if k==1 {
        println!("Yes");
    }
    else {
        println!("No");
    }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9 + 5;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

int main()
{
    int n;
    cin >> n;
    double coins[n + 1];
    for(int i = 0; i < n; i++)
        scanf("%lf", &coins[i]);
    double dp[n + 1][n + 1] = {};
    dp[0][0] = 1;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            dp[i + 1][j + 1] += dp[i][j] * coins[i];
            dp[i + 1][j] += dp[i][j] * (1 - coins[i]);
        }
    }
    double ans = 0;
    /* for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
            cout << dp[i][j] << ' ';
        cout << '\n';
    }*/
    for(int i = n / 2 + 1; i <= n; i++)
        ans += dp[n][i];
    printf("%.10lf",ans);
}


Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		String[] strA = sc.nextLine().split(" ");
		int ans = 0;
		for(int i=0; i<N; i++) {
			ans += half(Integer.parseInt(strA[i]), 0);
		}
		System.out.println(ans);
		sc.close();
	}

	private static int half(int num, int count) {
		if(num % 2 == 0) {
			count++;
			count = half(num / 2, count);
		}
		return count;
	}
}

Measured memory_bytes: 28220
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int n, x, t;
	cin >>n >>x >>t;
	int ans = n / x * t;
	if(n % x > 0)
		ans += t;
	cout <<ans <<'\n';
	return 0;
}


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

typedef long long ll;
const int MAX_N = 200000;

int main() {
  int N, Q;
  ll D[MAX_N];
  static std::tuple<ll, int, ll> events[2 * MAX_N];
  std::set<ll> stop;

  std::cin >> N >> Q;
  for(int i = 0; i < N; ++i) {
    ll S, T, X;
    std::cin >> S >> T >> X;
    events[2 * i] = std::make_tuple(S - X, 1, X);
    events[2 * i + 1] = std::make_tuple(T - X, -1, X);
  }
  for(int i = 0; i < Q; ++i) {
    std::cin >> D[i];
  }

  std::sort(events, events + 2 * N);
  int j = 0;
  for(int i = 0; i < Q; ++i) {
    while(j < 2 * N) {
      auto e = events[j];
      ll t = std::get<0>(e);
      if(t <= D[i]) {
        if(std::get<1>(e) > 0) {
          stop.insert(std::get<2>(e));
        } else {
          stop.erase(std::get<2>(e));
        }
        ++j;
      } else {
        break;
      }
    }
    auto lb = stop.lower_bound(0);
    if(lb != stop.end()) {
      std::cout << *lb << std::endl;
    } else {
      std::cout << -1 << std::endl;
    }
  }

}


Measured memory_bytes: 21504
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

bool primes[1000000];
bool isso(long long int a) {
	if (a == 1 || a == 0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	for (int i = 0; i < 1000000; ++i) {
		primes[i] = isso(i);
	}
	while (1) {
		int N, P; cin >> N >> P;
		if (N == -1)break;
		vector<int>aset;
		for (int i = N + 1; i < N + 1000; ++i) {
			for (int j = i; j < N + 1000; ++j) {
				if (primes[i] && primes[j]) {
					aset.emplace_back(i + j);
				}
			}
		}
		sort(aset.begin(), aset.end());
		cout << aset[P - 1] << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n, y;
    cin >> n >> y;
    rep(i, n + 1)
    {
        rep(j, n + 1)
        {
            if (i + j + (y / 1000 - 10 * i - 5 * j) == n && (y / 1000 - 10 * i - 5 * j) >= 0)
            {
                printf("%d %d %d\n", i, j, y / 1000 - 10 * i - 5 * j);
                return (0);
            }
        }
    }

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


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,cnt;
int main ()
{
    cin>>a>>b>>c>>x;
    for (int i=0; i <= a && 500*i<=x; i++)
        for (int j=0; j <= b && 100*j+500*i<=x; j++)
            for (int k=0; k <= c && 50*k+100*j+500*i<=x; k++)
                if (500*i+100*j+50*k==x)
                    cnt++;
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin>>N;
  vi L(N);
  rep(i,N) cin>>L[i];
  sort(L.begin(), L.end());
  int ans=0;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      int a = L[i], b=L[j];
      auto c = lower_bound(L.begin()+j, L.end(), a+b);
      ans += c-L.begin()-j-1;
    }
  }
  cout << ans << endl;
  return 0;
} 

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int n;
int x[24],y[24],r[24],c[24];

inline bool intersect(int p, int q)
{
    double dist=sqrt((x[p]-x[q])*(x[p]-x[q])+(y[p]-y[q])*(y[p]-y[q]));
    return dist<(r[p]+r[q]);
}

inline bool available(int p, int state)
{
    rep(i,p)
    {
        if(state>>i&1 && intersect(p,i)) return false;
    }
    return true;
}

char dp[1<<24];
char dfs(int state)
{
    if(dp[state]>=0) return dp[state];
    if(__builtin_popcount(state)<2) return 0;

    char ret=(char)0;
    rep(i,n)
    {
        if(state>>i&1)
        {
            if(!available(i,state)) continue;

            rep(j,n)
            {
                if(i==j) continue;
                if(c[i]!=c[j]) continue;

                if(state>>j&1)
                {
                    if(!available(j,state)) continue;
                    ret = max(ret,(char)(dfs(state-(1<<i)-(1<<j))+2));
                }
            }
        }
    }

    return dp[state]=ret;
}

int main()
{
    while(cin >>n,n)
    {
        rep(i,n) scanf(" %d %d %d %d", &x[i], &y[i], &r[i], &c[i]);
        memset(dp,(char)-1,sizeof(dp));
        cout << (int)dfs((1<<n)-1) << endl;
    }
    return 0;
}

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

int n,m;
char s1[100],s2[100];
char hash[2000];

char output[20000000];

int main(){
	int i;
	
	while(1){
		for( i = 0; i < 1000; i++ )
			hash[i] = 0;
			
		scanf("%d",&n);
		if(!n)break;
		for( i = 0; i < n; i++ ){
			scanf("%s%s",s1,s2);
			hash[(int)s1[0]] = s2[0];
		}
		scanf("%d",&m);
	//	printf("read finish!\n");
	
		for( i = 0; i < m; i++ ){
			s1[0] = '\0';
			scanf("%s",s1);
			if( hash[s1[0]] ){
				char s[3] = {hash[(int)s1[0]],'\0'};
				strcat(output,s);
			}
			else{
				strcat(output,s1);
			}
		}
		printf("%s\n",output);
		output[0] = '\0';
	}
	return 0;
}

Measured memory_bytes: 1132
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n) + out
        X_dumy = int(X_dumy / n)
    return out


def resolve():
    N, K = map(int, input().split())

    ans = Base_10_to_n(N, K)
    ans_list = list(str(ans))

    print(len(ans_list))


resolve()

Measured memory_bytes: 3060
function Main(input) {
    var result;
    const N = parseInt(input[0].split(/\s/)[0]);
    const M = parseInt(input.shift().split(/\s/)[1]);

    const KS = input.slice(0, M).map(value => value.split(/\s/).map(v => parseInt(v)));
    const P = input.slice(M)[0].split(/\s/);
    
    var count = 0;
    generateMap(N).forEach(SW => check(SW, KS, P) == true ? count++ : 0);
    // check([1,1], KS, P);
    console.log(count);
    
}

function generateMap(N) {
    var arr = [];
    for (var index = 0; index < Math.pow(2, N); index++) {
        var value = index;
        var insert = [];
        for (var i = 0; i < N; i++) {
            insert.push(value % 2);
            value = Math.floor(value/2);
        }
        arr.push(insert);
    }
    return arr;
}

function check(sw, KS, P){
    // console.log(sw,KS,P);
    for (var index = 0; index < KS.length; index++) {
        var ks = KS[index];
        var check = 0;
        for (var i = 1; i < ks.length; i++) {
            var s = ks[i]-1;
            // console.log("sw[s]", sw[s]);
            if(sw[s] == 1) check++;
        }
        
        
        if(P[index] == "1") check++;
        // console.log(index, check);
        
        if(check%2 > 0) return false;
    };
    
    
    return true;
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<int> a(n);
	int ap = 0;
	for (int i = 0; i < n; i++) {
		a.at(i) = l + i;
		ap += a.at(i);
	}

	int ans = 0, c = 1000000000;
	for (int i = 0; i < n; i++) {
		int tmp = ap - a.at(i);
		int d = abs(ap - tmp);
		if (d < c) {
			c = d;
			ans = tmp;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >>r;
	if(x>=r && x<=w-r && y>=r && y<=h-r && r<=w/2 && r<=h/2)  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3040
import bisect
A, B, Q = map(int, input().split())

s = [-float('inf')] + [int(input()) for i in range(A)] + [float('inf')]
t = [-float('inf')] + [int(input()) for i in range(B)] + [float('inf')]

res = []
for i in range(Q):
    x = int(input())
    a = bisect.bisect_left(s, x) - 1
    b = a + 1
    c = bisect.bisect_left(t, x) - 1
    d = c + 1
    ans = float('inf')
    for S in [s[a], s[b]]:
        for T in [t[c], t[d]]:
            ans = min(ans, abs(S - x) + abs(T - S), abs(T - x) + abs(S - T))
    res.append(ans)

print('\n'.join(map(str, res)))


Measured memory_bytes: 23904
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n; cin >> n;
        vector<int> a(n);
        FOR(i,0,n) cin >> a[i];
        sort(a.begin(), a.end(),greater<int>());
        int ans = a[0];
        int i = 2,ptr = 1;
        while(i <= n-2){
            ans += 2*a[ptr++];
            //cout << a[ptr] << " " << i << endl;
            i+=2;
        }
        if(i < n) ans += a[ptr]; 
        cout << ans;
    }   
}

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans;
    if (k <= a) {
        ans = k;
    } else if (k <= a + b) {
        ans = a;
    } else {
        ans = a - (k - a - b);
    }
    cout << ans;

    return 0;
}


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

using namespace std;

int A, B, C, D, E, F;
vector<int> water, sugar;

int main(void)
{
	cin >> A >> B >> C >> D >> E >> F;
	
	for(int a = 0; a*100 <= 3000; a += A){
		for(int b = 0; (a + b)*100 <= 3000; b += B){
			water.push_back( (a+b) * 100 );
		}
	}
	for(int c = 0; c <= 1500; c += C){
		for(int d = 0; (c + d) <= 1500; d += D){
			sugar.push_back( c+d );
		}
	}
	
	sort(water.begin(), water.end());
	sort(sugar.begin(), sugar.end());
	water.erase( unique(water.begin(), water.end()), water.end() );
	sugar.erase( unique(sugar.begin(), sugar.end()), sugar.end() );
	
	double max = -1, noudo;
	int ans_eki;
	int ans_sugar;
	
	for(int i = 0; i < (int)water.size(); i++){
		for(int j = 0; j < (int)sugar.size(); j++){
			if(water[i] + sugar[j] > F) continue;
			if(water[i] / 100.0 * E < sugar[j]) continue;
			noudo = (double)sugar[j] / (double)(water[i] + sugar[j]);
			if(max < noudo){
				max = noudo;
				ans_eki = water[i] + sugar[j];
				ans_sugar = sugar[j];
			}
		}
	}
	cout << ans_eki << " " << ans_sugar << endl;
	
	return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define SIZE 5005
#define INF 1000000005
#define ll long long
#define MS(x,y) memset(x,y,sizeof x);
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
using namespace std;

int n;
int a[100007];

int main()
{
    scanf("%d",&n);
    FOR(i,1,n)
        scanf("%d",&a[i]);
    int now = 0;
    int ans = 0;
    FOR(i,1,n)
    {
        if(a[i] == i)
        {
            ++now;
        }else
        {
            ans += (int)ceil(1.0 * now / 2);
            now = 0;
        }
    }
    ans += (int)ceil(1.0 * now / 2);
    printf("%d\n",ans);

    return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

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

    int n,m;cin>>n>>m;
    vii a(n);
    FOR(i,n) cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    int t=m-1,i=0,ret=0;
    vi stock;
    stock.reserve(n);
    while(i<n && t>=0){
        if (t+a[i].first<=m)  {stock.push_back(a[i++].second); push_heap(stock.begin(),stock.end());}
        else{
            if (!stock.empty()){
                ret += stock.front();
                pop_heap(stock.begin(),stock.end());
                stock.pop_back();
            }
            --t;
        }
    }
    while(t>=0 && !stock.empty()){
        ret += stock.front();
        pop_heap(stock.begin(),stock.end());
        stock.pop_back();
        --t;
    }
    cout << ret;
}



Measured memory_bytes: 1408
#include<stdio.h>

int main(){
        int n, k;
        scanf("%d%d", &n, &k);
        int p[n], i, j, tmp;
        for(i=0; i<n; i++){
                scanf("%d", &p[i]);
        }
        for(i=0; i<n; i++){
                for(j=i+1; j<n; j++){
                        if(p[i]>p[j]){
                                tmp=p[i];
                                p[i]=p[j];
                                p[j]=tmp;
                        }
                }
        }
        int sum=0;
        for(i=0; i<k; i++){
                sum+=p[i];
        }
        printf("%d", sum);
        return 0;
}


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

using namespace std;

#define NMax 1003

int n,m,a,b;
int v[NMax][NMax];

int main(){
    cin >> n >> m >> a >> b;
    for(int i = 1; i <= b; ++i){
        for(int j = 1; j <= a; ++j){
            v[i][j] = 1;
        }
    }
    for(int i = b + 1; i <= n; ++i){
        for(int j = a + 1; j <= m; ++j){
            v[i][j] = 1;
        }
    }
    for(int i = 1; i <= n; ++i){
        int z = 0;
        int u = 0;
        for(int j = 1; j <= m; ++j){
            u += (v[i][j] == 1);
            z += (v[i][j] == 0);
        }
        if(min(z,u) != a){
            cout << -1 << '\n';
            return 0;
        }
    }
    for(int i = 1; i <= m; ++i){
        int z = 0;
        int u = 0;
        for(int j = 1; j <= n; ++j){
            u += (v[j][i] == 1);
            z += (v[j][i] == 0);
        }
        if(min(z,u) != b){
            cout << -1 << '\n';
            return 0;
        }
    }

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            cout << v[i][j];
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 5120
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    string s;
    int n;
    
    cin >> n >> s;
    
    for(int i=0; i<s.size(); i++)
    {
        s[i] = s[i] + n;
        if(s[i] > 90) s[i] = s[i] - 26;
    }
    
    cout << s << endl;

    return 0;
}


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

using namespace std;

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    long long k, a, b;
    long long ans;
    cin >> k >> a >> b;

    if( b - a <= 2 ) {
        ans = k + 1;
    } else {
        ans = (k - a + 1)/2*(b - a) + a + ((k - a + 1) & 1LL);
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define int long long
typedef pair<int, int> P;
int rj[114514], ro[114514], ri[114514];
int aj, ao, ai;
signed main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'J')rj[i + 1]++;
		else if (s[i] == 'O')ro[i + 1]++;
		else ri[i + 1]++;
	}
	for (int i = 0; i < n; i++) {
		rj[i + 1] += rj[i];
		ro[i + 1] += ro[i];
		ri[i + 1] += ri[i];
	}

	//plus'J'
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') {
			int J = rj[i] - rj[0] + 1;
			int I = ri[n] - ri[i];
			aj += J*I;
		}
	}
	//plus'O'
	for (int i = 0; i < n; i++) {
		int J = rj[i] - rj[0];
		int I = ri[n] - ri[i];
		ao =max(ao,J*I);
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') {
			int J = rj[i] - rj[0];
			int I = ri[n] - ri[i];
			ao += J*I;
		}
	}
	//plus'I'
	for (int i = 0; i < n; i++) {
		if (s[i] == 'O') {
			int J = rj[i] - rj[0];
			int I = ri[n] - ri[i] + 1;
			ai += J*I;
		}
	}
	cout << max(aj, max(ao, ai)) << endl;
}

Measured memory_bytes: 5692
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // 無向グラフの対の辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

int e[710][710];

bool isBipartite(const Graph &g, long long v, long long c, vector<long long> &color) {
    color[v] = c;
    for(auto e : g[v]) {
        if (color[e.to] < 0) {
            bool f = isBipartite(g, e.to, c ^ 1, color);
            if (!f) return false;
        } else {
            if ((c^1) != color[e.to]) {
                return false;
            }
        }
    }
    return true;
}

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    for(int i = 0; i < M; ++i) {
        e[A[i]][B[i]] = e[B[i]][A[i]] = 1;
    }
    Graph g(N + 1);
    for(int i = 1; i <= N; ++i) for(int j = i + 1; j <= N; ++j) {
        if(!e[i][j]) {
            addUndirectedEdge(g, i, j, 1);
        }
    }
    vector<int> color(N + 1, -1);
    int c = 0;
    for(int i = 1; i <= N; ++i) {
        if (color[i] < 0) {
            if (!isBipartite(g, i, c, color)) {
                cout << -1 << endl;
                return;
            }
            c += 2;
        }
    }
    vector<int> cnt(c);
    for(int i = 1; i <= N; ++i) cnt[color[i]]++;
    vector<vector<bool>> dp(c / 2 + 1, vector<bool>(N + 1));
    dp[0][0] = true;
    for(int i = 0; i * 2 < c; i++) {
        for(int j = N; j >= 0; --j) {
            for(int k = 0; k < 2; ++k) {
                if (j - cnt[i * 2 + k] >= 0) {
                    dp[i + 1][j] = dp[i + 1][j] || dp[i][j - cnt[i * 2 + k]];
                }
            }
        }
    }
    int res = N * (N - 1) / 2;
    for(int i = 0; i <= N; ++i) {
        if (dp[c / 2][i]) {
            int a = i, b = N - i;
            res = min(res, a * (a - 1) / 2 + b * (b - 1) / 2);
        }
    }
    cout << res << endl;
}

signed main(){
	ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    ll a, b, t, n, m, k;
    ll mod=1000000007;
    cin >> n >> m;
    char c;
    int grid[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> c;
            if (c == '.')
            {
                grid[i][j] = 1;
            }
            else
            {
                grid[i][j] = 0;
            }
        }
    }

    ll dp[n][m];
    dp[0][0] = 1;
    for (int i = 1; i <= n + m; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (j < n && (i - j) < m && (i - j) >= 0)
            {
                if(grid[j][i-j]==0){
                    dp[j][i-j]=0;
                    continue;
                }
                if (j == 0)
                {
                    dp[j][i - j] = dp[j][i - j - 1];
                }
                else if ((i - j) == 0)
                {
                    dp[j][i - j] = dp[j - 1][i - j] ;
                }
                else
                {
                    dp[j][i - j] = dp[j - 1][i - j] + dp[j][i - j - 1];
                    dp[j][i-j]%=mod;
                }
            }
        }
    }

    cout<<dp[n-1][m-1]%mod;
    return 0;
}

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

int main() {
    string s , t;
    cin >> s >> t;
    deque<char> a , b;

    for ( int i = 0; i < s.length(); i++ ){
        a.push_back( s[i] );
        b.push_back( t[i] );
    }

    int len = s.length();
    for ( int i = 0; i < len; i++ ){
        if ( a == b ){
            cout << "Yes";
            return 0;
        }
        a.push_front( a.back() );
        a.pop_back();
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		if (n > 36) printf ("0\n");
		else {
			int tmp;
			int ans = 0;
			for (int i=0; i<10; ++i) {
				for (int j=0; j<10; ++j) {
					for (int k=0; k<10; ++k) {
						tmp = n - i - j - k;	
						if (tmp >= 0 && tmp < 10) ++ans;
					}
				}
			}
			printf ("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      if(a < b && b < c){
          System.out.println("Yes");
         
      }else{
          System.out.println("No");
      }
    }
    
  
    
}



Measured memory_bytes: 26380
// f[i]: 
// the number of combinions for women in set i and the first k men.
// k = number_of_ones(i)
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 22;
const int maxtot = 2100000;
const int mo = 1e9 + 7;

int n, g[maxn][maxn], f[maxtot];

int countOnes(int x) {
    int res = 0;
    while (x > 0) {
        res += (x & 1);
        x >>= 1;
    }

    return res;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> g[i][j];

    int tot = 1 << n;
    f[0] = 1;

    for (int i = 1; i < tot; ++i) {
        int idx = countOnes(i) - 1;
        for (int j = 0; j < n; ++j)
            if ((i & (1 << j)) && g[idx][j])
                f[i] = (f[i] + f[i - (1 << j)]) % mo;

        // printf("%d %d %d\n", i, idx, f[i]);
    }

    cout << f[tot-1] << endl;
	return 0;
}

Measured memory_bytes: 8448
var
  s:string;
  i,l,sc,sf:longint; 
begin
  readln(s);
  l:=length(s);
  sc:=maxlongint;
  for i:=1 to l do 
    if s[i]='F'then sf:=i;
  for i:=l downto 1 do 
    if s[i]='C'then sc:=i;
  if sc<sf then writeln('Yes')
  else writeln('No');
end.

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import itertools

n, m, q = map(int, input().split())
a = []
b = []
c = []
d = []
for i in range(q):
  _a, _b, _c, _d = map(int, input().split())
  a.append(_a)
  b.append(_b)
  c.append(_c)
  d.append(_d)

a_list = []
  
for i in range(m):
  a_list.append(i)

suuretsu_list = itertools.combinations_with_replacement(a_list, n)

point_list = [0]

for suuretsu in suuretsu_list:
  point = 0
  for _a, _b, _c, _d in zip(a, b, c, d):
    if suuretsu[_b - 1] - suuretsu[_a - 1] == _c:
      point += _d
  point_list.append(point)
print(max(point_list))



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int K, X; cin >> K >> X;
  string result = K*500>=X ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def modfact(n):
    fact=[1]*(n+1)
    invfact=[1]*(n+1)
    for i in range(1,n+1):
        fact[i]=i*fact[i-1]%MOD
    invfact[n]=pow(fact[n],MOD-2,MOD)
    for i in range(n-1,-1,-1):
        invfact[i]=invfact[i+1]*(i+1)%MOD
    return fact,invfact

def resolve():
    n,m,k=map(int,input().split())
    fact,invfact=modfact(n*m-2)
    ans=1
    ans*=fact[m*n-2]*invfact[k-2]*invfact[m*n-k]
    ans*=((n-1)*n*(n+1)*m*m+(m-1)*m*(m+1)*n*n)//6
    print(ans%MOD)
resolve()

Measured memory_bytes: 41712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;
  
  int q, scores[N];
  REP(i, N) scores[i] = K-Q;
  REP(i, Q){
    cin >> q;
    scores[q-1]++;
  };
  
  REP(i, N){
    cout << ((scores[i] > 0) ? "Yes" : "No") << endl;
  };
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  for(int i=0;i<h;i++) cin >> c[i];

  int cnt = 0;
  int ans = 0;
  for(int hb = 0;hb < (1<<h) ;hb++){
    for(int wb = 0;wb < (1<<w) ;wb++){
      cnt = 0;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(hb & (1<<i) && wb & (1<<j)){
            if(c[i][j] == '#'){
              cnt++;
            }
          }
        }
      }

      if(cnt == k){
        ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  REP(i, (1<<3)){
    int ret = s[0]-'0';
    REP(j, 3){
      if((i >> j)&1) ret += s[j+1]-'0';
      else ret -= s[j+1]-'0';
    }
    if(ret == 7){
      cout << s[0];
      REP(j, 3){
        if((i >> j)&1) cout << "+";
        else cout << "-";
        cout << s[j+1];
      }
      cout << "=7" << "\n";
      return 0;
    }
  }


  return 0;
}

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

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main(){
    int N;
    cin >> N;
    Graph g(N);
    for(int i =0; i < N-1; i++){
        int u,v,w;
        cin >> u >> v >> w; 
        u--;
        v--;
        w %= 2;
        g[u].push_back(Edge(v,w));
        g[v].push_back(Edge(u,w));
    }
    vector<int> dist(N, -1);
    queue<int> q;  //候補たち 
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int look = q.front();  //最初から一つだけ取り出す。
        q.pop();
        
        for(auto next: g[look]){
            if(dist[next.to] != -1) continue;
            q.push(next.to);
            dist[next.to] = (dist[look] + next.weight)%2;
        }
    }
    for(int i =0; i < N; i++){
        cout << dist[i] << endl;
    }
}

Measured memory_bytes: 6784
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#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 <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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>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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

signed main(){
	ll n, C; cin >> n >> C;
	vector<ll> x(n, 0), c(n, 0), x1(n), c1(n), q(n);
	for(int i = 0; i < n; i++){
		cin >> x[i] >> c[i]; q[i] = c[i];
		x1[i] = C - x[i]; c1[i] = c[i];
	}
	reverse(x1.begin(), x1.end());
	reverse(c1.begin(), c1.end());
	for(int i = 1; i < n; i++){
		c[i] += c[i - 1];
		c1[i] += c1[i - 1];
	}
	vector<ll> data1(n + 1, 0), data2(n + 1, 0);
	for(int i = 1; i <= n; i++){
		data1[i] = c[i - 1] - x[i - 1];
		data2[i] = c1[i - 1] - x1[i - 1];
	}
	vector<ll> data_left(n + 1, 0), data_right(n + 1, 0);
	for(int i = 1; i  <= n; i++){
		data_left[i] = max(data_left[i - 1], data1[i]);
		data_right[i] = max(data_right[i - 1], data2[i]);
	}
	ll ans = 0;
	for(int left = 0; left <= n; left++){
		if(left == 0) ans = max(ans, data_right[n]);
		ans = max(ans, data1[left] - x[left - 1] + data_right[n - left]);
	}
	for(int right = 0; right <= n; right++){
		if(right == 0) ans = max(ans, data_left[n]);
		else ans = max(ans, data2[right] - x1[right - 1] + data_left[n - right]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 10328
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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 (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  
  ll sum = 0;
  for(int i=1;i<=n;i++){
    if(i%3 !=0 && i%5 !=0) sum += i;
  }
  
  cout << sum << endl;
  
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    ll a[n];
    ll dp[n][n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i][i]=a[i];
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            dp[j][j+i-1]=max(a[j]-dp[j+1][j+i-1],a[j+i-1]-dp[j][j+i-2]);
        }
    }
    cout<<dp[0][n-1]<<endl;
}

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

using namespace std;

const long long INF = 5e18;

struct RMinQ {
private:
	int n;
	vector< long long >node;
public:
	RMinQ(vector< long long >v) {
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;
		node.resize(2 * n - 1, INF);
		for (int i = 0;i < sz;i++)node[i + n - 1] = v[i];
		for (int i = n - 2;i >= 0;i--)node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}
	long long getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return INF;
		if (a <= l && r <= b)return node[k];
		long long vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
		long long vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};

struct RMaxQ {
private:
	int n;
	vector< long long >Node;
public:
	RMaxQ(vector< long long >v) {
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;
		Node.resize(2 * n - 1, -1);
		for (int i = 0;i < sz;i++)Node[i + n - 1] = v[i];
		for (int i = n - 2;i >= 0;i--)Node[i] = max(Node[2 * i + 1], Node[2 * i + 2]);
	}
	long long getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return -1;
		if (a <= l && r <= b)return Node[k];
		long long vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
		long long vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
};

long long N, d, x, y, s, ans;
vector< pair< long long, pair< long long, long long > > >v;
vector< long long >vv, xx, yy;

int main() {
	cin >> N >> d;
	v.resize(N);
	for (int i = 0;i < N;i++) {
		cin >> x >> y >> s;
		v[i]=make_pair(s,make_pair(x,y));
	}
	sort(v.begin(), v.end());
	xx.resize(N), yy.resize(N), vv.resize(N);
	for (int i = 0;i < N;i++) {
		vv[i] = v[i].first;
		xx[i] = v[i].second.first;
		yy[i] = v[i].second.second;
	}
	RMinQ xmn(xx), ymn(yy);
	RMaxQ xmx(xx), ymx(yy);
	for (int i = 0;i < N;i++) {
		int it = upper_bound(vv.begin(), vv.end(), vv[i] + d) - vv.begin();
		ans = max(ans, (xmx.getmax(i, it) - xmn.getmin(i, it))*(ymx.getmax(i, it) - ymn.getmin(i, it)));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 30224
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    let mut ans = 0;
    let mut count = 1;
    while b > count {
        count += a - 1;
        ans += 1;
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
    int table[200][200]={{0}};
    int c,r;
    cin>>r>>c;
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin>>table[i][j];
        }
    }
    for(int i=0; i<r+1; i++){
        int sum=0;
        for(int j=0; j<c; j++){
            sum+=table[i][j];
        }
        table[i][c]=sum;
    }
     for(int j=0; j<c+1; j++){
        int num=0;
        for(int i=0; i<r; i++){
            num+=table[i][j];
        }
        table[r][j]=num;
     }
     for(int i=0; i<r+1; i++){
         for(int j=0; j<c; j++){
             cout<<table[i][j]<<" ";
         }
         cout<<table[i][c]<<endl;
     }
}
     


Measured memory_bytes: 3236
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cassert>
using namespace std;

typedef long long lli;

const int INF = 1 << 29;
const int H = 4;
const int W = 4;
const int N = H * W;
const int MAX_ANS = 45;

/*
  反復深化＋枝狩り（ヒューリスティック？）
  「現在の手数 + '0'以外の答えまでのマンハッタン距離の合計 <= 45」になるかどうかで枝狩り
  手元では31~32手目くらいでTLEになってしまう
 */


lli pow2[N+1];
int in_pos,sumcnt;//dfscnt;
bool ans;
vector<char> inG,G,ansG;

void make(){
  pow2[0] = 1;
  for(lli i=1;i<=N;i++) {
    pow2[i] = pow2[i-1] * i;
  }
  
  for(int i=1;i<N;i++) ansG.push_back(i);
  ansG.push_back(0);
}

int nextpos(int pos, int d){
  switch(d){
    //up
  case 0:
    return pos - W;

    //right
  case 1:
    if(pos % W == W-1) return -1;
    else return pos + 1;

    //down
  case 2:
    if(pos + W >= N) return -1;
    else return pos + W;

    //left
  case 3:
    if(pos % W == 0) return -1;
    else return pos - 1;
    
  default: 
    return -1;
  }
}

int distance(int i, int j, int now){
  return abs(i - (now-1)/W) + abs(j - (now-1)%W);
}

// ansGまでのマンハッタン距離の合計
int inith(){
 int res = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int now = G[i*W+j];
      if(now != 0){
        res += distance(i,j,now);
      }
    }
  }
  return res;
}

int cnt,nh;

void dfs(int pos, int prev, int h){
  int npos;
  //dfscnt++;
  if(ans) return;
  if(G == ansG){
    ans = true;
    return;
  }
  if(cnt + h > sumcnt) return;

  for(int i=0;i<4;i++){
    npos = nextpos(pos, i);
    if(npos < 0 || npos == prev) continue;
    nh = h - distance(npos/W, npos%W, G[npos]) + distance(pos/W, pos%W, G[npos]);
    if(cnt + 1 + nh <= sumcnt){
      swap(G[pos], G[npos]);
      cnt += 1;
      dfs(npos, pos, nh);
      cnt -= 1;
      swap(G[pos], G[npos]);
    }
  }
}

void solve(){
  ans = false;
  G = inG;

  for(int i=0;i<=MAX_ANS;i++){
    //cout << i << ":" << endl;
    sumcnt = i;
    //dfscnt = 0;
    cnt = 0;
    dfs(in_pos, -1, inith());
    //cout << "dfs cnt = " << dfscnt << endl;
    if(ans) {
      cout << i << endl;
      return;
    }
  }

  assert(false);
}

int main(){
  set<int> st1;
  int x;
  make();

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      assert(cin >> x);
      assert(x >= 0 && x < N);
      assert(st1.empty() || st1.find(x) == st1.end());
      st1.insert(x);
      inG.push_back(x);
      if(x == 0) in_pos = i * W + j;
    }
  }
  solve();
  
  assert(!(cin >> x));
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    k--;
    string s;
    cin >> s;
    if (s[k] == 'A') s[k] = 'a';
    else if (s[k] == 'B') s[k] = 'b';
    else s[k] = 'c';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix

from math import gcd


def solv(K):
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                ans += gcd(a, gcd(b, c))
    return ans

if __name__ == "__main__":

    # K
    #
    K = int(input())
    ans = solv(K)

    print(ans)


Measured memory_bytes: 67664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        long cnt = 0;

        for (int i = n - 1; i >= 0; i--) {
            long tmp = (a[i] + cnt) % b[i];
            cnt += (tmp != 0)? b[i] - tmp : 0;
        }

        System.out.println(cnt);
    }
}


Measured memory_bytes: 48804
A,B,K=[int(x) for x in input().rstrip().split()]

if(0<A):
    if A<=K:
        
        K=K-A
        A=0
    else:
        A=A-K
        K=0

    
if(A==0 and 0<B):
    if B<=K:
        
        K=K-B
        B=0
    else:
        B=B-K
        K=0
print(A,B)

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

int main()
{
    string S;
    cin >> S;
    if (S <= "2019/04/30")
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h> 
#include <string.h>
int main(void) 
{ 
    char s[1000][10];
    int n, i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%s",s[i]);
    
    for(i=0;i<n;i++){
        //printf("%c\n",s[i][0]);
        if(s[i][0]=='Y'){
            printf("Four\n");
            return 0;
        }
    }
    printf("Three\n");
    return 0;  
}

Measured memory_bytes: 1616
H, A = input().split()
H = int(H)
A = int(A)
 
if ( 1 <= H ) & ( H <= 10000 ):
  if( 1 <= A ) & ( A <= 10000 ):
    if( H%A == 0 ):
      n = int(H/A)
    else:
      n = int(H/A) + 1
  else:
    n = 0
else:
  n = 0
 
print(n)

Measured memory_bytes: 2940