akhauriyash/Code-Regression huggingface dataset:
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec x(n);
  loop(i,n)cin>>x[i];
  sort(all(x));
  vec xx(n);
  ll count=0;
  if(n%2==0){
    loop(i,n){
      xx[i]=1+2*(count/2);
      count++;
    }
  }
  else{
    loop(i,n){
      count++;
      xx[i]=2*(count/2);
    }
  }
  bool check=true;
  loop(i,n)if(x[i]!=xx[i])check=false;
  if(check){
    ll ans=1;
    ll t=n/2;
    loop(i,t){
      ans*=2;
      ans%=1000000007;
    }
    putout(ans);
  }
  else putout(0);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    vec r(N + 1), l(N + 1);


    r[0] = 0;
    queue<int> qr;
    REP(i, N){
        r[i + 1] = r[i] + 1;
        if(i >= 1){
            int a = A[i - 1], b = A[i];
            if(a >= b){
                while(a >= b * 4){
                    b *= 4;
                    qr.push(i);
                }
            }else{
                while(a < b){
                    a *= 4;
                    if(qr.empty()) r[i + 1] += 2 * i;
                    else{
                        int i0 = qr.front(); qr.pop();
                        r[i + 1] += 2 * (i - i0);
                    }
                }
            }
        }
    }
    l[N] = 0;
    queue<int> ql;
    IREP(i, N){
        l[i] = l[i + 1];
        if(i < N - 1){
            int a = A[i], b = A[i + 1];
            if(a <= b){
                while(a * 4 <= b){
                    a *= 4;
                    ql.push(i);
                }
            }else{
                while(a > b){
                    b *= 4;
                    if(ql.empty()) l[i] += 2 * (N - 1 - i);
                    else{
                        int i0 = ql.front(); ql.pop();
                        l[i] += 2 * (i0 - i);
                    }
                }
            }
        }
    }
    int ans = INF;
    REP(i, N + 1) ans = min(ans, r[i] + l[i]);
    cout << ans;
    
    return 0;
}

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

int main(){
    int N; int D; int count=0;
    int x; int y; 

    //ifstream myfile;
    //myfile.open("sample.txt");
    cin >> N >> D;

    double max_squared_distance = pow(D,2);
    map<pair<int,int>,double> m;
    
    while(N--){
        cin >> x >> y;
        if(abs(x) > D || abs(y)> D){
            continue;
        }
        pair<int,int> p = make_pair(x,y);
        if(m[p]){
            if(m[p] <= max_squared_distance){
                count++;
            }
            continue;
            
        }
        double squared_distance = pow(x,2) + pow(y,2);
        m[p] = squared_distance;
        if(squared_distance <= max_squared_distance){
            count++;
        }
    }
    cout << count;
    
    return 0;
}

Measured memory_bytes: 16080
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;



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

	for (int i = 0; i < N; ++i)
	{
		int A; cin >> A;
		if (A % 2 != 0) { continue; }

		if (A % 3 != 0 && A % 5 != 0)
		{
			cout << "DENIED" << endl;
			return 0;
		}
	}
	
	cout << "APPROVED" << endl;

	return 0;
}

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

