akhauriyash/Code-Regression huggingface dataset:
/* Author : tushar3105 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int (t); cin>>(t);while((t)--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	lli n, k, arr[210000];
	
	cin>>n>>k;
	
	ref(i,1,n)
		cin>>arr[i];
		
	lli pt=1, rem, cnt=0, visited[210000]={0}, pnt, len=0;
	
	do
	{
		visited[pt]=1;
		pt=arr[pt];
		cnt++;
	}	while (visited[pt]==0);
	
	fill (visited, visited+210000, 0);
	pnt=pt;
	
	do
	{
		len++;
		visited[pnt]=1;
		pnt=arr[pnt];
	}	while (visited[pnt]==0);
	
	cnt=0;
	pnt=1;
	
	while (cnt<k && pnt!=pt)
	{
		pnt=arr[pnt];
		cnt++;
	}
	
	if (cnt==k)
		cout<<pnt<<endl;
		
	else
	{
		//cout<<"IDHAR\n";
		rem=k-cnt;
		rem=rem%len;
	
		while (rem--)
			pnt=arr[pnt];
			
		cout<<pnt<<endl;
	}

	return 0;
}


Measured memory_bytes: 6864
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int, read().split())
A.sort()
print(A[-1]-A[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
	int A,B,M;
  cin >>A>>B>>M;
 vec a(A);
  vec b(B);
  for(int i=0;i<A;i++) cin >> a[i];
  for(int i=0;i<B;i++) cin >> b[i];
  vec x(M),y(M),c(M);
  for(int i=0;i<M;i++) cin >>x[i]>>y[i]>>c[i];
  int ans = 200000;
  for(int i=0;i<M;i++){
    int wa = a[x[i]-1] + b[y[i]-1] - c[i];
    ans = min(ans,wa);
  }
sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int waa = a[0] + b[0];
  ans = min(waa,ans);
	cout <<ans << endl;
}
  


Measured memory_bytes: 2176
import math, collections, heapq
T = int(input())


def solve(N, A, B, C, D):
    dp = collections.defaultdict(lambda: float('inf'))
    dp[0] = 0
    dp[1] = D

    def calc(x):
        if x in dp:
            return dp[x]
        cand = []
        q, r = divmod(x, 2)
        if r == 1:
            cand += [calc(x // 2) + min(A + D, D * (x - x // 2))]
            cand += [calc(x // 2 + 1) + min(A + D, D * (x - x // 2 - 1))]
        else:
            cand += [calc(x // 2) + min(A, D * (x - x // 2))]
        q, r = divmod(x, 3)
        if r < 2:
            cand += [calc(x // 3) + min(B + D * r, D * (x - x // 3))]
        else:
            cand += [calc(x // 3 + 1) + min(B + D, D * (x - x // 3 - 1))]
        q, r = divmod(x, 5)
        if r < 3:
            cand += [calc(x // 5) + min(C + D * r, D * (x - x // 5))]
        else:
            cand += [
                calc(x // 5 + 1) + min(C + D * (5 - r), D * (x - x // 5 - 1))
            ]
        dp[x] = min(cand)
        return dp[x]

    print(calc(N))


for _ in range(T):
    N, A, B, C, D = [int(_) for _ in input().split()]
    solve(N, A, B, C, D)


Measured memory_bytes: 20060
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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


























int main(){
    ll a, b;
    cin >> a >> b;
    ll ans;
    if(a <= 5) ans = 0;
    else if(a <= 12) ans = b / 2;
    else ans = b;
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }else if(a+b>c+d){
        cout<<"Left"<<endl;
    }else{
        cout<<"Right"<<endl;
    }
}


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

int main() {
	int k = 0, u = 0, p = 0, c = 0;
	string s; cin >> s;
	for (char v : s) {
		if (v == 'K')k++;
		if (v == 'U')u++;
		if (v == 'P')p++;
		if (v == 'C')c++;
	}
	printf("%d\n", min(k, min(u, min(p, c))));
}

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, ans;
ll f[51];
int prime[1000010], mark[1000010], tot;
ll find(ll x) {
    ll l = 1, r = 1000000, ret = -1;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (mid * (mid + 1) / 2 <= x) {
            ret = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    return ret;
}
void get_prime() {
    for (int i = 2; i <= 1000000; i++) {
        if (!mark[i]) prime[++tot] = i;
        for (int j = 1; j <= tot; j++) {
            if (prime[j] * i > 1000000) break;
            mark[i * prime[j]] = 1;
            if (i % prime[j] == 0) break;
        }
    }
}
int main() {
    get_prime();
    for (int i = 1; i <= 50; i++) {
        f[i] = find(i);
    }
    cin >> n;
    for (int i = 1; prime[i] * prime[i] <= n && i <= tot; i++) {
        if (n % prime[i] == 0) {
            ll cnt = 0;
            while (n % prime[i] == 0) {
                cnt++;
                n /= prime[i];
            }
            ans += f[cnt];
        }
    }
    if (n > 1) {
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 7860
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

int main() {
  int k, n;
  std::cin >> n >> k;
  std::vector<double> p;
  for (int i = 0; i < n; ++i) {
    double x;
    std::cin >> x;
    p.push_back((x + 1.) / 2.);
  }

  double pi = 0;
  for (int i = 0; i < k; ++i) {
    pi += p.at(i);
  }
  double max = pi;
  for (int i = k; i < n; ++i) {
    pi -= p.at(i - k);
    pi += p.at(i);
    max = std::max(pi, max);
  }

  std::cout << std::fixed << std::setprecision(12) << max << std::endl;
}


Measured memory_bytes: 2420
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  char s[50];

  scanf("%d%s", &n, s);

  ll ans = 0;
  
  for(int i=0;i < (1 << n);i++){
    char s1[19] = {}, s2[19] = {};
    int t1 = 0, t2 = 0;
    
    for(int j=0;j<n;j++){
      if(i & (1 << j)){
        s1[t1++] = s[j];
      }else{
        s2[t2++] = s[j];
      }
    }

    reverse(s1, s1+t1);
    reverse(s2, s2+t2);
    
    ll dp[20][20] = {};
    dp[0][0] = 1;
    
    for(int j=0;j<=t1;j++){
      for(int k=0;k<=t2;k++){
        if(!dp[j][k]) continue;
        
        int p = j+k + n;
        
        if(j < t1){
          if(s1[j] == s[p]) dp[j+1][k] += dp[j][k];
        }
        
        if(k < t2){
          if(s2[k] == s[p]) dp[j][k+1] += dp[j][k];
        }
      }
    }
    
    ans += dp[t1][t2];
  }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define N 60
vector<vector<ll>> ice(N,vector<ll>(N,1));
queue<vector<ll>> q;

void bfs(){
	ll nowx = q.front().at(0);
	ll nowy = q.front().at(1);
	q.pop();
	if (ice[nowx+1][nowy]==0 || ice[nowx+1][nowy]>ice[nowx][nowy]+1){
		ice[nowx+1][nowy] = ice[nowx][nowy]+1;
		q.push({nowx+1,nowy});
	}
	if (ice[nowx-1][nowy]==0 || ice[nowx-1][nowy]>ice[nowx][nowy]+1){
		ice[nowx-1][nowy] = ice[nowx][nowy]+1;
		q.push({nowx-1,nowy});
	}
	if (ice[nowx][nowy+1]==0 || ice[nowx][nowy+1]>ice[nowx][nowy]+1){
		ice[nowx][nowy+1] = ice[nowx][nowy]+1;
		q.push({nowx,nowy+1});
	}
	if (ice[nowx][nowy-1]==0 || ice[nowx][nowy-1]>ice[nowx][nowy]+1){
		ice[nowx][nowy-1] = ice[nowx][nowy]+1;
		q.push({nowx,nowy-1});
	}
}

int main(){
	ll h, w, cnt; cin >> h >> w;
	string s;
	cnt = 0;
	REP(i,h){
		cin >> s;
		REP(j,w){
			if (s[j]=='.') {
				ice[i+1][j+1]=0;
			}
			else {
				cnt++;
			}
		}
	}
	ice[1][1]=1;
	q.push({1,1});
	while (q.size()>0){
		bfs();
	}
	if (ice[h][w]==0){
		cout << -1 << endl;
	}
	else{
		cout << h*w-ice[h][w]-cnt << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		sc.close();
		
		if(X < A) {
			System.out.println(0);
		}else {
			System.out.println(10);
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

using P = pair<ll,ll>;

int main(){
    int N;cin >> N;
    vector<int> v(N);
    rep(i,N) cin >> v[i];

    vector<int> v1,v2;
    rep(i,N){
        if(i%2) v1.push_back(v[i]);
        else v2.push_back(v[i]);
    }

    map<int,int> mp1,mp2;
    for(const auto& val : v1) mp1[val]++;
    for(const auto& val : v2) mp2[val]++;

    vector<pii> p1,p2;
    for(const auto& p : mp1) p1.push_back(make_pair(p.second,p.first));
    for(const auto& p : mp2) p2.push_back(make_pair(p.second,p.first));
    sort(all(p1),greater<pii>());
    sort(all(p2),greater<pii>());

    if(p1.size() == 1){
        p1.push_back(make_pair(0,-1));
    }

    if(p2.size() == 1){
        p2.push_back(make_pair(0,-2));
    }

    int ans = 0;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(p1[i].second == p2[j].second) continue;
            int cnt = p1[i].first + p2[j].first;
            chmax(ans,cnt);
        }
    }

    cout << N - ans << endl;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
 

bool prime(int n) {
	for (int i = 2; i < sqrt(n) + 1; ++i)
	{
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}


int main() {
	int n;
	cin >> n;
	if (n == 2) {
		cout << 2;
	} else {
		int i = 0;
		while (!prime(n + i)) {
			i += 1;
		}
		cout << n + i;
	}
}
 


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

int main(void){
    int n;cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0&&n/i<10){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n;cin >> n;
   rep(i,n){
      char tmp;
      cin >> tmp;
      if(tmp == 'Y'){
         cout << "Four";
         return 0;
      }
   }
   cout << "Three";
   return 0;
}

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

int main()
{
    int N;
    string S;

    cin >> N >> S;

    int count = 0;

    for(int i = 0; i < N-2; i++)
    {
        if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C')count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  string S;
  cin >> S;
  int N = S.length();
  ll a[10] = {};
  REP(i,N) a[i] = S[i] - '0';
  ll ans = 0;
  ll base = 1;
  REP(i,N-1){
    REP(j,N-i){
      ans += a[j] * base*(1 << (N-2-i));
    }
    ans += a[N-i-1] * base*(1 << (N-2-i));
    base *= 10;
  }
  ans += a[0]*base;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long x,a,b;
    scanf("%ld%ld%ld", &x, &a, &b);

    if( abs(x-a) < abs(x-b) ) {
        printf("A\n"); 
    }
    else {
        printf("B\n"); 
    }    

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main() {
  ll N;
  cin >> N;
  ll h[MAX];
  ll i, j;
  
  ll ans=1;
  for(i=0; i<N; i++) cin >> h[i];
  
  vector<ll> c[3];
  c[0].push_back(-1);
  c[1].push_back(-1);
  c[2].push_back(-1);
  for(i=0; i<N; i++) {
    ll x=c[0][(ll)c[0].size()-1];
    ll y=c[1][(ll)c[1].size()-1];
    ll z=c[2][(ll)c[2].size()-1];
    
    ll cnt=0;
    ll id=0;
    if(x+1==h[i]) { cnt++; id=0; }
    if(y+1==h[i]) { cnt++; id=1; }
    if(z+1==h[i]) { cnt++; id=2; }
    
    moC(ans, *, cnt);
    c[id].push_back(h[i]);
    
  }
  
  pt(ans);
}

















Measured memory_bytes: 2296
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    string w; cin >> w;
    map<char, int> mp;
    for(int i = 0; i < w.size(); i++){
        mp[w[i]]++;
    }
    bool OK = true;
    for(auto itr : mp){
        if(itr.second % 2 != 0) OK = false;
    }
    if(OK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	const int monies[] = { 300000 , 200000,100000 };
	const int bounus = 400000;

	int x = 0, y = 0;
	std::cin >> x;
	std::cin >> y;

	int money = 0;
	if (x>=1 && x<=3) {
		money += monies[x - 1];
	}
	if (y >= 1 && y <= 3) {
		money += monies[y - 1];
	}
	if (x + y == 2) {
		money += bounus;
	}
	std::cout << money;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    ll d,t,s;
    cin >> d >> t >> s;
    ll time=t*s;
    if(d<=time) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
class Unionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)

    def find(self,x):#親を探す
        if self.par[x] ==x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self,x,y):#x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
        else:
            self.par[py]=px
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)
from collections import defaultdict
from heapq import heapify,heappop
import sys
N,M = map(int,input().split())
tree = Unionfindtree(N)
A = [int(i) for i in input().split()]
table=[]
for i in range(M):
    x,y=map(int,input().split())
    tree.union(x,y)

dd=defaultdict(list)
for i in range(N):
    dd[tree.find(i)].append(A[i])
ans=0
g=0
for s in dd.keys():
    heapify(dd[s])
    ans+=heappop(dd[s])
    g+=1
if g==1:
    print(0)
    sys.exit()
if g==2:
    print(ans)
    sys.exit()
L=[]
for s in dd.values():
    L+=list(s)
L.sort()
if len(L)<g-2:
    print('Impossible')
    sys.exit()

ans+=sum(L[:g-2])
print(ans)

Measured memory_bytes: 110488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    string yea = S.substr(0,4);
    int year = stoi(yea);
    string mont = S.substr(5,2);
    int month = stoi(mont);

    if(month <=4){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }
}

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

using namespace std;

int main() {
  string s;
  string a[10] = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
  cin >> s;
  for(int i=0; i < 10; i++) {
    if(a[i] == s) {
      cout << 7-i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int , input().split()))

class Cumulative_Sum:
    def __init__(self, a):
        la = len(a)
        self.s = [0] * (la + 1)
        for i in range(la):
            self.s[i+1] = self.s[i] + a[i]
    # s[l]からs[r]までの和
    def sum(self, l, r):
        return self.s[r] - self.s[l]

def nCr(n, r, mod=67280421310721):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


cs = Cumulative_Sum(a)
from collections import defaultdict
b = defaultdict(int)

for i in range(n+1):
    b[cs.s[i] % m] += 1
#print(cs.s)
#print(b)
ans = 0
for bi in b:
    if b[bi] > 1:
        ans += nCr(b[bi], 2)
        #print(bi, b[bi])
    #    ans += b[bi]
print(ans)

"""
for i in range(n+1):
    if cs.s[i] % m == 0:
        ans += 1
    print(cs.s[i] % m)
print(ans)
"""
"""
print('---')
ans = 0
for i in range(n):
    for j in range(i+1, n+1):
        if cs.sum(i, j) % m == 0:
            print(i, j, cs.s[i]%m, cs.s[j]%m)
            #ans += 1
#print(ans)
"""

Measured memory_bytes: 62576
#include <stdio.h>
#include <stdlib.h>

int partition(int *,int,int);



int main(){
  int i,j,n;
  int p=0;
  int q;

  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }


  q=partition(A,p,n-1);

  for(i=0;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  return 0;

}


int partition(int *A,int p,int r){
  int x,i,j;


  x=A[r];
  i=p-1;
  int tmp;

  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;


  return i+1;
}

Measured memory_bytes: 988
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n;
pair<ll,ll> a[100111];
pair<ll,int> lv[100111],rv[100111];
bool vis[100111];
ll solve()
{
	ll ret=0;
	for(int i=1;i<=n;i++)lv[i]=MP(a[i].FF,i);
	sort(lv+1,lv+n+1);
	reverse(lv+1,lv+n+1);
	for(int i=1;i<=n;i++)rv[i]=MP(a[i].SS,i);
	sort(rv+1,rv+n+1);
	ll pos=0;
	memset(vis,0,sizeof(vis));
	int itl=1,itr=1;
	while(true)
	{
		while(vis[lv[itl].SS])itl++;
		if(itl<=n&&lv[itl].FF>pos)
		{
			vis[lv[itl].SS]=1;
			ret+=lv[itl].FF-pos;
			pos=lv[itl].FF;
		}
		else break;
		while(vis[rv[itr].SS])itr++;
		if(itr<=n&&rv[itr].FF<pos)
		{
			vis[rv[itr].SS]=1;
			ret+=pos-rv[itr].FF;
			pos=rv[itr].FF;
		}
		else break;
	}
	return ret+abs(pos);
}
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		getii(a[i].FF,a[i].SS);
	}
	ll ans=0;
	ans=max(ans,solve());
	for(int i=1;i<=n;i++)
	{
		a[i]=MP(-a[i].SS,-a[i].FF);
	}
	ans=max(ans,solve());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5120
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

let sorted = Array(zip(a, Array(0..<n))).sorted(by: { $0.0 > $1.0 })

var dp: [[Int]] = Array(
  repeating: Array(
    repeating: 0,
    count: n + 1
  ),
  count: n + 1
)
dp[0][0] = 0

var answer = 0
for x in 0...n {
  for y in 0...n where 0 < x + y && x + y <= n {
    if x == 0 {
      dp[x][y] = dp[x][y-1] - sorted[x + y - 1].0 * (y - 1 - sorted[x + y - 1].1)
      continue
    }
    if y == 0 {
      dp[x][y] = dp[x-1][y] + sorted[x + y - 1].0 * (n - x - sorted[x + y - 1].1)
      continue
    }
    dp[x][y] = max(
      dp[x-1][y] + sorted[x + y - 1].0 * (n - x - sorted[x + y - 1].1),
      dp[x][y-1] - sorted[x + y - 1].0 * (y - 1 - sorted[x + y - 1].1)
    )
    if x + y == n && dp[x][y] > answer { answer = dp[x][y] }
  }
}

print(answer)


Measured memory_bytes: 39796
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    int n;
    cin >> n;
    cout << n*(n+1) / 2;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<class T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < data.size(); ++i){
            for(int j = 1; j < data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    CumulativeSum2D<int> S(h, w);
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '1')  S.add(i, j, 1);
        }
    }
    S.build();
    int ans = INF;
    for(int bit = 0; bit < (1 << (h - 1)); ++bit){
        vector<int> d;
        d.emplace_back(0);
        int cnt = 0;
        for(int i = 0; i < h - 1; ++i){
            if((bit >> i) & 1){
                d.emplace_back(i + 1);
                ++cnt;
            }
        }
        d.emplace_back(h);
        int n = d.size();
        bool ok = true;
        int left = 0, right = 1;
        vector<int> sum(n - 1, 0);
        while(right <= w){
            bool update = false;
            for(int i = 0; i + 1 < n; ++i){
                int foo = S.query(d[i], left, d[i + 1], right);
                if(foo > k){
                    ok = false;
                    break;
                }
                if(sum[i] + foo <= k)   sum[i] += foo;
                else{
                    update = true;
                    break;
                }
            }
            if(!ok) break;
            if(update){
                ++cnt;
                for(int i = 0; i + 1 < n; ++i){
                    sum[i] = S.query(d[i], left, d[i + 1], right);
                }
            }
            ++left, ++right;
        }
        if(ok)  chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int X;
    cin >> X;

    if (X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int n;
  int sum;
  cin >> n;
  if(n<10) {
    for(int i=0; i<=n; i++) {
      sum = i;
    }
  }      
  else if(n<100) {
    cout << 9 << endl;
    return 0;
  }
  else if(n<1000) {
    for(int i=100; i<=n; i++) {
      sum = i-99;
    }
    sum += 9;
  }
  else if(n<10000) {
    cout << 909 << endl;
    return 0;
  }
  else if(n<100000) {
    for(int i=10000; i<=n; i++) {
      sum =i-9999;
    }
    sum += 909;
  }
  else
    sum = 90909;

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int S, h, m, s;
    cin >> S;
    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600)%60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

using namespace std;
template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);

const long long Inf = 1LL << 60;

// 入力
int N;
long long h[100010];

// メモ用の DP テーブル
long long dp[100010];

long long rec(int i) 
{
    // DP の値が更新されていたらそのままリターン
    if (dp[i] < Inf) return dp[i];

    // 足場 0 のコストは 0
    if (i == 0) return 0;

    // i-1, i-2 それぞれ試す
    long long res = Inf;
    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合
    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合

    // 結果をメモしながら、返す
    return dp[i] = res;
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = Inf;

    // 答え
    cout << rec(N-1) << endl;
}

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

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

Measured memory_bytes: 6528
n,m = map(int,input().split())
point = [0] * n
cnt = 0
for i in range(m):
    a,b = map(int,input().split())
    point[a-1] += 1
    point[b-1] += 1
    # if a > b:
    #     a,b = b,a
    # for j in range(a,b):
    #     edge[j-1] += 1
for i in range(len(point)):
    if point[i] % 2 == 1:
        print("NO")
        exit()
print("YES")




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

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		int a[1000],b[1000],c[1000],d[1000];
		for(int i=0;i<n;i++){
			cin >> a[i] >> b[i] >> c[i] >> d[i];
		}
		int B,C,D,cal;
		cin >> B >> C >> D >> cal;
		bool flag = false;
		for(int i=0;i<n;i++){
			if(b[i]<=B && c[i]<=C && d[i]<=D && b[i]*4+c[i]*9+d[i]*4<=cal){
				flag = true;
				cout << a[i] << endl;
			}
		}
		if(!flag)
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 880
#include <iostream>

using namespace std;

int main()
{
    int N = 0;
    int A = 0;
    int B = 0;

    cin >> N >> A >> B;

    int densya = N * A;
    int taxi = B;

    if (densya < taxi) {
        cout << densya;
    } else {
        cout << taxi;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll= long long;
int main(){
    int n,m;
    cin >>n>>m;
    long long sum=0;
    vector <long long> a(n);
    priority_queue<vector<long long>> q;
    rep(i,n) cin >> a[i];
    rep(i,n) q.push({a[i],a[i],0});

    rep(i,m)  {
        ll b = q.top()[0];
        ll c = q.top()[1];
        ll d = q.top()[2]+1;
        ll e = c/pow(2,d);
        q.pop();
        q.push({e,c,d});
    }
    while(!q.empty()){
        sum += q.top()[0];
        q.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 7476
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 100 + 1;

vector <int> g[N];
int mt[N];
bool u[N];

bool dfs(int v)
{
    if (u[v])
    {
        return false;
    }
    u[v] = true;
    for (int to : g[v])
    {
        if (mt[to] == -1 || dfs(mt[to]))
        {
            mt[to] = v;
            return true;
        }
    }
    return false;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    cin >> n;
    vector <int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        mt[i] = -1;
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (a[i] < c[j] && b[i] < d[j])
            {
                g[i].push_back(j);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (dfs(i))
        {
            ans++;
            for (int j = 0; j < n; j++)
            {
                u[j] = 0;
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;

// CでもDでも割り切れない　=　Cで割れない　かつ　Dでわれない　なので、否定の「少なくともCかDで割れる」を考える。 CまたはDで割れる
// それぞれCで割れないときをU(C)とあらわすと、U(CかつD)　=　全体　-　｛　U（C-）＋　U(D-)　｝　＋　U(CD-）　とあらわせる 最小公倍数

// B/C - A/C でU(C-)が出るので、D-も同様に求める。　かつのときは、B/C+D　－　A/C+D　でおｋ
// 全体は　B-A+1　でおｋ

auto GCD(auto a,auto b){ //ユークリッドの互助法で最大公約数
    if (a%b == 0){
        return b;
    }
    else {
        return GCD(b,a%b);
    }
}

auto LCM(auto a,auto b){ //GCDを使って最小公倍数を求める
    return a*b / GCD(a,b);
}

int main(){
    LL A,B,C,D ;cin >> A >> B >> C >> D;
    LL sum,U,Ucb,Udb,Ucadb,Lcm;
    U = B-A+1;
    Ucb = B/C - (A-1)/C ;
    Udb = B/D - (A-1)/D ;
    Lcm = LCM(C,D);
    Ucadb = B/Lcm - (A-1)/Lcm;
    sum = U - (Ucb + Udb) + Ucadb ;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1000000007;
int power(int a, int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = 1LL * result * a % P;
        a = 1LL * a * a % P;
        b >>= 1;
    }
    return result;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i)
        cin >> a[i];
    reverse(a.begin(), a.end());
    int total = 1 << n;
    vector<int> factorial(total + 1), invFactorial(total + 1);
    factorial[0] = 1;
    for (int i = 1; i <= total; ++i)
        factorial[i] = 1LL * factorial[i - 1] * i % P;
    invFactorial[total] = power(factorial[total], P - 2);
    for (int i = total; i >= 1; --i)
        invFactorial[i - 1] = 1LL * invFactorial[i] * i % P;
    vector<int> dp(total);
    dp[0] = 1;
    auto binom = [&](int n, int m) {
        if (n < m)
            return 0LL;
        return 1LL * factorial[n] * invFactorial[m] % P * invFactorial[n - m] % P;
    };
    for (int i = 0; i < m; ++i)
        for (int s = total - 1; s >= 0; --s)
            for (int j = 0; j < n; ++j)
                if (~s >> j & 1)
                    dp[s | 1 << j] = (dp[s | 1 << j] + 1LL * dp[s] * binom(total - a[i] - s, (1 << j) - 1) % P * factorial[1 << j]) % P;
    int ans = 0;
    for (int i = 0; i < total; ++i) {
        int res = 1LL * dp[i] * factorial[total - 1 - i] % P;
        ans = (ans + (__builtin_parity(i) == 0 ? res : P - res)) % P;
    }
    cout << ((1LL * ans) << n) % P  << endl;
    return 0;
}

Measured memory_bytes: 1024
import heapq

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)
#print(d_AB)
H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        for ab in d_AB[i]:
            heapq.heappush(H,ab)
        #print(H)
        money += heapq.heappop(H)
        #print(money)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

typedef complex<int>P;

int N;
P p[16];
bool ok[1<<16];

int dp[1<<16];
signed main(){
    cin>>N;
    rep(i,N){
        int a,b;cin>>a>>b;
        p[i]=P(a,b);
    }

    rep(i,N){
        for(int j=i+1;j<N;j++){
            P d=p[j]-p[i];

            vpint lis;
            rep(k,N){
                for(int l=k+1;l<N;l++){
                    P dd=p[l]-p[k];
                    if(real(d)*imag(dd)-imag(d)*real(dd)==0)lis.pb({k,l});
                }
            }

            rep(i,1<<lis.size()){
                int b=0;
                rep(j,lis.size())if(i>>j&1)b|=(1<<lis[j].fi)|(1<<lis[j].se);
                ok[b]=true;
            }
        }
    }

    fill_n(dp,1<<16,INT_MIN);
    dp[0]=0;
    rep(i,1<<N){
        int sup=((1<<N)-1)^i;
        int sub=sup;
        do{
            if(ok[sub]){
                int c=__builtin_popcount(sub);
                c/=2;
                chmax(dp[i|sub],dp[i]+c*(c-1)/2);
            }
            sub=(sub-1)&sup;

        }while(sub!=sup);
    }
    cout<<*max_element(dp,dp+(1<<N))<<endl;
    return 0;
}

Measured memory_bytes: 3652
import itertools
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

cc = [i for i in range(1, M+1)]
ans = 0

for A in itertools.combinations_with_replacement(cc, N):
    A = list(A)
    t = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            t += d[i]
    ans = max(ans, t)

print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

int main(void){
    int N, M; cin >> N >> M;
    vector<int> p(N);
    for(int i=0; i<N; i++){
        int pi; cin >> pi; pi--;
        p[i] = pi;
    }

    UnionFind uni(N);

    for(int i=0; i<M; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        uni.connect(x, y);
    }

    int ans = 0;
    for(int i=0; i<N; i++) if(uni.root(i) == uni.root(p[i])) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
#define N (int)1e6+1

int main()
{
	ios
	int n,w;
	cin>>n>>w;
	ll value[w+1]={0};
	ll a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		for(int j=w;j>=0;j--)
		{
			if(j+a<=w)
			{
				value[j+a]=max(value[j+a],value[j]+b);
			}
		}
	}
	ll ans=0;
	for(int i=0;i<=w;i++)
		ans=max(ans,value[i]);
	cout<<ans<<nl;
}

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

int main() {
    int R, C, sx, sy, ex, ey; 
    cin >> R >> C >> sx >> sy >> ex >> ey;
    string s[R];
    for (int i = 0; i < R; i++) cin >> s[i];

    vector<vector<int>> dist(R, vector<int>(C, -1));
    deque<tuple<int, int, int>> dq;
    dq.emplace_back(sx - 1, sy - 1, 0);
    while (!dq.empty()) {
        int x, y, d; tie(x, y, d) = dq.front();
        dq.pop_front();
        if (x < 0 || x >= R || y < 0 || y >= C || dist[x][y] >= 0 || s[x][y] == '#') continue;
        dist[x][y] = d;

        for (int dx = -2; dx < 3; dx++) for (int dy = -2; dy < 3; dy++) {
            if (dx * dx + dy * dy == 1) dq.emplace_front(x + dx, y + dy, d);
            else if (dx * dx + dy * dy > 1) dq.emplace_back(x + dx, y + dy, d + 1);
        }
    }

    cout << dist[ex - 1][ey - 1];
    return 0;
}

Measured memory_bytes: 11868
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 


int main(){
	ios_base::sync_with_stdio(false);
	ll a[4];
	ll f[10]={0};
	For(i,0,4) cin>>a[i];
	For(i,0,4) f[a[i]]++;
	if(f[1]==1 && f[9]==1 && f[7]==1 && f[4]==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int ma = -1, ans = -1;
    for (int i = 1; i <= n; i++) {
        const int now = [](int e) {
            int cnt = 0;
            while (e && e % 2 == 0) {
                e /= 2;
                cnt++;
            }
            return cnt;
        }(i);
        if (now > ma) {
            ma = now;
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256