akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s,t;
  cin >> s>> t;
  t.pop_back();
  if(s==t) cout << "Yes" << endl;
  else cout << "No" << endl;
    
  return 0;     
}


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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

lli n, k, zeros, ne, po;
vector<lli> neg, pos;

lli getless(lli m)
{
    lli l=0, r=po-1, mid, re=po;
    while(l<=r){
        mid = (l+r)/2;
        if(pos[mid] >= m){
            re = mid;
            r = mid-1;
        }
        else{
            l = mid+1;
        }
    }
    //cout << po-re-1 << endl;
    return po-re;
}

lli getneg(lli m)
{
    lli l=0, r=ne-1, mid, re=0;
    while(l<=r){
        mid = (l+r)/2;
        if(neg[mid] > m){
            r = mid-1;
        }
        else{
            re = mid;
            l = mid+1;
        }
    }
    return re;
}

lli getpos(lli m)
{
    lli l=0, r=po-1, mid, re=0;
    while(l<=r){
        mid = (l+r)/2;
        if(pos[mid] > m){
            r = mid-1;
        }
        else{
            re = mid;
            l = mid+1;
        }
    }
    return re;
}

lli lesscnt(lli mid)
{
    if(mid == 0LL){
        return po*ne+zeros;
    }
    if(mid < 0LL){
        lli ret = 0;
        mid = -mid;
        for(auto x: neg){
            lli y = (mid+x-1)/x;
            ret += getless(y);
        }
        return ret;
    }
    else{
        lli ret = po*ne+zeros;

        for(int i=0; i<ne; i++){
            lli y = mid/neg[i];
            //cout << "neg" << endl;
            lli cc = getneg(y);
            cc = max(0LL, cc-i);
            ret += cc;
        }
        for(int i=0; i<po; i++){
            //cout << "pos" << endl;
            lli y = mid/pos[i];
            lli cc = getpos(y);
            cc = max(0LL, cc-i);
            ret += cc;
        }
        return ret;
    }
}

