akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];


ll H, W;
ll sx, sy, gx, gy;
ll d[1111][1111];
ll clr[1111][1111];
string s[1111];

void solve() {
  ll i, j, k;
  priority_queue<pair<ll, pll>> q;
  
  for(i=0; i<H; i++) for(j=0; j<W; j++) d[i][j]=INF;
  d[sx][sy]=0;
  q.push(make_pair(0, pll(sx, sy)));
  
  while(q.size()) {
    ll x=q.top().sc.ft;
    ll y=q.top().sc.sc;
    ll u=-q.top().ft;
    q.pop();
    
    if(clr[x][y]) continue;
    clr[x][y]=1;
    
    for(i=-2; i<=2; i++) {
      for(j=-2; j<=2; j++) {
        ll tx=x+i, ty=y+j;
        if(tx<0 || tx>=H || ty<0 || ty>=W) continue;
        if(s[tx][ty]=='#') continue;
        if(clr[tx][ty]) continue;
        
        if(abs(i)<=1 && abs(j)<=1 && abs(i+j)==1) {
          q.push(make_pair(-u, pll(tx, ty)));
          chmin(d[tx][ty], u);
        }else {
          q.push(make_pair(-u-1, pll(tx, ty)));
          chmin(d[tx][ty], u+1);
        }
        
      }
    }
    
  }
  
}


