akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using namespace atcoder;
using ll = long long;

int main()
{
    int n, m;
    cin >> n >> m;

    dsu d(n);
    rep (i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        d.merge(a, b);
    }

    vector<vector<int>> group = d.groups();
    cout << group.size() - 1 << endl;
    return 0;
}


Measured memory_bytes: 9048
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
constexpr int mxN = 1e5;
int dp[mxN];
void solve(){
    int n, k;
    read(n, k);
    vi h(n);
    REP(i,n) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n ; i++){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        int j = max(0, i - k);
        for(; j < i ; j++){
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])); 
        }
    }
    cout << dp[n-1] << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string a;
    cin>>a;
    map<int,int>mm;
    for (int i = 0; i < 4; ++i) {
        mm[a[i]]++;
    }
    for(auto i:mm)
    {
        if(i.second!=2)
        {
            cout<<"No";
            return 0;
        }
    }

    cout<<"Yes";
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
int i, n, frag=0;
char S[114], T[514];

   scanf("%s %s",&S,&T);
   for(n=0; S[n]!='\0'; ++n);

   for(int i=0;i<n;i++){
      if(S[i]==T[i]){
        frag++;
        continue;
      }
      else{
        break;
      }
   }
   if(frag==n)
     printf("Yes");
   else
     printf("No");
   
}

Measured memory_bytes: 1708
#include <iostream>

char grading(int middle, int final, int retest);

int main() {

    while (true) {
        int middle, final, retest;
        std::cin >> middle >> final >> retest;

        if (middle == -1 && final == -1 && retest == -1) {
            break;
        }

        std::cout << grading(middle, final, retest) << std::endl;
    }

    return 0;
}

char grading(int middle, int final, int retest)
{
    int sum = middle + final;

    if (middle == -1 || final == -1) {
        return 'F';
    } else if (sum >= 80) {
        return 'A';
    } else if (sum >= 65) {
        return 'B';
    } else if (sum >= 50) {
        return 'C';
    } else if (sum >= 30) {
        if (retest < 50) {
            return 'D';
        } else {
            return 'C';
        }
    } else {
        return 'F';
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int result = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int count = 500 * i + 100 * j + 50 * k;
                if (count == X) {
                    result++;
                }
            }
        }
    }
    cout << result;

    return 0;
}


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

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


int arr[50];
ll dp[51][51][2505];
int n, a;
ll solve(int i, ll cnt, ll sum){
    if(i==n){
        return (cnt && sum%cnt==0 && (sum/cnt)==a);
    }

    ll &ret = dp[i][cnt][sum];

    if(~ret) return ret;

    ll c = solve(i+1, cnt+1, sum + arr[i]) + solve(i+1, cnt, sum);

    return ret = c;
}
int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    cin>>n>>a;
    for(int i = 0; i<51; i++)
        for(int j = 0; j<51; j++)
            mem(dp[i][j], -1);

    for(int i =0; i<n; i++)cin>>arr[i];
    cout<<solve(0, 0, 0);
	return 0;

}