int main()
{
    cin >> n >> k;
    for(int i=0; i<n; i++){
        lli x;
        cin >> x;
        if(x<0) neg.push_back(-x);
        else if(x>0) pos.push_back(x);
        else zeros++;
    }
    zeros = (n*(n-1))/2 - ((n-zeros)*(n-zeros-1))/2;
    ne = neg.size();
    po = pos.size();
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());

    lli lo = -1e18, hi = 1e18, mid, ans;
    while(lo<=hi){
        mid =(lo+hi)/2;

        lli cnt = lesscnt(mid);
        if(cnt >= k){
            ans = mid;
            hi = mid-1;
        }
        else{
            lo = mid+1;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 2420
n,k=map(int,input().split())
s=input()

c='x'
if(s[k-1])=='A':
    c='a'
elif(s[k-1]=='B'):
    c='b'
else:
    c='c'

for i in range(n):
    if(i==k-1):
        print(c,sep="",end="")
    else:
        print(s[i],sep="",end="")
print()

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int a,b;
	cin>>a>>b;
	if(a-b>=0){
		cout<<a-b;
	}
	if(a-b<0){
		cout<<0;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
  for j in range(i + 1, n):
    for k in range(j + 1, n):
      if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and 2 * max(l[i], l[j], l[k]) < l[i] + l[j] + l[k]:
        ans += 1
print(ans)


Measured memory_bytes: 9192
#include <cstdio>
#include <vector>
#include <algorithm>
bool bigger (int a, int b) { return (a > b); }
void isRTriangleAndPrint (int a, int b, int c) {
	std::vector<int> list(3, 0);
	list[0]=a;list[1]=b;list[2]=c;
	sort(list.begin(), list.end(), bigger);
	if (list[0]*list[0] == list[1]*list[1]+list[2]*list[2])
		puts("YES");
	else
		puts("NO");
}

int main (int argc, char *argv[]) {
	int dataNumber;
	fscanf(stdin, "%d\n", &dataNumber);
	
	int side[3];
	for(int i = 0; i < dataNumber; ++i) {
		fscanf(stdin, "%d %d %d\n", &side[0], &side[1], &side[2]);
		isRTriangleAndPrint(side[0], side[1], side[2]);
	}
	return 0;
}

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

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
static const bool DEBUG = false;

signed main() {
	int p[62] = {};
	rep(i, 0, 62)p[i] = pow(2, i);
	for (int n; cin >> n;) {
		if (n == 0) { cout << 0 << endl; continue; }
		rrep(i, 0, 62) {
			dump(i);
			dump(p[i]);
			if (p[i] - 1 < n) {
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3268
#include<cstdio>
#include<algorithm>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
#define pc(x) __builtin_popcount(x)
int n,A,B,all;
void dfs(int x,int y,int ban){
	if(pc(ban^all)==1){printf("%d %d ",y,x^y);return;}
	for(int i=0;i<n;++i)
		if((~ban>>i&1)&&(x>>i&1))
			for(int j=0;j<n;++j)
				if((~ban>>j&1)&&i!=j){
					dfs(1<<j,y,ban|1<<i);
					dfs(x^(1<<i)^(1<<j),y^(1<<i)^(1<<j),ban|1<<i);
					return;
				}
}
int main(){
	n=gi(),A=gi(),B=gi(),all=(1<<n)-1;
	if(pc(A^B)&1)puts("YES"),dfs(A^B,A,0);
	else puts("NO");
	return 0;
}


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

using namespace std;
using ll = long long;

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

  int n;
  ll k;
  cin >> n >> k;
  vector<int> p(n);
  vector<ll> c(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 0; i < n; i++)
    cin >> c[i];

  const ll inf = 1e9;

  // loop_cnt[i] := iからスタートしてループするのにかかる回数
  // loop_score[i].size() - 1 で求められるから不要か
  vector<int> loop_cnt(n);
  // loop_cnt[i][j] := iからスタートしてj回移動した時に得られるスコア
  // vector<vector<ll>> loop_score(n, vector<ll>(n + 1, -inf));
  vector<vector<ll>> loop_score(n);
  for (int i = 0; i < n; i++) {
    int cur = i;
    ll sum = 0;
    loop_score[i].push_back(-inf);
    for (int j = 1;; j++) {
      cur = p[cur];
      sum += c[cur];
      loop_score[i].push_back(sum);
      if (cur == i) {
        loop_cnt[i] = j;
        break;
      }
    }
  }

  ll ans = *max_element(c.begin(), c.end());

  for (int i = 0; i < n; i++) {
    ll l = loop_cnt[i];
    // cerr << l << endl;

    auto score = loop_score[i];

    if (k <= l) {
      // 一周出来ない時
      ans = max(ans, *max_element(score.begin(), score.begin() + k + 1));
    } else if (score[l] < 0) {
      // 一周する価値が無い時
      ans = max(ans, *max_element(score.begin(), score.end()));
    } else {
      ll m = k / l;
      ans = max(ans,
                score[l] * (m - 1) + *max_element(score.begin(), score.end()));
      ans = max(ans, score[l] * m +
                         max(0ll, *max_element(score.begin(),
                                               score.begin() + k % l + 1)));
    }
  }

  cout << ans << endl;

  return 0;
}


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

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

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

  vector<long long> a(n);
  vector<long long> b(n);

  rep (i, n) {
    cin >> a[i];
  }

  int index = n / 2;
  int next_ = n % 2 ? 1 : -1;

  b[index] = a[0];

  rep (t, n-1) {
    int window = t / 2 + 1;
    // cout << window << endl;

    if (next_ == 1) {
      b[index+window*next_] = a[t+1];
      next_ = -1;
    }
    else {
      b[index+window*next_] = a[t+1];
      next_ = 1;
    }
  }

  rep (i, n) {
    cout << b[i];
    if (i != b.size()) cout << ' ';
    else cout << endl;
  }
}


Measured memory_bytes: 5248
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <string.h>
#define inf 0x7fffffff
using namespace std;


long long a,b,c,n,m,d,k,l[300010],o[300100],i;

int j[201000][10]={{1,0,-1,0},{0,-1,0,1}};
long long z[110][60],x,y;
char r[300],r1[600];
//deque<int> d;
vector<int> v[101000];
//A 65 a 97
//z 122 Z 90
/*struct P
{
    int x,y;
    bool operator<(const P &a)const
    {
        //printf("#%d %d\n",o[x],o[y]);
        return min(o[x],o[y])>min(o[a.x],o[a.y]);
    }
};*/
queue<int> q;

long long f(long long t,long long w)
{
    if(t==a&&w==b) return 1;
    if(t==a) return 0;
    if(z[t][w]>=0) return z[t][w];
    return z[t][w]=f(t+1,(w+o[t])%2)+f(t+1,w);
}

int main()
{
    memset(z,-1,sizeof(z));
    c=2;
    scanf("%lld %lld",&a,&b);
    for(long long t=0;t<a;t++)
        scanf("%lld",&o[t]);
    printf("%lld",f(0,0));
}




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

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

    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]||s[3]==s[4]){

        cout<<"Bad"<<endl;

    }else{

        cout<<"Good"<<endl;
    }

  return 0;
}


Measured memory_bytes: 256
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

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

    ll a[n];
    f(i,n) cin>>a[i];

    ll mini=INT_MAX;

    for(ll p=1;p<107;p++)
    {
        ll v=0;
        f(i,n) v+=(a[i]-p)*(a[i]-p);
        mini=min(mini,v);
    }
    cout<<mini<<"\n";

    return;
}

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

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    int n;
    cin>>n;
    set<string>tree;
    int ans=0;
    rep(i,n){
    string s;
    cin>>s;
    if(tree.find(s)==tree.end()){
        ans++;
        tree.emplace(s);
    }
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 19232
n, m, x = map(int, input().split())
books_info = []
price_info = []
for i in range(n):
    c, *a = map(int, input().split())
    books_info.append(a)
    price_info.append(c)
pattern_list = []
for j in range(2 ** n):
    tmp_list = []
    for k in range(n):
        if ((j >> k) & 1):
            tmp_list.append(k)
        else:
            pass
    pattern_list.append(tmp_list)
book_price = 10 ** 5 * 12 + 1
for pattern in pattern_list:
    # 全ての参考書を買わない=len(pattern)が0の場合はスキップする
    if len(pattern) == 0:
        continue
    is_ok = False
    price = 0
    for j in range(m):
        m_sum = 0
        price_sum = 0
        for k in pattern:
            m_sum += books_info[k][j]
            price_sum += price_info[k]
        if m_sum >= x:
            is_ok = True
        else:
            is_ok = False
            break
        price = price_sum
    if is_ok == True:
        book_price = min(price, book_price)
    else:
        pass
print(book_price if book_price != 10 ** 5 * 12 + 1 else -1)



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  string X;
  llong cnt = 0;

  cin >> N >> X;
  reverse(ALL(X));
  for (auto x: X) {
    cnt += x == '1';
  }

  vector<vector<llong>> moduro(N, vector<llong>(2)), rui(N + 1, vector<llong>(2)), beki(N + 1, vector<llong>(2));
  beki[0][0] = 1;
  beki[0][1] = 1;
  for (int i = 0; i < N; ++i) {
    if (cnt - 1 > 0) {
      moduro[i][0] = beki[i][0] * (X[i] - '0') % (cnt - 1);
      rui[i + 1][0] = (rui[i][0] + moduro[i][0]) % (cnt - 1);
      beki[i + 1][0] = beki[i][0] * 2 % (cnt - 1);
    }
    moduro[i][1] = beki[i][1] * (X[i] - '0') % (cnt + 1);
    rui[i + 1][1] = (rui[i][1] + moduro[i][1]) % (cnt + 1);
    beki[i + 1][1] = beki[i][1] * 2 % (cnt + 1);
  }

  for (int i = N - 1; i >= 0; i--) {
    llong m = X[i] == '0' ? cnt + 1 : cnt - 1;
    llong mid = X[i] == '0' ? 1 : 0;
    if (m == 0) {
      cout << 0 << endl;
      continue;
    }
    llong ans = 1;
    llong x = ((rui[N][mid] - rui[i + 1][mid]) + (beki[i][mid] * mid % m) + (rui[i][mid] - rui[0][mid]) + m) % m;

    while (x > 0) {
      ans++;
      x %= (__builtin_popcount(x));
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 36404
#ライブラリの点検
class Data():
    def __init__(self):
        self.power=1
        self.rev=1     
class Combi():
    def __init__(self,N,mod):
        self.lists=[Data() for _ in range(N+1)]
        self.mod=mod  
        for i in range(2,N+1):
            self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
        self.lists[N].rev=pow(self.lists[N].power,self.mod-2,self.mod)
        for j in range(N,0,-1):
            self.lists[j-1].rev=((self.lists[j].rev)*j)%self.mod

    def combi(self,K,R):
        if K<R:
            return 0
        else:
            return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev))%self.mod

######################
N,M,K=map(int,input().split())
mod=998244353
ans=0
C=Combi(2*10**5,mod)
for i in range(K+1):
    ans+=M*C.combi(N-1,i)*pow(M-1,N-1-i,mod)
print(ans%mod)
######################

Measured memory_bytes: 55168
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := sc.Text()

	d := 'a' - 'A'
	for _, r := range s {
		rr := r
		if 'A' <= r && r <= 'Z' {
			rr = r + d
		} else if 'a' <= r && r <= 'z' {
			rr = r - d
		}
		fmt.Printf("%c", rr)
	}
	fmt.Println()
}



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

const int N = (int) 1e6 + 7;



int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr), cout.tie(nullptr);
    
    int n;
    cin>>n;
    int k=n/2;
    cout<<std::setprecision(20)<< double(n-k)/n;
    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

