akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, K;
int x[MAX], y[MAX];
char c[MAX];
int a[4010][4010];

int s(int lx, int ly, int rx, int ry) {
  return a[lx][ly] + a[rx][ry] - a[lx][ry] - a[rx][ly];
}

int main() {
  // 入力
  cin >> N >> K;
  for (int i = 0; i < N; i++) scanf("%d %d %c", x + i, y + i, c + i);

  // 白、黒の区別をなくす
  for (int i = 0; i < N; i++) if (c[i] == 'W') {
    x[i] += K;
  }

  // 全てのマスを2K × 2Kの範囲に収める
  for (int i = 0; i < N; i++) {
    x[i] %= 2 * K;
    y[i] %= 2 * K;
    x[i]++;
    y[i]++;
  }

  // 各マスのK * Kの範囲の四隅に+1する
  for (int i = 0; i < N; i++) {
    a[x[i]][y[i]]++; // 左下
    a[x[i]+2*K][y[i]]++; // 右下
    a[x[i]][y[i]+2*K]++; // 左上
    a[x[i]+2*K][y[i]+2*K]++; // 右上
  }

  // 累積和をとる
  for (int i = 1; i <= 4 * K; i++) {
    for (int j = 0; j <= 4 * K; j++) {
      a[i][j] += a[i-1][j];
    }
  }
  for (int i = 0; i <= 4 * K; i++) {
    for (int j = 1; j <= 4 * K; j++) {
      a[i][j] += a[i][j-1];
    }
  }

  int ans = 0;
  for (int i = 0; i < 2 * K; i++) {
    for (int j = 0; j < 2 * K; j++) {
      ans = max(ans, s(i, j, i + K, j + K) + s(i + K, j + K, i + 2 * K, j + 2 * K));
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 64000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    vector<ll> c(26);
    rep(i,N){
        c[S[i] - 'a']++;
    }
    ll sum = 0;
    rep(i,26){
        sum += (c[i]*(c[i]-1))/2;
    }
    ll ans = 1 + N*(N-1)/2 - sum;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n)cout<<a[i]<<(i!=n-1?' ':'\n')
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


int n,m,_,x,y,q;
string s;

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

  cin>>n; int ans=-1e9,a[n],mi[n]; fill(mi,mi+n,1e9);
  rep(i,n)cin>>a[i];
  rer(i,1,n){
    mi[i]=min(mi[i-1],a[i-1]);
    cmax(ans,a[i]-mi[i]);
  }
  END
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i]-1;
        
    }
    if(n==1){
        if(a[0]==1)cout<<"Second"<<endl;
        else cout<<"First"<<endl;
        return 0;
    }
    if(n==2){
        if(a[0]%2&&a[1]%2)cout<<"Second"<<endl;
        else cout<<"First"<<endl;
        return 0;
    }
    if(sum%2==1){
        cout<<"First"<<endl;
        return 0;
    }
    ll now=0;
    for(;;){
        ll cnt=0;
        ll num=0;
        rep(i,0,n){
            cnt+=a[i]%2;
            if(a[i]%2)num=i;
        }
        if(cnt>=2){
            if(now==0)cout<<"Second"<<endl;
            else cout<<"First"<<endl;
            return 0;
        }
        if(a[num]==1){
            if(now==0)cout<<"Second"<<endl;
            else cout<<"First"<<endl;
            return 0;
        }
        a[num]--;
        ll g=a[0];
        rep(i,1,n)g=gcd(g,a[i]);
        ll su=0;
        rep(i,0,n){
            a[i]/=g;
            su+=a[i]-1;
        }
        if(su%2==1){
            if(now==0)cout<<"Second"<<endl;
            else cout<<"First"<<endl;
            return 0;
        }
        now^=1;
    }
}






Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n ==1 )
		cout << "1" << endl;
	if (2 <= n && n < 4)
		cout << "2" << endl;
	if (4 <= n && n < 8)
		cout << "4" << endl;
	if (8 <= n && n < 16)
		cout << "8" << endl;
	if (16 <= n && n < 32)
		cout << "16" << endl;
	if (32 <= n && n < 64)
		cout << "32" << endl;
	if (64 <= n && n <= 100)
		cout << "64" << endl;

}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0005

