akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = 100001;
        }
        int[] B = new int[N-1];
        for (int i = 0; i < N - 1; i++) {
            B[i] = Integer.parseInt(sc.next());
            if (B[i] < A[i]) {
                A[i] = B[i];
            }
            if (B[i] < A[i+1]) {
                A[i+1] = B[i];
            }
        }
        sc.close();

        out.printf("%d\n", Arrays.stream(A).sum());
        out.flush();
    }
}


Measured memory_bytes: 28372
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    class Job{
        int a, b;
        public Job(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public String toString() {
            return this.a +  " " + this.b;
        }
    }
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        PriorityQueue<Job> jQ = new PriorityQueue<>((o1, o2) -> o1.b - o2.b);


        for (int i = 0; i < n; i++) {
            jQ.add(new Job(sc.nextInt(), sc.nextInt()));
        }

        int time = 0;

        boolean isCompleted = true;
        for (int i = 0; i < n; i++) {
            Job j = jQ.poll();
            time = time + j.a;
            if (time > j.b) {
                isCompleted = false;
                break;
            }
        }

        System.out.println(isCompleted ? "Yes" : "No");
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 111356
s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)
ans = 0
f = 0
dp = [0]*(2020)
dp[0]+=1
tmp =0
x = 1
for e,i in enumerate(s):
    tmp = (tmp+x*i)%2019
    ans += dp[tmp]
    dp[tmp]+=1
    x = x*10 %2019
print(ans)


Measured memory_bytes: 13376
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using Int = int64_t;
template <class T>
istream& operator>>(istream& input, vector<T>& v) {
    for (auto& i : v) input >> i;
    return input;
}
int main() {
    Int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<Int> p(A), q(B), r(C);
    cin >> p >> q >> r;
    sort(p.begin(), p.end(), greater<Int>());
    sort(q.begin(), q.end(), greater<Int>());
    sort(r.begin(), r.end(), greater<Int>());
    vector<Int> t(p.begin(), p.begin() + X);
    t.insert(t.end(), q.begin(), q.begin() + Y);
    t.insert(t.end(), r.begin(), r.end());
    sort(t.begin(), t.end(), greater<Int>());
    cout << accumulate(t.begin(), t.begin() + X + Y, (Int)0) << endl;
}

Measured memory_bytes: 6592
import math
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

def lcm(a, b):
    return (a * b) // math.gcd(a, b)

a_lcm = 1
for ai in a:
    a_lcm = lcm(a_lcm, ai)

b_sum = 0
for i in range(n):
    b_sum += a_lcm // a[i]

print(b_sum%mod)


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

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  vector<int> d(m);
  map<int,int> dark_map;
  for(int i=0;i<m;i++){
    cin>>d[i];
    d[i]--;
    dark_map[d[i]]=i;
  }
  vector<vector<int>> v(n,vector<int>(k));
  for(int i=0;i<n;i++)
    for(int j=0;j<k;j++){
      cin>>v[i][j];
      v[i][j]--;
    }
  vector<vector<int>> v2(m);
  for(int i=0;i<m;i++){
    v2[i]=v[d[i]];
  }
  const int INF=1e9;
  vector<int> dp(1<<m,INF);
  int first_p=(1<<m)-1;
  dp[first_p]=0;
  pair<int,int> state=make_pair(0,first_p);
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
  que.push(state);

  while(!que.empty()){
    state=que.top();
    que.pop();
    int p=state.second;
    int sc=state.first;
    if(dp[p]<sc) continue;

    for(int i=0;i<k;i++){
      int top=0;
      for(int j=0;j<m;j++){
	if(p & (1<<j)){
	  if(dark_map.count(v2[j][i])){
	    top|=(1<<(dark_map[v2[j][i]]));
	  }
	}
      }
      if(dp[top]>sc+1){
	dp[top]=sc+1;
	que.push(make_pair(sc+1,top));
      }
    }
  }
  cout<<dp[0]<<endl;
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// }}} 1

