akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<ll> a(N*3);
    rep(i,N*3) cin>>a[i];

    vector<ll> S(N*2+1,0);
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    rep(i,N){
        S[i+1]=S[i]+a[i];
        que1.push(a[i]);
    }
    for(int i=N;i<2*N;i++){
        ll mi=que1.top();
        if(a[i]>mi){
            S[i+1]=S[i]-mi+a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else S[i+1]=S[i];
    }

    vector<ll> T(N*2+1,0);
    priority_queue<ll> que2;
    rep(i,N){
        T[i+1]=T[i]+a[N*3-1-i];
        que2.push(a[N*3-1-i]);
    }
    for(int i=N;i<N*2;i++){
        ll ma=que2.top();
        if(a[N*3-1-i]<ma){
            T[i+1]=T[i]-ma+a[N*3-1-i];
            que2.pop();
            que2.push(a[N*3-1-i]);
        }
        else T[i+1]=T[i];
    }

    ll res=-(1LL<<60);
    for(int i=N;i<=2*N;i++){
        res=max(res,S[i]-T[N*3-i]);
    }

    cout<<res<<endl;
}

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define pb push_back 
 #define fo(i,n) for(int i=0;i<n;i++)
#define ll long long 
#define int long long 
#define Mod 1000000009 
#define MAX 4294967296  // 2^32
const int M=1e9+7;
#define ip pair<int,int>
#define test(t) ll t;cin>>t;while(t--)
  
using namespace std;
void solve(){
float n,k,m;
cin>>n>>k>>m;
float t=n/m;
if(t<=k)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}

signed main(){


    // std::string binary = std::bitset<8>(n).to_string();
    ios::sync_with_stdio(0);
    cin.tie(0);
  solve();
  


}

Measured memory_bytes: 3736
a, b, c, d = map(int, input().split())
 
if a>=0 and c>=0:
  print(b*d)
elif b<=0 and d<=0:
  print(a*c)
elif b<=0 and c>=0:
  print(b*c)
elif a>=0 and d<=0:
  print(a*d)
elif a<=0 and b>=0 and c<=0 and d>=0:
  print(max([a*c, b*d]))
elif b<=0 and c<=0 and d>=0:
  print(a*c)
elif a<=0 and b>=0 and d<=0:
  print(a*c)
elif a<=0 and b>=0 and c>=0:
  print(b*d)
elif a>=0 and c<=0 and d>=0:
  print(b*d)




Measured memory_bytes: 9164
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()
xs = sorted(xs)
diff = [0]*(m-1)
for i in range(len(xs)-1):
    diff[i] = abs(xs[i+1] - xs[i])
diff = sorted(diff)
ans = sum(diff[:m-n])
print(ans)


Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b; cin >> n >> a >> b;
    vector<ll> v(n); rep (i, n) cin >> v[i];
    sort(all(v), greater<ll>());
    ll sum = 0, ka = 0, kb = 0, k = 0;
    rep (i, a) sum += v[i];
    rep (i, n) {
        if (v[i] == v[a - 1]) {
            if (i < a) ka++;
            else kb++;
            k++;
        }
    }
    chmin(kb, (ll)b - a);
    printf("%.6lf\n", (double)sum / a);
    eprintf("%lld %lld %lld\n", ka, ka + kb, k);

    vector<vector<ll>> com(n + 1, vector<ll>(n + 1));
    com[0][0] = 1;
    rep (i, n + 1) {
        rep (j, n + 1) {
            if (i > 0) com[i][j] += com[i - 1][j];
            if (j > 0) com[i][j] += com[i][j - 1];
            if (i < 10 && j < 10) eprintf("%5lld ", com[i][j]);
        }
        if (i < 10) eprintf("\n");
    }
    ll ans = 0;
    if (v[a - 1] == v[0]) rep (i, ka, ka + kb + 1) ans += com[k - i][i];
    else ans = com[k - ka][ka];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3804
