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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);

using namespace std;
ll mod = 1e9 + 7;
const ll N = 1e5 + 7;


ll arr[N];
ll fact[1000001]; ll inv[1000001];
ll primes[100007];
ll modPower(ll b, ll p) {
	if (p == 0)
		return 1;

	ll halfpow = modPower(b, p / 2);
	ll toReturn = (halfpow * halfpow) % mod;
	if (p % 2)
		toReturn = (toReturn * b) % mod;

	return toReturn;
}


void pre(ll n) {

	fact[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i <= n; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = modPower(fact[i], mod - 2);
		arr[i] = modPower(i, mod - 2);
	}
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}


int main() {
    MohamedMotaz;
	pre(N);
    ll x, k; cin >> x >> k;
	 
    for (int i = 1; i <= x; i++) {
        cin >> arr[i];
    }
	sort(arr + 1, arr + x + 1);
	ll ans = 0;
	for (int i = 1; i <= x; i++) {
		
		if (i >= k) {
			//cout << "max: " << arr[i] << " " << ncr(x, k - 1) << endl;
			ans += ((arr[i] % mod) * (ncr(i - 1, k - 1) % mod) % mod);
		}
		if (i <= x - k + 1) {
			//cout << "min: " << arr[i] << " " << ncr(x, k - 1) << endl;
			ans -= ((arr[i] % mod) * (ncr(x - i, k - 1) % mod) % mod);
		}

	}
	cout << ans % mod;
}



















Measured memory_bytes: 3840
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n;
string f[20];
int w[20],s[20];

bool isOK(vi num){
    int cap=99999999;
    
    rep(i,num.size()){
        cap=min(cap-w[num[i]],s[num[i]]);
    }
    if(cap>=0)return true;
    else return false;
}

double solve(vi num){
    
    int up=0;
    rep(i,num.size()){
        up+=(i+1)*w[num[i]];
    }

    int div=0;
    rep(i,num.size()){
        div+=w[num[i]];
    }

    return (double)up/div;
}


