akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

string s;

void go() {
    cout << "No" << '\n';
    exit(0);
}

int ok(char x) {
    for (int i = 0; i < (int)s.size(); ++i) if (s[i] == x) return 1;
    return 0;
}

main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    if ((ok('N')^ok('S'))) {
        go();
    }
    if ((ok('W')^ok('E'))) {
        go();
    }
    cout << "Yes" << '\n';
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    map<i64, i64, greater<i64>> dist;
    REP(i, N) {
        i64 a; cin >> a;
        dist[a]++;
    }

    i64 ans = 0;
    vector<i64> line;
    for (auto [a, n] : dist) {
        i64 m = n / 2;
        for (i64 i = 1; i <= min(m, 2L); i++) {
            line.pb(a);
        }
        if (line.size() >= 2) {
            ans = line[0] * line[1];
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9776
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;
    scanf("%d",&n);

    double a[n];
    
    for(int i = 0;i < n;i++){
        scanf("%lf",&a[i]);
    }

    double sum = 0;
    for(int i = 0;i < n;i++){
        sum += (double)1 / (double)a[i]; 
    }

    printf("%lf",(double)1 / (double)sum);
}

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

int main() {
    string s, t;
    int result = 0;

    cin >> s >> t;

    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            result++;
        }
    }

    cout << result << endl;
  	return 0;
}

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

using namespace std;

int main() {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s1.at(i) == s2.at(i)) count++;
    }
    cout << count << endl;
}


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

static int N=100;

