akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	long long n, k, x ,y,ans = 0;
	cin>>n>>k>>x>>y;
if( n < k )cout<<n*x<<endl;
else
{
	ans += x*k;
	ans += ( n -k  ) * y;

	cout<<ans;
}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 2000009
#define ll long long
#define ld long double
#define ff first
#define ss second
#define inf 1000000005
#define mod 1000000007
using namespace std;
ll h, w, dp[1009][1009];
char a[1009][1009];
int main() {
    cin>>h>>w;
    for(int i=1;i<=h;i++) {
        for(int j=1;j<=w;j++) {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h;i++) {
        for(int j=1;j<=w;j++) {
            if(a[i][j] == '#') {
                //cout<<0<<" ";
                continue;
            }
            if(i == 1 && j == 1) {
                dp[i][j] = 1;
                //cout<<dp[i][j]<<" ";
                continue;
            }
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            dp[i][j] %= mod;
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<dp[h][w];
}


Measured memory_bytes: 12388
#include<iostream>
#include<cstdio>
using namespace std;
const int N=205;
int n,k,p;
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%p;
		a=a*a%p,b>>=1;
	}
	return res;
}
long long fac[N],inv[N];
void init(int n=200)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%p;
	inv[n]=ksm(fac[n],p-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%p;
	return;
}
long long P(int n,int m)
{
	if(m>n) return 0;
	return fac[n]*inv[n-m]%p;
}
long long f[N][N];
long long sum[N][N];
int calc(int n,int m,int k)
{
	f[0][m]=1;
	for(int i=1;i<=m-1;i++)
		f[0][i]=0;
	f[0][0]=-1;
	for(int j=0;j<=m;j++)
	{
		sum[0][j]=j>0?sum[0][j-1]:0;
		sum[0][j]=(sum[0][j]+f[0][j]+p)%p;
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<=m;j++)
		{
			f[i][j]=0;
			if(i-1+j<=k&&n-i+m-j<=k)
			{
				f[i][j]=(f[i][j]+(sum[i-1][m]-(j>0?sum[i-1][j-1]:0)+p)%p)%p;
			}
			sum[i][j]=j>0?sum[i][j-1]:0;
			sum[i][j]=(sum[i][j]+f[i][j])%p;
		}
	return f[n][0];
}
long long solve(int n,int k)
{
	if(n==1) return 1;
	long long res=0;
	for(int deg=2;deg<n;deg++)
		res=(res+calc(deg,n-deg,k))%p;
	return res*fac[n-1]%p;
}
int main()
{
	scanf("%d%d%d",&n,&k,&p);
	init();
	long long ans=0;
	for(int i=0;i<=k;i++)
		ans=(ans+P(n,i)*solve(n-i,k-i)%p)%p;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4468
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    sf(n);
    for(i=9;i>=1;i--)
    {
        if(n%i==0)
        {
            if(n/i<=9)
            {
                cout<<"Yes\n"<<endl;
                return 0;
            }
        }
    }
    cout<<"No\n"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define N 100000000
#define M 10000

int main(void)
{
  int i,j,k=0,n,l[M],flag=0,fi,temp;
  double cmp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    cmp = sqrt(l[i]);
    fi = cmp+1;
    flag = 0;
    for(j=2;j<=fi;j++){
      if(l[i]%j==0 && l[i]!=2){
	flag = 1;
	break;
      }
    }
    if(flag==0)k++;
  }
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2140
let binom_memo ( * ) ( / ) n =
  let i = ref 0 in
  let a = Array.make (n + 1) 1 in
  let rec binom_memo_aux k =
    if k <= !i
    then a.(k)
    else begin
      incr i;
      a.(!i) <- a.(!i - 1) * (n - !i + 1) / !i;
      binom_memo_aux k
    end in
  binom_memo_aux

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let m = 998244353
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m
let ( /^ ) x y = power ( *^ ) x y (m - 2)

let () = Scanf.scanf "%d %d %d" @@ fun n m k ->
  let binom = binom_memo ( *^ ) ( /^ ) (n - 1) in
  Printf.printf "%d\n" @@
  List.fold_left ( +^ ) 0 @@
  List.init (k + 1) @@ fun k ->
    power ( *^ ) (m *^ binom k) (m - 1) (n - 1 - k)





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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

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

    int j;
    cin >> j;
    string s;
    cin >> s;
    if (s.size() % 2 == 1)
    {
        cout << "No";
        return 0;
    }
    int x = s.size() / 2;
    for (int i = 0; i < x; i++)
    {
        if (s[i] != s[x + i])
        {
            cout << "No";
            return 0;
        }
    }
    cout<<"Yes";


    return 0;
}

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

#define rep(i,n) for (int i=0; i < int(n); i++)


// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};


// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
  int a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

// 標準入力からグラフを読み込む
Graph input_graph() {
  Graph g;
  int m;
  cin >> g.n >> m;
  rep(i, m) {
    Edge e;
    cin >> e.a >> e.b >> e.cost;
    g.es.push_back(e);
  }
  return g;
}


int main()
{
  Graph g = input_graph();
  cout << "" << g.kruskal() << endl;
  return 0;
}

Measured memory_bytes: 2724
/*
AUTHOR: Naman
*/
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);
const ll N=2*1e6+1;
const ll M=1e9+7;