int main() {
    
    while(cin>>n){
        if(n==0)break;
        
        vi num;
        rep(i,n){
            num.pb(i);
            cin>>f[i]>>w[i]>>s[i];
        }
        
        double Gmin=99999999;
        vi ans;
        do{
            if( isOK(num) ){
                double res=solve(num);
                
                
                if(Gmin>res){
                    Gmin=res;
                    ans=num;
                    
                }
            }
        }while( next_permutation(all(num)) );
        
        rep(i,n){
            cout<<f[ans[i]]<<endl;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
using namespace std;
int main(){

  string N;
  cin>>N;
  int num=0;
  for(int i=0;i<=(int) N.length()-1;i++){
  
    if(N[i]=='0')num+=0;
    else if(N[i]=='1')num+=1;
    else if(N[i]=='2')num+=2;
    else if(N[i]=='3')num+=3;
    else if(N[i]=='4')num+=4;
    else if(N[i]=='5')num+=5;
    else if(N[i]=='6')num+=6;
    else if(N[i]=='7')num+=7;
    else if(N[i]=='8')num+=8;
    else if(N[i]=='9')num+=0;
    
  }
  if(num%9==0)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

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

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

    if(op == '?') break;

    switch(op) {
      case '+':
        printf("%d\n", a + b);
        break;
      case '-':
        printf("%d\n", a - b);
        break;
      case '*':
        printf("%d\n", a * b);
        break;
      case '/':
        printf("%d\n", a / b);
        break;
      default:
        break;
    }
  }
}



Measured memory_bytes: 2120
#include<stdio.h>
int main(){
int a, b, c;
char op;
scanf("%d %c %d", &a, &op, &b);
while( 1 ){
if ( op == '+' ){
c = a + b;
printf("%d\n",c);
} 
else if ( op == '-' ){
c = a - b;
printf("%d\n",c);
} 
else if ( op == '*' ){
c = a * b;
printf("%d\n",c);
} 
else if ( op == '/' ){
c = a / b;
printf("%d\n",c);
} 
else {
break;
}
scanf("%d %c %d", &a, &op, &b);
}
return 0;
}


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

#define     MX        100005
#define     mod       1000000007
#define     ll        long long
#define     ld        long double
#define     mem(a,b)  memset(a,b,sizeof(a))
#define     fast()    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     F         first
#define     S         second
//#define     mp        make_pair
#define     inf       2e18
#define     PI        acos(-1)

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


map<ll,ll>mp;
ll n,a,b,c,d;


ll process(ll now){
   // cout<<"start "<<now<<endl;
    if(now==0) return 0;
    if(now==1) return d;
    if(now>(n*5LL)) return inf;
    if(mp[now]>0) return mp[now];

   // cout<<"Now"<<now<<endl;
    ll res=inf;
    if(now%2LL) {
        //cout<<"enter two "<<now<<endl;
        ll rem=now%2LL;
        res= min(res,process((now-rem)/2LL) +rem*d + a);
        res= min(res,process((now+2-rem)/2LL) + (2-rem)*d +a);
       // cout<<"two"<<endl;
    }
    else res= min(res,process(now/2LL)+a);
    if(now%3LL) {
       // cout<<"enter three "<<now<<endl;
        ll rem=now%3LL;
        res= min(res,process((now-rem)/3LL) +rem*d +b);
        res= min(res,process((now+3-rem)/3LL) + (3-rem)*d + b);
        //cout<<"three"<<endl;
    }
    else res= min(res,process(now/3LL)+b);
    if(now%5LL) {
       // cout<<"enter five "<<now<<endl;
        ll rem=now%5LL;
        res= min(res,process((now-rem)/5LL) +rem*d +c);
        res= min(res,process((now+5-rem)/5LL) + (5-rem)*d +c);
       // cout<<"five"<<endl;
    }
    else res= min(res,process(now/5LL)+c);

    //cout<<"ret "<<now<<" "<<res<<endl;

    if((1.0*now*d)<res) res= now*d;
    //cout<<"ret "<<now<<" "<<res<<endl;
    return mp[now]=res;
}


int main(){
    fast();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t;
    cin>>t;
    while(t--){
        mp.clear();
        cin>>n>>a>>b>>c>>d;
        cout<<process(n)<<endl;

    }

}


Measured memory_bytes: 4420
a, b, k = map(int, input().split())

ans = set()
tmp = 0
for i in range(a, b + 1):
    tmp += 1
    if tmp <= k:
        ans.add(i)
    else:
        break
        
tmp = 0
for j in range(b, a - 1, -1):
    tmp += 1
    if tmp <= k:
        ans.add(j)
    else:
        break

ans = list(ans)
ans.sort()
for i in ans:
    print(i)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> ans;
    if(n == 1) return ans;
    for(ll i = 2; i*i <= n; i++){
        int cnt = 0;
        while(n%i == 0){
            cnt++;
            n /= i;
        }
        if(cnt) ans.eb(i, cnt);
    }
    if(n != 1) ans.eb(n, 1);
    return ans;
}

void Main() {
    ll n, p; cin >> n >> p;
    ll ans = 1;
    for(auto [pp, ee] : factorize(p)){
        // cout << pp << " " << ee << endl;
        int cnt = ee/n;
        if(cnt == 0) continue;
        ll tmp = 1;
        rep(i, cnt) tmp *= pp;
        ans *= tmp;
    }
    cout << ans << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3576
n=int(input())
a=[int(i) for i in input().split()]

ans=0
def plus_minus(i):
    while True:
        if i==n-1:
            break
        if a[i]==a[i+1]:
            i+=1
            continue
        if a[i]<a[i+1]:
            return 1
        if a[i]>a[i+1]:
            return -1

check=plus_minus(0)            
ans=1
for j in range(n-1):
    if check==1:
        if a[j] <= a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
    else:
        if a[j]>=a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
print(ans)

Measured memory_bytes: 14428
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort(reverse=True)
r=n-(k-1)
ans= float('inf')
for i in range(r):
    if ans>h[i]-h[i+k-1]:
        ans=h[i]-h[i+k-1]
print(ans)

Measured memory_bytes: 7384
n = gets.chomp.to_i
ary = []
n.times do |i|
  ary << gets.chomp.to_i
end

flag = true
# すべて偶数なら先手のmake
ary.each do |item|
  if item%2 != 0
    flag = false
    break
  end
end

if flag
  puts "second"
else
  puts "first"
end


Measured memory_bytes: 2684
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    int n = (int)S.length();
    vector<int> ans(n,0);

    {
        int Rcnt = 0;
        for(int i = 0; i < n;i++){
            if(S[i] == 'R'){
                Rcnt++;
            }else{
                ans[i] += Rcnt/2;
                ans[i-1] += Rcnt - Rcnt/2;
                Rcnt = 0;
            }
        }
    }
    {
        int Lcnt = 0;
        for(int i = n-1; i >= 0;i--){
            if(S[i] == 'L'){
                Lcnt++;
            }else{
                ans[i] += Lcnt/2;
                ans[i+1] += Lcnt - Lcnt/2;
                Lcnt = 0;
            }
        }
    }
    cout << ans << endl;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve<ll>(0);
    // cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3844
a, b = input().split(' ')
a = int(a)
b = int(b)

score = 0

if a >= b:
    score += a
    a -= 1
else:
    score += b
    b -= 1

if a >= b:
    score += a
    a -= 1
else:
    score += b
    b -= 1

print(score)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    int n, k;
    int count = 1;
    scanf("%d%d", &n, &k);
    while (1)
    {
        if (n < k)
            break;
        n = n / k;
        count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int di[] = { -1, -1, -1,  0, 0,  1, 1, 1 };
int dj[] = { -1,  0,  1, -1, 1, -1, 0, 1 };

void _main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];
    rep(i, 0, H)
    {
        rep(j, 0, W)
        {
            if (S[i][j] == '#')
            {
                cout << S[i][j];
            }
            else
            {
                int num = 0;
                rep(k, 0, 8)
                {
                    const int ni = i + di[k];
                    const int nj = j + dj[k];
                    if (ni >= 0 && ni < H && nj >= 0 && nj < W)
                    {
                        if (S[ni][nj] == '#')
                        {
                            ++num;
                        }
                    }
                }
                cout << num;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

ll n,a,b;

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

  ll ans = (b*(n-1)+a)-(a*(n-1)+b)+1;

  ans = max(ans,(ll)0);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = [-1]*N

for i in range(M):
    if(ans[sc[i][0]-1] == -1 or ans[sc[i][0]-1] == sc[i][1]):
        ans[sc[i][0]-1] = sc[i][1]
    else:
        print("-1")
        exit()

if N>1:
    if(ans[0] == 0):
        print("-1")
        exit()
    elif(ans[0] == -1):
        ans[0] = 1
A = 0
for i in range(N):
    if(ans[i] != -1):
        A += ans[i]*(10**(N-i-1))
print(A)

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int sum = 0;

  vector<int> A(N + 2);
  for (int i = 1; i < N + 1; i++) {
    cin >> A.at(i);
    sum += abs(A.at(i - 1) - A.at(i));
  }
  sum += abs(A.at(N));

  for (int i = 1; i < N + 1; i++) {
    int a = A.at(i - 1), b = A.at(i), c = A.at(i + 1);
    cout << sum - abs(a - b) - abs(b - c) + abs(a - c) << "\n";
  }
}

Measured memory_bytes: 1664
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0;i < n;i++){
			int count = scan.nextInt();
			int[] a = new int[count];
			for(int j = 0;j < count;j++){
				a[j] = scan.nextInt();
			}
			int up = 0;
			int down = 0;
			int t;
			for(int j = 0;j < count-1;j++){
				t = a[j+1] - a[j];
				if(up < t){
					up = t;
				}else if(down > t){
					down = t;
				}
			}
			System.out.println(up + " " + (-down));
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();

		int ans = 0;
		while (y >= x) {
			ans++;
			x = 2 * x;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 20564
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    A = (A + 11) % 13;
    B = (B + 11) % 13;
    if (A < B) {
        cout << "Bob" << endl;
    } else if (A > B) {
        cout << "Alice" << endl;
    } else {
        cout << "Draw" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+100;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    bool flag=true;
    rep(i,n){
        cin >> a[i];
        if(a[i]%2==0 && !(a[i]%3==0 || a[i]%5==0)){
            flag=false;
            break;
        }
    }
    if(flag){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

string s;
int main(){
    cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define II pair<int, int>
#define LL pair<ll, ll>
#define VI vector<int>
#define VB vector<bool>
#define VS vector<string>
#define VL vector<ll>
#define VII vector<II>
#define VLL vector<LL>
#define PB push_back
#define B begin()
#define E end()
#define F first
#define S second
#define SZ size()
#define P complex <ll> 
#define X real()
#define Y imag()
const int oo = 1e9;
const ll mod = 1e7;
/* * * *   * * *   	* * * */

/* *
 *
 * Author: Hamkor
 *
 * */
 VI a;
 void d(int n){
	 for (int i=1; i*i<=n; ++i){
		 if (n%i==0){
			 a.PB(i);
			 if (n/i != i)a.PB(n/i);
		 }
	 }
 }
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m = 0; cin>>n;
	for (int i=1; i<=n; ++i){
		if (i%2){
			a.clear();
			d(i);
			if ((int)a.SZ == 8) m++;
		}
	}
	cout<<m;
	return 0;
}


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

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

    int s, t, c;
    vector<vector<int>> imos(C + 1, vector<int>(2 * 100005, 0));
    for (int i = 0; i < N; i++)
    {
        cin >> s >> t >> c;
        imos[c][2 * s - 1]++;
        imos[c][2 * t]--;
    }

    for (int i = 0; i < imos.size(); i++)
    {
        for (int j = 1; j < imos[i].size(); j++)
        {
            imos[i][j] += imos[i][j - 1];
        }
    }
    for (int i = 0; i < imos.size(); i++)
    {
        for (int j = 1; j < imos[i].size(); j++)
        {
            imos[i][j] = min(imos[i][j], 1);
        }
    }

    int ans = 0;
    for (int i = 0; i < 2 * 100005; i++)
    {
        int tmp = 0;
        for (int j = 0; j < imos.size(); j++)
        {
            tmp += imos[j][i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    // for (int i = 1; i < imos.size(); i++)
    // {
    //     imos[i][0] += imos[i - 1][0];
    // }
    // for (int i = 1; i < imos.size(); i++)
    // {
    //     for (int j = 1; j < imos[i].size(); j++)
    //     {
    //         imos[i][j] += imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1];
    //     }
    // }

    // int ans = 0;
    // for (int s : imos.back())
    // {
    //     ans = max(ans, s);
    // }
    // assert(imos.back().back() == 0);
    // cout << ans << endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

string a="abcdefghijklmnopqrstuvwxyz";

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s;
  cin>>s;
  int ans=0;
  while(s.size()>1){
    if(s[0]==s[s.size()-1])s.erase(s.begin()),s.erase(s.begin()+s.size()-1);
    else if(s[0]=='x')ans++,s.erase(s.begin());
    else if(s[s.size()-1]=='x')ans++,s.erase(s.begin()+s.size()-1);
    else{
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
int solve()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int> > g(m);
	priority_queue<int> q;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		if(x>m)
			continue;
		g[m-x].pb(y);
	}
	int sum=0;
	for(int i=m-1;i>=0;i--){
		for(auto it:g[i]){
			q.push(it);
		}
		if(!q.empty()){
			sum+=q.top();
			q.pop();
		}
	}
	cout<<sum<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#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 cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       s.find(x) != s.end()

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
ll f[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin1(n);
    for1(i, n) {
        cin1(a[i]);
        sum += a[i];
        f[a[i]]++;
    }

    cin1(q);

    while(q--) {
        cin2(x, y);
        sum -= (f[x] * x);
        sum += (f[x] * y);
        f[y] += f[x];
        f[x] = 0;
        cot1(sum);
    }

    return 0;
}



Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define N 300009
#define inf 1e18
int mod=1e9+7;
int maxN=1e9;

#define PI 3.141596535

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    int a[n+1]={0};
    for(int i=2;i<=n;i++){
        int x;cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<"\n";
    return 0;
}

Measured memory_bytes: 5152
N, X = [int(x) for x in input().split()]

def main():
    x = X
    min_num = float('inf')
    for _ in range(N):
        m = int(input())
        x -= m
        min_num = min(m, min_num)
    print(N + x // min_num)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

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

  if(abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }else{
    if(abs(a-b)<=d&&abs(b-c)<=d){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int main()
{
    char a[5];
    scanf("%s",a);
    for(int i=1;i<4;i++)
    if(a[i]==a[i-1]){
        printf("Bad\n");
        return 0;
    }
    printf("Good\n");
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)


int A[33] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	fast;
	
	int K; cin>>K;
	cout<<A[K];
	
	
}



Measured memory_bytes: 256
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] <= h[b-1]:
        ans[a-1] = 0
    if h[b-1] <= h[a-1]:
        ans[b-1] = 0
print(sum(ans))

Measured memory_bytes: 20100
#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
inline int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); }
inline int lcm(int a,int b) { return (a*b)/gcd(a,b); }
int a,b;
signed main() {
	read(a); read(b);
	if(a<=10) print(b+(10-a)*100);
	else print(b);
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
for j in range(N):
    a=bisect_left(A, B[j])
    c=bisect_right(C, B[j])
    ans+=a*(N-c)
print(ans)

Measured memory_bytes: 23360
// TODO: 計算量が非常に多い気がする.
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define pb push_back
#define a first
#define b second
const int MAX = 101010;
int memo[MAX];
vector<int> graph[MAX];
map<pair<int, int>, int> m; // 着色時の頂点ペア, 色を保存.
vector<pair<int, int>> o;   // 入力時の頂点ペアを保存.
set<int> color[MAX];
int maxColor;

// グラフを幅優先探索する.
// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param s: 探索開始の頂点番号.
// @return: 特に無し.
void bfs(int s){
    
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. 訪問済みフラグ設定.
    // ※スタート地点は, 距離ゼロを指定.
    memo[s] = 0;
    
    // 3. 探索地点 s をキュー q に追加.
    q.push(s);
    
    // 4. キュー q が 空になるまで, 探索.
    while(!q.empty()){
        
        // 5. 頂点 u を キュー q から取り出す.
        int u = q.front();
        q.pop();
        
        // 6. 取り出した要素を処理.
        int c = 1;
        for(auto &e : graph[u]){
            // 6-1. 頂点u の 隣接する頂点e が, 未訪問だったら, キュー q に追加.
            if(memo[e] == 0 && e != s){
                // 頂点e を キュー q に追加.
                q.push(e);
                // 頂点e に 距離memo[u] プラス 1 を 加算.
                memo[e] += (memo[u] + 1);
                // 色を着色.
                // すでに使用している色があれば, Skip.
                while(color[u].count(c) != 0) c++;
                color[u].insert(c);
                color[e].insert(c);
                m[{u, e}] = c;
                m[{e, u}] = c;
                // 必要とする色の最大数を更新.
                maxColor = max(maxColor, c);
            }
        }
    }
}

int main(){
    
    // 1. 入力情報.
    int N, a, b;
    scanf("%d", &N);
    
    // 2. グラフ作成.
    rep(i, N - 1){
        scanf("%d %d", &a, &b);
        a--, b--;
        graph[a].pb(b);
        graph[b].pb(a);
        o.pb({a, b}); // オリジナルの入力情報.
    }
    
    // 3. 頂点 0 から 探索.
    bfs(0);
    // rep(i, N) printf("%d ", memo[i]);
    // printf("\n");
    // printf("maxColor=%d\n", maxColor);
    // for(auto &p : m) printf("a=%d b=%d c=%d\n", p.a.a, p.a.b, p.b);
    
    // 4. 出力.
    printf("%d\n", maxColor);
    for(auto &p : o) printf("%d\n", m[p]);
    return 0;

}

Measured memory_bytes: 33780
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, M;
  get(N, M);
  vector<int> cnt(N);
  FOR(i, M) {
    int a, b;
    get(a, b);
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }
  bool f = 1;
  FOR(i, N) {
    if (cnt[i] % 2 == 1)
      f = 0;
  }
  print(f ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct time
{
	long int start;
	long int end;
}Ti;
Ti t[200005];

bool comp(Ti a,Ti b)
{
	return a.start<b.start;
}

int main()
{
	long int T,sum=0;
	int N,i;
	scanf("%d %ld",&N,&T);
	for(i=1;i<=N;i++)
	{
		scanf("%d",&t[i].start);
		t[i].end=t[i].start+T;
	}
	sort(t+1,t+N+1,comp);
	Ti now=t[1];
	sum=now.end-now.start;
	for(i=2;i<=N;i++)
	{
		if(now.end>=t[i].start)
		{
			if(now.end>=t[i].end) continue;
			else
				{
					sum+=t[i].end-now.end;
					now.end=t[i].end;
				}
		}
		else
		{
			sum+=t[i].end-t[i].start;
			now=t[i];
		}
	}
	printf("%d",sum);
} 

Measured memory_bytes: 3328
from heapq import heappop, heappush


def solve(nn, mm, ss, line_list, cd_list):
    if ss > 5000:
        ss = 5000
    g = dict()
    for i in range(1, nn + 1):
        for s in range(5001):
            g[i * 10000 + s] = dict()
            if s + cd_list[i - 1][0] < 5000:
                g[i * 10000 + s][i * 10000 + s + cd_list[i - 1][0]] = cd_list[i - 1][1]
            elif s < 5000:
                g[i * 10000 + s][i * 10000 + 5000] = cd_list[i - 1][1]
    for u, v, a, b in line_list:
        for s in range(a, 5001):
            g[u * 10000 + s][v * 10000 + s - a] = b
            g[v * 10000 + s][u * 10000 + s - a] = b

    # start from 1
    # d[i, j] = best time at city i with silver j
    d = [10 ** 18] * ((nn + 1) * 10000)
    d[10000 + ss] = 0
    h = []
    heappush(h, (0, 10000 + ss))
    while len(h) > 0:
        t, u = heappop(h)
        for v in g[u].keys():
            if t + g[u][v] < d[v]:
                d[v] = t + g[u][v]
                heappush(h, (t + g[u][v], v))

    res = []
    for i in range(2, nn + 1):
        res.append(min(d[i * 10000:(i + 1) * 10000]))
    # print(res)
    return res


def main():
    n, m, s = map(int, input().split())
    line_list = [list(map(int, input().split())) for _ in range(m)]
    cd_list = [list(map(int, input().split())) for _ in range(n)]
    res = solve(n, m, s, line_list, cd_list)
    for r in res:
        print(r)


def test():
    assert solve(3, 2, 1, [[1, 2, 1, 2], [1, 3, 2, 4]], [[1, 11], [1, 2], [2, 5]]) == [2, 14]
    assert solve(
        4, 4, 1, [[1, 2, 1, 5], [1, 3, 4, 4], [2, 4, 2, 2], [3, 4, 1, 1]], [[3, 1], [3, 1], [5, 2], [6, 4]]
    ) == [5, 5, 7]


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 174532
N = int(input())
book = []
for i in range(N):
    s , p = input().split()
    book.append([s,int(p),i + 1])
if N == 1:
    print(1)
    exit()
book.sort()
tmp_name = book[0][0]
tmp_list = []
tmp_list.append(book[0])

for i in range(1,N):
    if book[i][0] == tmp_name:
        tmp_list.append(book[i])
    else:
        tmp_list.sort(key = lambda x: -x[1])
        for j in tmp_list:
            print(j[2])
        tmp_name = book[i][0]
        tmp_list = []
        tmp_list.append(book[i])
    if i == N - 1:
        tmp_list.sort(key=lambda x: -x[1])
        for j in tmp_list:
            print(j[2])


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  int a, b;

  scanf("%d%d", &a, &b);
  if(a > b){
    printf("a > b\n");
  }else if(a < b){
    printf("a < b\n");
  }else{
    printf("a == b\n");
  }

  return 0;
}

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

#define ll long long
#define endl long long
using namespace std;

int arr[5];

int main()
{
    int k;
    for(int i=0; i<5; i++) cin >> arr[i];
    sort(arr, arr+5);
    cin >> k;
    if(arr[4] - arr[0] > k) cout << ":(";
    else cout << "Yay!";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>

using namespace std;


int digitSum(int n) {

    int sum = 0;

    while (n != 0) {

        sum += (n % 10);

        n = n / 10;
    }

    return sum;
}

bool isHarshadNumber(int n) {

    return n % digitSum(n) == 0;
}

int main() {

    int N;
    cin >> N;

    if (isHarshadNumber(N)) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }

    return 0;
}

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

int main(void)
{
    int i;

    enum {B, C} classify;

    int ball[10];

    bool isYES = true;

    int datasets;
    scanf("%d", &datasets);

    while (datasets--) {
        int b_list[10] = {0},c_list[10] = {0};
        int b_cnt = -1, c_cnt = -1;
        for (i = 0; i < 10; i++) {
            b_list[i] = c_list[i] = 0;
        }

        for (i = 0; i < 10; i++) {
            scanf("%d", ball + i);
        }

        b_list[++b_cnt] = ball[0];
        classify = B;
//        /**/printf("b_list[%d] = %d\n", b_cnt, b_list[b_cnt]);

        for (i = 1; i < 10; i++) {
            if (classify == B) {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
//                            /**/printf("b_list[%d] = %d\n", b_cnt, b_list[b_cnt]);
                        } else {
                            c_list[++c_cnt] = ball[i];
//                            /**/printf("c_list[%d] = %d\n", c_cnt, c_list[c_cnt]);
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
//                        /**/printf("b_list[%d] = %d\n", b_cnt, b_list[b_cnt]);
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
//                    /**/printf("c_list[%d] = %d\n", c_cnt, c_list[c_cnt]);
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            } else {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
//                            /**/printf("b_list[%d] = %d\n", b_cnt, b_list[b_cnt]);
                        } else {
                            c_list[++c_cnt] = ball[i];
                            /**/printf("c_list[%d] = %d\n", c_cnt, c_list[c_cnt]);
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
//                        /**/printf("b_list[%d] = %d\n", b_cnt, b_list[b_cnt]);
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
//                    /**/printf("c_list[%d] = %d\n", c_cnt, c_list[c_cnt]);
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            }
        }

        if (isYES == true) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N=1e6+10;

int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        if(x%2==0){
            int cnt=0;
            while(x%2==0){
                x/=2;
                cnt++;
            }
            ans+=cnt;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#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 N; cin >> N;
  string S;
  cin >> S;

  VI ls(N+1), rs(N+1);
  REP(i,N)
	rs[i+1] = rs[i] + (S[i] == '>');
  for(int i=N-1;i>=0;--i)
	ls[i] = ls[i+1] + (S[i] == '<');

  int ans = 0;
  REP(i,N){
	if(rs[i+1] == ls[i]){
	  if(S[i] == '<'){
		int it = lower_bound(ALL(rs), 1) - begin(rs) - 1;
		maxi(ans, N - it);
	  }
	  else{
		int it = lower_bound(RALL(ls), 1) - ls.rbegin() - 1;
		maxi(ans, N - it);
	  }
	}
	else if(rs[i+1] > ls[i]){
	  int it = lower_bound(ALL(rs), rs[i+1]-ls[i]) - begin(rs) - 1;
	  maxi(ans, N - it);
	}
	else{
	  int it = lower_bound(RALL(ls), ls[i]-rs[i]) - ls.rbegin() - 1;
	  maxi(ans, N - it);
	}
  }
  cout << ans << endl;
  
  return 0;
}

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

#define int long long
#define loop(i,n) for(int i=1;i<=n;i++)
int a[100002];
int d[100002];

signed main(){
  int n,t,q,x;
  cin>>n>>t>>q;
  loop(i,n)cin>>a[i]>>d[i];
  a[0]=(int)(-5e18);
  a[n+1]=(int)(5e18);
  d[0]=1;
  d[n+1]=2;
  loop(i,q){
    cin>>x;
    if(d[x]==1){
      int y=x;
      while(d[y]==1)y++;
      cout<<min(a[x]+t,(a[y-1]+a[y])/2)<<endl;
    }
    if(d[x]==2){
      int y=x;
      while(d[y]==2)y--;
      cout<<max(a[x]-t,(a[y]+a[y+1])/2)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4624
#include<iostream>
using namespace std;
int c[110][110];
int t[110][110];
int main(){
	int n,m;
	for(;cin>>n>>m,n+m;){
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			c[i][j]=t[i][j]=10000000;
		}
	}
	for(int i=1;i<=m;i++)c[i][i]=t[i][i]=0;
	for(int i=0;i<n;i++){
		int a,b,cost,time;
		cin>>a>>b>>cost>>time;
		c[a][b]=c[b][a]=min(cost,c[a][b]);
		t[a][b]=t[b][a]=min(time,t[a][b]);
	}
	for(int k=1;k<=m;k++){
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m;j++){
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
				t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
			}
		}
	}
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
		int p,q,r;
		cin>>p>>q>>r;
		cout<<(r?t[p][q]:c[p][q])<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 952
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    x = N % 1000
    print(1000 - x if x != 0 else 0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 72432
#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n>>p)

    {
        if(m>p||m+n<p)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
n=int(input())
a_s=list(map(int,input().split()))

def sakujo(a_list):
    for i in range(len(a_list)):
        if a_list[i]!=0:
            end=i
            break
    return a_list[i:]

while True:
    a_s.sort()
    a_s=sakujo(a_s)
    if len(a_s)==1:
        break
    for i in range(1,len(a_s)):
        a_s[i]=a_s[i]%a_s[0]

print(sum(a_s))


Measured memory_bytes: 15020
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

"""
for h in range(1,N+1):
    for i in range(N):
        if A[i] == h:
            print(i + 1)
#このやり方でもOKだけど、nが馬鹿でかくなった時にTLEしちゃうよ
"""

S = []
for i in range (N):
    S.append([A[i] , i + 1])
S.sort()

for i in range(N):
    print(S[i][1])


Measured memory_bytes: 21468