akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14


using namespace std;


class UnionFind {
public:
    vector<int> parent;
    vector<int> setSize;

    UnionFind(unsigned int size) {
        parent.resize(size + 1);
        iota(parent.begin(), parent.end(), 0);
        setSize.resize(size + 1, 1);
    }

    // x??¨y???????????????????±??????????
    bool isSameSet(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    // x??¨y????±??????????????????????
    void unionSet(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) { return; }

        parent[x] = y;
        setSize[y] += setSize[x];
    }

private:
    // ??¨??????????±???????
    int findRoot(int x) {
        if (parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = findRoot(parent[x]);
        }
    }
};


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

    int n, q;
    cin >> n >> q;

    UnionFind uf(n);
    FOR(i, 0, q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            uf.unionSet(x, y);
        }
        else {
            cout << uf.isSameSet(x, y) << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3296
M, D = [int(_) for _ in input().split()]
ans = 0
for m in range(1, M+1):
  for d in range(1, D+1):
    d0 = d%10
    d10 = (d - d%10)//10
    if d0 > 1 and d10 > 1 and d0 * d10 == m: ans += 1
print(ans)



Measured memory_bytes: 8984
import math
import collections
def trial_division_sqrt(n):

    prime_count = collections.Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[n] += 1

    return prime_count
def pc(n, r):
    return math.factorial(n) // (math.factorial(n - r)  * math.factorial(r))
nCr = {}
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n;

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result;
s=0
x,N = map(int,input().split())

li = trial_division_sqrt(N)
li = li.most_common()
ans = 1
for i in range(0, len(li)):
    ans *= cmb(li[i][1] + x-1, x-1)
print(ans % (pow(10, 9)+7))

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

const int N = 1e5 + 10, M = 32;
int n, ans, x, ar[N], cnt[N], mark[M];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		x ^= ar[i];
		
		int tmp = ar[i];
		while (tmp % 2 == 0) {
			cnt[i]++;
			tmp /= 2;
		}
		mark[++cnt[i]]++;
	}
	
	for (int i = M - 2; i >= 0; i--)
		if (x & (1LL << i)) {
			if (!mark[i + 1])
				return cout << -1, 0;
			x = ~x;
			ans++;
		}
	cout << ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=155;
int n,K,P,f[N][N],g[2*N][N][N];
inline void sol1()
{
	K/=2;f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=K;j++)f[i][0]=(f[i][0]+f[i-1][j])%P;
		for(int j=0;j<K;j++)f[i][j+1]=(f[i][j+1]+f[i-1][j])%P;
	}
	int ans1=0,ans2=0;
	for(int i=0;i<=K;i++)ans1=(ans1+f[n/2][i])%P;
	for(int i=0;i<=K;i++)ans2=(ans2+f[(n+1)/2][i])%P;
	printf("%lld\n",1ll*ans1*ans2%P);
}
inline void sol2()
{
	int p;g[0][0][0]=1;
	for(int i=2;i-K<=n;p=i,i+=2)
	{
		for(int j=0;j<=n;j++)for(int k=0;k<=K+1;k++)g[i][0][0]=(g[i][0][0]+g[i-2][j][k])%P;
		if(i<=n)for(int j=0;j<=n;j++)for(int k=0;k<=K+1;k++)g[i][j+1][0]=(g[i][j+1][0]+g[i-2][j][k])%P;
		if(i>K)for(int j=0;j<=n;j++)g[i][0][0]=(g[i][0][0]+g[i-2][j][0])%P;
		if(i>K)for(int j=0;j<=n;j++)for(int k=1;k<=K+1;k++)g[i][0][k+1]=(g[i][0][k+1]+g[i-2][j][k])%P;
		if(i<=n&&i>K)for(int j=0;j<=n;j++)for(int k=0;max(k,j+1)<=K;k++)g[i][j+1][max(k,j+1)+1]=(g[i][j+1][max(k,j+1)+1]+g[i-2][j][k])%P;
	}
	int ans=0;for(int i=0;i<=n;i++)for(int j=0;j<=K+1;j++)ans=(ans+g[p][i][j])%P;
	printf("%d\n",ans);
}
int main()
{
	scanf("%d%d%d",&n,&K,&P);
	if(K&1)sol2();else sol1();
	return 0;
}

