akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>
using namespace std;
using ll = long long;
 
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
 
// nCrはO(k)で求まる
mint ncr(ll n, ll k) {
  mint a = 1, b = 1;
  for (int i = 0; i < k; i++) a *= n - i;
  for (int i = 1; i <= k; i++) b *= i;
  return a / b;
}
 
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  // 二項係数の和をもし知らなくても、制約みて間に合わそう、だからいい方法ないかな？という考え方を身につける。
  auto ans = mint(2).pow(n) - ncr(n, a) - ncr(n, b) - 1;
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long X = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		long D = long.Parse(str[2]);
		long ans = 0;
		if(Math.Abs(X)>=Math.Abs(K*D)){
			ans = Math.Abs(X) - Math.Abs(K*D);
		} else {
			long ct = Math.Abs(X) / Math.Abs(D);
			long a1 = Math.Abs(X) - ct * Math.Abs(D);
			if((K-ct)%2==0){
				ans = a1;
			} else {
				ans = D - Math.Abs(a1);
			}
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 17928
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, y;
    cin >> n;
    vector <int> a(n);
    for (auto &i : a) {
        cin >> x >> y;
        i = x == y;
    }
    for (int i = 2; i < n; i++) {
        if (a[i] && a[i - 1] && a[i - 2]) {
            cout << "Yes\n";
            rr;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
int d[10]={};
int P[10];
int Q[10];
int N;
int a,b;
int sw[10];
int c=0;
void perm(int T){
  if(T>N){
    int ps=1,qs=1;
    for(int i=1;i<=N;i++){
      if(P[i]!=d[i]) ps=0;
      if(Q[i]!=d[i]) qs=0;
    }
    c++;
    if(ps==1) a=c;
    if(qs==1) b=c;
  }else{
    for(int i=1;i<=N;i++){
      if(sw[i]!=1){
        d[T]=i;
        sw[i]=1;
        perm(T+1);
        sw[i]=0;
      }
    }
  }
}
int main(){
  scanf("%d\n",&N);
  for(int i=1;i<=N;i++)
    scanf("%d\n",P+i);
  for(int i=1;i<=N;i++)
    scanf("%d\n",Q+i);
  for(int i=1;i<=N;i++)
    sw[i]=0;
  perm(1);
  printf("%d\n",a>=b?a-b:b-a);
  return 0;
}

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

int main() {
    int N,m=0,r=0;
    cin >> N;
    vector<int> h(N);
    rep(i,N) {
        cin >> h.at(i);
        m = max(m, h.at(i));
    }
    
    rep(j,m) {
        bool c=0;
        int t=m-j;
        rep(i,N) {
            if(!c && h.at(i)>=t)
                r++, c=1;
            else if(c && h.at(i)<t)
                c=0;
        }
    }

    cout << r << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    s = input()
    _q = int(input())
    
    for k in map(int,input().split()):
        res = 0
        p = 0
        cnt = 0
        q = 0
        for i in range(n):
            if i >= k:
                if s[i-k] == 'D':
                    cnt -= 1
                    p -= q
                elif s[i-k] == 'M':
                    q -= 1

            if s[i] == 'D':
                cnt += 1
            elif s[i] == 'M':
                p += cnt
                q += 1
            elif s[i] == 'C':
                res += p
        print(res)

if __name__ == '__main__':
    main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import heapq
class Prim():
    """
    ・無向辺
    ・負のコストがあっても大丈夫？
    ・計算量はO(E log|V|)　
    ・heapを使う
    """
    
    class Edge():
        #重み付き有向辺（あとで往復させる）
        
        def __init__(self, _to, _cost):
            self.to =_to
            self.cost = _cost
    
    def __init__(self, V):
        #引数Vは頂点数
        self.G = [[] for _ in range(V)] #隣接リストG[u][i]が，頂点uのi番目の辺
        self. _E = 0 #辺の数
        self._V = V #頂点数
    
    #proparty - 辺の数
    def E(self):
        return self._E
    
    #proparty - 頂点数
    def V(self):
        return self._V
    
    def add(self, _from, _to, _cost):
        #2頂点と辺のコストを追加
        self.G[_from].append(self.Edge(_to,_cost))
        self._E +=1
        
    def add2(self, _from, _to, _cost):
        #2頂点と辺のコスト（無向）を追加
        self.G[_from].append(self.Edge(_to, _cost))
        self.G[_to].append(self.Edge(_from, _cost))
        self._E +=1
        
    def CostSum(self):
        #print(self.G[0][0].cost)
        
        used = [0]*self.V()
        que = [] #priority queue
        heapq.heappush(que,(0,0)) #始点の距離と頂点番号=0をヒープに追加
        ans =0 #辺の長さの和
        
        while len(que)!=0:
            #print("que:",format(que))
            #キューに格納されてある中で一番コストが小さい頂点を取り出す
            cost,v = heapq.heappop(que)
            
            #すでにX内にあれば(使用ずみならば)処理しない
            if used[v] ==1:
                continue
            used[v] = 1
            ans += cost
            
            #現在の全域木Xから，Xの外にある頂点e.toとの距離を見てqueに入れていく
            for i in range(len(self.G[v])):
                e = self.G[v][i] #vのi個目の隣接辺
                #print("e:",format(e.to))
                if used[e.to]==0:
                    heapq.heappush(que,(e.cost,e.to))
                    
        return ans   



def main():
    mod=10**9+7
    N=I()
    xyi=[[0,0,0] for _ in range(N)]
    for i in range(N):
        xyi[i][0],xyi[i][1]=MI()
        xyi[i][2]=i
    xyi.sort()
    prim = Prim(N)
    for i in range(N-1):
        prim.add2(xyi[i][2],xyi[i+1][2],abs(xyi[i][0]-xyi[i+1][0]))
        
    xyi.sort(key=lambda x: x[1])
    for i in range(N-1):
        prim.add2(xyi[i][2],xyi[i+1][2],abs(xyi[i][1]-xyi[i+1][1]))

        
    ans = prim.CostSum()
    
    print(ans)
    

main()


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

int n, k, m = 300000001;
int x[100000];

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

	for (int i = 0; i < n; i++)
		cin >> x[i];

	for (int i = 0; i <= n - k; i++) {
		if (x[i] < 0 && x[i + k - 1] < 0)
			m = min(m, -x[i]);
		else if (x[i] < 0 && x[i + k - 1] >= 0)
			m = min(m, x[i + k - 1] - x[i] + min(x[i + k - 1], -x[i]));
		else if (x[i] >= 0 && x[i + k - 1] >= 0)
			m = min(m, x[i + k - 1]);
	}

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 640
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    val A = Array(N) { next() }
    val B = Array(M) { next() }
    for (i in 0 until N) {
        for (j in 0 until N) {
            var ok = true
            loop@ for (k in 0 until M) {
                for (l in 0 until M) {
                    if (i + k >= N || j + l >= N || A[i + k][j + l] != B[k][l]) {
                        ok = false
                        break@loop
                    }
                }
            }
            if (ok) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

Measured memory_bytes: 37744
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct node{
    int city;
    long long num;
    int no;
    int i;
}a[100000+5];
bool cmp(struct node A,struct node B){
    if(A.city < B.city){
        return true;
    }else if(A.city == B.city){
        if(A.num < B.num){
            return true;
        }else{
            return false;
        }
    }else {
        return false;
    }
};
bool cmp1(struct node A,struct node B){
    if(A.i < B.i){
        return true;
    }else {
        return false;
    }
}
int main(){
    int N,M;
    cin>>N>>M;
    for(int i = 0;i < M;i++){
        a[i].i = i;
        int city,num;
        cin>>city>>num;
        a[i].city = city;
        a[i].num = num;
    }
    sort(a,a+M,cmp);
    int flag = 1;
    for(int i = 0;i < M;i++){
        if(i == 0){
            a[i].no = flag;
        }else if(a[i].city != a[i-1].city){
            flag = 1;
        }
        a[i].no = flag;
        flag++;
    }
    sort(a,a+M,cmp1);
    for(int i = 0;i < M;i++){
        printf("%06d%06d\n",a[i].city,a[i].no);
    }
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u,k;
    cin >> u >> k;

    vector<int> row(n, 0);
    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;

      row[v-1] = 1;
    }

    // output
    cout << row[0];
    for (int j = 1; j < n; j++) {
      cout << " " << row[j];
    }
    cout << eol;
  }
  
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vll &a){sort(a.begin(),a.end()) ;}
//void myrev(vll &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(100001,0) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		cnt.at(a)++ ;
	}
	ll num = 0 ;
	vll vec ;
	for(int i=0;i<cnt.size();i++){
		if(cnt.at(i)>2){
			num += (cnt.at(i)-1)/2 ;
			cnt.at(i) = 1+(cnt.at(i)-1)%2 ;
		}
		if(cnt.at(i)==2) vec.push_back(i) ;
	}
	num += (vec.size()+1)/2 ;
	cout << n-num*2 << endl ;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = 1e8;
using namespace std;

int main(){
  int N;
  cin >> N;
  // make coin array
  vector<int> coin;
  coin.push_back(1);
  for(int i = 1; N >= pow(6,i); i++){
    coin.push_back(pow(6,i));
  }
  for(int i = 1; N >= pow(9,i); i++){
    coin.push_back(pow(9,i));
  }

  //make dp table
  int coinNum = coin.size();
  int dp[coinNum + 1][N+1];
  rep(i,coinNum+1)rep(j,N+1) dp[i][j] = INF;
  dp[0][0] = 0;
  
  FOR(i,1,coinNum+1){// i = 何種類のコインを見たか
    rep(j,N+1){
      //if(j - coin[i-1] >= 0) cout << dp[i-1][j] << ',' << dp[i][j - coin[i-1]] + 1 << endl;
      if(j - coin[i-1] >= 0) dp[i][j] = min(dp[i-1][j] , dp[i][j - coin[i-1]] + 1);
      else                   dp[i][j] = dp[i-1][j];
    }
  }

  cout << dp[coinNum][N] << endl;
  return 0;
}


Measured memory_bytes: 5376
def main():
    n = int(input())
    x = list(map(int,input().split()))

    tmp = (100**2)*100

    for i in range(1,101):
        ans = 0
        for j in range(0,n):
            ans += (x[j]-i)**2
        tmp = min(tmp, ans)

    print(tmp)

main()

Measured memory_bytes: 38640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
vvi dp;
int main(){
	int y;
	cin>>y;
	while(y--){
		int n,m;
		cin>>n>>m;
		int N=(n+1)*2,M=(m+1)*2;
		dp=vvi(N,vi(M,0));
		rep(i,n)rep(j,m)dp[2*i+2][2*j+2]=-1;
		dp[1][1]=1;
		int q;
		cin>>q;
		while(q--){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			dp[a+c+1][b+d+1]=-1;
		}
		for(int i=1;i<N;i++)for(int j=1;j<M;j++){
			if(dp[i][j]==-1)continue;
			if(dp[i-1][j]+1)dp[i][j]+=dp[i-1][j];
			if(dp[i][j-1]+1)dp[i][j]+=dp[i][j-1];
		}
		if(dp[N-1][M-1]==0)cout<<"Miserable Hokusai!"<<endl;
		else cout<<dp[N-1][M-1]<<endl;
	}
}

Measured memory_bytes: 1232
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<assert.h>

typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int n, cnt = 0;
	scanf("%d\n", &n);
	for (size_t i = 0; i < n; i++)
	{
		int a;
		scanf("%d ", &a);
		if (a == cnt+1)
		{
			cnt++;
		}
	}

	if (cnt)
	{
		printf("%d", n - cnt);
	}
	else
	{
		printf("-1");
	}
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ans[n+1];
  int s=sqrt(n);
  for(int i=1;i<=n;i++)
    ans[i]=0;
  for(int i=1;i<=s;i++)
    for(int j=1;j<=s;j++)
      for(int k=1;k<=s;k++)
      {
      	int currans=i*i+j*j+k*k+i*j+j*k+k*i;
        if(currans>n)
          break;
        ans[currans]++;
      }
  for(int i=1;i<=n;i++)
    cout<<ans[i]<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int N=6010;
int n,a[N],b[N],f[N],ans[N][N],top[N]; char s[N];
string tmp[N],dp[N],mx[N]; bool vis[N];
int main(){
    scanf("%d%s",&n,s+1);
    for(int i=1; i<=2*n; ++i)
        if(s[i]=='a')a[++a[0]]=i;
        else b[++b[0]]=i;
    a[0]=b[0]=0;
    bool flag=0;
    for(int i=1; i<=n; ++i)
        if(b[i]<a[i])flag=1;
    if(!flag){
        for(int i=1; i<=n; ++i)f[i]=1;
        for(int i=1; i<=n; ++i)
            for(int j=1; j<i; ++j)
                if(b[j]<a[i])f[i]=max(f[i],f[j]+1);
        int ans=0;
        for(int i=1; i<=n; ++i)ans=max(ans,f[i]);
        for(int i=1; i<=ans; ++i)printf("ab");
        return 0;
    }
    for(int i=1; i<=n; ++i)if(b[i]<a[i]){
        int t=a[i]; ans[i][top[i]=1]=i;
        for(int j=i+1; j<=n; ++j){
            if(b[j]>t)break;
            if(b[j]<a[j]){
                t=max(t,a[j]);
                ans[i][++top[i]]=j;
            }
        }
    }
    for(int i=1; i<=n; ++i){
        memset(vis,0,sizeof(vis));
        for(int j=1; j<=top[i]; ++j)
            vis[a[ans[i][j]]]=vis[b[ans[i][j]]]=1;
        for(int j=1; j<=2*n; ++j)
            if(vis[j])tmp[i]=tmp[i]+s[j];
    }
    for(int i=n,t=n; i>=1; --i)if(a[i]>b[i]){
        while(t>i&&b[t]>a[ans[i][top[i]]])--t; ++t;
        dp[i]=tmp[i]+mx[t]; --t;
        mx[i]=max(mx[i+1],dp[i]);
    }else mx[i]=mx[i+1];
    int pos=0;
    for(int i=1; i<=n; ++i)
        if(a[i]>b[i])pos=i;
    int R=a[pos];
    for(int i=1; i<=n; ++i)if(a[i]>R)f[i]=1;
    for(int i=1; i<=n; ++i)
        if(a[i]>R)
            for(int j=1; j<i; ++j)
                if(b[j]<a[i]&&a[j]>R)f[i]=max(f[i],f[j]+1);
    int res=0;
    for(int i=1; i<=n; ++i)res=max(res,f[i]);
    cout << mx[1]; for(int i=1; i<=res; ++i)printf("ab");
    return 0;
}
/*
11
abbbaababaababbabaabaabb
*/

Measured memory_bytes: 64492
n = int(input())
li = [tuple(map(int,input().split())) for _ in range(n)]
li.sort(key=lambda x: x[1])
t = 0
for i in range(n):
    if t + li[i][0] > li[i][1]:
        print("No")
        exit()
    else:
        t += li[i][0] 
print("Yes")

Measured memory_bytes: 31824
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONGINF 1000000000000000000
int main() {
	int n;
	string a, b;
	cin >> n >> a >> b;
	long long ans = a.length()+b.length();
	for (int i = a.length() - 1;i >= 0;--i) {
		for (int q = 0;q + i < a.length();++q) {
			if (b[q] != a[q + i]) goto failed;
		}
		ans = i + b.length();
	failed:;
	}
	cout << ans << endl;
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 085_abc_d / Link: https://abc085.contest.atcoder.jp/tasks/abc085_d?lang=en  ----- */
/* ------問題------

あなたが散歩していると、突然一体の魔物が出現しました。幸い、あなたは N 本の刀、刀 1、刀 2、…、刀 N を持っていて、次の二種類の攻撃を自由な順番で行うことができます。
持っている刀のうち一本を振る。刀 i (1≤i≤N) を振ると、魔物は ai ポイントのダメージを受ける。同じ刀を何度振ることもできる。
持っている刀のうち一本を投げつける。刀 i (1≤i≤N) を投げつけると、魔物は bi ポイントのダメージを受け、あなたはその刀を失う。すなわち、あなたは以後その刀を振ることも投げつけることもできなくなる。
魔物は、受けたダメージの合計が H ポイント以上になると消滅します。魔物を消滅させるには、最小で合計何回の攻撃が必要でしょうか。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,H;

LL ans = 0LL;

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

	cin >> N>>H;
	VL a(N), b(N);
	priority_queue<LL>pqa;
	priority_queue<LL>pqb;

	FOR(i, 0, N) {
		cin >> a[i] >> b[i];
		pqa.push(a[i]);
		pqb.push(b[i]);
	}

	while (true){

		LL A = pqa.top();
		if (pqb.empty()) {
			ans += (H + A - 1) / A;
			break;
		}
		LL B = pqb.top();
		if (A >= B) {
			ans += (H+A-1) / A;
			break;
		}
		else {
			ans++;
			H -= B; if (H <= 0)break;
			pqb.pop();
		}
	}

	cout << ans << "\n";

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(vector<bool> v) {bool first = true; cerr << "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {cerr << ", ";} first = false; __print(v[i]);} cerr << "}";}
template <size_t N>
void __print(bitset<N> bs) {string res = "<"; for (size_t i = 0; i < N; i++) {res += static_cast<char>('0' + bs[i]);} res += '>'; cerr << res;}
template<typename T>
void __print(const T &x) {int j = 0; cerr << "{"; for (auto &i: x) cerr << (j++ ? ", " : ""), __print(i); cerr << "}";}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << "("; __print(x.first); cerr << ", "; __print(x.second); cerr << ")";}
template <typename A, typename B, typename C>
void __print(const tuple<A, B, C> t) {cerr << "("; __print(get<0>(t)); cerr << ", "; __print(get<1>(t)); cerr << ", "; __print(get<2>(t)); cerr << ")";}
template <typename A, typename B, typename C, typename D>
void __print(const tuple<A, B, C, D> t) {cerr << "("; __print(get<0>(t)); cerr << ", "; __print(get<1>(t)); cerr << ", "; __print(get<2>(t)); cerr << ", "; __print(get<3>(t)); cerr << ")";}
void _print() {cerr << " ]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define deb(...) cerr << "~ [ " << #__VA_ARGS__ << " ] => [ "; _print(__VA_ARGS__)
#define debn(...) cerr << "~ [ "; _print(__VA_ARGS__)
#else
#define deb(...)
#define debn(...)
#endif

#define ALL(DS) (DS).begin(), (DS).end()
#define PB push_back
#define EB emplace_back
#define SZ(DS) (int)((DS).size())
#define fo(ITER, LO, UP) for (int ITER = (LO); ITER < (UP); ++ITER)
#define foi(ITER, LO, UP) for (int ITER = (LO); ITER < (UP); ++ITER)
#define foll(ITER, LO, UP) for (ll ITER = (ll)(LO); ITER < (ll)(UP); ++ITER)
#define folli(ITER, LO, UP) for (ll ITER = (ll)(LO); ITER < (ll)(UP); ++ITER)
#define iter(ITER, DS) for (auto &ITER: DS)

const int M = 1000000007;
const int INF = 1e9 + 5;

void solve() {
    int n; cin >> n;

    int res = 0;
    if (n%1000) {
        res = 1000*((n/1000) + 1) - n;
    }

    printf("%d\n", res);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    solve();
}



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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
ll pgc[SZ], sgc[SZ];



int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin1(n);
    for1(i, n) cin1(a[i]);

    for1(i, n) pgc[i] = __gcd(pgc[i-1], a[i]);
    forb(i, n, 1) sgc[i] = __gcd(sgc[i+1], a[i]);

    for1(i, n) {
        ans = max(ans, __gcd(pgc[i-1], sgc[i+1]));
    }
    cot1(ans);

    return 0;
}



Measured memory_bytes: 5940
#include<iostream> 
#include<vector> 
#include<string> 
#include<algorithm> 
using namespace std; 
int main()
{
	int h, w; 
	cin >> h >> w;  
	vector<string> p(h);
	for (int i = 0; i < h; i++)
	{
		cin >> p.at(i);
	}  
	
	for (int i = 0; i < w+2; i++)
	{
		cout << "#";
	} 
	cout << endl; 
	for (int i = 0; i < h; i++)
	{
		cout << "#" << p.at(i) << "#" << endl;
	} 
	for (int i = 0; i < w + 2; i++)
	{
		cout << "#";
	} 
	cout << endl;
}

Measured memory_bytes: 256
#define  REP(i, s, e) for(register int i = s; i <= e ;i++)
#define DREP(i, s, e) for(register int i = s; i >= e ;i--)

#define DEBUG fprintf(stderr, "Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__)
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

#include <bits/stdc++.h>

using namespace std;
const int maxn = 100010;

template <typename T> T read() {
	T ans(0), p(1);
	char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') p = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		ans = ans * 10 + c - 48;
		c = getchar();
	}
	return ans * p;
}

int m, n, k, p[maxn];
string a[maxn];

inline int to(string x) {
	register int len = x.size(), ans(0);

	REP(i, 0, len - 1) ans = ans * 10 + x[i] - 48;
	return ans;
}

map <string, int> Sum, vis;

int main() {
#ifdef CraZYali
	freopen("c.in", "r", stdin);
	freopen("c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	REP(i, 1, n) cin >> a[i], Sum[a[i]]++, p[i] = to(a[i]);
	REP(i, 1, n) 
		if (!vis[a[i]]) {
			vis[a[i]] =1 ;
			if (Sum[a[i]] > p[i]) k += Sum[a[i]] - p[i];
			else if (Sum[a[i]] < p[i]) k += Sum[a[i]];
		}
	cout << k;
	return 0;
}

Measured memory_bytes: 17920
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve(){
	ll n;cin>>n;
	ll a[n][3];

	ll i;
	rep(i,n)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	ll dp[n+1][3];
	memset(dp,0,sizeof(dp));
	fr(i,1,n)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i-1][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i-1][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i-1][2];
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main(){
	//fio();
	fast

	solve();
	return 0;
}

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

#include <utility>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

template<typename T, typename F, typename G> struct SegTree{
    int sz=1;
    T et;
    F f;
    G g;
    vector<T> node;

    SegTree(int sz_, T et_, F f_, G g_): et(et_), f(f_), g(g_){
        while(sz<sz_) sz<<=1;
        node.resize(sz<<1, et);
    }

    void update(int i, T x){
        i+=sz;
        node[i]=g(node[i], x);
        i>>=1;
        while(i){
            node[i]=f(node[i<<1], node[(i<<1)+1]);
            i>>=1;
        }
    }

    T query(int l, int r){
        T vl=et, vr=et;
        for(l+=sz, r+=sz; l<r; l>>=1, r>>=1){
            if(l&1) vl=f(vl, node[l++]);
            if(r&1) vr=f(node[--r], vr);
        }
        return f(vl, vr);
    }
};

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    auto f=[](int a, int b){return min(a, b);};
    auto g=[](int a, int b){return b;};
    SegTree<int, decltype(f), decltype(g)> st(n, INT_MAX, f, g);

    while(q--){
        int c, x, y;
        scanf("%d%d%d", &c, &x, &y);
        if(c==0) st.update(x, y);
        else printf("%d\n", st.query(x, y+1));
    }
}


Measured memory_bytes: 3864
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= print . foldl ( \p k -> ( p * k ) `mod` 1000000007 ) ( 1 :: Integer ) . ( \x -> [ 1 .. x ] ) . read


Measured memory_bytes: 12668
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		long ans=Max(s[0]*s[2],Max(s[0]*s[3],Max(s[1]*s[2],s[1]*s[3])));
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27500
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

int n, m, r;
vector<pair<int, int>> G[100009];
ll d[100009];

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

    cin >> n >> m >> r;

    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
    }

    rep(i, n) d[i] = inf;
    d[r] = 0;
    priority_queue<pair<int, int>> q;
    q.emplace(0, r);

    while(!q.empty()) {
        int dist = -q.top().first;
        int v = q.top().second;
        q.pop();
        if(d[v] < dist) continue;
        for(auto p : G[v]) {
            int cost = p.second;
            int to = p.first;
            if(chmin(d[to], dist + cost)) q.emplace(-d[to], to);
        }
    }

    rep(i, n) {
        if(d[i] < inf)
            cout << d[i] << "\n";
        else
            cout << "INF\n";
    }

    return 0;
}


Measured memory_bytes: 13296
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()

typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int32_t, int32_t> pii;
typedef vector<int32_t> vi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;

  int32_t N, W;
  cin >> N >> W;

  int32_t vsum = 0;
  int64_t dW[N], dV[N];
  rep(i, N) {
    cin >> dW[i] >> dV[i];
    vsum += dV[i];
  }

  int32_t best = 0;
  int64_t values[2][vsum + 1];
  values[0][0] = 0;
  values[1][0] = 0;
  for (int i = 1; i <= vsum; i++) {
    values[0][i] = -1;
    values[1][i] = -1;
  }

  rep(i, N) {
    for (int iv = 1; iv <= vsum; iv++) {
      int64_t minW = values[(i + 1) % 2][iv];
      if (iv - dV[i] >= 0 && values[(i + 1) % 2][iv - dV[i]] >= 0) {
        int64_t localW = values[(i + 1) % 2][iv - dV[i]] + dW[i];
        if (localW <= W) {
          if (minW >= 0) {
            minW = min(minW, localW);
          } else {
            minW = localW;
          }
        }
      }
      if (minW != -1) {
        values[i % 2][iv] = minW;
        best = max(best, iv);
      }
      // cerr << setw(3) << bag[i % 2][iw] << ' ';
    }
    // cerr << '\n';
  }

  cout << best;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n;
ll x[202020],y[202020],a[202020],b[202020]; 
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>x[i]>>y[i];
		a[i]=x[i]+y[i];
		b[i]=1e9-x[i]+y[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	cout<<max(a[n-1]-a[0],b[n-1]-b[0])<<endl;
	return 0;
}


Measured memory_bytes: 9900
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const BUFSIZE = 10000000

var rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)

func main() {
	var a, b, t int
	fmt.Scanf("%d %d %d", &a, &b, &t)

	fmt.Println(b * int(math.Floor(float64(t/a))))
}

func NextLineInt() []int {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}

		buf = append(buf, l...)

		if !p {
			break
		}
	}
	str := strings.Split(string(buf), " ")
	l := len(str)

	ret := make([]int, l)

	for i := range str {
		// ret[i], ok = strconv.Atoi(str[i])
		v, ok := strconv.Atoi(str[i])

		if ok == nil {
			ret[i] = v
		}
	}

	return ret
}

func Bool2Int(b bool) int {
	if b {
		return 1
	} else {
		return 0
	}
}

func Abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Distance(a, b int) int {
	return Abs(a - b)
}


Measured memory_bytes: 2944
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	ll f[3];
	ll sum = 1;
	for (int i = 0; i < 3; i++) {
		scanf("%lld", &f[i]);
		sum = sum * f[i];
	}
	ll tmp;
	if (sum % 2) {
		qsort(f, 3, sizeof(long long int), cmp);
		tmp = f[0] * f[1];
	}
	else {
		tmp = 0;
	}

	ll ans = tmp;
	printf("%ld\n", ans);


#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
mod = 10**9+7
n, m = map(int, input().split())


def inv(a, mod):
    r = [1, 0, a]
    w = [0, 1, mod]
    while w[2] != 1:
        q = r[2]//w[2]
        r_new = [r[0]-q*w[0], r[1]-q*w[1], r[2]-q*w[2]]
        r = w
        w = r_new
    x, y = w[0], w[1]    # a*x+y*mod = 1
    return (mod+x % mod) % mod


max_num = 5*10**5+2  # 10**6 にしたほうがよい?
fact = [0 for _ in range(max_num)]
ifact = [0 for _ in range(max_num)]

fact[0] = fact[1] = 1
ifact[0] = ifact[1] = 1

for i in range(2, max_num):
    fact[i] = fact[i-1] * i % mod

ifact[max_num-1] = inv(fact[max_num-1], mod)

for i in range(2, max_num):
    ifact[max_num-i] = (ifact[max_num-i+1] * (max_num-i+1)) % mod


def comb(x, y):
    if x < 0 or y < 0 or x < y:
        return 0
    else:
        return fact[x] * ifact[y] * ifact[x-y] % mod


tmp = 0
for i in range(1, n+1):
    tmp2 = comb(n, i) * fact[m-i] * ifact[m-n]
    tmp2 %= mod
    tmp += (-1)**(i-1)*tmp2

tmp = fact[m]*ifact[m-n] - tmp
tmp %= mod

ans = tmp*fact[m]*ifact[m-n]
ans %= mod

print(ans)


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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

vector<ll> P(51, 0);

void initP(int n) {
  if (n == 0) return;
  if (P[n - 1] == 0) initP(n - 1);
  P[n] = 2 * P[n - 1] + 1;
  return;
}

ll calc(ll n, ll x) {
  if (n == 0) return 0;
  if (x == 0) return 0;

  if (n == 1) {
    if (x == 0) return 0;
    if (x == 1) return 1;
    if (x == 2) return 2;
    if (x == 3) return 3;
    if (x == 4) return 3;
  }

  ll m = pow(2, n + 1) - 2;
  if (x == m - 1) return P[n - 1];
  if (x == m) return P[n - 1] + 1;

  if (x < m) return calc(n - 1, x - 1);
  if (x == 2 * m) return 2 * P[n - 1] + 1;

  return P[n - 1] + 1 + calc(n - 1, x - (pow(2, n + 1) - 1));
}

int main() {
  ll N, X;
  cin >> N >> X;

  P[0] = 1;
  initP(50);

  std::cout << calc(N, X - 1) << "\n";
  return 0;
}

Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    s = list(input())
    c = ["dreamer", "dream", "erase", "eraser"]
    n = [7, 5, 5, 6]
    while True:
        f = True
        for i in range(4):
            if "".join(s[-n[i] :]) == c[i]:
                f = False
                s = s[: -n[i]]
                break
        if f:
            if len(s) == 0:
                print("YES")
            else:
                print("NO")
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 228552
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    vector<long long> H(N);
    for(long long i = 0; i < N; i++){
        cin >> H[i];
    }
    reverse(H.begin(),H.end());
    for(long long i = 0; i < N-1; i++){
        if(H[i] < H[i+1]) H[i+1]--;
    }
    for(long long i = 0; i < N-1; i++) {
        if(H[i] < H[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024