int main() {

    int n,K,a;
    bool x[10] = {};
    bool en = false;
    Scd2(n,K);

    Rep(i,K){
        Scd(a);
        x[a] = true;
    }
    Rep(h,10){
        if( x[h] && h != 0 ) continue;
        Rep(i,10){
            if( x[i] && h+i ) continue;
            Rep(j,10){
                if( x[j] && h+i+j ) continue;
                Rep(k,10){
                    if( x[k] && h+i+j+k ) continue;
                    Rep(l,10){
                        if( x[l] && h+i+j+k+l ) continue;
                        if( h*10000 + i*1000 + j*100 + k*10 + l >= n ){
                            n =  h*10000 + i*1000 + j*100 + k*10 + l;
                            printf ("%d\n", n);
                            en = true;
                        }
                        if( en ) break;
                    }
                    if( en ) break;
                }
                if( en ) break;
            }
            if( en ) break;
        }
        if( en ) break;
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,s,p=0,i,j,k;
    cin >> a >> b >> c >> x;
    for( i = 0; i <= a; i++)
    {
        for( j = 0; j <= b; j++)
        {
            for( k = 0; k <= c; k++)
            {
                s = 500*i + 100*j + 50*k;
                if(x == s) p++;
                else if(s > x) break;
            }
        }
    }
    cout << p << endl;
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  int cnt=0;
   for(int i=0;i<n-2;i++){
     if(vec[i]<vec[i+1]&&vec[i+1]<vec[i+2])cnt++;
     if(vec[i]>vec[i+1]&&vec[i+1]>vec[i+2])cnt++;
   }
  cout<<cnt<<endl;
}

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

int main(){
    string T;
    cin >> T;
    rep(i,T.size()){
        if(T.at(i)=='?'){
            T.at(i) = 'D';
        }
    }
    cout << T << endl;
}

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

int main(){
    int n;
    cin>>n;
    string tmp;
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        cin>>tmp;
        if(tmp=="AC")ac++;
        else if(tmp=="WA")wa++;
        else if(tmp=="TLE")tle++;
        else if(tmp=="RE")re++;
    }

    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;


}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    ll h; cin >> h;
    ll ans = 1;
    while (ans <= h){
        ans = ans << 1;
    }
    ans--;
    
    cout << ans << endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int now[4];
char C[4], op[2] = {'+', '-'};

int main(){
  for (int i = 0; i < 4; i++){
    cin >> C[i];
    now[i] = C[i] - '0';
  }

  for (int i = 0; i < 8; i++){
    int val = now[0], num = i;

    for (int j = 1; j < 4; j++){
      val += pow(-1, num % 2) * now[j];
      num /= 2;
    }

    if (val == 7){
      num = i;
      cout << now[0];
      for (int j = 1; j < 4; j++){
        cout << op[num%2] << now[j];
        num /= 2;
      }

      cout << "=7" << endl;

      return 0;
    }

  }

  return 0;
}


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

const int64_t MOD = 998244353;

int64_t pow(int64_t n, int64_t k) {
  int64_t result = 1;
  while (k != 0) {
    if (k % 2 == 1) {
      result = result * n % MOD;
    }
    k /= 2;
    n = n * n % MOD;
  }
  return result;
}

