akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var mn=arr.shift().split(" ").map(Number);
var cnt=0;
for(var i=0;i<mn[0];i++){
   var str=arr.shift();
   if(i!=0)str=str.replace(/0/g,"a").replace(/1/g,"b").replace(/b/g,"0").replace(/a/g,"1");
   var ary=str.split(" ").map(Number);
   while(true){
      if(ary[0]==1){
         cnt++;
         ary.shift();
         if(ary.length==0)break;
         if(ary[0]==0)ary[0]=1;
         else ary[0]=0;
      }else if(ary[ary.length-1]==1){
         cnt++;
         ary.pop();
         if(ary.length==0)break;
         if(ary[ary.length-1]==0)ary[ary.length-1]=1;
         else ary[ary.length-1]=0;
      }else{
         ary.shift();
         if(ary.length==0)break;
         if(ary[0]==0)ary[0]=1;
         else ary[0]=0;
      }
   }
}
console.log(cnt);

Measured memory_bytes: 17284
def main():
    n = int(input())

    # 奇数の数列生成
    odd = [i for i in range(1, n+1, 2)]

    res = 0
    for i in odd:
        cnt = 0
        for j in range(1, i+1, 2):
            if i % j == 0:
                cnt += 1
        if cnt == 8:
            res += 1
    print(res)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  string u;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'B' && u.size() > 0) u.pop_back();
    else if (s[i] != 'B') u.push_back(s[i]);
  }
  cout << u << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

ll dp[510][510];
int flag[510][510];
int d[510][510];
int n,m,q;

ll ddpp(int l,int r){
    if (flag[l][r])return dp[l][r];
    flag[l][r]=1;
    if (l==r){
        dp[l][r]=d[l][l];
        return d[l][l];
    }
    else if (r==l+1){
        dp[l][r]=d[l][r]+ddpp(l+1,r)+ddpp(l,r-1);
        return dp[l][r];
    }
    else{
        dp[l][r]=d[l][r]+ddpp(l+1,r)+ddpp(l,r-1)-ddpp(l+1,r-1);
        return dp[l][r];
    }
}

int main() {
    cin>>n>>m>>q;
    memset(d,0,sizeof(d));
    rep(i,m){
        int l,r;
        cin>>l>>r;
        d[l][r]+=1;
    }
    ddpp(1,n);
    rep(i,q){
        int p1,q1;
        cin>>p1>>q1;
        cout<<dp[p1][q1]<<endl;
    }
    
    

    return 0;
}

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

using namespace std;

int main() {
  set<int> s;
  for (int i = 0; i < 3; ++i) {
    int x;
    cin >> x;
    s.insert(x);
  }

  if (s.size() == 2) puts("Yes");
  else puts("No");
  return 0;
}



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

int main(){
	double n;
	vector<double> vec;
	while(cin >> n){
		vec.push_back(n);
	}

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

	cout << *(vec.end() - 1) - *vec.begin() << endl;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;

ll n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen("input.in", "r", stdin);
    ///freopen("output.out", "w", stdout);
    cin >> n;
    vector <vector <ll>> dp (n + 1);
    for (ll i = 1; i <= n; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        dp[i] = {a, b, c};
    }
    for (ll i = 2; i <= n; ++i)
        for (ll j = 0; j < 3; ++j)
            dp[i][j] = max ({(j == 0 ? 0LL : dp[i][j] + dp[i - 1][0]),
                             (j == 1 ? 0LL : dp[i][j] + dp[i - 1][1]),
                             (j == 2 ? 0LL : dp[i][j] + dp[i - 1][2])});

    cout << max ({dp[n][0], dp[n][1], dp[n][2]}) << '\n';
    return 0;
}


Measured memory_bytes: 5760
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,K = map(int,input().split())

# anss = [0 for i in range(K)]
inserts = [[] for i in range(N)]
for i in range(N):
    inserts[i] = [int(i) for i in input().split()]


inserts.sort()
cnt = 0
for insert in inserts:
    cnt += insert[1]
    ans = insert[0]
    # print(cnt)
    if cnt >= K:
        break

print(ans)


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

#define MAX_N 110
#define MAX_V 100100
#define INF	(1<<30)

int dp[MAX_N][MAX_V];
int weight[100],value[100];

int main(){
	for(int i=0;i<MAX_N;i++){
		for(int j=0;j<MAX_V;j++) dp[i][j]=INF;
	}dp[0][0]=0;

	int N,W;	cin>>N>>W;
	for(int i=0;i<N;i++) cin>>weight[i]>>value[i];

	dp[0][0]=0;

	for(int i=0;i<=N;i++){
		for(int sumV=0;sumV<=MAX_V;sumV++){

			if(sumV-value[i]>=0){
				dp[i+1][sumV]=min ( dp[i+1][sumV], dp[i][sumV-value[i]] + weight[i]);
			}
			dp[i+1][sumV] = min(dp[i+1][sumV], dp[i][sumV]);

		}
	}

	int ans=0;
	for(int sumV=0;sumV<MAX_V;sumV++){
		if( dp[N][sumV]<=W) ans=sumV;
	}

	cout<<ans<<endl;






	return 0;
}