int main(void) {
  ll i, j, k;
  
  
  cin >> H >> W;
  cin >> sx >> sy >> gx >> gy;
  sx--; sy--; gx--; gy--;
  for(i=0; i<H; i++) cin >> s[i];
  
  solve();
  if(d[gx][gy]==INF) pt(-1);
  else pt(d[gx][gy]);
  
}
 
 




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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	LL D; cin >> D;
	if(D%9 != 0) return cout << 0 << endl, 0;
	D /= 9;
	LL ans = 0;
	repp(i,1,19){
		LL z = 1;
		repp(k,0,i) z *= 10;
		LL x = D;
		LL a = 1;
		LL b = 1;
		while(z > 0){
			a *= 10-x%10-b;
			if(z == 1) break;
			x -= x%10*(z-1)/9;
			if(x < 0) x = -x;
			x /= 10;
			z /= 100;
			b = 0;
		}
		if(x == 0) ans += a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 3000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

int n , m, dp[N][2 * N][2];


int calc(int idx , int red , bool k) {
	if (idx == m)return k;
	int &ret = dp[idx][red][k];
	if (ret != -1)return ret;
	ret = 0;
	if (red > 0) {
		ret = (ret + calc(idx + 1, red - 1, k || (red == 1))) % MOD;
		ret = (ret + calc(idx + 1, red, k || (red == 1))) % MOD;
	}
	if (red < n) {
		ret = (ret + calc(idx + 1, red + 1, k || (red == 0))) % MOD;
		ret = (ret + calc(idx + 1, red, k || (red == 0))) % MOD;
	}
	return ret;
}
int main() {
	cin >> n >> m;
	memset(dp, -1, sizeof dp);
	int sum = 0;
	for (int i = 0 ; i <= n ; ++i){
		sum = (sum + calc(0, i, 0)) % MOD;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 150656
i=61,f[],c,m,s;main(y){for(;s?m=fmax(m,++f[y*12+*f+"=>?2J13IK<@V&"[--s]]):~scanf("%d,%d,%d",f,&y,&s)?s=s*4+1:++i<180?i%12<2|f[i]||++c:!printf("%d\n%d\n",c,m););}

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

int sectime;

void input(){
    cin >> sectime;
}

int main(){
    input();

    int hour, min, sec;
    
    hour = sectime / 3600;
    min = sectime / 60 - hour * 60;
    sec = sectime % 60;

    cout << hour << ":" << min << ":" << sec << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,bef,cou,ans;
  vector<int> go[2];
  while(scanf("%d",&n),n!=0){
    cou = 0;
    ans = 0;
    for(int i=0;i<n;i++){
      scanf("%d",&c);
      if(i == 0) bef = c;
      if(bef == c) cou++;
      else {
	go[bef].push_back(cou);
	cou = 1;
	if(i%2 == 1 && go[c].empty()){
	  cou += go[bef][0];
	  go[bef].pop_back();
	} else if(i%2 == 1){
	  cou += go[c][go[c].size()-1]+go[bef][go[bef].size()-1];
	  go[c].pop_back();
	  go[bef].pop_back();
	}
      }
      bef = c;
    }
    go[c].push_back(cou);
    for(int i=go[0].size()-1;i>=0;i--){
      ans += go[0][i];
      go[0].pop_back();
    }
    printf("%d\n",ans);
    go[1].clear();
  }
  return (0);
}

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


int main()
{


        long long n,m,a,b,c,e,f,g,p,q,r,fr,sc,tr,sz,tz,sz1,zr=0,sz2,i,j,k,mx=-9,mn=999999999999; string str,ttr,ntr;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct,tct; vector<string>vst;
        set<long long>st,nt,tt; map<string,long long>mp,nq,qr,mp1; map<long long,long long>mmm,mp2;

        char ch,th;
        cin>>ch; th=ch+1;   cout<<th<<endl;











    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  char s[1010000];
  int r=0,b=0,n;
  scanf("%d %s",&n,s);
  for(int i=0;i<n;i++){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b) puts("Yes");
  else puts("No");
  return 0;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	long long ans = 1e10;
	if (h % 3 == 0)
		ans = 0;
	else
		ans = min(ans, (long long)w);
	if (w % 3 == 0)
		ans = 0;
	else
		ans = min(ans, (long long)h);
	for (int i = 0; i <= h; i++)
	{
		long long a = (long long)(i)*w, b = (long long)(h - i) * (w / 2), c = (long long)(h - i) * (w - w / 2);
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
	}
	for (int i = 0; i <= w; i++)
	{
		long long a = (long long)(i)*h, b = (long long)(w - i) * (h / 2), c = (long long)(w - i) * (h - h / 2);
		ans = min(ans, max({a, b, c}) - min({a, b, c}));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

const int MAX = 100005;

struct Node
{
    int key;
    Node *parent, *left, *right;
};

int n;
Node *root, *NIL;

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL)
    {
        root = z;
    }
    else
    {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

Node *find(Node *u, int k)
{
    while (u != NIL && k != u->key)
    {
        if (k < u->key)
        {
            u = u->left;
        }
        else
        {
            u = u->right;
        }
    }
    return u;
}
void Preorder(Node *u)
{
    cout << " " << u->key;
    if (u->left != NIL)
        Preorder(u->left);

    if (u->right != NIL)
        Preorder(u->right);
}

void Inorder(Node *u)
{

    if (u->left != NIL)
        Inorder(u->left);
    cout << " " << u->key;
    if (u->right != NIL)
        Inorder(u->right);
}

void Postorder(Node *u)
{

    if (u->left != NIL)
        Postorder(u->left);

    if (u->right != NIL)
        Postorder(u->right);
    cout << " " << u->key;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        if (s == "insert")
        {
            int v;
            cin >> v;
            insert(v);
        }
        else if (s == "find")
        {
            int v;
            cin >> v;
            Node *t = find(root, v);
            if (t != NIL)
                cout
                    << "yes" << endl;
            else
                cout << "no" << endl;
        }
        else if (s == "print")
        {
            Inorder(root);
            cout << endl;
            Preorder(root);
            cout << endl;
        }
    }
    return 0;
}


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

#define NUM_MAX 2147483647
#define N_MAX 2048
int n;
int dat[2*N_MAX-1]; //segment tree

// n_ elements
//initialize segment tree
void init(int n_) {
    n = 1;
    while(n < n_) n *= 2;
    for(int i=0; i < 2 * n - 1; ++i) dat[i] = NUM_MAX;
}

// change kth elements to a
void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while(k > 0) {
        k = (k - 1) / 2;
        dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
    }
}

// return minimum in [a,b)
// usage : query(a, b, 0, 0, n);
int query(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;

    if(r <= a || l >= b) return NUM_MAX;

    if(a <= l && r <= b) return dat[k];
    
    int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
}

int main() {
    int N;
    long long x;
    cin >> N >> x;
    
    init(N);
    for(int i=0; i<N; ++i) {
        int a;
        cin >> a;
        update(i, a);
    }

    long long res = 1001001001001001001;
    for(int k=0; k<N; ++k) {
        long long tmp = k * x;
        for(int i=0; i<N; ++i) {
            if(i - k < 0) tmp += min(query(0, i + 1), query((i - k + N) % N, N));
            else tmp += query(i - k, i + 1);
        }
        res = min(res, tmp);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    int n;cin>>n;
    vector<int> s(n);
    for(int i=0;i<n;i++) cin>>s[i];
    int q;cin>>q;
    int ans=0;
    for(int i=0;i<q;i++){
        int t;cin>>t;
        auto iter=lower_bound(s.begin(),s.end(),t);
        ll index=iter-s.begin();
        if(t==s[index]) ans++;
    }
    cout<<ans<<endl;
}



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


int main() {
    int N;
    cin>>N;
    vector<long long> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }

    int sum=0;
    for(int i=0;i<N;i++){
        long long val;
        int count=0;
        val = a.at(i);
        while(val%2==0){
            val = val/2;
            count++;
        }
        sum += count;
    }

    cout<<sum<<endl;
    

    return 0;



}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k,a,b;
	cin>>k>>a>>b;
	ll ans=0;
	k++;
	if(2>=b-a)cout<<k<<endl;
	else{
		ll ans=0;
		if(k<=a)ans=k;
		else{
			ans=a;
			k-=a;
			ans+=(k/2)*(b-a);
			if(k%2==1)ans++;
		}
		cout<<ans<<endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair


bool siv[505050]
;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

rep(i, 2, 55555){
    if(siv[i])continue;
    for(int j=i*2; j<=55555; j+=i){
        siv[j]=true;
    }
}
int n;
cin >> n;
rep(i, 2, 55555){

if(!siv[i] && i%5 == 4){
    n--;
    cout << i << " ";
}
if(n<=0)break;
}

return 0;}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

const ll mod = 1000000007;

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

    int N;
    cin >> N;
    ll A[N], B[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];

    sort(A, A+N);
    sort(B, B+N);

    ll ans = 1LL, a = 0, b = 0;
    for (int i = 0; i < 2 * N; i++) {
        if (b == N || A[a] < B[b]) {
            if (a < b) ans = ans * (b - a) % mod;
            a++;
        } else {
            if (b < a) ans = ans * (a - b) % mod;
            b++;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ld long double
    #define MOD 1000000007
    #define mod9 1000000009
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define mp make_pair
    #define pb push_back
    #define ct ll t;cin>>t;while(t--)
    #define bi begin()
    #define ei end()
    #define fi first 
    #define se second  
    #define foe(i,a,b) for(ll i=a;i<b;i++)
    #define rfoe(i,a,b) for(ll i=a;i>=0;i--)
    #define sz(s) s.size() 
    #define mem(a,s) memset(a,s,sizeof(a)) 
    #define all(v) v.bi,v.ei
    #define MAX             8000000000000000064LL
    #define MIN            -8000000000000000064LL   

    typedef pair<ll,ll> pii;
    
    ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
    ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
    ll fact[1000007 ]={0};
    ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
    y=y>>1;x=(1ll*x*x)%MOD;} return res;}
    void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
    ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
    ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
    int const N=2e5+9;
    ll const INF = 2e18+5;
    ll dx[8]={0,0,1,-1,1,1,-1,-1};
    ll dy[8]={1,-1,0,0,-1,1,-1,1};
    long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res%MOD;
}
    void solve()
    {  
        ll n;
        cin>>n;
        ll mn=2e18,mx=-2e18,mn1=2e18,mx1=-2e18;
        ll x,y;
        foe(i,0,n)
        {
            cin>>x>>y;
            mn=min(mn,x+y);
            mx=max(mx,x+y);
            mn1=min(mn1,x-y);
            mx1=max(mx1,x-y);
        }
        cout<<max(abs(mn-mx),abs(mn1-mx1))<<"\n";
    }
    int main()
    {
        // fast
        facto();
        // Sieve();
    //    ct    
        { 
            solve();
        }
    }


Measured memory_bytes: 11444
import sys, math
from functools import lru_cache
import numpy as np
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    S = input()
    N = len(S)
    for i in range(N-1):
        for j in range(i, N):
            if S[:i]+S[j:] == 'keyence':
                print('YES')
                return
    print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 27024
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define pb push_back
#define ll long long
#define PI 3.14159265
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define eps 1e-7
const int mod=1e9+7;
const int maxn=1e5+5;
using namespace std;
ll n,k;
int a[1000];
//char a[100];
int main()
{
     std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=1,tmp=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
       if(a[i]<tmp)
       {
           ans++;
           tmp=a[i];
       }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;


vector<int> a[N];
ll b[N], fact[N], sz[N], ans1[N];

ll power(ll x, ll y) {
    ll ans = 1;
    ll t = x;
    while (y) {
        if (y % 2) {
            ans = (ans * t) % mod;
        }

        t = (t * t) % mod;
        y /= 2;
    }

    return ans;
}

ll comb(ll n, ll c) {
    ll ans = (fact[n] * power(fact[c], mod - 2)) % mod;
    return (ans * power(fact[n - c], mod - 2)) % mod;
}

void g(int x, int p) {
    sz[x] = 1;
    for (int e : a[x]) {
        if (e != p) {
            g(e, x);
            sz[x] += sz[e];
        }
    }

}

void f(int x, int p) {
    for (int e : a[x]) {
        if (e != p) {
            f(e, x);
        }
    }

    b[x] = 1;
    ll rem = sz[x] - 1;
    for (int e : a[x]) {
        if (e != p) {
            ll h = (comb(rem, sz[e]) * b[e]) % mod;
            b[x] = (b[x] * h) % mod;
            rem -= sz[e];
        }
    }

}

void final(int x, int p, int n) {
    ans1[x] = 1;
    if (p != -1) {
        ll num = ans1[p];
        ll den = (comb(n - 1, sz[x]) * b[x]) % mod;
        ans1[x] = (num * power(den, mod - 2)) % mod;
    }

    int rem = n - 1;
    for (int e : a[x]) {
        if (e != p) {
            ll h = (comb(rem, sz[e]) * b[e]) % mod;
            ans1[x] = (ans1[x] * h) % mod;
            rem -= sz[e];
        }
    }

    for (int e : a[x]) {
        if (e != p) {
            final(e, x, n);
        }
    }

}


int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        a[u].pb(v);
        a[v].pb(u);
    }

    fact[0] = 1;
    for (int i = 1; i < n + 1; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }

    g(1, -1);
    f(1, -1);
    final(1, -1, n);
    for (int i = 1; i < n + 1; i++) {
        cout << ans1[i] << '\n';
    }

}


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

using namespace std;

int main()
{
    int K,S;
    cin >> K >> S;
    int i,j;
    int result = 0;
    vector<int>v;
    for(i = 0 ; i <= 2*K; i++)
    {
        v.push_back(i);
    }
    for(i=0;i<= K; i++)
    {
        if(binary_search(v.begin(),v.end(),S - i))
        {
            for(j = 0; j <= K; j++)
            {
                if((S-i-j >= 0)&&(S-i-j <= K))
                {
                    result++;
                }
            }
        }
    }
    cout << result <<endl;
    return 0;
}

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

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<bool> vb;
mt19937_64 rnd(time(0));

void start() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(10);
    // cerr << fixed << setprecision(10);
#ifdef MY
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

signed main() {
    start();
    int n, W, ans = -1, WW = 0;
    cin >> n >> W;
    vi w(n), c(n);
    for (int i = 0; i < n; ++i) cin >> w[i] >> c[i], WW += c[i];
    vector<vi> d(n + 1, vi(WW + 1, 1e18));
    d[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= WW; ++j) {
            d[i][j] = d[i - 1][j];
            if (j >= c[i - 1])
                d[i][j] = min(d[i][j], d[i - 1][j - c[i - 1]] + w[i - 1]);
            if (d[i][j] <= W) ans = max(ans, j);
        }
    }
    cout << ans;


}