int	main() {
	int N;
	cin >>N;
	vector<vector<int>> C(10, vector<int> (10, 0));
	for (int i=1; i<=N; i++) {
		int c1=i%10;
		int c2=i;
		while (c2>9)
			c2 /=10;
		C.at(c1).at(c2)++;
	}
	int S=0;
	for (int i=1; i<=9; i++)
		for (int j=1; j<=9; j++)
			S +=C.at(i).at(j)*C.at(j).at(i);
	cout <<S <<endl;
	return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    string s;
    cin>>n>>s;
    int R=0;
    int B=0;
    for (char c: s) {
	if (c=='R') R++;
	if (c=='B') B++;
    }

    cout<<(R>B ? "Yes\n" : "No\n");
    
    return 0;
}


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

int main(){
	long long t;
	cin >> t;
	long long sum = 0;
	int max = -1000000;
	int min = 1000000;
	for(int i = 0; i < t; i++){
		int temp;
		cin >> temp;
		if(temp > max)
			max = temp;
		if(temp < min)
			min = temp;
		sum += temp;
	}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

#define REP(i,m,M) for(int i=m; i<M; i++)
#define REPR(i,M,m) for(int i=M; i>m; i—-)
#define REPLL(i,m,M) for(ll i=m; i<M; i++)
#define REPLLR(i,M,m) for(ll i=M; i>m; i—-)
#define ALL(v) v.begin(),v.end()

int main(int argc, const char * argv[]) {
    int N, K, Q;
    cin >> N >> K >> Q;
    vll A(N);
    for (int n=0; n<N; ++n) {
        cin >> A[n];
    }
    
    ll Res = INFLL;
    for (ll Y : A) {
        vll c;
        multiset<ll> ms;
        for (int n=0; n<N; ++n) {
            if (A[n] < Y) {
                int l = c.size();
                if (l >= K) {
                    sort(c.begin(), c.end());
                    auto it = c.begin();
                    for (int k=0; k<l-K+1; ++k, ++it) {
                        ms.insert(*it);
                    }
                }
                c.clear();
            } else {
                c.push_back(A[n]);
            }
        }
        int l=c.size();
        if (l >= K) {
            sort(c.begin(), c.end());
            auto it = c.begin();
            for (int k=0; k<l-K+1; ++k, ++it) {
                ms.insert(*it);
            }
        }
        if (ms.size() < Q) continue;
        auto it = ms.begin();
        for (int q=0; q<Q-1; ++q) ++it;
        if (*it-Y < Res) Res = *it-Y;
    }
    
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
using namespace std;

struct ice{
	int money;
	double v;
	double ms;
}a[4];

bool cmp(ice a, ice b)
{
	return a.ms<b.ms;
}

int main()
{
	int q, h, s, d;
	double n;
	scanf("%d%d%d%d%lf", &q, &h, &s, &d, &n);
	a[0].v = 0.25, a[0].money = q, a[0].ms = q*1.0/0.25;
	a[1].v = 0.5, a[1].money = h, a[1].ms = h*1.0/0.5;
	a[2].v = 1, a[2].money = s, a[2].ms = s*1.0/1.0;
	a[3].v = 2, a[3].money = d, a[3].ms = d*1.0/2.0;
	sort(a, a+4, cmp);
	long long sum = 0;
	for(int i=0; i<4; i++)
	{
		if(a[i].v>n||n-a[i].v<0)
			continue;
		int mid = n/a[i].v;
		while(mid--)
		{
			sum += a[i].money;
			n -= a[i].v;
		}
		//sum += mid*a[i].money;
		//n -= a[i].v*mid;
		//if(n == 0)
			//break;
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())
w = [int(ball) for ball in sys.stdin.readline().rstrip().split()]

total = sum(w)
half = total // 2

cur_sum = 0
s_1 = 0

for i in range(n):
  pre_sum = cur_sum
  cur_sum += w[i]
  if cur_sum > half:
    break

pre_diff = abs(2 * pre_sum - total)
cur_diff = abs(2 * cur_sum - total)

print(min(pre_diff, cur_diff))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

class KMP {
public:
    string pattern;
    int plen;
    vector<int> table;

    // tからsを探す
    KMP(const string& s) : pattern(s), plen((int)pattern.size()), table(plen + 1) {
        table[0] = -1;
        int j = -1;
        for (int i = 0; i < plen; i++) {
            while (j >= 0 && pattern[i] != pattern[j]) j = table[j];
            if (pattern[i + 1] == pattern[++j]) table[i + 1] = table[j];
            else table[i + 1] = j;
        }
    }

    // マッチする左端の箇所
    vector<int> search(const string& text) {
        vector<int> res;
        int head = 0, j = 0, tlen = (int)text.size();
        while (head + j < tlen) {
            if (pattern[j] == text[head + j]) {
                if (++j != plen) continue;
                res.push_back(head);
            }
            head += j - table[j], j = max(table[j], 0);
        }
        return res;
    }
};

int main() {
    string t, p; cin >> t >> p;
    KMP kmp(p);
    for (int ans : kmp.search(t)) {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8440
#include <iostream>
using namespace std;
int main()
{
  int card[52];
  for(int i=0;i<52;i++)
    card[i]=0;

  int n;
  cin>>n;
  char s;
  int num;
  for(int i=0;i<n;i++)
  {
    cin>>s>>num;
    switch(s)
    {
      case 'S':
        card[num-1]=1;
        break;
      case 'H':
        card[13+num-1]=1;
        break;
      case 'C':
        card[26+num-1]=1;
        break;
      case 'D':
        card[39+num-1]=1;
        break;
    }
  }
for(int i=0;i<52;i++)
  {
    if(card[i]==0)
    {
      switch(i/13)
      {
        case 0:
          cout<<"S "<<i%13+1;break;
        case 1:
          cout<<"H "<<i%13+1;break;
        case 2:
          cout<<"C "<<i%13+1;break;
        case 3:
          cout<<"D "<<i%13+1;break;
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 3088
#!usr/bin/env python3
from collections import defaultdict

def main():
    #Read stdin
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    #Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t,w))

    #initialized
    d = {}
    INF = float('inf')
    #INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = q.pop(0)
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                q.append(v[0])



    for k in d.keys():
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])

if __name__ == '__main__':
    main()

Measured memory_bytes: 106856
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bits/stdc++.h>
#include <array>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
    // source code
    int a,b;
    cin >> a >> b;
    if (a > 9 || b > 9) cout << -1;
    else cout << a * b;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var k = int.Parse(_[0]);
            var x = int.Parse(_[1]);

            var minPos = (x - k + 1) >= -1000000 ? (x - k + 1) : -1000000;
            var l = Enumerable.Range(minPos, k * 2 - 1).Where(i => i <= 1000000).Select(i => i.ToString()).ToArray();

            Console.WriteLine(string.Join(" ", l));
        }
    }
}


Measured memory_bytes: 13396
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	x := nextInt()
	a := nextInt()
	b := nextInt()
	fmt.Println(SolveA(x, a, b))
}

func SolveA(x, a, b int) string {
	if  a >= b {
		return "delicious"
	} else if a + x >= b {
		return "safe"
	} else {
		return "dangerous"
	}
}

Measured memory_bytes: 640
s=input()
f=int(s[:2])
g=int(s[2:])
if 0<f<13 and 0<g<13:
  print('AMBIGUOUS')
elif 0<f<13:
  print('MMYY')
elif 0<g<13:
  print('YYMM')
else:
  print('NA')

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

static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i=0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
    
    while(!PQ.empty()){
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first*(-1) ) continue;
        
        for(int j=0; j<adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v]==BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v] = GRAY;
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << i << " " << (d[i]==INFTY ? -1 : d[i]) << endl;
    }
}