#include <stdio.h>

int cal_gcd(int a, int b)
{
    int t;
    
    if (a < b){
        t = a;
        a = b;
        b = t;
     }
        
     while (a % b != 0){
        t = b;
        b = a % b;
        a = t;
    }
    return (b);
}

int main(void)
{
    int a, b;
    int gcd, lcm;
    
    while (scanf("%d%d", &a, &b) != EOF){
        gcd =cal_gcd(a, b);
        
        lcm = a / gcd * b;
        
        printf("%d %d\n", gcd, lcm);
    }
    
    return (0);
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const int INF = 1 << 28;



int main() {
    int N; cin >> N;
    int n = pow(2, N);
    multiset<int> S;
    rep(i, n) {
        int c; cin >> c;
        S.insert(-c);
    }

    vi vec;
    vec.pb(*S.begin());
    S.erase(S.begin());
    bool can = true;

    while(!S.empty()){
        vi tmp = vec;
        for(auto x: vec){
            auto itr = S.lower_bound(x+1);
            if(itr == S.end()){
                can = false;
                break;
            }
            tmp.pb(*itr);
            S.erase(itr);
        }
        if(!can) break;
        vec.swap(tmp);
    }

    cout << (can ? "Yes" : "No") << endl; 


}


Measured memory_bytes: 14196
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

string s,t;

int main() {
	cin>>s>>t;
	cout<<(s+t.back()==t?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
 
typedef pair<int, int> P;
typedef pair<int, P> P2;
 
int W, H;
 
int T[30][30];
int V[30][30];
 
int DX[4] = {0, -1, 1, 0};
int DY[4] = {-1, 0, 0, 1};
 
int main() {
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;
    for (int i=0; i<H; i++) {
      for (int j=0; j<W; j++) {
        T[j][i] = 0, V[j][i] = 0;
      }
    }
    for (int i=0; i<H; i++) {
      for (int j=0; j<W-1; j++) {
        int x; cin >> x;
        if (x == 1) {
          T[j  ][i] |= 4;
          T[j+1][i] |= 2;
        }
      }
      if (i == H-1) continue;
      for (int j=0; j<W; j++) {
        int x; cin >> x;
        if (x == 1) {
          T[j][i  ] |= 8;
          T[j][i+1] |= 1;
        }
      }
    }
    queue<P2> q;
    q.push(P2(1, P(0, 0)));
    while (!q.empty()) {
      int r = q.front().first,
          x = q.front().second.first,
          y = q.front().second.second; q.pop();
      if (V[x][y] != 0) continue;
      V[x][y] = r;
 
      for (int k=0; k<4; k++) {
        int dx = x + DX[k], dy = y + DY[k];
        if (dx < 0 || dx >= W || dy < 0 || dy >= H) continue;
        if (T[x][y] & (1<<k)) continue;
        q.push(P2(r+1, P(dx, dy)));
      }
    }
    cout << V[W-1][H-1] << "\n";
  }
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll MOD=2019;
ll binpow(ll a,ll b)
{
    if (b==0)
        return 1;
    if (b%2==0)
        return (binpow(a,b/2)*binpow(a,b/2))%MOD;
    return ((binpow(a,b/2)*binpow(a,b/2))%MOD*a)%MOD;
}
int main()
{
    string s;
    cin>>s;
    map<ll,ll>mp;
    ll mo=0;
    mp[mo]++;
    ll ans=0;
    for (ll i=s.length()-1;i>=0;i--)
    {
        mo+=((s[i]-'0')*binpow(10,s.length()-i-1))%MOD;
        mo%=MOD;
        ans+=mp[mo];
        mp[mo]++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/

int to[M];
int vs[M];

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n,k;
  	cin>>n>>k;
  	for(int i=1;i<=n;i++)cin>>to[i];
  	int tp=1;
  	ll nm=0;
  	while(1)
  	{
  		vs[tp]++;
  		nm++;
		if(nm==k)
		{
			cout<<to[tp]<<endl;
			return 0;
		}
		
		tp=to[tp];
		if(vs[tp]==2)break;
	}
	ll nw=0;
	for(int i=1;i<=n;i++)if(vs[i]==2)nw++;
	k-=nm;
	k%=nw;
	while(k)
	{
		tp=to[tp];
		k--;
	}
	cout<<tp<<endl;
	return 0;
}

Measured memory_bytes: 5212
#include <iostream>

using namespace std;
int main() {
 int number1,number2;
 cin>>number1>>number2;
 if (number1>=1 && number1<=13 && number2>=1 && number2<=13){
 if (number1 !=1 && number2!=1 && number1>number2){
    cout<<("Alice");
 }
 else if (number1 !=1 && number2!=1 && number1<number2){
    cout<<("Bob");
 }
 if (number1==1 & number2!=1){
    cout<<("Alice");
 }
 else if (number2==1 & number1!=1){
    cout<<("Bob");
 }
 if (number1==number2){
    cout<<("Draw");
 }
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,b,c,m;
  cin >> a >> b >> c >> m;
  rep(i,10) {
    rep(j,10) {
      rep(k,10) {
        if(i+j+k<=m) {
          ll x=a,y=b,z=c;
          rep(l,i+1) x*=2;
          rep(l,j+1) y*=2;
          rep(l,k+1) z*=2;
          if(x<y&&y<z) {
            pr("Yes");
            return;
          }
        }
      }
    }
  }
  pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)

int main(){
    ll n,m;
    cin >> n >> m;
    ll ans=0;
    if(2*n<m){
        ans += n;
        m -= 2*n;
        ans += m/4;
    }else if(2*n==m){
        ans = n;
    }else if(2*n>m){
        ans = m/2;
    }
    cout << ans << endl;
}


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

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


int main(){
  string w;
  cin >> w;
  rep(i, w.size()){
    if('A' <= w[i] && w[i] <= 'Z'){
      w[i] = w[i] - 'A' + 'a';
    }
  }
  string s;
  int cnt = 0;
  while(cin >> s){
    if(s == "END_OF_TEXT") break;
    rep(i,s.size()){
      if('A' <= s[i] && s[i] <= 'Z'){
        s[i] = s[i] - 'A' + 'a';
      }
    }
    if(s == w) cnt++;
  }
  cout << cnt << endl;
}






Measured memory_bytes: 3192
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    ll a, b;
    cin >> a >> b;
    if(a <= 5)
        cout << 0;
    else if(a <= 12)
        cout << b / 2;
    else
        cout << b;
    return 0;
}


Measured memory_bytes: 256
n = int( input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
fact = factorization( n )

cnt = 0
for f in fact:
  if f[0] == 1:
    continue
  fa = f[ 1 ]
  fa -= 1
  i = 2
  while fa >= 0:
    cnt += 1
    fa -= i
    i += 1
print( cnt )


Measured memory_bytes: 9484
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> ab(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        ab[a-1].push_back(b-1);
    }
    for(auto aaa: ab[0]){
        for(auto bbb: ab[aaa]){
            if(bbb==N-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

vector<pair<long long, int>> factorize(long long n){
    vector<pair<long long, int>> res;
    
    if(n%2 == 0){
        res.emplace_back(2,0);
        while(n%2 == 0){
            n /= 2;
            res.back().second++;
        }
    }
    
    for(int i=3; i*i<=n; i+=2){
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

long long num_divisors(long long n){

    vector<pair<long long ,int>> fact = factorize(n);

    long long res = 1;
    for(int i=0; i<fact.size(); i++){
        res *= fact[i].second+1;
    }

    return res;
}

int main(void){
    int N; cin >> N;
    int ans = 0;
    for(int i=1; i<=N; i+=2){
        if(num_divisors((ll)i) == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import * as fs from "fs"

const input = fs.readFileSync('/dev/stdin', 'utf-8').split('\n')
const n = input[0]
const s = input[1]
const t = s.substr(0,parseInt(n)/2)

if (s === `${t}${t}`) {
    console.log("Yes")
} else {
    console.log("No")
}

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

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

const int MOD = 2019;

int main()
{
    long long L, R;
    cin >> L >> R;

    if(R/MOD > (L-1)/MOD) cout << 0 << endl;
    else{
        long long ans = 1e+18;
        FOR(i, L, R+1){
            FOR(j, i+1, R+1) ans = min(ans, (long long) i*j%MOD);
        }
        cout << ans << 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 REPR(i, n) for(int i = 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; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
//累乗計算
ll C(ll n,ll k)
{
  ll x=1,y=1;
  for(int i=1;i<=k;i++)
  {
    x=x*(n-i+1)%mod;
    y=y*i%mod;
  }
  return x*power(y,mod-2)%mod;
}

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

    ll N,A,B;
    cin>>N>>A>>B;
    ll ans=power(2,N);
    ans-=C(N,A);
    ans-=C(N,B);
    ans--;
    cout<<(ans%mod+mod)%mod<<endl;
    return 0;
}



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

int main() {
  int c[3][3];
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }

  int a[3] = {};
  for (a[0] = 0; a[0] <= 100; ++a[0]) {
    for (a[1] = 0; a[1] <= 100; ++a[1]) {
      for (a[2] = 0; a[2] <= 100; ++a[2]) {
        bool f = false;
        for (int j = 0; j < 3; ++j) {
          int d = c[0][j] - a[0];
          for (int i = 1; i < 3; ++i) {
            if (c[i][j] - a[i] != d) f = true;
          }
        }

        if (!f) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
l=[]
for i in range(5):
    l.append(int(input()))
indexn=10
indx=0
for v in range(5):
    if l[v]%10==0:
        pass
    else:
        if l[v]%10<indexn:
            indexn=l[v]%10
            indx=v
for k in range(5):
    l[k]=((l[k]-1)//10+1)*10
        
print(sum(l)-10+indexn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	map<int, int> m;
	bool is = false;
	rep(i, n)
	{
		int a;
		cin >> a;
		if(m[a])
			is = true;
		m[a] = 1;
	}
	cout << (is ? "NO" : "YES") << endl;
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int n,a,tmp;
int s[10],w[10];
string f[10],temp;
int t[10];
vector<int>ans;
 
int get_weight(int);
void swap_data(int);
void sort_data();
 
int main(){
  while(cin>>n&&n!=0){
    ans.clear();
    for(int i=0;i<n;i++){
      cin>>f[i];
      cin>>w[i]>>s[i];
    }
 
     
    sort_data();
 
    //for(int i=0;i<n;i++)cout<<f[i]<<' '<<w[i]<<' '<<s[i]<<endl;
    //cout<<'='<<endl;

      for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      if(w[j]<w[j+1]){
        swap_data(j);
         
        a=get_weight(j+1);
        if(a>s[j])swap_data(j);
         
 
      
     
    }
      }
    }
    for(int i=0;i<n;i++)cout<<f[i]<<endl;
     
     
  }
  return 0;
}
 
int get_weight(int x){
  int res=0;
  for(int i=x;i<n;i++)res+=w[i];
  return res;
}
 
void swap_data(int x){
   
  tmp=w[x];
  w[x]=w[x+1];
  w[x+1]=tmp;
 
  tmp=s[x];
  s[x]=s[x+1];
  s[x+1]=tmp;
 
  temp=f[x];
  f[x]=f[x+1];
  f[x+1]=temp;
}
 
void sort_data(){
  for(int i=n-1;i>0;i--){
    for(int j=0;j<i;j++){
      if(s[j]<s[j+1])swap_data(j);
      else if(s[j]==s[j+1]&&w[j]<w[j+1])swap_data(j);
    }
  }
}

Measured memory_bytes: 1204
N, K = map( int, input().split() )
ps = list( map( int, input().split() ) ) 
s=sum(ps[0:K])
ans=s
for i in range( 1, N-K+1 ) :
  s = s + ps[i-1+K] - ps[i-1]
  if s > ans:
    ans=s
print( (ans+K)/2 )

Measured memory_bytes: 24804
#include <iostream>
#include <math.h>
using namespace std;
typedef long long int ll;
int main() {
    ll N, x, a1, a2, ans = 0;
    cin >> N >> x >> a1;
    for(ll i = 1; i < N; i++) {
        cin >> a2;
        ll sum = a1 + a2;
        if(sum > x) {
            ans += sum - x;
            a2 -= sum - x;
            a1 = max(0ll, a2);
        } else {
            a1 = a2;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BTrainingCamp {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    ll p = 1;
	    for(int i=1; i<=n; i++){
	        p *= i;
	        p %= mod;
	    }
	    out << p << endl;
	}
};


int main() {
	BTrainingCamp solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
s = input()

l = []
for i in range(2**(len(s)-1)):
  pat = ''
  for j in range(len(s)-1):
    pat += s[j]
    if i >> j & 1:
      pat += '+'
    else:
      pat += '-'
  l.append(pat+s[-1])

for i in range(len(l)):
  if eval(l[i]) == 7:
    print(l[i] + '=7')
    break

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (auto& p : P) {
        cin >> p;
        --p;
    }
    vector<ll> C(N);
    for (auto& c : C) {
        cin >> c;
    }
    ll ans = -INF;
    rep(u, 0, N) {
        int nxt_node = P[u];
        int loop_length = 1;
        ll loop_cost = C[nxt_node];
        while (nxt_node != u) {
            nxt_node = P[nxt_node];
            loop_cost += C[nxt_node];
            ++loop_length;
        }
        if (loop_cost > 0) {
            // 回れるだけ回る
            ll loop_cnt = K / loop_length;
            ll now_ans = loop_cost * loop_cnt;
            if (loop_cnt) {
                chmax(ans, now_ans);
            }
            int rest = K % loop_length;
            int now_node = P[u];
            rep(i, 0, rest) {
                now_ans += C[now_node];
                chmax(ans, now_ans);
                now_node = P[now_node];
            }
            // 1周分だけ少なく回る
            now_ans = loop_cost * max(0LL, loop_cnt - 1);
            now_node = P[u];
            rep(i, 0, K - max(0LL, loop_cnt - 1) * loop_length) {
                now_ans += C[now_node];
                chmax(ans, now_ans);
                now_node = P[now_node];
            }
        }
        // 1周より多く回らない
        nxt_node = P[u];
        ll now_ans = C[nxt_node];
        chmax(ans, now_ans);
        int rest = K - 1;
        while (nxt_node != u && rest) {
            nxt_node = P[nxt_node];
            now_ans += C[nxt_node];
            --rest;
            chmax(ans, now_ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a <= c && c <= b) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	int g = 0, p = 0;
	for (char x : s)
	{
		if (x == 'g')++g;
		else ++p;
	}
	cout << (g - p) / 2 << endl;
}


Measured memory_bytes: 512
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY
puts get_nsp.count("1")

Measured memory_bytes: 1788
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(1000000);

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var str=arr.shift();
   if(str=="0 0")break;
   var ary=str.split(" ").map(Number);
   var a=ary[0];
   var b=ary[1];
   var A=[];
   p.some(function(v){
      if(a==1)return true;
      if(a%v==0)A.push(v);
      while(a%v==0)a/=v;
   });
   var B=[];
   p.some(function(v){
      if(b==1)return true;
      if(b%v==0)B.push(v);
      while(b%v==0)b/=v;
   });
   A.sort(function(a,b){return b-a;});
   B.sort(function(a,b){return b-a;});
   var numA=A[0]+A[0]-A.reduce(function(a,b){return a+b;},0);
   var numB=B[0]+B[0]-B.reduce(function(a,b){return a+b;},0);
   var ans=(numA>=numB)?"a":"b";
   console.log(ans);
}

Measured memory_bytes: 36396
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  long int K,S,ans=0;
  cin >> K >> S;
  FOR(X,0,K+1)FOR(Y,0,K+1)if(S-X-Y>=0 && K>=S-X-Y)ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<deque>
#include<map>
#include<utility>
using namespace std;
int main(void)
{
	map<char, int> priority;
	priority['*'] = 30;
	priority['/'] = 30;
	priority['+'] = 10;
	priority['-'] = 10;
	priority['('] = 0;
	priority[')'] = 0;
	char str[128], *p,*next;
	int v, n;

	scanf("%d", &n);
	while(n--)
	{
		scanf("%s",str);
		deque<pair<char,int> > source;	
		stack<char> subStack;

		p = str;
		while(*p)
		{
			if(isdigit(*p))
			{
				v = strtol(p, &next, 10);
				source.push_back(make_pair('\0', v));
				p = next;
			}
			else
			{
				switch(*p)
				{
				case '(':
					subStack.push(*p);
					break;
				case ')':
					while(subStack.top() != '(')
					{
						source.push_back(make_pair(subStack.top(),0));
						subStack.pop();
					}
					subStack.pop();
					break;
				case '*':
				case '/':
				case '+':
				case '-':
					while(!subStack.empty() && priority[*p] <= priority[subStack.top()])
					{
						source.push_back(make_pair(subStack.top(),0) );
						subStack.pop();
					}
					subStack.push(*p);
					break;
				case '=':
					break;
				}
				++p;
			}
		}
		while(!subStack.empty())
		{
			source.push_back(make_pair(subStack.top(),0));
			subStack.pop();
		}
		stack<int> s;
		while(!source.empty())
		{
			if(source.front().first)
			{
				int lhv, rhv;
				rhv = s.top();s.pop();
				lhv = s.top();s.pop();
				switch(source.front().first)
				{
				case '+': s.push(lhv+rhv); break;
				case '-': s.push(lhv-rhv); break;
				case '*': s.push(lhv*rhv); break;
				case '/': s.push(lhv/rhv); break;
				}
			}
			else s.push(source.front().second);
			source.pop_front();
		}
		printf("%d\n", s.top());
		s.pop();
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll h, w, ans = INF64, a, b, c, d;
int main() {
	cin >> h >> w;
	a = (h % 3 == 0 ? 0 : 1);
	b = (w % 3 == 0 ? 0 : 1);
	c = (h % 2 == 0 ? 0 : 1);
	d = (w % 2 == 0 ? 0 : 1);
	ans = min(a * w, b * h);
	REPO(i, h - 1) {
		ans = min(ans, max(abs(i * w - (h - i) * (w / 2)),abs(i * w - ((h - i) * d + (h - i) * (w / 2)))));
	}
	REPO(i, w - 1) {
		ans = min(ans, max(abs(i * h - (w - i) * (h / 2)),abs(i * h - ((w - i) * c + (w - i) * (h / 2)))));
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$X = explode(" ", fgets(STDIN));
//var_dump($X);

$X = array_map('intval', $X);

$mean_ceil = ceil(array_sum($X) / count($X));
$mean_floor = floor(array_sum($X) / count($X));

$ans_1 = 0;
$ans_2 = 0;

for ($i = 0; $i < count($X); $i++){
    $ans_1 += pow($X[$i] - $mean_ceil, 2);
    $ans_2 += pow($X[$i] - $mean_floor, 2);
}

echo min($ans_1, $ans_2);

Measured memory_bytes: 3576
N = int(input())

D1 = [0] * N
D2 = [0] * N
for i in range(N):
    D1[i], D2[i] = map(int, input().split())
f=0
for i in range(N):
    if D1[i]==D2[i]:
        f+=1
        
    if D1[i]!=D2[i]:
        f=0
        continue
    
    if f==3:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 9192
import java.util.*;
 
public class Main {
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(sc.hasNext()){
            int n = sc.nextInt();
            for(int k=0;k<n;k++){
                String s = sc.next();
                int[] num = new int[8];
 
                for(int i=0;i<8;i++){
                    num[i] = Integer.valueOf(s.substring(i,i+1));
                }
                Arrays.sort(num);
                int a = 0;
                int b = 0;
                int c = 1;
                for(int i=0;i<8;i++){
                    a += num[i]*c;
                    b += num[7-i]*c;
                    c *= 10;
                }
                System.out.println(a-b);
                 
            }
        }
     
    }   
}

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

int main()
{
    long long int n,m,a[100000],sum=0,d;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    d=n-sum;
    if(d>=0)
    {
        cout<<d<<endl;
    }
    else
    {
        cout<<"-1\n";
    }
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;

template<class T> struct BiCoef {
  vector<T> fact_, inv_, finv_;
  constexpr BiCoef() {}
  constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
    init(n);
  }
  constexpr void init(int n) noexcept {
    int MOD = fact_[0].getMod();
    fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
    for(int i = 2; i < n; i++){
      fact_[i] = fact_[i-1] * i;
      inv_[i] = -inv_[MOD%i] * (MOD/i);
      finv_[i] = finv_[i-1] * inv_[i];
    }
  }
  constexpr T perm(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return com(n, k) * fact(k);
  }
  constexpr T com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return fact_[n] * finv_[k] * finv_[n-k];
  }
  constexpr T fact(int n) const noexcept {
    if (n < 0) return 0;
    return fact_[n];
  }
  constexpr T inv(int n) const noexcept {
    if (n < 0) return 0;
    return inv_[n];
  }
  constexpr T finv(int n) const noexcept {
    if (n < 0) return 0;
    return finv_[n];
  }
};


int main() {
  int n, k; cin >> n >> k;
  BiCoef<mint> bc(n+1);
  k = min(k, n-1);
  mint ans = 0;
  loop(i,0,k+1) {
    ans += bc.com(n, i) * bc.com(n-1, i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8012
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll a, b;
ll c;
bool d[1000005];
ll cnt;

ll gcd(ll p, ll q)
{
    if(q == 0) return p;
    return gcd(q, p % q);
}

int main()
{
    scanf("%lld%lld", &a, &b);
    c = gcd(max(a, b), min(a, b));
    for(ll i = 2; i <= 1000000; i++)
    {
        if(d[i]) continue;
        for(ll j = i * i; j <= 1000000; j += i)
        {
            d[j] = true;
        }
        if(c % i == 0) cnt++;
        while(c % i == 0) c /= i;
    }
    if(c > 1) cnt++;
    printf("%lld", ++cnt);
    return 0;
}


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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for(int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    vector<vector<int>> A(N, vector<int>(M));
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < N; i++)
    {
        int res = 0;
        for(int j = 0; j < M; j++)
        {
            res += B[j] * A[i][j];
        }

        res += C;

        if(res > 0)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map <string, int> cnt;
    string s;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> s;
        umax(mx, ++cnt[s]);
    }
    vector <string> ans;
    for (auto i : cnt) {
        if (i.y == mx) {
            cout << i.x << '\n';
        }
    }
}


Measured memory_bytes: 19212
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**19

for bit in range(2**N):
    if bin(bit).count('1') != K:
        continue

    cost, height = 0, 0
    for i in range(N):
        if bit & (1 << i) == 0:
            if height < a[i]:
                height = a[i]
            continue
        if height >= a[i]:
            cost += height - a[i] + 1
            height += 1
        else:
            height = a[i]

    if ans > cost:
        ans = cost

print(ans)


Measured memory_bytes: 42860
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i;
	int j;
	int a, b;
	double sum = 0;
	int ans=0;
	cin >> a >> b;
	if (b >= 1 && b < 10) {
		a *= 10;
	}
	else if (b >= 10 && b < 99) {
		a *= 100;
	}
	else if (b == 100) {
		a *= 1000;
	}
	sum = a + b;
	//cout << sum << endl;

	sum = sqrt(sum);
	if (floor(sum) == sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll arr[n];
    ll mx = 1e9;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i <= 150; i++) {
        ll curr = 0;
        for (int j = 0; j < n; j++) curr += (arr[j] - i) * (arr[j] - i);
        mx = min(mx, curr);
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = (sum(b)) // len(b)
d = c + 1
mc = 0
md = 0
for i in b:
    mc += abs(i - c) ** 2
    md += abs(i - d) ** 2
print(min(mc, md))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<pair<long long, long long>> ab(n);
  for(int i=0;i<n;i++)cin>>ab[i].first>>ab[i].second;
  ab.emplace_back(0,10000000000000LL);
  ab.emplace_back(10000000000000LL,0);
  sort(ab.begin(),ab.end());
  long long ans=0;
  for(int i=0;i<=n;i++)ans+=min(abs(ab[i].first-ab[i+1].first),abs(ab[i].second-ab[i+1].second));
  cout<<ans<<endl;
}


Measured memory_bytes: 6408
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    s=str(input())
    t=str(input())
    ans=2*N
    for i in range(1,N+1):
        #print(s[-i:])
        #print(t[:i])
        if s[-i:]==t[:i]:
            ans=2*N-i
    print(ans)



resolve()

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint last[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - last[i]);
	}
	return -sum;
}

int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	lint score = 0;
	REP(i, D) {
		lint t;
		cin >> t; t--;
		last[t] = i + 1;
		score += satis[i][t];
		score += downscore(i + 1);
		cout << score << endl;
	}
}


Measured memory_bytes: 3668