akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
vector<pair<int,int> > blist[1024];
set<int> already;
vector<int> bugs;
int cost(int node,int rootcost)
{
  if(bugs[node]) return rootcost;
  int tmp=0,edgecost,nextnode;
  REP(i,SZ(blist[node])){
    tie(nextnode,edgecost)=blist[node][i];
    if(already.insert(nextnode).second)
      tmp+=cost(nextnode,edgecost);
  }
  if(rootcost<tmp) tmp=rootcost;
  return tmp;
}
int main(void)
{
  bugs.PB(0);
  int n;
  cin >> n;
  REP(i,n-1){
    int tmp;
    cin >> tmp;
    bugs.PB(tmp);
  }
  REP(i,n-1){
    int a,b,c;
    cin >> a >> b >> c;
    blist[a].PB(MP(b,c));
    blist[b].PB(MP(a,c));
  }
  already.insert(0);
  cout << cost(0,1000000) << endl;
  return 0;
}

Measured memory_bytes: 1284
S=input()
l=len(S)

for i in range(1<<(l-1)):
  Q=[]
  ans=int(S[0])
  for j in range(l-1):
    if (i>>j)&1:
      Q.append('+')
    else:
      Q.append('-')
  for k in range(l-1):
    if Q[k]=='+':
      ans+=int(S[k+1])
    else:
      ans-=int(S[k+1])
  if ans==7:
    ret=str(S[0])
    for k in range(l-1):
      ret+=Q[k]
      ret+=S[k+1]
    ret+='=7'
    print(ret)
    exit()

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;
 
int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=n*m-2*(n+m)+4;
  if(n==1&&m==1)ans=1;
  else if(n==1||m==1)ans=n*m-2;
  cout<<ans<<endl;
  return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  int a[100], b[100];
  for (int i = 0; i < n - 1; ++i)
  {
    cin >> b[i];
  }
  
  a[0] = b[0];
  a[n-1] = b[n-2];
  
  for (int i = 1; i < n - 1; ++i)
  {
    a[i] = b[i - 1] < b[i] ? b[i - 1] : b[i];
  }
  
  int sum;
  for (int i = 0; i < n; ++i)
  {
    sum += a[i];
  }
  cout << sum << endl;
  
  return 0;
}


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

using namespace std;


const int maxn = 1e5+5;
struct node{
	int ls,rs;
	int se,ad,minv,maxv;
}z[maxn*60];//24M * 6
int tot,rt;
int X,K,Q;
int R[maxn];
int T[maxn],A[maxn];
int newp(int L,int R) {
	int p = ++tot;
	z[p].se = -1; z[p].ad = 0;
	z[p].minv = L; z[p].maxv = R;
	return p;
}
void upd(int p) {
	z[p].minv = min(z[z[p].ls].minv,z[z[p].rs].minv);
	z[p].maxv = max(z[z[p].ls].maxv,z[z[p].rs].maxv);
}
void ptd(int p,int l,int mid,int r) {
	if(!z[p].ls) z[p].ls = newp(l,mid);
	if(!z[p].rs) z[p].rs = newp(mid+1,r);
	if(z[p].se!=-1) {
		z[z[p].ls].se = z[z[p].rs].se = z[z[p].ls].minv = z[z[p].rs].minv = 
		z[z[p].ls].maxv = z[z[p].rs].maxv = z[p].se;
		z[z[p].ls].ad = z[z[p].rs].ad = 0;
		z[p].se = -1;
	}
	if(z[p].ad!=0) {
		z[z[p].ls].minv += z[p].ad;
		z[z[p].rs].minv += z[p].ad;
		z[z[p].ls].maxv += z[p].ad;
		z[z[p].rs].maxv += z[p].ad;		
		z[z[p].ls].ad += z[p].ad;
		z[z[p].rs].ad += z[p].ad;
		z[p].ad = 0;
	}
}
void segadd(int &p,int l,int r,int dd) {
	if(!p) p = newp(l,r);
	if(z[p].minv>=X-dd) {
		z[p].minv = z[p].maxv = z[p].se = X;
		z[p].ad = 0;
		return;
	} else if(z[p].maxv<=X-dd) {
		z[p].minv += dd; z[p].maxv += dd; z[p].ad += dd;
		return;
	}
	int mid = (l+r)>>1;
	ptd(p,l,mid,r);
	segadd(z[p].ls,l,mid,dd) , segadd(z[p].rs,mid+1,r,dd);
	upd(p);
}
void segsub(int &p,int l,int r,int dd) {
	if(!p) p = newp(l,r);
	if(z[p].maxv<=dd) {
		z[p].minv = z[p].maxv = z[p].se = 0;
		z[p].ad = 0;
		return;
	} else if(z[p].minv>=dd) {
		z[p].minv -= dd; z[p].maxv -= dd; z[p].ad -= dd;
		return;
	}
	int mid = (l+r)>>1;
	ptd(p,l,mid,r);
	segsub(z[p].ls,l,mid,dd) , segsub(z[p].rs,mid+1,r,dd);
	upd(p);
}
int query(int &p,int l,int r,int x) {
	if(!p) p = newp(l,r);
	if(l==r) return z[p].minv;
	int mid = (l+r)>>1;
	ptd(p,l,mid,r);
	if(x<=mid) return query(z[p].ls,l,mid,x);
	else return query(z[p].rs,mid+1,r,x);
}
int main() {
	scanf("%d%d",&X,&K);
	for(int i=1;i<=K;i++) {
		scanf("%d",&R[i]);
	}
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++) {
		scanf("%d%d",&T[i],&A[i]);
	}
	R[K+1] = 1e9+1;
	int RE = 0;
	int now = 1;
	for(int i=0;i<=K;i++,RE^=1) {
		while(now<=Q&&T[now]<=R[i+1]) {
			int tm = query(rt,1,X,A[now]);
			if(RE==0) tm = max(0,tm-T[now]+R[i]);
			else tm = min(X,tm+T[now]-R[i]);
			now++;
			printf("%d\n",tm);
		}
		if(now==Q+1) return 0;
		if(!RE) segsub(rt,1,X,R[i+1]-R[i]);
		else segadd(rt,1,X,R[i+1]-R[i]);
	}
	return 0;
}