int main(){
  int i,l,j,k,n,p[N+1],m[N+1][N+1];
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  
  for(l=2;l<=n;l++)
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1<<21;
      for(k=i;k<=j-1;k++){
	m[i][j]=fmin(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
 
  printf("%d",m[1][n]);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2112
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int H = int.Parse(str[0]);
		int W = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		int[,]A = new int[H,W];
		for(var i=0;i<H;i++){
			string str2 = Console.ReadLine();
			for(var j=0;j<W;j++){
				if(str2.Substring(j,1)=="#"){
					A[i,j]=1;
				}
			}
		}
		int[,]B = new int[H,W];
		int S = 0;
		for(var i=0;i<H;i++){
			int ct = 0;
			for(var j=0;j<W;j++){
				if(A[i,j]==1){
					ct++;
				}
			}
			if(ct==0){
				for(var j=0;j<W;j++){
					if(i==0){
						B[i,j]= -1;
                    } else {
                      	B[i,j] = B[i-1,j];
                    }
				}
			} else if(ct==1){
				S = S+1;
				for(var j=0;j<W;j++){
					B[i,j]=S;
				}
			} else {
              	int SM = S+ct;
				S = S+1;
				for(var j=0;j<W;j++){
                  	B[i,j]=S;
                     if(A[i,j]==1){
                       S = Math.Min(S+1,SM);
                     }

				}
			}
		}
      	for(var j=0;j<W;j++){
          	int t = -1;
          	for(var i=H-1;i>=0;i--){
				if(B[i,j]==-1){
                  	B[i,j] = t;
                } else {
                  t = B[i,j];
                }
            }
        }
		for(var i=0;i<H;i++){
			Console.Write(B[i,0]);
			for(var j=1;j<W;j++){
				Console.Write(" "+B[i,j]);
			}
          	Console.WriteLine();
		}
	}
}

Measured memory_bytes: 17796
n,w=list(map(int,input().split()))
gds=[list(map(int,input().split())) for _ in range(n)]
w1=gds[0][0]
goods={w1+i:[0] for i in range(4)}

for cw,cv in gds:
    goods[cw].append(cv)

for i in range(4):
    goods[w1+i]=sorted(goods[w1+i],reverse=True)
ans=0

for d in range(min(w//(w1+3),len(goods[w1+3]))+1):
    wd=w-d*(w1+3)
    for c in range(min(wd//(w1+2),len(goods[w1+2]))+1):
        wc=wd-c*(w1+2)
        for b in range(min(wc//(w1+1),len(goods[w1+1]))+1):
            wb=wc-b*(w1+1)
            a=wb//w1

            ans=max(ans,sum(goods[w1][:a])+sum(goods[w1+1][:b])+sum(goods[w1+2][:c])+sum(goods[w1+3][:d]))

print(ans)

Measured memory_bytes: 74656
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }

    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;


ll binpow(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        x>>=1;
    }
    return res;
}

ll modInverse(ll a, ll m) 
{ 
    return(binpow(a, m-2)); 
} 
 
 // これで、nCkを求められる.
ll binomialCoeff(ll n, ll k)  
{  
    if(k > n) return 0;
    ll res = 1; 
    ll den=1; 
    ll inv;
    if ( k > n - k )  
        k = n - k;  
    for (ll i = 0; i < k; ++i)  
    {  
        res = (res*(n - i))%MOD; 
        inv=modInverse(i+1,MOD);
        res=(res*inv)%MOD;
    }  
    return res;  
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    int a, b; cin >> a >> b;

    print(binomialCoeff(a, 2) + binomialCoeff(b, 2));
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int counter,rez;
int n;
int Divisor(int k){
    counter =0;
for(int i =1;i<=k;i++){
    if(k%i==0){
        counter++;
    }
}
return counter;
}
int main(){
cin>>n;
for(int i =1;i<=n;i++){
    if(Divisor(i)==8 && i%2!=0){
        rez++;
    }
}
cout<<rez<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
 

int main() 
{
    fast();
    ll n;
    cin>>n;
    vi a(n);
    cin>>a;
    ll total=0;
    for(ll i=0;i<n;i++)
        total = (total^a[i]);
    vi ans(n);
    for(ll i=0;i<n;i++)
    {
        ans[i]=total^a[i];
    }
    cout<<ans<<nl;
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int x,n;
    cin >> x >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    map<int,bool> mp;
    for(int i = 0; i < n; i++){
        mp[p[i]] = true;
    }
    for(int i = 0; i < 200; i++){
        if(!mp[x-i]){
            cout << x-i << endl;
            return 0;
        }else if(!mp[x+i]){
            cout << x+i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<queue>
#include<string>
#include<climits>
#include<bitset>
#include<set>
#include<functional>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	unsigned long long int n;
	cin>>n;
	unsigned long long int  ans = (n/500)*1000;
	n = n%500;
	ans = ans+(n/5)*5;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

int main(){

  int n, c, k;
  scanf("%d %d %d", &n, &c, &k);

  vector<int> v;
  REP(i, n){
    int t;
    scanf("%d", &t);
    v.pb(t);
  }

  SORTV(v);

  int res = 0;
  REP(i,v.size()){
    int s_t = v[i], count = 1, j = i;
    while(j < v.size()){
      if(v[j] <= s_t + k && count <= c){
        j++; count++;
      }else{
        j--;
        break;
      }
    }
    res++;
    i = j;
  }

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

  return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	vector<string> a(h), b(h);
	a[0] = string(w, '#');
	a.back() = string(w, '.');
	b[0] = string(w, '.');
	b.back() = string(w, '#');


	REP(i, 1, h-1) {
		a[i] = string(w, '.');
		b[i] = string(w, '.');
		rep(j, w) {
			(j&1 ? a[i][j] : b[i][j]) = '#';
		}
	}
	rep(i, h) rep(j, w) {
		if(s[i][j] == '#') a[i][j] = b[i][j] = '#';
	}
	rep(i, h) cout << a[i] << endl;
	cout << endl;
	rep(i, h) cout << b[i] << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

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

typedef long long ll;

const ll mod = (ll)(1e9+7);

int main() {
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  
  ll r = 0;
  rep(k,60) {
    ll m = 0;
    rep(i,n) m += (a[i]>>k) % 2;
    r = (r + (n - m) * m % mod * ((1L<<k) % mod)) % mod;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

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

typedef long long ll;
typedef long double ld;

using namespace std;

int n, k, arr[105], dp[N][105];

int solve(int left, int mov)
{
    if(dp[left][mov]!=0)
        return dp[left][mov];
    if(left<arr[1])
        return 3-mov;
    int ret;
    if(mov==1)
    {
        ret=2;
        for(int a=1; a<=n; a++)
            if(left-arr[a]>=0)
                ret=min(ret, solve(left-arr[a], 2));
            else break;
    }
    else
    {
        ret=1;
        for(int a=1; a<=n; a++)
            if(left-arr[a]>=0)
                ret=max(ret, solve(left-arr[a], 1));   
            else break;
    }
    return dp[left][mov]=ret;
}

int main()
{
    ind2(n, k);
    for(int a=1; a<=n; a++)
        ind(arr[a]);
    sort(arr+1, arr+n+1);
    int ans=solve(k, 1);
    if(ans==1) printf("First\n");
    else printf("Second\n");
    return 0;
}

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

int main()
{
  int r,d,x;
  cin>>r>>d>>x;
  vector<int> wei(10);
  for(int i=0;i<10;i++)
  {
    cin>>wei.at(i);
  }
  wei.at(0)=r*x-d;
  cout<<wei.at(0)<<endl;
  for(int i=1;i<10;i++)
  {
    wei.at(i)=r*wei.at(i-1)-d;
    cout<<wei.at(i)<<endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc165/tasks/abc165_a

import sys

input_k = input()
input_a_b = input()

k = int(input_k)
input_a, input_b = input_a_b.split()
a = int(input_a)
b = int(input_b)

xd = a // k # Divine
xm = a % k  # Amari

if xm == 0:
    print('OK')
    sys.exit(0)

if b >= k * (xd+1):
    print('OK')
    sys.exit(0)

print('NG')
sys.exit(0)


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,p;
    cin >> a >> b >> c >> d >> p;
    int q,w;
    q=p*a;
    if(p<=c){w=b;}
    else w=b+d*(p-c);
    cout << min(q,w) << endl;

    return 0;
}


Measured memory_bytes: 3136
import math

K=input()
D=int(input())
n=len(K)
dp=[[[0 for _ in range(D)] for _ in range(2)] for _ in range(n+1)]
MOD=10**9+7

dp[0][0][0]=1
for i in range(0,n):
    a=int(K[i])
    x=a%D
    for j in range(D):
        for x in range(10):
            dp[i+1][1][(j+x)%D]=(dp[i+1][1][(j+x)%D]+dp[i][1][j])%MOD
        for x in range(a):
            dp[i+1][1][(j+x)%D]=(dp[i+1][1][(j+x)%D]+dp[i][0][j])%MOD
        dp[i+1][0][(j+a)%D]=dp[i][0][j]

print((dp[n][0][0]+dp[n][1][0]-1)%MOD)


Measured memory_bytes: 93704
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int T = Integer.parseInt(sc.next());
        int[] c = new int[N];
        int[] t = new int[N];
        int min = 1001;
        for(int i=0; i<N; i++) {
            c[i] = Integer.parseInt(sc.next());
            t[i] = Integer.parseInt(sc.next());
            if(T < t[i]) {
                continue;
            }
            if(min > c[i]) {
                min = c[i];
            }
        }
        if(min == 1001) {
            System.out.println("TLE");
        }else {
            System.out.println(min);
        }
    }
    
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    vector<set<P>> v(n);
    rep(i, m) {
        int p, y;
        cin >> p >> y;
        p--;
        v[p].emplace(P(y, i));
    }
    vector<P> ans(m);
    rep(i, n) {
        int num = 1;
        for (P p : v[i]) {
            ans[p.se] = P(i+1, num++);
        }
    }
    rep(i, m) {
        printf("%06d%06d\n", ans[i].fi, ans[i].se);
    }
    
}


Measured memory_bytes: 13480
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int D,G;
int p[11],c[11];
int main(){
    cin>>D>>G;
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
    }
    int ans=100000;
    for(int i=0;i<(1<<D);i++){
        int point=0;
        int ans_temp=0;
        for(int j=0;j<D;j++){
            if((i&(1<<j))!=0){//コンプリートする問題群のとき
                //cout<<"i:"<<i<<" , 1<<j:"<<(1<<j)<<endl;
                point += 100*(j+1)*p[j]+c[j];
                ans_temp+=p[j];
            }
        }
        //cout<<i<<":"<<point<<endl;
        for(int j=D-1;j>=0;j--){
            if((i&(1<<j))==0){//コンプリートしない問題群のとき
                for(int k=0;k<p[j]-1 && point<G;k++){//コンプリートしないようにp[j]-1まで
                    point+=(j+1)*100;
                    ans_temp++;
                }
            }
        }
        if(point>=G){
            ans=min(ans,ans_temp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int ans1 = -1, ans2 = -1;
  for(int i=0;i<S.size()-1;++i) {
    if(S[i]==S[i+1]) {
      ans1 = i+1;
      ans2 = i+2;
      break;
    }
  }
  for(int i=0;i<S.size()-2;++i) {
    if(S[i]==S[i+2]) {
      ans1 = i+1;
      ans2 = i+3;
      break;
    }
  }
  cout<<ans1<<" "<<ans2<<endl;
}



Measured memory_bytes: 3688
#!/usr/bin/env python3
_ = int(input())
even = 0
odd = 0
for a in map(int, input().split()):
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
ans = odd % 2 == 0 or (even == 0 and odd == 1)
print(['NO', 'YES'][ans])

Measured memory_bytes: 11104
N = int(input())
T,A = map(int,input().split())
H = [int(i) for i in input().split()]
 
res = - 1
res_val = 100000
for i in range(N):
    av_temp = T - H[i] * 0.006
    if res_val > abs(av_temp - A):
        res = i
        res_val = abs(av_temp - A)
 
print(res+1)

Measured memory_bytes: 3064
// #include C {
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<cmath>
// }

// #include C++ {
#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<map>
#include<set>
// }

using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 100005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
int counts[MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
//  WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		int val;
		scanf("%d", &val);
		counts[val]++;
	}
	int now = counts[0] + counts[1] + counts[2];
	int maxx = now;
	for (int k = 3; k < MAX_N; k++) {
		now += counts[k] - counts[k - 3];
		maxx = max(maxx, now);
	}
	printf("%d\n", maxx);
}

Measured memory_bytes: 640
import sys
from collections import Counter

n, k, q = map(int, sys.stdin.readline().split())
a = map(int, sys.stdin.read().split())
counter = Counter(a)

for i in range(n):
    if k - q + counter[i+1] > 0:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


Measured memory_bytes: 16336
import sys
from itertools import accumulate

input = sys.stdin.readline


def solve(H, W, D, A, Q, LR):
    position = [None] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = [0] * (H * W + 1)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = list(accumulate(mp[d::D]))

    ans = [str(mp[r] - mp[l]) for l, r in LR]
    ans = "\n".join(ans)
    return ans


def main():
    H, W, D = map(int, input().split())
    A = [tuple(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    LR = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = solve(H, W, D, A, Q, LR)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44224
s = list(input())
s1 = s.copy()
s2 = s.copy()
c1 = 0
c2 = 0
for i in range(len(s1)-1):
    if s1[i] == s1[i+1]:
        c1 += 1
        s1[i+1] = '0' if s1[i] == '1' else '1'
for j in range(len(s2)-1, 0, -1):
    if s2[j] == s2[j-1]:
        c2 += 1
        s2[j-1] = '0' if s2[j] == '1' else '1'
print(min(c1, c2))

Measured memory_bytes: 5544
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 10000

int linerSearch(int *,int ,int);


int main(){
  int S[N],T[N],n,q;
  int i,key,status,cnt=0;


  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %d",&S[i]);
  }

  scanf(" %d",&q);

  for(i=0;i<q;i++){
    scanf(" %d",&key);
    cnt+=linerSearch(S,key,n);
  }


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

  return 0;
}

int linerSearch(int *S,int key,int n){
  int i=0;
  
  while(1){
    if(S[i]==key)return 1;
    i++;
    if(i==n) return 0;
    
   
   }
  }




Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if(n <= k)
	{
		cout << n * x << endl;
	}
	else
	{
		cout << k * x + (n - k) * y << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])  

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

int main()
{
    int W, a, b;
    cin >> W >> a >> b;
    if (a > b)
        swap(a, b);

    int distace = b - a - W;

    if (distace > 0)
        cout << distace << endl;
    else
        cout << "0" << endl;
}


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

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,pi> pii;
typedef vector<int> vi;

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define INF 1999999999999999999LL

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}

const int MAX=2e5+5;

int N;
ll dpl[MAX], dpr[MAX], A[MAX], D, ret;

int main()
{
    N=in(), D=in();
    forn(i, N)
        A[i]=in(), ret+=A[i];
    ret+=(N-1)*D;
    dpr[0]=A[0];
    Forn(i, N-1)
        dpr[i]=min(dpr[i-1]+D, A[i]);
    dpl[N-1]=A[N-1];
    for(int i=N-2; i>-1; i--)
        dpl[i]=min(dpl[i+1]+D, A[i]);
    Forn(i, N-2)
        ret+=min(dpl[i], dpr[i]);
    printf("%lld\n", ret);
    return 0;
}

Measured memory_bytes: 4992
//FMC
#include <iostream>
using namespace std;

int main()
{
	int n, a[4][13],p;
	char s;
	cin >> n;
	
	for(int j = 0; j < 4; j++)
		for(int i = 0; i < 13; i++)
			a[j][i] = 0;
	
	for(int i = 0; i < n; i++){
		cin >> s >> p;
		switch(s){
			case 'S':
				a[0][p-1] = 1;
				break;
			case 'H':
				a[1][p-1] = 1;
				break;
			case 'C':
				a[2][p-1] = 1;
				break;
			case 'D':
				a[3][p-1] = 1;
				break;
		}
	}
	
	for(int j = 0; j < 4; j++){
		switch(j){
			case 0:
				s = 'S';
				break;
			case 1:
				s = 'H';
				break;
			case 2:
				s = 'C';
				break;
			case 3:
				s = 'D';
				break;
		}
		for(int i = 0; i < 13; i++){
			if(a[j][i] == 0)
			cout << s << " " << i+1 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3020
n,k=map(int,input().split())
*s,=input()
g=[]
t=1
for i in range(1,n):
 if s[i]==s[i-1]:t+=1
 else:g.append(t);t=1
g.append(t)
for i in range(1,len(g)):g[i]+=g[i-1]
g=[0]+g+[g[-1]]
print(max(g[i]-g[max(0,i-2*k-1)]for i in range(s[0]=='1',len(g),2)))

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

#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define ll long long 

int main() {
    IOS;
    int n;
    int a[101];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n);
    int cnt = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (a[i] + a[j] > a[k] && (a[i] != a[j]) && (a[i] != a[k]) && (a[j] != a[k])) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt;
    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,ans=0;
	cin>>x;
	while(x>=500){
		ans+=1000;
		x-=500;
	}
	while(x>=5){
		ans+=5;
		x-=5;
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PII pair < int, int >
#define x first
#define y second
#define pb push_back
  
using namespace std;
int n, x;
set < int > S;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    while (n--){
		cin >> x;
		if (S.count(x)) S.erase(x);
		else S.insert(x);
	}
	cout << S.size();
}


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

int main() {
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int D;
    cin >> D;
    mp[D]++;
  }
  
  int M;
  cin >> M;
  bool ans = true;
  for (int i = 0; i < M; i++) {
    int T;
    cin >> T;
    if (mp[T] == 0) ans = false;
    else mp[T]--;
  }

  cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <assert.h>
#pragma warning(disable : 4996)

#define N_MAX 100001
#define M_MAX 100001
#define K_MAX 100001

int N, M, K;


struct NodeInfo {
	int index;
	int dec;
	int size;
	int rank;
	NodeInfo *p;
	NodeInfo() : index(-1), dec(1), size(1), rank(0), p(NULL) {}
};

NodeInfo infos[N_MAX];

int GetGroupIndex(NodeInfo *ni) {
	while (ni->p != NULL) {
		ni = ni->p;
	}
	return ni->index;
}
void Merge(NodeInfo *a, NodeInfo *b) {
	int ai = GetGroupIndex(a);
	int bi = GetGroupIndex(b);
	if (ai != bi) {
		if (infos[ai].rank < infos[bi].rank) {
			int tmp = ai;
			ai = bi;
			bi = tmp;
		}
		infos[bi].p = &infos[ai];
		infos[ai].size += infos[bi].size;
		if (infos[ai].rank < infos[bi].rank + 1) {
			infos[ai].rank = infos[bi].rank + 1;
		}
	}
	a->dec += 1;
	b->dec += 1;
}

int main(void) {
	scanf("%d %d %d", &N, &M, &K);
	for (int i = 0; i <= N; ++i) {
		infos[i].index = i;
	}
	// friend ship
	for (int i = 0; i < M; ++i) {
		int A, B;
		scanf("%d %d", &A, &B);
		Merge(&infos[A], &infos[B]);
	}
	// block ship
	for (int i = 0; i < K; ++i) {
		int C, D;
		scanf("%d %d", &C, &D);
		if (GetGroupIndex(&infos[C]) == GetGroupIndex(&infos[D])) {
			++infos[C].dec;
			++infos[D].dec;
		}
	}
	for (int i = 1; i <= N; ++i) {
		int gi = GetGroupIndex(&infos[i]);
		printf("%d ", infos[gi].size-infos[i].dec);
	}
	return 0;
}
 

Measured memory_bytes: 3072
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

/* we choose at least k numbers from (0,N), how
 * many sums possible ?
 * k<=n
 * nCr(n,k) + nCr(n,k+1) + ... nCr(n,n) sets,
 * but _not_ every set has distinct sum.
 * Sets of diff size have diff sums.
 * So, how much sets in one size have same sum?
 *
 * Example, k=2, n=4
 * 1+2=3
 * 1+3=4
 * 1+4=5
 * 2+3=5
 * 2+4=6
 * 3+4=7
 * We can build all sums between smallest and biggest.
 * Smallest is 1+2+...+k
 * Biggest is n+n-1+n-2+n-(k-1)
 * ...
 */
void solve() {
    cini(n);
    cini(k);

    const int MOD=1e9+7;
    int ans=0;
    for(int i=k; i<=n+1; i++) { /* i=number of choosen numbers */
        int mi=((i-1)*i)/2; /* min sum of choosen numbers: 0+1+2.. */
        int ma=n*i - ((i-1)*i)/2; /* max sum of choosen numbers: n-0+n-1+n-2... */
        ans+=ma-mi+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, LR):
    LR.sort(key=lambda x: x[1])
    LR.sort(key=lambda x: x[0])


    lc = []
    l = 0
    r = INF
    for i in range(N):
        l_, r_ = LR[i]
        l = max(l, l_)
        r = min(r, r_)
        lc.append((l, r))
    
    rc = []
    l = 0
    r = INF
    for i in range(N-1, -1, -1):
        l_, r_ = LR[i]
        l = max(l, l_)
        r = min(r, r_)
        rc.append((l, r))
    
    def c(l, r):
        return max(0, r-l+1)

    ans = 0
    for i in range(N-1):
        ans = max(ans, c(*lc[i]) + c(*rc[N-1-1-i]))
    for i in range(N):
        tmp = c(*LR[i])
        l, r = (0, INF)
        if i != 0:
            l = max(l, lc[i-1][0])
            r = min(r, lc[i-1][1])
        if i != N-1:
            l = max(l, rc[N-1-i][0])
            r = min(r, rc[N-1-i][1])
            
        tmp += c(l, r)
        ans = max(ans, tmp)

    return ans


def main():
    N = read_int()
    LR = [read_int_n() for _ in range(N)]
    print(slv(N, LR))


if __name__ == '__main__':
    main()


Measured memory_bytes: 97368
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,k;
char s[100000+10];
int l,r;
int num_z;
int most=-inf;
bool zero=0;
int main()
{
    cin>>n>>k;
    cin>>s;
    if(s[0]=='0')	num_z++;
    while(1)
    {
        bool if_break=0;
        for(;;r++)
        {
            if(r>=n)
            {
                if_break=1;
                break;
            }
            if(s[r]=='1')
            {
                zero=1;
            }
            else
            {
                if(zero)
                {
					zero=0;
                    num_z++;
                    if(num_z>k) break;
                }
            }
            most=max(most,r-l+1);
        }
        if(num_z>k)
        {
            for(;;l++)
            {
                if(s[l]=='0')
                {
                    zero=1;
                }
                else
                {
                    if(zero)
                    {
                        zero=0;
                        num_z--;
                		if(num_z<=k) break;
                    }
                }
            }
        }
        if(if_break)    break;
    }
    cout<<most;
    return 0;
}

Measured memory_bytes: 384
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Measured memory_bytes: 122268
Scanf.scanf "%d" (fun n ->
    let xyp = Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun x y p -> x, y, p)) in

    let hp = Array.init (1 lsl n) (fun bit ->
        let rec loop j acc =
            if j = n then acc else
                if bit land (1 lsl j) = 0 then loop (j + 1) acc else
                    let _, k, _ = xyp.(j) in
                    loop (j + 1) (k :: acc)
        in
        let l = loop 0 [] in
        Array.init n (fun i ->
            let _, me, p = xyp.(i) in
            let rec loop acc = function
                | [] -> acc * p
                | k :: tl -> loop (min acc (abs (k - me))) tl
            in
            loop (abs me) l
        )
    )
    in
    let vp = Array.init (1 lsl n) (fun bit ->
        let rec loop j acc =
            if j = n then acc else
                if bit land (1 lsl j) = 0 then loop (j + 1) acc else
                    let k, _, _ = xyp.(j) in
                    loop (j + 1) (k :: acc)
        in
        let l = loop 0 [] in
        Array.init n (fun i ->
            let me, _, p = xyp.(i) in
            let rec loop acc = function
                | [] -> acc * p
                | k :: tl -> loop (min acc (abs (k - me))) tl
            in
            loop (abs me) l
        )
    )
    in
    let calc h v =
        let rec loop i acc =
            if i = n then acc else
                loop (i + 1) (acc + min v.(i) h.(i))
        in
        loop 0 0
    in

    let best = Array.make (n + 1) max_int in
    best.(0) <- calc hp.(0) vp.(0);
    let rec loop i c hbit vbit =
        if i < n then (
            loop (i + 1) c       hbit          vbit;

            let li = 1 lsl i in
            let q = min (calc hp.(hbit lor li) vp.(vbit)) (calc hp.(hbit) vp.(vbit lor li)) in
            best.(c + 1) <- min best.(c + 1) q;
            loop (i + 1) (c + 1) (hbit lor li) vbit;
            loop (i + 1) (c + 1) hbit          (vbit lor li);
        )
    in
    loop 0 0 0 0;

    Array.iter (Printf.printf "%d\n") best;
)

Measured memory_bytes: 15100
#include <bits/stdc++.h>
#define MAX 10005
#define INF 99999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define M 1000000007
using namespace std;
 typedef long long int ll;
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <ll > vi;

int fun(int end,int p[])
{
  int x=end,sum=1;
  while(p[x]!=-1)
    sum++,x=p[x];
  return sum;
}


int main()
{
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin>>a>>b;
  if(abs(a-b)>=2)
  {
    cout<<0<<endl;
    return 0;
  }
  ll p1=1,p2=1;
  for(int i=2;i<=a;i++)
    p1=(p1*i)%M;
  for(int i=2;i<=b;i++)
    p2=(p2*i)%M;
  ll ans=(p1*p2)%M;
if(p1==p2)
  ans=(ans*2)%M;
cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            if (i * 500 + j * 100 + k * 50) == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include<bits/stdc++.h> 
#include<cstring>
#include<utility>
#define ll long long
using namespace std;
 
 ll mx(vector<ll> &A, vector<vector<ll> > &dp, int i, int j)
 {
 	if(dp[i][j]!=-1) return dp[i][j];
 	if(i==j) dp[i][j]= A[i];
 	else if(i==j-1) dp[i][j] = max(A[i], A[j]);
 	else dp[i][j] = max(A[i] + min(mx(A, dp, i+2, j), mx(A, dp, i+1, j-1)), 
	 A[j] + min(mx(A, dp, i, j-2),mx(A, dp, i+1, j-1) ));
	 
	 return dp[i][j];
 }
int main()
{
   int n;
   cin>>n;
   vector<ll> A;
   for(int i =0;i<n;i++)
   {
   	int a;
   	cin>>a;
   	A.push_back(a);
   }
   vector<vector<ll> > dp;
   vector<ll> temp;
   for(int i =0;i<n;i++)
   temp.push_back(-1);
   
   for(int i =0;i<n;i++)
   dp.push_back(temp);
   
   ll x = mx(A, dp, 0, n-1);
   ll sum=0;
   for(int i =0;i<n;i++)
   sum+=A[i];
   
   ll y = sum - x;
   
   cout<<x-y;
	return 0;
}

Measured memory_bytes: 72704
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
const int N = 1000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll a,b,c;
cin>>a>>b>>c;
cout<<max(0ll,c-(a-b));
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    string ans = "";
    rep(i, S.size()) {
        ans.push_back('x');
    }

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


Measured memory_bytes: 3616
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

H, W, K = reads()
P = 10**9 + 7

M = W + 100
fib = [0] * M
fib[0] = fib[1] = 1
for i in range(M-2):
  fib[i+2] = (fib[i] + fib[i+1]) % P

@functools.lru_cache(100000)
def solve(h, k):
  if h == 0:
    return 1 if k == 1 else 0
  if k == 1:
    return (solve(h-1, 1) * fib[W-1] + solve(h-1, 2) * fib[W-2]) % P
  elif k == W:
    return (solve(h-1, W) * fib[W-1] + solve(h-1, W-1) * fib[W-2]) % P
  else:
    return (solve(h-1, k) * fib[k-1] * fib[W-k]
      + solve(h-1, k-1) * fib[k-2] * fib[W-k]
      + solve(h-1, k+1) * fib[k-1] * fib[W-k-1]) % P

if W == 1:
  print(1); exit()
print(solve(H, K))



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

using namespace std;

typedef long long int ll;
#define MOD 1'000'000'007
int main()
{
	int n; cin >> n;
	ll both = 0;
	ll onlyZero = 1;
	ll onlyOne = 1;
	ll none = 8;

	for(int i = 1; i < n; ++i)
	{
		ll newBoth = (((both * 10LL)%MOD + onlyZero) % MOD + onlyOne) % MOD;
		ll newOnlyZero = (none + (onlyZero * 9LL) % MOD ) % MOD;
		ll newOnlyOne = (none + (onlyOne * 9LL) % MOD ) % MOD;
		ll newNone = (none * 8LL ) % MOD;


		both = newBoth;
		onlyZero = newOnlyZero;
		onlyOne  = newOnlyOne;
		none     = newNone;
	}

	cout << both;

	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int in(){int k;cin>>k;return k;}
inline int low(int x){return x&(-x);}
char s[N],a[N],b[N];int n,m;
typedef std::pair<int,int> P;
#define mk make_pair
inline void add(int &x,int y){if((x+=y)>=YL)x-=YL;}
int check(int mid)
{
	int p=mid;
	for(int i=1;i<=m;++i)
		if(s[p]==a[i])
		{
			p+=b[i]=='L'?-1:1;
			if(!p)return -1;
			else if(p>n)return 1;
		}
	return 0;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m>>s+1;
	for(int i=1;i<=m;++i)cin>>a[i]>>b[i];
	int l=1,r=n,ans=0;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(check(mid)==-1)ans=mid,l=mid+1;
		else r=mid-1;
	}
	int res=n-ans;l=1,r=n,ans=n+1;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(check(mid)== 1)ans=mid,r=mid-1;
		else l=mid+1;
	}
	res-=n-ans+1;printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 896