akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, 2010 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

for i in range(K):
    print((cmb(K - 1, i, mod) * cmb(N - K + 1, N - K - i, mod)) % mod)


Measured memory_bytes: 3572
# ABC 143 D - Triangles
# https://atcoder.jp/contests/abc143/tasks/abc143_d

n = gets.chomp.to_i
l = gets.chomp.split(/ /).map(&:to_i).sort

class Stick
  def initialize(length, index)
    @length = length
    @index = index
  end

  attr_reader :length, :index
end

sticks = l.map.with_index(0) { |length, i| Stick.new(length, i) }

# puts sticks.inspect
# puts ""

count = 0
0.upto(n - 3) do |i|
  a = sticks[i]
  (i + 1).upto(n - 2) do |j|
    b = sticks[j]
    c_candidates = sticks[(j + 1)..(n - 1)]
    t = a.length + b.length
    c_over = c_candidates.bsearch { |stick| stick.length >= t }
    if c_over.nil?
      c_last_index = n - 1
    else
      c_last_index = c_over.index - 1
    end
    # puts "--------"
    # puts c_candidates.inspect
    # puts "a: #{a}, b: #{b}, a + b: #{t} -> #{c_last_index - j}"
    # puts ""
    count += c_last_index - j
  end
end

puts count


Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  for(int i=A;i<=B;i++){
    string s,s_;
    s = to_string(i);
    s_ = s;
    reverse(all(s_));
    if(s == s_) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  queue<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int> (w, -1));
  rep(i,h) {
    rep(j,w) {
      if(grid[i][j] == '#') {
        dist[i][j] = 0;
        que.push({i, j});
      }
    }
  }

  while(!que.empty()) {
    int vh = que.front().fi;
    int vw = que.front().se;
    que.pop();

    rep(dir, 4) {
      int nvh = vh + dy[dir];
      int nvw = vw + dx[dir];

      if(nvh < 0) continue;
      if(nvw < 0) continue;
      if(nvh >= h) continue;
      if(nvw >= w) continue;
      if(dist[nvh][nvw] != -1) continue;
      if(grid[nvh][nvw] == '#') continue;

      dist[nvh][nvw] = dist[vh][vw]+1;
      que.push({nvh, nvw});
    }
  }

  int res = -inf;
  rep(i,h) rep(j,w) res = max(res, dist[i][j]);

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 13456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);

    using Pi = pair< T, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
        auto next_cost = cost + e.cost;
        if(dist[e.to] <= next_cost) continue;
        dist[e.to] = next_cost;
        que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main(void) {
    int H, W;
    cin >> H >> W;

    WeightedGraph<int> g(10);
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            int cost;
            cin >> cost;
            g[i].emplace_back(j, cost);
        }
    }

    vector<int> distance(10);
    for(int i=0; i<10; i++) {
        distance[i] = dijkstra(g, i)[1];
    }

    int ans = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            int A;
            cin >> A;
            if(A != -1) {
                ans += distance[A];
            }
        }
    }

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


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

int main () {
	int h,w;
	while ( cin >> h >> w){
		if ( h == 0 && w == 0){
			break;
		}
		for ( int a = 0 ; a < w ; a++){
			cout << '#';
		}
		cout << endl;
		for ( int b = 2 ; b < h ; b++){
			cout << '#';
			for ( int c = 2 ; c < w ; c++){
				cout << '.';
			}
			cout << '#' << endl;
		}
		for ( int d = 0 ; d < w ; d++){
			cout << '#';
		}
		cout << endl << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100005];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	int cc=0;
	for (int i=1;i<=n;i++)
		if (a[i]>0){
			cc=i;
			break;
		}
	if (cc==1){
		printf("%lld\n",a[k]);
		return 0;
	}
	ll ans=500000000000000;
	int t=1,w=k;
	while (w<=n){
		ll sum=0;
		if (a[t]>0){
			sum=a[w];
			ans=min(ans,sum);
			break;
		}
		if (a[w]<0){
			sum=-a[t];
		}
	else{
		sum=-2*a[t]+a[w];
		ans=min(ans,sum);
		sum=-a[t]+2*a[w];
	}
		ans=min(ans,sum);
		t++;w++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] ss = new int[N];
   for(int i=0;i<N;i++)  ss[i] = sc.nextInt();
   
   int[] forans = new int[100001];
   for(int i=0;i<N;i++) forans[ss[i]]++;
   
   int tmp = forans[0]+forans[1]+forans[2];
   int max = tmp;
   for(int i=1;i<99999;i++)
   {
     tmp+=forans[i+2]-forans[i-1];
     if(tmp>max) max=tmp;
   }
   
   System.out.println(max);
 }
}

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