Measured memory_bytes: 43264
// https://atcoder.jp/contests/abc067/tasks/abc067_b

#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()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, k, sum = 0;
  vector<int> l;

  cin >> n >> k;

  REP(i, n)
  {
    int li;
    cin >> li;
    l.push_back(li);
  }

  sort(ALL(l), greater<int>());

  REP(i, k)
  {
    sum += l[i];
  }

  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
sys.setrecursionlimit(10**9)
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
#グラフの閉路検出だけ
def resolve():
    N,M=pin()
    gragh={(v+1):[] for v in range(N)}
    for i in range(M):
        a,b=pin()
        gragh[a].append(b)
        gragh[b].append(a)
    #print(gragh)#->ok
    heiro=dict()
    heiro2=set()
    def dfs(v_from,travel,prev=None):
        tra=list(travel)    
        for v_to in gragh[v_from]:
            #stoper
            if v_to==prev:
                #print("a")
                continue
            if v_to in(tra):#closed 
                dicset=set()
                f=0
                kyori=0
                for n,t in enumerate(tra):
                    if v_to==t:
                        f=1
                    if f==1:
                        kyori+=1
                        dicset.add(t)
                if len(dicset)>2:
                    dicset=frozenset(dicset)
                    heiro.setdefault(dicset,kyori)
                    #print(gragh[v_from],(prev,v_from,v_to),dicset,tra)
                    break
                continue
            #caller
            prev=v_from
            tra2=tra[:]
            tra2.append(v_to)  
            #print(tra,v_to) 
            dfs(v_to,tra2,prev)

        return
        
    dfs(1,[1])
    #print(heiro)
    for j in (heiro.keys()):
        temp=set(j)
        #print(temp)
        for k in temp:
            heiro2.add(k)
    #print(heiro2)
    seen=heiro2.copy()
    global ans
    def dfs2(f):
        global ans
        if  f in seen:return
        ans+=1
        seen.add(f)
        for t in gragh[f]:
            dfs2(t)
            
    ans=0        
    for i in range(1,N+1):
        if i in seen:continue
        dfs2(i)
    if len(heiro2)==0:ans-=1
    print(ans)    
#%%submit!
resolve()

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

int main(){
    ll N, M;
    cin >> N >> M;
    pair<int, int> num[100010];
    ll A[100010];
    ll B[100010];
    ll C[100010];
    for(ll i = 0;i < N;i++){
        cin >> A[i];
    }
    for(ll i = 0;i < M;i++){
        cin >> B[i] >> C[i];
        num[i] = make_pair(C[i], B[i]);
    }
    sort(A, A+N);
    sort(num, num+M);
    ll ans = 0;
    ll now = M-1;
    ll count = 0;
    for(ll i = N-1;count != N;i--){
        if(A[i] < num[now].first && num[now].second != 0){ans += num[now].first;num[now].second--;i++;}
        else ans += A[i];
        if(now != 0 && num[now].second == 0)now--;
        count++;
    }
    cout << ans;
}


Measured memory_bytes: 3328
L,R=map(int,input().split())
cnt=0
c=L//2019
d=R//2019+1
for i in range(c,d+1):
    if L<=2019*i<=R:
        cnt+=1
        break
if cnt==1:
    print(0)
else:
    ans=100000
    for i in range(L,R+1):
        for j in range(L,R+1):
            if i==j:
                continue
            else:
                if ans>i*j%2019:
                    ans=i*j%2019
    print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int table[64][100000];
int b[64];
int Abit[64][100000];
int shift[64];
int dim;


