akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<int,int>
#define INF 1e9 + 7
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define add emplace_back

int sum(int x, int y){
    return (x+y)%1000000007;
}
int main(){ios_base::sync_with_stdio(false);

    int h, w;
    while(cin >> h >> w){
        vs grid(h);
        for(int i=0; i<h; ++i) cin >> grid[i];
        
        vvi dp(h+1, vi(w+1,0));
        dp[0][0] = 1;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if(grid[i][j]!='#'){
                    if(j<w-1 && grid[i][j+1]!='#') dp[i][j+1] = sum(dp[i][j+1], dp[i][j]);
                    if(i<h-1 && grid[i+1][j]!='#') dp[i+1][j] = sum(dp[i+1][j], dp[i][j]);
                }
            }
        }
        
        /*
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }
        */

        cout << dp[h-1][w-1] << endl;

    } 

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<int> ans(n, 0);

    REP(z, 2) {
        int count = 0;
        REP(i, n) {
            if (s[i] == 'R') count++;
            else {
                ans[i] += count / 2;
                ans[i - 1] += (count + 1) / 2;
                count = 0;
            }
        }
        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        REP(i, n) {
            if (s[i] == 'R') s[i] = 'L';
            else s[i] = 'R';
        }
    }

    REP(i, n) {
        cout << ans[i];
        if (i != n - 1) cout << ' ';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n,k;cin>>n>>k;
	vi a(n);
	rep(i,n) cin>>a[i];

	int ran=k;
	int ans=1;
	while(ran<n){
		ran+=k-1;
		ans++;
	}
	cout<<ans<<endl;


	return 0;
}



Measured memory_bytes: 4020
#include <bitset>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef vector<vector<ll>> vvll;

typedef pair<int, int> Pair;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

//nが素数かをO(√n)で判断
bool is_prime(int n) {
    bool res = true;

    if (n == 1) return false;
    else if (n == 2) return true;

    else {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                res = false;
                break;
            }
        }
    }

    return res;
}



int perm(int n, int r) {
    if (r == 1) return n;
    return n * perm(n - 1, r - 1);
}

int fact(int n) {
    if (n == 1) return 1;
    return fact(n - 1) * n;
}

int comb(int n, int r) {
    int a = min(n, r), b = max(n, r);
    return perm(a, b) / fact(a);
}



/*
ll pow_mod(ll a, ll n, ll mod) {
    ll res = 1;

    ll base = a;
    while (n) {
        if (n & 1) res = res * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return res;
}
*/

//aの逆元　（a^(-1)）を求める
ll inv_mod(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

/*
ll fact_mod(ll n, ll mod) {
    if (n == 1) return 1;
    return n * fact_mod(n - 1, mod) * mod;
}
*/

// 階乗 (mod とりバージョン)
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

// 組み合わせ nCr を求める (modあり)
ll comb_mod(ll n, ll r, ll mod) {
    if (r > n - r) r = n - r;
    if (r == 0) return 1;
    ll a = 1;
    for (int i = 0; i < r; i++) a = a * ((n - i) % mod) % mod;
    ll b = pow_mod(fact_mod(r, mod), mod - 2, mod);
    return (a % mod) * (b % mod) % mod;
}











int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = max(a * c, a * d);
    ll anss = max(b * c, b * d);

    cout << max(ans, anss) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll sum=0,M=0;
    rep(0,i,n){
        cin>>a[i];
        M=max(a[i],M);
        sum+=a[i];
    }
    sum-=M;
    if(M<sum){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

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

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

    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0])
        cout << "YES\n";
    else
        cout << "NO\n";
    
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct mod_fac{
    private:
        vector<ll> f,i_f;
        int n;ll MOD;
    public:
        void init(int n,ll m){
            MOD=m;
            f.resize(n+1,0);
            i_f.resize(n+1,0);
            f[0]=1;
            rep(i,n){
                f[i+1]=f[i]*(i+1)%MOD;
            }
            i_f[n]=power(f[n],MOD-2);
            per(i,n){
                i_f[i]=(i_f[i+1]*(i+1))%MOD;
            }
        }
        ll power(ll a ,ll x){
            if (x==0) return 1;
            if (x==1) return a%MOD;
            if (x==2) return (a*a)%MOD;
            if (x%2==1) return (a*power(power(a,(x-1)/2),2))%MOD;
            return (power(power(a,x/2),2))%MOD;
        }
        ll fac(int x){
            return f[x];
        }
        ll invfac(int x){
            return i_f[x];
        }
        ll comb(int m,int k){
            if (m<0 or k<0) return 0;
            if (m<k) return 0;
            return (((f[m]*i_f[k])%MOD)*i_f[m-k])%MOD;
        }
};