int main() {
	string s;cin>>s;
	int flag=1;
	for(int i=0;i<s.size();i++){
		if(s[i]!=s[s.size()-i-1]){
			flag=0;
		}
	}
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()/2-1-i]){
			flag=0;
		}
		if(s[s.size()/2+1+i]!=s[s.size()-1-i]){
			flag=0;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S,T = list(map(str, input().split()))
S_list = list(S)
T_list = list(T)
ans_list = list()
for i in range(N):
  ans_list.append(S_list[i])
  ans_list.append(T_list[i])
ans = ''.join(ans_list)
print(ans)

Measured memory_bytes: 3060
from bisect import bisect

N,K = map(int,input().split())
Ali = list(map(int,input().split()))
ans = 1
Ali.sort()
mod = 10**9+7

if K%2 == 1:
  ans = Ali.pop()
  K -= 1
  
Am = Ali[0:bisect(Ali,0)]
Ap = Ali[bisect(Ali,0):]

if ans>=0:
  Am.sort(reverse = True)
  Ap.sort()
else:
  Am.sort()
  Ap.sort(reverse = True)

mp = len(Am)-1
pp = len(Ap)-1

while K>0:
  mmax = -1
  pmax = -1
  if mp >= 1:
    mmax = Am[mp]*Am[mp-1]
  if pp >= 1:
    pmax = Ap[pp]*Ap[pp-1]
    
  if mmax == pmax == -1:
    ans *= Am[0]*Ap[0]
    print(ans%mod)
    exit()
    
  if mmax >= pmax:
    ans = ans * mmax % mod
    mp -= 2
    K -= 2
  else:
    ans = ans * pmax % mod
    pp -= 2
    K -= 2
  



print(ans%mod)

Measured memory_bytes: 105104
import sys

L, R = map(int, input().split())

if L <= 2019 and 2019 <= R:
    ans = 0

else:
    ans = 2019
    for i in range(L, R):
        for j in range(L+1, R+1):
            if (i % 2019 == 0) or (j % 2019 == 0):
                ans = 0
                print(ans)
                sys.exit()
            tmp = (i*j) % 2019
            if tmp <= ans:
                ans = tmp
print(ans)

Measured memory_bytes: 3060
def main():
    n,m=map(int,input().split())
    L=[list(input().split()) for _ in range(m)]
    AC=[0]*n
    WA=[0]*n
    for l in L:
        i = int(l[0])-1
        if AC[i]<1:
            if l[1]=='WA':
                WA[i] += 1
            else:
                AC[i]=1
    print(AC.count(1),sum([i*j for i,j in zip(AC,WA)]))
main()

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

int main(){

    int N;
    int fX = 0;
    cin >> N;
    int X = N;
    
    while(N){
        fX += N%10;
         N /= 10;
    }
    
    cout << (X%fX ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

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

  while(cin>>a>>b>>c,a||b||c){
    double len = min(a*a+b*b, min(a*a+c*c, b*b+c*c));
    int n;
    cin>>n;

    rep(i,n){
      double r;
      cin>>r;
      r *= 2;
      if(len >= r*r){
        cout<<"NA\n";
      }
      else{
        cout<<"OK\n";
      }
    }
  }
}

Measured memory_bytes: 0
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;

int main(int argc, char **argv)
{
	int i, n, r, rmin, prof;

	scanf("%d", &n);
	scanf("%d", &rmin);
	scanf("%d", &r);
	prof = r - rmin;
	if (rmin > r) rmin = r;

	for (i = 2; i < n; i++) {
		scanf("%d", &r);
		if ((r - rmin) > prof) {
			prof = r - rmin;
		}
		if (r < rmin) rmin = r;
	}
	printf("%d\n", prof);

	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = (1LL << 31) - 1;
const int MOD = (int)(1e9 + 7);

class RangeAddQuery {
public:
	int n;
	vector<int> d;
	int time;
	RangeAddQuery(int m) {
		for (n = 1; n < m; n *= 2);
		d.assign(n * 2, 0);
	}
	//[l, r)
	void add(int l, int r, int x) {
		for (; l && l + (l&-l) <= r; l += l&-l) 
			d[(n + l) / (l&-l)] += x;
		for (; l < r; r -= r&-r) 
			d[(n + r) / (r&-r) - 1] += x;
	}
	int get(int i) {
		int ret = d[n + i];
		for (int j = (n + i) / 2; j > 0; j >>= 1) 
			ret += d[j];
		return ret;
	}
};

signed main() {
	int n, q; cin >> n >> q;
	RangeAddQuery RAQ(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com == 0) {
			int s, t, x; cin >> s >> t >> x;
			RAQ.add(s, t + 1, x);
		}
		else {
			int i; cin >> i;
			cout << RAQ.get(i) << endl;;
		}
	}
	return 0;
}

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


#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);


signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        float ans = (float)(3.14)*(2*n);
        cout<<fixed<<setprecision(5)<<ans;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k < a){
        cout << k << endl;
    }else if(a <= k && k <= a+b){
        cout << a << endl;
    }else{
        cout << a - min(k-a-b,c) << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    char a;
    cin >> a;
    if(a<='Z') cout << 'A' << endl;
    if('a'<=a) cout << 'a' << endl;
}

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

using namespace std;

int main()
{
	int N;
	long long sum = 0;
	cin >> N;

	vector<int> A(3 * N);
	for (int i = 0;i < 3 * N;i++)
		cin >> A[i];

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

	for (int i = N;i < 3 * N;i += 2)
		sum += A[i];

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
using namespace std;
using LL=long long;

int N,W,w,v,ans,dp[1000005];

int main()
{
	scanf("%d%d",&N,&W);
	for(int j=1E6;j>0;j--)
		dp[j]=1E9+5;
	for(int i=1;i<=N;i++)
	{
		scanf("%d%d",&w,&v);
		for(int j=1E6;j>=v;j--)
			dp[j]=min(dp[j],dp[j-v]+w);
	}
	for(ans=1E6;ans>0&&dp[ans]>W;ans--);
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 4096
<?php

fscanf(STDIN, "%d %d %d", $a, $b, $c);

$x = ($a === $b) && ($a !== $c);
$y = ($a === $c) && ($a !== $b);
$z = ($b === $c) && ($b !== $a);

if ($x || $y || $z) {
    echo 'Yes';
} else {
    echo 'No';
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0;(i) < (ll)(n);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1;(i) >= 0LL;(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string text = "abc";
    ll abc[3] = { };
    string S;
    cin >> S;
    for(ll i = 0;i < S.size();i++) {
        ll index = text.find(S[i]);
        abc[index]++;
    }
    if(abs(abc[0] - abc[1]) <= 1 && abs(abc[2] - abc[1]) <= 1 && abs(abc[0] - abc[2]) <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * (n)
j = 1
tmpdp = 10 ** 9
for i in range(1,n):
  while i - j >= 0 and j <= k:
    if tmpdp > dp[i-j] + abs(h[i] - h[i-j]):
      tmpdp = dp[i-j] + abs(h[i] - h[i-j])
    j += 1
  dp[i] = tmpdp
  j = 1
  tmpdp = 10 ** 9

print(dp[-1])

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
void solve(void)
{
  int N;
  cin>>N;
  vector<int> W(N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>W[i];
  }
  for (int i = 0; i < N-1; i++)
  {
    W[i+1] += W[i];
  }
  // DEBUG(W);
  int ANS = INF;
  for (int i = 0; i < N-1; i++)
  {
    chmin(ANS,abs(W[N-1] - 2*W[i]));
  }
  
  
  
  cout<<ANS<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long long  n , m;
        cin >> n >> m;
        vector<long long>  v;
        v.assign(n+1 , 0);
        long  long a;
        for(int i = 0 ; i < m ; i++){
            cin >> a;
            v[a] = -1;
        }
        long mod = 1000000007;
        v[0] = 1;
        if(v[1] == 0) v[1] = 1;
        for(int i = 2 ; i <= n ; i++){
            if(v[i] == -1) {
                continue;
            }
            if(v[i-1] == -1 && v[i-2] == -1){
                v[i] = 0;
            }else if(v[i-2] == -1){
                v[i] = v[i-1];
            }else if(v[i-1] == -1){
                v[i] = v[i-2];
            }else{
                v[i] = (v[i-1] + v[i-2]) % mod;
            }
        }
        cout << v[n] << endl;
        
        return 0;
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int one[64];
int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];
	rep(i, N) {
		rep(j, 60) {
			if (a[i] >> j & 1) one[j]++;
		}
	}
	ll ans = 0;
	rep(i, 60) {
		int x = 0;
		rep(j, N) {
			if (a[j]>>i & 1) x++;
		}
		ll temp = x * (N-x) % MOD;
		rep(j, i) temp = temp * 2 % MOD;
		ans += temp;
		ans %= MOD;
	}
	cout << ans << endl;
}

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

using namespace std;


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

    S[K - 1] = S[K - 1] + 0x20;

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1000005;
const int mod=998244353;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)<0?x+mod:x;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
inline int Pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return res;
}
int n,a[max_n];
int main(){
    scanf("%d",&n);
    int ans=0;
    int mx=0;
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        ans=Sub(ans,x);
        a[x]++;
        mx=max(mx,x);
    }
    n=mx;
    for(int i=1;i<=n;i++)a[i]=Mul(a[i],i);
    for(int i=1;i<=n;i++){
        for(int j=i*2;j<=n;j+=i)a[i]=Add(a[i],a[j]);
    }
    for(int i=1;i<=n;i++)a[i]=Mul(a[i],a[i]);
    for(int i=n;i>=1;i--){
        for(int j=i*2;j<=n;j+=i)a[i]=Sub(a[i],a[j]);
    }
    for(int i=1;i<=n;i++){
        a[i]=Mul(a[i],Pow(i,mod-2));
        ans=Add(ans,a[i]);
    }
    ans=Mul(ans,Pow(2,mod-2));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4096
import pprint
H,W,K=map(int,input().split())
table=[list(input()) for _ in range(H)]
ans=[[0 for _ in range(W)] for _ in range(H)]
l= [0]*W
begin=0
end=0
cnt=1
while end<H:
    l2=[0]*W
    flag=0
    for i in range(W):
        l2[i]=l[i]
    for i in range(W):
        if (table[end][i]=="#")and(l[i]==1):
            l=l2
            flag=1
            break
        elif (table[end][i]=="#"):
            l[i]=1
    if flag==0:
        end=end+1
    else:
        lr=[]
        st=0
        for i in range(W):
            if l[i]==1:
                en=i+1
                lr.append([st,en])
                st=en
        lr[len(lr)-1][1]=W
        #print(begin,end,l,lr)
        for i in range(len(lr)):
            left=lr[i][0]
            right=lr[i][1]
            for j in range(begin,end):
                for k in range(left,right):
                    ans[j][k]=cnt
            cnt=cnt+1
        begin=end
        l=[0]*W
lr=[]
st=0
for i in range(W):
    if l[i]==1:
        en=i+1
        lr.append([st,en])
        st=en
lr[len(lr)-1][1]=W
#print(begin,end,l,lr)
for i in range(len(lr)):
    left = lr[i][0]
    right = lr[i][1]
    for j in range(begin, end):
        for k in range(left, right):
            ans[j][k] = cnt
    cnt = cnt + 1
for i in range(H):
    print(*ans[i])




Measured memory_bytes: 81068
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    checked = [1] * n
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        h_a = heights[a]
        h_b = heights[b]
        if h_a < h_b:
            checked[a] = 0
        elif h_a > h_b:
            checked[b] = 0
        else:
            checked[a] = 0
            checked[b] = 0

    return sum(checked)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 20048
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = str(sys.stdin.readline().rstrip())

R,G,B = 0,0,0

for c in S:
    if c == 'R':
        R+=1
    elif c == 'G':
        G+=1
    else:
        B+=1

ans = R*G*B

for j in range(N):
    for i in range(N):
        if j-i < 0 or j+i >= N:
            break
        elif S[j-i] != S[j] and S[j+i] != S[j] and S[j+i] != S[j-i]:
            ans-=1

print(ans)

Measured memory_bytes: 9264
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		WriteLine(I[0] * I[1] % 2 == 0 ? "No" : "Yes");
	}
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>

#define MAX_N 100000

long N;
long res=0, diff[MAX_N];

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        long a, b;
        std::cin >> a >> b;
        res -= b;
        diff[i] = a+b;
    }
    std::sort(diff, diff+N, std::greater< long >() );
    for (int i=0; i<N; ++i) {
        if ( i%2 == 0 ) res += diff[i];
    }
    std::cout << res << std::endl;
    return 0;
}