int main(){
    int k,u,v,c;
    
    //cout << "testing" << endl;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    
    
    dijkstra();
    
    return 0;
}

Measured memory_bytes: 7960
#define max(x,y)((x)>(y)?(x):(y))
#define min(x,y)((x)<(y)?(x):(y))
char map[501*500];
DH[501];
main(){
	int H,W,i,x,y,w,h,S;
	for(;scanf("%d%d\n",&H,&W),H;){
		for(i=0;i<(W+1)*H;i++)
			map[i]=getchar();
		memset(DH,0,sizeof(DH));
		S=0;
		for(y=1;y<=H;y++){
			for(x=1;x<=W;x++){
				if(map[(y-1)*(W+1)+(x-1)]=='.'){
					DH[x]++;
					h=H;
					for(w=1;h;w++){
						h=min(h,DH[x-w+1]);
						S=max(S,w*h);
					}
				}else{
					DH[x]=0;
				}
			}
		}
		printf("%d\n",S);
	}
	exit(0);
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  string s,out="";cin>>s;
  vector<bool> used(26,false);
  if(s.size()<26){
    out = s;
    for(int i=0;i<s.size();++i){
      int c = (int)(s[i]-'a');
      used[c] = true;
    }
    for(int j=0;j<used.size();++j){
      if(!used[j]){
        out += (char)(j+'a');
        break;
      }
    }
  } else {
    int sid =-1;
    int aid =-1;
    for(int j=0;j<s.size();++j){
      int cid = (int)(s[s.size()-1-j] - 'a');
      used[cid] = true;
      for(int i=cid+1;i<26;++i){
        if(used[i]){
          sid = s.size()-1-j;
          aid = i;
          break;
        }
      }
      if(sid>-1)break;
    }
    if(sid>-1){
      out += s.substr(0,sid);
      out += (char)(aid+'a');
    } else {
      out = "-1";
    }
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder.BeginnersSelections
{
    class C_EnergyDrinkCollector
    {
        static void Main(string[] args)
        {
            WriteLine(Solve());
        }

        static long Solve()
        {
            var nm = ReadLine().Split().Select(int.Parse).ToArray();
            var dic = new SortedDictionary<long, long>();
            for (int i = 0; i < nm[0]; i++)
            {
                var ab = ReadLine().Split().Select(long.Parse).ToArray();
                if (!dic.ContainsKey(ab[0]))
                    dic.Add(ab[0], 0);
                dic[ab[0]] += ab[1];
            }

            long remain = nm[1];
            long amount = 0;
            foreach (var kv in dic)
            {
                if (remain == 0) break;
                var buyCount = Math.Min(remain, kv.Value);
                amount += kv.Key * buyCount;
                remain -= buyCount;
            }
            return amount;
        }
    }
}


Measured memory_bytes: 25252
n, m, c = (int(i) for i in input().split())
list_b = [int(i) for i in input().split()]
list_a = [[int(i) for i in input().split()] for j in range(0, n)]
count = 0
tmp = 0
for i in range(0, n):
    for j in range(0, m):
        tmp += list_b[j] * list_a[i][j]
    tmp += c
    if tmp > 0: count += 1
    tmp = 0
print(count)

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, a, b, c, d;
	long long loc, lod, hic, hid;
	
	cin>>n>>a>>b>>c>>d;
	
	for (loc = n - 1, lod = 0, hic = 0, hid = n - 1; loc >= 0; --loc, --lod, --hic, --hid)
	{
		if (loc * c + lod * d <= b - a && b - a <= hic * c + hid * d)
		{
			cout<<"YES\n";
			return 0;
		}
	}
	cout<<"NO\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n, t;
int a[120000];

int main() {
	scanf("%d%d", &n, &t);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	int mn = 1e9;
	int mx = 0;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		mn = min(mn, a[i]);
		int d = a[i] - mn;
		if (d > mx)
			mx = d, cnt = 1;
		else if (d == mx)
			++cnt;
	}
	cout << cnt << "\n";
	return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main () {
  int n;
  cin >> n;
   
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  
  int cnt = 1;
  sort(s.begin(),s.end());
  rep(i,n-1) if (s[i] != s[i+1]) cnt++;
  cout << cnt;
}

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

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

    vector<vector<pair<int,int>>> G(n);

    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;    b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }

    queue<int> q;
    q.push(0);

    vector<int> ans(n,-1);
    ans[0] = 0;
    while(!q.empty()){
        int now = q.front();    q.pop();

        for(pair<int,int> p: G[now]){
            int next = p.first;
            int dist = p.second;
            if(ans[next]!=-1) continue;

            if(dist%2==1) ans[next] = ans[now]^1;
            else ans[next] = ans[now];

            q.push(next); 
        }
    }
    for(int i=0;i<n;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 9436
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	string n;
	cin >> n;

	if (n.at(0) == n.at(2)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  REP(i, N) cin >> h[i];
  int ans = 0;
  int now = 0;
  REP(i, N) {
    if (now < h[i]) ans += h[i] - now;
    now = h[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1000000007;

int main(){
    int n,x;
    cin >> n;
    string ans;
    int temp;
    int even = 0;
    int odd = 0;
    rep(i,n){
        cin >> temp;
        (temp % 2 == 0)?even++:odd++;
    }
    if (odd % 2 == 0 )ans = "YES";
    else ans = "NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S=list(input())
all=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for s in all:
  if s not in S:
    print(s)
    exit()
print('None')

Measured memory_bytes: 3956
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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


int n;
string s;

void input(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> s;
    
    
    
}





void solve(){
    
    
    string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    ABC = ABC + ABC + ABC;
    
    string ans = "";
    
    map<char,char> ROT{};
    for (int i = 0; i < 26; i++) ROT[ABC[i]] = ABC[i+n];
    
    for (int i = 0; i < s.size(); i++) ans += ROT[s[i]];
    
    cout << ans << endl;
    
    
    
    
    
    

}



signed main() {
    
    input();
    solve();
    return 0;
}



Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> aSet = new HashSet<>();
        for(int i = 0; i < n; i++) aSet.add(Integer.parseInt(sc.next()));
        System.out.println(aSet.size() == n ? "YES" : "NO");
    }
}


Measured memory_bytes: 68500
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s = [c for c in gete()]
    ans = 0
    a = 0
    cur = 0
    while cur < len(s) - 2:

        if "".join(s[cur:cur + 3]) == "ABC":
            ans += a + 1
            cur += 2
            s[cur] = "A"
        else:
            if s[cur] == "A":
                a += 1
            else:
                a = 0
            cur += 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 60108
def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            if (4*h*n-N*n-N*h) == 0:
                continue
            w = (N*h*n)/(4*h*n-N*n-N*h)
            if w > 0 and w.is_integer():
                return print(h, n, int(w))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a;
    long long s=0;
    cin>>n>>m;
    while(m--)
    {
        cin>>a;
        s+=a;
    }
    if(s>n) cout<<"-1\n";
    else cout<<n-s<<"\n";
}

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

int main() {
  long n,ans;
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);
  for(long i=0;i<n;i++) cin >> a[i] >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(n%2==0) {
    long m1_min=a[n/2-1],m1_max=b[n/2-1],m2_min=a[n/2],m2_max=b[n/2];
    ans=m1_max+m2_max-m1_min-m2_min+1;
  } else {
    ans=b[n/2]-a[n/2]+1;
  }
  cout << ans << endl;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int a[80];
long long dp[80];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    dp[0] = 1000;
    for (int i=1; i<n; i++) {
        dp[i] = dp[i-1];
        for (int j=0; j<i; j++)
            dp[i] = max(dp[i], dp[j] / a[j] * a[i] + dp[j] % a[j]);
    }

    cout << dp[n-1] << "\n";

    return 0;
}


Measured memory_bytes: 3636
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int cnt = 0;
	rep(i, 101) {
		if (a <= i && i <= b) {
			if (c <= i && i <= d) {
				cnt++;
			}
		}
	}
	if (cnt) cnt -= 1;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int N,M,B[MAXN];
pair<int,int> A[MAXN];
vector<pair<int,int> > To[MAXN];
bool flag[MAXN],Mark[MAXN];
void dfs(int x)
{
	flag[x]=true;
	for (int i=0;i<To[x].size();++i)
	{
		int to=To[x][i].first;
		int v=To[x][i].second;
		if (!flag[to])
		{
			dfs(to);
			if (B[to])
			{
				Mark[v]=true;
				B[x]^=1;
			}
		}
	}
}
int main()
{
	cin>>N>>M;
	for (int i=1;i<=N;++i) scanf("%d%d",&A[i].first,&A[i].second);
	sort(A+1,A+1+N);
	for (int i=1;i<=N+1;++i) B[i]=A[i-1].second^A[i].second;
	for (int i=1;i<=M;++i)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		l=lower_bound(A+1,A+1+N,make_pair(l,-1))-A;
		r=upper_bound(A+1,A+1+N,make_pair(r,2))-A;
		if (l>=r) continue;
		To[l].push_back(make_pair(r,i));
		To[r].push_back(make_pair(l,i));
	}
	dfs(N+1);
	for (int i=1;i<=N;++i)
		if (!flag[i])
		{
			dfs(i);
			if (B[i]) {printf("-1\n");return 0;}
		}
	int Cnt=0;
	for (int i=1;i<=M;++i) Cnt+=Mark[i];
	cout<<Cnt<<endl;
	for (int i=1;i<=M;++i) if (Mark[i]) printf("%d ",i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
#define int long long 
using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;
  
  vector<pair<int, int>> P(N);
  int A, B;
  for( int i = 0; i < N; i++ ){
    cin >> A >> B;
    P.at(i) = make_pair(A, B);
  }
  sort(P.begin(), P.end());
  
  priority_queue<int> que;
  int cnt = 0; //Pをどこまで見たか
  int ans = 0;
  for( int i = 1; i <= M; i++ ){
    while( cnt < N && P.at(cnt).first <= i  ){
      que.push(P.at(cnt).second);
      cnt++;
    } 
    if( !que.empty() ){
      ans += que.top();
      que.pop();
    }
  }
  
  cout << ans << endl;
  
  
  
}
  

  

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int main() {
  cout << setprecision(10);
  int N, R;
  cin >> N >> R;
  int ret = R;
  if (N <= 10) ret += (10 - N) * 100;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//const ll MOD  = 998244353;
//ll MOD;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}



int main(void){
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> AB(N);
  rep(i, N) cin >> AB[i].f >> AB[i].s;
  sort(AB.begin(), AB.end());
  
  ll ans = 0;
  priority_queue<ll> pque;
  int j = 0;
  for(int i = 1; i <= M; i++){
    while(j < N){
      if(AB[j].f <= i){
        pque.push(AB[j].s);
        j++;
      }else{
        break;
      }
    }
    if(pque.empty()) continue;
    ans += pque.top();
    pque.pop();
  }
  cout << ans << endl;


}


Measured memory_bytes: 2936