int n,m;
ll a,b,c,d,e;
mod_fac mo;

ll f(int s,int t,int k){
    ll res=0;
    rep(i,min(min(k+1,s+1),t+1)){
        res+=mo.comb(s,i)*mo.comb(s+(t-i)/2,s);
        res%=mod;
    }
    return res;
}


void solve(){
    cin >> n >> m;
    mo.init(n+(3*m)/2,mod);
    a=f(n,3*m,m);
    b=f(n,3*m-1,m);
    c=f(n-1,m-1,m);

    //cout << a << " " << b << " " << c << endl;

    ll ans=((a-b)%mod-n*c%mod+2*mod)%mod;

    cout << ans << endl;
}

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

Measured memory_bytes: 27648
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<cctype>
using namespace std;


int main(){
    int tp=0, hp=0;

    int n;
    cin >> n;

    string tstr, hstr;

    for(int i=0;i<n;i++){
        cin >> tstr >> hstr;
        if(tstr > hstr) tp+=3;
        else if(tstr < hstr) hp += 3;
        else {
            tp+=1; 
            hp+=1;
        }
    }
    cout << tp << " " << hp << endl;
}


Measured memory_bytes: 3164
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

N = int(input())

tbl = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N+1) :
  tbl[int((str(i))[0])][int((str(i))[-1])] += 1

ans = 0
for x in range(1, 10) :
  for y in range(1, 10) :
    ans += tbl[x][y] * tbl[y][x]

print (ans)




Measured memory_bytes: 3436
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;