Measured memory_bytes: 1152
# 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# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
    L = int(input())
    print((L/3) ** 3)
if __name__ == "__main__":
    run()


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

using namespace std;
using ll = long long;


int main()
{
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 2, vector<ll>(2600)));
    dp[0][0][0] = 1;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= n; j++) {
            for(int k = 0; k <= 2500; k++) {


                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + a[i]] += dp[i][j][k];

            }
        }
    }


    vector<vector<ll>> ret = dp[n];
    ll sum = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= 2500; j++) {
            if(i * s == j) sum += ret[i][j];
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 58404
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string S;
	int K;
	cin>>S>>K;

	int c1=0;

	int i=0;

	while(S[i]=='1'){
		c1++;
		i++;
	}

	char ans='u';

	if(S.size()==1 || c1>=K)ans=S[0];

	else{
		REP(i,S.size()){
			if(S[i]!='1'){ans=S[i];break;}
			else continue;
		}
		if(ans=='u')ans='1';
	}

	cout<<ans<<endl;







	return 0;
}













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

int main() {
	int n;
	cin >> n;
	int tmp;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		while (tmp % 2 == 0) {
			cnt++;
			tmp /= 2;
		}		
	}
	cout << cnt;	
}

Measured memory_bytes: 256
n,k,*a=map(int,open(0).read().split())
d=[0]*41 #aの各桁の1の数の和
for i in range(n):
  for j in range(41):
    d[j]+=(a[i]>>j)&1