vll adj[N];
bool vis[N];
ll cur=0;

void dfs(ll root)
{
    cur++;
    vis[root]=1;
    
    for(auto x:adj[root])
        if(!vis[x])dfs(x);
}


int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	Fo(_,1,t)
	{
	   //cout<<"Case #"<<_<<": ";
	   ll n,m;
	   cin>>n>>m;
	   memset(vis,0,sizeof(vis));
	   
	   Fo(i,0,m-1)
	   {
	       ll u,v;
	       cin>>u>>v;
	       adj[u].pb(v);
	       adj[v].pb(u);
	   }
	   ll ans=0;
	   Fo(i,1,n)
	   {   cur=0;
	       if(!vis[i])dfs(i);
	       ans=max(ans,cur);
	   }
	   
	  
	   cout<<ans;
	   


	   cout<<endl;
	   
	}
	
    
}

Measured memory_bytes: 64856
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c,k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    int sum=0;
    if(k<=a)sum=k;
    if(k>a&&k<=(a+b))sum=a;
    if(k>(a+b))sum=a-(k-a-b);
    printf("%d",sum);
    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll x; cin >> x;
    cout << x / 11 * 2 + (x % 11 > 0) + (x % 11 > 6)  << endl;
    return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end
class UFT
  attr_accessor:par,:rank,:size
  def initialize(n)
    @par=Array.new(n){|i| i}
    @rank=array(n,1,0)
    @size=array(n,1,1)
  end

  def find(x)
    return x if @par[x]==x
    @par[x]=find(@par[x])
    return @par[x]
  end
  
  def union(x,y)
    x=find(x)
    y=find(y)
    return if x==y
    if @rank[x]<@rank[y]
      @par[x]=y
      @size[y]+=@size[x]
    else
      @par[y]=x
      @size[x]+=@size[y]
      if @rank[x]==@rank[y]
        @rank[x]+=1
      end
    end
  end
  def same?(x,y)
    return find(x)==find(y)
  end
  
  def size_gr(x)
    return @size[find(x)]
  end
end

n,m=get_i
uft=UFT.new(n)
ans=n*(n-1)/2
ab=array(m,1)
m.times do|i|
  ab[i]=get_i
  ab[i][0]-=1
  ab[i][1]-=1
end
ans=[]
all=n*(n-1)/2
ans.push(all)
m.times do|i|
  if uft.same?(ab[m-1-i][0],ab[m-1-i][1])
    ans.push(ans[i])
  else
    ans.push(ans[i]-uft.size_gr(ab[m-1-i][0])*uft.size_gr(ab[m-1-i][1]))
  end
  uft.union(ab[m-1-i][0],ab[m-1-i][1])
end
m.times do|i|
  puts ans[m-i-1]
end

Measured memory_bytes: 13876
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}



void oneCase () {
    ll h, n;
    cin >> h >> n;
    ll s = 0;
    while (n > 0) {
        --n;
        ll a;
        cin >> a;
        s += a;
    }
    if (s >= h) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }


}




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

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  int a, b;
  cin >> a >> b;

  int ans = max(a + b, max(a - b, a * b));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
*t, = map(int, input().split())
*v, = map(int, input().split())
sumt = sum(t)

sv = [0]
for i in range(N):
    for j in range(t[i]*2):
        sv.append(v[i])
sv.append(0)

# dp[i][j] := i/2秒後に速度がj/2のときの最大距離
dp = [[-float('inf')]*201 for _ in range(sumt*2+1)]
dp[0][0] = 0
for i in range(1, len(dp)):
    maxj = min(sv[i], sv[i+1])*2
    for j in range(len(dp[i])):
        k = 0.25*j
        # 変化なし
        if j <= maxj:
            dp[i][j] = max(dp[i][j], dp[i-1][j]+k)
        # 加速
        if (j+1) <= maxj:
            dp[i][j+1] = max(dp[i][j+1], dp[i-1][j]+k+0.25)
        # 減速
        if j > 0 and (j-1) <= maxj:
            dp[i][j-1] = max(dp[i][j-1], dp[i-1][j]+k-0.25)

print(dp[-1][0])