Measured memory_bytes: 83164
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> pref(n+1,vector<int>(10));
    for ( int i=0; i<n; i++ ) {
        pref[i+1] = pref[i];
        pref[i+1][s[i]-'0']++;
    }
    vector<int> prv(10,0);
    long long ans = 0;
    for ( int i=0; i<n; i++ ) {
        int d = s[i] - '0';
        long long l=0, r=0;
        {
            for ( int j = 0; j < 10; j++ ) {
                l += (pref[i][j]>0 && pref[prv[d]][j]==0);
            }
        }
        {
            for ( int j = 0; j < 10; j++ ) {
                r += (pref[n][j] - pref[i+1][j] > 0);
            }
        }
        ans += l*r;
        prv[d] = i;
    }
    cout << ans << '\n';
    return 0;
}

// 242424

Measured memory_bytes: 5372
#include<iostream>
#include<vector>
#include<climits>
#include<queue>
#include<climits>
using namespace std;
#define INF INT_MAX

int n,m,s,g1,g2;
vector< vector<long long> > edge;

void init(){
  n=m=s=g1=g2=0;
  edge.clear();
}

bool input(){
  cin>>n>>m>>s>>g1>>g2;
  if(n==0&&m==0&&s==0&&g1==0&&g2==0){
    return 0;
  }
  s--;g1--;g2--;
  edge.resize(n+1);
  for(int i=0;i<n+1;i++){
    edge[i].resize(n+1);
    for(int j=0;j<n+1;j++){
      edge[i][j]=INF;
    }
    edge[i][i]=0;
  }
  for(int i=0;i<m;i++){
    long long  b1,b2,c;
    cin>>b1>>b2>>c;
    b1--;b2--;
    edge[b1][b2]=c;
  }
  return 1;
}




