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

#define ll long long

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    ll X, Y, ans = 0;
    cin >> X >> Y;
    ll x1, x2;
    if(2*X-Y >= 0 && (2*X-Y)%3 == 0){
        x2 = (2*X-Y)/3;
        if(X-2*x2 >= 0){
            x1 = X-2*x2;
            ans = COM(x1+x2, x1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27072
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var dic = new Dictionary<int, int>();
        for (var i = 0; i < num; i++)
            if (dic.ContainsKey(ar[i])) dic[ar[i]]++;
            else dic[ar[i]] = 1;
        WriteLine(dic.Keys.Count % 2 == 0 ? dic.Keys.Count-1 : dic.Keys.Count);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 21088
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{		
	double r;
	cin >> r;
	
	double area = r * r * M_PI;
	double leng = r * 2 * M_PI;
	
	cout << fixed << area << " " << leng << endl;
	
	return 0;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define int long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <=n; i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
#define PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
    start();
    int n, m;
    cin >> m >> n;
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            if ( (2 * i + 4 * j) == n && (i + j) == m) {
                cout << "Yes" << el;
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3652
N, T = map(int, input().split())
A = list(map(int, input().split()))

# 最大収益
max_income = 0
# リンゴの最低価格
min_num = A[0]
# 青木君が減らさないといけない組の数
comb = 0
    
# 2つ目の町から探索
# n = 現在の町のリンゴの価格
for n in A[1:]:
    # 最低価格を更新する
    if n < min_num:
        min_num = n
    
    # 最大利益を更新する
    elif n - min_num > max_income:
        max_income = n-min_num
        # 組数を1にする
        comb =1
    
    # 最大利益を持つ組が2個あった場合、
    elif n - min_num == max_income:
        # 組数を1増やす
        comb +=1
        

print(comb)

Measured memory_bytes: 15020
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char c[100007];
int main(){
    scanf("%s",c);int l=strlen(c),g=0;
    for(int i=0;i<l;++i)if(c[i]=='g')g++;
    printf("%d\n",min(l/2,g)-min(l-l/2,l-g));
    return 0;
}

Measured memory_bytes: 256
num = int(input())
goal = 0
success = False

for n in range(num):
  a,b = input().split()
  if int(a) == int(b):
    goal += 1
  else:
    goal = 0
   
  if goal == 3:
    success = True
    
if success:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9172
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
void init2(int n);
int find2(int n);
void unite2(int x,int y);
bool same2(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int N,M,a,b,res=0,n;
  
  cin >> N >> M;
  vector<vector <int> > iya;
  iya = vector<vector<int> >(N+2, vector<int>(0,0));
  set <int> st;
  REP(i,M){
    cin >> a >> b;
    iya[a].push_back(b);
  }
  n=1;
  REP(j,iya[1].size()){
        st.insert(iya[1][j]);
      }
  for(int i=2;i<=N;i++){
    set<int>::iterator iti = st.find(i);
    if(iti != st.end()){
      res += 1;
      n = i;
      st.clear();
      REP(j,iya[i].size()){
        st.insert(iya[i][j]);
      }
    }else{
      REP(j,iya[i].size()){
        st.insert(iya[i][j]);
      }
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}


int par2[MAX_N];
int ranks2[MAX_N];

//n要素で初期化
void init2(int n){
  REP(i,n){
    par2[i] = i;
    ranks2[i] = 0;
  }

}

//木の根を求める
int find2(int x){
  if(par2[x] == x){
    return x;
  }else{
    return par2[x] = find2(par[x]);
  }
}

void unite2(int x,int y){
  x = find2(x);
  y = find2(y);
  if(x == y) return ;
  if(ranks2[x] < ranks2[y]){
    par2[x] = y;
  }else{
    par2[y] = x;
    if(ranks2[x] == ranks2[y]) ranks2[x]++;
  }
}

bool same2(int x, int y){
  return find2(x) == find2(y);
}



Measured memory_bytes: 6784
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int freq[3];
    int n = s.length();
    for(int i = 0; i<3; i++){
        freq[i] = 0;
    }
    for(int i = 0; i<n; i++){
        freq[(int)(s[i]-'a')]++;
    }
    sort(freq,freq+3);
    int maxi = n/3;
    if(n%3!=0){
        maxi++;
    }
    if(freq[2]<=maxi){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1e18
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

int main() {
	optimizar_io
	int n; cin >> n;
	vector<lli> v(n);
	bool zero = false;
	fore(i, 0, n) {
		cin >> v[i];
		if(!v[i]) zero = true;
	}
	if(zero) {cout << 0 << endl; return 0;}
	lli ans = 1;
	fore(i, 0, n) {
		if(v[i] <= (1000000000000000000 / ans)) ans = ans * v[i];
		else {	
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3948
import math
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0.0
        for k in range(d):
            dist += (x[i][k] - x[j][k])**2
            # print(x[i][k], x[j][k])
        if (math.sqrt(dist)).is_integer():
            # print(i, j, dist)
            ans += 1
# print(x)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  if(n[0]==n[1]&&n[1]==n[2]) cout << "Yes" << endl;
  else if(n[1]==n[2]&&n[2]==n[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  if (n % 1000 % 111 == 0) 
    cout << "Yes" << endl;
  else if (n / 10 % 111 == 0)  
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;
char s[maxn];
int main() {
    while (~scanf("%s",s+1)) {
        int ans=0;
        int len=strlen(s+1);
        int p=0,g=1;
        for (int i=2;i<=len;i++) {
            if (g>p) {
                p++;
                if (s[i]=='g') ans++;
            } else {
                g++;
                if (s[i]=='p') ans--;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def sol():
    H, W, N = map(int, input().split())
    origin = defaultdict(int)

    ans = [0 for _ in range(10)]
    ans[0] = (H - 2) * (W - 2)

    def addBlack(h, w):
        ans[origin[(h, w)]] -= 1
        ans[origin[(h, w)] + 1] += 1
        origin[(h, w)] += 1

    for _ in range(N):
        h, w = map(int, input().split())

        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if 2 <= h + a <= H - 1 and 2 <= w + b <= W - 1:
                    addBlack(h + a, w + b)

    for a in ans:
        print(a)

sol()

Measured memory_bytes: 166868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int n;
    string s;
    cin >> n >> s;
    char c = s[0];
    int ans = 1;
    for (int i = 1; i < sz(s); i++) {
        if (s[i] != c) {
            c = s[i];
            ans++;
        }
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    string s, t;
    cin >> s >> t;
    ll result = LLONG_MAX;
    for (ll i = 0; i <= s.length() - t.length(); ++i)
    {
        ll count = 0;
        for (ll j = 0; j < t.length(); ++j)
        {
            if (t[j] != s[i + j])
            {
                ++count;
            }
        }
        result = min(result, count);
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;

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

	vector<vector<int>> u(h, vector<int>(w)), 
						d(h, vector<int>(w)), 
						l(h, vector<int>(w)), 
						r(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '#') {
				if (i == 0) {
					d[i][j] = 1;
				}
				else {
					d[i][j] = d[i - 1][j] + 1;
				}
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '#') {
				if (j == 0) {
					r[i][j] = 1;
				}
				else {
					r[i][j] = r[i][j - 1] + 1;
				}
			}
		}
	}
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (s[i][j] != '#') {
				if (i == h - 1) {
					u[i][j] = 1;
				}
				else {
					u[i][j] = u[i + 1][j] + 1;
				}
			}
		}
	}
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (s[i][j] != '#') {
				if (j == w - 1) {
					l[i][j] = 1;
				}
				else {
					l[i][j] = l[i][j + 1] + 1;
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 67200
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int color[110000];
vector<pair<int,int>> V[110000];
int N,mycount=0,u,v,w;
bool flag=1;

void gogo(int x,int d){
  color[x]=d;
  //if(x==3) cout<<"3 "<<d<<endl;
  mycount++;
  for(int i=0;i<V[x].size();i++){
    int next=V[x][i].first,nextD=V[x][i].second;
    if(color[next]==-1){
      //cout<<x<<" "<<next<<" "<<nextD<<endl;
      gogo(next,(d+nextD)%2);
    }
  }
  if(mycount==N && flag==1){
    //cout<<"N"<<" "<<N<<endl;
    for(int i=1;i<=N;i++){
      cout<<color[i]<<endl;
    }
    flag=0;
  }
}


int main(){
  for(int i=0;i<110000;i++){
    color[i]=-1;
  }
  cin>>N;
  for(int i=0;i<N-1;i++){
    cin>>u>>v>>w;
    V[u].push_back(make_pair(v,w%2));
    V[v].push_back(make_pair(u,w%2));
  }
  gogo(1,0);
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 100000000000

#define MAXN 1000001

using namespace std;

int dp[MAXN][2];

int main(){
  string s;cin>>s;
  reverse(s.begin(), s.end());
  s+='0';
  int n=s.size();

  rep(i, n+1)rep(j, 2)dp[i][j]=INF;
  dp[0][0]=0;
  
  rep(i, n)rep(j, 2){
    int x = s[i]-'0'+j;
    int ni = i+1;

    // この桁では繰り下がらずにx枚のみを払ってやり過ごす。
    // 繰り下がり分の1を足して10になっていると、更に次の桁で1枚払っているという感じになって枚数がおかしくなってしまうので、分岐で制限する。
    if(x<10)dp[ni][0] = min(dp[ni][0], dp[i][j] + x);
    // 繰り下がりがある時の処理なので、1が自動的に足される。なのでxが0だとダメ
    if(x>0)dp[ni][1] = min(dp[ni][1], dp[i][j]+(10-x));
                           
  }

  cout<<dp[n][0]<<endl;

  return 0;
}

Measured memory_bytes: 12056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int n;
    cin>>n;
    int a[n];
    int m=0;
    int m_i=0;
    int m2=0;
    int m2_i=0;
    rep(i,n){
      int tmp;
      cin>>tmp;
      a[i] = tmp;
      if(m<a[i]){
        m=a[i];
        m_i=i;
      }
    }

    rep(i,n){
      if(i==m_i){
        continue;
      }
      else{
        if(m2<a[i]){
          m2=a[i];
          m2_i=i;
        }
      }
    }

    rep(i,n){
      if(i==m_i){
        cout<<a[m2_i]<<endl;
      }
      else{
        cout<<a[m_i]<<endl;
      }
    }

    
}

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
long long N, A[87], CurrentMoney = 1000;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 1; i <= N - 1; i++) {
long long Stocks = 0;
if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
 CurrentMoney += (A[i + 1] - A[i]) * Stocks;
 }
 cout << CurrentMoney << endl;
 }

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a;
    int temp;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());

    int counter = 0;

    for (int i = 0; i < n; ++i) {
        x -= a[i];

        if (i == n - 1 && x > 0) {
            break;
        }

        if (x >= 0) {
            ++counter;
        }
        else {
            break;
        }
    }

    cout << counter << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
	string N;
	cin >> N;
	for (int i = 0; i < 3; i++) {
		if (N[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
using namespace std;

int sumDigit(int n){
	string d = to_string(n);

	int sum = 0;
	for(int i=0; i<d.size(); i++)
		sum += d[i] - '0';

	return sum;
}

int main(void)
{
	int N;
	cin >> N;

	int ret = INT_MAX;
	for(int i=1; i<N/2+1; i++)
		ret = min(ret, sumDigit(i)+sumDigit(N-i));

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,i,m,s,t;cin>>n>>m>>s>>t;s--;t--;
	vector<vector<int>>go(n);
	vector<int>sdis(n,mod);
	vector<int>tdis(n,mod);
	for(i=0;i<m;i++){
		int x,y;cin>>x>>y;x--;y--;
		go[x].pub(y);
		go[y].pub(x);
	}
	queue<int>que;
	que.push(s);
	sdis[s]=0;
	while(que.size()){
		int x=que.front();
		
		que.pop();
		for(auto it:go[x]){
			if(sdis[it]!=mod){continue;}
			sdis[it]=sdis[x]+1;
			que.push(it);
		}
	}
	//cerr<<sdis[t]<<endl;
	que.push(t);
	tdis[t]=0;
	while(que.size()){
		int x=que.front();
		que.pop();
		for(auto it:go[x]){
			if(tdis[it]!=mod){continue;}
			tdis[it]=tdis[x]+1;
			que.push(it);
		}
	}
	int f=sdis[t];
	//cerr<<f<<endl;
	vector<llint>sdn(n);
	vector<llint>tdn(n);
	for(i=0;i<n;i++){
		if(sdis[i]<n){sdn[sdis[i]]++;}
		if(tdis[i]<n){tdn[tdis[i]]++;}
	}
	llint ans=0;
	for(i=0;i+2<=f;i++){ans+=sdn[i]*tdn[f-i-2];}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11784
S = list(input())
T = list(input())

ans = 10**9

for i in range(len(S)-len(T)+1):
    Spart = S[i:i+len(T)]
    #print(Spart)
    temp_ans = 0
    
    for j in range(len(T)):
        #print(Spart[j],T[j])
        if Spart[j] != T[j]:
            temp_ans += 1
            
    if temp_ans < ans:
        ans = temp_ans
        
print(ans)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    string s,t; cin >> s >> t;
    int ans = 0;

    REP(i,s.length())
    {
        FOR(j,0,s.length()-i+1)
        {
            string subst = s.substr(i,j);
            dump(subst)
            if(t.substr(0,j) == subst) 
            {

                if(ans < j) ans = j;
            }
        }
    }
    dump(ans)
    dump(s)
    dump(t)
    int hoge = s.length() + t.length() - ans; 
    cout << max(hoge,N) << endl;



}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.HashSet;

public class Main{
    public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			sc.nextLine();
			String S = sc.nextLine();
			String[] arare = S.split(" ", 0);
			List<String> listA = new ArrayList<String>();
			for(int i=0; i<arare.length; i++){
				listA.add(arare[i]);
				//System.out.println(S);
			}
			//System.out.println(listA);
			List<String> listB = new ArrayList<String>(new HashSet<>(listA));
			//System.out.println(listB.size());
			if(listB.size()==3){
				System.out.println("Three");
			}else if(listB.size()==4){
				System.out.println("Four");
			}
		}
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 1505, inf = 0x3f3f3f3f;
int n,a[N][N],f[N][N];short l[N][N],r[N][N];char S[N][N];ll res;
#define umax(a,b) (a=a>b?a:b)
#define umin(a,b) (a=a<b?a:b)
int main() {//freopen("1.in","r",stdin);
	memset(S,'#',sizeof(S));read(n);rep(i,1,n)scanf("%s",S[i]+1);
	rep(i,1,n)rep(j,1,n)if(S[i][j]!='#')a[i][j]=S[i][j]-'0';
	memset(l,inf,sizeof(l));
	per(i,n,1)per(j,n,1)
		if(a[i][j]){
			if(!a[i+1][j]&&!a[i][j+1]){
				r[j][i]=l[j][i]=j;
			//	rep(k,i+1,n)r[j][k]=-inf,l[j][k]=inf;
			}
			else if(!a[i+1][j]){
				l[j][i]=j;r[j][i]=r[j+1][i];rep(k,i+1,n)r[j][k]=r[j+1][k],l[j][k]=l[j+1][k];
				f[i][j]=f[i][j+1];
			}
			else if(!a[i][j+1]){
				l[j][i]=r[j][i]=j;
				f[i][j]=f[i+1][j];
			}
			else{
				f[i][j]=f[i+1][j]+f[i][j+1];//assume
				l[j][i]=j;r[j][i]=r[j+1][i];
				int lst=0;
				rep(k,i+1,n){
					if(l[j+1][k]<=r[j][k]&&lst<l[j+1][k]){
						f[i][j]-=f[k][l[j+1][k]];
					}
					umax(lst,r[j][k]);
					umax(r[j][k],r[j+1][k]);
					umin(l[j][k],l[j+1][k]);
				}
			}
			res+=a[i][j]*f[i][j];f[i][j]+=a[i][j];
		//	cerr<<i<<' '<<j<<' '<<f[i][j]<<endl;
		}
		else{
			rep(k,i,n)r[j][k]=-inf,l[j][k]=inf;
		}
//	rep(i,1,n){rep(j,1,n)printf("%d ",f[i][j]);puts("");}
	cout<<res;return 0;
}


Measured memory_bytes: 29056
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    string s;
    cin >> s;
    vector<int> xcnt;
    int pos = 0;
    int cnt = 0;
    string t="", u;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == 'x') cnt++;
        else {
            t += s[i];
            u += s[i];
            xcnt.push_back(cnt);
            pos++;
            cnt = 0;
        }
    }
    xcnt.push_back(cnt);
    reverse(u.begin(), u.end());
    if (t != u) {
        cout << -1 << endl;
        return 0;
    }
    int l = 0, r = (int)xcnt.size()-1;
    int ans = 0;
    while (l <= r) {
        ans += abs(xcnt[l]-xcnt[r]);
        l++;
        r--;
    }
    cout << ans << endl;
    return 0;
}

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











#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
//最大公約数
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
//最小公倍数
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    ll n,k;
    cin>>n>>k;
    VI p(n);
    rep(i,n)
    cin>>p.at(i);
    sort(p.begin(),p.end());
    ll ans=0;
    rep(i,k)
    ans+=p.at(i);
    cout<<ans<<endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> ans(n,0);
    rep(i,n) cin>>a[i];
    ll now=0;
    rep(i,n){
      if(i%2==0){
        now+=a[i];
      }else{
        now-=a[i];
      }
    }
    rep(i,n){
      if(i==0){
        cout<<now<<' ';
        continue;
      }
      now=2*a[i-1]-now;
      cout<<now<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for (int i=0; i<=s.size()-t.size(); i++) {
        int cnt = 0;
        for (int j=0; j<t.size(); j++) {
            if (s[i+j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


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

int main()
{
  char s[102];
  cin>>s;
  int count=0;
  for(int i=0;i<strlen(s)/2;i++)
  {
    if(s[i]!=s[strlen(s)-i-1])
      count++;
  }
  cout<<count;
    
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

void init()
{
}

void solve()
{
	char c;
	cin >> c;

	if ('a' <= c && c <= 'z')
	{
		cout << 'a' << endl;
	}
	else
	{
		cout << 'A' << endl;
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n;
	cin >> n;
	vector<int64_t> a(n);
	set<int64_t> s;
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		s.insert(a.at(i));
	}
	if (a.size() == s.size())cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 11136
#include<stdio.h>
int main(void){
    int a,b,c,i,x=0;
    scanf("%d %d %d\n",&a,&b,&c);
    for(i=a;i<=b;i++){
            if(c%i==0)x++;
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 2096
import java.util.function.IntPredicate;
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long a = scanner.nextInt();
        long b = scanner.nextInt();
        int[] h = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
            max = Math.max(max, h[i]);
        }
        max = (int)Math.ceil((double)max / b) + 1;
        System.out.println(binarySearch(max, t -> {
            long count = 0;
            for (double i : h) {
                if (b * t < i) {
                    count += Math.ceil((i - b * t) / (a - b));
                }
            }
            return count > t;
        }) + 1);
    }

    static int binarySearch(int max, IntPredicate predicate) {
        int ok = 0, ng = max;
        while (Math.abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (predicate.test(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        return ok;
    }
}

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

int const N = 500, M = 10000000;
int p[M / 10], p2[10000], sz;
ll an[N][N];
bool pr[M];

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(){
	for (int i = 2; i * i < M; ++i)if (!pr[i])for (int j = i * i; j < M; j += i)pr[j] = true;
	f(i, 2, M)if (!pr[i])p[sz++] = i;
	int kk = 0;
	for (int i = 1999; i > 0; i -= 3){
		p2[kk++] = p[i];
		p2[kk++] = p[i - 1];
		p2[kk++] = p[i - 2];
		p2[kk++] = p[(1999-i) / 3];
		if (kk == 2000)break;
	}
	int n;
	scanf("%d", &n);
	if (n == 2) { printf("4 7\n23 10\n"); return 0; }
	f(i, 0, n)f(j, 0, n)an[i][j] = 1;
	kk = 0;
	for (int i = 0; i < n; i += 2, ++kk)for (int j = 0, z = i; j < n && z < n; ++j, ++z)an[z][j] *= p[kk];
	for (int j = 2; j < n; j += 2, ++kk)for (int i = 0, z = j; i < n && z < n; ++i, ++z)an[i][z] *= p[kk];
	for (int i = 0; i < 2*n - 1; i += 2, ++kk)for (int j = i < n ? 0 : i - n + 1, z = i < n ? i : n - 1; j < n && z >= 0; ++j, --z)an[z][j] *= p[kk];
	f(i, 0, n)for (int j = i + 1 & 1; j < n; j += 2)an[i][j] = 1 + lcm(i ? an[i - 1][j] : 1, lcm(i + 1 < n ? an[i + 1][j] : 1, lcm(j ? an[i][j - 1] : 1, j + 1 < n ? an[i][j + 1] : 1)));
	f(i, 0, n){
		printf("%lld", an[i][0]);
		f(j, 1, n)printf(" %lld", an[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 17408
//#define CCF
//#define OLD

#ifndef CCF
    #pragma comment(linker, "/STACK:102400000,102400000")
    #ifdef OLD
        #pragma GCC diagnostic error "-std=c++11"
    #endif
    #pragma GCC optimize ("O3")
    #pragma GCC -mcmodle=large
#endif

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

int father[100500];
int dis[100500];
int find_father(int x) {
    if(father[x]==x)return x;
    int a1=father[x];
    int a2=find_father(father[x]);
    father[x]=a2;
    dis[x]=dis[x]+dis[a1];
    return a2;
}

int find_dis(int x){
    if(father[x]==x)return 0;
    return find_dis(father[x])+dis[x];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int num,cas,L,R,D;
    cin>>num>>cas;
    for(int i=0; i<=num; i++) {
        father[i]=i;
        dis[i]=0;
    }
    while(cas--) {
        cin>>L>>R>>D;
        int fl=find_father(L);
        int fr=find_father(R);
        if(fl==fr) {
            if(dis[L]+D!=dis[R]) {
                cout<<"No"<<endl;
                return 0;
            }
        } else {
            father[fr]=fl;
            dis[fr]=find_dis(L)-find_dis(R)+D;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int w, d;
    while (cin >> w >> d && w){
        VI a(w), b(d);
        REP(i,w) cin >> a[i];
        REP(i,d) cin >> b[i];
        REP(i,w) a[i] *= -1;
        REP(i,d) b[i] *= -1;
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        REP(i,w) a[i] *= -1;
        REP(i,d) b[i] *= -1;
        int ans = 0;
        a.push_back(0);
        b.push_back(0);
        int i = 0, j = 0;
        while (i <= w && j <= d){
            if (a[i] > b[j]){
                ans += a[i];
                i++;
            }else if (a[i] < b[j]){
                ans += b[j];
                j++;
            }else{
                ans += a[i];
                i++;
                j++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2988
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

    int cnt = 0;
    for (int i = 1; i < N; i++) {
        if (S[i] == 'E') {
            ++cnt;
        }
    }

    int minCnt = cnt;
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == 'W') {
            ++cnt;
        }
        if (S[i] == 'E') {
            --cnt;
        }
        minCnt = min(minCnt, cnt);
    }

    cout << minCnt << endl;

    return 0;
}

Measured memory_bytes: 3384
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  while(getline(cin,s)){
    s+=' ';
    stack<double>st;
    double p=0;
    int t=0;
    r(i,s.size()){
      if(s[i]==' '&&isdigit(s[i-1])){
        if(p!=0){
          if(!t)st.push(p),p=0;
          else st.push((-1)*p),p=0,t=0;
        }
      }
      else if(s[i]=='*'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2*x1);
      }
      else if(s[i]=='+'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2+x1);
      }
      else if(s[i]=='/'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2/x1);
      }
      else if(s[i]=='-'){
        if(isdigit(s[i+1]))t++;
        else{
          double x1=st.top();st.pop();
          double x2=st.top();st.pop();
          st.push(x2-x1);
        }
      }
      else if(isdigit(s[i])){
        p*=10,p+=s[i]-'0';
      } 
    }
    printf("%.6f\n",st.top());
  }
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string akiba = "AKIHABARA";
    string str;
    cin >> str;

    int j = 0;
    for(int i = 0; i < str.size(); i++){
        if(str[i] != akiba[j++]){
            if(str[i] != akiba[j++]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    //dump(j);
    if (j < 8) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;

    return 0;
}


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

struct BFS{
    vector<vector<int>> adj;
    queue<int> Q;
    vector<int> d;
    int n_;
    BFS(int n):adj(n),d(n,-1){
        n_ = n;
    }

    void init(){
        rep(i,n_){
            int u,k;cin>>u>>k;u--;
            rep(i,k){
                int tmp;cin>>tmp;tmp--;
                adj[u].push_back(tmp);
            }
        }
    }

    void visit(int u){
        Q.push(u);
        d[u] = 0;
        while(!Q.empty()){
            int v = Q.front();Q.pop();
            for(int h:adj[v]){
                if(d[h] == -1){
                    Q.push(h);
                    d[h] = d[v] + 1;
                }
            }
        }
    }
    void solve(){
        init();
        visit(0);
        rep(i,n_){
            cout<<i+1<<" "<<d[i]<<endl;
        }
    }

};

int main(){
    int n;cin>>n;
    BFS bfs(n);
    bfs.solve();
    return 0;
}


Measured memory_bytes: 3168
N, K = map(int, input().split())
As = list(map(int, input().split()))

sum_bin = [0] * 41

for a in As:
  a_binary = format(a, 'b')
  for j in range(len(a_binary)):
    tmp = a >> j
    # print(a, a_binary, j, tmp)
    if tmp & 1:
      sum_bin[j] += 1

# print(sum_bin)

def f(x):
  c = 0
  for i in range(40, -1, -1):
    # XOR
    if x >> i & 1:
      c += (N-sum_bin[i])*2**i
    else:
      c += sum_bin[i]*2**i
  return c

g_X = 0
for i in range(40, -1, -1):
  if sum_bin[i] <= N - sum_bin[i]:
    g_X += 2 ** i 
    
ans = f(0)
l = len(format(K, 'b'))

for i in range(l):
  # print(K >> i)
  if K >> i & 1:
    c = ''
    if K >> i+1 != 0:
      c = format(K >> i+1, 'b')
    c += '0'+format(g_X, 'b')[41-i:]
    # print(c, i)
    # print(int(c, 2))
    ans = max(ans, f(int(c, 2)))
ans = max(ans, f(K))
print(ans)

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

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

bool check(int logl, int k, const vector<int> &a){
    if(logl<=0){return false;}
    int ans = 0;
    for(int x: a){
        ans += (x/logl - (x%logl==0?1:0));
    }
    return (ans <= k);
}

void ssolve(std::istream& in, std::ostream& out){
    int n, k;
    s2(n, k);
    vi a(n);
    f(i, 0, n){
        s(a[i]);
    }
    int l = 1, h = 1e9+1;
    while(l < h){
        int m = (l + h)/2;
        if(check(m, k, a)){
            h = m;
        }else{
            l = m+1;
        }
    }
    assert(l==h);
    p(l);
    return;
}

class ELogsEditorial {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    ELogsEditorial solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 4792
#include<iostream>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include <map>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <limits.h>
#include <string>
#include<functional>
#include <set>
#include <utility>
#include <iomanip>
#include <string>
#define INF 1<<30
#define inf 0x3f3f3f3f3f3f3f3f
#define MO 1000000007
#define MI 998244353
#define ll long long
#define woo 140737488355327
using namespace std;
char str[210010];
int vis[3000];
int main()
{
   scanf("%s",str);
   int l=strlen(str);ll cnt=0,ans=0,k=1;vis[0]=1;
   while(l--)
   {
      ans=((str[l]-'0')*k%2019+ans)%2019;
      k=k*10%2019;vis[ans]++;
      cnt+=vis[ans]-1;
   }
   printf("%lld\n",cnt);
}


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

const ll MOD = 1000000007;

struct mint {
    ll x;  // cout << ans.x << endl; で出力する
    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;
    }
};

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) {
        return f[x] == x;
    }
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    Sieve sieve(1e6);
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

		map<int,int> mp;
		rep(i,N){
			auto f = sieve.factor(A[i]);
			for(auto p:f){
				mp[p.first] = max(mp[p.first],p.second);
			}
		}

		mint lcm = 1;
		for(auto p:mp){
			rep(i,p.second){
				lcm *= p.first;
			}
		}

		mint ans;
		rep(i,N){
			mint b = lcm/A[i];
			ans += b;
		}

		cout << ans.x << endl;
}

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

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;

int main() {

    cin >> N;
    
    vector<int> a(N), b(N), c(N), d(N);
    vector<pair<int, int> > R(N), B(N);
    vector<bool> used(N,false);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        R[i] = make_pair(a[i],b[i]);
    }
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> d[i];
        B[i] = make_pair(c[i],d[i]);
    }

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

    int count = 0;

    for (int i = 0; i < N; i++) {
        int bx = B[i].first, by = B[i].second;
        int argmax = -1, ymax = -1;
        for (int i = 0; i < N; i++) {
            if (!used[i] && R[i].first <= bx && R[i].second <= by 
            && R[i].second >= ymax) {
                ymax = R[i].second;
                argmax = i;
            }
        }
        if (argmax == -1)  continue;
        used[argmax] = true;
        count++;
    }

    cout << count << endl;
    

    


}


Measured memory_bytes: 256