f=0
la=len(bin(max(a)))-2 #max(a)の桁数
lk=len(bin(k))-2 #kの桁数
b=[0]*41 #最適なX
#k以下の数で上桁からみる,kが1でXが0となったときXはそれより下桁は自由にとれる
#各桁1と0どちらが多いかでXの各桁を決める
for i in range(lk-1,-1,-1):
  if (k>>i)&1==1:
    if d[i]<n-d[i]:
      b[i]=1
    else:
      b[i]=0
      f=1
  if (k>>i)&1==0:
    if d[i]<n-d[i] and f==1:
      b[i]=1
    else:
      b[i]=0
ans=0
#答えはXの各桁の数,ではない方の数の個数の和
for i in range(max(lk,la)):
  ans+=(1<<i)*[d[i],n-d[i]][b[i]]
print(ans)

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

int main() {
  int N, K;
  cin >> N >> K;
  long long int ret = (4 * 1e18);
  vector<long long int> xs, ys;
  vector<pair<long long int, long long int>> ps;
  for (int i = 0; i < N; i++) {
    long long int x, y;
    cin >> x >> y;
    xs.push_back(x);
    ys.push_back(y);
    ps.push_back(make_pair(x, y));
  }

  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  sort(ps.begin(), ps.end());

  for (int xi = 0; xi < N; xi++) {
    for (int xj = xi + 1; xj < N; xj++) {
      for (int yi = 0; yi < N; yi++) {
        for (int yj = yi + 1; yj < N; yj++) {
          int cnt = 0;
          for (int k = 0; k < N; k++) {
            pair<long long int, long long int> p = ps[k];
            if (xs[xi] <= p.first && p.first <= xs[xj] && ys[yi] <= p.second &&
                p.second <= ys[yj]) {
              cnt++;
            }
          }
          if (cnt >= K) {
            ret = min((xs[xj] - xs[xi]) * (ys[yj] - ys[yi]), ret);
          }
        }
      }
    }
  }

  cout << ret << endl;
}


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