using namespace std;

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

	map<string, int> memo;
	string s;
	for (int i = 0; i < n; i++) {
		cin >> s;

		memo[s] += 1;
	}

	int max;

	for (const auto &x : memo) {
		int v = x.second;
		if (v > max) {
			max = v;
		}
	}
	for (auto i = memo.begin(); i != memo.end(); i++) {
		if (i->second == max) {
			cout << i->first << endl;

		}
	}

	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    
    string S;
    ll N=0;
    cin >> S;
    REP(i,S.size()){
        N += S[i]-'0';
        N%=9;
    }
    
    if(N==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

using pll = pair<ll, ll>;
vector<pll> v;

int main(){
	ll n; scanf("%lld", &n); n *= 2;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			v.EB(i, n/i);
			if(i *i < n) v.EB(n/i, i);
		}
	}
	ll ans = LLONG_MAX;
	for(auto [p, q] : v){
		auto [y, z] = crt({0, -1}, {p, q});
		if(z){
			if(y == 0) y = z;
			SML(ans, y);
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3976
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#define DBL_MIN 0.000000000000001

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */


//ちゃんとlong型でやってる？
using namespace std;
int main(void){
    Real A,B,N;
    cin >> A >> B >> N;
    
    Real pA = floor(A*N/B) - A*floor(N/B);
    Real pB = floor(A*(B-1)/B) - A*floor((B-1)/B);
     
    if(N >= B)
        cout << pB << endl;
    else
        cout << min(pA,pB) << endl;
    return 0;
}

Measured memory_bytes: 3856
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
LL powm(LL base,LL power, LL mod){
  LL ret=1;
  while(power){
    if(power&1) ret=(ret*base)%mod;
    base=(base*base)%mod;
    power>>=1;
  } return ret;
}
int main(){
  int n,a,b; si(n);
  if(n==1) return 0*puts("Hello World");
  si(a);si(b);
  cout<<a+b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    string s;
    cin>>s;
    int a=INF;
    int b=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            a=min(a,i);
        }
        if(s[i]=='Z'){
            b=max(b,i);
        }
    }
    cout<<b-a+1<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

ll v[3010][3010];
ll dp[3010][3010][4];

int main() {
  int R, C, K; cin>>R>>C>>K;
  REP(i,K) {
    int r, c, value; cin>>r>>c>>value;
    v[r][c] = value;
  }
  for(int r = 1; r <= R; r++) {
    for(int c = 1; c <= C; c++) {
      for(int cnt = 0; cnt <= 3; cnt++) {
	//	if(v[r][c] == 0) {
	  chmax(dp[r][c][cnt], dp[r][c-1][cnt]);
	  chmax(dp[r][c][0], dp[r-1][c][cnt]);
	  //	}
	  //	else 
if(v[r][c] > 0) {
	  //	  chmax(dp[r][c][0], dp[r-1][c][cnt]);
	  chmax(dp[r][c][1], dp[r-1][c][cnt] + v[r][c]);
	  //	  chmax(dp[r][c][cnt], dp[r][c-1][cnt]);
	  if(cnt <= 2) {
	    chmax(dp[r][c][cnt+1], dp[r][c-1][cnt] + v[r][c]);
	  }
	}
      }

      //      for(int cnt = 0; cnt <= 3; cnt++) {
      //	cout << r << " " << c << " "<< cnt << " " << dp[r][c][cnt] << endl;
      //      }


    }
  }
  ll ans = 0;
  for(int cnt = 0; cnt <= 3; cnt++) {
    chmax(ans, dp[R][C][cnt]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 355704
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = (n % (a + b));
    ans = min(ans, a);

    ans += a * (n / (a + b));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b,temp=0;
    cin>>a>>b;
    if(a==b)
    temp=1;
    else if(a==2 || b==2)
    temp=0;
    else if(a==4 || a==6 || a==9 || a==11)
    {
        if(b==4 || b==6 || b==9 || b==11)
        temp=1;
    }
    else
    {
        if(b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12 )
        temp=1;
    }
    if(temp)
    cout<<"Yes";
    else
    cout<<"No";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main() {
  int N;cin >> N;
  vll a(N);
  repeat(i,N){
    cin >> a[i];
  }
  ll ans = 0;
  ll S=1;
  while(S>0){
    S = 0;
    repeat(i,N){
      S += a[i]/N;
    }
    ans += S;
    repeat(i,N){
      a[i] += (S-(a[i]/N))-(a[i]/N)*N;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXA = 1e6;
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> c(MAXA+1, 0);
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    ++c[A];
  }
  std::vector<bool> ok(MAXA+1, true);
  for(int a = 1; a <= MAXA; ++a) if(c[a] > 0) {
    if(!ok[a]) continue;
    if(a*2 > MAXA) continue;
    for(int j = 2; a*j <= MAXA; ++j) ok[a*j] = false;
  }
  int ans = 0;
  for(int a = 1; a <= MAXA; ++a) {
    if(c[a] == 1 && ok[a]) ++ans;
  }
  fin(ans);
  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    ll n;
    cin >> n;
    vector<double> a(n);
    vll p(n);

    bool b = true;
    rep(i, n) {
        ll t;
        cin >> t;
        p[i] = t;
        if (t == 0) {
            b = false;
            break;
        }

        a[i] = log10(1.0 * t);
    }

    if (b) {
        double t = 18.0;
        double sum = 0.0;

        bool c = true;

        rep(i, n) {
            sum += a[i];

            if (sum > t) {
                c = false;
                break;
            }
        }

        if (c) {
            ll ans = 1;
            rep(i, n) {
                ans *= p[i];
            }

            if (ans > 1000000000000000000) {
                cout << -1 << endl;
            } else {
                cout << ans << endl;
            }

        } else {
            cout << -1 << endl;
        }

    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 4796
#include<bits/stdc++.h>
#define LL long long


using namespace std;
const int maxn=1e5+5;

int main()
{
    LL n;
    cin>>n;
    LL a[n];
    map<LL,LL>  mp;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                LL a1=a[i];
                LL b1=a[j];
                LL c1=a[k];
                if(a1+b1>c1&&a1+c1>b1&&c1+b1>a1&&a1!=b1&&b1!=c1&&c1!=a1)
                    {ans++;/*cout<<a1<<" "<<b1<<" "<<c1<<endl;*/}
            }
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    sort(s.begin(), s.end());
    if (s[n-1] == 'g'){
        cout << n / 2 << endl;
        return 0;
    } else if (s[0] == 'p') {
        cout << n / 2 - n << endl;
        return 0;
    }
    int i, l = 0, r = n;
    while (1) {
        i = (l + r) / 2;
        if (s[i-1] == 'g' && s[i] == 'p') break;
        if (s[i] == 'g') l = i;
        else             r = i;
    }
    cout << n / 2 - (n - i) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
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 <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
    }
    return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

const int MOD = 998244353;
using mint = modint<MOD>;

int main() {
    int N, K;
    cin >> N >> K;
    vector<pint> v(K);
    for (int i = 0; i < K; ++i) cin >> v[i].first >> v[i].second;

    vector<mint> dp(N, 0), sdp(N+1, 0);
    dp[0] = 1, sdp[1] = 1;
    for (int n = 1; n < N; ++n) {
        for (auto p : v) {
            int left = max(0, n - p.second);
            int right = max(0, n - p.first + 1);
            dp[n] += sdp[right] - sdp[left];
        }
        sdp[n+1] = sdp[n] + dp[n];
    }
    cout << dp[N-1].a << endl;
    return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N,X;
ll S[200];
ll fact[201];
ll dp[100010][210];
ll dfs(ll s, ll i){
    if(dp[s][i]>=0) return dp[s][i];
    if(s<=S[0]){
        dp[s][i]=(s%S[0])*fact[i+1]%MOD;
    }
    else if(i==0){
        dp[s][i]=s%S[0]%MOD;
    }
    else if(s<S[i]){
        dp[s][i]=(i+1)*dfs(s,i-1)%MOD;
    }
    else dp[s][i]=(dfs(s%S[i], i-1)+dfs(s, i-1)*i%MOD)%MOD;
    return dp[s][i];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>X;
    rep(i,0,N){
        cin>>S[i];
    }
    fact[1]=1;
    rep(i,2,201){
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    rep(i,0,X+1){
        rep(j,0,N){
            dp[i][j]=-1;
        }
    }
    sort(S,S+N);
    cout <<dfs(X,N-1)%MOD<<"\n";
}

Measured memory_bytes: 164352
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;
 
int main(void)
{
	int n;
	vector <int> c, s, f;
	int C, S, F;
 
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin >> n;
 
	for (int i = 0; i < n-1; i++)
	{
		cin >> C >> S >> F;
		c.push_back(C);
		s.push_back(S);
		f.push_back(F);
	}
 
	for (int i = 0; i < n-1; i++)
	{
		int time = 0;
		for (int j = i; j < n-1; j++)
		{
			if (time < s[j])
			{
				time = s[j];
			}
			else
			{
				int x = time - s[j];
				if (x%f[j] != 0)
				{
					time += (f[j] - (x%f[j]));
				}
			}
			time += c[j];
		}
		cout << time << '\n';
	}
	cout << 0 << '\n';
	return 0;
}

Measured memory_bytes: 256
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int r,c;
int sen[10][10000];
int count(int b){
	int ans=0;
	int tsen[10][10000];
	rep(i,r)rep(j,c)tsen[i][j]=sen[i][j]^(!!(b&(1<<i)));
	rep(j,c){
		int t=0;
		rep(i,r)t+=tsen[i][j];
		ans+=t>r-t?t:r-t;
	}
	return ans;
}
int main(){
	while(cin>>r>>c,r){
		rep(i,r)rep(j,c)cin>>sen[i][j];
		int mx=0,tmp;
		rep(i,1<<r){
			tmp=count(i);
			if(mx<tmp)mx=tmp;
		}
		cout<<mx<<endl;
	}
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[3];
    int m,i;
    m=0;
    cin>>s;
    for(i=0;i<strlen(s);++i)
    if(s[i]=='1')
      m++;
    cout<<m<<endl;
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll ans = 0;
  for (ll a = 1; a <= n; a++) {
    for (ll b = 1; a * b <= n; b++) {
      ll res = n - a * b;
      if (res > 0) ans++;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3648
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<bitset>
#include<iostream>
using namespace std;

/**** Type Define ****/

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

#define FOR(i,n) for(ll i = 0;i<n;i++)

#define FORp(i,k,n) for(ll i = k;i<n;i++)
/**** Const List   ****/
const ll mod = 1000000007;
/**** General Functions ****/
template <typename T>
T tmin(T a, T b) { return a > b ? b : a; };

template <typename T>
T tmax(T a, T b) { return a > b ? a : b; };

template <typename T>
T tadd(T a, T b) { return a + b; };

template <typename T>
T tmul(T a, T b) { return a * b; };

template <typename T>
T tpow(T a, T b) { return a * b; };

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll nCk(ll n, ll k, ll mod) {
  ll ans = 1;
  for (ll i = n, j = 1; j <= k; i--, j++) ans = (((ans * i) % mod) * invmod(j, mod)) % mod;
  return ans;
}

ll lmin(ll a, ll b) { return a > b ? b : a; };

ll lmax(ll a, ll b) { return a > b ? a : b; };

ll lsum(ll a, ll b) { return a + b; };

ll lmul(ll a, ll b) { return a * b; };


ll lpow(ll a, ll b) { return a * b; };

  /**** Original Define ****/
char a[20],b[20],c[20],ans[20]="NO";

  /**** main function ****/
int main(){
scanf("%s %s %s",a,b,c);
if(a[strlen(a)-1]==b[0] && b[strlen(b)-1] ==c[0]) strcpy(ans ,"YES");
printf("%s",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <cstdlib>
#include <cmath>

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

using namespace std;

int main() {

	char cap;

	cin >> cap;
	if (cap == 'a' || cap == 'i' || cap == 'u' || cap == 'e' || cap == 'o') {
		cout << "vowel" << endl;
	}
	else
		cout << "consonant" << endl;

	return 0;
}



Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 998244353;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

ll modpow(ll a, ll p){
	ll ret = 1;
	while(p){
		if(p&1) ret = ret * a % MOD;
		a = a * a % MOD;
		p >>= 1;
	}
	return ret;
}

struct Combination{
        std::vector<ll> fac, finv, inv;
        Combination(int max=6e5): fac(max+1), finv(max+1), inv(max+1) {
                fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
                for(int i=2; i<=max; 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 C(int n, int r) const {
                if(n<0 or n<r) return 0;
                return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
        }
};

int main(){
	ll n, m, k, ans = 0;
	scanf("%ld %ld %ld", &n, &m, &k);
	Combination comb(2e5);
	REP(i, 0, k+1){
		ans += m * modpow(m-1, n-i-1) % MOD * comb.C(n-1, i);
		ans %= MOD;
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 8004
#include <bits/stdc++.h>
using namespace std;
int ans[100009], vis[100009];
vector<pair<int,int> > adj[100005];
void solve(int u, int color)
{
	ans[u] = color;
	vis[u] = 1;
	for(int i=0;i<(int)adj[u].size();++i) {
		if(vis[adj[u][i].first] == 0) {
			if(adj[u][i].second % 2 == 0) {
				solve(adj[u][i].first, color);
			} else {
				solve(adj[u][i].first, 1-color);
			}
		}
	}
}
int main() {
	int n;
	cin>>n;
	
	memset(ans, 0, sizeof ans);
	for(int i=0;i<n-1;++i) {
		int x,y,z;
		cin>>x>>y>>z;
		adj[x-1].push_back(make_pair(y-1,z));
		adj[y-1].push_back(make_pair(x-1,z));
	}
	solve(0, 0);
	for(int i=0;i<n;++i) {
		cout<<ans[i]<<"\n";
	}
	return 0;
}

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

int main(){
  int d, g;
  cin >> d >> g;
  vector<P> p(d);
  rep(i,d) cin >> p[i].first >> p[i].second;
  
  int ans = INF;
  
  //点数p[i]の問題を全て解く必要があるかどうか
  //そうでなければ残った問題のうち一番点数が大きい問題を解く
  
  for(int bit = 0; bit < (1 << d); ++bit){
      int score = 0, cont = 0, rest = -1;
      
      rep(i,d){
          if(bit & (1 << i)){
              score += 100*(i+1)*p[i].first + p[i].second;
              cont += p[i].first;
          }else rest = i;
      }
      if(score < g){
          int score2 = 100*(rest+1);
          int cont2 = (g - score + score2 - 1)/score2;
          if(cont2 >= p[rest].first) continue;
          cont += cont2;
      }
      ans = min(ans, cont);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
x=[int(k) for k in input()]
for i in range(2**3):
  total=x[0]
  bag=[""]*3
  for j in range(3):
    if (i>>j)&1:
      bag[j]="+"
      total+=x[j+1]
    else:
      bag[j]="-"
      total-=x[j+1]
  if total==7:
    print("{}{}{}{}{}{}{}=7".format(x[0],bag[0],x[1],bag[1],x[2],bag[2],x[3]))
    break
      
      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int i,c=0;
		if(s[0]=='0')break;
		for(i=0;i<s.size();i++)c+=s[i]-'0';
		cout<<c<<endl;
	}
}

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

long long f(long long n) {
    long long c=0;
    for(long long i=5;n/i>=1;i*=5)c+=n/i; 
    return c; 
}

int main (){
    long long n;cin>>n;
    if(n%2==0)printf("%lld\n",f(n/2));
    else puts("0");
    return 0;
}

Measured memory_bytes: 256
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
  int n;
  cin >> n;
  ll d[n];
  ll x = 1;
  REP(i,n){
      cin >> d[i];
  }
  REP(i,n){
      if(d[i] == 0){
          cout << 0 << endl;
          return 0;
      }
  }
  bool f = true;
  ll mx = 1;
  REP(i,18){
      mx *= 10;
  }
  REP(i,n){
      
      if(d[i] > mx/x){
          x = -1;
          break;
      }else{
          x *= d[i];
      }
  }
  
  cout << x << endl;

  return 0;
}


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

const int INF = (1 << 30);

int n;
int adj[201][201] = {};
int cache[201][201] = {};

int dist(int i, int j)
{
    if(cache[i][j] != 0) return cache[i][j];
    auto cmp = [](auto& x, auto& y) { return x.second > y.second; };
    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cmp);
    q.emplace(i, 0);

    bool visited[201] = {};

    while(!q.empty())
    {
        auto k = q.top();
        q.pop();

        const int node = k.first;
        const int dist = k.second;

        visited[node] = true;

        if(node == j)
        {
            cache[i][j] = dist;
            cache[j][i] = dist;
            return dist;
        }

        for(int i = 0; i < 200; ++i)
        {
            if(visited[i] || adj[node][i] == 0) continue;
            q.emplace(i, dist + adj[node][i]);
        }
    }

    return INF;
}

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

    int m, r;
    cin >> n >> m >> r;

    vector<int> nodes(r);
    for(int i = 0; i < r; ++i)
    {
        cin >> nodes[i];
        nodes[i]--;
    }

    for(int i = 0; i < m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a -= 1;
        b -= 1;

        if(adj[a][b] == 0)
        {
            adj[a][b] = c;
            adj[b][a] = c;
        }
    }

    sort(nodes.begin(), nodes.end());

    int min_dist = numeric_limits<int>::max();
    do
    {
        int curr_dist = 0;
        for(int i = 1; i < nodes.size(); ++i)
        {
            const int from = nodes[i - 1];
            const int to = nodes[i];
            const int D = dist(from, to);
            curr_dist += D;
        }
        min_dist = min(curr_dist, min_dist);
    } while(next_permutation(nodes.begin(), nodes.end()));

    cout << min_dist << endl;
}


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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	int t[N], a[N];

	for (int i = 0; i < N; i++)
	{
		cin >> t[i] >> a[i];
	}

	//int rel = 0;
	ll ft = t[0], fa = a[0];
	ll rel = ft - fa;
	for (int i = 1; i < N; i++)
	{
		ll new_rel = t[i] - a[i];
		if (rel < 0)
		{
			if (new_rel > 0)
			{
				ll tmp = fa; 
				if(tmp % a[i])
				{
					tmp = (tmp / a[i] + 1) * a[i];
				}
				fa = tmp;
				ft = fa / a[i] * t[i];
			}
			else if (new_rel == 0)
			{
				ft = fa;
			}
			else
			{
				ll tmp = ft;
				if (tmp % t[i])
				{
					tmp = (tmp / t[i] + 1) * t[i];
					
				}
				if (tmp / t[i] * a[i] < fa)
				{
					if (fa % a[i])
					{
						tmp = (fa / a[i] + 1) * t[i];
					}
					else
					{
						tmp = fa / a[i] * t[i];
					}
					
				}
				ft = tmp;
				fa = ft / t[i] * a[i];
			}
		}
		else if (rel == 0)
		{
			if (new_rel > 0)
			{
				ll tmp = fa; 
				if(tmp % a[i])
				{
					tmp = (tmp / a[i] + 1) * a[i];
				}
				fa = tmp;
				ft = fa / a[i] * t[i];
			}
			else if (new_rel < 0)
			{
				ll tmp = ft; 
				if(tmp % t[i])
				{
					tmp = (tmp / t[i] + 1) * t[i];
				}
				ft = tmp;
				fa = ft / t[i] * a[i];
			}
		}
		else if (rel > 0)
		{
			if (new_rel < 0)
			{
				ll tmp = ft; 
				if(tmp % t[i])
				{
					tmp = (tmp / t[i] + 1) * t[i] ;
				}
				ft = tmp;
				fa = ft / t[i] * a[i];
			}
			else if (new_rel == 0)
			{
				fa = ft;
			}
			else
			{
				ll tmp = fa;
				if (tmp % a[i])
				{
					tmp = (tmp / a[i] + 1) * a[i];
					
				}
				if (tmp / a[i] * t[i] < ft)
				{
					//tmp = (ft / t[i] + 1) * a[i];
					if (ft % t[i])
					{
						tmp = (ft / t[i] + 1) * a[i];
					}
					else
					{
						tmp = ft / t[i] * a[i];
					}
				}
				fa = tmp;
				ft = fa / a[i] * t[i];
			}
		}
		rel = new_rel;
		//cout << "ft=" << ft << "; fa=" << fa << "; new_rel="<<rel<< endl;
	}

	cout << ll(fa + ft) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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; }


int main() {
	
	int n;
	cin >> n;
	
	map<char, int> ans,t;
	string s;
	cin >> s;
	for (auto st : s) ans[st]++;
	
	for (int i = 0; i < n - 1; ++i) {
		t.clear();
		cin >> s;
		for (auto st : s) t[st]++;
		for (char j = 'a'; j <= 'z'; ++j) ans[j] = min(ans[j], t[j]);
	}

	for (auto a : ans) if (a.second > 0) rep(i, a.second) cout << a.first;
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
//12
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

int dsq(int x,int y,int xx,int yy){
  return (x-xx)*(x-xx)+(y-yy)*(y-yy);
}

int main(){
  int t;
  cin>>t;
  while(t--){
    int n,x,y,nx,ny;
    cin>>n>>x>>y>>nx>>ny;
    int xx[1000],yy[1000];
    for(int i=0;i<n;i++){
      cin>>xx[i]>>yy[i];
    }
    vector<int> v(n);
    for(int i=0;i<n;i++){
      if(dsq(nx,ny,xx[i],yy[i])<=100){
	v[i]=-1;
      }
    }
    set<vector<int> > s;
    int t;
    bool w=false;
    for(t=0;;t+=x){
      if(!s.insert(v).second){
	w=true;
	break;
      }
      int i;
      for(i=0;i<n;i++){
	if(v[i]==-1)break;
      }
      if(i==n)break;
      for(int i=0;i<n;i++){
	if(v[i]!=-1){
	  v[i]=max(v[i]-x,0);
	}
      }
      vector<int> nv=v;
      for(int i=0;i<n;i++){
	if(v[i]==-1){
	  for(int j=0;j<n;j++){
	    if(v[j]==0&&dsq(xx[i],yy[i],xx[j],yy[j])<=2500){
	      nv[j]=-1;
	    }
	  }
	  nv[i]=y+1;
	}
      }
      v=nv;
    }
    if(w){
      cout<<"You're always welcome!"<<endl;
    }else{
      cout<<t<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで、intは2*10^9まで

#define INF (int)pow(10, 8)
typedef tuple<int, int, int> P;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for(int i=0; i<n; i++)
    cin >> a[i];
  sort(a, a+n);
  int ans=a[n-1];
  double l=0, r=a[n-1], mid;
  while(r-l>0.000005){
    mid=(l+r)/2;
    int tmp=0;
    for(int i=0; i<n; i++){
      tmp+=floor((a[i]-1)/mid);
    }
    if(tmp<=k){
      r=mid;
      ans=ceil(mid);
    }
    else {
      l=mid;
    }
  }
  cout << ans;
  return 0;
}

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

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String sl[] = s.split(" ");
    int n = Integer.parseInt(sl[0]);
    int a = Integer.parseInt(sl[1]);
    int b = Integer.parseInt(sl[2]);

    System.out.printf("%d %d", Math.min(a, b), Math.max(0, a + b - n));
  }

}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)


int main() {
        ll A, B, C, K;
        cin >> A >> B >> C >> K;

        ll ans = 0;

        // A (1)
        if (K <= A) {
                ans = K;
                K = 0;
        } else {
                ans = A;
                K -= A;
        }

        // B (0)
        K -= B;

        // C (-1)
        if (K > 0) ans -= K;

        cout << ans << endl;

        return 0;
}


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

void solve() 
{
    int n,k;cin>>n>>k;
    int p[n];REP(i,n)cin>>p[i];
    double pp[1010],sum=0;
    REP(i,1010){
        sum+=i+1;
        pp[i]=sum/(i+1);
    }
    sum=0;
    REP(i,k){sum+=pp[p[i]-1];}
    double memsum=sum;
    REP(i,n-k){
        sum+=pp[p[i+k]-1];
        sum-=pp[p[i]-1];
        memsum=max(memsum,sum);
    }
    cout<<setprecision(10)<<memsum<<endl;
}

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


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

const int N=100005;
long long MOD=1e9+7;
const long long INF=0x3f3f3f3f3f3f3f3f;
int n;
long long a[405],dp[405][405];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) a[i]+=a[i-1];
	for(int len=2;len<=n;len++)
	{
		for(int i=1;i<=n-len+1;i++)
		{
			int j=i+len-1;
			dp[i][j]=INF;
			for(int k=i;k<j;k++)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
			}
			dp[i][j]+=a[j]-a[i-1];
		}
	}
	printf("%lld\n",dp[1][n]);
}

Measured memory_bytes: 1536
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")


# update: node[x] を更新する
# segfunc: 半開区間 [a, b) での処理
def segfunc(a, b):
    return max(a, b)


class SegmentTree:
    def __init__(self, arr, ini):
        size = len(arr)
        self.ini = ini
        self.n = 2 ** (size-1).bit_length()
        self.node = [self.ini] * (2*self.n)

        for i in range(size):
            self.node[i+self.n-1] = arr[i]
        for i in reversed(range(self.n-2)):
            self.node[i] = segfunc(self.node[2*i+1], self.node[2*i+2])
    

    def update(self, x, val):
        x += (self.n - 1)
        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = segfunc(self.node[2*x+1], self.node[2*x+2])
    
    
    def query(self, a, b):
        res = self.ini
        l = self.n - 1 + a
        r = self.n - 1 + (b-1)
        
        while l <= r:
            if l == r:
                res = segfunc(res, self.node[l])
                break

            if l % 2 == 0:
                res = segfunc(res, self.node[l])
            if r % 2 == 1:
                res = segfunc(res, self.node[r])
            l = l // 2
            r = r // 2 - 1
        
        return res
 

# 処理内容
def main():
    N, K = map(int, input().split())
    
    seg = SegmentTree([0]*300010, 0)
    for _ in range(N):
        A = int(input())
        a = max(A-K, 0)
        b = min(A+K, 300000)
        tmp = seg.query(a, b+1) + 1
        seg.update(A, tmp)
    
    print(seg.query(0, 300000))


if __name__ == '__main__':
    main()

Measured memory_bytes: 85320
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
 
    int N = stdIn.nextInt();
    int sum= 0;
 
    for (int i = 1; i <= N; i++)
        sum += i;

    System.out.println(sum);
    }
}

Measured memory_bytes: 8788
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,d=INTM()
    ct=min(b,d)-max(a,c)
    print(max(0,ct))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import sys
  
def ans(num):
    ans = 0
  
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a+b+c+d == num:
                        ans += 1
  
    return ans
  
  
def main():
    a = []
  
    for line in sys.stdin:
        a.append(int(line))
  
    for line in a:
        print(ans(line))
  
if __name__ == "__main__":
    main()


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;
using Real=long double;
const lint INF=1e18;

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

   int N; lint K; cin>>N>>K;
   vector<int> a(N);
   for(int i=0;i<N;i++) cin>>a[i];
   sort(a.begin(),a.end());

   auto check=[&](lint x)
   {
      lint cnt=0;
      for(int i=0;i<N;i++){
         if(a[i]>0){
            lint mx=floor((Real)x/a[i]);
            cnt+=upper_bound(a.begin(),a.begin()+i,mx)-a.begin();
         }else if(a[i]<0){
            lint mn=ceil((Real)x/a[i]);
            cnt+=(a.begin()+i)-lower_bound(a.begin(),a.begin()+i,mn);
         }else{
            cnt+=(x>=0? i:0);
         }
      }
      return cnt>=K;
   };

   lint ng=-INF-1,ok=INF;
   while(ok-ng>1){
      lint mid=(ng+ok)/2;
      (check(mid)? ok:ng)=mid;
   }
   cout<<ok<<endl;
   return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define er erase
#define bg begin()
#define ed end()
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define enter cout << "\n"
#define space cout << " "
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (n); ++i)
#define fj(st,n) for (int j = (st); j <= (n); ++j)
#define fk(st,n) for (int k = (st); k <= (n); ++k)
#define fq(st,n) for (int q = (st); q <= (n); ++q)
#define fw(st,n) for (int w = (st); w <= (n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (n); ++(i))
#define ei(st,n) for (int i = (st); i >= (n); --i)
#define ej(st,n) for (int j = (st); j >= (n); --j)
#define ek(st,n) for (int k = (st); k >= (n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (n); --(i))
#define ri(st,n) for (int i = (st); i < (n); ++i)
#define rj(st,n) for (int j = (st); j < (n); ++j)
#define rk(st,n) for (int k = (st); k < (n); ++k)
#define rq(st,n) for (int q = (st); q < (n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = (int)1e9;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 1e9 + 7;
const int maxn = (int) 1e6 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0));

ll n, y, x[maxn], s[maxn], ans, p[maxn];

int main() {
//    fin("t.in");
    sync;
    cin >> n;
    fi(1, n) {
        cin >> x[i];
    }
    y = 1;
    clean(p);
    x[0] = -1;
    s[0] = 0;
    fi(1, n) {
        while (s[i - 1] < i - 1) {
            s[i - 1] += 2;
            ++y;
        }
        s[i] = s[i - 1] + x[i] - x[i - 1] - 1;
//        cout << s[i] << endl;
        ++p[y];
    }
    ans = 1;
    y = 0;
    fi(1, n) {
        y += p[i];
        ans *= y;
        ans %= mod;
        --y;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n,cnt=0,k=0;
  string s,t,a,b;
  cin >> n >> s >> t;
  reverse(s.begin(),s.end());
  for(int i=0;i<n;i++){
    	b += t.at(i);
    	a += s.at(i);
    reverse(a.begin(),a.end());
  if(a==b) cnt = a.size();
    reverse(a.begin(),a.end());
  }
  cout << n*2-cnt << endl;
}

Measured memory_bytes: 256
from math import ceil


def main():
    area = int(input())
    upper_limit = 10 ** 9
    answer = [0, 0, upper_limit, 1, 0, ceil(area / upper_limit)]
    answer[4] = upper_limit * answer[5] - area
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060