Measured memory_bytes: 51200
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 dd, tt, ss;
	cin >> dd >> tt >> ss;
	if(dd <= tt * ss)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int k;
  cin >> k;

  if(k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int index = 1;
  ll base = 7;
  while(true) {
    if(base % k == 0) break;
    base %= k;
    index++;
    base = base * 10 + 7;
    if(index > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << index << endl;
  return 0;
}


Measured memory_bytes: 3632
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3010;
const ll mod = 998244353;

ll a[N], dp[N][N];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, s;
    cin >> n >> s;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i ++)
        for (int j = 0; j < N; j ++)
            dp[i][j] = (2 * dp[i - 1][j] + (a[i] <= j ? dp[i - 1][j - a[i]] : 0)) % mod;
    cout << dp[n][s];
    return 0;
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N;
ll A[333];
ll Axor;
ll i, j, k;

int main(){
    scanf("%lld", &N);
    rep(i,0,N){
        scanf("%lld", &A[i]);
        Axor ^= A[i];
    }
    if(Axor%2==1){
        printf("-1\n");
        return 0;
    }
    Axor ^= A[0] ^ A[1];
    ll a = A[0] + A[1], b = 0;
    rep(i,0,50){
        if((Axor>>i)&1){
            a -= (1ll << i);
        }
    }
    if(a<0){
        printf("-1\n");
        return 0;
    }

    i = 50;
    while(i>=0){
        if((Axor>>i)&1^1){
            if(a>=(2ll<<i)){
                a -= (2ll << i);
                b += (1ll << i);
            }
        }
        --i;
    }
    if(a!=0||A[0]<b){
        printf("-1\n");
        return 0;
    }
    //printf("%lld\n", b);
    i = 50;
    while(i>=0){
        //if(Axor>>i&1)
        //    printf("%lld:%lld,%lld\n", i, A[0], b + (1ll << i));
        if((Axor>>i&1)&&A[0]>=b+(1ll<<i)){
            b += (1ll << i);
            //printf("a%lld:%lld\n", i, b);
        }
        --i;
    }
    if(b>0){
        printf("%lld\n", A[0] - b);
    }else{
        printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
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 main(){
    int N,Q;
    cin>>N>>Q;
    vector<pair<int,int>> P(Q);
    string S;
    cin>>S;
    for(int i=0;i<N;i++){
        S.at(i)=S.at(i);
    }
 for(int i=0;i<Q;i++){
   cin>>P.at(i).first;
   cin>>P.at(i).second;
 }
 
vector<int> count(N+1,0);

for(int i=1;i<N;i++){
    count.at(i)=count.at(i-1);
    if(S.at(i-1)=='A'&&S.at(i)=='C'){
            count.at(i)+=1;
             }     
}
for(int i=0;i<Q;i++){
   cout<<count.at(P.at(i).second-1)-count.at(P.at(i).first-1)<<endl;
}
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define MAX 1000000001



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

    if(2*n>=m){
        cout<<m/2<<endl;
    }else{
        cout<<n+(m-2*n)/4<<endl;
    }
}

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

for i in range(n):
    v = li[i]
    j = i - 1
    while j >= 0 and li[j] > v:
        li[j+1] = li[j]
        j -= 1
    li[j+1] = v
    print(str(li).replace(',', '')[1:-1])


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	string s,t;
	cin >> s >> t;
	vector<ll> v[50];

	FOR(i,s.size()){
		v[s[i]-'a'].push_back((ll)i);
		v[s[i]-'a'].push_back((ll)i+(ll)s.size());
	}

	bool aaa=1;
	FOR(i,t.size()){
		if(v[t[i]-'a'].empty())aaa=0;
	}

	FOR(i,30){
		sort(all(v[i]));
	}

	if(aaa){
		ll cnt=-1;
		ll ans=0;
		FOR(i,t.size()){
			auto itr=upper_bound(all(v[t[i]-'a']),cnt);
			ans+=*itr-cnt;
			cnt=*itr;
			cnt%=(ll)s.size();

		}

		cout << ans << endl;

	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 2872
#include<stdio.h>
#define MAX 100000

typedef struct{
  int p;
  int l;
  int r;
}Node;

Node tree[MAX];
int depth[MAX],child[MAX];
int n;

int getdepth(int x){
  int d=0;

  while(tree[x].p>=0){
    x=tree[x].p;
    d++;
  }
  return d;
}

void print(int x){
  int i,cnt=0;

  printf("node %d: parent = %d, depth = %d, ",x,tree[x].p,depth[x]);

  if(tree[x].p==-1)
    printf("root, [");
  else if(tree[x].l==-1)
    printf("leaf, [");
  else
    printf("internal node, [");

  x=tree[x].l;
  while(x!=-1){
    if(cnt==0)
      printf("%d",x);
    else
      printf(", %d",x);

    x=tree[x].r;
    cnt++;
  }
  printf("]\n");
}

int main(){
  int i,j;
  int k,x;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    tree[i].p=-1;
    tree[i].l=-1;
    tree[i].r=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&k);
    for(j=0;j<k;j++){
      scanf("%d",&child[j]);
      tree[child[j]].p=x;

      if(j==0)
        tree[x].l=child[0];
      else
        tree[child[j-1]].r=child[j];
    }
  }

  for(i=0;i<n;i++)
    depth[i] = getdepth(i);

  for(i=0;i<n;i++)
    print(i);

  return 0;
}

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

typedef pair<int, int> Pair;

int n;
int m;
Pair ps[114514];

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0;
     
    for (int i=0; i<n; i++) {
      int d;
      int p;
      scanf("%d%d", &d, &p);
      ps[i] = Pair(p, d);
    }
    sort(ps, ps+n, greater<Pair>());
    
    int ans = 0;
    for (int i=0; i<n; i++) {
      Pair pa = ps[i];
      int p = pa.first;
      int d = pa.second;
      if (m >= d) {
        m -= d;
      } else {
        d -= m;
        m = 0;
        ans += d*p;
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=305;
const ll mod=1e9+7;
ll dp[N][N][N];
bool is0[N][N][N];
int n;

void make_zeros(int l,int r,int x){
	vector<int>vec;
	FER(i,1,r)FER(j,i+1,r){
		vec.clear();
		vec.pb(i);vec.pb(j);vec.pb(r);
		do{
			int cnt=0;
			for(int val:vec)if(val>=l)cnt++;
			if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
		}while(next_permutation(all(vec)));
	}
	FER(i,1,r){
		vec.clear();
		vec.pb(0);vec.pb(i);vec.pb(r);
		do{
			int cnt=0;
			for(int val: vec)if(val>=l)cnt++;
			if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
		}while(next_permutation(all(vec)));
	}
	vec.clear();
	vec.pb(0);vec.pb(0);vec.pb(r);
	do{
		int cnt=0;
		for(int val: vec)if(val>=l)cnt++;
		if(cnt!=x)is0[vec[0]][vec[1]][vec[2]]=true;
	}while(next_permutation(all(vec)));
}

void MOD(ll &a){
	if(a>=mod)a-=mod;
}



int main(){	
	fastio;
	int q;cin>>n>>q;
	memset(dp,0,sizeof(dp));
	memset(is0,false,sizeof(is0));
	dp[0][0][0]=1;
	while(q--){
		int l,r,x;cin>>l>>r>>x;
		make_zeros(l,r,x);
	}
	FER(i,1,n+1)FER(j,1,n+1)FER(k,1,n+1)
		if(i==j||j==k||i==k)is0[i][j][k]=true;

	ll ans=0;
	
	FER(i,0,n+1)FER(j,0,i+1)FER(k,0,j+1){
		vector<int>vec;
		vec.pb(k);vec.pb(j);vec.pb(i);
		int nx=i+1;
		do{
			if(!is0[nx][vec[1]][vec[2]]){
				dp[nx][vec[1]][vec[2]]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[nx][vec[1]][vec[2]]%=mod;
				MOD(dp[nx][vec[1]][vec[2]]);
			}
			if(!is0[vec[0]][nx][vec[2]]){
				dp[vec[0]][nx][vec[2]]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[vec[0]][nx][vec[2]]%=mod;
				MOD(dp[vec[0]][nx][vec[2]]);
			}
			if(!is0[vec[0]][vec[1]][nx]){
				dp[vec[0]][vec[1]][nx]+=dp[vec[0]][vec[1]][vec[2]];
				//dp[vec[0]][vec[1]][nx]%=mod;
				MOD(dp[vec[0]][vec[1]][nx]);
			}
		}while(next_permutation(all(vec)));
	}



	FER(r,0,n+1)FER(g,0,n+1)FER(b,0,n+1){
		int mx=max(r,max(g,b));
		if(mx==n){
			ans+=dp[r][g][b];
			MOD(ans);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 249600
class UnionFind
    def initialize(n)
        @have_node_num = Array.new(n, -1)
    end
    def findSet(x)
        return x if @have_node_num[x] < 0
        @have_node_num[x] = findSet(@have_node_num[x])
        return @have_node_num[x]
    end
    def link(x, y)
        return if x == y
        x, y = y, x if @have_node_num[x] > @have_node_num[y]
        @have_node_num[x] += @have_node_num[y]
        @have_node_num[y] = x
    end
    def unite(x, y)
        link(findSet(x), findSet(y))
    end
    def same(x, y)
        findSet(x) == findSet(y)
    end
    def size(idx)
        return -@have_node_num[findSet(idx)]
    end
end

n, m, k = gets.chomp.split.map(&:to_i)
uf = UnionFind.new(n)
minus = Array.new(n, 0)
ans = []
m.times do
    a, b = gets.chomp.split.map(&:to_i)
    a -= 1
    b -= 1
    minus[a] += 1
    minus[b] += 1
    uf.unite(a, b)
end

k.times do
    c, d = gets.chomp.split.map(&:to_i)
    c -= 1
    d -= 1
    if uf.same(c, d) then
        minus[c] += 1
        minus[d] += 1 
    end
end

n.times do |i|
    ans << uf.size(i) - minus[i] - 1
end

puts ans.join(" ")

Measured memory_bytes: 17280
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int n; cin >> n;
    int v[n];
    int c[n];
    int vminusc[n];
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }
    for(int i=0; i<n; i++){
        vminusc[i]=v[i]-c[i];
    }
    sort(vminusc,vminusc+n);
    int ans=0;
    for(int i=0; i<n; i++){
        if(vminusc[i]>0) ans+=vminusc[i];
    }
    cout << ans << endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";
using ll = long long;

void solve(long long X){
    if(X >= 30){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
 public:
  int n;
  vector<vector<T>> mat;
  F func;

  SparseTable(const vector<T>& a, const F& f) : func(f) {
    n = static_cast<int>(a.size());
    int max_log = 32 - __builtin_clz(n);
    mat.resize(max_log);
    mat[0] = a;
    for (int j = 1; j < max_log; j++) {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++) {
        mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
      }
    }
  }

  T get(int from, int to) const {
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 32 - __builtin_clz(to - from + 1) - 1;
    return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};

int n, k;

int main() {
  cin >> n >> k;
  vector<int> p(n);
  range(i, 0, n) scanf("%d", &p[i]);
  SparseTable<int> st(p, [&](int x, int y){ return max(x ,y); });
  SparseTable<int> sp(p, [&](int x, int y){ return min(x, y); });
  vector<int> to(n);
  husk(i, n - 1, -1) {
    if(i < n - 1 && p[i] < p[i + 1]) to[i] = to[i + 1];
    else to[i] = i;
  }
  int res = 0;
  range(i, 0, n) if(to[i] >= i + k - 1) res = 1;
  vector<int> pos;
  range(i, 0, n - k + 1) if(to[i] < i + k - 1) pos.push_back(i);
  while(pos.size()) {
    res++;
    int u = pos.back();
    pos.pop_back();
    while(pos.size()) {
      int v = pos.back();
      if(v + k - 1 < u) break;
      int mx = st.get(u, v + k - 1);
      int mn = sp.get(u, v + k - 1);
      if(to[v + k] >= u + k - 1 && to[v] >= u - 1 && p[v + k] > mx && p[u - 1] < mn) {
        pos.pop_back();
      } else break;
    }
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 29176
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const int N=1e5;
int main()
{
    FASTINOUT;
    double x,y,z;
    cin>>x>>y>>z;
    if (x+y+2*sqrtl(x)*sqrtl(y)<z)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int Y,X;
    cin >> Y >> X;
    vector<string> a(Y);
    rep(y,Y) cin >> a[y];
    vector<vector<modint>> dp(Y+1, vector<modint>(X+1));
    dp[0][0] = 1;
    rep(y,Y)rep(x,X){
        if (a[y][x] == '#') continue;
        dp[y+1][x] += dp[y][x];
        dp[y][x+1] += dp[y][x];
    }
    cout << dp[Y-1][X-1] << endl;

    return 0;
}


Measured memory_bytes: 9216
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N=200050;
struct node
{
	long long int to,next,c;
}e[N];
long long int first[N],dep[N],visit[N];
long long int fa[N][30],dis[N];
int cnt=0;
void insert(int u,int v,int c)
{
	e[++cnt].to=v;e[cnt].next=first[u];first[u]=cnt;e[cnt].c=c;
	e[++cnt].to=u;e[cnt].next=first[v];first[v]=cnt;e[cnt].c=c;
}
void dfs(int x)
{
	visit[x]=1;
	for(int i=1;(1<<i)<=dep[x];i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int k=first[x];k;k=e[k].next)	
	if(!visit[e[k].to])
	{
		fa[e[k].to][0]=x;
		dep[e[k].to]=dep[x]+1;
		dis[e[k].to]=dis[x]+e[k].c;
		dfs(e[k].to);
	}
}
int lca(int x,int y)
{
	if(dep[x]<dep[y])	std::swap(x,y);
	int t=dep[x]-dep[y];
	for(int i=0;(1<<i)<=t;i++)
	if((1<<i)&t)	x=fa[x][i];

	for(int i=25;i>=0;i--)
	if((1<<i)<=dep[x]&&fa[x][i]!=fa[y][i])
	x=fa[x][i],y=fa[y][i];
	if(x==y)	return x;
	return fa[x][0];
}
int main()
{
	long long int n;	
	scanf("%lld",&n);
	int v,u,c;
	for(int i=2;i<=n;i++)		scanf("%d %d %d",&v,&u,&c),insert(v,u,c);
	dfs(1);
	int m,k;
	scanf("%d %d",&m,&k);
	for(int i=1;i<=m;i++)
	{
		long long int x,y;
		scanf("%lld %lld",&x,&y);
		long long  lc=lca(x,k);
		long long ans=dis[x]+dis[k]-2*dis[lc];
		lc=lca(y,k);
		ans+=dis[y]+dis[k]-2*dis[lc];
		printf("%lld\n",ans);
	}
	return 0;	
}

Measured memory_bytes: 41472
#include<cstdio>
#include<algorithm>
#include<cmath>
#define MAX 100005
using namespace std;

int main(){
  int n, a[MAX], i, l, mid, r, c;
  long long ans = 1;
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a+n);
  
  if(a[0]*2 > a[n-1]) c = a[0];
  else if(a[n-2]*2 <= a[n-1]) c = a[n-2];
  else {
    l = 0; r = n-2;
    while(r-l > 1){
      mid = (l + r) / 2;
      if(a[mid] * 2 > a[n-1]) r = mid;
      else l = mid;
    }
    c = ((a[n-1] - a[l]*2) < (a[r]*2 - a[n-1])) ? a[l] : a[r];
  }
  printf("%d %d\n", a[n-1], c);
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

ll a[maxn], f[maxn];

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

    fast;

    int n, k = 2;

    cin >> n;

    for(int i = 1; i <= n; i++) cin >> a[i];

    f[n] = 0;

    for(int i = n - 1; i > 0; i--){
        f[i] = 1e18;

        for(int j = 1; j <= k; j++){
            if(i + j > n) continue;

            f[i] = min(f[i], f[i + j] + abs(a[i] - a[i + j]));
        }
    }

    cout << f[1] << endl;

    return 0;
}

Measured memory_bytes: 5168
N,Q=map(int,input().split())
S=input()
li=[0]*N
t=0
for i in range(N-1):
  if S[i:i+2]=="AC":
      t+=1
  li[i+1]=t
for _ in range(Q):
  l,r=map(int,input().split())
  print(li[r-1]-li[l-1])

Measured memory_bytes: 7596
#include <bits/stdc++.h>
#define mem(a,b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f
#define rep(a, b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 5;

int main()
{
    string a;
    cin >> a;
    if(a == "SUN")
    {
        cout << 7 << endl;
    }
    else if(a == "SAT")
        cout << 1 << endl;
    else if(a == "MON")
        cout << 6 << endl;
    else if(a == "TUE")
        cout << 5 << endl;
    else if(a == "WED")
        cout << 4 << endl;
    else if(a == "THU")
        cout << 3 << endl;
    else if(a == "FRI")
        cout << 2 << endl;
    return 0;
}


Measured memory_bytes: 256
/*
Created on Fri Aug 25 16:34:06 2020

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
const int mod = 1e9+7;
#define INF INT_MAX;
#define endl "\n"
#define append push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

int a[101];
int wt[101];
ll weird(ll n, ll w, ll sum) {
	ll dp[n+1][sum+1];
	for(int i = 0; i<sum+1; i++) dp[0][i] = INF;
	for(int i = 0; i<n+1; i++) dp[i][0] = 0;
	
	for(int i = 1; i<n+1; i++) {
		for(int j = 1; j<sum+1; j++) {
			
			if(a[i-1] <= j)
				dp[i][j] = min(wt[i-1] + dp[i-1][j-a[i-1]], dp[i-1][j]);
			
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	ll res = 0;
	for(int i = 0; i<sum+1; i++) {
		if(dp[n][i]<=w)
			res = i;
	}
	
	return res;
}

int main() {
	roastedcoder
	ll n, w, sum = 0; cin>>n>>w;
	for(int i = 0; i<n; i++) {
		cin>>wt[i]>>a[i];
		sum += a[i];
	}
	cout<<weird(n, w, sum);
}

//__________________________________________________________________
/*
Sample Input:
500 1000 20 30


Sample Output:
Vasya

*/

Measured memory_bytes: 82400
using System;
using System.Linq;
using System.Collections.Generic;

namespace program{
  class Program{
    static void Main(){
      long[] input = Input.ScanLongArray();
      long N = input[0];
      long W = input[1];
      long[] MinWaight = new long[100001];
      for(int i=1;i<=100000;i++) MinWaight[i] = 1LL<<60;
      for(long i = 0; i < N; i++)
      {
        input = Input.ScanLongArray();
        for(int k = 100000; k>=input[1]; k--)
          MinWaight[k] = Math.Min(MinWaight[k], MinWaight[k-input[1]] + input[0]);
      }
      long MaxValue;
      for(MaxValue = 100000; MaxValue >=0; MaxValue--)
      {
        if(MinWaight[MaxValue] <= W) break;
      }
      Console.WriteLine($"{MaxValue}");
    }
  }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }
}


Measured memory_bytes: 13920
#include<iostream>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
//input
int n,l;
cin>>n;
//compute
if(n<=81){
  for(int i=1;i<10;i++){
   int m=n%i;
   int p=n/i;
   if(m==0&&p<=9){
     l=1;
     break;
   }
  }
}
else l=0;

if(l==1)printf("Yes");
else printf("No");
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}




int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> a(N + 1);
    a[0] = 0;
    //累積和の構築
    for(int i = 1; i < N; i++){
        if(S.at(i - 1) == 'A' && S.at(i) == 'C') a[i + 1] = a[i] + 1;
        else a[i + 1] = a[i];
    }

    vector<int> ans(Q);

    rep(i, Q){
        int l, r;
        cin >> l >> r;
        ans[i] =  a[r] - a[l];
    }
    rep(i, Q)cout << ans[i] << endl;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, ma = 1, m = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int s = i, u = 0;
		while (s % 2 == 0)
			s /= 2, u++;
		if (m < u)
			ma = i, m = u;
	}
	cout << ma << endl;
	getchar(); getchar();
}

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

int main(){
	int N;
	cin >> N;
	vector<string> s(N);
	for(int i=0;i<N;i++)cin >> s[i];
	
	int ans=0,A=0,B=0,AB=0;
	for(int i=0;i<N;i++){
		if(s[i][0]=='B')B++;
		if(s[i][s[i].size()-1]=='A')A++;
		if(s[i][0]=='B' && s[i][s[i].size()-1]=='A')AB++;
		for(int j=0;j<s[i].size()-1;j++)if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
	}
	
	if(AB>0 && A==AB && B==AB)ans+=AB-1;
	else ans+=min(A,B);
	
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("hard1.txt","r",stdin)
#define OUT freopen("hard1.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 1000005
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii ;

#define maxn 200005
#define mod 998244353LL
#define lim 1000000000
#define INF 4500000000000000000LL
#define Max(x,y,z) max(max(x,y),z)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char s[maxn] ;
int cnt[35] ;

int main()
{
    scanf("%s",s) ;

    int n = strlen(s) ;

    for(int i=0 ; i<n ; i++) cnt[ s[i]-'a' ]++ ;

    i64 ans = (1LL*(n-1)*n)/2 ;

    for(int i=0 ; i<26 ; i++)
    {
        ans -= ( 1LL*(cnt[i]-1)*cnt[i] )/2 ;
    }

    printf("%lld\n",ans+1) ;

    return 0 ;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

void solve(){
	ll n,k;
	cin >> n >> k;
	if(n >= k){
		cout << min(abs(n-k * (n/k)),abs(n-k * (n/k+1))) << endl;
	}else{
		cout << min(min(n,k), abs(n-k)) << endl;
	}
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3632
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        final boolean[][] paths = new boolean[N+1][N+1];
        for (int i = 0; i < M; i++) {
            final int a = sc.nextInt();
            final int b = sc.nextInt();
            paths[a][b] = true;
        }

        final List<Integer> candidate = IntStream.rangeClosed(1, N).boxed().collect(Collectors.toList());
        final List<List<Integer>> perms = new ArrayList<>();
        perm(candidate, new ArrayList<>(), perms);

        int ans = 0;

        for (List<Integer> perm : perms.stream().filter(e -> e.get(0) == 1).collect(Collectors.toList())) {
            boolean matched = true;
//            System.out.println("[" + perm + "]");
            for (int i = 0; i < N-1; i++) {
//                System.out.println(perm.get(i) + "->" + perm.get(i+1) + " ... " + paths[perm.get(i)][perm.get(i+1)] + ", " + paths[perm.get(i+1)][perm.get(i)]);
                if (!paths[perm.get(i)][perm.get(i+1)] && !paths[perm.get(i+1)][perm.get(i)]) {
                    matched = false;
                    break;
                }
            }

            if (matched) {
                ans++;
            }
        }

        System.out.println(ans);
    }

    private static void perm(final List<Integer> candidate, final List<Integer> perm, final List<List<Integer>> perms) {
        if (candidate.size() == 0) {
            perms.add(perm);
        }
        for (int i = 0; i < candidate.size(); i++) {
            final List<Integer> c = new ArrayList<>(candidate);
            final List<Integer> p = new ArrayList<>(perm);
            p.add(candidate.get(i));
            c.remove(i);
            perm(c, p, perms);
        }
    }
}


Measured memory_bytes: 45804
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long double ld;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//function area
//main area
int main(){
    int n;
    while(cin >> n){
        if(n == 0) break;
        int s[n];
        int sum = 0;
        rep(i,n){
            cin >> s[i];
            sum += s[i];
        }
        ld ave = sum * 1.0 / n;
        ld k = 0;
        rep(i,n){
            k += (s[i] - ave)*(s[i] - ave);
        }
        cout << fixed << setprecision(6) << sqrtl(k / n) << endl;
    }
}


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

signed main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i,h) cin >> c[i];

  int ans = 0;
  for (int hbit = 0; hbit < (1<<h); ++hbit) {
    for (int wbit = 0; wbit < (1<<w); ++wbit) {
      int count = 0;
      for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
          if (c[i][j] == '.') continue;
          if ((hbit & (1<<i)) || (wbit & (1<<j))) continue;
          ++count;
        }
      }
      if(count == k) ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
def solve(string):
    n, *a = map(int, string.split())
    ans = 0
    while all([_a % 2 == 0 for _a in a]):
        a = [_a // 2 for _a in a]
        ans += 1
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 3060
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=500016;

char s[N];
int a[N],b[N],n,sz,cur;

il bool check(int x){
	memcpy(b,a,sizeof(int)*sz);
	rep(i,sz,cur-1) b[i]=0;
	b[0]+=x*9;
	int sum=0;
	rep0(i,cur){
		b[i+1]+=b[i]/10;
		b[i]%=10;
		sum+=b[i];
	}
	return sum<=x*9;
}

int main(){
//	fileio("test");
	scanf("%s",s),n=strlen(s);
	rep0(i,n){
		a[i]+=(s[n-i-1]-'0')*9;
		a[i+1]+=a[i]/10;
		a[i]%=10;
	}
	sz=(!a[n]?n:n+1);
	cur=qmax(sz+1,10);
	int ur=n,ul=0;
	while(ur-ul>1){
		int mid=ul+ur>>1;
		if(check(mid)) ur=mid;else ul=mid;
	}
	printf("%d\n",ur);
	return 0;
} 

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0 ; i < int(N);i++)
using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;



int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    string s ;
    cin >> s ;
    int x = 0;
    for (char c : s ){
    	x += (c - '0');
    	// cout << x << endl;
    	    }
    if (x % 9 == 0 ){
    	cout << "Yes";
    }
    else {
    	cout << "No";
    }

	return 0 ;
}

Measured memory_bytes: 3748
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  long sum=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
    sum+=i;
    }
  }
  System.out.println(sum);
}
}

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