int main() {
  vector<string> ans = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
  int N;
  cin >> N;
  cout << ans.at(N % 10) << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
vector<int> Edge[110];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    while(cin >> a >> b){
        Edge[a].push_back(b);
        Edge[b].push_back(a);
        if(a == 0){
            if(Edge[1].size() % 2 == 0 || Edge[2].size() % 2 == 0){
                cout << "NG" << endl;
                rep(i, 110) Edge[i].clear();
                continue;
            }
            bool con = false;
            REP(i, 3, 101){
                if(Edge[i].size() % 2){
                    cout << "NG" << endl;
                    rep(i, 110) Edge[i].clear();
                    con = true;
                    continue;
                }
            }
            if(con) continue;
            cout << "OK" << endl;
            rep(i, 110) Edge[i].clear();
            continue;
        }
    }
    
}

Measured memory_bytes: 1220
N=int(input())
*A,=map(int,input().split())
A=A[::-1]
B=[0]*N

i=1
count=0
while count<N:
    if count%2==0:
        B[i-1]=A[count]
    else:
        B[-i]=A[count]
        i+=1
    count+=1

print(*B)

Measured memory_bytes: 30980
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int coin = 0;
		int day = 0;
		while (coin < C) {
			day++;
			coin += A;
			if (day % 7 == 0) {
				coin += B;
			}
			if (coin >= C) {
				break;
			}
		}
		System.out.println(day);
	}

}



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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int func(int n){
    if (n == 1) return 1;
    return n + func(n-1);
}