int main() {
  int64_t n, m, k;
  cin >> n >> m >> k;
  int64_t factorial[n], ifactorial[n], inv[n];
  inv[1] = 1;
  factorial[0] = 1;
  factorial[1] = 1;
  ifactorial[0] = 1;
  ifactorial[1] = 1;
  for (int64_t i = 2; i < n; ++i) {
    inv[i] = (-MOD / i + MOD) * inv[MOD % i] % MOD;
    factorial[i] = factorial[i - 1] * i % MOD;
    ifactorial[i] = ifactorial[i - 1] * inv[i] % MOD;
  }
  auto C = [&](int64_t n, int64_t k) {
    return factorial[n] * ifactorial[k] % MOD * ifactorial[n - k] % MOD;
  };
  int64_t result = 0;
  for (int64_t i = 0; i <= k; ++i) {
    result = (result + m * C(n - 1, i) % MOD * pow(m - 1, n - 1 - i)) % MOD;
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 7832
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCpder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;





signed main() {
    ll A, B, K;
    cin >> A >> B >> K;

    ll lastA = 0;
    ll lastB = 0;

    if (A > K) {
        lastA = A - K;
        lastB = B;
    }
    else if(A+B > K) {
        lastA = 0LL;
        lastB = A + B - K;
    }
    else {
        lastA = 0LL;
        lastB = 0LL;
    }


    cout << lastA << " " << lastB << endl;
}

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

int main(){
    int M1,M2,D1,D2;
    cin >> M1 >> D1 >> M2 >> D2;
    cout << (D2 < D1);
    return 0;
}


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

using namespace std;

int main() {
	int n; scanf("%d", &n);
	vector<pair<int, int>> pts(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &pts[i].first, &pts[i].second);
	}
	if (n == 1) {
		printf("1\n");
		return 0;
	}
	int ans = 100;
	set<pair<int, int>> ptset(begin(pts), end(pts));
//	printf("here\n");
	for (int fi = 0; fi < n; ++fi) {
		for (int fj = 0; fj < fi; ++fj) {
			int p = pts[fi].first - pts[fj].first;
			int q = pts[fi].second - pts[fj].second;
			if (p == 0 && q == 0) continue;
			int cfans = 0;
			for (int i = 0; i < n; ++i) {
				if (ptset.count(make_pair(pts[i].first - p, pts[i].second - q)) == 0) {
					++cfans;
				}
			}
			ans = min(ans, cfans);
//			printf("force collect pair %d %d ans %d\n", fi, fj, cfans);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[120][120];
bool vis[120][120];
int n, m;
int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);
	for(int i = 1; i <= n; i++) {
		bool flag = true;
		for(int j = 1; j <= m; j++)
			if(a[i][j] != '.') {
				flag = false;
				break;
			}
		if(flag) {
			for(int j = 1; j <= m; j++) {
				vis[i][j] = true;
			}
		}
	}
	for(int i = 1; i <= m; i++) {
		bool flag = true;
		for(int j = 1; j <= n; j++)
			if(a[j][i] != '.') {
				flag = false;
				break;
			}
		if(flag) {
			for(int j = 1; j <= n; j++) {
				vis[j][i] = true;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		bool flag = false;
		for(int j = 1; j <= m; j++)
			if(vis[i][j] == false) {
				printf("%c", a[i][j]);
				flag = true;
			}
		if(flag == true) puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> itv;
  REP(i, M) {
    int L, R;
    cin >> L >> R;
    itv.PB(MP(L, R));
  }
  pair<int, int> ans(1, N);
  REP(i, M) {
    if (itv[i].SE < ans.FI || ans.SE < itv[i].FI) {
      cout << 0 << endl;
      return 0;
    } else if (ans.FI <= itv[i].FI && itv[i].SE <= ans.SE) {
      ans = itv[i];
    } else {
      ans.FI = max(ans.FI, itv[i].FI);
      ans.SE = min(ans.SE, itv[i].SE);
    }
  }
  cout << (ans.SE - ans.FI + 1) << endl;

  return 0;
}


Measured memory_bytes: 1400
n, m = map(int, input().split())
tama = [1]*n
red = [False]*n
red[0] = True

for i in range(m):
    x,y = map(int, input().split())
    tama[x-1] -= 1
    tama[y-1] += 1
    red[y-1] = red[y-1] or red[x-1]
    if tama[x-1] == 0:
        red[x-1] = False
print(sum(red))

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	while(cin>>n, n!=0){
		ll w, h; cin>>w>>h;
		vector<vector<char> > field(h, vector<char>(w, ' '));
		rep(i, n){
			ll x, y; cin>>x>>y;
			field[y-1][x-1] = 't';
		}
		ll s, t; cin>>s>>t;
		ll ans=0;
		for(int i=0; i<=h-t; i++){
			for(int j=0; j<=w-s; j++){
				ll cnt=0;
				rep(k, t)rep(l, s)
					if (field[i+k][j+l]=='t') cnt++;
				ans = max(ans, cnt);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cmath>

using namespace std;

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

    long half = sqrt(N);

    for (long i=half; i > 0; --i) {
        if (N % i == 0) {
            cout << (N / i) + i - 2 << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<map>
using namespace std;
typedef long long int ll;
 
ll gcd(ll a, ll b){
    if (b == 0) return a;

    return gcd(b, a % b);
}

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

    if (S.length() <= K) cout << S << endl;
    else {
        for (int i = 0; i < K; i++){
            cout << S[i];
        }
        cout << "..." << endl;
    } 
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>

using namespace std;

typedef long long LL;

int main() {
    int n, m;
    cin >> n >> m;
    int s=0;
    switch(n) {
        case 1: s+= 300000; break;
        case 2: s+= 200000; break;
        case 3: s+= 100000; break;
    }
    switch(m) {
        case 1: s+= 300000; break;
        case 2: s+= 200000; break;
        case 3: s+= 100000; break;
    }
    if(n==1&&m==1) s+= 400000;
    cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<cmath>
#include<set>
#define int long long int
const int maxn=21;
int32_t main()
{
    int n;
    cin>>n;
    set<int> s;
    int j;
    for(j=0;j<n;j++)
    {
		int x;
		cin>>x;
		s.insert(x);
	}
	int val=s.size();
	int cut=n-val;
	if(cut%2!=0)
	   val--;
	cout<<val<<endl;
}


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

signed main(){
    int N,a;
    cin>>N;
    vector<int>vec(N,0);
    REP(i,N-1){
        cin>>a;
        vec[a-1]++;
    }
    REP(i,N) cout<<vec[i]<<endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)998244353) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

class Tree{
public:
	int n;
	vector<int> p;
	vector<vector<int>> c;
	vector<int> d;
	vector<int> h;

	Tree(int N){
		n=N;
		p.resize(N, -1);
		c.resize(N);
		d.resize(N, -1);
		h.resize(N, -1);
	}

	void add(int pa, vector<int> ch){
		foreach(i, ch){
			if(i==-1)continue;
			c[pa].push_back(i);
			p[i]=pa;
		}
	}

	int get_brother(int id){
		if(p[id]==-1)return -1;
		foreach(i, c[p[id]]){
			if(i!=id)return i;
		}
		return -1;
	}
	
	int get_depth(int id){
		if(p[id] == -1)return 0;
		if(d[id] >= 0)return d[id];
		return d[id] = get_depth(p[id]) + 1;
	}

	int get_height(int id){
		if(h[id]>=0)return h[id];
		int res = 0;
		foreach(i, c[id]){
			res = max(res, get_height(i)+1);
		}
		return h[id]=res;
	}

	int get_degree(int id){
		return c[id].size();
	}

	int get_parent(int id){
		return p[id];
	}
};

int main(){
	int N;
	cin >> N;
	Tree t(N);
	REP(i, N){
		int a;
		vector<int> l(2);
		cin >> a;
		foreach(i, l)cin>>i;
		t.add(a, l);
	}
	REP(i, N){
		cout << "node " << i << ": parent = " << t.get_parent(i) << ", sibling = "
			<< t.get_brother(i) <<", degree = " << t.get_degree(i) << ", depth = "
			<< t.get_depth(i) << ", height = " << t.get_height(i) << ", "
		   	<< (t.get_parent(i)==-1?"root":t.get_degree(i)==0?"leaf":"internal node")
		   	<< endl;
	}
	return 0;
}



Measured memory_bytes: 3168
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce
# table_size = 510000
table_size = 2*10**5+1  # 200001
mod = 10**9+7


# Combination の計算を最適化する必要がある?
# def nCr(n, r):
#     numerator = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
#     denominator = reduce(lambda x, y: x * y % mod, range(1, r + 1), 1)
#     return numerator * pow(denominator, mod-2, mod) % mod

class Combination:
    def __init__(self):
        self.fac = [None for _ in range(table_size)]
        self.finv = [None for _ in range(table_size)]
        self.inv = [None for _ in range(table_size)]

        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1

        for i in range(2, table_size):
            self.fac[i] = self.fac[i - 1] * i % mod
            # この逆元 (inv[i]) の計算は拡張ユークリッドの互除法をもとにしている
            # self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
            self.inv[i] = pow(i, mod - 2, mod)
            self.finv[i] = self.finv[i - 1] * self.inv[i] % mod

    def nCr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0

        return self.fac[n] * (self.finv[r] * self.finv[n - r] % mod) % mod


n, k = map(int, input().split())
# n, k = 3, 2  # Expected: 10
# n, k = 200000, 1000000000  # Expected: 607923868
# n, k = 15, 6  # Expected: 22583772

c = Combination()

k = min(k, n - 1)
total = 0
for i in range(k + 1):
    total += c.nCr(n - 1, i) * c.nCr(n, i)
    total %= mod

print(total)


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

char s[16];

int main(int argc, char *argv[]) {
  scanf("%s", s);
  int num_of_digits = 0;
  for(int i = 0; ; i++){
    if(s[i] < '0' || '9' < s[i]) {
      s[i] = 0;
      num_of_digits = i;
      break;
    }
    s[i] -= '0';
  }
  uint64_t grand_total = 0;
  for(int bits = 0; bits < (1 << (num_of_digits - 1)); bits++){
    uint64_t last_num = 0;
    for(int i = 0; i < num_of_digits; i++){
      last_num *= 10;
      last_num += s[i];
      if((bits & (1 << i)) == 0) continue;
      grand_total += last_num;
      last_num = 0;
    }
    grand_total += last_num;
  }
  std::cout << grand_total << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main (){
	int a,b,i,sum=0;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b);
		sum=sum+b;
	}
	printf("%d\n",sum-a);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main()
{
	int n;
	int ans;
	scanf("%d\n",&n);
	int d[n];
	rep(i,n){
	scanf("%d ",&d[i]);
	}
	
	
	ans = 0;
	
	rep(i,n){
		rep(j,n){
			ans += d[i]*d[j] ;
		}
	}
	
	
	rep(i,n){
		ans -= d[i]*d[i] ;
	}
	
	printf("%d",ans/2);
	
}

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

int main(){
    int d, g;
    cin >> d >> g;

    int p[d], c[d];

    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;

    for(int mask = 0; mask < (1 << d); mask++){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < d; i++){
            if(mask & (1 << i)){
                s = s + 100 * (i+1) * p[i] + c[i];
                num = num +  p[i];
            }else{
                rest_max = i;
            }
        }

        if(s < g){
            int s1 = 100 *(rest_max + 1);
            int need = (g - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num = num + need;
        }
        ans = min(ans, num);
    }

    printf("%d\n", ans);

    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 7;
int a[maxn], cnt[maxn];
priority_queue<pii> q1, q2;
int main(){
    #ifdef LOCAL
    freopen("a", "r", stdin);
    #endif // LOCAL
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i += 2){
        cnt[a[i]]++;
    }
    for(int i = 0; i < maxn; ++i){
        if(cnt[i]){
            q1.push((pii){cnt[i], i});
        }
    }
    q1.push((pii){0, 0});
    memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i < n; i += 2){
        cnt[a[i]]++;
    }
    for(int i = 0; i < maxn; ++i){
        if(cnt[i]){
            q2.push((pii){cnt[i], i});
        }
    }
    q2.push((pii){0, 0});
    pii top1 = q1.top();q1.pop();
    pii top2 = q2.top();q2.pop();
    if(top1.second != top2.second){
        printf("%d\n", n-top1.first-top2.first);
    }
    else if(top1.first + q2.top().first <= top2.first + q1.top().first){
        printf("%d\n", n-q1.top().first-top2.first);
    }
    else{
        printf("%d\n", n-top1.first-q2.top().first);
    }
}


Measured memory_bytes: 2168
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]

L = [[0 for j in range(w)] for i in range(h)]
R = [[0 for j in range(w)] for i in range(h)]
U = [[0 for j in range(w)] for i in range(h)]
D = [[0 for j in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        ri, rj = h-1-i, w-1-j
        if S[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
        if S[ri][rj] == '.':
            if rj == w-1:
                R[ri][rj] = 1
            else:
                R[ri][rj] = R[ri][rj+1] + 1
            if ri == h-1:
                D[ri][rj] = 1
            else:
                D[ri][rj] = D[ri+1][rj] + 1

ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)


Measured memory_bytes: 312456
import numpy as np

N = int(input())
A = [0] + list(map(int, input().split()))
S = np.cumsum(A, dtype=np.int64)

dp = np.zeros((N + 1, N + 1), dtype=np.int64)
for length in range(2, N + 1):
    for l in range(N - length + 1):
        r = length + l
        dp[l][r] = np.amin(dp[l, l + 1:r] + dp[l + 1:r, r]) + S[r] - S[l]
print(dp[0][N])


Measured memory_bytes: 18552
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num) - 1
    return cnt

while True:
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        exit()
    tmp = count(mid)
    if right - left <= 1:
        mid = right
        break
    elif tmp > K:
        left = mid
    else:
        right = mid

right = mid

while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    elif tmp == K:
        right = mid
    else:
        if left == mid:
            print(right)
            break
        left = mid
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        break

Measured memory_bytes: 31040
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
vote = [0]*(m+1)
for _ in range(n):
    like = list(li())
    
    for i in like[1:]:
        vote[i] += 1
        
ans = 0
for vi in vote:
    if vi == n:
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define F first
#define S second
#define pb push_back
#define bit __builtin_popcount
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mkp make_pair
#define ffs fflush(stdout)

using namespace std;
using namespace __gnu_pbds;

//order_of_key(k) : Number of items strictly smaller than k
//find_by_order(k) : K-th element in a set (counting from 0)

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef vector <int> lnum;
typedef pair <int, int> pii;

const int N = (int)1e6 + 5;
const int MOD = (int)1e8 + 7;
const int inf = (int)1e18;
const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const ld eps = 1e9 - 7;
const int pp[] = {29, 31, 31, 67, 71};
const double pi = acos(-1.0);

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

int h[N], p[N];

int n;
string s;

bool check(int x) {
  unordered_map <string, int> cnt;
  unordered_map <string, int> f;
  for (int i = 0; i < n; ++i) {
    if (i + x - 1 < n) {
      string t = s.substr(i, x);
      if (f[t] <= i) {
        ++cnt[t];
        if (cnt[t] > 1)
          return 1;
        else
          f[t] = i + x;
      }
    }
  }
  return 0;
}

signed main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  cin >> s;
  int l = 0, r = n, ans = 0;
  while (r >= l) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      l = mid + 1;
      ans = mid;
    }else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}


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

const int N=200010;
unordered_map<int,int> mp;
int a[N],n;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        mp[a[i]]++;
    }
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
        for(int p=30;p>=0;p--)
        {
            int x=(1<<p)-a[i];
            if(!mp.count(x)) continue;
            if(a[i]==x&&mp[x]<2) continue;
            if(mp[x]==0||mp[a[i]]==0) continue;
            ans++;mp[x]--;mp[a[i]]--;
            break;
        }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9288
#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 m, n;
	cin >> m >> n;

	vector<string> a(m);
	FOR(i,0,m) cin >> a[i];
	
	ll res = 0;
	FOR(si,0,m) FOR(sj,0,n) if (a[si][sj] == '.') {
		vvl dist(m,vl(n,oo));
		dist[si][sj] = 0;
		queue<pll> q;
		q.emplace(si,sj);
		
		ll cur = 0;
		while (sz(q)) {
			ll i, j;
			tie(i,j) = q.front();
			cur = dist[i][j];
			q.pop();
			FOR(di,-1,2) FOR(dj,-1,2) if (abs(di)+abs(dj) == 1) {
				ll ni = i+di, nj = j+dj;
				if (ni < 0 || ni >= m || nj < 0 || nj >= n) continue;
				if (a[ni][nj] == '#') continue;
				if (dist[ni][nj] < oo) continue;
				dist[ni][nj] = dist[i][j] + 1;
				q.emplace(ni,nj);
			}
		}
		res = max(res, cur);
	}
	cout << res << endl;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	vector<int> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << i + 1;
			return;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

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

int main(void) {
	char c[1001], end[1001];
	int i, j, n, sum;
	scanf("%s", c);
	strcpy(end, "0");
	while (strcmp(c, end)!=0)
	{
		sum=0;
		n=strlen(c);
		for (i=0; i<n; i++)
		{
			j=c[i]-'0';
			sum=sum+j;
		}
		printf("%d\n", sum);
		scanf("%s", c);
	}
	return 0;
}

Measured memory_bytes: 544
d=int(input())
c=list(map(int,input().split()))
last = [0] * 26
satis=0
for i in range(1,d+1):
  s=list(map(int,input().split()))
  decline=0
  for j in range(26):
    decline += c[j]*(i-last[j])
  exp=satis - decline + c[0]*(i-last[0]) + s[0]
  t=0
  for j in range(1,26):
    tmp = satis - decline + c[j]*(i-last[j])+s[j]
    if tmp > exp:
      t=j
      exp=tmp
  satis = exp
  print(t+1)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, r;
	cin >> n >> r;
	if(n < 10) r += (10 - n) * 100;
	cout << r << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, a, b, a_pos, b_pos;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (i == 0) {
      a = x;
      a_pos = 0;
    } else if (i == 1) {
      if (x > a) {
        b = a;
        b_pos = a_pos;
        a = x;
        a_pos = i;
      } else {
        b = x;
        b_pos = i;
      }
    } else {
      if (x > a) {
        b = a;
        b_pos = a_pos;
        a = x;
        a_pos = i;
      } else if (x > b) {
        b = x;
        b_pos = i;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d\n", ((i == a_pos) ? b : a));
  }
  return 0;
}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    N2=int(N**0.5)+5
    
    ans=0
    for i in range(1,N2):
        m=(N-i)//i
        if m*i+i==N:
            if i<m:
                ans+=m
                
    print(ans)

main()


Measured memory_bytes: 63844
#include <stdio.h>
int main()
{
  int n,m,i,d;
  int ans;
  scanf("%d %d", &n, &m);
  i = 0;
  ans = n;
  while(i < m)
  {
    scanf("%d", &d);
    ans -= d;
    i++;
  }
  if(ans < 0)
    printf("-1");
  else
    printf("%d", ans);
  return (0);
}

Measured memory_bytes: 1724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskDD solver = new TaskDD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskDD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int current = 1;
            int nb = 0;
            for (int i = 0; i < n; i++) {
                if (current == a[i]) {
                    current++;
                } else {
                    nb++;
                }
            }
            if (current == 1)
                out.println(-1);
            else
                out.println(nb);
        }

    }
}



Measured memory_bytes: 71140
// #include "../utils.cpp"
/*
Problem

Category
二分探索

URL:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=ja

考察:
再帰でやるか、候補を全列挙するか。


Date: 2020/04/11
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int n, q;
vector<int> S, T;
// vector<pair<int, int>> Q;


/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>n;
    S = vector<int>(n, 0);
    for(int i=0; i<n; ++i) {
        cin>>S[i];
    }
    cin>>q;
    T = vector<int>(q, 0);
    for(int i=0; i<q; ++i) {
        cin>>T[i];
    }
    
    
}

void solve() {
    // print(S, T);
    set<int> setS, setT;
    for(auto s: S) setS.insert(s);
    for(auto t: T) setT.insert(t);
    int cnt = 0;
    for(auto t: T) {
        if (setS.find(t) != setS.end()) cnt++;
    }
    cout<<cnt<<endl;
}





Measured memory_bytes: 10956
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int H, N;
	cin >> H >> N;
	ll total = 0;
	int t;
	rep(i, N) {
		cin >> t;
		total += t;
	}
	
	if (total >= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
} 

Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[10];
  int t;
}P;

void enqueue(P x);
P dequeue();
int min(int a, int b){return a < b ? a : b; }
P Q[LEN+1];
int head, tail, n;

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d", &n, &q);
  head = 1;
  tail = n + 1;
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }
  
  return 0;
}


void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1)%LEN;
  return x;
}

Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
//define
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007

string syugei(int N){
  string ST="b";
  for(int i=0;i<N;i++){
    if(i%3==0||i==0)ST="a"+ST+"c";
    else if(i%3==1||i==1)ST="c"+ST+"a";
    else if(i%3==2||i==2)ST="b"+ST+"b";
  }
  return ST;
}
// int hantei(string S){
//   for(int i=0;i<S.size(),i++){
//     for(int j=0;j<)
//   }
// }
//main
signed main(){
  int N,M,O,P,X,count=0,count2=0;
  double D=0;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>N>>M;
  for(int i=M-(N-1);i<M+N;i++){
    cout<<i<<endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}//continue break
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int r,g,b;cin>>r>>g>>b;
        int k;cin>>k;
        int c=0;
        while(g<=r){
            g=g*2;c++;
        }
        while(b<=g){
            b=b*2;c++;
        }
        if(c<=k){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3656
from collections import deque
def main():
  N=int(input())
  G=[[] for i in range(N)]
  ans=[]
  for i in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w%2])
    G[v-1].append([u-1,w%2])
  ans=[-1]*N
  finish=[0]*N
  q=deque([0])
  while q:
    now=q.pop()
    for i in G[now]:
      if finish[i[0]]==1:
        continue
      else:
        if i[1]%2==1:
          ans[i[0]]=-1*ans[now]
        else:
          ans[i[0]]=ans[now]
        finish[i[0]]=1
        q.append(i[0])
  for i in ans:
    print(i%2 if i == -1 else 0)#print(*ans)
main()

Measured memory_bytes: 42932
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,m,h,sum;
int tm[100000],drinknum[100000],drink[100000];
int main()
{
	scanf("%I64d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&tm[i]);
		sum=sum+tm[i];
	}
	scanf("%I64d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&drinknum[i],&drink[i]);
		h=sum-(tm[drinknum[i]]-drink[i]);
		cout<<h<<endl;
	}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long
const ll INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000 + 1000;


const int N = 1000 * 100 + 100;
int cnt[N];

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
    	int a, b;
    	cin >> a >> b;
    	cnt[a]++;
    	cnt[b]++;
    }

    for(int i = 1; i <= n; i++)
    	if(cnt[i] % 2 == 1){
    		cout << "NO\n";
    		return 0;
    	}
    cout << "YES\n";
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

c1 = 0
while True:
  c2 = 0
  for i in range(n):
    if a[i] % 2 == 0:
      a[i] /= 2
      c2 += 1
  
  if c2 == n:
    c1 += 1
  else:
    break
    
print(c1)

Measured memory_bytes: 9136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define all(arr) arr.begin(),arr.end()
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif 
#define unique(a)       sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);}
const int MOD = 1000000007;
using PII = pair<int, int>;
using LL = long long int;

template <typename T>
void input(vector<T> &arr,LL n) {
	T temp;
	for(LL i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
	T temp;
	for(auto x:arr) cout<<x<<" ";
	cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,LL n) {
	T temp;
	for(LL i=0;i<n;i++) cin>>temp, arr.insert(temp);
}


LL power(LL num,LL base) {
	if(base==0)
		return 1;

	if(base%2)
		return (num%MOD*power(num,base-1)%MOD)%MOD;
	else {
		LL x=power(num,base/2);
		x=(x*x)%MOD;
		return x;
	}
}
const int MM = 7;
int H, W, K;
int h[MM+1], w[MM+1];
char grids[MM+1][MM+1];
int ans = 0;
int tot = 0;

void fillHW() {
	for(int i = 1; i <= W; i++) {
		int cnt = 0;
		for (int j = 1; j <= H; j++) {
			cnt += grids[j][i] == '#';	
		}
		w[i] = cnt;
	}
	for(int i = 1; i <= H; i++) {
		 int cnt = 0;
		for (int j = 1; j <= W; j++) {
			cnt += grids[i][j] == '#';	
		}
		h[i] = cnt;
	}
}
int countOne(vector<int> rows, vector<int> cols) {
	int kk = 0;
	for (auto r : rows) kk += h[r];
	for (auto c : cols) kk += w[c];
	for (auto r : rows)  {
			for (auto c : cols) {
				kk -= grids[r][c] == '#';
			}
	}
	return tot - kk;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	cin>>H>>W>>K;
	for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
					cin>>grids[i][j];
					tot += grids[i][j] == '#';
			}
	}
	fillHW();
	for (int i = 0; i < 2 << H;  i++) {
		vector<int> rows;
		vector<int> cols;		
		for (int k = 0; k < H; k++) {
				if (i & (1 << k)) rows.push_back(k+1);
		}
  	for (int j = 0; j < 2 << W; j++) {
			cols.clear();
			for (int k = 0; k < W; k++) {
					if (j & (1 << k)) cols.push_back(k+1);
			}
			ans += countOne(rows, cols) == K; 
		}
	}
	cout<<ans/4<<endl;
	return 0;
}


Measured memory_bytes: 3648
<?php
$inputArray = array();
while (!feof(STDIN)) {
  $input = trim(fgets(STDIN));
  if (empty($input)) {
    break;
  }
  array_push($inputArray, $input);
}

$ening = array_shift($inputArray);

$outcount=0;
$diamond = 0;
$nowEning = 1;
foreach ($inputArray as $daseki) {
  if ($daseki == "HIT") {
    $diamond*=2;
    $diamond++;
  } else if ($daseki == "HOMERUN") {
    $diamond*=16;
    $diamond+=8;
  } else if ($daseki == "OUT") {
    $outcount++;
    if ($outcount > 2) {
      $diamond/=8;
      $point = substr_count(decbin($diamond), '1');
      echo $point . "\n";
      $diamond = 0;
      $outcount = 0;
      $nowEning++;
      if ($ening < $nowEning) {
        break;
      }
    }
  }
}

Measured memory_bytes: 15416
# frozen_string_literal: true

def read
  [gets.to_i, gets.chomp]
end

def solve(n, s)
  min = f = s.count('E')
  for i in 0...n
    f = f + if s[i] == 'W' then 1
            else -1
            end
    min = f if f < min
  end
  min
end

puts solve(*read)
# puts [
#   solve(5, 'WEEWW') == 1,
#   solve(12, 'WEWEWEEEWWWE') == 4,
#   solve(8, 'WWWWWEEE') == 3
# ].all?


Measured memory_bytes: 2436
#include <iostream>
#include <stdio.h>

using namespace std;

void swap(int *x, int *y)
{
    *y = *x + *y;
    *x = *y - *x;
    *y = *y - *x;
}

int main()
{
    int a, b, c, temp;

    cin >> a >> b >> c;
    if (a > b)
        swap(&a, &b);
    if (b > c)
        swap(&b, &c);
    if (a > b)
        swap(&a, &b);
    printf("%d %d %d\n", a, b, c);
}


Measured memory_bytes: 3200
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[fastout]
fn main() {
    input! {
        n:usize
    }
    let mut ans = 0_usize;
    for s in 1..n {
        ans += (n - 1) / s;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2192