Measured memory_bytes: 27776
#include <iostream>
#include <algorithm>

#define MAXN 100000

using namespace std;

typedef long long ll;

int A[MAXN+1];
int N;

int main ()
{
  ll sum = 0;
  cin >> N;

  for ( int i = 1; i <= N; ++i ) {
    scanf("%d", &A[i]);
    sum += abs(A[i]-A[i-1]);
  }
  sum += abs(A[N]);

  for ( int i = 1; i <= N; ++i ) {
    if ( i != N ) {
      ll tmp = sum;
      tmp += abs(A[i+1]-A[i-1]);
      tmp -= abs(A[i+1]-A[i]);
      tmp -= abs(A[i]-A[i-1]);
      cout << tmp << "\n";
    } else {
      ll tmp = sum;
      tmp -= abs(A[i-1]-A[i]);
      tmp -= abs(A[i]);
      tmp += abs(A[i-1]);
      cout << tmp << "\n";
    }
  }
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

bool hoge(vector<int> &vec) {
  bool flag = true;
  int prev = - INT_MAX;
  for (auto &v : vec) {
    if (v < prev)
      flag = false;
    prev = v;
  }
  return flag;
}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  bool flag = hoge(vec);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      swap(vec[i], vec[j]);
      flag += hoge(vec);
      swap(vec[i], vec[j]);
    }
  }

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

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<bool> x(101),y(101);
    for(int i=a;i<b;i++){
        x[i]=true;
    }
    for(int i=c;i<d;i++){
        y[i]=true;
    }
    int cnt=0;
    for(int i=0;i<=100;i++){
        if(x[i]==true&&y[i]==true){cnt++;}
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    string str;
    cin>>str;
    n=str.length();
    s=0;
    for(i=1;i<n;i++)
    {
        if(str[i]!=str[i-1])s++;
    }
    cout<<s;
    /*reverse(str.begin(),str.end());
    z=0;
    for(i=1;i<n;i++)
    {
        if(str[i]!=str[i-1])z++;
    }
    cout<<min(s,z);*/
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map<int, int>Map[201000];
int n, H, W;
int main() {
	int i, j, x, y;
	scanf("%d%d%d",&H,&W, &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &x, &y);
		Map[x][y] = 1;
	}
	int ed = 1;
	for (i = 2; i <= H; i++) {
		if (!Map[i].empty()) {
			auto it = Map[i].begin();
			if (it->first <= ed) {
				printf("%d\n", i - 1);
				return 0;
			}
			if (it->first != ed + 1) ed = min(ed + 1, W);
		}
		else {
			ed = min(ed + 1, W);
		}
	}
	printf("%d\n", H);
}

Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  int i,cunt=0;
  cin>>s1>>s2;
  for(i=0;i<s1.size();i++)
  {
    if(s1[i]!=s2[i])cunt++;
  }
  cout<<cunt<<endl;
  return 0;}
  