int main(){
    int N;
    cin >> N;
    cout << func(N) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define wrln cout<<'\n';
using namespace std;
const int N=1e3+100;
int cot[4]={0,1,0,-1},hang[4]={1,0,-1,0},k,dau,cuoi,n,m,xd,yd,ex,ey,res,z,c;
int kt[N][N],kt2[N][N],f[N*N];
pair <int,int> q[N*N];
char a[N][N];

void dfs(int x,int y)
{
    if (x<=0 || x>n || y<=0 || y>m || kt[x][y]>0 || a[x][y]!='.' ) return ;
    kt[x][y]=k;
    for (int i=0; i<=3; i++)
    {
        dfs(x+cot[i],y+hang[i]);
    }
}

void dfs2(int x,int y)
{
    if (x<=0 || x>n || y<=0 || y>m || kt2[x][y]>0 || a[x][y]!='.' ) return ;
    kt2[x][y]=z;
    for (int z=0; z<=3; z++)
    {
        for (int i=max(x-2,1); i<=x+2 && i<=n; i++)
        {
            for (int j=max(y-2,1); j<=y+2 && j<=m; j++)
            {
                if ( a[i][j]=='.' && kt[i][j]==0)
                {
                    ++k;
                    dfs(i,j);
                    f[k]=c+1;
                    q[++cuoi]={i,j};
                }
            }
        }
        dfs2(x+cot[z],y+hang[z]);
    }
}

void bfs(int x, int y)
{
    dau=cuoi=0;
    q[++cuoi]={x,y};
    ++k;
    dfs(x,y);
    f[k]=0;
    while (dau<=cuoi)
    {
        int x=q[++dau].fi; int y=q[dau].se;
        c=f[kt[x][y]];
        if (kt[ex][ey]>0)
        {
            res=f[kt[ex][ey]] ; return;
        }
        ++z;
        dfs2(x,y);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) ;
    cin>>n>>m;
    cin>>xd>>yd;
    cin>>ex>>ey;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            cin>>a[i][j];
        }
    bfs(xd,yd);
    if (kt[ex][ey]>0)
    cout<<res;
    else cout<<"-1";
}