int main()
{
	int x;
	cin >> x;
	if (x >= 30) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 2e9+7;

int main() {
    string s;
    int k;
    cin >> s;
    cin >> k;
    int th = 0;
    rep(i, s.size()) {
        if (s[i] == '1') th = i + 1;
        else break;
    }
    if (k <= th) cout << 1 << endl;
    else cout << s[th] << endl;
}

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

int main() {
	int R[200000], n;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -1000000000;
	int minv =  R[0];

	for (int j = 1; j < n; j++) {
		maxv = max(maxv, R[j] - minv);
		minv = min(minv, R[j]);
	}

	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3888
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k, x = inpm()
if(500 * k >= x):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 74876
#include <iostream>
using namespace std;
int main()
{
	int flag=0;
	string n;
	cin>>n;
	for(int i=0;i<n.length();i++)
	{
		if(n[i]=='C')
		flag=1;
		if(n[i]=='F'&&flag==1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
} 

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll ans[N+1] = {};
    priority_queue<pair<ll, int>> pq;
    rep(i, N){
        ll a; cin >> a;
        pq.push(make_pair(a, i+1));
    }
    int idx = N;
    while(!pq.empty()){
        //最大の数をなるべくたくさん取り出す
        ll cnt = 0;
        ll base = pq.top().first;
        pair<ll, int> op;
        while(!pq.empty() && pq.top().first == base){
            cnt++;
            op = pq.top();
            pq.pop();
        }
        idx = min(idx, op.second);
        ll diff;
        if(!pq.empty()) diff = op.first - pq.top().first;
        else diff = op.first;
        //diff*(これまで取り出したものの数)だけans[op.second]に加算
        //op.secondではない
        ans[idx] += diff*(N-pq.size());
    }
    for(int i = 1; i <= N; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if( abs(A-B)%2== 0 ) cout << "Alice" << endl;
    else cout << "Borys" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=a;i<=b;i++)
#define per(i,a,b) for (rg int i=b;i>=a;i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 101000
int a[maxn];
int b[maxn];
int n;
int check(int v)
{
	b[1] = v;
	rep(i,1,n-1)
	{
		b[i+1] = a[i] - b[i];
		if(b[i]<0)
		{
			if(i%2 == 1) return 1;
			else return -1;
		}
	}
	if(b[n]+b[1] < a[n]) return 1;
	else if(b[n]+b[1]>a[n]) return  -1;
	return 0;
}
void solve()
{
	n = read();
	rep(i,1,n) a[i] = read();
	int l = 0,r = a[1];
	int ans = 0;
	while(l<=r)
	{
		int mid = (l+r)>>1;
		int t = check(mid);
		if(t == 0) break;
		if(t == 1) l = mid+1;
		else r = mid - 1;
	}
	rep(i,1,n) cout<<b[i]*2<<" ";
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

Measured memory_bytes: 4444
#include<bits/stdc++.h>
using namespace std;
int n,m,a[50],b[50],A[51],B[51];
int dp[51][51][51][51][2][2];
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==-1)a[i]=0;
    A[i+1]=A[i]+a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
    if(b[i]==-1)b[i]=0;
    B[i+1]=B[i]+b[i];
  }
  for(int x=n;x>=0;x--)
    for(int y=m;y>=0;y--)
      for(int s=x;s>=0;s--)
        for(int t=y;t>=0;t--)
          for(int f=1;f>=0;f--)
            for(int p=1;p>=0;p--){
              int &res=dp[x][y][s][t][f][p];
              if(p==0){
                res=-1e9;
                if(f==1&&x==s&&y==t)res=max(res,0);
                else res=max(res,dp[x][y][x][y][x==s&&y==t][1]+A[x]-A[s]-B[y]+B[t]);
                if(x<n&&a[x]==0)res=max(res,dp[x+1][y][s][y][0][1]);
                if(x<n&&a[x]>0)res=max(res,dp[x+1][y][s][t][0][1]);
              }else{
                res=1e9;
                if(f==1&&x==s&&y==t)res=min(res,0);
                else res=min(res,dp[x][y][x][y][x==s&&y==t][0]+A[x]-A[s]-B[y]+B[t]);
                if(y<m && b[y]==0)res=min(res,dp[x][y+1][x][t][0][0]);
                if(y<m && b[y]>0)res=min(res,dp[x][y+1][s][t][0][0]);
              }
            }
  cout<<dp[0][0][0][0][0][0]<<endl;
  return 0;
}

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

int main(){
	int n,k;
  cin >>n >>k;
  int d[k];
  for(int i=0;i<k;i++)cin >>d[i];
  bool out=true;
  while(out){
    out=false;
    int s=n;
    vector<int> kazu;
    while(s!=0){
      kazu.push_back(s%10);
      s/=10;
    }
    for(int i=0;i<kazu.size();i++){
      for(int j=0;j<k;j++)if(d[j]==kazu[i])out=true;
    }
    if (out)n++;
  }
  cout <<n <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 int distance(int N, int D, int x[], int y[])
{
   int count=0;
  for(int i=0;i<N;++i)
  {
   if((pow(x[i],2)+pow(y[i],2))<=pow(D,2))
     count++;
  }
   return count;
}

int main()
{
  int N,D;
  cin>>N>>D;
  int x[N], y[N];
  for(int i=0;i<N;i++)
  {
   cin>>x[i]>>y[i];
   }
  cout<<distance(N,D,x,y);
  
  
}

Measured memory_bytes: 5152
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	string S;
  	cin >> S;
  	if(S[2]==S[3] && S[4]==S[5]){
  		cout << "Yes" <<endl;
  	}else{
  		cout << "No" <<endl;
  	}

    
  	return 0;
}


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

using namespace std;
typedef long long ll;

int main(){

  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++){
    cin >> s[i];
  }

  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;

  for (int i = 0; i < h; i++){
    cout << '#';
    cout << s[i];
    cout << '#' << endl;
  }

  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

struct SuffixArray{
    string s;
    vector<int> sa,rev;
    SuffixArray(const string &S):s(S){
        int n=s.size();
        s.push_back('$');
        sa.resize(n+1);
        iota(all(sa),0);
        sort(all(sa),[&](int a,int b){
            if (s[a]==s[b]) return a>b;
            return s[a]<s[b];
        });
        vector<int> cs(n+1,0),rs(n+1),cnt(n+1);
        rep(i,n+1) rs[i]=(int)s[i];
        for (int k=1;k<=n;k*=2){
            rep(i,n+1){
                cs[sa[i]]=i;
                if (i&&rs[sa[i-1]]==rs[sa[i]]
                &&sa[i-1]+k<=n&&rs[sa[i-1]+k/2]
                ==rs[sa[i]+k/2]) cs[sa[i]]=cs[sa[i-1]];
            }
            iota(all(cnt),0);
            copy(all(sa),rs.begin());
            rep(i,n+1){
                int sl=rs[i]-k;
                if (sl>=0) sa[cnt[cs[sl]]++]=sl;
            }
            cs.swap(rs);
        }
        rev.resize(n+1);
        rep(i,n+1) rev[sa[i]]=i;
    }
    int operator[](int i){
        return sa[i];
    }
    bool lt_substr(string &t,int si,int ti){
        int sn=s.size(),tn=t.size();
        while(si<sn&&ti<tn){
            if (s[si]<t[ti]) return 1;
            if (s[si]>t[ti]) return 0;
            ++si,++ti;
        }
        return si==sn&&ti<tn;
    }
    int lower_bound(string &t){
        int l=0,r=s.size();
        while(l+1<r){
            int m=(l+r)>>1;
            if (lt_substr(t,sa[m],0)) l=m;
            else r=m;
        }
        return r;
    }
    int upper_bound(string &t){
        ++t.back();
        int res=lower_bound(t);
        --t.back();
        return res;
    }
    int count(string &T){
        return upper_bound(T)-lower_bound(T);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string T; int Q; cin >> T >> Q;
    SuffixArray SA(T);
    rep(i,Q){
        string P; cin >> P;
        cout << (SA.count(P)>0) << endl;
    }
}


Measured memory_bytes: 24588
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    vector<int> X(N); for (auto &x : X) cin >> x;
    int ans = 1e9;
    for (int p = 1; p <= 100; p++) {
        int a = 0;
        for (auto x : X) a += (x - p) * (x - p);
        ans = min(ans, a);
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;
    V<ll> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    reverse(ALL(B));

    ll j = 0;
    REP(i, N){
        if(A[i] == B[i]){
            while(j<N){
                if(A[i] != B[j] and A[j] != B[i]) break;
                j++;
            }
            if(j<N) swap(B[i], B[j]);
        }
    }   

    REP(i, N){
        if(A[i] == B[i]){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    cout << B << endl;

    return 0;
}

Measured memory_bytes: 6316
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll H, W, N, A[10000];

int main(void) {
  cin >> H >> W >> N;
  REP(i, 0, N) cin >> A[i];

  ll ans[10000];
  ll p = 0;
  REP(i, 0, N) REP(j, 0, A[i]) ans[p++] = i + 1;
  REP(i, 0, H) if(i % 2 == 1) reverse(ans + (W * i), ans + (W * (i + 1)));

  REP(i, 0, H) REP(j, 0, W) {
    cout << ans[i * W + j];
    if(j + 1 != W) cout << " ";
    else cout << endl;
  }
}


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

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

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

struct UnionFind {
    vector<int> data;

    UnionFind(int size) : data(size, -1) {}

    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};


vector<pair<int, int> > g;

void solve(ll N, ll M, vector<ll> A, vector<ll> B) {
    UnionFind uf(2 * N);
    for (int i = 0; i < M; i++) {
        A[i]--;
        B[i]--;
        uf.unionSet(2 * A[i], 2 * B[i] + 1);
        uf.unionSet(2 * A[i] + 1, 2 * B[i]);
    }
    if (uf.size(0) == N) {
        int black = 0;
        for (int i = 0; i < N; i++) {
            if (uf.findSet(0, i * 2)) {
                black++;
            }
        }
        int white = N - black;
        cout << 1ll * black * white - M << endl;
    } else {
        assert(uf.size(0) == 2 * N);
        cout << N * (N - 1) / 2 - M << endl;
    }

}


void main_(istream &cin) {
    ll M;
    ll N;
    cin >> N;
    cin >> M;
    vector<ll> A(M - 1 + 1);
    vector<ll> B(M - 1 + 1);
    for (int i = 0; i <= M - 1; i++) {
        cin >> A[i];
        cin >> B[i];
    }
    solve(N, M, A, B);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N;
    cin >> N;
    map<int,int> mp;

    FOR(i,1,101) FOR(j,1,101) FOR(k,1,101) {
        mp[i*i+j*j+k*k+i*j+j*k+k*i]++;
    }

    REP(i,N) {
        cout << mp[i+1] << endl;
    }
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/aising2020/aising2020_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/aising2020/aising2020_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/aising2020/aising2020_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 5964
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x=max(a*d,b*c);
    ll y=max(a*c,b*d);
   
    cout<<max(x,y);
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{int to; ll cost;};

int main(){
    int N;
    cin >> N;
    vector<edge> es[2*N];
    rep(i, N){
        int x; cin >> x;
        es[i].eb((edge){N+i, x}), es[N+i].eb((edge){i, x});
    }
    rep(i, N-1){
        int u, v; ll c;
        cin >> u >> v >> c;
        u--, v--;
        es[N+u].eb((edge){N+v, c}), es[N+v].eb((edge){N+u, c});
    }

    vector<ll> d(2*N, INF);
    vector<int> c(2*N, -1);
    priority_queue<pli, vector<pli>, greater<pli> > que;
    rep(i, N) que.emplace(d[i] = 0, i), c[i] = i;
    
    while(!que.empty()){
        ll p; int i;
        tie(p, i) = que.top(); que.pop();
        if(p > d[i]) continue;
        for(auto &e: es[i]){
            if(chmin(d[e.to], d[i]+e.cost)){
                que.emplace(d[e.to], e.to);
                c[e.to] = c[i];
            }
        }
    }

    ll ans = 0;
    rep(i, 2*N){
        for(auto &e: es[i]){
            if(c[i] < c[e.to]) ans += d[i]+d[e.to]+e.cost;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 52084
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;

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

    int ans = 0;

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

    for(int i=0; i<N; i++){
        if(max < A[i]){
            max = A[i];
        }
    }

    for(int i=0; i<N; i++){
        if(min > A[i]){
            min = A[i];
        }
    }

    ans = max - min;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long X = scn.nextLong();
			long A = 0;
			long B = 0;
			long tmp = 0;

			for(int i = 0; i < 500; i++) {
				A = i;
				A *= i;
				A *= i;
				A *= i;
				A *= i;

				tmp = X - A;

				for(int j = 0; j < 500; j++) {
					B = j;
					B *= j;
					B *= j;
					B *= j;
					B *= j;

					if(tmp == B) {
						System.out.println(i + " " + (j * -1));
						System.exit(0);
					}

					if(tmp == (B * -1)) {
						System.out.println(i + " " + j);
						System.exit(0);
					}

					if(tmp <= B && tmp >= (B * -1)) break;

				}
			}
		}
	}
}

Measured memory_bytes: 27224
def F(x, y):
    if x % y == 0:
        return y
    return F(y, x % y)
while True:
    try:
        x, y = map(int,input().split())
        print('{0} {1}'.format(F(x, y), int(x * y / F(x, y))))
    except EOFError:
        break



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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
};

int main()
{
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    long p[100005], q[100005], r[100005];
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];
    
    sort(p, p + A);
    sort(q, q + B);
    sort(r, r + C);

    //REP(i, A) cout << p[i] << " ";
    //cout << endl;
    //REP(i, B) cout << q[i] << " ";
    //cout << endl;

    long ansp = 0;
    long ansq = 0;
    for(int i = A-X; i<A; i++) ansp += p[i];
    for(int i = B-Y; i<B; i++) ansq += q[i];

    int minp = A - X;
    int minq = B - Y;
    int maxr = C - 1;

    while(maxr >= 0){
        if(minp == A && minq == B) break;
        if(minp == A){
            if(r[maxr] > q[minq]){
                ansq = ansq + r[maxr] - q[minq];
                minq++;
                maxr--;
                continue;
            }else break;
        }
        if(minq == B){
            if(r[maxr] > p[minp]){
                ansp = ansp + r[maxr] - p[minp];
                minp++;
                maxr--;
                continue;
            }else break;
        }

        long temp = min(p[minp], q[minq]);
        if(temp > r[maxr]) break;

        if(p[minp] > q[minq]){
            ansq = ansq + r[maxr] - q[minq];
            minq++;
            maxr--;
        }else{
            ansp = ansp + r[maxr] - p[minp];
            minp++;
            maxr--;
        }
    }

    cout << ansp + ansq << endl;

    
    return 0;
}



Measured memory_bytes: 2560
let s: Int = Int(readLine()!)!

var res: Int = 1
var a: Int = s
var new: Int = -1
var seq: [Int] = [a]

while true {
    res += 1
    if a%2==0 {
        new = a / 2
    } else {
        new = 3 * a + 1
    }
    if seq.contains(new) {
        break
    } else {
        seq.append(new)
        a = new
    }
}
print(res)  // (๑•ૅㅁ•๑)

Measured memory_bytes: 7812
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    int N;
    int count=0;


    //入力
    cin >> N;

    vector<pair<int, int> > p(N);
    rep(i, N) cin >> p[i].first, p[i].second=i;
    sort(p.begin(), p.end() );
    rep(i, N) if(p[i].second - i != 0) count++;

    

    if(count ==2 || count == 0) cout << "YES" << endl;
    else                        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define swap(a,b,type)do{type temp; temp= a;a = b; b= temp;}while(0); 
int main(){
 string s,a;
 int b = 0;
 cin >> s>> a;
 rep(i,a.size()){
   if(s[i]==a[i]){
     b++;
   }
 }
 if(b==a.size()-1){
   cout << "Yes" << endl;
 }else{
   cout << "No" << endl;
 }
 return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    vector <int > a(2);
    REP(i,2)cin >> a[i];
    sort(ALL(a));
    REP(i,2){
        if(i+1 != a[i]){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;
typedef long long int lli;
typedef long int li;
const int inf = numeric_limits<int>::max();


bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 


int main(){
    li n;lli k;
    cin>>n>>k;
    vector<li> v(n);
    for(li i = 0;i<n;i++){
        cin>>v[i];

    }
    li loop_count = 0;
    li curr_pos = 0;
    unordered_set<li> s;
    s.insert(0);
    vector<li> visited;
    
    while(true){
        //cout<<curr_pos;
        visited.push_back(curr_pos);
        loop_count++;
        curr_pos = v[curr_pos] - 1;
        
        if(s.count(curr_pos)){
            break;
        }
        s.insert(curr_pos);

    }
    //cout<<curr_pos<<endl;
    li pre_size = 0;
    for(li i = 0;i<visited.size();i++){
        if(visited[i]==curr_pos){
            pre_size = i;
            break;
        }
    }
    li loop_size = visited.size()-pre_size;
    if(k<visited.size()){
        cout<<visited[k]+1;
        return 0;
    }
    k = k - visited.size();
    k = k%loop_size;
    cout<<visited[pre_size+k]+1;


    /*
    //cout<<loop_count;
    k = k%loop_count;
    //cout<<k;
    li pos = 0;
    for(li i = 0;i<k;i++){
        pos = v[pos]-1;
    }
    cout<<pos+1;
    */
    
}

/*
    int n,,m;
    cin>>n>>m;
    li x;cin>>x;
    vector<vector<li>> book_skill(n,vector<li>(m+1));
    for(int i = 0;i<n;i++){
        for(int j = 0;j<=m;j++){
            cin>>book_skill[i][j];
        }
    }
    sort(book_skill.begin(),book_skill.end(),sortcol());
    int max_depth = 0;
    int curr_depth = 0;
    int curr_skill = 0;
    for(int i = 0;i<n;i++){
        for(int j = 1;j<=m;j++){
            
        }
    }
*/

Measured memory_bytes: 14300
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

q = ["3", "5", "7"]

ans_list = []
ans = 0
while q:
    a = q.pop()

    if len(a) != 0:
        if int(a) <= N:
            cnt = 0
            for i in [3, 5, 7]:
                if a.count(str(i)) >= 1:
                    cnt += 1
            if cnt == 3:
                ans += 1
                ans_list.append(a)

        
            for i in [3, 5, 7]:
                b = deepcopy(a)
                b += str(i)
                q.append(b)

print(ans)
# print(ans_list)

Measured memory_bytes: 5700
n = int(input())
P = 10**9 + 7
memo = [{} for i in range(n + 1)]
def ok(last4):
    if last4.count('AGC') >= 1:return False
    for i in range(3):
        t = list(last4)
        t[i], t[i+1] = t[i+1] , t[i]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if cur == n:
        return 1
    if last3 in memo[cur]:
        return memo[cur][last3]
    ret = 0
    for c in 'AGCT':
        if(ok(last3+c)):
            ret = (ret + dfs(cur + 1, last3[1:]+c))%P
    memo[cur][last3] = ret
    return ret
print(dfs(0, 'TTT'))

Measured memory_bytes: 3852
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

w,h,n = readInts()
xya = [readInts() for i in range(n)]

xmin = 0
xmax = w
ymin = 0
ymax = h

for x,y,a in xya:
  if a==1:
    xmin = max(x,xmin)
  elif a==2:
    xmax = min(x,xmax)
  elif a==3:
    ymin = max(y,ymin)
  else:
    ymax = min(y,ymax)

print(max(0,xmax-xmin)*max(0,ymax-ymin))

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define mod 1000000007
#define PI 3.1415926535
using namespace std;
ll power(ll x, ll y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return power(x, y / 2) * power(x, y / 2);
	else
		return x * power(x, y / 2) * power(x, y / 2);
}
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modExpo((x*x)%mod,n/2);
    else                            
        return (x*modExpo((x*x)%mod,(n-1)/2))%mod;
 
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	ll n;
	cin>>n;
	ll i,a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll s=0,mx=a[0];
	for(i=1;i<n;i++)
	{
		if(a[i]>=mx)
			mx=a[i];
		else 
			s+=(mx-a[i]);
	}
	cout<<s<<endl;
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

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

int main(int argc, char const *argv[]) {
  string word, sentence;
  cin >> word;
  int count = 0;
  transform(word.begin(), word.end(), word.begin(), ::tolower);

  while (cin >> sentence) {
    if (sentence == "END_OF_TEXT") {
      break;
    }
    transform(sentence.begin(), sentence.end(), sentence.begin(), ::tolower);
    if (sentence == word) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3144
#include<stdio.h>
int main(){
	int s,i,cnt=0;
	char n[100001];
	scanf("%d",&s);
	scanf("%s",n);
	for(i=0;i<s;i++){
		if(n[i]=='O' && n[i+1]=='X' || n[i]=='X' && n[i+1]=='O'){
			cnt++;
			i++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}



Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, x;
    cin >> a >> b >> x;

    CFYN(a <= x && a+b >= x)

    return 0;
}

Measured memory_bytes: 256
def bubble_sort(num_list):
    flag = 1
    while flag:
        flag = 0
        for i in range(len(num_list)-1,0,-1):
            if int(num_list[i][1:]) < int(num_list[i-1][1:]):
                num_list[i],num_list[i-1] = num_list[i-1],num_list[i]
                flag = 1

def selectin_sort(num_list):
    for i in range(len(num_list)):
        min_idx = i
        for j in range(i,len(num_list)):
            if int(num_list[j][1:]) < int(num_list[min_idx][1:]):
                min_idx = j
        num_list[i],num_list[min_idx] = num_list[min_idx],num_list[i]

n = input()
card_list_1 = [i for i in input().split()]
card_list_2 = [i for i in card_list_1]
bubble_sort  (card_list_1)
selectin_sort(card_list_2)

print(' '.join(card_list_1))
print('Stable')
print(' '.join(card_list_2))
if card_list_1 == card_list_2:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    
    double X = N / 1.08;
  	if (X - (int)X == 0) {
      	cout << (int)X << endl;
    }
    else if (X - (int)X < 1 - (1 / 1.08)) {
        cout << ":(" << endl;
    }
    else {
        cout << ceil(X) << endl;
    }
    
    //getline(cin, str);
    //vector < vector < int > > A(x, vector(y, 0));
    //int avg = round((float)accumulate(X.begin(), X.end(), 0.0) / N);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int a[1005];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int n,m;
	cin>>n>>m;
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]*4*m>=sum)  cnt++;
	} 
	if(cnt>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256