Measured memory_bytes: 66688
N, W = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
DP=[[0]*(W+1) for i in range(N+1)]
for i in range(1, W+1):
    DP[0][i] = float("-inf")
for i in range(1, N+1):
    for j in range(W+1):
        if j-X[i-1][0] >= 0:
            DP[i][j] = max(DP[i-1][j], DP[i-1][j-X[i-1][0]]+X[i-1][1])
        else:
            DP[i][j] = DP[i-1][j]
print(max(DP[N]))
                    
#最後から2行目。
#ありえないのは-INFで選ばれないように


Measured memory_bytes: 306168
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>


using namespace std;

int main(void){
 char s[5];
 map<char,int> s_cnt;
 int check=0;

 cin>>s;
 
 for(int i=0; i<strlen(s);i++){
  s_cnt[s[i]]++; 
  if(s_cnt[s[i]]==2)check++;
 }
 
 if(check==2)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

 return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const int N = 1e6 + 1;

void solve() {
	ll a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if (abs(a - b) <= t * (v - w)) {
		cout << "YES" << endl;	
	} else {
		cout << "NO" << endl;
	}
}

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


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
    int N,K;
    scanf("%d%d",&N,&K);

    //使用可能なら1,無理なら0
    int c[10];
    for(int i=0;i<10;i++) c[i]=1;

    for(int i=0;i<K;i++){
        int D;
        scanf("%d",&D);
        c[D]=0;
    }

    int ans;
    int M=N;
    while(1){
        int tmp=M;
        int flg=1;
        while(tmp){
            int digit=tmp%10;
            if(!c[digit]){
                flg=0;
                break;
            }
            else{
                tmp=(tmp-digit)/10;
            }
        }
        if(flg){
            ans=M;
            break;
        }
        else M++;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
S=A[0]+A[1]
X=0
for i in range(2,N):
    X=X^A[i]
if (S-X)%2==1 or S<X:
    print(-1)
    exit()
D=(S-X)//2
if X&D!=0:
    print(-1)
    exit()
a=0
#print(X,D)
B=[0 for i in range(42)]
for k in range(41,-1,-1):
    x=(X&(1<<k))>>k
    d=(D&(1<<k))>>k
    if (x,d)==(0,0):
        pass
    elif (x,d)==(0,1):
        a=a^(1<<k)
    elif (x,d)==(1,0):
        B[k]=1
    else:
        pass
for k in range(41,-1,-1):
    if B[k]==0:
        continue
    if a^(1<<k)<A[0]:
        a=a^(1<<k)
if 0<a<=A[0]:
    print(A[0]-a)
else:
    print(-1)


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

int main(void) {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  int count = 1;
  int minp = P.at(0);
  for (int i = 1; i < N; i++) {
    if (minp > P.at(i)) {
      count++;
      minp = P.at(i);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int cost(pii a,pii b) {
    return abs(a.first-b.first)+abs(a.second-b.second);
}
signed main() {
    int H,W,D;
    cin>>H>>W>>D;
    vector<vector<int>> A(H,vector<int>(W));
    cin>>A;
    vector<pii> pos(H*W);
    REP(i,H) {
        REP(j,W) {
            pos[A[i][j]-1]={i,j};
        }
    }
    vector<int> sum(H*W,0);
    REP(i,H*W) if(i-D>=0) sum[i]=sum[i-D]+cost(pos[i-D],pos[i]);

    int Q;
    cin>>Q;
    while(Q--) {
        int L,R;
        cin>>L>>R;
        R--,L--;
        cout<<sum[R]-sum[L]<<endl;
    }
    return 0;
}



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

using namespace std;

int main() {
    int n;
    cin >> n;
    map<long long, bool> m;
    vector<long long> a(n);

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

    for(int i=0; i<n; i++) {
        long long key = a.at(i);

        if (m.count(key)) {
            cout << "NO" << endl;
            return 0;
        }
        else {
            m[key] = true;
        }
    }

    cout << "YES" << endl;

    return 0;
}



Measured memory_bytes: 14464
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)n; ++i)

int n, an[500 * 500 + 2], p = 1;
pair<int, int> x[500];

void no(){
	printf("No\n");
	exit(0);
}

void fill(int id, int f, int l, int r){
	while (an[p])++p;
	while (f && p >= l && p <= r){
		if (!an[p])an[p] = id, --f;
		++p;
	}
	if (f)no();
}

int main(){
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", &x[i].first), x[i].second = i + 1;
	sort(x, x + n);
	f(i, 0, n){
		fill(x[i].second, x[i].second - 1, 1, x[i].first - 1);
		an[x[i].first] = x[i].second;
	}
	f(i, 0, n)fill(x[i].second, n - x[i].second, x[i].first + 1, n * n);
	printf("Yes\n%d", an[1]);
	int nn = n * n;
	f(i, 2, nn + 1)printf(" %d", an[i]);
	printf("\n");
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 ll n,ans;
 cin >> n;
 if(n%2==1){
   cout << 0;
   return 0;
 }else{
   n/=10;
   ll i=1,ans=0;
   while(n>0){
     ans+=i*n;
     n/=5;
   }
   cout << ans;
   return 0;
 }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;


using ll = long long;

ll n, k;
ll a[5678];
int dp[2][5678][5678];//0:left 1:right


int main(void)
{
	cin >> n >> k;
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i];
		if (k < a[i])a[i] = k;
	}
	if (n == 1)
	{
		cout << ((a[0] >= k) ? 0 : 1) << endl;
		return 0;
	}
	for (ll x = 0; x <= k; ++x)
	{
		dp[0][0][x] = 0;
	}
	dp[0][0][0] = 1;
	for (ll p = 1; p <= n; ++p)
	{
		for (ll x = 0; x <= k; ++x)
		{
			dp[0][p][x] = dp[0][p - 1][x];
			if (x - a[p - 1] >= 0)
				dp[0][p][x] |= dp[0][p - 1][x - a[p - 1]];
		}
	}
	for (ll x = 0; x <= k; ++x)
	{
		dp[1][n][x] = 0;
	}
	dp[1][n][0] = 1;
	for (ll p = n - 1; p >= 0; --p)
	{
		for (ll x = 0; x <= k; ++x)
		{
			dp[1][p][x] = dp[1][p + 1][x];
			if (x - a[p] >= 0)
				dp[1][p][x] |= dp[1][p + 1][x - a[p]];
		}
	}
	ll ans = 0;
	for (ll s = 0; s < n; ++s)
	{
		ll lef = s;
		ll rht = s + 1;
		ll bot = k - a[s];//下限
		if (bot <= 0)bot = 0;
		ll range = k - bot;
		bool ismake = false;

		vector<ll>rimos;
		rimos.reserve(k);
		rimos.push_back(0);
		for (ll x = 0; x <= k; ++x)
		{
			rimos.push_back(rimos.back() + dp[1][rht][x]);
		}
		for (ll col = 0; col <= bot; ++col)
		{
			ll now = dp[0][lef][col];
			if (now && (rimos[bot - col + range] - rimos[bot - col]))
			{
				ismake = true;
			}
		}
		//残り(コーナー)
		for (ll col = bot + 1; col <= k; ++col)
		{
			ll now = dp[0][lef][col];
			if (now && (rimos[bot - col + range] - rimos[0]))
			{
				ismake = true;
			}
		}
		if (!ismake)++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 227712
#include<bits/stdc++.h>
using namespace std;
long long n[50050],f[100050],zs,a,lefts,rights;
bool b[100050];
int main()
{
	b[0]=1,b[1]=1;
	for(int s=2;s<=100005;s++)
	{
		if(!b[s])
		{
			n[zs++]=s;
		}
		for(int v=0;v<zs;v++)
		{
			if(s*n[v]>100005)break;
			b[n[v]*s]=true;
			if(s%n[v]==0)break;
		}
	}
	cin>>a;
	for(int s=2;s<=100005;s++)
	{
		if(s%2==1&&b[s]==0&&b[(s+1)/2]==0)
		f[s]=1;
		f[s]+=f[s-1];
	}
	while(a--)//输入
	{
		cin>>lefts>>rights;
		cout<<f[rights]-f[lefts-1]<<endl;
	}
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

int bit[100009];

void add(int pos, int x) {
	pos++;
	while (pos <= 100008) { bit[pos] += x; pos += (pos&-pos); }
}
int sum(int pos) {
	pos++; int s = 0;
	while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); }
	return s;
}

long long solve(vector<int>A) {
	for (int i = 0; i < 100009; i++) bit[i] = 0;
	long long ret = 0;
	for (int i = 0; i < A.size(); i++) {
		ret += sum(100005) - sum(A[i]);
		add(A[i], 1);
	}
	return ret;
}

int N, A[3][100009], C[100009]; bool U[100009];

int main() {
	cin >> N;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < N; j++) cin >> A[i][j];
	}
	for (int i = 0; i < N; i++) {
		int minx = min({ A[0][i], A[1][i], A[2][i] });
		if (minx % 3 != 1) {
			cout << "No" << endl;
			return 0;
		}
		if (A[0][i] == minx && A[1][i] == minx + 1 && A[2][i] == minx + 2) { C[i] = minx / 3; U[i] = false; }
		else if (A[0][i] == minx + 2 && A[1][i] == minx + 1 && A[2][i] == minx) { C[i] = minx / 3; U[i] = true; }
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	vector<int>vec1, vec2; long long G1 = 0, G2 = 0;
	for (int i = 0; i < N; i += 2) { vec1.push_back(C[i]); if (U[i] == true) G1++; }
	for (int i = 1; i < N; i += 2) { vec2.push_back(C[i]); if (U[i] == true) G2++; }
	for (int i = 0; i < vec1.size(); i++) {
		if (vec1[i] % 2 == 1) { cout << "No" << endl; return 0; }
	}
	for (int i = 0; i < vec2.size(); i++) {
		if (vec2[i] % 2 == 0) { cout << "No" << endl; return 0; }
	}
	long long v1 = solve(vec1);
	long long v2 = solve(vec2);

	// 1 -> 2 の場合
	if ((G1 + v2) % 2 == 0 && (G2 + v1) % 2 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std; 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pii pair<int ,int > 
#define pb push_back
#define mo 1000000007
ll a[200005];int h[200005];int b[200005];
ll tree[800005];int n ; 

void update(int node , int start , int end , int idx , ll val)
{
	if(start==end)
	{
		a[start]= val; 
		tree[node]= val ; 
		return;
	}
	int mid = (start+end)/2; 
	
	if(idx<=mid)
	{
		update(node*2+1, start, mid, idx, val);
	}
	else
	update(node*2+2, mid+1, end , idx, val);
	
	tree[node]= max(tree[node*2+1],tree[node*2+2]);
}

ll query(int node, int start , int end , int l , int r)
{
	if(end<l||start>r)
	return(0);//0 in case of sum , high value in case of min , low value in case of max and soooo on 
	
	if(l<=start&&r>=end)
	return(tree[node]);
	int mid = (start+end)/2 ; 
	ll p1 = query(node*2+1, start, mid, l, r);
	ll p2 = query(node*2+2, mid+1, end , l ,r);
	return(max(p1,p2));
}
int main()
{
ios; 
int n ; 
cin>>n;
for(int i = 0; i<n ; i++)
cin>>h[i];
for(int j = 0; j<n ; j++)
cin>>b[j];
ll ans = 0; 
for(int i= 0; i<n ; i++)
{
	ll temp =(ll) b[i]+ query(0,0,n,1,h[i]-1);
	ans = max(ans, temp);
	if(temp>a[h[i]])
	update(0,0,n,h[i],temp);
	
}
cout<<ans; 
return(0);
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    ll part_sum1 = 0;
    ll part_sum2 = 0;
    ll ans1 = 0;
    ll ans2 = 0;
    ll ans = 0;
    if (vec[0] <= 0){
        part_sum1 = 1;
        ans1 = 1 - vec[0];
    }
    else{
        part_sum1 = vec[0];
    }
    for (ll i = 1; i <= N - 1; i++){
        if (i % 2 == 1){
            if (part_sum1 + vec[i] >= 0){
                ans1 += part_sum1 + vec[i] + 1;
                part_sum1 = -1;
            }
            else{
                part_sum1 += vec[i];
            }
        }
        else{
            if (part_sum1 + vec[i] <= 0){
                ans1 += 1 - (part_sum1 + vec[i]);
                part_sum1 = 1;
            }
            else{
                part_sum1 += vec[i];
            }
        }
    }
    if (vec[0] >= 0){
        part_sum2 = -1;
        ans2 = 1 + vec[0];
    }
    else{
        part_sum2 = vec[0];
    }
    for (ll i = 1; i <= N - 1; i++){
        if (i % 2 == 1){
            if (part_sum2 + vec[i] <= 0){
                ans2 += 1 - (part_sum2 + vec[i]);
                part_sum2 = 1;
            }
            else{
                part_sum2 += vec[i];
            }
        }
        else{
            if (part_sum2 + vec[i] >= 0){
                ans2 += 1 + part_sum2 + vec[i];
                part_sum2 = -1;
            }
            else{
                part_sum2 += vec[i];
            }
        }
    }
    ans = min(ans1, ans2);
    cout << ans << endl;
}


Measured memory_bytes: 3988
#include <stdio.h>

int map[101][101];

int max(int H, int W, int S, int T){
    int x,y,i,j;
    int sum,max=0;
    for(y=1;y+T-1<=H;y++){
        for(x=1;x+S-1<=W;x++){
            sum=0;
            for(i=0;i<T;i++){
                for(j=0;j<S;j++){
                    if(map[x+j][y+i]) sum++;
                }
            }
            if(sum>max)max=sum;
        }
    }
    return max;
}

int main(void){
    int N,i,j;
    while(scanf("%d",&N),N){
        int H,W;
        scanf("%d %d",&W,&H);
        int x,y;
        for(y=1;y<=H;y++){
            for(x=1;x<=W;x++){
                map[x][y]=0;
            }
        }
        for(i=0;i<N;i++){
            scanf("%d %d", &x,&y);
            map[x][y]=1;
        }
        int S,T;
        scanf("%d %d", &S,&T);
        printf("%d\n",max(H,W,S,T));
    }
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,A,B;

int main(){
    cin>>N>>A>>B;
    out(min(A*N,B));

    
    
}


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

using namespace std;

int main() {
    string S;
    cin >> S;

    string ans = "No";
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ans = "Yes";
    if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ans = "Yes";
    if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) ans = "Yes";
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> u(n), v(n);
	for(int i = 0; i < n; ++i){
		ll x, y;
		cin >> x >> y;
		u[i] = x + y;
		v[i] = x - y;
	}
	const bool even = (u[0] % 2 == 0);
	for(int i = 0; i < n; ++i){
		if((u[i] % 2 == 0) != even){
			cout << -1 << endl;
			return 0;
		}
		if(even){
			--u[i];
			--v[i];
		}
	}
	const int m = 32;
	cout << (m + (even ? 1 : 0)) << endl;
	for(int i = m - 1; i >= 0; --i){
		cout << (1ll << i) << " ";
	}
	if(even){ cout << 1; }
	cout << endl;
	for(int i = 0; i < n; ++i){
		const ll base = (1ll << m) - 1;
		vector<char> solution;
		ll cu = u[i], cv = v[i];
		for(int j = m - 1; j >= 0; --j){
			const ll d = (2ll << j);
			int dmask = 0;
			if(cu - d >= -base){
				cu -= d;
				dmask |= 1;
			}
			if(cv - d >= -base){
				cv -= d;
				dmask |= 2;
			}
			solution.push_back("LUDR"[dmask]);
		}
		if(even){ solution.push_back('R'); }
		solution.push_back('\0');
		cout << solution.data() << endl;
	}
	return 0;
}



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

struct Node
{
    int key;
    Node *parent,*right,*left;
};
Node *root = NULL;
void inserts(int key)
{
    Node *z,*y,*x;
    z = (Node*)malloc(sizeof(Node));
    z->key = key;
    z->left = z->parent = z->right = NULL;
    y = NULL;
    x = root;
    while(x!=NULL)
    {
        y = x;
        if(x->key < z->key)
            x = x->right;
        else
            x = x->left;
    }
    z->parent = y;
    if(y==NULL){
        root = z;
    }
    else if(z->key < y->key){
        y->left = z;
    }
    else {
        y->right = z;
    }
}
void preParse(Node *x){
    if(x==NULL){
        return ;
    }
    printf(" %d",x->key);
    preParse(x->left);
    preParse(x->right);
}
void inParse(Node *x){
    if(x==NULL){
        return;
    }
    inParse(x->left);
    printf(" %d",x->key);
    inParse(x->right);
}
void print(){
    inParse(root);
    putchar('\n');
    preParse(root);
    putchar('\n');
}
int finda(int key){
    Node *x,*y = root;
    x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->left = x->parent = x->right = NULL;
    while(y!=NULL){
        if(x->key<y->key)
            y = y->left;
        else if(x->key>y->key)
            y = y->right;
        else if(x->key==y->key)
            return 1;
    }
    return 0;
}
int main()
{
    int m,key,i;
    char com[7];
    scanf("%d",&m);
    for(i = 0; i < m; i++)
    {
        scanf("%s",&com);
        if(com[0]=='i')
        {
            scanf("%d",&key);
            inserts(key);
        }
        else if(com[0]=='p')
        {
            print();
        }
        else if(com[0]=='f'){
            scanf("%d",&key);
            if(finda(key))printf("yes\n");
                else printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 21864
import sys
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]

    MOD = 10 ** 9 + 7

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, k, p):
        if (k < 0) or (n < k):
            return 0
        r = min(k, n - k)
        return fact[n] * factinv[k] * factinv[n - k] % p

    for i in range(2, 10 ** 6 + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    X = fact[M] * factinv[M - N]

    ans = 0
    for i in range(N + 1):
        c = fact[M - i] * factinv[(M - i) - (N - i)]
        if i % 2 == 0:
            ans += X * c * cmb(N, i, MOD)
        else:
            ans -= X * c * cmb(N, i, MOD)

        ans %= MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    rep(i,5)
    {
        int num;cin >> num;
        if(num==0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    

}

Measured memory_bytes: 3568
n = gets.to_i
a_arr = gets.split.map(&:to_i)

can_create = {0 => true}
a_arr.each do |a|
  can_create.keys.each do |k|
    can_create[k+a] = true
  end
end

q = gets.to_i
m_arr = gets.split.map(&:to_i)

m_arr.each do |m|
  puts can_create.key?(m) ? 'yes' : 'no'
end

Measured memory_bytes: 8724
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int n, m;
   cin >> n >> m;
   cout << (n - 1) * (m - 1) << endl;

   return 0;
}


Measured memory_bytes: 256
import fractions
a, b, k = map(int, input().split())

def mklist(a, b):
  nums = []
  for i in range(1, min(a, b)+1):
    if a % i == 0 and b % i == 0:
      nums.append(i)
  nums.sort(reverse=True)
  return nums

print(mklist(a,b)[k-1])


Measured memory_bytes: 5048
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut best = seq.clone();
    best.sort();
    for i in 0..n {
        for j in i..n {
            seq.swap(i, j);
            if seq == best {
                println!("YES");
                return;
            }
            seq.swap(i, j);
        }
    }
    println!("NO");
}


Measured memory_bytes: 4352
/*input
1000 1 1000 1 1000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=1005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n,a,b,c,d;

ll dp[maxn][maxn];
ll C[maxn][maxn];
ll meow[maxn][maxn];
ll f(int pp,int g){
	if(pp<0) return 0;
	if(pp==0) return 1;
	if(g>b) return 0;
	if(dp[pp][g]!=-1) return dp[pp][g];
	ll cnt=0;
	for(int i=c;i<=d&&i*g<=pp;i++){
		ll pre=C[pp][g*i]*meow[g][i]%MOD;
		cnt+=pre*f(pp-g*i,g+1)%MOD;
		//if(pp==3&&g==1) cout<<cnt<<'\n';
		if(cnt>=MOD) cnt-=MOD;
	}
	cnt+=f(pp,g+1);
	if(cnt>=MOD) cnt-=MOD;
	//cout<<pp<<' '<<g<<' '<<cnt<<'\n';
	return dp[pp][g]=cnt;
}

ll inv[maxn];

int main()
{
	//IOS;
	inv[1]=1;
	for(int i=2;i<maxn;i++){
		inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
	}

	for(int i=1;i<maxn;i++) REP(j,i+1){
		if(j==0||j==i) C[i][j]=1;
		else{
			C[i][j]=C[i-1][j-1]+C[i-1][j];
			if(C[i][j]>=MOD) C[i][j]-=MOD;
		}
	}
	for(int i=1;i<maxn;i++) for(int j=1;j*i<maxn;j++){
		if(j==1) meow[i][j]=1;
		else{
			meow[i][j]=meow[i][j-1]*C[i*j][i]%MOD;
			meow[i][j]=meow[i][j]*inv[j]%MOD;
		}
	}
	cin>>n>>a>>b>>c>>d;
	REP(i,maxn) REP(j,maxn) dp[i][j]=-1;
	cout<<f(n,a);

	return 0;
}


Measured memory_bytes: 23040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;
using D = double;
using LD = long double;
const int mod = 1e9+7;
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; }
int main(){
    int n; ll d,a; cin >> n >> d >> a;
    vector<ll> x(n), h(n);
    rep(i,n) cin >> x[i] >> h[i];
    vector<P> pos(n);
    rep(i,n) pos[i] = make_pair(x[i], h[i]);
    sort(ALL(pos));
    rep(i,n) {
        x[i] = pos[i].first;
        h[i] = pos[i].second;
    }
    ll ans = 0;
    vector<ll> s(n+1, 0);
    rep(i,n){
        if(s[i] < h[i]){
            ll cnt = (h[i] - s[i] + a - 1) / a;
            ll range = x[i] + 2*d;
            int reach = upper_bound(ALL(x), range) - x.begin();
            s[i] += cnt*a;
            s[reach] -= cnt*a;
            ans += cnt;
        }
        s[i+1] += s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int n,sol,a,b;
int usu(int x)
{
    int s=0;
    while(x)
    {
        s+=x%10;
        x/=10;
    }
    return s;
}
int main()
{
    sol=2e9;
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<n;++i)
    {
        a=i;
        b=n-i;
        sol=min(sol,usu(a)+usu(b));
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
//这里是简单循环，特别的还是手写吧，或者有的循环用的全局变量也要手写
#define fup(i,a,b) for(int i=a; i<=b; ++i)
#define fwn(i,a,b) for(int i=b; i>=a; --i)

int main()
{
    int L, D, G;
    scanf("%d %d %d", &L, &D, &G);
    printf("%d\n", (L-G)/(D+G));
    return 0;
}

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

int main() {
  int q_num, total_time = 0;
  cin >> q_num;
  vector<int> t(q_num);

  for(int i=0; i < q_num; i++) {
    cin >> t[i];
    total_time += t[i];
  }

  int drink_type;
  cin >> drink_type;
  vector<int> t_t(drink_type, total_time);

  for(int i=0; i < drink_type; i++) {
    int P, X;
    cin >> P >> X;
    t_t[i] += X - t[P-1];
  }

  for(int i=0; i < drink_type; i++) {
    cout << t_t[i] << endl;
  }
}



Measured memory_bytes: 3560
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


bool max_u(int&m, int v)
{
	if(m>=v) return false;
	m=v;
	return true;
}


void dump(vi&v, const char*s)
{
	printf("%s", s);
	for(int mv:v) printf(" %d", mv);
	printf("\n");
}


int solve(vpii&lr)
{
	int n=lr.size();
	int ans=0;
	vi l(n), r(n), w(n);

	sort(lr.begin(), lr.end());

	for(int i=0;i<n;i++)
	{
		l[i]=lr[i].first;
		r[i]=-lr[i].second;
		w[i]=r[i]-l[i]+1;
		max_u(ans, w[i]);
	}

	vi lminr(n), rminr(n), rmaxl(n);

	lminr[0]=r[0];
	for(int i=1;i<n;i++)
	{
		lminr[i]=min(lminr[i-1], r[i]);
	}

	rminr[n-1]=r[n-1];
	rmaxl[n-1]=l[n-1];
	for(int i=n-1-1;i>=0;i--)
	{
		rminr[i]=min(rminr[i+1], r[i]);
		rmaxl[i]=max(rmaxl[i+1], l[i]);
	}

	for(int i=0;i+1<n;i++)
	{
		int ans1st=max(lminr[i]-l[i]+1, 0);
		int ans2nd=max(rminr[i+1]-rmaxl[i+1]+1, 0);
		max_u(ans, ans1st+ans2nd);
	}
	sort(r.begin(), r.end());
	sort(l.rbegin(), l.rend());
//dump(r, "sort r");
//dump(l, "sort l");
	for(int i=0;i<n;i++)
	{
		int ar=r[0], al=l[0];
		if(al==lr[i].first) al=l[1];
		if(ar==-lr[i].second) ar=r[1];
		int aw=max(ar-al+1, 0);
		max_u(ans, w[i]+aw);
	}

	return ans;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi l(n), r(n), w(n);
		vpii lr(n);
		int ans=0;

		for(int i=0;i<n;i++)
		{
			scanf("%d%d", &lr[i].first, &lr[i].second);
			lr[i].second=-lr[i].second;
		}
		ans=solve(lr);

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


Measured memory_bytes: 4480
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            Map<Integer, Integer> dh = new HashMap<>();
            int ch = 0;
            for (int i = 1; i <= 999; i++) {
                ch += i;
                dh.put(i, ch);
            }

            out.println(dh.get(b - a) - b);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (bufLength == -1)
                    throw new InputMismatchException();
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return (c >= 33 && c <= 126);
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public long nextLong() {
            long n = 0;

            boolean minus = false;
            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || b > '9')
                throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (isSpaceChar(b) || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {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 powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    while(t--){
    	int d,t,s;cin>>d>>t>>s;
    	if(s*t>=d)cout<<"Yes";
    	else cout<<"No";
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n,a[30]={};
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	int s=1;
	for(int i=2;i<=n;++i){
		bool p=0;
		for(int j=1;j<i;++j)
		 if(a[j]>a[i])p=1;
		if(!p)++s;
	} 
	printf("%d",s);
	return 0;
}

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

using namespace std;

ll MOD=998244353;
ll f[200005];
ll fi[200005];
ll n_max=200005;
ll power(ll n,ll p)
{
    if(p==0)
        return 1;
    ll z=power(n,p>>1);
    z=(z*z);
    z%=MOD;
    ll x = ((z*n)%MOD);
    return (1&p)?x:z;
}

void prefac()
{
    for(ll i=0;i<n_max-1;i++)
    {
        f[i+1]=(f[i]*(i+1))%MOD;
        fi[i+1]=power(f[i+1],MOD-2);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fi[0]=1;
    f[0]=1;
    prefac();
    ll ans=0;
    ll n,m,k,j;
    cin>>n>>m>>k;
    n--;
    m--;
    for(ll i=0;i<=k;i++)
    {
        j=(fi[n-i]*power(m,n-i))%MOD;
        j=(fi[i]*j)%MOD;
        ans += j;
    }
    ans%=MOD;
    ans=(f[n]*ans)%MOD;
    ans=((m+1)*ans)%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6776
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int n;cin >> n;
    cout << n+n*n+n*n*n << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll cnt[M];

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

	ll i,j,k,v,n;

	cin >> n;

	for(i=1;i<=100;++i)
	{
		for(j=1;j<=100;++j)
		{
			for(k=1;k<=100;++k)
			{
				v = i*i+j*j+k*k+i*j+i*k+j*k;
				cnt[v]++;
			}
		}
	}

	for(i=1;i<=n;++i)
		cout << cnt[i] << "\n";
}

Measured memory_bytes: 4084
def main():
    A,B,C = map(int,input().split())
    K = int(input())
    num = 0

    while (B <= A):
        num += 1
        if num <= K:
            B *= 2
        else:
            return ("No")

    while (C <= B):
        num += 1
        if num <= K:
            C *= 2
        else:
            return ('No')

    return('Yes')

print(main())


Measured memory_bytes: 9184
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    if N==1:
        print(abs(a[-1]-W))
    else:
        print(max(abs(a[-1]-W),abs(a[-2]-a[-1])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<int> dx{1, -1, 0, 0};
vector<int> dy{0, 0, 1, -1};
/* function */
/* main */
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> pic(H);
    for (int i = 0; i < H; i++) cin >> pic[i];

    for (int x = 0; x < H; x++) {
        for (int y = 0; y < W; y++) {
            if (pic[x][y] == '.') continue;
            bool can = false;
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
                if (pic[nx][ny] == '#') can = true;
            }
            if (can == false) {
                cout << "No" << '\n';
                return 0;
            }
        }
    }

    cout << "Yes" << '\n';
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;


class P
{
    static void Main()
    {
        float res = 0;
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Split();
            res += float.Parse(s[0]) * (s[1] == "BTC" ? 380000 : 1);
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std ;
int a[10100] ;

int main()
{
  int n , m ;
  string s ;
  cin >> n >> m >> s ;
  long long ans = 0 ;
  if(m == 2 || m == 5)
   {
     for(int i = 0 ;i < n ;i ++)
      if((s[i] - '0') % m == 0)
       ans += i + 1 ;
   }
  else
   {
     a[0] = 1 ;
     int v = 0 , t = 1 ;
     for(int i = n - 1; i >= 0 ;i --)
      {
        v += t * (s[i] - '0') ;
        v %= m ;
        ans += a[v] ;
        a[v] ++ ;
        t *= 10 ;
        t %= m ;
      }

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



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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N, 0);
    vector<int> L(N, 0LL);
    vector<int> R(N, 0LL);
    for (auto & a : A) cin >> a;
    L[0] = A[0];
    for (int i = 1; i < N; ++i) L[i] = __gcd(L[i - 1], A[i]);
    R[N - 1] = A[N - 1];
    for (int i = N - 2; i >= 0; --i) R[i] = __gcd(R[i + 1], A[i]);
    int ans = max(L[N - 2], R[1]);
    for (int i = 1; i <= N - 2; ++i) ans = max(ans, __gcd(L[i - 1], R[i + 1]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
n,m=gets.split.map &:to_i
ab=[]
n.times do |i|
    ab<<gets.split.map(&:to_i)
end
cd=[]
m.times do |i|
    cd<<gets.split.map(&:to_i)
end

ab.each do |p|
    ans=0
    min=100000000000
    m.times do |i|
        dist=(p[0]-cd[i][0]).abs+(p[1]-cd[i][1]).abs
        if min>dist
            min=dist
            ans=i+1
        end
    end
    p ans
end

Measured memory_bytes: 1788