Measured memory_bytes: 14544
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 998244353
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,a,b,k;

int fac[310000];

int inv(int x){
  if(x==1) return 1;
  return (M-M/x)*inv(M%x)%M;
}


int comb(int n,int k){
  int x=(fac[k]*fac[n-k])%M;
  return (fac[n]*inv(x))%M;
}

int fac_init(int n){
  fac[0]=1;
  FOR(i,1,n+1){
    fac[i]=fac[i-1]*i;
    fac[i]%=M;
  }
}


main(){
  init();
  cin>>n>>a>>b>>k;

 
  fac_init(n);

  int ans=0;
 

  rep(aa,n+1){
    int bb=k-aa*a;
    if(bb>=0&&bb%b==0&&bb/b<=n){
      ans+=comb(n,aa)*comb(n,bb/b);
      ans%=M;
    
    }
  }



  cout<<ans<<endl;
}


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

int main() {
	int a1;
	int a2;
	int a3;
	cin >> a1 >> a2 >> a3;
	if (a1 + a2 + a3 <= 21) {
		cout << "win" << endl;
	}
	else {
		cout << "bust" << endl;
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String str1 = sc.next();
    String str2 = sc.next();
    int a1 = sc.nextInt();
    int a2 = sc.nextInt();
    String str = sc.next();

    if (str.equals(str1)) {
      a1--;
    }
    if (str.equals(str2)) {
      a2--;
    }
    System.out.print(a1 + " " + a2);
    
  }
}


Measured memory_bytes: 22228
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int H,W;
  
    

    cin  >> H>>W;
    char grid[H][W];

    int left[H][W];
    int right[H][W];
    vector<string> S;
    FOR(i,H){
        string tmp;
        cin >>tmp;
        S.push_back(tmp);
        FOR(j,W){
            grid[i][j]=S[i][j];
            left[i][j]=0;
            right[i][j]=0;
        }
    }
    /*FOR(i,H){
        FOR(j,W){
            if(grid[i][j]=='#'){
                cout << "? ";
            }else{
                cout << "* ";
            }
        }
        cout <<endl;
    }*/
    FOR(i,H){

        int pointerL=0;
        int pointerR=0;
        while(pointerR<W){
            while(pointerR<W && grid[i][pointerR]=='#'){
                pointerR++;
            }
            pointerL=pointerR;
            while(pointerR<W && grid[i][pointerR]=='.'){
                pointerR++;
            }

            //cout << "debug pL:"<<pointerL << ",pR:"<<pointerR<<" ";

            int sm=pointerR-pointerL;
            for(int q=pointerL;q<pointerR;q++){
                left[i][q]=sm;
            }
            
            
        }
        

    }

    FOR(j,W){

        int pointerT=0;
        int pointerB=0;
        while(pointerB<H){
            while(pointerB<H && grid[pointerB][j]=='#'){
                pointerB++;
            }
            pointerT=pointerB;
            while(pointerB<H && grid[pointerB][j]=='.'){
                pointerB++;
            }
            int sm=pointerB-pointerT;
            for(int q=pointerT;q<pointerB;q++){
                right[q][j]=sm;
            }
            
        }
        

    }
    int max=0;
    FOR(i,H){
        FOR(j,W){
            //cout << left[i][j]<<","<<right[i][j]<<" ";
            int tmp=left[i][j]+right[i][j]-1;
            if(max<tmp){
                max=tmp;
            }
        }
        //cout <<endl;
    }
    int ans=max;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39424
k, n = list(map(int, input().split(' ')))
a_list = list(map(int, input().split(' ')))

max_gap = max([abs(a_list[i-1] - a_list[i]) for i in range(1, n)])
if max_gap < (a_list[0] + k - a_list[-1]):
    max_gap = a_list[0] + k - a_list[-1]
print(k - max_gap)


Measured memory_bytes: 26420
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
TAYA
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>


using namespace std;



#define ll long long
#define ld double
#define null NULL
#define prev prev228
#define index index228
#define left left228
#define right right228
#define hash hash228
#define y1 y1228
#define y0 y0228
#define firn(i, n) for (int i = 0; i < (int)n; ++i)
#define forn(i, n) for (int i = 1; i <= (int)n; ++i)
#define int long long