int solve(){
  for(int k=0;k<n+1;k++){
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
        edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
      }
    }
  }
  long long res=INF;
  for(int i=0;i<n+1;i++){
    res=min(res,edge[s][i]+edge[i][g1]+edge[i][g2]);
  }
  return res;
}


int main(){
  while(init(),input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1296
// --------------
// Tejas Pandey  |
// 26 - 01 - 20  |
// ATCODER #153  |
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		ll h,n,k;
		cin >> h >> n;
		ll s = 0;
		for(int i = 0;i < n;i++)
			cin >> k,s += k;
		if(s < h)
			cout << "No\n";
		else
			cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char[] c = s.toCharArray();
        int r = 0;
        for (int i = 0; i < n; i++) {
            if (c[i] == 'R') {
                r++;
            }
        }
        int w = 0;
        for (int i = 0; i < r; i++) {
            if (c[i] == 'W') {
                w++;
            }
        }
        System.out.println(w);
    }

}


Measured memory_bytes: 41172
/*-----lusar98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
int main()
{
    //fast();
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(ll i=0;i<n;i++)
    	cin>>arr[i];
    ll dp[n+2];
    dp[0]=0;
    for(ll i=1;i<n;i++)
    {
        dp[i]=1ll<<60;
        for(ll j=1;j<=k && i-j>=0;j++)
    	dp[i] = min(dp[i-j] + abs(arr[i]-arr[i-j]), dp[i]);
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
$n, $m, q = gets.chomp.split(" ").map(&:to_i);
$c = 0

$query = Array.new($n)
$n.times do |i| 
  $query[i] = []
end
q.times do
  a, b, c, d = gets.chomp.split(" ").map(&:to_i);
  a-=1
  b-=1
  $query[b] = [] if $query[b].nil?
  $query[b] << [a ,b ,c, d]
end


$arr = Array.new($n, 0)
$max = 0

def bt (index, last, now)
  if index == $n
    $max = [now, $max].max
    #pp $arr
    return 1
  end
  (last..$m).each do |i|
    plus = 0
    $arr[index] = i
    $query[index].each do |query|
      plus += query[3] if ($arr[query[1]] - $arr[query[0]]) == query[2]
    end
    bt(index + 1, i, now + plus)
  end
end

bt(0, 1, 0)
puts $max

Measured memory_bytes: 14320
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb(a) push_back(a)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
using vP = vector<P>;
const int INF = 1001001001;

int main(){
    int n;
    cin>>n;
    
    vector<ll> a(n);
    //map<int,ll> m;
    vector<ll> m(n,0);
    
    
    rep(i,n){
        cin>>a[i];
        a[i]--;
        m[a[i]]++;
    }
    
    ll ans = 0;
    /*
    for(auto p: m){
        ans += p.second*(p.second-1)/2;
    }
    */
    
    rep(i,n){
        ans += m[i]*(m[i]-1)/2;
    }
    
    for(int i=0; i<n; i++){
        cout << ans -( m[a[i]] - 1 ) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5760
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            String s = sc.next();
            if(s.equals("-"))break;

            char[] chars = s.toCharArray();
            int n = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < n; i++) {
               sum += sc.nextInt();
            }
            for (int i = 0; i < chars.length; i++) {
                System.out.print(chars[(sum+i)%chars.length]);
            }
            System.out.println();
        }

        sc.close();
    }
    
    public static void printary(int[] a)
    {
        for ( int i = 0; i < a.length; i++) {
            if(i>0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 26364
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    ll N, W; cin>>N>>W;
    vector<ll> v(N);
    vector<ll> w(N);
    for(int i=0; i<N; ++i){
        cin>>w[i]>>v[i];
    }
    ll dp[N+1][W+1];
    for(int i=0; i<=N; ++i) dp[i][0] = 0;
    for(int i=0; i<=W; ++i) dp[0][i] = 0;
    for(int i=1; i<=N; ++i){
        for(int j=1; j<=W; ++j){
            dp[i][j] = max(dp[i-1][j], (j-w[i-1]>=0)?(v[i-1]+dp[i-1][j-w[i-1]]):0);
        }
    }
    cout<<dp[N][W]<<endl;
}

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

//#include <map>

using namespace std;

int main()
{
	vector<int> vInt;
	int t;

	while (cin >> t)
	{
		if (t == 0)break;
		vInt.push_back(t);
	}

	for (int i = 0; i < vInt.size(); i++)
	{
		char ch[20];
		sprintf(ch, "Case %d: %d", i + 1, vInt.at(i));
		cout << ch << endl;
	}

	return 0;
}

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

int main(){
	vector<vector<int>> bingo(3, vector<int>(3));
	vector<vector<bool>> a(3, vector<bool>(3));
	rep(i, 3){
		rep(j, 3){
			cin >> bingo.at(i).at(j);
		}
	}

	int n;
	cin >> n;
	rep(k, n){
		int d;
		cin >> d;

		rep(i, 3){
			rep(j, 3){
				if(d == bingo.at(i).at(j)) a.at(i).at(j) = true;
			}
		}
	}
	
	bool ans = false;

	rep(i, 3) if(a.at(i).at(0) && a.at(i).at(1) && a.at(i).at(2)) ans = true;
	rep(i, 3) if(a.at(0).at(i) && a.at(1).at(i) && a.at(2).at(i)) ans = true;

	if(a.at(0).at(0) && a.at(1).at(1) && a.at(2).at(2)) ans = true;
	if(a.at(0).at(2) && a.at(1).at(1) && a.at(2).at(0)) ans = true;

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

using namespace std;

bool check(string &s, int len) {
  for (int i = 0; i < len / 2; ++i) {
    if (s[i] != s[len / 2 + i]) {
      return false;
    }
  }

  return true;
}

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  int ans = 0;
  for (int len = s.size() - 2; len >= 2; len -= 2) {
    if (check(s, len)) {
      ans = len;
      break;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, k;
	cin >> a >> b >> c;
	cin >> k;
	if (max({a, b, c}) == a){
		REP(i, k){
			a *= 2;
		}
	}else if (max({a, b, c}) == b){
		REP(i, k){
			b *= 2;
		}
	}else{
		REP(i, k){
			c *= 2;
		}
	}
	cout << a + b + c << "\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(map(int,(input().split())))
d.sort()

k = 0 #以上ならARC 未満はABC

x = (n // 2) -1 # 配列のスタート

start = d[x] + 1
end = d[x+1] + 1

result = list(range(start,end))
print(len(result))




Measured memory_bytes: 14008
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			int r = s.nextInt();
			int D = s.nextInt();
			int x2000 = s.nextInt();

			int x = x2000;
			for (int i = 1; i <= 10; i++) {
				x = r * x - D;
				System.out.println(x);
			}
		}
	}
}


Measured memory_bytes: 21076
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a,c[100009];
ll ans=1ll;
int main(){
    cin>>n;
    c[0]=3;
    for(int i=0;i<n;i++){
        cin>>a;
        (ans*=c[a])%=1000000007;
        c[a]--;
        c[a+1]++;
    }
    cout<<ans<<endl;
}


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

int main() {
   std::vector<int> a(3);
   int tmp;
   int ans = 0;

   for (size_t i = 0; i < 3; i++) {
      std::cin >> a.at(i);
   }

   for (size_t i = 0; i < 3; i++) {
      for (size_t j = 2; j >= i + 1; j--) {
         if (a.at(j) < a.at(j-1)) {
            tmp = a.at(j);
            a.at(j) = a.at(j - 1);
            a.at(j-1) = tmp;
         }
      }
   }

   for (size_t i = 1; i < 3; i++) {
      ans += abs(a.at(i - 1) - a.at(i));
   }
   std::cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		long answer = 0;

		for (int i = 1; i <= N; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				answer += i;
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 35732
#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, std::vector<long long> P) {
  long long curMax = 1e18;
  long long ans = 0;
  for(int i = 0 ; i < P.size() ; i++){
    if( curMax > P[i] ){
      ans++;
      curMax = P[i];
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;


int main(void){
	ll N,A,B,ans;
	
	cin>>N>>A>>B;
	ans=(N-2)*(B-A)+1;
	if(A>B){
		cout<<0<<endl;
	}else{
		if(ans>=0)cout<<ans<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 256
s = input()
l, r = 0, len(s)-1
ans = 0
while(True):
    if l >= r: break
    sl, sr = s[l], s[r]
    if sl == sr: l += 1; r -= 1
    elif sl == "x":
        ans += 1
        l += 1
    elif sr == "x":
        ans += 1
        r -= 1
    elif sl != sr:
        ans = -1
        break

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl ans;

void dfs(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        ans[u] += ans[v];
        dfs(u, v);
        // 帰りの処理はこのへんに書く
    }
}

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

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    ans.resize(n);
    rep(i, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    const ll root = 0;
    dfs(root);

    rep(i, n) {
       cout << ans[i] << " ";
    }

    cout << endl;
    re0;
}

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

int main() {
    int n;cin>>n;
    long long int a[n],ans;

    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    ans= __gcd(a[0],a[1]);
    if(n>2){
        for(int i=2;i<n;++i){
        ans = __gcd(ans,a[i]);
        }
    }
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
'''
リストや文字列の並び替え
↓↓↓
https://note.nkmk.me/python-reverse-reversed/
'''
a,b=map(int,(input().split()))
ans=0

for i in range(a,b+1):
  num=str(i)
  num_reverse=num[::-1]
  if num==num_reverse:
    ans+=1
print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    int l=0,r=0;
    for(int i=1;i<n;i++){
        if(s[i]=='W') r++;
    }
    int ans=n-r-1;
    for(int i=1;i<n;i++){
        if(s[i-1]=='E')  l++;
        if(s[i]=='W') r--;
        ans=min(ans,n-l-r-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 900
#include<iostream>
#include<string>
#include <cmath>
using namespace std;
int main() {
    char s[2][3];
    for(int i=0; i<2; ++i){
        for(int j=0; j<3; ++j){
            cin >> s[i][j];
        }
    }
    if(s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,h,w,ans = 0;
	cin >> n >> h >> w;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		ans += (a >= h && b >= w);
	}
	cout << ans << endl;
}

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

int gcd(int y, int x){
	if(y<x)swap(y,x);
	
	if(x==0)return y;
	
	return gcd(x, y%x);
}

int main(){
	string s;	cin>>s;
	string x="";
	string loop="";

	int pos=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='('){
			pos=i;
			break;
		}else{
			x.push_back(s[i]);
		}
	}

	if(pos){
		for(int i=pos+1; i+1<s.length(); i++){
			loop.push_back(s[i]);
		}
	}

	if(x[x.length()-1]=='.')x.pop_back();
	//cout<<x<<endl;

	// {{{ A/B (循環してない部分)を生成
	int A=0,B=1;
	int m=0;
	bool flag=false;
	for(int i=0;i<x.length();i++){
		if(x[i]=='.'){
			flag=true;
			continue;
		}
		A=A*10+(x[i]-'0');
		if(flag){
			m++;
			B*=10;
		}
	}
	//printf("%d / %d\n",A,B);
	// }}}

	int C=0, D=1;
	if(loop.length()){
		//cout<<loop<<endl;
		//cout<<loop.length()<<endl;
		C=stoi(loop);
		D=pow(10,loop.length())-1;
		D*=pow(10,m);
		//printf("%d / %d\n",C,D);
	}

	// {{{ A/B + C/D

		// -> E/F

		int E=A*D + C*B;
		int F=D*B;
		int tmp=gcd(E,F);
		//printf("ans: %d / %d\n",E,F);
		//printf("[%d:%d]=%d\n",E,F,tmp);
		E/=tmp;	F/=tmp;
	// }}}

	printf("%d/%d\n",E,F);
	return 0;
}



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

int main(){
	bool flag;
	int result[3],buf,temp[10];
	for(int i = 0; i < 10; i++){
		cin >> temp[i];
	}
	for(int l = 0; l < 3; l++){
		while(1){
			for(int j = l; j < 9; j++){
				if(temp[j] < temp[j+1]){
					buf = temp[j+1];
					temp[j+1] = temp[j];
					temp[j] = buf;
				}
			}
			flag = false;
			for(int k = l; k < 9; k++){
				if(temp[l] < temp[k]) flag = true;
			}
			if(flag != true){
				result[l] = temp[l];
				break;
			}
		}
	}
	cout << result[0] << endl;
	cout << result[1] << endl;
	cout << result[2] << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   const int mod = 100000;
   int n, m;
   cin >> n >> m;
   vector<int> s(n - 1);
   rep(i, 0, n - 1) cin >> s[i];
   vector<int> a(m);
   rep(i, 0, m) cin >> a[i];

   vector<int> dist(n);
   rep(i, 1, n) dist[i] = (dist[i - 1] + s[i - 1]);
   int b_id = 0, ans = 0;
   rep(i, 0, m) {
      (ans += abs(dist[b_id + a[i]] - dist[b_id])) %= mod;
      b_id += a[i];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 4156
int max(int a, int b)
{
  int n;
  if (a >= b)
    n = a;
  else
    n = b;
  return (n);
}

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);
  if ((a - b) % 2 == 0)
    printf("%d", max(a, b) - abs((a - b) / 2));
  else
    printf("IMPOSSIBLE");
}


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

int main() {
  int a;
  cin >> a;
  
  int n=0;
  
  for(int i=0;i<=a;i++){
    int c = i*1.08;
    if(c == a){
      cout << i << endl;
      n=1;
      break;
    }
  }
  
  if(n==0){
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 200010
ll n,x[N],y[N];
int main(){
  cin>>n;
  ll mi=1e17,pmi=-1,ma=-1e17,pma=-1;
  ll xma=-1e17,ymi=1e17;
  for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
      if(x[i]>y[i])swap(x[i],y[i]);
      if(x[i]<mi)mi=x[i],pmi=i;
      if(y[i]>ma)ma=y[i],pma=i;
      chmax(xma,x[i]);
      chmin(ymi,y[i]);
  }
  ll ans=(xma-mi)*(ma-ymi);
  if(pmi!=pma){
      ll k1=y[pmi],k2=x[pma];
      vector<pair<ll,ll> >v;
      multiset<ll> s;
      s.insert(k1); s.insert(k2);
      for(int i=0;i<n;i++){
          if(i==pmi||i==pma)continue;
          v.push_back(make_pair(x[i],y[i]));
          s.insert(x[i]);
      }
      sort(v.begin(),v.end());
      for(int i=0;i<v.size();i++){
          s.erase(s.find(v[i].first));
          s.insert(v[i].second);
          ll vl=*s.begin();
          auto it=s.end(); it--;
          ll vr=*it;
          chmin(ans,(ma-mi)*(vr-vl));
      }
  }
  cout<<ans<<endl;
  return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=(a)-((a)>(n)); i!=(n)-((a)>(n)); i+=1-2*((a)>(n)))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_back
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12);
#define fill(a, b) memset(a, b, sizeof(a)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

int main(){
	flash; QuickSilver;
	int h, w; cin>>h>>w;
	vvl a(h, vl(w));
	rep(i,0,h) rep(j,0,w){
		char x; cin>>x; 
		a[i][j]=(x=='.')?1:0;
	}
	rep(i,0,h) rep(j,0,w) 
		if(!i && j && a[i][j]) a[i][j]=a[i][j-1];
		else if(!j && i && a[i][j]) a[i][j]=a[i-1][j];
		else if(i && j && a[i][j]) a[i][j]=(a[i-1][j]+a[i][j-1])%mod;
	cout<<a[h-1][w-1]<<"\n";
    return 0;
} 

Measured memory_bytes: 8064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll L[n];
    rep(i, n){
        cin >> L[i];
    }
    sort(L, L + n);

    ll a, b, c;
    ll ans = 0;
    rep(i, n - 2){
        for(ll j = i + 1; j < n - 1; j++){
            for(ll k = j + 1; k < n; k++){
                if(L[k] < L[i] + L[j]){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

constexpr ll mod = 998244353;

ll mod_pow(ll a, ll n){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

int main(){
    ll N;
    cin >> N;
    map<ll, ll> mp;
    bool f = false;
    ll mx = 0;
    rep(i, 0, N){
        ll d; cin >> d;
        mp[d]++;
        mx = max(mx, d);
        if(i != 0 && d == 0) f = true;
        if(i == 0 && d != 0) f = true;
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    rep(i, 1, mx+1){
        if(mp.count(i) == 0){
            cout << 0 << endl;
            return 0;
        }
        ans *= mod_pow(mp[i-1], mp[i]);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528