void dump(const vector<int>& look, const int N) {
    for (int i=0; i<look.size(); i++) {
        for (int j=0; j<N; j++) {
            cerr << table[i][j] << " ";
        }
        cerr << endl;
    }
}
int main() {
    int N;
    cin >> N;
    long long A[100000];
    for (int i=0; i<N; i++) cin >> A[i];

    long long allxor = 0;
    for (int i=0; i<N; i++) allxor ^= A[i];

    vector<int> look;

    {
        long long i = allxor;
        for (int step=0; step<64; step++, i/=2) {
            if (i%2 == 0) {
                look.push_back(step);
            }
        }
    }
    reverse(look.begin(), look.end());

/*
    for (auto a : look) {
        cerr << a << " ";
    } cerr << endl;
*/

    for (int i=0; i<N; i++) {
        long long x = A[i];
        int step = 0;
        while (x > 0) {
            if (x % 2 == 1) {
                Abit[step][i] = 1;
            }
            x /= 2;
            step++;
        }
    }
    
    {
        int dim = 0;
        for (int a: look) {
            for (int i=0; i<N; i++) table[dim][i] = Abit[a][i];
            b[dim] = 1;
            dim++;
        }
    }

    
    long long left = 0;
    int rank = 0;
    for (int level=0; level<look.size(); level++) {
        int idx = -1;
        for (int i=rank; i<N; i++) {
            if (table[level][i] == 1) {
                idx = i;
                break;
            }
        }
        if (idx == -1) { //ill
            if (b[level] == 0) {
                left |= 1LL << look[level];
            }
            continue;
        }
        // swap
        for (int i=0; i<look.size(); i++) {
            int tmp = table[i][rank];
            table[i][rank] = table[i][idx];
            table[i][idx] = tmp;
        }
        for (int i=0; i<look.size(); i++) {
            if (i == level) continue;
            if (table[i][rank] == 0) continue;
            for (int j=0; j<=N; j++) {
                table[i][j] ^= table[level][j];
            }
            b[i] ^= b[level];
        }
        left |= 1LL << look[level];
        rank++;

        //dump(look, N);
    }
    cout << left + (allxor ^ left) << endl;    
    return 0;
}



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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


auto solve() {
    int N;
    cin >> N;

    int SIZE = N * 2 + 10;

    vll sumC(SIZE, 0);
    vll sumM(SIZE, 0);
    vll sumBef(SIZE, 0);


    string S;
    cin >> S;
    S.reserve(N);

    REP(i, N) {
        sumC[i + 1] = sumC[i] + (int) (S[i] == 'C');
        sumM[i + 1] = sumM[i] + (int) (S[i] == 'M');
        sumBef[i + 1] = sumBef[i];
        if (S[i] == 'C')
            sumBef[i + 1] += sumM[i + 1];
    }
    FOR(i, N + 1, SIZE) {
        sumC[i] = sumC[i - 1];
        sumM[i] = sumM[i - 1];
        sumBef[i] = sumBef[i - 1];
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int k;
        cin >> k;

        ll res = 0;
        REP(i, N + 1) {
            if (S[i] == 'D') {
                ll diffC = sumC[i + k] - sumC[i];
                ll diffBef = sumBef[i + k] - sumBef[i];
                res += diffBef - diffC * sumM[i + 1];
            }
        }
        cout << res << endl;
    }

}

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

//    cout << solve() << endl;
    solve();
//REP(i,(int)1e6) cout << (char)('A' + (i % 26));
//cout <<endl;
    return 0;
}


