akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    REP(i,1,10){
        if(n%i==0 && n/i<10){
            Yes(1);
            return 0;
        }
    }
    Yes(0);
}


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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x | (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    LL k=0,sum=0;
    cin >> k;
    FOR(a,1,k){
        FOR(b,1,k){
            int g=__gcd(a,b);
            FOR(c,1,k){
                LL d=__gcd(g,c);
                sum+=d;
            }
        }
    }
    cout << sum;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, 0, N) cin >> a.at(i);
    int ans_f = INF;
    rep(i, -100, 101){
        int ans = 0;
        rep(j, 0, N) ans += pow(a.at(j) - i, 2);
        ans_f = min(ans, ans_f);
    }
    cout << ans_f << endl;
}

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

int main()
{
	int n, m = 0, k = 0;
	bool f = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;

		if (a)
			k++;
		else {
			if (k > m)
				m = k;
			k = 0;
		}
	}

	if (k > m)
		m = k;

	cout << m + 1 << endl;

	return 0;
}



Measured memory_bytes: 3124
#include<cstdio>
#include<cstring>

using namespace std;

int main() {
	char ch[1001];

	while (1) {
		scanf("%s", ch);
		if (ch[0] =='0')break;
		int sum = 0;
		for (int i = 0; i < strlen(ch); i++) {
			sum += (ch[i] - '0');
		}

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

	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll sN;
char s[202020];
ll i, j, k,ans;
int main(){
    scanf("%s", s);
    for (sN = 0; s[sN];sN++)
        ;
    if(sN==1&&sN==2){
        printf("0");
        return 0;
    }
    ll aa=0;
    ll bc=0;
    fornum(i,0,sN){
        //printf("%lld:%lld ",i, aa);
        if(s[i]=='A'){
            aa++;
        }else{
            if(s[i]=='B'&&s[i+1]=='C'){
                ans += aa;
                i++;
            }else{
                aa = 0;
            }
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int num = 1;
		while (num * 2 <= n) {
			num *=2;
		}
		
		System.out.println(num);
		
		sc.close();
	}
}




Measured memory_bytes: 27072
#include<bits/stdc++.h>
    using namespace std;
     
    #define int long long
    #define hell 998244353 
    #define endl "\n"
     
    int min(int a, int b){
     
        if(a>b)
            return b;
        return a;
    }
     
    int max(int a, int b){
     
        if(a>b)
            return a;
        return b;
    }
     
     
int32_t main()
{

    int a,b;
    cin>>a>>b;

    cout<<max(a+b, max(a*b, a-b));



    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> S(n+1);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        S[i+1] = S[i]+x+1;
    }
    int ans = 0;
    for (int i = 0; i+k <= n; ++i) {
        ans = max(ans, S[i+k]-S[i]);
    }
    printf("%.10lf\n", ans/2.0);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

map<ll, map<ll, ll>> memo;

map<ll, ll> prime_factorization(ll n) {
    map<ll, ll> m;
    ll x = n;
    ll d = 2;
    while (x > 1 && d * d <= n) {
        if (memo.count(x) > 0) {
            for (auto z : memo[x]) {
                m[z.first] += z.second;
            }
            x = 1;
            break;
        }
        if (x % d == 0) {
            m[d]++;
            x /= d;
        } else {
            d++;
        }
    }
    if (x != 1) m[x]++;
    return m;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> m;
    vector<map<ll, ll>> x(n);
    REP(i, n) {
        cin >> a[i];
        x[i] = prime_factorization(a[i]);
        memo[a[i]] = x[i];
        for (auto l : x[i]) {
            chmax(m[l.first], l.second);
        }
    }
    int ans = 0;
    REP(i, n) {
        ans += modinv(a[i], MOD);
        ans %= MOD;
    }
    ll z = 1;
    for (auto l : m) {
        z *= pow(l.first, l.second);
        z %= MOD;
    }
    cout << ans * z % MOD << EOL;
}


Measured memory_bytes: 6528
from itertools import product
s=input()
t=input()
t_point=-1
for i in range(len(s)-len(t)+1):
     for j in range(len(t)):
          if s[i+j]=='?':
               continue
          elif s[i+j]!=t[j]:
               break
     else:
          t_point=i
if t_point<0:
     print('UNRESTORABLE')
else:
     s=[x for x in s]
     for j in range(len(t)):
          s[t_point+j]=t[j]
     for i in range(len(s)):
          if s[i]=='?':
               s[i]='a'
     print(''.join(s))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        int MOD = 2019;
        int[] M = new int[N];
        M[0] = 1;
        for(int i=1;i<N;i++){
            M[i] = M[i-1] * 10;
            M[i] %= MOD;
        }
        long[] cnts = new long[2019];//0..2018 amari
        cnts[0] = 1;
        long sum = 0;
        int acc = 0;
        for(int i=0;i<N;i++){
            char keta = S.charAt(N-1-i);
            int k = keta-'0';
            int nowmod = k*M[i] % MOD;
            acc += nowmod;
            acc %= 2019;
            sum += cnts[acc];
            cnts[acc] ++;
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 41364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;
vector<vector<int>> idx(200001);
int main(){ 
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i], idx[a[i]].emplace_back(i);
  vector<int> dp(n+1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    (dp[i+1] += dp[i]) %= mod;
    int itr = lower_bound(idx[a[i]].begin(), idx[a[i]].end(), i) - idx[a[i]].begin();
    if (itr > 0) {
      int j = idx[a[i]][itr-1];
      if (i - j > 1) (dp[i+1] += dp[j+1]) %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
} 

Measured memory_bytes: 12800
#include<algorithm>
#include<chrono>
#include<ctime>  
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e6 + 10;

int n;
string s;
vector<int> graph[MAXN];

int cal(int src) {
	vector<int> vis(n);
	queue<int> q({src});
	vis[src] = 1;
	int step = 0, len;
	while(q.size()) {
		len = q.size();
		step++;
		while(len--) {
			auto front = q.front();
			q.pop();
			for(auto j : graph[front]) {
				if(!vis[j]) {
					q.push(j);
					vis[j] = step + 1;
				}
				else if(vis[j] != step + 1 && vis[j] != step - 1) {
					// debug << src << front << j << step << vis[j]<< endl;
					return -1;
				}
			}
		}
	}
	return step;
}
 
int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> s;
    	for(int j = 0; j < n; j++) {
    		if(i < j && s[j] == '1') {
    			graph[i].push_back(j);
    			graph[j].push_back(i);
    		}
    	}
    }

    int res = -1;
    for(int i = 0; i < n; i++) {
    	res = max(res, cal(i));
    }
    cout << res << endl;


    return 0;
 
}























Measured memory_bytes: 23936
#include<bits/stdc++.h>
#define  p5         100005
#define  p6         1000007
#define  PI         acos(-1)
#define  M          1000000007
#define  sc         scanf
#define  ss         second
#define  ff         first
#define  pf         printf
#define  scin(x)    sc("%d",&x)
#define  scin2(x,y) sc("%d%d",&x,&y)
#define  READ(f)    freopen(f, "r", stdin)
#define  WRITE(f)   freopen(f, "w", stdout)
#define  ll         long long
#define  pp         pair < int, int>
#define  pq         priority_queue
#define  pb         push_back
#define OK          pf("Yes\n")
#define _OK         pf("No\n")
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
map<pair<ll,ll>,ll>mp;
vector<ll>graph[p5+2];
vector<pair<ll,ll> >ar;
ll pa[p5+2],mx=-1;
bool visit[p5+2];
void bfs(ll x)
{
    visit[x]=1;
    queue<ll>q;
    q.push(x);
    while(!q.empty())
    {
        ll p=q.front();
        //cout<<p<<endl;
        q.pop();
        ll cnt=1;
        for(ll i=0; i<graph[p].size(); i++)
        {
            ll r=graph[p][i];
            ll a=p,b=r;
            if(visit[r]==0)
            {
                if(cnt==pa[p]) cnt++;
                pa[r]=cnt;
                mx=max(mx,cnt);
                visit[r]=1;
                if(a>b)
                    swap(a,b);
                q.push(r);
                mp[make_pair(a,b)]=cnt++;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,j,k;
    cin>>n;
    for(i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;
        graph[x].pb(y);
        graph[y].pb(x);
        ar.pb(make_pair(x,y));
        mp[make_pair(x,y)]=0;
    }
    bfs(1);
    cout<<mx<<endl;
    for(i=0; i<ar.size(); i++)
    {
        cout<<mp[ar[i]]<<endl;
    }
    return 0;
}
//https://github.com/me-shaon/bangla-programming-resources


Measured memory_bytes: 15344
(function(input) {
  'use strict';
  const DEBUT_POSSIBLE = [ 111, 222, 333, 444, 555, 666, 777, 888, 999];
  input.split("\n").forEach(function(line) {
    const lineNm = parseInt(line, 10)
    let MIN = 1100
    let res
    let flag = false
    DEBUT_POSSIBLE.forEach(element => {
      if (flag) return
      if (element == lineNm) {
        res = lineNm
        flag = true
      }
      const temAbs = Math.abs(element-lineNm)
      if (temAbs < MIN && element > lineNm) {
        MIN = temAbs
        res = element
      }
    });
    if (res) console.log(res);
  })
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int>x(n);
  for(int i=0; i<n; i++)cin >> x[i];
  priority_queue<int>q;
  for(int i=0; i<n-k+1; i++){
    int j=i+k-1;
    q.push(-(x[j]-x[i]+abs(x[i])));
    q.push(-(x[j]-x[i]+abs(x[j])));
  }
  int r=-q.top();
  cout << r;
  return 0;
}

Measured memory_bytes: 1276
N,K = map(int,input().split())
N = N+1
setK = set()
setK2 = set()
for i in range(1,N):
    if i%K == 0:
        setK.add(i)
    elif K%2 == 0 and i%K == K/2:
        setK2.add(i)
        
ans = (len(setK)) ** 3 + (len(setK2)) ** 3
print(ans)
        

Measured memory_bytes: 20884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005], x, n;
int main() {
	cin >> n;
  	for (int i=1; i<n; i++) {
      cin >> x; a[x]++;
    }
  	for (int i=1; i<=n; i++) cout << a[i] << "\n";
}

Measured memory_bytes: 4384
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int  second[MAX],count[MAX];
int num;

void CountingSort(short first[],short con){
  int i,j;
  //初期化
  for(i=0;i<=con;i++){
    count[i]=0;
  }
  for(j=1;j<=num;j++){
    count[first[j]]++;
  }
  for(i=1;i<=con;i++){
    count[i]=count[i]+count[i-1];
  }
  for(j=num;j>=1;j--){
    second[count[first[j]]]=first[j];
    count[first[j]]--;
  }
  //出力
  for(i=1;i<num;i++){
    printf("%d ",second[i]);
  }
  printf("%d\n",second[num]);
}

int main(){
  short first[MAX];
  int i;
  short conv=0;

  scanf("%d", &num);
  //firstは入力配列でsecondは出力配列
  for(i=1;i<=num;i++){
    scanf("%hd",&first[i]);
    if(conv<first[i]){
      conv=first[i];
    }
  }

  CountingSort(first,conv);
  return 0;
}



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

int p[10000];
int n;

int isPrime(int m){
  for(int i=0;i<n;i++){
    if(p[i]==m)return 1;
  }
  return 0;
}

int main(){
  int i,j,k,cnt=0;
  int q;
  cin>>q;
  int l[q],r[q];
  for(i=0;i<q;i++)cin>>l[i]>>r[i];
  for(i=2;i<=100000;i++){
    int flg=1;
    for(j=0;j<cnt;j++){
      if(i%p[j]==0){
        flg=0;
        break;
      }
    }
    if(flg)p[cnt++]=i;
  }
  n=cnt;
  int a[100001];
  a[1]=0;
  for(i=3;i<=100000;i++){
    if(i%2==1 && (isPrime(i)==1 && isPrime((i+1)/2)==1))a[i]=a[i-1]+1;
    else a[i]=a[i-1];
  }
  for(i=0;i<q;i++)cout<<a[r[i]]-a[l[i]-1]<<endl;
}

Measured memory_bytes: 1792
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n;
vi g[N];

int dfs(int c,int fa) {
  vi f;
  for(auto t : g[c]) if(t != fa)
    f.pb(dfs(t , c));
  f.pb(1);
  int res = 0;
  for(int i=0,d=0,j=0;i<20;++i) {
    int s = d;
    for(auto e : f)
      s += e >> i & 1;
    if(s == 1) {
      res |= 1 << i;
      if(d == 1) {
        rep(k,j,i) if(res >> k & 1)
          res ^= 1 << k;
        j = i;
      }
    }
    if(s >= 2)
      d = 1;
    else
      d = 0;
  }
  return res;
}

int main(){
  scanf("%d",&n);
  rep(i,1,n) {
    int u,v;
    scanf("%d%d",&u,&v);
    g[u].pb(v);
    g[v].pb(u);
  }
  printf("%d\n",31-__builtin_clz(dfs(1,0)));
  return 0;
}


Measured memory_bytes: 12544
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n), c(m), d(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	for (int i = 0; i < n; i++) {
		int f = abs(a[i] - c[0]) + abs(b[i] - d[0]), ans = 1;
		for (int j = 1; j < m; j++) {
			int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (tmp < f) {
				f = tmp;
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()

int main(){
    string s; cin>>s; int n = s.size(); int ans = 100000;
    rep(i, n-2) { int t = stoi(s.substr(i,3)); ans = min(ans, abs(t-753)); }
    cout<<ans<<endl;
}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int num_A = (A+D-1)/D;
    int num_B = (C+B-1)/B;
    if (num_A<num_B){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 3584
#include <stdio.h>

#define MAX 101
void selectionSort(int *,int);

int main(void){
  int A[MAX],i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  selectionSort(A,n);
  return 0;
}

void selectionSort(int A[],int n){
  int i,j,a,minj,tmp,count=0,flag;

  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]){
        minj=j;
      }
    }
    tmp = A[i];
    A[i]=A[minj];
    A[minj]=tmp;
    if(i!=minj)count++;
  }
  for(a=0;a<n;a++){
    printf("%d",A[a]);
    if(a!=n-1)printf(" ");
  }
  printf("\n%d\n",count);
}

Measured memory_bytes: 604
s = input()
k = int(input())

# tle
subst = set()
for fil_i in range(1, k+1):
    for ix in range(0, len(s)):
        if ix + fil_i <= len(s):

            subst.add(s[ix: ix + fil_i])
        else:
            break

ans = sorted(list(subst))
print(ans[k-1])


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int A, B, K;
	cin >> A >> B >> K;
	int ans;
	int idx = 0;
	for (int i = min(A, B); i > 0; i--)
	{
		if(A%i==0&&B%i==0){
			idx++;          
			if(idx==K) {
              ans=i;
              break;
            }
		}
	}
	
	cout << ans << endl;
}

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

int main(void){
    int n,ans = 0;
    cin >> n;
    string s[n];
    map<string,int> mp;
    
    for(int i = 0;i < n;i++)cin >> s[i];
    for(int i = 0;i < n;i++){
        mp[s[i]]++;
        ans = max(ans,mp[s[i]]);
    }
    
    for(auto i : mp){
        if(ans != i.second)continue;
        cout << i.first << endl;
    }
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int white = 0;
  int black = 0;
  for(int i=0; i<N; i++){
    if(S.at(i) == '.'){
      white++;
    }
    else{
      black++;
    }
  }
  int x_white = 0;
  int x_black = 0;
  int ans = N;
  for(int i=0; i<N; i++){
    if(S.at(i) == '.'){
      x_white++;
    }
    else{
      x_black++;
    }
    ans = min(ans,x_black + (white-x_white));
  }
  
  ans = min(ans,black);
  ans = min(ans,white);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

int main()
{
  int N;
  std::cin>>N;
  
  std::string c;
  std::cin>>c;
  
  int result=0;
  for(int i=0,j=N-1;i<j;i++)
  {
    if(c[i]=='W')
    {
      for(;i<j;j--)
      {
        if(c[j]=='R')
        {
          result++;
          auto t=c[i];
          c[i]=c[j];
          c[j]=t;
          j--;
          break;
        }
      }
    }
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

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

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

  while (q--) {
    int c, a, n;
    cin >> c >> a >> n;

    int ans = 0;

    int d = min({c, a, n});
    c -= d;
    a -= d;
    n -= d;
    ans += d;

    d = min(c / 2, a);
    c -= 2 * d;
    a -= d;
    ans += d;

    ans += c / 3;

    cout << ans << endl;
  }
}

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

LL n, V;

int main(){
	scanf("%lld %lld", &n, &V);
	LL t = 2LL;
	
	LL ans = 1;
	while(t * t <= V){
		if(V%t == 0){
			int cnt = 0;
			while(V%t == 0)
				++cnt, V /= t;
			
			cnt /= n;
			while(cnt--)
				ans *= t;
		}
		
		++t;
	}
	
	if(V > 1){
		if(n == 1)
			ans *= V;
	}
	
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;
  T e;
 
  T f(T a, T b) {return max(a, b);}
  void g(T &a, T b) {a = b;}
 
  SegmentTree (int sz, T init = 0) {
    n = 1; e = init; while (n < sz) n <<= 1;
    node.assign(2*n, init);
    for (int i = n - 2; i >= 0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }
 
  void update(int k, T x) {
    k += (n - 1);
    g(node[k], x);
    while (k > 0) {
      k = (k - 1) >> 1;
      node[k] = f(node[2*k+1], node[2*k+2]);
    } 
  }
 
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
 
  T getvalue(int k) {
    return query(k,k+1);
  }
  
  template <typename F> 
  int find (int a, int b, T x, F &ok, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (!ok(node[k]) || r <= a || b <= l) return b;
    if (k >= n - 1) return k - n + 1;
    int vl = find(a, b, x, ok, 2*k+1, l, (l + r)/2);
    if (vl != b) return vl;
    return find(a, b, x, ok, 2*k+2, (l + r)/2, r);
  }
 
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  SegmentTree<int> dp(300010);

  for (int i = 0; i < n; i++) {
    int l = max(0, a[i] - k), r = min(300000, a[i] + k);
    int b = dp.query(l, r + 1) + 1;
    if (b > dp.query(a[i], a[i] + 1)) dp.update(a[i], b);
  }

  cout << dp.query(0, 300010) << endl;
  return 0; 
}

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

using namespace std;

int main()
{
  bool isPrime[300001];
  for(int i = 0; i <= 300000; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i*i <= 300000; i++){
    if(isPrime[i]){
      for(int j = 2 * i; j <= 300000; j += i) isPrime[j] = false;
    }
  }

  int n;
  while(cin >> n, n){
    int cnt = 0;
    for(int i = n + 1; i <= 2 * n; i++){
      if(isPrime[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1452
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

mod = 998244353
n,s = inpl()
a = inpl()
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(s+1):
        dp[i+1][j] = dp[i][j] * 2
        if j - a[i] >= 0:
            dp[i+1][j] += dp[i][j-a[i]]
        dp[i+1][j] %= mod
# print(dp)
print(dp[-1][-1])

Measured memory_bytes: 144364
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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;}

int b[200001] = {};

int main () {
  int N, K; cin >> N >> K;
  vi A(N); REP(i,N) cin >> A[i];

  REP(i,N) {
    b[A[i]]++;
  }

  int s = 0;
  REP(i,200001) {
    if (b[i]) s++;
  }
  int d = K - s;

  if (d >= 0) {
    cout << 0 << endl;
    return 0;
  }

  d = abs(d);
  sort(b,b+200001);

  int ans = 0;
  int cnt = 0;
  for (int i = 0; cnt < d; i++) {
    ans += b[i];
    if (b[i]) cnt++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();

            var n = cin.nextInt();
            int[] d = new int[n];
            for (int i = 0; i < n; i++)
            {
                d[i] = cin.nextInt();
            }
            Array.Sort(d);

            int odd = d.Length / 2;

            
            if(d[odd] == d[odd - 1])
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine( d[odd] - d[odd - 1]);
            }
        }

       
    }

    class Point
    {
        public int x { get; set; }
        public int y { get; set; }
    }


    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 18784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <limits>

using namespace std;

typedef std::pair<int, int> P;

std::vector<std::vector<int>> map;
int x, y;
int ans = std::numeric_limits<int>::max();//??????

void dfs(int count, std::vector<std::pair<int, int>> delta, int posi, int posj) {//???????????§??????????????????
	if (count > 10) {
		return;
	}
	if (map[posi][posj] == 3) {
		ans = std::min(ans, count);
		return;
	}
	auto copy = map;
	for (auto i = 0; i < delta.size();i++) {
		copy[delta[i].first][delta[i].second] = 0;//??????????????£????????????????§????
	}
	if (posi + 1 < y) {
		if (copy[posi + 1][posj] != 1) {
			for (int i = posi; i < y; i++) {
				if (copy[i][posj] == 1) {
					auto deltacopy = delta;
					deltacopy.push_back(std::make_pair(i, posj));
					dfs(count + 1, deltacopy, i - 1, posj);
					break;
				}
				if (copy[i][posj] == 3) {
					dfs(count + 1, delta, i, posj);
					break;
				}
			}
		}
	}
	if (posi - 1 >= 0) {
		if (copy[posi - 1][posj] != 1) {
			for (int i = posi; i >= 0; i--) {
				if (copy[i][posj] == 1) {
					auto deltacopy = delta;
					deltacopy.push_back(std::make_pair(i, posj));
					dfs(count + 1, deltacopy, i + 1, posj);
					break;
				}
				if (copy[i][posj] == 3) {
					dfs(count + 1, delta, i, posj);
					break;
				}
			}
		}
	}
	if (posj + 1 < x) {
		if (copy[posi][posj + 1] != 1) {
			for (int j = posj; j < x; j++) {
				if (copy[posi][j] == 1) {
					auto deltacopy = delta;
					deltacopy.push_back(std::make_pair(posi, j));
					dfs(count + 1, deltacopy, posi, j - 1);
					break;
				}
				if (copy[posi][j] == 3) {
					dfs(count + 1, delta, posi, j);
					break;
				}
			}
		}
	}
	if (posj - 1 >= 0) {
		if (copy[posi][posj - 1] != 1) {
			for (int j = posj; j >= 0; j--) {
				if (copy[posi][j] == 1) {
					auto deltacopy = delta;
					deltacopy.push_back(std::make_pair(posi, j));
					dfs(count + 1, deltacopy, posi, j + 1);
					break;
				}
				if (copy[posi][j] == 3) {
					dfs(count + 1, delta, posi, j);
					break;
				}
			}
		}
	}
}

int main() {
	while (cin >> x >> y, x * y) {
		map.resize(y);
		int si, sj;
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				int A;
				cin >> A;
				map[i].push_back(A);
				if (A == 2)si = i, sj = j;
			}
		}
		dfs(0, {}, si, sj);
		if (ans == std::numeric_limits<int>::max()) ans = -1;
		std::cout << ans << std::endl;
		ans = std::numeric_limits<int>::max();
		map.clear();
	}
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
const int INF = 1e9;
using namespace std;

int main(void) {
    int N;
    string S;
    cin>>N>>S;
    // E[i] : i以下のEの個数、W[i] : i以下のWの個数
    int E[N + 1],W[N + 1];
    E[0] = 0;
    W[0] = 0;
    for (int i = 1; i <= N; i++) {
        if (S[i - 1] == 'E') {
            E[i] = E[i - 1] + 1;
            W[i] = W[i - 1];
        }
        else {
            W[i] = W[i - 1] + 1;
            E[i] = E[i - 1];
        }
    }
    int mi = INF;
    // リーダの位置でループを回す
    for (int i = 1; i <= N; i++) {
        int num;
        num = W[i - 1] + (E[N] - E[i]);
        if (mi > num) mi = num;
    }
    cout << mi << endl;
    return 0;
}

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

int main()
{
    int N,d;
    int A[110]={0};
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> d;
        A[d] = 1;
    }
    d = 0;
    for(int i=0; i<110; i++){
        d += A[i];
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static PrintWriter p = new PrintWriter(System.out, true);

	public static void main(String[] args) throws Exception {
		
		try {
			int n = Integer.parseInt(sc.nextLine());
			Map<String, Integer> map = new HashMap<>();
			int ma = Integer.MIN_VALUE;
			for(int i=0;i<n;i++)
			{
				String s = sc.nextLine();
				map.put(s, map.getOrDefault(s, 0)+1);
				ma = Math.max(ma,map.get(s));
			}
			TreeMap<String, Integer> sorted = new TreeMap<>(); 
			sorted.putAll(map); 
			for(Map.Entry<String, Integer> m:sorted.entrySet()) {
				if(ma==m.getValue()) {
					System.out.println(m.getKey());
				}
			}
						
		}catch(Exception i) {}
	}

	private static StringBuilder reverse(StringBuilder sb) {
		// TODO Auto-generated method stub
		return null;
	}
}

Measured memory_bytes: 182416
N = int(input())
A = list(map(int, input().split()))

A_i = [A[i] - i - 1 for i in range(N)]
A_i.sort()
if N % 2 == 1:
    b = A_i[N // 2]
    ans = 0
    for a in A_i:
        ans += abs(a - b)

    print(ans)
else:
    b1 = A_i[N // 2]
    b2 = A_i[N // 2 - 1]
    ans1 = 0
    ans2 = 0
    for a in A_i:
        ans1 += abs(a - b1)
        ans2 += abs(a - b2)
    print(min(ans1, ans2))


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for(int i = 0; i < (int)(n) ; i++)

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

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


void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B,
           std::vector<long long> C) {
    long long dist[2550] = {};
    bool reachable1[2550] = {};
    bool reachable2[2550] = {};

    reachable1[0] = true;
    reachable2[N - 1] = true;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            reachable1[B[j] - 1] |= reachable1[A[j] - 1];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            reachable2[A[j] - 1] |= reachable2[B[j] - 1];
        }
    }

    for (int i = 0; i < N; i++)
        dist[i] = -1e9;

    dist[0] = 0;

    long long ans = 0;
    for (int i = 0; i <= N; i++) {
        vector<int> visit(N);
        for (int j = 0; j < M; j++) {
            visit[B[j] - 1] |= chmax(dist[B[j] - 1], dist[A[j] - 1] + C[j] - P);
        }
        if (i == N) {
            for (int j = 0; j < N; j++)
                if (visit[j] && reachable1[j] && reachable2[j]) {
                    cout << -1 << endl;
                    return;
                }
        }
    }
    cout << max(0ll, dist[N-1]) << endl;


}

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



Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n, x;
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> x;
		if(x%2==0){
			if(!(x%3==0 || x%5==0)){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

const int maxN = 200010;

class RMQ{
private:
	int n;
	P dat[maxN * 4];

	//[a,b),[l,r) //(Max,Min)
	P rec(int a, int b, int k, int l, int r){
		if (b <= l || r <= a)return P(-infi, infi);
		if (a <= l && r <= b)return P(dat[k].first, dat[k].second);
		else {
			P vl = rec(a, b, 2 * k + 1, l, (l + r) / 2), vr = rec(a, b, 2 * k + 2, (l + r) / 2, r);
			return P(std::max(vl.first, vr.first), std::min(vl.second, vr.second));
		}
	}

public:
	void init(int x){
		n = 1;
		while (n < x)n *= 2;
		rep(i, 2 * n - 1)dat[i] = P(-infi, infi);
	}

	void update(int k, int a){
		k += n - 1;
		dat[k] = P(a, a);
		while (k > 0){
			k = (k - 1) / 2;
			dat[k].first = std::max(dat[2 * k + 1].first, dat[2 * k + 2].first);
			dat[k].second = std::min(dat[2 * k + 1].second, dat[2 * k + 2].second);
		}
	}

	//[a,b] //(Max,Min)
	P query(int a, int b){
		return rec(a, b + 1, 0, 0, n);
	}
};

struct Star{ int x, y, b; };
Star star[200001];
int n, d;
RMQ up, right;

bool comp(const Star &lhs, const Star &rhs){
	return lhs.b < rhs.b;
}

int main(){
	std::cin >> n >> d;
	rep(i, n)std::cin >> star[i].x >> star[i].y >> star[i].b;
	std::sort(star, star + n, comp);
	ll ans = 0;
	int first = 0;
	up.init(n), right.init(n);
	rep(i, n){
		up.update(i, star[i].y);
		right.update(i, star[i].x);
		while (star[i].b - star[first].b > d)++first;
		P a = up.query(first, i), b = right.query(first, i);
		ll mul = (ll)(a.first - a.second) * (b.first - b.second);
		ans = std::max(ans, mul);
	}
	std::cout << ans << std::endl;
	return 0;
}

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

std::string s;

int main() {
    std::cin >> s;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i-1]) {
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }
    std::cout << "Good" << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	int N;
	CIN(N);
	vector<int> T(N);
	ll sum = 0;
	REP(i, N) {
		int n;
		CIN(n);
		T[i] = n;
		sum += n;
	}
	int M;
	CIN(M);
	REP(i, M) {
		int p, x;
		CIN2(p, x);
		COUT(sum - (T[p - 1] - x));
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class RMQ{
  static const int MAX_N = 1<<22;
  static const ll INF = (ll)(1e17);
  ll RMQ_n;
  vector<ll> RMQ_dat;
public:
  RMQ(int n_) : RMQ_dat(2*MAX_N-1){
    RMQ_n=1;
    while(RMQ_n<n_) RMQ_n*=2;
    for(int i=0; i<2*RMQ_n-1; i++) RMQ_dat[i] = 0;
  }
  ll query(int a, int b){ return _query(a,b,0,0,RMQ_n); }
  ll _query(int a, int b, int k, int l, int r){
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return RMQ_dat[k];
    else{
      ll vl = _query(a,b,k*2+1,l,(l+r)/2);
      ll vr = _query(a,b,k*2+2,(l+r)/2,r);
      return max(vl, vr);
    }
  }
  void update(int i, ll x){
    i+=RMQ_n-1;
    RMQ_dat[i] = x;
    while(i>0){
      i=(i-1)/2;
      RMQ_dat[i] = max(RMQ_dat[i*2+1], RMQ_dat[i*2+2]);
    }
  }
};

int main(){
  int N;
  cin >> N;
  vector<int> v;
  vector<ll> w;
  rep(i,N){
    int h;
    cin >> h;
    v.push_back(h);
  }
  rep(i,N){
    ll a;
    cin >> a;
    w.push_back(a);
  }

  RMQ rmq(200005);
  rep(i,N){
    int h = v[i];
    ll a = w[i];

    ll x = rmq.query(0,h);
    rmq.update(h, x + a);
  }
  
  ll ret = 0;
  rep(i,200004){
    ret = max(ret, rmq.query(i,i+1));
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 68336
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    string S; cin >> S;
    if(S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
m,d=map(int,input().split())
count=0
for i in range(1,m+1):
    for j in range(1,d+1):
        if j>=10:
            d1=int(str(j)[-1])
            d2=int(str(j)[0])
            if d1>=2 and d2>=2 and d1*d2==i:
                count+=1
print(count)


Measured memory_bytes: 3060
from sys import stdin
from math import factorial

if __name__ == '__main__':

    N, K = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = 1000000007
    r = 0
    for r in range(K):
        r += 1
        n = N - K + 1

        if n - r < 0 or K - r < 0:
            print(0)
            continue

        ret = factorial(n) // factorial(r) // factorial(n - r)
        ret2 = factorial(K-1) // factorial(r-1) // factorial((K - 1) - (r - 1))

        print((ret * ret2) % tmp)


Measured memory_bytes: 3316
#include <stdio.h>
int main(){
    int a,b,c,x,i,j,k,r=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(i=0;i<=x/500;i++)for(j=0;j<=(x-500*i)/100;j++){
        k=x-500*i-100*j;
        r+=k%50==0&&c>=k/50&&a>=i&&b>=j;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 1724
R, C, K = map(int, input().split())
inf = float('inf')
v_list = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    v_list[r - 1][c - 1] = v

dp = [[0, 0, 0, 0] for _ in range(C)]
for r in range(R):
    for c in range(C):
        if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
        if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])            
print(max(dp[-1]))

Measured memory_bytes: 155148