template<typename T> inline void uin(T &a, T b) {
    if (b < a) a = b;
}

template<typename T> inline void uax(T &a, T b) {
    if (b > a) a = b;
}


const int maxn = 100 * 1000 + 228, INF = 1e9 + 228;


bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second || (a.second == b.second && a.first > b.first);
}

bool comp(pair<int, int> a, pair<int, int> b) {
	return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
}

int dp[maxn][2];

signed main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector< pair<int, int> > cur;
	forn(i, m) {
		int a, b;
		cin >> a >> b;
		cur.push_back(make_pair(a, b - 1));
	}
	sort(cur.rbegin(), cur.rend(), comp);
	vector< pair<int, int> > v;
	int cur_r = INF;
	for (auto p : cur) {
		if (p.second < cur_r) {
			v.push_back(p);
			uin(cur_r, p.second);
		}
	}
	int sz = (int)v.size();
	sort(v.begin(), v.end(), cmp);
	forn(i, sz) {
		dp[i][0] = dp[i][1] = INF;
	}
	dp[0][0] = 0;
	forn(i, sz) {
		if (i > 1 && v[i - 2].first >= v[i - 1].first) {
			dp[i][0] = dp[i - 1][0];
		}
		int take = v[i - 1].first;
		int l = 0, r = i;
		while (r - l > 1) {
			int mid = (l + r) >> 1;
			if (v[mid - 1].second < take) l = mid;
			else r = mid;
		}
		dp[i][1] = min(dp[l][0], dp[l][1]) + 1;
	}
	cout << min(dp[sz][0], dp[sz][1]) << "\n";
	return 0;
}



// kek













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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; 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; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	vi a(n);
	int sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	sort(all(a));
	if(sum%10!=0){
		cout<<sum<<endl;
        return 0;
	}
	else{
		rep(i,n){
			if(a[i]%10!=0){
				cout<<sum-a[i]<<endl;
				return 0;
			}
		}
	}
	cout<<0<<endl;
}

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

int main(){
    string str;

    cin >> str;

    int counter = 0;

    if(str[0] == 'o') counter++;
    if(str[1] == 'o') counter++;
    if(str[2] == 'o') counter++;

    cout << 700 + 100 * counter << endl;

}

Measured memory_bytes: 256
s = input()
t = input()

dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]
dp[0][0] = 0

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+1)
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

ans = ''
i,j = len(s),len(t)

while i>0 and j>0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1]+ans
        i -= 1
        j -= 1
        
print(ans)

Measured memory_bytes: 120412
from collections import defaultdict

H, W, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
h = defaultdict(int)
for a, b in ab:
    for y in range(max([a - 2, 1]), min([a, H - 2]) + 1):
        for x in range(max([b - 2, 1]), min([b, W - 2]) + 1):
            h[(y, x)] += 1

ans = [0] * 10
for v in h.values():
    ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for a in ans:
    print(a)

Measured memory_bytes: 154488
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, a);
    IN(ll, b);
    IN(ll, c);
    ll d = c - a - b;
    YES(d > 0 and 4 * a * b < d * d);
}

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

#define INF (1<<30)

signed main(){
	long long n,m,v,p;	cin>>n>>m>>v>>p;
	vector<long long> A(n+1);	A[0]=INF;
	for(long long i=1;i<=n;i++)cin>>A[i];
	sort(A.begin(), A.end(), greater<>());
	A[0]=-1;

	long long L_Bound=A[p];

	long long OK=1, NG=n+1;
	while(NG-OK>1){
		long long mid=(OK+NG)/2;

		if(mid<=p)OK=mid;
		else if(A[mid]+m < L_Bound)NG=mid;
		else{
			long long tmp=0;
			for(long long i=0;i<n;i++){
				if(i<p || mid<i)tmp+=m;
				else{
					// p<=i<mid
					tmp+=A[mid]+m-A[i];
				}
			}

			if(tmp<m*v)NG=mid;
			else OK=mid;
		}
	}
	cout<<OK<<endl;


	return 0;
}


Measured memory_bytes: 1024