Measured memory_bytes: 3840
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, k;
	cin >> n >> k;

	if((n+1)/2 >= k) puts("YES");
	else puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int digitHead(int n){
  int head;
  while(n >= 10){
    n/=10;
  }
  return n;
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> cnt(10,vector<int>(10));
  for(int i=0;i<10;i++) cnt[i].assign(10,0);

  for(int i=1;i<=n;i++){
    int head = digitHead(i);
    int tail = i%10;
    cnt[head][tail]++;
  }

  int sum = 0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      sum += cnt[i][j]*cnt[j][i];
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

/*#define int ll*/


int h,w;
string s[111];
bool can[111];
bool retu[111];

signed main(){
    cin>>h>>w;
    rep(i,0,h){
        cin>>s[i];
    }
    bool x=true;
    rep(i,0,h){
        x=true;
        rep(j,0,w){
            if(s[i][j]=='#')x=false;
            if(s[i][j]=='#')can[j]=true;
        }
        if(x)retu[i]=true;
    }
    rep(i,0,h){
        if(retu[i])continue;
        rep(j,0,w){
            if(!can[j])continue;
            cout<<s[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    string s;
    cin>>n>>m>>s;
    reverse(s.begin(), s.end());
    vector<ll> ans;
    ll po = 0;
    while(po<=n){
        ll t = po;
        FOR(i,1,m+1){
            if(i+po > n+1)break;        
            if(s[i+po] == '0')t = i+po;
        }
//        cout<<"t = "<<t<<endl;
        if(t >= n+1){
            po = t;
            break;
        }
        if(t == po && t < n){
            ans.push_back(-1);
            break;
        }
        else if(t == po){
            break;
        }
        else{
            ans.push_back(t - po);
            po = t;
        }
    }
    reverse(ans.begin(), ans.end());
    if(ans[0] == -1)cout<<-1<<endl;
    else{
        FOR(i,0,ans.size()){
            if(i != ans.size()-1)cout<<ans[i]<<" ";
            else cout<<ans[i]<<endl;
        }
    }
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; 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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

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

    if(a==b&&b==c)yn;

    return 0;
}
 
 


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

int main() {
    int n;
    cin >> n;
    
    vector<string> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec[i];
    }
    
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(string a: vec){
        if(a == "AC"){
            ac++;
        }else if(a == "WA"){
            wa++;
        }else if(a == "TLE"){
            tle++;
        }else if(a == "RE"){
            re++;
        }
    }
    
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

int a, b;

int main() {
    std::cin >> a >> b;
    if (a <= 0 && b >= 0 || a >= 0 && b <= 0) {
        std::cout << "Zero" << std::endl;
        return 0;
    }
    if (a > 0 && b > 0) {
        std::cout << "Positive" << std::endl;
        return 0;
    }
    if (a < 0 && b < 0) {
        int num = (b - a)+1;
        if (num % 2 == 0) {
            std::cout << "Positive" << std::endl;
        }
        else {
            std::cout << "Negative" << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define reps(i, start, end) for(int i = start; i < (int)(end); ++i)
vector<int> ki[200001];
int ans[200001];
bool visited[200001];
void add_tree(int i){
    visited[i] = true;
    for(int j = 0; j < ki[i].size(); j++){
        if(visited[ki[i][j]]) continue;
        ans[ki[i][j]] += ans[i];
        add_tree(ki[i][j]);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    rep(i, q){ 
        int p, x;
        cin >> p >> x;
        ans[p] += x;
    }
    add_tree(1);
    reps(i, 1, n){
        cout << ans[i] << " ";
    }
    cout << ans[n] << endl;
    return 0;
}

Measured memory_bytes: 23680
X,Y,A,B,C = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
pq = p[:X:]
q.sort(reverse=True)
pq.extend(q[:Y:])
pq.sort()
r.sort()
ans = 0
cnt = len(r)
for i in range(X+Y):
    if 0 < cnt and pq[i] < r[-1]:
        ans += r.pop()
        cnt -= 1
    else:
        ans += pq[i]

print(ans)

Measured memory_bytes: 105528
N, Q = map(int, input().split())
S = input()
query = [list(map(int, input().split())) for _ in range(Q)]
counter = [0]
for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        counter.append(counter[-1] + 1)
    else:
        counter.append(counter[-1])
for left, right in query:
    print(counter[right - 1] - counter[left - 1])

Measured memory_bytes: 31116
n = int(input())
s = list(map(int, input().strip().split()))

s.sort()

p = [s[-1]]
h = s[:-1]
for i in range(n):
    t = []
    o = []
    for j in p:

        while len(h):
            if h[-1] < j:
                o.append(h.pop())
                break
            t.append(h.pop())

    h.extend(t)
    p.extend(o)
    p.sort(reverse=True)
    h.sort()

print("Yes" if len(h) == 0 else "No")


Measured memory_bytes: 134828
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

int a[100010];
signed main(){
  int n;cin>>n;
  ivec dp(n+1,INF);
  rep(i,n)cin>>a[n-1-i];
  rep(i,n){
    *lower_bound(all(dp),a[i]+1)=a[i];
  }
  cout<<lower_bound(all(dp),INF)-dp.begin()<<endl;
  return 0;
}


Measured memory_bytes: 4808
chk _ _ _ [] = "NA"
chk t s i (x:xs) =
  if (s+x) >= t
  then show(i)
  else chk t (s+x) (i+1) xs

ans ([0]:_) = []
ans ([n]:x) =
  let d = take 12 x
      r = drop 12 x
      a = chk n 0 1 $ map (\ [a,b] -> a - b) d
  in
    a:(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c
      o = ans i
  mapM_ putStrLn o

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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int n;
	char s;
	scanf("%d", &n);
	int flag = 0;
	REP(i, n) {
		scanf(" %c", &s);
		if (s == 'Y')flag = 1;
		if (flag) {
			puts("Four");
			return 0;
		}
	}
	puts("Three");
}

Measured memory_bytes: 128
import heapq
n, m = map(int, input().split())
A = list(map(lambda x: int(x)*-1, input().split()))
heapq.heapify(A)

for i in range(m):
  max_elm = heapq.heappop(A)*-1 //2
  heapq.heappush(A, max_elm*-1)

print(sum(A)*-1)

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

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    set<int> Mochi;
    for (int i = 0; i < N; i++) {
        int d; cin >> d;
        Mochi.insert(d);
    }
    
    cout << Mochi.size() << endl;
    
    return 0;
}


Measured memory_bytes: 888
using System;

namespace Range {
    class Program {
        static void Main(string[] args) {
            string[] N = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(N[0]);
            int b = Convert.ToInt32(N[1]);
            int c = Convert.ToInt32(N[2]);

            if(a < b && b < c) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9060
import math

a,b,C = map(int,input().split())

rad = C / 180 * math.pi
h = b * math.sin(rad)
L = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(rad)) + a + b
S = h * a / 2 

print(S)
print(L)
print(h)


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int H, W;
  cin >> H >> W;
  VS vs(H);
  REP(y,H) cin >> vs[y];

  VVI num(H, VI(W));
  REP(y,H) REP(x,W){
	if(vs[y][x] == '#'){
	  REP(dy,3) REP(dx,3){
		int tx = x + dx - 1;
		int ty = y + dy - 1;
		if(0 <= tx && tx < W && 0 <= ty && ty < H)
		  num[ty][tx]++;
	  }
	}
  }

  REP(y,H) REP(x,W){
	if(vs[y][x] != '#'){
	  vs[y][x] = num[y][x] + '0';
	}
  }
  REP(y,H) cout << vs[y] << endl;

  return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

ans = 0
for i in range(2 ** H):
    for j in range(2**W):
        c = 0
        for ci in range(H):
            for cj in range(W):
                if ((i >> ci) & 1) and ((j >> cj) & 1) and C[ci][cj] == '#':
                    c += 1
        if c == K:
            ans += 1

print(ans)


Measured memory_bytes: 73988
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

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

using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
stdin.ReadLine().Split(" ")
|> Array.map int
|> Array.map (fun x -> if x = 1 then 14 else x)
|> Array.reduce (-)
|> fun x ->
    if x = 0 then "Draw"
    else if x > 0 then "Alice"
    else "Bob"
|> printfn "%s"


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

using Lint=long long;

int main()
{
    Lint t[2],a[2],b[2];
    cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1];

    Lint X=(a[0]-b[0])*t[0];
    Lint Y=(a[1]-b[1])*t[1];
    if(X>0) X=-X,Y=-Y;

    if(X+Y<0) cout<<0<<endl;
    else if(X+Y==0) cout<<"infinity"<<endl;
    else{
        Lint ans=(-X)/(X+Y)*2+((-X)%(X+Y)!=0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
c=0
M=[]
for i in range(l,r+1):
    M.append(i%2019)
    c+=1
    if c>2019:
        break
n=len(M)
a=2020
for i in range(n-1):
    for j in range(i+1,n):
        a=min(a,M[i]*M[j]%2019)
print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 500;
ll x, _p5[N*2+1];
ll *p5 = _p5+N;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  for(ll i=-N; i<=N; i++) p5[i] = i*i*i*i*i;
  cin >> x;
  for(ll i=-N; i<=N; i++) for(ll j=-N; j<=N; j++) if(p5[i]-p5[j]==x){
    cout << i << " " << j << endl;
    return 0;
  }
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int i=0,j=s.length()-1;
    int start=0,end=0;
    while(i<s.length()){
        if(s[i]=='A')
            break;
        i++;
    }
    while(j>-1){
        if(s[j]=='Z')
         break;
        j--;
    }
    
    cout << j-i+1;
    return 0;
}

Measured memory_bytes: 3744
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint LCM(lint a,lint b){
  if(a==0 || b==0) return 0;
  lint tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}

lint GCD(lint a,lint b){
  if(a==0 || b==0) return max(a,b);
  else return (a*b)/LCM(a,b);
}

int main(void){
    string S;
    cin >> S;
    int N=S.length();
    set<char> alf;
    rep(i,26) alf.insert('a'+i);
    rep(i,N) alf.erase(S[i]);
    if(N<26){
        cout << S << *alf.begin() << endl;
        return 0;
    }
    char s[26];
    rep(i,N) s[i]=S[i];
    if(!next_permutation(S.begin(),S.end())){
        cout << -1 << endl;
        return 0;
    }
    rep(i,26){
        if(S[i]!=s[i]){
            cout << S[i] << endl;
            break;
        }
        else cout << S[i];
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	const int MOD = 1000000007;
	int N, M;
	cin >> N >> M;
	
	vector<int> dp(N+1);
	vector<bool> ko(N+1, false);
	
	for(int i=0;i<M;i++){
		int a;
		cin >> a;
		ko[a] = true;
	}
	
	dp[0] = 1;
	if(ko[1]) dp[1] = 0;
	else dp[1] = 1;
	
	if(N>1) {
		for(int i=2;i<=N;i++){
			if(ko[i]) dp[i] = 0;
			else dp[i] = (dp[i-1] + dp[i-2]) % MOD;
		}
	}
	
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 640
n=int(input())
h=list(map(int,input().split()))

dp=[float('inf')]*n

dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
	dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 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;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int n, k; std::cin >> n >> k;
    std::cout << (n>k? 0:1) << std::endl;
    
    return 0;
}


Measured memory_bytes: 50036
#include <iostream>

using namespace std;

int main() {
  bool v[4] = {false, true, true, true};
  int a, b;
  cin >> a >> b;
  v[a] = false;
  v[b] = false;
  for (int i = 1; i < 4; ++i) {
    if (v[i])
      cout << i << endl;
  }
  return 0;
}


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

struct Rest {
  int i;
  string S;
  int P;
};

bool comp_S(Rest R1, Rest R2) { return R1.S < R2.S; }

bool comp_P(Rest R1, Rest R2) { return R1.P > R2.P; }

int main() {
  int N;
  cin >> N;
  vector<Rest> v;
  for (int i = 0; i < N; ++i) {
    string S;
    int P;
    cin >> S >> P;
    Rest R = {i + 1, S, P};
    v.push_back(R);
  }
  stable_sort(v.begin(), v.end(), comp_P);
  stable_sort(v.begin(), v.end(), comp_S);
  for (int i = 0; i < N; ++i) {
    cout << v.at(i).i << endl;
  }
}


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

int main()
{
    string s,s2,s3;
    cin>>s;
    ll n=s.size(),n1,n2;
    s2=s;
    reverse(s2.begin(),s2.end());
    if(s2==s){
        s2=s.substr(0,(n-1)/2);
        //cerr<<s2<<endl;
        s3=s2;
        reverse(s3.begin(),s3.end());
        if(s2==s3){
            s2=s.substr(((n+3)/2)-1,n);
            s3=s2;
            reverse(s3.begin(),s3.end());
            if(s2==s2){
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,q;
char s[maxn];
int sum[maxn];
int main(){
  scanf("%d%d",&n,&q);
  scanf("%s",s + 1);
  for(int i = 1;i < n;i++) if(s[i] == 'A' && s[i + 1] == 'C') sum[i] = 1;
  for(int i = 1;i <= n;i++) sum[i] += sum[i - 1];
  while(q--){
    int l,r;
    scanf("%d%d",&l,&r);
    printf("%d\n",sum[r - 1] - sum[l - 1]);
  }
  return 0;
}


Measured memory_bytes: 1280
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long s = 0;
        for (int i = 1; i <= n; i++)
        {
            if (i % 3 != 0 && i % 5 != 0)
            {
                s += i;
            }
        }

        Console.WriteLine(s);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27548
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        if (K <= A) {
            System.out.println(K);
        }else if ( K <= A + B ) {
            System.out.println(A);
        } else {
            int c = K - A - B;
            System.out.println(A - c);
        }
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

constexpr int lim = 3000;
int n;
double dp[lim][lim];
double p[lim];

int main(){
  cin >> n;
  REP(i, n) cin >> p[i];

  dp[0][0] = 1;
  REP(i, n)REP(j, n){
    dp[i+1][j] += dp[i][j] * (1-p[i]);
    dp[i+1][j+1] += dp[i][j] * p[i];
  }

  double ans = 0;
  FOR(i, 1, n+1){
    if(i*2 > n) ans += dp[n][i];
  }

  cout << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 70528
#include <stdio.h>
int main() {
    int H, W;
    while (true) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j) % 2 == 0) printf("#");
                else printf (".");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2620
import bisect
from itertools import accumulate

def func(x):
    cnt = 0
    for i in a:
        index = bisect.bisect_left(a, x - i)
        cnt += N - index
    if cnt >= M:
        return True
    else:
        return False

N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ar = sorted(a, reverse=True)
b = [0] + list(accumulate(ar))

MIN = 0
MAX = 2 * 10 ** 5 + 1
while MAX - MIN > 1:
    MID = (MIN + MAX) // 2
    if func(MID):
        MIN = MID
    else:
        MAX = MID

ans = 0
cnt = 0
for i in ar:
    index = bisect.bisect_left(a, MIN - i)
    ans += i * (N - index) + b[N - index]
    cnt += N - index
print(ans - (cnt - M) * MIN)

Measured memory_bytes: 14256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

		
	int a, b;
	cin >> a >> b;
	if(a==b) cout << a+b;
	else cout << max(a,b)+max(a,b)-1;


	return 0;
}


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

int main(){
	int N,C,K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for(int i=0;  i<N; i++) cin >> T[i];
	sort(T.begin(),T.end());

	int ans = 0;
	int i = 0;
	while(i<N){
		ans++;
		int a = T[i]+K;
		int p = i;
		for(int j=0; j<C; j++){
			if(T[p+j] > a)break;
			i++;
		}
	}

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



Measured memory_bytes: 3792
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll power(ll a, ll b)
{
	ll res = 1;
	while(b != 0)
	{
		if(b & 1)
			res = res * a;
		a = a * a;
		b /= 2;
	}
	return res;
}
ll func(ll n)
{
	if(n <= 0)
		return 0;
	ll ans = 0, val;
	for (int i = 45; i >= 1; --i)
	{
		val = power(2, i);
		if(val > n)
			continue;
		if((n / val) % 2 == 0)
			continue;
		ans = ans + val * ((n % val + 1) % 2 == 1);
	}
	ans = ans + (((n + 1) / 2) % 2 == 1);
	return ans;
}
int main()
{
	ll a, b;
	cin >> a >> b;
	cout << (func(b) ^ func(a - 1));
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<string,bool> m;
int main()
{
	string s;
	int k;
	cin>>s;
	cin>>k;
	int l=s.size();
	if(l>5)l=5;
	for(int i=1;i<=l;i++)
	{
		for(int j=0;j+i-1<s.size();j++)
		{
			m[s.substr(j,i)]=true;
		}
	}
	map<string,bool>::iterator it=m.begin();
	for(int i=1;i<k;i++)it++;
	cout<<it->first<<endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int k; char s[101];
  while (scanf("%d %s", &k, s) != EOF)
  {
    if (strlen(s) <= k) printf("%s\n", s);
    else
    {
      s[k] = '\0';
      printf("%s...\n", s);
    }
  }
  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <complex>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(void)
{
    int n;
    double x[100], y[100];
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    for (int i = 0; i < n; ++i)
        cin >> y[i];

    double d1 = 0.0, d2 = 0.0, d3 = 0.0, dm = 0.0;
    for (int i = 0; i < n; ++i) {
        d1 += abs(x[i] - y[i]);
        d2 += pow(x[i] - y[i], 2.0);
        d3 += abs(pow(x[i] - y[i], 3.0));
        dm = (dm < abs(x[i] - y[i]))? abs(x[i] - y[i]) : dm;
    }

    cout << fixed << setprecision(10);
    cout << pow(d1, 1.0 / 1.0) << endl;
    cout << pow(d2, 1.0 / 2.0) << endl;
    cout << pow(d3, 1.0 / 3.0) << endl;
    cout << dm << endl;
}







Measured memory_bytes: 3464
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m, nq; readV(n, m, nq);

  auto t = new int[][](n+2, n+2);

  foreach (_; 0..m) {
    int l, r; readV(l, r);
    ++t[1][r];
    --t[l+1][r];
    --t[1][n+1];
    ++t[l+1][n+1];
  }

  foreach (j; 0..n+2)
    foreach (i; 0..n+1)
      t[i+1][j] += t[i][j];
  foreach (i; 0..n+2)
    foreach (j; 0..n+1)
      t[i][j+1] += t[i][j];

  foreach (_; 0..nq) {
    int p, q; readV(p, q);
    writeln(t[p][q]);
  }
}


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

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

long long MOD = 1000000000 + 7;

ll N, K;

bool check(vector<ll> A, vector<ll> F, ll K, ll X){
  // X: score

  bool ret;
  ll time = 0;
  for(int i = 0; i < N; i++){
    ll tmp = A[i] * F[i];

    if(tmp <= X){
      continue;
    } else { 
      ll target = X / F[i];
      time += A[i] - target;
    }
  }
  if(time <= K) return true;
  else return false;
}


int main(){
  cout << setprecision(10);
  cin >> N >> K;
  vector<ll> A,F;
  A.assign(N,0);
  F.assign(N,0);

  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> F.at(i);
  }
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll max_val = 0;
  for(int i = 0; i < N; i++){
    max_val = max(max_val, A.at(i) * F.at(i));
  }



  /* どんな二分探索でもここの書き方を変えずにできる！ */

  ll right = max_val;
  ll left = -1;

  while (right - left > 1) {
    ll mid = left + (right - left) / 2;

    // K回以下の修行でスコアmidを達成できるかどうか
    if(check(A,F,K,mid)){
      right = mid;
    } else {
      left = mid;
    } 
  }

  cout << right << endl;

}


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

int main() {
  string s;
  cin >> s;
  int ans;
  if (s == "SSS") {
    ans = 0;
  } else if (s == "SSR" || s == "SRS" || s == "RSS" || s == "RSR" ||
             s == "SRS") {
    ans = 1;
  } else if (s == "SRR" || s == "RRS") {
    ans = 2;
  } else {
    ans = 3;
  }

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


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

ll n, m, i, j, k,z;

int main() {
	cin >> n >> m;
	k = m / n;
	for (i = k; i > 0; i--) {
		if (m % i == 0) {
			z = i;
			break;
		}

	}


	cout << z;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string a, b;
int dp[4005][4005] = { 0 };
int main() {
	while (cin >> a >> b) {
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < b.size(); j++) {
				if (a[i] == b[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		int res = 0;
		for (int i = 1; i <= a.size(); i++) {
			for (int j = 1; j <= b.size(); j++) {
				res = max(res, dp[i][j]);
			}
		}
		cout << res << endl;
	}
	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> G[N];
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }

    for (int i = 0; i < G[0].size(); i++) {
        int u = G[0][i];
        for (int j = 0; j < G[u].size(); j++) {
            int v = G[u][j];
            if (v == N - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12016
#include "bits/stdc++.h"
using namespace std;
#define shandom_ruffle random_shuffle
#define pb push_back
#define nl puts("")
using ll = long long;
using pii = pair<ll,ll>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using mpll = map<ll,ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 1e5;
const ll rc = 64;
const ll MOD = 998244353; 
int main() {
  string n; 
  cin >> n;
  if(n[0] == '7' || n[1] == '7' || n[2] == '7') puts("Yes");
  else puts("No");
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  long long ans = 0;
  ans += min(a, k);
  if (k > a + b) {
    ans -= k - a - b;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
using System;

namespace Csharp_ITP1 {
    class ITP1_1_D {
        static void Main() {
            var x = int.Parse(Console.ReadLine());
            var h = x / 3600;
            var m = x / 60 % 60;
            var s = x % 60;
            Console.WriteLine(h + ":" + m + ":" + s);
        }
    }
}


Measured memory_bytes: 15932
N = int(input())
H = [int(x) for x in input().split()]
ans, temp = 0, 0


for i in range(N-1)[::-1]:
    if H[i] >= H[i+1]:
        temp += 1
    else:
        if ans < temp:  ans = temp
        temp = 0
    
if ans < temp:  ans = temp
print(ans)

Measured memory_bytes: 14252