akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define repvin(n) vint a(n);r(i,n)cin>>a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60

signed main(){
  int a,b,q;
  cin>>a>>b>>q;
  vector<int> s(a),t(b),x(q);
  repi(a)cin>>s[i];
  repi(b)cin>>t[i];
  repi(q)cin>>x[i];
  s.pb(INF);s.pb(-INF);
  t.pb(INF);t.pb(-INF);
  SORT(s);SORT(t);
  int res=INF;
  rep(i,q){
    int sitr=lower_bound(all(s),x[i])-s.begin();
    int titr=lower_bound(all(t),x[i])-t.begin();
    int sitr2=sitr-1;
    int titr2=titr-1;
    sitr=s[sitr];
    sitr2=s[sitr2];
    titr=t[titr];
    titr2=t[titr2];
    vector<int> ans;
    ans.pb(min(abs(x[i]-sitr)+abs(sitr-titr),abs(x[i]-titr)+abs(titr-sitr)));
    ans.pb(min(abs(x[i]-sitr2)+abs(sitr2-titr2),abs(x[i]-titr2)+abs(titr2-sitr2)));
    ans.pb(min(abs(x[i]-sitr)+abs(sitr-titr2),abs(x[i]-titr2)+abs(titr2-sitr)));
    ans.pb(min(abs(x[i]-sitr2)+abs(titr-sitr2),abs(x[i]-titr)+abs(titr-sitr2)));
    SORT(ans);
    cout<<ans[0]<<endl;
  }


  return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <string>
using namespace std;

const int MOD = 1e9+7;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string>arr(h+1);
    vector<vector<int>>dp(h+1,vector<int>(w+1));
    for(int i=1; i<=h; i++){
        cin>>arr[i];
    }
    dp[1][1]=1;
    for(int i=0; i<=h; i++){
        for(int j=0; j<=w; j++){
            if(arr[i][j-1]=='.'&&(i!=1||j!=1)&&i!=0&&j!=0){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }else if((i!=1||j!=1)){
                dp[i][j] = 0;
            }
        }
    }

    cout<<dp[h][w];
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define reps(i,start,end,step) for(int i=start;i< end;i+=step)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define Pr(x) cout << x << endl
#define Prs(x) cout << x << " "

long long s[1000000];
long long a[1005];

int main()
{
    long long N, K;
    cin >> N >> K;

    rep(i, N){
        cin >> a[i];
    }

    long long idx =0;
    rep(i, N){
        long long temp=0;
        for(int j=i; j<N; j++){
            temp += a[j];
            s[idx] += temp;
            idx++;
        }
    }
    
    //sort(s, s+idx, std::greater<long long>());
    //rep(i, idx) cout << static_cast<std::bitset<8> >(s[i]) << endl;
    ll bmax=42;
    ll b = 0;
    ll ans =0;
    for(ll i; i<bmax;i++){
        int bnum=0;
        b = 1LL << (bmax - i-1);
        //Pr(b);
        ans += b;
        rep(j, idx){
            if ((ans & s[j]) == ans){
                bnum++;
            }
        }
        if (bnum < K) ans -=b;
    }
    cout << ans << endl;    
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;

    for(int i = 0; i < N-2; i++){
        char tmp1 = S[i];
        char tmp2 = S[i+1];
        char tmp3 = S[i+2];

        if(tmp1 == 'A' && tmp2 =='B' && tmp3 == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		long A=stdIn.nextLong();
		long B=stdIn.nextLong();
		long C=stdIn.nextLong();
		if(A%2==1||B%2==1||C%2==1)
			System.out.println(0);
		else{
			if(A==B&&B==C)
				System.out.println(-1);
			else{
				int ans=0;
				long a=0,b=0,c=0;
				while(true){
					a=B/2+C/2;
					b=A/2+C/2;
					c=B/2+A/2;
					A=a;B=b;C=c;
					ans++;
					if(A%2==1||B%2==1||C%2==1)
						break;
				}
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;
template <typename T>
using PQ = priority_queue<T>;

int main() {
    int n;
    PQ<ll> q;
    q.push(0); q.push(0);
    cin >> n;
    map<ll, int> m;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        m[x]++;
        if(m[x]%2 == 0){
             q.push(x);
        }
    }
    ll a = q.top(); q.pop();
    ll b = q.top(); q.pop();
    cout << a * b << "\n";
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
int n,k;
signed main(){
    cin>>n>>k;
    int ans=n-k+1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
int main()
{
    int h, w, i, j;
    while (1) {
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) {
            break;
        }
        else if (h != 0 && w != 0) {
            for (i = 0; i < h; i++) {
                for (j = 0; j < w; j++) {
                    printf("#");
                }
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> F(H, vector<char>(W, '.'));
    rep(i, H){
        rep(j, W){
            cin >> F[i][j];
        }
    }

    ll ans = 0;
    for(ll bit_h=0;bit_h<(1<<H); ++bit_h){
        for(ll bit_w=0;bit_w<(1<<W);++bit_w){
            vector<vector<char>> F2 = F;
            rep(i, H){
                if((bit_h>>i)&1){
                    rep(j, W){
                        F2[i][j] = '&';
                    }
                }
            }
            rep(i, W){
                if((bit_w>>i)&1){
                    rep(j, H){
                        F2[j][i] = '&';
                    }
                }
            }

            ll num = 0;
            rep(i, H){
                rep(j, W){
                    num += (F[i][j] == '#') & (F2[i][j] == '#');
                }
            }

            ans += (num == K);

        }
    }

    cout << ans <<endl;
}

int main(){
    // ll a = 10;
    // cout << (a>>1 & 1) << endl;
    Main();
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 107;
int H, W, X, Y, ans;
short f[N][N][N][N];
short s1[N][N], s2[N][N];
char s[N][N];
int main() {
#ifdef fwat
#endif
	H = gi(), W = gi();
	rep(i, 1, H) {
		scanf("%s", s[i] + 1);
		rep(j, 1, W) if(s[i][j] == 'E') X = i, Y = j;
	}
	rep(i, 1, H)
	rep(j, 1, W) {
		s1[i][j] = s1[i - 1][j];
		s2[i][j] = s2[i][j - 1];
		if(s[i][j] == 'o')
			++s1[i][j], ++s2[i][j];
	}
	int xl = X - 1, xr = H - X, yl = Y, yr = W - Y;
	rep(a, 0, xl) {
		rep(b, 0, xr)
		rep(c, 0, yl)
		rep(d, 0, yr) {
			int L = max(Y - c, d + 1), R = min(Y + d, W - c);
			if(L <= R) {
				Max(f[a + 1][b][c][d], short(f[a][b][c][d] + (X - a - 1 <= b ? 0 : s2[X - a - 1][R] - s2[X - a - 1][L - 1])));
				Max(f[a][b + 1][c][d], short(f[a][b][c][d] + (X + b + 1 > H - a ? 0 : s2[X + b + 1][R] - s2[X + b + 1][L - 1])));
			}
			L = max(X - a, b + 1), R = min(X + b, H - a);
			if(L <= R) {
				Max(f[a][b][c + 1][d], short(f[a][b][c][d] + (Y - c - 1 <= d ? 0 : s1[R][Y - c - 1] - s1[L - 1][Y - c - 1])));
				Max(f[a][b][c][d + 1], short(f[a][b][c][d] + (Y + d + 1 > W - c ? 0 : s1[R][Y + d + 1] - s1[L - 1][Y + d + 1])));
			}
		}
	}
	printf("%d\n", f[xl][xr][yl][yr]);
	return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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


bool is_prime(int n) {
  int limit = ceil(sqrt(n + 0.5));
  
  for (int i = 2; i < limit; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  int n; cin >> n;
  
  int sum = 0;
  REP(i, n) {
    int m; cin >> m;
    if (is_prime(m)) ++sum;
  }
  
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>

int main(void)
{

  long long int w,h,x,y;
  scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
  long double ans=(double)w*h/2;
  printf("%.10llf\n",ans);

  if((double)h/2==(double)y&&(double)w/2==(double)x){
    printf("1");
    return 0;
  }
  else {
    printf("0");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
int k, n;
char s[20];
bool vis[10];
bool check(int i){
	do{
		int t=i%10;
		i/=10;
		if(vis[t])return 0;
	}while(i);
	return 1;
}
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 0, k){
		int t;
		scanf("%d", &t);
		vis[t]=1;
	}
	rep(i, n, 1e6){
		if(check(i)){
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

class Stack{
private:
  int inf[1000];
  int tp;

public:

  Stack(){
    tp=0;
  }


  void push(int x){
    tp++;
    inf[tp] = x;
  }

  void pop(){
    tp--; 
  }

  int top(){
    int x = inf[tp];
    return x;
  }

  bool isempty(){
    if(tp == 0)return true;
    return false;
  }

  int size(){
    return tp;
  }

};

 

int main(){
  Stack stack;
  string str,s[10000];
  int ind=0,th=0;
  
  getline(cin,str);
  for(int i=0;i<str.length();i++){
    
    if(str[i] == ' ')
      {
	th=0;
	ind++;
      }    else
      {
	
	s[ind].insert(th,str.substr(i,1));
	th++;
      }
  }
  ind++;

  for(int i=0;i<ind;i++){
       
    if(s[i] == "+" || s[i] == "*" || s[i] == "-")
      {
	
	int x2 = stack.top();
	stack.pop();
	int x1 = stack.top();
	stack.pop();
	if(s[i] == "+")
	  {
	    stack.push(x1+x2);
	  }       
	else if(s[i] == "-")
	  {
	    stack.push(x1-x2);
	  }
	else if(s[i] == "*")
	  {
	    stack.push(x1*x2);
	  }
      }
    else 
      {
	if(s[i] == " ")continue;
	int n = atoi(s[i].c_str());
	stack.push(n);
      }
  }
  cout << stack.top() << endl;


}

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

long long int gcd(long long int x, long long int y){
  long long int tmp;
  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }

  long long int r = x%y;
  while(r!=0){
    x = y;
    y = r;
    r = x%y;
  }

  return y;
}

int main()
{
  long long int n, x, y, a, ans;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(i == 0){
      y = a;
    }else{
      y = gcd(y, a);
    }
  }
  ans = y;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int mod;

void plusle(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
}

int mul(int a, int b) {
    return (int)((ll) a * b % mod);
}

int power(int a,int b) {
    int res=1;
    while (b>0) {
        if (b&1) res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res;
}
int inv(int x) {
    return power(x,mod-2);
}

vector<int> mul(const vector<int> &p,int j) {
    /// c[0]+(c[1]*x)+(c[2]*(x^2)+...)c[n-1]*(x^(n-1))
    /// multiply
    /// (x-j)
    int n = SZ(p);
    vector<int> s(n+1,0); // 0 -> n
    FOR(i,0,n-1) plusle(s[i+1], p[i]);
    FOR(i,0,n-1) plusle(s[i], mul(p[i], j));
    return s;
}

vector<int> div(vector<int> p,int j) {
    /// c[0]+c[1]*x+...+c[n-1]*(x^(n-1))
    /// divide
    /// x-j
    int n = SZ(p);
    vector<int> s(n-1,0);
    FORE(i,n-1,1) {
        plusle(p[i-1], mul(j,p[i]));
        s[i-1]=p[i];
    }
    return s;
}

int get(const vector<int> &g,int x){
    int res=0;
    int now=1;
    FOR(i,0,SZ(g)-1) {
        plusle(res, mul(g[i], now));
        now = mul(now, x);
    }
    return res;
}

int p, a[MAXN];
vector<int> t = {0,1}; // x

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> p;
    mod = p;
    FOR(i,0,p-1) cin >> a[i];
    FOR(i,1,p-1) t = mul(t,i);
    vector<int> res(p, 0);

    FOR(i,0,p-1) {
        if (!a[i]) continue;
        vector<int> s = div(t,i);
        int cur = get(s,i);
        cur = inv(cur);
        FOR(j,0,SZ(s)-1) plusle(res[j], mul(s[j], cur));
    }

    FOR(i,0,p-1) cout << res[i] << ' ';
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(void){
  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << endl;
}

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

#define endl "\n"
#define ll long long
#define pb emplace_back
#define fi first
#define se second
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double

#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=n-1; i>=0; i--)
#define repa(i,a,b) for(ll i=(a);i<=(b);i++)
#define all(x) (x).begin(), (x).end()
#define ordered_set tree<int , null_type, less<int> , rb_tree_tag, tree_order_statistics_node_update>
/*
 Ordered set docs:
 order_of_key (k) : Number of items strictly smaller than k .
 find_by_order(k) : K-th element in a set (counting from zero).
*/
#define blc boost::lexical_cast<long long>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
const int MOD = 1e9+7;

ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);}

ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);}

ll lcm(ll x, ll y) {ll res=(x*y)/__gcd(x,y); return res;}

ll powerLL(ll x, ll n, ll mod) 
{ 
    ll result = 1; 
    while (n) { if (n & 1) result = (result%mod * x%mod) % mod; n = n / 2; x = (x%mod * x%mod) % mod; } return result; 
} 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve()
{
    ll a,b,c, k;
    cin>>a>>b>>c>>k;
    while(b<=a)
    {
    	b*=2;
    	k--;
    }
    while(c<=b)
    {
    	c*=2;
    	k--;
    }
    if(k>=0)
    	cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
int32_t main()
{
    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0; 
}

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

using namespace std;

#define ld long double
#define ll long long int
#define endl '\n'
#define check_time() cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1e9+7
#define INF 0x3f3f3f3f
#define maxarr(A,n) *max_element(A,A+n) 
#define minarr(A,n) *min_element(A,A+n);

int main()
{
	fastio();
	
	char str[4];
	cin>>str;
	if(str[1]=='B')
		cout<<"ARC"<<endl;
	else
		cout<<"ABC"<<endl;
	return 0;   
}   


Measured memory_bytes: 3648
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 19-Apr-2020 18:36:21
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;


int solve() {
    int n, m; Int(n, m);

    int sum = 0;
    FOR (i, 1, m) {
        int x; Int(x);
        sum += x;
        if (sum > n) {
            return puts("-1");
        }
    }

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

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 21;

int dp[1<<maxn];
const int mod = 1e9 + 7;

void add(int &a, int b){
	a += b;
	if(a >= mod){a -= mod;}
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	int a[maxn][maxn];
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	dp[0] = 1;
	
	for(int k=0;k<(1<<n);k++){
		i = __builtin_popcount(k);
		for(j=0;j<n;j++){
			if(a[i][j] == 0){continue;}
		
			if(!(k & (1<<j))){
				add(dp[k | (1<<j)], dp[k]);
			}
		}
	}

	printf("%d\n",dp[(1<<n)-1]);
	return 0;
};

Measured memory_bytes: 8448
import math
import sys
from collections import Counter
readline = sys.stdin.readline


def main():
    s = readline().rstrip()
    t = readline().rstrip()
    cnt = 0
    for k in range(len(s)):
        cnt += 1 if s[k] != t[k] else 0
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9564
import math


def check(arr, d):
    count = 0
    length = len(arr)
    # print(length)
    for i in range(length):
        for j in range(i + 1, length):
            sum = 0
            for k in range(d):
                sum += (arr[i][k] - arr[j][k]) ** 2
            # print(math.sqrt(sum))
            # print(math.sqrt(sum).is_integer())
            if(math.sqrt(sum).is_integer() == True):
                # print(math.sqrt(sum))
                count += 1
    return count


s = []
s = input().split(' ') #0:n 1:d
n = int(s[0])
d = int(s[1])

arr = []

ans = 0
for i in range(n):
    s = input().split(' ')
    point = []
    for j in range(d):
        point.append(int(s[j])) 
    arr.append(point)
    # print(arr)


print(check(arr, d))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < n - k; i++)
    {
        long first = a[i];
        long second = a[k + i];
        if (second > first)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4832
#include <stdio.h>
#define MAX_N 10000

int par[MAX_N], rank[MAX_N];
int n, q;

void init(int n);
void unite(int a, int b);
int find(int x);

int main(void)
{
    int i;
    int com, a, b;

    scanf("%d %d",&n, &q);

    init(MAX_N);

    for (i = 0; i < q; i++) {
        scanf("%d %d %d",&com, &a, &b);
        if (com) {
            if (find(a) == find(b)) {
                puts("1");
            } else {
                puts("0");
            }
        } else {
            unite(a, b);
        }
    }
    return 0;
}

void init(int n) 
{
    int i;
    for (i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        par[x] = find(par[x]);
        return par[x];
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) {
        return ;
    }

    if (rank[x] < rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

Measured memory_bytes: 660
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  int cont =0;
  int a,b;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    string s=to_string(i),s_rev=to_string(i);
    reverse(all(s_rev));
    if(s==s_rev) cont++;
  }
  cout << cont << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 2e5+5;

int n,x,y;
vector<pair<int,int>>P;
int A[N], tree[N], X[N], Y[N];
int sz[N], par[N];

int find_set(int x){
    if(par[x] == x) return x;
    return  par[x] = find_set(par[x]);
}

void union_set(int x,int y){
    if(sz[x] < sz[y]){
        swap(x,y);
    }
    sz[x] += sz[y];
    par[y] = x;
}

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

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x >> y;
        P.pb({x,i});
        X[i] = x; Y[i] = y;
        A[y] = i;
        par[i] = i;
        sz[i] = 1;
    }

    sort(P.begin(),P.end());
    vector<int>v;
    for(int i = 0; i < n; i++){
        int ind = P[i].ss;
        int y = Y[ind];
        if(v.size() == 0){
            v.pb(y);
        }
        else {
            int x = v.back();
            while(v.size() && v.back() < y){
                int a = find_set(A[y]);
                int b = find_set(A[v.back()]);
                if(a != b)union_set(a,b);
                v.pop_back();
            }
            x = min(x, y);
            v.pb(x);
        }
    }

    for(int i = 1; i <= n; i++){
        cout << sz[find_set(i)] << " ";
    }
}


Measured memory_bytes: 8952
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 998244353;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
ll n,sum;
ll ar[3005];
ll dp[3005][3005];
ll solve(ll idx,ll ss)
{
  if(idx>=n)
  {
     return 0; 
  }
  if(dp[idx][ss]!=-1) return dp[idx][ss];
  ll ans=0;
  if(ar[idx]==ss)
  {
     ans=(n-idx+solve(idx+1,ss))%MOD;
  }
  else if(ar[idx]<ss)
  {
     ans=(solve(idx+1,ss)+solve(idx+1,ss-ar[idx]))%MOD;
  }
  else
  {
    ans=solve(idx+1,ss)%MOD;
  }
  return dp[idx][ss]=ans%MOD;
}
int32_t main()
{   
     IOS;
     cin>>n>>sum;
     memset(dp,-1,sizeof dp)
;     for(ll i=0;i<n;i++) cin>>ar[i];
      ll f=0;
    for(ll i=0;i<n;i++)
    {
      f+=solve(i,sum);
      f%=MOD;
    }
    cout<<f<<endl;
     
     
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 70912
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"


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

	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	if(in[0]==0){
		cout<<0<<endl;
	}else{
		int t=1;
		rep(i,n){
			if(t>1000000000000000000ll/in[i]){
				cout<<-1<<endl;
				return 0;
			}
			t*=in[i];
		}
		cout<<t<<endl;
	}

}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define INF 100005

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    vector<int>a;
    int num;
    cin >> num;
    a.push_back(num);
    cin >> num;
    a.push_back(num);
    cin >> num;
    a.push_back(num);
    sort(a.begin(),a.end());
    if(a[0]==5 && a[1]==5 && a[2]==7)
    {
    	cout << "YES" << "\n"; 
    }else
    {
    	cout << "NO" << "\n";
    }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
use std::cmp::{max};

fn main() {
    input! {
        n: usize,
        s: String,
    }
    println!("{}", max(0,
             s.chars().map(|c| if c == 'I' {1} else {-1}).collect::<Vec<i32>>().iter().cloned()
             .scan(0, |state, i| {
                 *state += i;
                 Some(*state)
             }).max().unwrap())
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;

int main(){
    ll n;
    const ll d=1000000007;
    ll sum=0;
    ll ans=0;
    cin>>n;
    vector<ll>a(n);
    vector<ll>b(n);
    rep(i,n){
        cin>>a[i];
        b[i]=a[i]%d;
        sum+=a[i];
    }

    rep(i,n-1){
        sum-=a[i];
        ans+=(b[i]*(sum%d))%d;
    }
    cout<<ans%d;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,x,y,z;
  cin>>x>>y>>z;
  for(int i=0;i<=x/y+1;i++){
    a=y*i+z*(i+1);
    if(a>x){
      if(i-1>=0){
        cout<<i-1<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

const double PI=3.14159265358979323846;

int main(){
  double r;
  cin >> r;
  cout << setprecision(20) << r*2*PI << endl;
}

Measured memory_bytes: 3788
#include <stdio.h>

int main (void){
  int n;
  scanf("%d",&n);
  
  int a[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&a[i]);
  }

  int max = a[0] , min = a[0];
  
  for(int i = 0;i < n;i ++){
    if(a[i] > max){
      max = a[i];
    } 
    else if(a[i] < min){
      min = a[i];
    }
  }
  
  printf("%d",max - min);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;

int main() {

  string s; cin >> s;

  int a[3] = {0,0,0};

  for(int i=0; i<s.size(); i++){
    a[ s[i]-'a' ]++;
  }
  if( max({a[0],a[1],a[2]}) - min({a[0],a[1],a[2]}) <= 1 ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

// EOF


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k) cout << s << "\n";
    else {
        for (int i = 0; i < k; i++) cout << s[i];
        cout << "...\n";
    }
}

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

typedef long long ll;
const int maxn = 2e5;
int n, p[maxn + 3], v[maxn + 3], fa[maxn + 3];
bool vis[maxn + 3];
ll ans;

struct thing {
	int x, y, u, f;
	friend bool operator > (const thing &a, const thing &b) {
		return 1ll * a.x * b.y < 1ll * b.x * a.y;
	}
} cur[maxn + 3];

priority_queue<thing, vector<thing>, greater<thing> > H; 

int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		scanf("%d", &p[i]);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", &v[i]);
	}
	for (int i = 1; i <= n; i++) {
		fa[i] = i;
		cur[i].u = i, cur[i].f = p[i];
		cur[i].x = !v[i], cur[i].y = v[i];
		H.push(cur[i]);
	}
	while (!H.empty()) {
		thing x = H.top();
		H.pop();
		if (!x.f || vis[x.u]) {
			continue;
		}
		vis[x.u] = true;
		int u = x.u, v = find(x.f);
		ans += 1ll * cur[v].y * cur[u].x;
		cur[v].x += cur[u].x;
		cur[v].y += cur[u].y;
		fa[u] = v;
		H.push(cur[v]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,x,t; cin >> n >> x >> t;
  cout << ((n+x-1)/x)*t << endl;
  return 0;
}


Measured memory_bytes: 3596
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

const int NMAX = int(1e6);
ll fact[NMAX+1], finv[NMAX+1], inv[NMAX+1];

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

void comb_init(int N) {
    // init
    REP(i, 2) {
        fact[i] = 1;
        finv[i] = 1;
        inv[i] = 1;
    }

    FOR(i, 2, N+1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return (fact[n] * finv[k] % MOD) * finv[n-k] % MOD;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K;
    cin >> N >> K;

    comb_init(N);

    mint ans = 0;
    REP(i, min(K, N - 1) + 1) {
        ans += comb(N, i) * comb(N - 1, i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define inf 1000000007
using namespace std;
int main()
{
    ll i,j,k,n,t;
    string s;
    cin>>n;
    cin>>s;
    ll x,f;
    x=f=0;
    FOR(i,0,n-1)    {
        if(s[i]=='I') x++;
        else x--;
        f=max(f,x);
    }
    cout<<f<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=2e3+5;
const ll MOD=1e9+7;
const ll INF=1e18;
const double eps=1e-10;
ll n,m,l[MAXN][MAXN],r[MAXN][MAXN],u[MAXN][MAXN],d[MAXN][MAXN];
char str[MAXN][MAXN];
void precalc()
{
    //计算l
    for(ll i=1;i<=n;i++)
    {
        l[i][0]=0;
        for(ll j=1;j<=m;j++)
        {
            l[i][j]=l[i][j-1];
            if(str[i][j]=='#')
            {
                l[i][j]=j;
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        r[i][m+1]=m+1;
        for(ll j=m;j>=1;j--)
        {
            r[i][j]=r[i][j+1];
            if(str[i][j]=='#')
            {
                r[i][j]=j;
            }
        }
    }


    for(ll j=1;j<=m;j++)
    {
        d[n+1][j]=n+1;
        for(ll i=n;i>=1;i--)
        {
            d[i][j]=d[i+1][j];
            if(str[i][j]=='#')
            {
                d[i][j]=i;
            }
        }
    }


    for(ll j=1;j<=m;j++)
    {
        u[0][j]=0;
        for(ll i=1;i<=n;i++)
        {
            u[i][j]=u[i-1][j];
            if(str[i][j]=='#')
            {
                u[i][j]=i;
            }
        }
    }



}
ll calc(ll x,ll y)
{
    if(str[x][y]=='#')
    {
        return 0;
    }
    ll lb=l[x][y];
    ll rb=r[x][y];
    ll ub=u[x][y];
    ll db=d[x][y];
    return (rb-lb-1)+(db-ub-1)-1;
}
void solve()
{
    ll ans=0;
    precalc();
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            ans=max(ans,calc(i,j));
        }
    }
    printf("%lld\n",ans);
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
    while(~scanf("%lld %lld",&n,&m))
    {
//        string ss;
//        cin>>ss;
//        cout<<ss<<endl;
        for(ll i=1;i<=n;i++)
        {
            scanf("%s",str[i]+1);
        }
        solve();
    }
}
/*

*/


Measured memory_bytes: 129792
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int k,n;
  cin>>k>>n;
  int a[n+1];
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  sort(a+1,a+1+n);
  int mx=0;
  for(int i=1;i<n;i++){
    mx=max(mx,a[i+1]-a[i]);
  }
  mx=max(mx,a[1]-a[n]+k);
  cout<<k-mx;
}

Measured memory_bytes: 1024
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next()), y = Integer.parseInt(sc.next());
    for (int i = 0; i < n+1; i++){
      for (int j = 0; j < n-i + 1; j++){
        int k = n - i - j;
        int sum = 10000*i + 5000*j + 1000*k;
        if (sum == y){
          System.out.println(i + " " + j + " " + k);
          return;
        }
      }
    }
    System.out.println(-1 + " " + -1 + " " + -1);
  }
}


Measured memory_bytes: 39664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n, a, b;
  string s;
  cin >> n >> a >> b;
  int totalpass = 0;
  int overseaspass = 0;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    string ret = "No";
    if(s[i] == 'a' && totalpass < a+b) {
      ret = "Yes";
      totalpass++;
    }
    else if(s[i] == 'b' && totalpass < a+b && overseaspass < b) {
      ret = "Yes";
      totalpass++;
      overseaspass++;
    }
    cout << ret << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 848
N,H=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)

am=max(A)
pop=[]
for i in reversed(range(N)):
  if B[i]<am:
    B.pop(i)
    A.pop(i)

n=0
for i in reversed(sorted(B)):
  if H<=0:
    print(n)
    exit()
  else:
    n+=1
    H-=i

print((H-1)//am+1+n)



Measured memory_bytes: 12120
#include "bits/stdc++.h"
using namespace std;

template <class... Args>
void gin(Args&&... args) { (cin >> ... >> args); }
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long

void solve(){
 int n; gin(n);
 string s;gin(s);
//  Choose two stones (not necessarily adjacent) and swap them.
// Choose one stone and change its color (from red to white and vice versa).
 int cnt = count(all(s),'W');
 int ans = 0;
 for(int i=n-1;i>=0;i--,cnt--){
 	if(!cnt) break;
 	if(s[i] == 'R') ans++;

 }
 cout << ans;
}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}

Measured memory_bytes: 3740
<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
$memo = [];
for ($i=0; $i < $cnt; $i++) { 
    for ($j=0; $j < $cnt; $j++) { 
        if ($i === $j || in_array($j.'_'.$i, $memo)) {
            continue;
        }
        $ans+=$nums[$i]*$nums[$j];
        $memo[] = $i.'_'.$j;
    }
}
echo $ans;

Measured memory_bytes: 4604
def solve(i, m, s, memo={}):
    if (i, m) in memo:
        return memo[(i, m)]

    if m == 0:
        memo[(i, m)] = True
        return True

    if m < 0:
        memo[(i, m)] = False
        return False

    if len(s) <= i:
        return False

    ret = solve(i+1, m, s, memo) or solve(i+1, m-s[i], s, memo)
    memo[(i, m)] = ret

    return ret

def main():
    _ = input()
    ss = [int(x) for x in input().split(' ')]

    _ = input()
    ms = [int(x) for x in input().split(' ')]

    for m in ms:
        if solve(0, m, ss):
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    main()



Measured memory_bytes: 9324
#include <cstdio>

using namespace std;

using int64 = long long;

class Combination {
 public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 800000;
  class LookupTable {
   public:
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt{};
  // return nCk
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) %
           mod_;
  }

 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};

template<typename T> inline void fastin(T& num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

Combination com;

int main() {
  int x, y; fastin(x); fastin(y);
 
  if ((x + y) % 3 != 0) {
    printf("%d\n", 0);
    return 0;
  }
 
  int nn = (x + y) / 3;
  int r = x - nn;
 
  int64 ans = com.Get(nn, r);
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;

int multi(int c) {
	int ans = 1;
	rep(i, c) {
		ans *= 2;
	}
	return ans;

}

int main() {
	int r,g,b,k;
	cin >> r >> g >> b >> k;

	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k - i; j++) {
			int l = k - i - j;
			int cur_r = r * multi(i);
			int cur_g = g * multi(j);
			int cur_b = b * multi(l);

			// b > g > r 
			if (cur_g > cur_r && cur_b > cur_g) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3128