Measured memory_bytes: 141016
#include<iostream>
using namespace std;
string s,s1("CODEFESTIVAL2016");
signed main()
{
	cin>>s;int ans(0);
	for(register int i(0);i<s.length();i++)
	{
		ans+=(s[i]!=s1[i]);
	}
	return cout<<ans<<endl,0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

int main() {
	int n, x;
	cin >> n >> x;
	vi L(n);
	for (int i = 0; i < n; i++)cin >> L[i];
	int cnt = 1;
	int now = 0;
	for (int i = 0; i < n; i++) {
		now += L[i];
		if (now <= x)cnt++;

	}
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
string a="AC";
string b="WA";
string c="TLE";
string d="RE";
int x[5];
int main()
{
    string k;
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>k;
        if(k==a)
        {
            x[1]++;
        }
        else if(k==b)
        {
            x[2]++;
        }
        else if(k==c)
        {
            x[3]++;
        }
        else if(k==d)
        {
            x[4]++;
        }
    }
    cout<<a<<" x "<<x[1]<<endl;
    cout<<b<<" x "<<x[2]<<endl;
    cout<<c<<" x "<<x[3]<<endl;
    cout<<d<<" x "<<x[4]<<endl;
    return 0;
}


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int arr[maxr];
int32_t main()
{
	GO;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (arr[i] < arr[i - 1]) {
			ans += arr[i - 1] - arr[i];
			arr[i] = arr[i - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  for(int i=0;i<t.size();i++){
    if(s.size()<i){cout<<"Yes"; return 0;}
    if(s[i]>t[i]) break;
    else if(s[i]==t[i] ) continue;
    else{ cout<<"Yes"; return 0;}
  }
  cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d",&a,&b,&c);
	if ("%d %d", a < b)
	{
		if ("%d %d", b < c)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 2580
def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = list()
    while len(B) > 0:
        D = [(i + 1) - b for i, b in enumerate(B)]
        last_zero_index = -1
        for i, d in enumerate(D):
            if d < 0:
                print(-1)
                return
            if d == 0:
                last_zero_index = i
        if last_zero_index == -1:
            print(-1)
            return
        ans.append(B[last_zero_index])
        B = B[:last_zero_index] + B[(last_zero_index+1):]
    ans.reverse()
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9060
import re

N = int(input())
memo = [{} for i in range(N+1)]
MOD = 10 ** 9 + 7


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if not re.match('.AGC|.ACG|.GAC|A.GC|AG.C', last3 + c):
            ret += dfs(cur + 1, last3[1:] + c)
    ret = ret % MOD
    memo[cur][last3] = ret
    return ret


print(dfs(0, 'TTT'))

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

const int MAXN = 100005;
int n;
int a[MAXN];
int b[MAXN];

void solve() {
    sc(n);
    sca(a, n+1);
    sca(b, n);
    ll ans = 0;
    for (int i = n-1; i >= 0; i--) {
        if (a[i+1] <= b[i]) {
            ans += (ll) a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
            int s = min(b[i], a[i]);
            ans += (ll) s;
            b[i] -= s;
            a[i] -= s;
        }
        else {
            ans += (ll) b[i];
        }
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	k := scanInt(sc)

	ints := make([]int, n)
	values := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = scanInt(sc)
		values[i] = scanInt(sc)
	}

	max := buyMax(ints, values, k)
	for i := uint(0); k>>i > 0; i++ {
		// 右端から i 番目のビットが立っているか
		if (k>>i)%2 == 0 {
			continue
		}

		// i 番目を 0 にし、それより右のビットを全て立てる
		mask := (k>>i-1)<<i + (1 << i) - 1
		sum := buyMax(ints, values, mask)

		if sum > max {
			max = sum
		}
	}

	fmt.Println(max)
}

func buyMax(ints, values []int, mask int) int {
	sum := 0
	for i, m := range ints {
		// mask で立っていないビットが立っていない整数は全て買える。
		if m|mask == mask {
			sum += values[i]
		}
	}
	return sum
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 4992
/***                                                                    
 *            .,,       .,:;;iiiiiiiii;;:,,.     .,,                   
 *          rGB##HS,.;iirrrrriiiiiiiiiirrrrri;,s&##MAS,                
 *         r5s;:r3AH5iiiii;;;;;;;;;;;;;;;;iiirXHGSsiih1,               
 *            .;i;;s91;;;;;;::::::::::::;;;;iS5;;;ii:                  
 *          :rsriii;;r::::::::::::::::::::::;;,;;iiirsi,               
 *       .,iri;;::::;;;;;;::,,,,,,,,,,,,,..,,;;;;;;;;iiri,,.           
 *    ,9BM&,WA了活该       .,:;;:,,,,,,,,,,,hXA8:   T了天命..,,,.       
 *   ,;&@@#r:;;;;;::::,,.   ,r,,,,,,,,,,iA@@@s,,:::;;;::,,.   .;.      
 *    :ih1iii;;;;;::::;;;;;;;:,,,,,,,,,,;i55r;;;;;;;;;iiirrrr,..       
 *   .ir;;iiiiiiiiii;;;;::::::,,,,,,,:::::,,:;;;iiiiiiiiiiiiri         
 *   iriiiiiiiiiiiiiiii;;;::::::::::::::::;;;iiiiiiiiiiiiiiiir;        
 *  ,riii;;;;;;;;;;;;;:::::::::::::::::::::::;;;;;;;;;;;;;;iiir.       
 *  iri;;;::::,,,,,,,,,,:::::::::::::::::::::::::,::,,::::;;iir:       
 * .rii;;::::,,,,,,,,,,,,:::::::::::::::::,,,,,,,,,,,,,::::;;iri       
 * ,rii;;;::,,,,,,,,,,,,,:::::::::::,:::::,,,,,,,,,,,,,:::;;;iir.      
 * ,rii;;i::,,,,,,,,,,,,,:::::::::::::::::,,,,,,,,,,,,,,::i;;iir.      
 * ,rii;;r::,,,,,,,,,,,,,:,:::::,:,:::::::,,,,,,,,,,,,,::;r;;iir.      
 * .rii;;rr,:,,,,,,,,,,,,,,:::::::::::::::,,,,,,,,,,,,,:,si;;iri       
 *  ;rii;:1i,,,,,,,,,,,,,,,,,,:::::::::,,,,,,,,,,,,,,,:,ss:;iir:       
 *  .rii;;;5r,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sh:;;iri        
 *   ;rii;:;51,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.:hh:;;iir,        
 *    irii;::hSr,.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.,sSs:;;iir:         
 *     irii;;:iSSs:.,,,,,,,,,,,,,,,,,,,,,,,,,,,..:135;:;;iir:          
 *      ;rii;;:,r535r:...,,,,,,,,,,,,,,,,,,..,;sS35i,;;iirr:           
 *       :rrii;;:,;1S3Shs;:,............,:is533Ss:,;;;iiri,            
 *        .;rrii;;;:,;rhS393S55hh11hh5S3393Shr:,:;;;iirr:              
 *          .;rriii;;;::,:;is1h555555h1si;:,::;;;iirri:.               
 *            .:irrrii;;;;;:::,,,,,,,,:::;;;;iiirrr;,                  
 *               .:irrrriiiiii;;;;;;;;iiiiiirrrr;,.                    
 *                  .,:;iirrrrrrrrrrrrrrrrri;:.                        
 *                        ..,:::;;;;:::,,.                             
 */  
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main() {
	int n;
	cin>>n;
	ll ans = 1;
	for(int i = 1; i <= n; i++){
		ans = (ans*i)%mod;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
r=Array.new 1000000,1
(2..1000).each{|i|
	next if r[i]==0
	j=i*i
	while j<1000000
		r[j]=0
		j+=i
	end
}
r[0]=r[1]=0
(2..1000000).each{|i|r[i]=r[i]==1?r[i-1]+1:r[i - 1]}
while gets
	p r[$_.to_i]
end

Measured memory_bytes: 13900
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define LLMAX 1000000000000000000
#define pic pair<ll,char>

string str;

bool work(int mid)
{
	vector<int> v;
	bool x=0, y=0;
	for(int i=0; i<str.size(); i++)
	{
		if(i<mid && i>=str.size()-mid)
		{
			if(str[i]-48) x=1;
			else y=1;
		}
	}
	return (x^y) || (!x&&!y);
}
int main()
{
	cin >> str;
	int lo=0, hi=str.size(), mid, ans=-1;
	while(lo<=hi)
	{
//		cout<<lo<<" "<<mid<<" "<<hi<<endl;
		mid = (lo+hi)/2;
		if(work(mid)) lo = mid+1;
		else if(hi==lo) { ans = mid-1; break; }
		else hi = mid;
	}
	if(ans<0) ans = (lo+hi)/2;

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



Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-25 14:14:13 +0900
# LastModified: 2020-06-25 14:20:03 +0900
#


import os
import sys
from math import sqrt
# import numpy as np
# import pandas as pd


def main():
    s = list(map(str, input().split()))
    num = sqrt(int(s[0]+s[1]))
    if num.is_integer():
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":
    main()


Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

bool a[10];int n,k,d;

bool t(int x){
    while(x){
        if(a[x%10])return 0;
        x/=10;
    }return 1;
}

void solve(){
    cin>>n>>k;
    REP(i,k){cin>>d;a[d]=1;}
    while(!t(n))n++;
    cout<<n<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

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

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    ll N,M;
    cin >> N >> M;
    vector<vector<int>> S(M);
    REP(i,M) {
        ll K;
        cin >> K;
        REP(j,K) {
            ll s;
            cin >> s;
            S[i].pb(s-1);
        }
    }
    vector<int> p(M);
    REP(i,M) cin >> p[i];

    ll ans = 0;
    REP(i,1<<N) {
        int t = i;
        vector<bool> ss(N,false);
        REP(j,N) {
            ss[j] = t % 2;
            t /= 2;
        }
        bool check = true;
        REP(j,M) {
            ll n = 0;
            REP(k,S[j].size()) {
                if (ss[S[j][k]]) n++; 
            }
            if (n%2 != p[j]) check = false; 
        }
        if (check) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long KnapSack(long long wt[], long long val[], long long w, long long n){
    long long table[n+1][w+1];
    for(int i = 0; i<=n; i++)
        for(int j = 0; j<=w; j++)
            if(i == 0 || j == 0)
                table[i][j] = 0;


    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=w; j++){
            if(wt[i-1] <= j)
                table[i][j] = max(val[i-1] + table[i-1][j-wt[i-1]], table[i-1][j]);
            else 
                table[i][j] = table[i-1][j];
        }
    }
    return table[n][w];
}
int main(){
    long long n;
    long long w;
    cin>>n;
    cin>>w;
    long long wt[n];
    long long val[n];
    for(int i = 0; i<n; i++){
        cin>>wt[i]>>val[i];
    }
    cout<<KnapSack(wt, val, w, n)<<"\n";    
}

Measured memory_bytes: 82468
#include <iostream>
#include <algorithm>
using namespace std;
 
void fastin(int &number) {
    bool negative = false;
    int c;
    number = 0;
    c = getchar_unlocked();
    if (c == '-') {
        negative = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) number = number * 10 + c - 48;
    if (negative) number *= -1;
}
 
void fastout(int64_t n) {
    int64_t N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { count++; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar('0');
}
     
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        
    int N; fastin(N);
    int A[N];
    for (int i = 0; i < N; ++i) fastin(A[i]);
    sort(A, A + N, greater<int>());
     
    int point1 = -1; int point2 = -1;
    int len1, len2;
    for (int i = 0; i < N - 1; ++i) {
    if (A[i] == A[i + 1]){
           point1 = i; len1 = A[i]; break;
        }
    }
    if (point1 < 0){
        fastout(0); return 0;
    }
    for (int i = point1 + 2; i < N - 1; ++i) {
        if (A[i] == A[i + 1]){
            point2 = i; len2 = A[i]; break;
        }
    }
    if (point2 < 0){
        fastout(0); return 0;
    }    
    int64_t ans = 1LL * len1 * len2;
    fastout(ans);
     
    return 0;
}

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


int MarkToIndex(char mark)
{
	if (mark == 'S') return 0;
	if (mark == 'H') return 1;
	if (mark == 'C') return 2;
	if (mark == 'D') return 3;

	return -1;
}
char IndexToMark(int index)
{
	if (index == 0) return 'S';
	if (index == 1) return 'H';
	if (index == 2) return 'C';
	if (index == 3) return 'D';

	return -1;
}


int main()
{
	bool card[4][13] = { 0 };
	int n;
	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		char mark;
		int number;
		cin >> mark >> number;

		card[MarkToIndex(mark)][number - 1] = true;
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 13; ++j)
		{
			if (!card[i][j]) cout << IndexToMark(i) << " " << j + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
import itertools
import bisect
import sys
sys.setrecursionlimit(10 ** 7)

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

N = int(input())
S = list(input())

STR = [[] for _ in range(3)]
RGB = {'R': 0, 'G': 1, 'B': 2}
for i in range(N):
    s = S[i]
    STR[RGB[s]].append(i)

if not STR[0] or not STR[1] or not STR[2]:
    print(0)
    exit()

cnt = 0
for x, y in itertools.combinations(range(3), 2):
    for a, b in itertools.product(STR[x], STR[y]):
        if b < a:
            a, b = b, a

        c = b + (b - a)

        if N - 1 < c:
            continue

        t = RGB[S[c]]

        if t != x and t != y:
            cnt += 1

ans = len(STR[0]) * len(STR[1]) * len(STR[2]) - cnt
print(ans)


Measured memory_bytes: 9356
#include <stdio.h>

struct _log {
	int i;
	long t;
};
typedef struct _log log;

int main() {
	while(1) {
		int n, j, k;
		int count = 0;
		long t;
		scanf("%d",&n);
		if (n == 0) break;
		for (j = 0; j < n; j++) {
			log l[4000];
			int i, p, q;
			int idx = -1;

			scanf("%d %d %d",&i, &p, &q);
			t = (long)p * (long)q;
			for (k = 0; k < j; k++) {
				if (l[k].i == i) {
					idx = k;
					break;
				}
			}
			if (idx >= 0) {
				if (l[idx].t < 1000000) {
					l[idx].t += t;
					if (l[idx].t >= 1000000) {
						printf("%d\n", i);
						count++;
					}
				}
			} else {
				l[j].i = i;
				l[j].t = t;
				if (t >= 1000000) {
					printf("%d\n", i);
					count++;
				}
			}
		}
		if (count == 0) {
			printf("NA\n");
		}
	}
	return 0;
}

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

struct Point {
    int x, y;

    Point() = default;
    Point(int x, int y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }

    Point operator-(const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }

    long long operator*(const Point &rhs) const {
        return 1ll * x * rhs.x + 1ll * y * rhs.y;
    }

    long long operator%(const Point &rhs) const {
        return 1ll * x * rhs.y - 1ll * y * rhs.x;
    }
};

int main() {
    int n; cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i].x >> p[i].y;

    long long ans = 0;
    for (int i = 0; i < n; ++i) ans += p[i] % p[(i + 1) % n];
    ans = abs(ans);
    cout << ans / 2;
    if (ans & 1) cout << ".5" << endl;
    else cout << ".0" << endl;
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
class Point{
  public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
};
struct seg{Point p1,p2;};
double norm(Point p){return p.x*p.x+p.y*p.y;}
double abs(Point p){return sqrt(norm(p));}
double dot(Point a,Point b){return a.x*b.x+a.y*b.y;}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double getDistancePP(Point a,Point b){return abs(a-b);}
double getDistanceLP(seg l,Point p){return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));}
double getDistanceSP(seg s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}
int n,m,c=1,pre,fro,p,t;
Point a[5001];
seg w;
bool vis[5001];double d[5001];
double dd=1000000000,dis=0;
int main(){
  cin>>n>>m;n++;
  r(i,n)cin>>a[i].x>>a[i].y;
  r(i,n)d[i]=abs(a[0]-a[i]);
  vis[0]=1;
  seg w;w.p1=a[0];w.p2=a[p];
  while(m--){
    dd=10000000;t=-1;c=0;
    r(i,n)if(!vis[i])if(t<0||d[i]<d[t])t=i;
    r(i,n)if(vis[i])if(abs(a[i]-a[t])<abs(a[c]-a[t]))c=i;
    dis+=abs(a[c]-a[t]);
    w.p1=a[c];w.p2=a[t];
    vis[t]=1;
    r(i,n)if(!vis[i])d[i]=min(d[i],getDistanceSP(w,a[i]));
  }
  printf("%.12f\n",dis);
}

Measured memory_bytes: 3396
s = input()
n = len(s)


def check(t):
    for i in range(len(t)):
        if t[i] != t[len(t) - i - 1]:
            return False
    return True


ans = 'Yes' if check(s) and check(s[:(n - 1) // 2]) and check(s[(n + 1) //
                                                                2:]) else 'No'

print(ans)


Measured memory_bytes: 2940
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = listOfInt().sortedDescending()
    val D = arrayListOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val B = (0 until M).map { D[A[it]] }
    val dp = Array(N + 1) { -1 }; dp[0] = 0
    for (m in 0 until M) {
        for (d in B[m] .. N) {
            dp[d] = Math.max(dp[d], dp[d - B[m]] + 1)
        }
    }
    var ans = ""
    var n = N
    while (n > 0) {
        for (a in A) {
            if (n >= D[a] && dp[n - D[a]] == dp[n] - 1) {
                ans += a
                n -= D[a]
                break;
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e5+5;

int n,a[N];

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

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

    sort(a+1,a+1+n);

    cout<<a[1+n/2]-a[n/2];
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define s_pri(str) printf("%s\n",str);
#define PRINT(str) printf(#str "\n")
#define v_pri(val) printf("%d\n",val);
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define pi acos(-1.0)
#define sca(x) scanf("%d",&x);

typedef long long int ll;

/*
puts("aa");
//*/


int main(void) {


	char S[100001];
	scanf("%s", S);

	while (strlen(S) > 0) {
		if (strcmp(&S[strlen(S) - 7], "dreamer") == 0) {
			S[strlen(S) - 7] = 0;
		}
		else if (strcmp(&S[strlen(S) - 5], "dream") == 0) {
			S[strlen(S) - 5] = 0;
		}
		else if (strcmp(&S[strlen(S) - 6], "eraser") == 0) {
			S[strlen(S) - 6] = 0;
		}
		else if (strcmp(&S[strlen(S) - 5], "erase") == 0) {
			S[strlen(S) - 5] = 0;
		}
		else {
			s_pri("NO");
			return 0;
		}
		
	}
	
		if (S[0] == 0) {
			s_pri("YES");
		}
		else {
			s_pri("NO");
		}
		

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){

  int a, b;
  
  cin >> a >> b;
  
  if (a % 2 == 1 && b % 2 == 1)
    cout << "Odd" << endl;
  
  else
    cout << "Even" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

#define N_MAX 100000
#define MOD 1000000007

int N, M, V, P;
int table[N_MAX];
bool func(int index)
{
	if (table[index] + M < table[N - P]){
		return false;
	}

	int vote = V - P;
	if (vote <= index){
		return true;
	}

	vote -= index;
	lli sum = 0;
	for (int i = index + 1; i <= N - P; i++){
		if (table[index] + M - table[i] <= 0){
			break;
		}
		sum += (lli)min(M, table[index] + M - table[i]);
	}

	return sum >= (lli)vote*(lli)M;
}

void solv()
{
	scanf("%d%d%d%d", &N, &M, &V, &P);
	for (int i = 0; i < N; i++){
		int A; scanf("%d", &A);
		table[i] = A;
	}

	sort(table, table + N);

	if (P >= V){
		for (int i = 0; i < N; i++){
			if (table[i] + M >= table[N - P]){
				printf("%d", N - i);
				break;
			}
		}
	}
	else{
		int left = 0, right = N - 1;
		while (right - left>1){
			int mid = (left + right) / 2;
			if (func(mid)){
				right = mid;
			}
			else{
				left = mid;
			}
		}
		if (func(left)){
			right = left;
		}
		printf("%d", N - right);
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 512
N, A, B = list(map(int, input().split()))

r_sum = 0
for i in range(1, N+1):
  sum_digit = 0
  n_str = str(i)
  for j in range(len(n_str)):
    sum_digit += int(n_str[j])
  if A <= sum_digit and sum_digit <= B:
    r_sum += i
print(str(r_sum))

Measured memory_bytes: 9104
from copy import deepcopy
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]


def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d

B = deepcopy(A)
#d = warshall_floyd(A)
#if B != d:
#  print(-1)
#  exit()

for i in range(N):
  for j in range(N):
    for k in range(N):
      if i == j or j == k or k == i:
        continue
      if A[i][k] + A[k][j] < A[i][j]:
        print(-1)
        exit()
      elif A[i][k] + A[k][j] == A[i][j]: 
        B[i][j] = 0

ans = 0
for i in range(N):
  for j in range(i+1, N):
    ans += B[i][j]

print(ans)

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

int main(){
  int N;cin>>N;
  vector<int>B(N-1);
  for(int i=0;i<N-1;i++){
    cin>>B.at(i);
  }
  
  long S=0;
  
  S+=B.at(0);
  for(int i=0;i<N-2;i++){
    S+=min(B.at(i),B.at(i+1));
  }
  S+=B.at(N-2);
  
  cout<<S;
}

Measured memory_bytes: 256
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
#print(N, type(N))
#print(list_A, type(list_A))
#print(list_B, type(list_B))
#print(list_C, type(list_C))

sum = 0
for i in range(N):
#    print('i=', i)
    sum += list_B[list_A[i]-1]
#    print('list_A=', list_A[i], 'list_B=', list_B[list_A[i]-1])
    if ((list_A[i] - list_A[i-1]) == 1) and (i != 0):
        sum += list_C[list_A[i-1]-1]
#        print('list_C=', list_C[list_A[i-1]-1])
#    print('sum=', sum)
print(sum)

Measured memory_bytes: 3064
def get_sharp_or_dot(number):
    if number % 2 == 0:
        return '#'
    else:
        return '.'

while True:
    [H, W] = [int(x) for x in raw_input().split()]
    if [H, W] == [0, 0]:
        break
    for x in range(H):
        print("".join([get_sharp_or_dot(i) for i in range(x, W + x, 1)]))

    print('')

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int n,m;
int v[100010],s[100010],ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)s[i]=1;
	v[1]=ans=1;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(s[x])
		{
			--s[x];
			++s[y];
			if(v[x]&&!v[y])v[y]=1,++ans;
			if(!s[x]&&v[x])v[x]=0,--ans;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 1024
import sys
from operator import itemgetter

input = sys.stdin.readline

N = int(input())

task_list = [tuple(map(int, input().split())) for _ in range(N)]

task_list.sort(key=itemgetter(1))

deadline = 0
time = 0

for task in task_list:
    time += task[0]
    deadline = task[1]
    if deadline < time:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 32200
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

ll pow2(int n){
	ll ans = 1;
	rep(i, n){
		ans = (ans*2)%1000000007;
	}
	return ans;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n;cin>>n;
	vector<ll> b(61,0);
	vector<ll> d(61,0);
	
	ll  m = 1000000007;
	ll one = 1;

	rep(i, n){
		ll c;
		cin>>c;
		int cou = 0;
		/*while(c>0){
			if((c&1)==1){
				b[cou]++;
			}
			cou++;
			c >>= 1;
		}*/
		rep(j, 61){
			if(((c>>j)&one)){
				b[j]++;
			}else{
				d[j]++;
			}
		}
	}
	
	ll ans = 0;
	rep(i, 61){
		//cout << i << b[i] << endl;
		ans =(ans + ( ((b[i]*d[i])%m)*((one<<i)%m) )%m  )%m;
	}
	cout << ans %m<< endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int A[1000000],n;

int binarySearch(int key){
	int left=0;
	int right=n;
	int mid;
	
	while(left<right){
		mid = (left+right)/2;
		if(key==A[mid])return 1;
		if(key>A[mid])left=mid+1;
		else if(key<A[mid])right=mid;
	}
	return 0;
}

int main(){
	int i,q,k,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&k);
		if(binarySearch(k))sum++;
		
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 980
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string a;
  string b;
  string c;
  cin >> a;
  for(int i = 0; i < a.size() ; i++ )
  {
    if(a[i] >= 'A')
    {
      a[i] -= 32;
    }
  }
  int cnt = 0;
  while(1)
  {
    b = "";
    cin >> b;

    if(b == "END_OF_TEXT")break;
    if(a.size() == b.size())
    {
      for(int i = 0; i < a.size(); i ++)
      {
        if(a[i] != b[i] && (char)(a[i]+32)!=b[i])break;
        if(i == (a.size() - 1))cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,X;
  cin>>N>>X;
  if(N==1){
    if(X<5)
      cout<<X-1<<endl;
    else
      cout<<X-2<<endl;
    return 0;
  }
  //P /-1- /1
  //BPPPB 1-1/-3- (2/3)/3+1*2=5
  //BBPPPBPBPPPBB2-1-1-2/-3-1-3 (6/7)/3+5*2=13
  //BBBPPPBPBPPPBBPBBPPPBPBPPPBBB3-1-1-2-2-1-1-3/-3-1-3-1-3-1-3/ (14/15)3+13*2=29
  //BBBBPPPBPBPPPBBPBBPPPBPBPPPBBBPBBBPPPBPBPPPBBPBBPPPBPBPPPBBBB (30/31)/3+29*2=61
  //4-1-1-2-2-1-1-3-3-1-1-2-2-1-1-4/-3-1-3-1-3-1-3-1-3-1-3-1-3-1-3
  //BBBBBPPPBPBPPPBBPBBPPPBPBPPPBBBPBBBPPPBPBPPPBBPBBPPPBPBPPPBBBBPBBBBPPPBPBPPPBBPBBPPPBPBPPPBBBPBBBPPPBPBPPPBBPBBPPPBPBPPPBBBBB
  //B>P>B
  //総数出しとく。抜粋数に対してどうする？
  //B0P0B=1
  //B1P1B=2
  //B2P2B=3
  //B3P3B=4
  //-----=50
  //2文探索みたいな感じで終了地点を探す。～以下にあるなら総数/2を足してそうじゃないなら範囲狭めるだけ
  vector<ll> Z(N+1,1);
  for(int i=1; i<=N; i++){
    Z[i]=Z[i-1]*2+3;
  }
  ll ans=0, h=Z[N], l=1, mid=(h+l)/2;
  while(1){
    if(mid<=X){
      l=mid;
      ans+=(h-l)/2+1;
    }
    else if(mid>X)
      h=mid;
    l++;
    h--;
    if(l>h)
      break;
    mid=(h+l)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll linf=1e18;
const int inf=1001001001;
const ll mod=1e9+7; // 998244353 = (119<<23)+1
// head
ll a,b;
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>a>>b;
		cout<<a*b/(ll)__gcd(a,b);

		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
   ll k ;
   cin>>k ;
   ll n;
   cin>>n ;
   int arr[n] ;
   for(int i=0;i<n;i++)
   {
       cin>>arr[i] ;
   }
   int max = 0 ;
   for(int i=0;i<n-1;i++)
   {
       if((arr[i+1]-arr[i])>max) 
       {
           max = arr[i+1]-arr[i] ;
        }
   }
   int dis = arr[n-1]-arr[0] ;
   if(dis>k/2) 
    dis = k-dis ;
   if(dis>max) 
   {    
        max =dis ;
   }    
    ll ans = k-max ;
    cout<<ans<<endl ;
	return 0;
}


Measured memory_bytes: 1024
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    flg=1
    for i in a:
        if i%2==0:
            if i%3==0 or i%5==0:
                pass
            else:
                flg=0
    if flg==1:
        print('APPROVED')
    else:
        print('DENIED')
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
module Main where

import Control.Monad
import Control.Applicative

main = do
 [a, b, c] <- map (read::String -> Int) . words <$> getLine
 k <- fmap (read::String -> Int) getLine
 print $ solve a b c k

solve::Int -> Int -> Int -> Int -> Int
solve a b c k
 | a >= b && a >= c = a * (2 ^ k) + b + c
 | b >= a && b >= c = a + b * (2 ^ k) + c
 | c >= a && c >= b = a + b + c * (2 ^ k)



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

int main() {
  int n;
  cin >> n;
  
  int A[n][200];
  
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    
    for(int j = 'a'; j <= 'z'; j++) {
      A[i][j] = 0;
    }
    
    for(int j = 0; j < s.length(); j++) {
      A[i][s[j]]++;
    }
  }
  
  for(int j = 'a'; j <= 'z'; j++) {
    int m = 2000000000;
    for(int i = 0; i < n; i++) {
      if(A[i][j] < m) {
        m = A[i][j];
      }
    }
    for(int i = 0; i < m; i++) {
      cout << (char) j;
    }
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::string S; std::cin >> S;

  int r = 0, b = 0;
  for (char c : S) {
    if (c == 'R') ++r;
    else          ++b;
  }

  if (r>b) std::cout << "Yes" << std::endl;
  else     std::cout << "No" << std::endl;
}


Measured memory_bytes: 256