Measured memory_bytes: 49180
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  char s[2][SIZE];
  ll dp[60][3][3] = {};
  
  scanf("%d",&n);

  for(int i=0;i<2;i++){
    scanf("%s",s[i]);
  }

  if(s[0][0] == s[1][0]){
    dp[0][0][0] = 1;
    dp[0][1][1] = 1;
    dp[0][2][2] = 1;
  }else{
    dp[0][0][1] = 1;
    dp[0][0][2] = 1;
    dp[0][1][0] = 1;
    dp[0][1][2] = 1;
    dp[0][2][0] = 1;
    dp[0][2][1] = 1;
  }
  
  for(int k=1;k<n;k++){

    for(int p=0;p<3;p++){
      for(int q=0;q<3;q++){
        for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
            bool flag = false;
            
            if(s[0][k-1] == s[0][k] && s[1][k-1] == s[1][k]){
              if(p == i && q == j && i != j) flag = true;

            }else if(s[0][k-1] == s[0][k]){
              if(p == i && q != j && i != j) flag = true;

            }else if(s[1][k-1] == s[1][k]){
              if(p != i && q == j && i != j) flag = true;

            }else if(s[0][k] == s[1][k]){
              if(p != i && q != j && i == j) flag = true;

            }else{
              if(p != i && q != j && i != j) flag = true;
            }

            if(flag){
              dp[k][i][j] = (dp[k][i][j] + dp[k-1][p][q])%mod;
            }
          }
        }
      }
    }
  }
  
  ll  ans = 0;

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      ans = (ans + dp[n-1][i][j])%mod;
    }
  }

  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
  int N;
  int M;
  scanf("%d%d",&N,&M);
  int A[N];
    int i,sum=0;

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    sum+=A[i];
  }
  int big=0,j;
    for(j=0;j<N;j++){
    if(sum<=4*M*A[j]){
      big++;
    }
  }
  
    if(big>=M){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int freq[27];
int main()
{
    string s;
    cin>>s;
    set<char>st;

    for(int i=0;i<s.length();i++)
    {
        st.insert(s[i]);
        freq[s[i]-'a']=1;
    }
    if(st.size()!=s.length())
    {
        cout<<-1<<endl;
        return 0;
    }
    if(s.length()!=26)
    {
        cout<<s;
        for(int i=0;i<26;i++)
        {
            if(freq[i]==0){cout<<(char)(i+97);break;}
        }

    }
    else
    {
        int ans;
        int min=10000;
        for(int i=s.length()-1;i>=0;i--)
        {
            for(int j=i+1;j<=s.length()-1;j++)
            {
                if(s[j]-'a'>s[i]-'a')
                {
                    if(min>s[j]-'a') min=s[j]-'a';
                }
            }
            if(min!=10000)
            {
                s[i]=(char)(min+97);
                ans=i;break;
            }
        }
        if(min==10000)
        {
            cout<<-1<<endl;
            return 0;
        }
        for(int i=0;i<=ans;i++)
            cout<<s[i];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
@ExperimentalStdlibApi
fun main(args: Array<String>) = abc163d()

@ExperimentalStdlibApi
fun abc163d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }

    val cSum = (0L..n).toList().scan(0L, Long::plus)

    val answer = (k..n + 1).map { (cSum.last() - cSum[cSum.lastIndex - it]) - cSum[it] + 1 }
        .fold(0L) { acc, l -> (acc + l) % MOD }

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

Measured memory_bytes: 59224
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  vector<bool> u(n, false);
  int ans = 0, res = 0;
  while (1) {
    if (res == 1) {
      cout << ans << endl;
      return 0;
    }
    else if (u[res]) {
      cout << -1 << endl;
      return 0;
    }
    u[res] = true;
    ans++;
    res = a[res];
  }


  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count=0;
  bool finished = true;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i < N; i++)
    cin >> A.at(i);
  while (finished){
    for (int i=0; i < N; i++){
      if(A.at(i) % 2 == 0)
        A.at(i) = A.at(i)/2;
      else{
        finished = false;
        break;
      }
    }
    if (finished)
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,j,N,sum=0,res=0,ans;
  cin>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  sum=accumulate(all(v),0LL);
  res=v[0];
  ans=abs(sum-res*2);
  rep1(i,N-1){
    res+=v[i];
    chmin(ans,abs(sum-res*2));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
h,w = map(int, input().split())
maze = [input() for i in range(h)]
route = [[0] * w for i in range(h)]
white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            white += 1
 
 
class MyStack:
    def __init__(self):
        self.stack = []
    def push(self, item_1, item_2):
        self.stack.append([item_1,item_2])
    def pop(self):
        result = self.stack.pop(0)
        return result[0],result[1]
 
 
def min_route():
    global h,w
    stack = MyStack()
    stack.push(1,1)
    route[0][0] = 0
    n = 0
    while len(stack.stack) >= 1:
        y,x = stack.pop()
        route_num = route[y-1][x-1] + 1
        if y != h:
            if maze[y][x-1] == '.' and route[y][x-1] == 0:
                stack.push(y+1,x)
                route[y][x-1] += route_num
        if y != 1:
            if maze[y-2][x-1] == '.' and route[y-2][x-1] == 0:
                stack.push(y-1,x)
                route[y-2][x-1] += route_num
        if x != w:
            if maze[y-1][x] == '.' and route[y-1][x] == 0:
                stack.push(y,x+1)
                route[y-1][x] += route_num
        if x != 1:
            if maze[y-1][x-2] == '.' and route[y-1][x-2] == 0:
                stack.push(y,x-1)
                route[y-1][x-2] += route_num
        if route[h-1][w-1]  != 0:
            return route[h-1][w-1]
        n += 1
    print(-1)
    exit()
 
ans = white - min_route() - 1
 
if ans < 0:
    print(-1)
else:
    print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    int ans = 0;
    int pre = 0;
    reverse(data.begin(),data.end());
    for (int i=0;i < N-1;i++) {
        if (data.at(i) <= data.at(i+1)) {
           pre++; 
        } else {
            pre = 0;
        }
        ans = max(ans, pre);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> arr(n);
  for(int i=1;i<=n;++i){
    int curr;cin>>curr;
    arr[curr-1] = i;
  }
  for(auto i:arr)cout<<i<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);


int H, W, K;
vector<vector<char>> c;

int main() {

    cin >> H >> W >> K;

    c.assign(H, vector<char>(W));

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

    int res = 0;
    
    for (int i = 0; i < (1 << H); i++) {
        for(int j = 0; j < (1 << W); j++) {

            int sum = 0;

            for (int k = 0; k < H; k++) {
                if (i & (1 << k)) continue;
                for(int l = 0; l < W; l++) {
                    if (j & (1 << l)) continue;
                    cerr << c[k][l] << endl;
                    if (c[k][l] == '#') sum++;
                }
            }

            cerr << i << " " << j << " " << sum << endl;
            if (sum == K) res++;
        }
    }

    cout << res << endl;
    

    return 0;
}

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

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


const int mx = 1e6 + 9;

ll f[mx];

ll ncr(ll n, ll r) {
    return modDiv(f[n], modMul(f[r], f[n - r]));
}

ll total_path(ll r, ll c) {
    return ncr(r + c - 2, r - 1);
}

int main() {
    f[0] = 1;
    for (int i = 1; i < mx; i++) f[i] = modMul(i, f[i - 1]);
    ll h, w, a, b; cin >> h >> w >> a >> b;
    ll ttl = 0;

    for (ll i = 1; i <= h - a; i++) {
        ll temp = modMul(total_path(i, b), total_path(h - i + 1, w - b));
        ttl = modAdd(ttl, temp);
    }

    cout << ttl << endl;
}

Measured memory_bytes: 11416
#include <iostream>
#include <algorithm>
using namespace std;
int a,b,c,cnt;
int main(void){
    cin>>a>>b>>c;
    for(;!(a==b&&b==c);){
        ++cnt;
        if(a<=b&&a<=c){
            ++a;
        }else if(b<=a&&b<=c){
            ++b;
        }else if(c<=a&&c<=b){
            ++c;
        }
        if(a<=b&&a<=c){
            ++a;
        }else if(b<=a&&b<=c){
            ++b;
        }else if(c<=a&&c<=b){
            ++c;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (c < a) {
                System.out.printf("%d %d %d\n", c, a, b);
            } else {
                System.out.printf("%d %d %d\n", a, c, b);
            }
        } else {
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else if (c < b) {
                System.out.printf("%d %d %d\n", c, b, a);
            } else {
                System.out.printf("%d %d %d\n", b, c, a);
            }
        }
    }
}


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

int main(){
  int n,ans=0,j=1,c=0;cin>>n;
  vector<int> a(n+1,0),f(n+1,0);
  REP(i,n) cin>>a.at(i+1);
  
  while(!f.at(j)){
    f.at(j)=1;
    if(a.at(j)==2){
      cout<<c+1;
      return 0;
    }else{
      j=a.at(j);
      c++;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int p=1e9+7;
int n,f[100005],g[100005],sf[100005],sg[100005],lf[100005],lg[100005];
int prf[100005],prg[100005];
long long A,B,a[100005];
int main()
{	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	f[1]=sf[1]=g[1]=sg[1]=lf[1]=lg[1]=1;
	prf[1]=prg[1]=0;
	for(int i=2;i<=n;i++)
	{	if(a[i]-a[i-1]<A)lf[i]=i;else lf[i]=lf[i-1];
		if(a[i]-a[i-1]<B)lg[i]=i;else lg[i]=lg[i-1];
		prf[i]=prf[i-1],prg[i]=prg[i-1];
		while(a[i]-a[prf[i]+1]>=A)++prf[i];
		while(a[i]-a[prg[i]+1]>=B)++prg[i];
		int x=min(i-1,prf[i]+1);
		if(x>=lg[i-1])f[i]=(sg[x]-sg[lg[i-1]-1]+p)%p;
			else f[i]=0;
		x=min(i-1,prg[i]+1);
		if(x>=lf[i-1])g[i]=(sf[x]-sf[lf[i-1]-1]+p)%p;
			else g[i]=0;
		sf[i]=(sf[i-1]+f[i])%p;
		sg[i]=(sg[i-1]+g[i])%p;
	}
	int ac=((sg[n]-sg[lg[n]-1]+p)%p+(sf[n]-sf[lf[n]-1]+p)%p)%p;
	printf("%d\n",ac);
	return 0;
}

Measured memory_bytes: 4096
n = gets.to_i
boder = gets.to_i
fir = gets.to_i
fin = gets.to_i
arr = Array.new(n)
a = [boder,n].min
a.times do |i|
  arr[i] = fir
end
puts arr.inject(0){|sum,i|sum += !i.nil? ? i : fin}

Measured memory_bytes: 3836
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    D, T, S = map(int, input().split())
    if S * T < D:
        print('No')
    else:
        print('Yes')


if __name__ == "__main__":
    run()

Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll ans=0;
  for(int i=0;i<n;i++){
    ans^=(a[i]-1)%(d+1);
  }
  if(ans==0) cout<<"Second"<<endl;
  else cout<<"First"<<endl;
  return 0;
}



Measured memory_bytes: 4020
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI t(N+1),x(N+1),y(N+1);
		t.PB(0);x.PB(0);y.PB(0);
		RANGE(i, 1, N+1) cin>>t[i]>>x[i]>>y[i];
		bool ok=1;
		RANGE(i, 1, N+1) {
			if(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])>t[i]-t[i-1]) ok=0;
			if(( (x[i-1]+y[i-1])%2 ^ (t[i]-t[i-1])%2) != (x[i]+y[i])%2) ok=0;
		}
		
		cout<<YN(ok)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<assert.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fd(i,b,a) for(int i=(b);i>=(a);--i)
#define bfo(i,v,u) for(int i=BB[v],u=B[i][1];i;u=B[i=B[i][0]][1])
using namespace std;
typedef long long ll;
int read(){int n=0,p=1;char ch;for(ch=getchar();ch<'0' || ch>'9';ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=2e5+5;
int n,S,B0,BB[N],B[N<<2][2],d0[N],d1[N],ans[N];
void link(int u,int v){B[++B0][1]=v,B[B0][0]=BB[u],BB[u]=B0;}
bool ban[N<<2];
void dfs(int v)
{
	for(int i=BB[v],u=B[i][1];i;i=BB[v],u=B[i][1])
	{
		BB[v]=B[i][0];
		if(ban[i]) continue;
		ban[i]=ban[i^1]=1;
		dfs(u);
		if(u==v+n) ans[v]=1;
		if(v==u+n) ans[u]=-1;
	}
}
int main()
{
	n=read();S=n+n+1;
	B0=1;
	fo(i,1,n)
	{
		int x=read();
		if(x==-1) link(S,i),link(i,S),++d0[i];
		else link(x,i),link(i,x),++d0[i],++d0[x];
	}
	fo(i,1,n)
	{
		int x=read();
		if(x==-1) link(S,n+i),link(n+i,S),++d1[i];
		else link(n+x,n+i),link(n+i,n+x),++d1[i],++d1[x];
	}
	fo(i,1,n)
		if((d0[i]+d1[i])&1) return puts("IMPOSSIBLE"),0;
		else
		if(d0[i]&1) link(i,n+i),link(n+i,i);
	puts("POSSIBLE");
	dfs(S);
	fo(i,1,n) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 18048
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll k;
    string s;
    set<string> v;
    cin>>s>>k;
    rep(l,1,6){
        rep(i,0,s.size()){
            v.insert(s.substr(i,l));
        }
    }
    auto it = v.begin();
    rep(i,0,k-1) it++;
    cout<<*it<<endl;
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if(b <= c){
        ans += b * 2;
        c -= b;

        if(a > c) ans += c;
        else if(a == c) ans += c;
        else if(a < c) ans += a + 1;
        
    }
    else{
        ans += b + c;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)

const int INF = 1001001001;

void solve(){
  int h, n; cin >> h >> n;
  vector<int> dp(h+1, INF);
  dp[0] = 0;
  rep(i, n) {
    int a, b; cin >> a >> b;
    rep(j, h+1) {
      int bj = max(0, j-a);
      dp[j]=min(dp[j], dp[bj]+b);
    }
  }

  cout << dp[h] << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(list(input()))

    c_h = []
    c_w = []

    for i in range(h):
        flag = False
        for j in range(w):
            if a[i][j] == '#':
                flag = True
                break
        
        if flag:
            c_h.append(i)

    for i in range(w):
        flag = False
        for j in range(h):
            if a[j][i] == '#':
                flag = True
                break
        if flag:
            c_w.append(i)

    new_a = []

    if len(c_h) == 0:
        if not len(c_w) == 0:

            for i in range(h):
                temp = []
                for j in c_w:
                    temp.append(a[i][j])
                new_a.append(temp)

    elif len(c_w) == 0:
        if not lne(c_h) == 0:

            for i in range(w):
                temp = []
                for j in c_h:
                    temp.append(a[j][i])
                new_a.append(temp)

    elif not(len(c_h) == 0 or len(c_w) == 0):
        for i in c_h:
                temp = []
                for j in c_w:
                    temp.append(a[i][j])
                new_a.append(temp)
    
    else:
        pritn()
        return 0


    for i in new_a:
        print(''.join(i))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 66900
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n+2);
  a[0] = a[n+1] = 0;
  re(i, n) std::cin >> a[i+1];
  ll s = 0;
  for(int i=1;i<=n+1;i++) s+=abs(a[i]-a[i-1]);
  for(int i=1;i<=n;i++){
    ll pre = abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]);
    ll to = abs(a[i+1] - a[i-1]);
    std::cout << s - (pre-to) << '\n';
  }
  return 0;
}


Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(200001)

N, M = [int(n) for n in input().split()]
S = input()

p1 = False
x1 = 0
m1 = N
c1 = 0
for n in S:
    if n == "1":
        if p1:
            c1 += 1
        else:
            c1 = 1
            p1 = True
    else:
        p1 = False
        if c1 > 0:
            if c1 > x1:
                x1 = c1
            if c1 < m1:
                m1 = c1
           
def rest(l, ans):
    s = M
    while s > 0:
        if s >= l:
            ans.append(l)
            return ans
        if S[l-s] == "1":
            if s == 1:
                return -1
            s -= 1
            continue
        l -= s
        if rest(l, ans) == -1:
            s -= 1
        else:
            ans.append(s)
            return ans
    return -1

if x1 > M - 1:
    ans = -1
else:
    ans = rest(N, [])

if ans == -1:
    print(-1)
else:
    print(" ".join([str(n) for n in ans]))

Measured memory_bytes: 89028
# coding:utf-8

NM = raw_input().split()
N = int(NM[0])
M = int(NM[1])

a = []
b = []
c = []
d = []
for i in xrange(N):
    ab = raw_input().split()
    a.append(int(ab[0]))
    b.append(int(ab[1]))

for i in xrange(M):
    cd = raw_input().split()
    c.append(int(cd[0]))
    d.append(int(cd[1]))

for i in xrange(N):
    memo = []
    for j in xrange(M):
        memo.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
    print memo.index(min(memo)) + 1


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

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int l[n];
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);

    ll ans = 0;
    rep(i, 0, n) rep(j, i + 1, n) rep(k, j + 1, n) {
        if (l[k] < l[i] + l[j]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int N, K, h[100005];

int main(void) {

	cin >> N >> K;

	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (h[i] >= K) { ans++; }
	}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
    #ifdef LOCAL
        freopen("A.txt","r",stdin);
    #endif
    buf[fread(buf,1,MAXSIZE,stdin)]='\0';
    bufpos=0;
}
#if NEG
int readint(){
    bool isneg;
    int val=0;
    for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
    bufpos+=(isneg=buf[bufpos]=='-');
    for(;isdigit(buf[bufpos]);bufpos++)
        val=val*10+buf[bufpos]-'0';
    return isneg?-val:val;
}
#else
int readint(){
    int val=0;
    for(;!isdigit(buf[bufpos]);bufpos++);
    for(;isdigit(buf[bufpos]);bufpos++)
        val=val*10+buf[bufpos]-'0';
    return val;
}
#endif
char readchar(){
    for(;isspace(buf[bufpos]);bufpos++);
    return buf[bufpos++];
}
int readstr(char* s){
    int cur=0;
    for(;isspace(buf[bufpos]);bufpos++);
    for(;!isspace(buf[bufpos]);bufpos++)
        s[cur++]=buf[bufpos];
    s[cur]='\0';
    return cur;
}
int myabs(int x){
    return x>0?x:-x;
}
int main(){
    init();
    int n=readint();
    int l=0,xl=0,yl=0;
    while(n--){
        int t=readint(),x=readint(),y=readint();
        if ((x^xl^y^yl^t^l)&1)
            return puts("No"),0;
        if (myabs(x-xl)+myabs(y-yl)>t-l)
            return puts("No"),0;
        l=t,xl=x,yl=y;
    }
    puts("Yes");
}

Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1 << 25;
const int MAX_V = 30 * 30;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;

void dijkstra(int s) {
	fill(d, d + V, INF);
	fill(used, used + V, false);
	d[s] = 0;

	while(true) {
		int v = -1;
		for(int u = 0; u < V; u++) {
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}
		if(v == -1) break;

		used[v] = true;
		for(int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}
int main() {
	int n, m, s, g, money, pillar;
	scanf("%d %d", &n, &m);
	V = n;

	for(int i = 0; i < V; i++) {
		for(int j = 0; j < V; j++) {
			cost[i][j] = (i == j) ? 0 : INF;
		}
	}
	for(int i = 0; i < m; i++) {
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		a--, b--;
		cost[a][b] = c;
		cost[b][a] = d;
	}
	scanf("%d,%d,%d,%d", &s, &g, &money, &pillar);
	s--, g--;
	int sum = pillar;
	dijkstra(s);
	sum += d[g];
	dijkstra(g);
	sum += d[s];
	printf("%d\n", money - sum);
}

Measured memory_bytes: 1080
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    int n, a, b, c, d, ans;
    pair<int, int> ap, bp, cp, dp;
    cin >> n;
    cin >> a >> b;
    cin >> c >> d;
    ans = 10000000;
    for (int i = 1; i < n; ++i) {
        int grid[100][100] = {0};
        int count = 1;
        // cout << "-------" <<endl;
        for (int y = 0; y < i; ++y) {
            for (int x = 0; x < n - i + 1; ++x) {
                if (count > n) break;
                grid[x][y] = count;
                // cout << count << " ";
                if (a == count) ap = make_pair(x, y);
                if (b == count) bp = make_pair(x, y);
                if (c == count) cp = make_pair(x, y);
                if (d == count) dp = make_pair(x, y);
                count++;
            }
            // cout << endl;
        }
        // printf("a:(%d, %d) b:(%d, %d)\n", ap.first, ap.second, bp.first, bp.second);
        // printf("tmp: %d\n", abs(ap.first - bp.first) + abs(ap.second - bp.second) 
        //         + abs(cp.first - dp.first) + abs(cp.second - dp.second));
        ans = min(ans, abs(ap.first - bp.first) + abs(ap.second - bp.second) 
                + abs(cp.first - dp.first) + abs(cp.second - dp.second));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3080
n = int(input())
ans = 0
def factorize(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.append(n)
    return divisors

def check(num, mod):
    if num % mod == 1:
        return 1
    elif num % mod == 0:
        num = num / mod
        return check(num, mod)
    else:
        return 0


nfct = factorize(n)
n_1fct = factorize(n - 1)
if n_1fct != [1]:
  ans += len(n_1fct)
for mod in nfct:
  ans += check(n,mod)
print(ans)


Measured memory_bytes: 3188
n, m = map(int, input().split())
list_a = list(map(int, input().split()))
list_a.sort()
dict_c = {}
for i in range(m):
    b, c = map(int, input().split())
    if(c in dict_c):
        dict_c[c] += b
    else:
        dict_c[c] = b
keys_c_sorted = [0]
for i in sorted(dict_c):
    keys_c_sorted.append(i)
sum_a = 0
for i in list_a:
    if(keys_c_sorted[-1] > i):
        sum_a += keys_c_sorted[-1]
        if(dict_c[keys_c_sorted[-1]] == 1):
            keys_c_sorted.pop()
        else:
            dict_c[keys_c_sorted[-1]] -= 1
    else:
        sum_a += i
print(sum_a)

Measured memory_bytes: 23412
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  $m = 1000000007;
  for($i=1; $i<=$k; $i++){
    $ans = combination($n-$k+1, $i, $m) * combination($k-1, $i-1, $m) % $m;
    echo $ans.PHP_EOL;
  }


/**
 * mod Pの世界での繰り返し二乗法
 * @param $b 基数
 * @param $p 指数
 * @param $m 素数
 */
function repeatSqrt($b, $p, $m){
  if($p==1)
  {
    return $b;
  }
  else if($p%2 == 0)
  {
    $t = repeatSqrt($b, floor($p/2), $m);
    return ($t * $t) % $m;
  }
  else
  {
    return ($b * repeatSqrt($b, $p-1, $m)) % $m;
  }
}

/**
 * mod Pの世界での組み合わせ(nCa)
 * @param $n 全体の数
 * @param $a 選択する数
 * @param $m 素数
 */
function combination($n, $a, $m)
{
    $x=1; // bunbo
    $y=1; // bunshi
    for($i=0;$i<$a;$i++)
    {
        $x=$x*($n-$i)%$m;
        $y=$y*($i+1)%$m;
    }
    // フェルマーの小定理 
    // Y^(P-1)≡1 (mod P) より
    // Y^(P-2)≡1/Y (mod P)
    // つまり
    // $x / $y = $x * $y^($m-2) (mod P)
    $y=repeatSqrt($y, $m-2, $m);
    return ($x*$y)%$m;
}

Measured memory_bytes: 4604
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	dijkstra
# CreatedDate:  2020-07-07 00:05:59 +0900
# LastModified: 2020-07-07 00:27:43 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
import heapq


def main():
    V, E, r = map(int, input().split())
    distance = [float("inf")]*V
    distance[r] = 0
    path = [[] for _ in range(V)]
    for _ in range(E):
        s, t, d = map(int, input().split())
        path[s].append([d, t])
    Q = [[0, r]]
    while Q:
        _, u = heapq.heappop(Q)
        for dis, v in path[u]:
            if distance[u]+dis < distance[v]:
                distance[v] = distance[u]+dis
                heapq.heappush(Q, [dis, v])
    distance = [dis if dis != float("inf") else "INF" for dis in distance]
    for dis in distance:
        print(dis)


if __name__ == "__main__":
    main()



Measured memory_bytes: 116900
h,n=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
maxmp=pow(10,8)
dp=[maxmp]*(h+10000) # dp[i]:ダメージをぴったりi与えるのに必要な最小魔力
dp[0]=0
for i in range(h+10000):
  b=[dp[i-a]+b for a,b in ab if i-a>=0]
  dp[i]=min(dp[i],min(b)) if b else dp[i]
print(min(dp[h:]))


Measured memory_bytes: 47236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int mn=2e5+10;
vector<int>ix[mn],iy[mn];
int x[mn],y[mn];
bool vis[mn];
ll tot;
set<int>sx,sy;
void dfs(int n){
    vis[n]=1;
    sx.insert(x[n]);
    sy.insert(y[n]);
    for(int k:ix[x[n]])if(!vis[k])dfs(k);
    for(int k:iy[y[n]])if(!vis[k])dfs(k);
}
int main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",x+i,y+i);
        ix[x[i]].push_back(i);
        iy[y[i]].push_back(i);
    }
    for(i=0;i<n;i++){
        if(!vis[i]){
            dfs(i);
            tot+=sx.size()*sy.size();
            sx.clear();
            sy.clear();
        }
    }
    printf("%lld",tot-n);
}

Measured memory_bytes: 21376