vector<int> path, cycle;
map<int, bool> mp;

int main() {
    long long n, k; cin >> n >> k;
    int a[n + 1] = {}; 
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; 1; i = a[i]) {
        if (!mp[a[i]]) {
            path.push_back(a[i]);
            mp[a[i]] = true;
        } else {
        	bool flag = false;
        	for (int j : path) {
        		if (j == a[i]) flag = true;
        		if (flag) cycle.push_back(j);
        	}
        	break;
        }
    }
    if (k <= path.size()) cout << path[k - 1];
    else {
        k -= path.size();
        k %= cycle.size();
        cout << cycle[(k - 1 + cycle.size()) % cycle.size()];
    }
}


Measured memory_bytes: 14920
K, N = map(int, input().split())
A = list(map(int, input().split()))

B = [0]*N
B[0] = A[0] + (K - A[N-1])
for i in range(1, N):
  B[i] = A[i] - A[i-1]
#print(B)
print(K-max(B))

Measured memory_bytes: 26444
#include<stdio.h>
#include<string.h>

int main(){
  int count=0;
  int sum=0;
  char s[101];
  int p[200],n,L;
  scanf("%d",&n);
  scanf("%d",&L);
  for(int i=0;i<n;i++){
    p[i]=L+i;
    sum+=p[i];
  }
  if(p[0]<=0&&p[n-1]>=0){count=sum;}
  else if(L<=0){count=sum-p[n-1];}
  else{count=sum-p[0];}
  
  printf("%d\n",count);
  
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vector<vector<pll>> a(n);
	FOR(i,0,n) {
		ll m; cin >> m;
		while (m--) {
			ll x, y;
			cin >> x >> y;
			x--;
			a[i].eb(x,y);
		}
	}

	int res = 0;
	FOR(mask,0,1 << n) {
		bool ok = true;
		FOR(i,0,n) if (mask & (1 << i)) for (auto pr: a[i]) {
			if (pr.yy != ((mask >> pr.xx) & 1)) ok = false;
		}
		if (ok) res = max(res,__builtin_popcount(mask));
	}
	cout << res << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  int a,b,k;
  cin>>a>>b>>k;
  int loop=min(a,b);
  vint res;
  for(int i=1;i<=loop;++i){
    if(a%i==0&&b%i==0)res.pb(i);
  }
  reverse(all(res));
  cout<<(res[k-1])<<endl;
  

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
#define N 500000


void Merge(int *, int, int, int);
void Merge_Sort(int *, int, int);

int cnt=0;

int main(void)
{
  int i,n,A[N];

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

  Merge_Sort(A, 0, n);

  for(i=0; i<n; i++){
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}

void Merge(int *A,int left,int mid,int right)
{
  int n1,n2,i,j,k;
  int L[N],R[N];

  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }

  for(i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = j = 0;

  for(k=left; k<right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
    cnt++;
  }
}

void Merge_Sort(int *A,int left,int right)
{
  int mid;

  if(left+1 < right){
    mid = (left + right)/2;
    Merge_Sort(A, left, mid);
    Merge_Sort(A, mid, right);
    Merge(A, left, mid, right);
  }

}

Measured memory_bytes: 5492
c=[list(map(int,input().split())) for i in range(3) ]
Y=[c[0][1]-c[0][0],c[0][2]-c[0][1]]
T=[c[1][0]-c[0][0],c[2][0]-c[1][0]]
flg=0
for i in range(1,3):
    if (c[i][1]-c[i][0])!=Y[0] or (c[i][2]-c[i][1])!=Y[1]:
        flg=1
        break
if flg<1:
    for i in range(1,3):
        if (c[1][i]-c[0][i])!=T[0] or (c[2][i]-c[1][i])!=T[1]:
            print("T",i)
            flg=1
            break
print(["Yes","No"][flg])




Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] B = (int[]) A.Clone();
		Array.Sort(B);
		
		int lm = B[N/2 - 1];
		int rm = B[N/2];
		
		int[] Ans = new int[N];
		for(int i=0;i<N;i++){
			if(lm == rm) Ans[i] = lm;
			else {
				if(A[i] <= lm) Ans[i] = rm;
				else Ans[i] = lm;
			}
		}
		
		Console.WriteLine(String.Join("\n",Ans));
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 45048
from sys import stdin
from collections import defaultdict
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())


def main():
    N = i_input()
    d = defaultdict(lambda: 1)
    ans = 0
    for i in range(2, N):
        for j in range(i, N, i):
            d[j] += 1
    for c in range(1, N):
        ans += d[c]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 265328