#include<cstdio>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int t;	scanf("%d",&t);
	while(t--){
		int n,k;	scanf("%d%d",&n,&k);
		static int x[100000];
		for(int i=0;i<n;i++)	scanf("%d",x+i);

		sort(x,x+n);

		static int d[100000];
		for(int i=0;i<n-1;i++)	d[i]=x[i+1]-x[i];

		sort(d,d+n-1,greater<int>());

		int len=x[n-1]-x[0];
		for(int i=0;i<k-1;i++)	len-=d[i];
		printf("%d\n",max(len,0));
	}

	return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
    if (t&1) a *= *this;
      return a;
  }
   mint inv() const { return pow(MOD-2);}
   mint& operator/=(const mint a) { return *this *= a.inv();}
   mint operator/(const mint a) const { return mint(*this) /= a;}
};
typedef vector<mint> vm;
typedef vector<vm> vvm;
  
int main() {
  int N,M;
  cin >> N >> M;
  vi a(N,0),b(M,0);
  rep(i,N) {
    cin >> a[i];
  }
  rep(i,M) {
    cin >> b[i];
  }
  vvm sum(N+1,vm(M+1,0));
  rep(i,N)rep(j,M) {
    sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j];
    if(a[i]!=b[j]) {
      continue;
    }
    sum[i+1][j+1]+=sum[i][j]+1;
  }
  mint ans = sum[N][M]+1;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 34500
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int P = 1e9 + 7,N = 200005;
inline void upd(int &x,int v){ x = (x+v>=P)?(x+v-P):(x+v); }
int dp[4005][4005],n,x[N],y[N];
int fac[N],nfac[N],inv[N];
inline int C(int n,int m){ return (LL)fac[n] * nfac[m] % P * nfac[n-m] % P; }
int main(){
	int i,j;
	fac[0] = nfac[0] = inv[0] = fac[1] = nfac[1] = inv[1] = 1;
	for (i = 2; i <= 100000; ++i)
		fac[i] = (LL)fac[i-1] * i % P,inv[i] = (LL)(P-P/i) * inv[P%i] % P,nfac[i] = (LL)nfac[i-1] * inv[i] % P;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> x[i] >> y[i],++dp[2001-x[i]][2001-y[i]];
	for (i = 1; i <= 4001; ++i)
	for (j = 1; j <= 4001; ++j) upd(dp[i][j],dp[i-1][j]),upd(dp[i][j],dp[i][j-1]);
	int ans = 0;
	for (i = 1; i <= n; ++i) upd(ans,dp[2001+x[i]][2001+y[i]]),ans = (ans + P - C((x[i]+y[i])<<1,x[i]<<1)) % P;
	ans = (LL)ans * (P+1>>1) % P;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 68928
def is_valid(vals, M, X):
    for i in range(M):
        if vals[i] < X:
            return False
    return True

def solve(N, M, X, C, A):
    ret = float("inf")
    for i in range(2 ** N):
        tmp_vals = [0 for _ in range(M)]
        cost = 0
        for j in range(N):
            if (i >> j) & 1:
                cost += C[j]
                for k in range(M):
                   tmp_vals[k] += A[j][k]
        ret = min(ret, cost) if is_valid(tmp_vals, M, X) else ret
    return ret if ret != float("inf") else -1




if __name__ == '__main__':
    N, M, X = map(int, input().split())
    C = []
    A = []
    for _ in range(N):
        tmp = list(map(int, input().split()))
        C.append(tmp[0])
        A.append(tmp[1:])

    print(solve(N, M, X, C, A))

Measured memory_bytes: 74568
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string a,b;
  cin>>a>>b;
  a+=b;
  int n=stoi(a);
  bool flag=0;
  for(int i=1;i<n;i++){
    if(n==i*i){
      flag=1;
      break;
    }
    if(n>(i-1)*(i-1)&&n<i*i)  break;
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

int main() {
	long long int a, b,c, tmp, r;
	std::cin >> a >> b;
	c = a * b;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	std::cout << c/b << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	bool ok=true;
	for (int i=0; i<s.size(); i++) {	
		if (s[i]=='R'&&i%2) ok=false;  
		else if (s[i]=='L'&&i%2==0) ok=false;	
	}
	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}


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

int main() {
  int a, b, c, d, e;
  cin >> a;
  
  b = a / 1000;
  c = a % 1000 / 100;
  d = a % 100 / 10;
  e = a % 10;
  if (((b == c) && (c == d)) || ((c == d) && (d == e))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N+1);
		REP(i,1,N+1) cin >> A[i];
		vector<int> s(N+1);
		REP(i,1,N+1) s[i]=s[i-1]+A[i];
		lli ans=-INF_;
		REP(i,0,N+1) REP(j,i+1,N+1) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
n = int(input())

array = []
for i in range(n):
	a = int(input())
	array.append(a)

array.sort()
last = -1
count = 0
ans = 0

for i in range(len(array)):
	if last != array[i]:
		if count % 2 == 1:
			ans += 1
		
		count = 1
	else:
		count += 1
		
	last = array[i]

if count % 2 == 1:
	ans += 1

print(ans)



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

int main() {
  vector<char> vec{'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'};
  char c, answer;
  cin >> c;
  
  for(int i = 0; i < 26 ; i++) {
    if(c == vec.at(i)) {
      answer = vec.at( i + 1 );
      break;
    }
  }
    
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    
    vi pre(n),suf(n);
    pre[0]=v[0];
    for(int i=1;i<n;i++){
        pre[i]=max(pre[i-1],v[i]);
    }
    suf[n-1]=v[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i]=max(suf[i+1],v[i]);
    }
    
    for(int i=0;i<n;i++){
        int a=0,b=0;
        
        if(i)a=pre[i-1];
        if(i+1<n)b=suf[i+1];
        cout<<max(a,b)<<"\n";
    }
}



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

typedef struct{
    string name;
    int time;
}Process;

int main ()
{
    int n, q, finishTime = 0;
    cin >> n >> q;
    queue <Process> P_queue;
    Process p;
    for (int i = 1;i <= n;i++)
    {
        cin >> p.name >> p.time;
        P_queue.push(p);
    }
    
    while(!P_queue.empty())
    {
        Process now = P_queue.front();
        if (now.time <= q)
        {
            finishTime += now.time;
            cout << now.name << " " << finishTime << endl;
            P_queue.pop();
        }
        else
        {
            now.time -= q;
            finishTime += q;
            P_queue.pop();
            P_queue.push(now);
        }
    }
    
    return 0;
}


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

int main() {
	int n; 
	while (cin >> n, n) {
		int c1 = 0, c2 = 0;
		rep(i, n) {
			int a, b; cin >> a >> b;
			if (a > b)c1 += a + b;
			else if (a < b)c2 += a + b;
			else { c1 += a; c2 += b; }
		}
		cout << c1 << ' ' << c2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
vl ans;

void dfs(int n,int p,vvl &g)
{
	for(int c:g[n]){
		if(c==p)continue;
		ans[c]+=ans[n];
		dfs(c,n,g);
	}
	return;
}

signed main(){
	int n,q; cin>>n>>q;
	vvl g(n,vl(0));
	ans.resize(n);
	rep(i,0,n-1){
		int a,b; cin>>a>>b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	while(q--){
		int p,x; cin>>p>>x;
		ans[p-1]+=x;
	}
	dfs(0,-1,g);
	rep(i,0,n) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 28156
/*input
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long n,ans=3;
	string s1,s2;
	cin>>n>>s1>>s2;
	int i;
	if(s1[0]==s2[0]) i=1,ans=3;
	else i=2,ans=6;
	while(i<n){
		if(s1[i]==s2[i]){
			if(s1[i-1]==s2[i-1]) ans=ans*2%md,++i;
			else ++i;
		}
		else{
			if(s1[i-1]==s2[i-1])
				ans=ans*2%md,i+=2;
			else
				ans=ans*3%md,i+=2;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
// Created by new_sm
//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	string s;
	cin>>s;
	if(s=="RRS"||s=="SRR")
	cout<<2;
else

{
	if(s=="RRR")
		cout<<3;
	else
	{
		if(s=="SSS")
			cout<<0;
		else
			cout<<1;
	}
}
}
int main()
{
//code
	
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


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

using namespace std;

const int maxn = 15e5, maxk = 1e7;
int root[maxn], L[16 * maxn], R[16 * maxn], sum[16 * maxn];
int rt = 1, sz = 1;
int lpos[maxk];

int copy(int v, int &u)
{
    L[sz] = L[v];
    R[sz] = R[v];
    sum[sz] = sum[v];
    return u = sz++;
}

void make_root()
{
    copy(root[rt - 1], root[rt]);
    rt++;
}

void add(int pos, int x, int v = root[rt - 1], int l = 0, int r = maxn)
{
    sum[v] += x;
    if(r - l == 1)
        return;
    int m = (l + r) / 2;
    if(pos < m)
        add(pos, x, copy(L[v], L[v]), l, m);
    else
        add(pos, x, copy(R[v], R[v]), m, r);
}

int get(int a, int b, int v, int l = 0, int r = maxn)
{
    if(a <= l && r <= b)
        return sum[v];
    if(r <= a || b <= l)
        return 0;
    int m = (l + r) / 2;
    return get(a, b, L[v], l, m) + get(a, b, R[v], m, r);
}

int main()
 {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
    {
        int t;
        cin >> t;
        make_root();
        add(lpos[t], -1);
        lpos[t] = i;
        add(lpos[t], 1);
    }

    int l, r;
    while(q--)
    {
        cin >> l >> r;
        cout << get(l, r + 1, root[r]) << "\n";
    }
    return 0;
 }


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i]; --a[i];
  }
  set<int> se;
  se.insert(0);
  int cur = 0;
  while (true) {
    cur = a[cur];
    if (cur == 1) break;
    if (se.count(cur)) {
      cout << -1 << endl;
      return 0;
    }
    se.insert(cur);
  }
  cout << se.size() << endl;
}
  
  
  

Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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 Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int g[100001][26];

int main() {
  string s,t;
  while(cin>>s>>t) {
    int n =s.size();
    int m =t.size();
    memset(g,-1,sizeof(g));
    REPR(i,n) {
      REP(j,26) {
        g[i][j] = g[i+1][j];
        if (s[i]-'a' == j) {
          g[i][j] = i;
        }
      }
    }
    int ans = 0;
    int cur = 0;
    REP(i,m) {
      int c = t[i]-'a';
      if (g[cur][c] == -1) {
        if (g[0][c] == -1) {
          ans = -1;
          break;
        }
        ans++;
        cur = g[0][c] + 1;
      } else {
        cur = g[cur][c] + 1;
      }
    }
    if (ans == -1) cout << -1 << endl;
    else cout << ((ll)ans*n + cur) << endl;
  }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i-1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 4028
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int a, b;
string s;
bool sol;

int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b;
    cin >> s;
    sol = true;

    if((int)s.length() != a+b+1) sol = false;

    forn(i,(int)s.length()){
        if(i == a){
            if(s[i] != '-'){
                sol = false;
            }
            continue;
        }

        if(s[i] < '0' || s[i] > '9'){
            sol = false;
        }
    }

    if(sol){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
long a,b;
char op;

while(1){
scanf("%ld ",&a);
scanf("%c",&op);
scanf(" %ld",&b);

if(op=='+'){
printf("%ld\n",a+b);
}
if(op=='-'){
printf("%ld\n",a-b);
}
if(op=='*'){
printf("%ld\n",a*b);
}
if(op=='/'){
printf("%ld\n",a/b);
}
if(op=='?'){
break;
}
}
return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
char s[100];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	n-=8;
	for(int i=1;i<=n;i++)
		putchar(s[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 384
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
ans = 0

for i in range(N):
    A = [int(i) for i in input().split()]
    if sum([a * b for a, b in zip(A, B)]) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int P[201] = {0};

int main()
{
	int K = 0, X = 0;
	int i = 0;
	scanf("%d %d", &K, &X);
	i = ((X-K)+1);
	for (; i < (K+X); i++) {
		printf("%d ", i);
	}
	printf("\n");

    return 0;
}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int n;
    cin >> n;
    int f = n;
    int nn = 0;
    while (f)
    {
        nn += f % 10;
        f /= 10;
    }
    if (n % nn == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    // srand((unsigned)time(NULL));
    // int t = clock();
    solve();
    // double et = 1.0 * (clock() - t) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

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

int main(){
    long long N;
    cin >> N;
    long long A[N];
    long long sum = 0;
    map<long long,long long> m;
    rep(i,N){
        cin >> A[i];
        m[A[i]]++;
    }
    for(auto it = m.begin();it != m.end();it++){
        long long p = it->second;
        sum += p * (p-1) / 2;
    }

    rep(i,N){
        cout << sum - (m[A[i]] > 1 ? m[A[i]] - 1 : 0 ) << endl;
    }

    return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define pll pair<ll,ll>
#define pii pair<int32_t,int32_t>
#define loop(i,n) for(int64_t i=0; i<n; i++)
#define loop1(i,a,b) for(int64_t i=a; i<=b; i++)
#define rloop(i,n) for(int64_t i=n-1; i>=0; i--) 
#define rloop1(i,a,b) for(int64_t i=a; i>=b; i--) 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define print(val) cout << #val << ": " << val << "\n";
#define print_c(a) cout<<#a<<": ";for(auto it=begin(a);it!=end(a);it++)cout<<*it<<" ";cout<<"\n";
#define fill(c,v) fill(begin(c),end(c),v);
template <typename T> T flip(T val) {reverse(begin(val),end(val)); return val;}

int main() {
  fast_io
  ll t=1; 
  while(t--) {
    ll n,k; cin >> n >> k;
    ll p[n]; 
    loop(i,n) cin >> p[i];
    sort(p,p+n);
    ll ans=0;
    loop(i,k) ans+=p[i];
    cout << ans << "\n";
  }
}

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

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


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	string A;
	int f = 0;
	vector<char> B;
	cin >> A;

	for (int i = 0; i < 4; i++)
	{
		char ch = A[i];
		B.push_back(ch);
	}
	for (int i = 0; i < 4; i++)
	{
		size_t n_count = count(B.begin(), B.end(), B[i]);
		if (n_count != 2) { f = 1; }
	}

	if (f == 0) { cout << "Yes" << endl; }
	else{ cout << "No" << endl; }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;cin>>n;
  int u=pow(2,n);
  vector<int> v;for(int i=0;i<u;i++){
    int a;cin>>a;v.push_back(a);
  }
  for(int i=0;i<n;i++){
    vector<int> w;
    for(int j=0;j<v.size();j+=2){
      if(v[j]==v[j+1])w.push_back(v[j]);
      else{
        w.push_back(abs(v[j]-v[j+1]));
      }
    }
    v=w;
  }
  cout<<v[0]<<endl;
}

Measured memory_bytes: 2292
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
using namespace std;
#define mp make_pair
#define ll long long
#define re register
typedef pair<int,int> pii;
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline ll gi()
{
	ll f=1,sum=0;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int A,V,B,W,T;
int main()
{
	A=gi();V=gi();B=gi();W=gi();T=gi();
	if(V<=W)return puts("NO"),0;
	if(1ll*(V-W)*T<(ll)abs(B-A))puts("NO");
	else puts("YES");
	return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strIn = null;

		while ((strIn = parseStdin()) != null) {
			System.out.println(decode(strIn));
		}
	}

	private static String decode(String plain) {
		String	decode = "";
		int		len    = plain.length();

		for (int i = 0; i < len; i++) {
			char	c = plain.charAt(i);
			if (c == '@') {
				c = plain.charAt(i + 2);
				for (int j = plain.charAt(i + 1) - '0'; j > 0; j--) {
					decode += c;
				}
				i += 2;
			}
			else {
				decode += c;
			}
		}
		
		return decode;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16888
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	mm := make([]int, n+1)
	ans := 0
	mm[0] = math.MaxInt32
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
		if mm[i] >= pp[i] {
			ans++
			mm[i+1] = pp[i]
		} else {
			mm[i+1] = mm[i]
		}
	}

	fmt.Fprintln(writer, ans)
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 998244353;


ll Solve() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (auto &a_i : a) cin >> a_i;

    const int SUM = accumulate(a.begin(), a.end(), 0);
    vector<vector<ll>> dp1(n + 1, vector<ll>(SUM + 1));
    vector<vector<ll>> dp2(n + 1, vector<ll>(SUM + 1));
    dp1[0][0] = dp2[0][0] = 1;
    for (int i = 0, sum = 0; i < n; ++i) {
        for (int j = 0; j <= sum; ++j) {
            if (dp1[i][j] != 0) {
                (dp1[i + 1][j] += 2 * dp1[i][j]) %= MOD;
                (dp1[i + 1][j + a[i]] += dp1[i][j]) %= MOD;

                (dp2[i + 1][j] += dp2[i][j]) %= MOD;
                (dp2[i + 1][j + a[i]] += dp2[i][j]) %= MOD;
            }
        }
        sum += a[i];
    }

    ll res = 1;
    for (int i = 0; i < n; ++i) (res *= 3) %= MOD;

    ll cnt1 = 0;
    for (int i = (SUM + 1) / 2; i <= SUM; ++i)
        (cnt1 += dp1[n][i]) %= MOD;
    (cnt1 *= 3) %= MOD;
    (cnt1 = MOD - cnt1) %= MOD;

    ll cnt2 = 0;
    if (SUM % 2 == 0) {
        (cnt2 = 3 * dp2[n][SUM / 2]) %= MOD;
    }

    return (res + cnt1 + cnt2) % MOD;
}

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

    cout << Solve() << endl;

    return 0;
}
 

Measured memory_bytes: 423872
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for i in range(n)]

ans = x
for i in a:
    ans += 1
    for j in range(1, d + 1):
        sub = (i * j) + 1
        if sub > d:
            break
        ans += 1

print(ans)

Measured memory_bytes: 3060
class Dice
  attr_accessor :status
  def initialize(status)
    @status = status
  end

  def compareSpec(dice)
    @d2 = dice.status
    d1 = matchDirect
    return (d1 == @d2) ? true : false
  end

  def matchDirect
    dt = Array.new(6)
    2.times do |i|
      idx = detectIndex(i)
      dt[i] = @status[idx]
      dt[5-i] = @status[5-idx]
    end
    top = @status.index(dt[0]) + 1
    front = @status.index(dt[1]) + 1
    idx = detectSideIndex(top,front)
    dt[2] = @status[idx]
    dt[3] = @status[5-idx]
    return dt
  end

  def detectIndex(i)
    idx = 0
    @status.each_with_index do |dir,j|
      if ((dir == @d2[i]) && (@status[5-j] == @d2[5-i]))
        idx = j
        break
      end
    end
    return idx
  end

  def detectSideIndex(top,front)
    idx = 0
    case top
    when 1,6
      s = [2,3,5,4]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 1) ? s[1] - 1 : s[-1] - 1
    when 2,5
      s = [1,4,6,3]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 2) ? s[1] - 1 : s[-1] - 1
    when 3,4
      s = [1,2,6,5]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 3) ? s[1] - 1 : s[-1] - 1
    end
    return idx
  end
end

d1 = Dice.new(gets.split.map(&:to_i))
d2 = Dice.new(gets.split.map(&:to_i))
result = d1.compareSpec(d2)
puts (result == true) ? "Yes" : "No"

Measured memory_bytes: 8624
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		List<Integer> list = new ArrayList<Integer>();

		for (int i = 0; i < 10; i++)
			list.add(sc.nextInt());

		Collections.sort(list);
		Collections.reverse(list);
		for (int i = 0; i < 3; i++)
			System.out.println(list.get(i));
	}
}

Measured memory_bytes: 17172
// ABC177D Friends改

#include<stdio.h>
int par[200001];//親
int siz[200001];//サイズ
int rank[200001];//ランク

void ini(int n){ //初期化
  for(int i=0;i<=n;i++){
    par[i] = i;
    siz[i] = 1;
    rank[i] = 0;
  }
}

int root(int x){
    int count=0,s[200001];
    if(par[x] == x){
        for(int i=0;i<count;i++){
            par[s[i]] = x;
        }
        return x;
    }
    else{
        s[count] = par[x];
        count++;
        return par[x] = root(par[x]);
    }
}

void uni(int x, int y){ 
    x = root(x);
    y = root(y);
    if(x != y){
        if(rank[x] > rank[y]){
            par[y] = x;
            siz[x] += siz[y];
        }
        else if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }
        else{
            par[y] = x;
            siz[x] += siz[y];
            rank[x]++;
        }
    }
}

int size(int x){ //サイズを返す
  return siz[root(x)];
}

int max(int x, int y){
  if(x>=y) return x;
  else return y;
}

int main(void){
  int n,m,a,b,ma=0;
  scanf("%d %d",&n,&m);
  ini(n);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    uni(a,b);
  }
  for(int i=1;i<=n;i++){
    ma = max(ma,size(i));
  }
  printf("%d",ma);
  return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

 ll a,b,c,k,ans=1;
 cin>>a>>b>>c>>k;
 if(a>=k)
 {
     cout<<k<<endl;
 }
 else if((a+b)>=k)
 {
     cout<<a<<endl;
 }
 else
 {
     cout<<a-(k-(a+b))<<endl;
 }
return 0;
}



Measured memory_bytes: 3652
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = 0;
	for (int i=1; i<=N; i++) {
		int a;
		cin >> a;

		if (i % 2 == 1 && a % 2 == 1) ans++;
	}


	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout << (a<=8&&b<=8 ? "Yay!" : ":(") << endl;
	return 0;
}


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

int main() {
    long l,r;
    cin >> l >> r;
    if (r - l > 2019) {
        cout << 0 << endl;
    }
    else{
        vector<long> num(r-l+1);
        for (long i = 0; i < r-l+1; i++) {
            num[i] = (l+i) % 2019;
        }
        long ans = 5000000;
        for (long i = 0; i < r-l; i++) {
            for (long j = 1; j < r-l+1; j++) {
                ans = min(ans,(num[i]*num[j])%2019);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
n = input()
a,b,c,d = map(str,(n[0],n[1],n[2],n[3]))
x = []
for i in range(8):  
  for j in range(3):
    if (i>>j)&1:
      x.append("+")
    else:
      x.append("-")
  line = a + x[0] + b + x[1] + c + x[2] + d
  if eval(line) == 7:
    print(line + "=7")
    break
  x = []

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

int main(){
    vector<long long int> a(7);
    for(int i=0; i<7; i++){
        cin >> a[i];
    }

    long long int ans = (a[0] / 2 + a[3] / 2 + a[4] / 2) * 2;// I-type, J-type, L-type
    if(a[0] > 0 && a[3] > 0 && a[4] > 0){
        ans = max(ans, 3 + ((a[0]-1) / 2 + (a[3]-1) / 2 + (a[4]-1) / 2) * 2);
    }
    ans += a[1];// O-type    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>

using namespace std;

int d;
double v[16];

double interpolate(int n, int E){
	// 補間多項式L(x) のx=n での値L(n) を計算する
	// L(x) の作成において，点(n,V[n]) と(E,V[E]) は使わない
	double sum = 0.0;
	for(int k = 0; k < d + 3; ++k){
		if(k == E || k == n){
			continue;
		}
		double p = v[k];
		for(int i = 0; i < d + 3; ++i){
			if(i != k && i != n && i != E){
				p *= 1.0 * (n - i) / (double)(k - i);
			}
		}
		sum += p;
	}
	return sum;
}

bool outlier(int E){
	for (int i=0; i<d+3; ++i){
		if(i == E){
			continue;
		}
		double p = interpolate(i, E);
		if(abs(p - v[i]) > 0.1){
			return false;
		}
	}
	return true;
}

int main(){
	while (cin >> d && d){
		for(int i = 0; i < d + 3; ++ i){
			cin >> v[i];
		}
		for(int i = 0; i < d + 3; ++ i){
			if(outlier(i)){
				cout << i << endl;
				//cout << interpolate(i, d);
				break;
			}
		}
	}
	
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;
int A[200010], B[200010];

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N;
    REP(i, N) cin >> A[i] >> B[i];
    bool tigau = false;
    REP(i, N) tigau |= (A[i] != B[i]);
    if (!tigau) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    int mn = INF;
    REP(i, N) {
        ans += A[i];
        if (A[i] > B[i]) CHMIN(mn, B[i]);
    }
    ans -= mn;
    cout << ans << endl;

    return 0;
}

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

int main() {
    string s, s2;
    ll k;
    cin >> s >> k;
    int n = s.size();
    s2 = s + s;

    if (n == 1) {
        cout << k / 2 << endl;
        return 0;
    } else if (all_of(s.begin(), s.end(), [s](char x) { return x == s[0]; })) {
        cout << n * k / 2 << endl;
        return 0;
    }

    int cnt = 1;
    ll ans = 0, ans2 = 0;
    rep(i, n) {
        if (s[i] == s[i + 1])
            cnt++;
        else
            ans += cnt / 2, cnt = 1;
    }

    cnt = 1;
    rep(i, n * 2) {
        if (s2[i] == s2[i + 1])
            cnt++;
        else
            ans2 += cnt / 2, cnt = 1;
    }

    ans = ans * k + (ans2 - ans * 2) * (k - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	int m,n,i,t,j,k;
	char s[1000];
	scanf("%s",&s);
	int flag=0;
	m=strlen(s);
	if(m%2!=0) flag=1;
	int p=0;
	while(m!=0&&flag==0)
	{
		if(s[p]!='h')
		{
			flag=1;
		}
		p++;m--;
		if(s[p]!='i')
		{
			flag=1;
		}
		p++;m--;
	}
	if(flag) printf("No");
	else printf("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
    using namespace std;  
    const int N = 100005;  
    typedef long long ll;  
    int a[N];  
    double b[N];  
    int main()  
    {  
         int n,maxa=-1;  
         cin>>n;  
         for(int i=1;i<=n;i++)  
            scanf("%d",&a[i]);  
        sort(a+1,a+1+n);  
        double mid=1.0*a[n]/2,minb=1000000009.0;  
        int ans;  
        for(int i=1;i<n;i++){  
           // printf("%lf\n",mid-(1.0*a[n]-1.0*a[i]));  
            if(fabs(mid-(1.0*a[n]-1.0*a[i]))<minb)  
            {  
                ans=a[i];  
                minb=fabs(mid-(1.0*a[n]-1.0*a[i]));  
            }  
        }  
        printf("%d %d\n",a[n],ans);  
    }  

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {
    ll N, X;
    cin >> N >> X;
    
    ll sum = 0;
    vector<ll > A(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    sort(A.begin(), A.end());
    
    cout << N + (X - sum) / A[0] << endl;

}

Measured memory_bytes: 256