akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<vector>
#define MAX 10000
#define INFTY 1<<21
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

vector<pair<int, int> > adj[MAX];   // <頂点,重み>
priority_queue<pair<int, int> > PQ; // <重み,頂点> 正確には重み×-1
int d[MAX], color[MAX];
int n;

// ダイクストラのアルゴリズムに優先度付きキューを用いて、
// 最短経路上の各頂点まで道のりを求めて出力する。
void dijkstra()
{
	for (int i = 0; i < n; i++)
	{
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	PQ.push(make_pair(0, 0));

	while (!PQ.empty())
	{
		pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;

		if (d[u] < f.first * (-1)) continue;

		color[u] = BLACK;

		for (int i = 0; i < adj[u].size(); i++)
		{
			int v = adj[u][i].first;

			if (color[v] == BLACK) continue;

			if (d[u] + adj[u][i].second < d[v])
			{
				d[v] = d[u] + adj[u][i].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		int x = (d[i] == INFTY) ? -1 : d[i];
		cout << i << " " << x << endl;
	}
}

int main()
{
	cin >> n;

	int k, u, v, c;
	for (int i = 0; i < n; i++)
	{
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}

	dijkstra();

	return 0;
}

// 参考
// 本P310掲載の重み付き有向グラフの作成
void testSample()
{
	n = 7;
	adj[0].push_back(make_pair(1, 6));
	adj[0].push_back(make_pair(2, 12));
	adj[0].push_back(make_pair(3, 7));
	adj[2].push_back(make_pair(2, 8));
	adj[3].push_back(make_pair(4, 3));
	adj[3].push_back(make_pair(5, 53));
	adj[4].push_back(make_pair(3, 1));
	adj[4].push_back(make_pair(5, 0));
}


Measured memory_bytes: 8088
def print_ans(input_line):
    """Test Case
    >>> print_ans("Sunny")
    Cloudy
    >>> print_ans("Rainy")
    Sunny
    """
    if input_line == "Sunny":
        print("Cloudy")
    elif input_line == "Rainy":
        print("Sunny")
    else:
        print("Rainy")


if __name__ == '__main__':
    print_ans(input())


Measured memory_bytes: 2940
<?php

$N = fgets(STDIN);


$MOD = pow(10, 9) + 7;

$a = mypow(10, $N);
$b = mypow(9, $N);
$c = mypow(8, $N);

$ans = ($a - 2*$b + $c);

while($ans < 0){
    $ans += $MOD;
}

$ans = $ans % $MOD;

echo $ans;

function mypow($b, $p)
{
    $mod = pow(10, 9) + 7;
    $res = 1;
    for ($i = 0; $i < $p; $i++) {
        $res = ($res * $b) % $mod;
    }
    return $res;
}


?>


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int k, n;
	cin >> k >> n;
	vi a(n);
	rep(i, n) cin >> a[i];

	int mx = 0;
	Rep(i, n) {
		mx = max(mx, a[i] - a[i - 1]);
	}
	mx = max(mx, (k + a[0]) - a[n - 1]);
	cout << k - mx << endl;
}

Measured memory_bytes: 1024
(defn shift-only [n a]
  (loop [counter 0 arr a]
    (if (not-every? even? arr)
        counter
        (recur (+ counter 1) (map #(/ % 2) arr)))))

(defn create-data [s]
  (map #(bigint %) (.split s " ")))

(println (shift-only (Long/parseLong (read-line)) (create-data (read-line))))

Measured memory_bytes: 70820
import sys
from collections import defaultdict
input = sys.stdin.readline


n, m = map(int, input().split())
path = defaultdict(list)

for _ in range(m):
    a, b = map(int, input().split())
    path[a].append(b)

idx = 1
ans = 1
right = n
while idx <= n:
    candidate = path[idx]
    if not candidate:
        idx += 1
        continue
    if right <= idx:
        ans += 1
        right = n
    cut = min(candidate)
    right = min(right, cut)
    idx += 1

print(ans)

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(c)     for(bool p=1;p;p=next_permutation(ALL(c)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

struct edge { ll from, to, cost; };
edge es[2002];

ll d[1002];
ll V, E;

void bellman_ford(ll s) {
    REP(i, V) d[i] = inf;
    d[s] = 0;
    REP(i, V-1) REP(j, E) {
        edge e = es[j];
        if (d[e.from] == inf) continue;
        d[e.to] = min(d[e.to], d[e.from] + e.cost);
    }
}

// グラフ内に負閉路があるか判定
bool find_negative_loop() {
    memset(d, 0, sizeof(d));
    REP(i, V) REP(j, E) {
        edge e = es[j];
        if (d[e.to] > d[e.from] + e.cost) {
            d[e.to] = d[e.from] + e.cost;
            if (i == V - 1) return true;
        }
    }
    return false;
}

// 出発地sから目的地tまでに負閉路があるか判定
bool find_negative_loop(ll s, ll t) {
    bellman_ford(s);
    vector<bool> negative(V, false);
    REP(i, V) REP(j, E) {
        edge e = es[j];
        if (d[e.from] == inf) continue;
        
        if (d[e.to] > d[e.from] + e.cost) {
            d[e.to] = d[e.from] + e.cost;
            negative[e.to] = true;
        }
        if (negative[e.from]) negative[e.to] = true;
    }
    return negative[t];
}

int main() {
    ll N, M; cin >> N >> M;
    REP(i, M) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        es[i] = (edge){a, b, -c};
    }
    
    V = N; E = M;
    if (find_negative_loop(0, N-1)) {
        cout << "inf" << endl;
    } else {
        bellman_ford(0);
        cout << -d[N-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a;
    cin>>a;
	string s;
    cin>>s;
    bool aflag=true;
    bool bflag=true;
    bool cflag=true;
    int cou=0;
    rep(i,a-2){
        string t;
        t=s.substr(i,3);
        if(t=="ABC"){
            cou++;
        }
    }
    cout<<cou<<endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N;cin>>N;vvi A(2,vector<int>(N));
  rep(i,2){
    rep(j,N)cin>>A[i][j];
  }
  vi wu(N);
  vi wd(N);
  wu[0]=A[0][0];
  wd[0]=A[1][0];
  f(i,1,N){
    wu[i]=wu[i-1]+A[0][i];
    wd[i]=wd[i-1]+A[1][i];
  }
  int ans=wu[0]+wd[N-1];
  f(i,1,N){
    ans=max(ans,wu[i]+wd[N-1]-wd[i-1]);
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

ll sum(ll n){
	ll val=0;
	while(n>=1){
		val+=n%10;
		n/=10;
	}
	return val;
}


int main() {
ll n;
cin>>n;
ll ans=inf;
for(ll i=1;i<n;i++){
ll k=i;
ll l=n-i;
ans=min(ans,sum(k)+sum(l));
}

cout<<ans<<endl;
return 0;


}




Measured memory_bytes: 256
import java.util.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Int[] I = new Int[N];
        for (int i = 0; i < N; i++) {
            I[i] = new Int(sc.nextLong(), sc.nextLong()+1);
        }
        Arrays.sort(I);
        Int[] X = new Int[N+1];
        X[0] = new Int(-1, Long.MAX_VALUE);
        for (int i = 0; i < N; i++) {
            X[i+1] = X[i].merge(I[i]);
        }
        Int[] Y = new Int[N+1];
        Y[N] = new Int(-1, Long.MAX_VALUE);
        for (int i = N-1; i >= 0; i--) {
            Y[i] = Y[i+1].merge(I[i]);
        }
        
        long res = 0;
        for (int i = 0; i < N; i++) {
            if (i < N-1) {
                res = Math.max(res, X[i+1].size() + Y[i+1].size());
            }
            res = Math.max(res, X[i].merge(Y[i+1]).size() + I[i].size());
        }
        System.out.println(res);
    }
    
}


class Int implements Comparable<Int> {
    long L, R;
    Int(long l, long r) {
        L = l; R = r;
    }
    
    Int merge(Int I) {
        return new Int(Math.max(L, I.L), Math.min(R, I.R));
    }
    
    long size() {
        return Math.max(R-L, 0);
    }

    @Override
    public int compareTo(Int t) {
        int res = Long.compare(L, t.L);
        if (res != 0) return res;
        return Long.compare(R, t.R);
    }
}

Measured memory_bytes: 102836
//   ----------- |\S/|\E/|\C/|\O/|\N/|\D/|\T/|\O/|\N/|\O/|\N/|\E/| -----------
 #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define I_L_Z_D ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
const int N = 1e5 + 8;
int dp[N];

int32_t main(){
I_L_Z_D;
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1 ; i <= n ;i++) cin >> a[i];
	fill(dp,dp + N , 1e6);
	 dp[1] = 0;
	 dp[2] = dp[1] + abs(a[1] - a[2]);
	for(int i = 3 ; i <= n ;i++){
			dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]) , dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n] << " ";


return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    V<int> a(5);
    read(a);
    for (int i = 0; i < 5; i++) {
        if (a[i] == 0) {
            cout << i + 1 << newl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
n = int(input())
m=list(map(int,input().split()))
d={}
k=0
for i in range(n):
    k+=m[i]
    if m[i] in d:
        d[m[i]]+=1
    else:
        d[m[i]]=1
for x in range(int(input())):
    
    b,c=list(map(int,input().split()))

    
    
    if b in d:
        k+=d[b]*(c-b)
        if c in d:
            d[c]+=d[b]
        else:
            d[c] = d[b]
        del d[b] 
    print(k)
    

Measured memory_bytes: 20800
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)


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

	int sum = 0;
	int num_to_take = k;
	int num_a = min(num_to_take, a);
	sum += num_a;
	num_to_take -= num_a;

	int num_b = min(num_to_take, b);
	num_to_take -= num_b;

	int num_c = min(num_to_take, c);
	sum -= num_c;
	num_to_take -= num_c;

	cout << sum << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3628
lst = [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]
num = int(input())
print(lst[num - 1])

Measured memory_bytes: 3060
# 最大積載量p でk台のトラックに全ての荷物を積載できるかチェックする
def check(p):
  global n, k, w

  # k台のトラックに積載済の荷物の個数
  i = 0

  # k台のトラックに順番に荷物を積載する
  for j in range(k):
    # j台目のトラックの積載量の合計
    s = 0

    # 積載量の合計が 最大積載量p を超えるまで荷物を積み込む
    while (s + w[i] <= p):
      s += w[i]
      
      # トラックに積載済の荷物の個数（合計）をカウントアップ
      i += 1

      # 最大積載量p で すべての荷物を積み込めた場合
      if (i == n):
        return True

  # 最大積載量p で すべての荷物を積み込めなかった場合
  return False


# メイン処理
def solve():
  global n

  # 積載量の下限
  left = 0

  # 積載量の上限（個数の最大値 × 重量の最大値）
  right = 100000 * 10000

  while (1 < right - left):
    # 最大積載量p
    p = int((left + right) / 2)

    if check(p):
      # 最大積載量pで全ての荷物が積み込めた場合、p より小さい範囲を探索
      right = p
    else:
      # 最大積載量pで全ての荷物が積み込めなかった場合、p より大きい範囲を探索
      left = p
  
  # 全ての荷物を積み込むことができた最小の最大積載量を返却する
  return right

n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
print(solve())



Measured memory_bytes: 9576
import java.util.*;
    public class Main {
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            // 整数の入力
            int a = sc.nextInt();
            // スペース区切りの整数の入力
            int b = sc.nextInt();
            int wawana=b;
            int c = sc.nextInt();
            int wana[];
            int costr=0;
            int costl=0;
            wana=new int[wawana];
            for(int i=0;i<b;i++){
                wana[i]=sc.nextInt();
            }

            for(int i=c;i<a;i++){
                for(int gg=0;gg<=wawana-1;gg++){
                    if(i==wana[gg]){
                        costr++;
                    }

                }

            }

            for(int i=c;i>=0;i--){
                for(int gg=0;gg<=wawana-1;gg++){
                    if(i==wana[gg]){
                        costl++;
                    }

                }

            }


            if(costl==costr){
                System.out.println(costl);
            }else if(costl>costr){
                System.out.println(costr);
            }else{
                System.out.println(costl);
            }

            // 文字列の入力

        }
    }

Measured memory_bytes: 25556
def readinput():
    n=int(input())
    commands = []
    for i in range(n):
        command=input().split()
        commands.append(command)
    return n, commands

def main(n,commands):
    d = dict()
    for cmd in commands:
        if(cmd[0]=='insert'):
            d[cmd[1]]=cmd[1]
        elif(cmd[0]=='find'):
            if(cmd[1] in d):
                print('yes')
            else:
                print('no')

if __name__=='__main__':
    n,commands=readinput()
    main(n,commands)



Measured memory_bytes: 303788
N = int(input())
L = list(map(int,input().split()))
count = 0

for i in range(len(L)-3+1):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] != L[j] and L[j] != L[k] and L[i] != L[k] and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[i]+L[j]:
                count += 1

print(count)

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

class Timer {
private:
    chrono::high_resolution_clock::time_point start;
public:
    Timer() {
        reset();
    }
    void reset() {
        start = chrono::high_resolution_clock::now();
    }
    chrono::milliseconds::rep elapsed() {
        auto end = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(end - start).count();
    }
} timer;

const int D = 365;
const int N = 26;

int ans = 0;

vector<int> C(N);
vector<vector<int>> S(D, vector<int>(N));
vector<int> T(D);
vector<vector<int>> L(N, vector<int>(D, -1));
vector<set<int>> H(N);
vector<int> score(N);

int calc(int t) {
    int res = 0;
    for(auto &d : H[t]) res += S[d][t];
    for(int d = 0; d < D; ++d) res -= C[t] * (d - L[t][d]);
    return res;
}

void updateLast(int t) {
    for(auto &i : H[t]) L[t][i] = i;
    for(int _d = 1; _d < D; ++_d) L[t][_d] = max(L[t][_d], L[t][_d - 1]);
}

void insert(int t, int d) {
    L[t].assign(D, -1);
    H[t].insert(d);
    updateLast(t);
}

void erase(int t, int d) {
    L[t].assign(D, -1);
    H[t].erase(d);
    updateLast(t);
}

int main() {
    srand(time(NULL));
    int _; cin >> _;
    for(int i = 0; i < N; ++i) cin >> C[i];
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < N; ++j) cin >> S[i][j];
    }

    for(int i = 0; i < D; ++i) {
        int mx = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        T[i] = mx;
        L[T[i]][i] = i;
        H[T[i]].insert(i);
    }
    for(int d = 1; d < D; ++d) {
        for(int i = 0; i < N; ++i) {
            L[i][d] = max(L[i][d], L[i][d - 1]);
        }
    }

    for(int t = 0; t < N; ++t) {
        score[t] = calc(t);
        ans += score[t];
    }

    while(timer.elapsed() < 1800) {
        int d = rand() % D;
        int q = rand() % N;
        int p = T[d];
        T[d] = q;
        if(p == q) continue;

        int tmp = ans;

        int pre_p = score[p];
        int pre_q = score[q];
        tmp -= score[p];
        tmp -= score[q];

        erase(p, d);
        insert(q, d);

        score[p] = calc(p);
        score[q] = calc(q);
        tmp += score[p];
        tmp += score[q];

        if(ans < tmp) {
            ans = tmp;
        } else {
            score[p] = pre_p;
            score[q] = pre_q;
            insert(p, d);
            erase(q, d);
            T[d] = p;
        }
    }
    for(int d = 0; d < D; ++d) cout << T[d] + 1 << '\n';
    return 0;
}


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

using namespace std;

int main(){
    int N, K, sum(0);
    cin>>N>>K;
    int P[N];
    for (int i = 0; i < N; i++){
        cin>>P[i];
    }
    sort(P, P+N);
    for (int i = 0; i < K; i++){
        sum += P[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll npw_max=524288;//2^19
vector<pair<ll,ll > > dp[npw_max];
vector<int> g[npw_max];

void update(ll j, ll i){
  vector<pair<ll,ll > > tmp;
  rep(k,dp[i].size()){
    tmp.pb(dp[i][k]);
  }
  rep(k,dp[j].size()){
    tmp.pb(dp[j][k]);
  }
  sort(tmp.rbegin(), tmp.rend());
  dp[j][0] = tmp[0];
  int k=1;
  while(tmp[0].second==tmp[k].second){
    k++;
  }
  dp[j][1] = tmp[k];
  /*
  if(i==0){
    auto fir = dp[i][0];
    if(dp[j][0].first <= fir.first && dp[j][0].second != fir.second){
      dp[j][1]=dp[j][0];
      dp[j][0]=fir;
    }
    else if(dp[j][1].first <= fir.first && dp[j][1].second != fir.second && dp[j][0].second != fir.second){
      //      cout << "num j i " << dp[j][1].second << " " << fir.second << endl;
      dp[j][1]=fir;
    }
    return;
  }else{
  auto fir = dp[i][0];
  auto sec = dp[i][1];

  if(dp[j][0].first <= fir.first && dp[j][0].second != fir.second){
    dp[j][1]=dp[j][0];
    dp[j][0]=fir;
    if(dp[j][1].first < sec.first) dp[j][1] = sec;
  }
  else if(dp[j][1].first <= sec.first && dp[j][1].second != sec.second){
    dp[j][1]=dp[j][0];
    dp[j][0]=sec;
  }
  else if(dp[j][1].first <= fir.first && dp[j][1].second != fir.second && dp[j][\
0].second != fir.second){
    dp[j][1]=fir;
  }
  return;
  }*/
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll npw= pow(2,n);
  ll a[npw];
  rep(i,npw) cin >> a[i];
  dp[0].pb(mp(a[0],0));
  ll cmax=0;  
  rep1(j,npw-1){//0
    if(a[j]>a[0]){
      dp[j].pb(mp(a[j],j));
      dp[j].pb(mp(a[0],0));
    }
    else {
      dp[j].pb(mp(a[0],0));
      dp[j].pb(mp(a[j],j));
    }
    rep(i,20){
      if((1LL<<i) & j){
	update(j,j^(1LL<<i));
	//	cout << "部分集合 " << (j^(1LL<<i)) << endl;
      }
    }
    assert(dp[j][0].second!=dp[j][1].second);
    //    cout << "部分集合 " << (j^(1LL<<i)) << endl;
    cmax = max(cmax, dp[j][0].first+dp[j][1].first);
    cout << cmax << endl;
  }


  
  return 0;
    

}


Measured memory_bytes: 41984
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a, b, c, d; cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }else if(a+b<c+d){
    cout<<"Right"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    for a in 1..10 {
        for b in 1..10 {
            if n==a*b{
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


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

int main ()
{

	int n;
	scanf("%d",&n);
	string x;
	
	cin >> x;

	if(x.substr(0,n/2)==x.substr(n/2,n))printf("Yes");
	else printf("No");
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int V = sc.nextInt();
	int B = sc.nextInt();
	int W = sc.nextInt();
	int T = sc.nextInt();
	boolean cat = false;
	int kyo = Math.abs(A-B);
	for (int t=0;t<T;t++) {
	    kyo -= V - W;
	    if(kyo <= 0) cat = true;
	}
	if (V < W) cat = false;
	if (cat == true) {
	    System.out.print("YES");
	} else {
	    System.out.print("NO");
	}
    }
}



Measured memory_bytes: 36228
package main

import (
        "fmt"
        "sort"
)

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        ls := make([]int, n)
        for k := range ls {
                fmt.Scan(&ls[k])
        }
        sort.Sort(sort.Reverse(sort.IntSlice(ls)))
        var sum int
        for i := 0; i < k; i++ {
                sum += ls[i]
        }
        fmt.Printf("%d\n", sum)
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	stack<int> t;
	int ans = 0;
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if(S[i]=='0'){
			if(t.empty()){
				t.push(0);
				continue;
			}
			int now = 0;
			if(t.top()!=now){
				t.pop();
				ans += 2;
			}else{
				t.push(now);
			}
		}else{
			if(t.empty()){
				t.push(1);
				continue;
			}
			int now = 1;
			if(t.top()!=now){
				t.pop();
				ans += 2;
			}else{
				t.push(now);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1232
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi prime(100000+1, 1);
	prime[0] = prime[1] = 0;
	FOR(i, 2, 100000) {
		if(prime[i]) {
			for(int j = 2*i; j <= 100000; j += i) {
				prime[j] = 0;
			}
		}
	}

	int m, a, b;
	while(cin >> m >> a >> b, m) {
		for(int i = m; i > 0; i--) {
			for(int j = 2; j*j <= i; j++) {
				if(i%j) {
					continue;
				}
				if(prime[j] && prime[i/j]) {
					if(i/j*a <= b*j) {
						cout << j << " " << i/j << endl;
						goto next;
					}
				}
			}
		}
		next:;
	}

	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int max = 0;
		int[] honest = new int[n];
		int[] unkind = new int[n];

		for (int i = 0, a, x, y; i < n; i++) {
			a = scanner.nextInt();
			for (int j = 0; j < a; j++) {
				x = scanner.nextInt() - 1;
				y = scanner.nextInt();
				if (y == 1) {
					honest[i] |= personBit(x);
				} else {
					unkind[i] |= personBit(x);
				}
			}
		}

		for (int i = 1, white, black; i < 1 << n; i++) {
			if (Integer.bitCount(i) <= max)
				continue;
			white = sumBit(honest, i, n);
			black = sumBit(unkind, i, n);
			if ((~i & white) == 0 && (i & black) == 0)
				max = Integer.bitCount(i);
		}
		System.out.println(max);
	}

	static int personBit(int n) {
		return 1 << n;
	}

	static int sumBit(int[] arr, int bit, int n) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if ((bit & personBit(i)) > 0) {
				sum |= arr[i];
			}
		}
		return sum;
	}

}


Measured memory_bytes: 22996
# 写経AC
from collections import defaultdict

N = int(input())
A = [int(i) for i in input().split()]

# dp[(i, x, flag)]:= i番目まででx個選んでいる時の最大値
# flag: i番目をとるフラグ
dp = defaultdict(lambda: -float("inf"))

# 初期条件
dp[(0, 0, 0)] = 0

# 貰うDP
for i, a in enumerate(A, 1):
    # i番目までで選ぶ個数
    for x in range((i // 2) - 1, (i + 1) // 2 + 1):
        dp[(i, x, 0)] = max(dp[(i - 1, x, 0)], dp[(i - 1, x, 1)])
        dp[(i, x, 1)] = dp[(i - 1, x - 1, 0)] + a

print(max(dp[(N, N // 2, 0)], dp[(N, N // 2, 1)]))

Measured memory_bytes: 211024
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N;
	vector<ll>A(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans = max(ans, abs(A[i] - A[j]));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
package main
import (
  "fmt"
  "os"
  "bufio"
  "strconv"
  "strings"
)

func main() {
  var n, r int
  
  stdin := bufio.NewScanner(os.Stdin)
  stdin.Scan()
  input := stdin.Text()
  nr := strings.Fields(input)
  n, _ = strconv.Atoi(nr[0])
  r, _ = strconv.Atoi(nr[1])
    
  var rate int
  if n<10 {
    rate = r + 100 * (10 - n)
  } else {
    rate = r
  }
  
  fmt.Println(rate)
}

Measured memory_bytes: 640
#include<iostream>
#include<string.h>

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	char cell[50][50];
	char num[50][50];
	memset(num,0,sizeof(num));
	for(int i = 0;i < h;i++){
		for(int j = 0;j< w;j++){
			cin >> cell[i][j];
		}
	}
	
	for(int i = 0;i < h;i++){
		for(int j = 0;j< w;j++){
			if(cell[i][j] == '#'){
				cout << '#';
			}else{
				int num = 0;
				
				for(int p = -1;p <= 1;p++){
					for(int q = -1;q <= 1;q++){
						if(0 <= i+p && i+p < h && 0 <= j+q && j+q < w){
							if(cell[i+p][j+q] == '#') num++;
						}
					}
				}
				
				cout << num;
			}
		}cout << endl;
	}
	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

long long mod_pow(long long x, long long n, int M=1000000007) {
    if (n < 0) return 1;
    long long ret = 1;
    while(n) {
        if(n & 1) (ret *= x) %= M;
        (x *= x) %= M;
        n >>= 1;
    }
    return ret;
}

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

    vector<int> C(N);
    for (auto &i : C) cin >> i;

    sort(C.begin(), C.end(), greater<int>());

    auto f = [&](int n){
        return (mint)mod_pow(2, n) + (mint)n * mod_pow(2, n-1);
    };

    mint ans = 0;
    rep(i, N) {
        ans += f(i) * C[i] * mod_pow(2, N-1-i);
    }

    ans *= mod_pow(2, N);

    cout << ans << endl;
}

Measured memory_bytes: 4036
<?php
//変数でも文字列ならば各文字にはキーでアクセス可能
//しかし、array_reverse($str) はエラーとなる。

$str = trim(fgets(STDIN));
$rstr = '';

$strlen = strlen($str);

for($i=$strlen-1; $i>=0; $i--){
	$rstr = $rstr.$str[$i];    //文字列なのでドット演算子を使って結合
}

echo $rstr.PHP_EOL;

Measured memory_bytes: 6556
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int i,j,k,n;
char s[81];
while(cin.getline(s,81)){
n=strlen(s);
for(j=1;j<27;j++){
for(i=0;i<n;i++){
if(96<s[i]&&s[i]<122)s[i]++;
else if(s[i]==122)s[i]=97;
}
for(i=0;i<n;i++){
if(!strncmp(s+i,"the",3))goto L1;
if(!strncmp(s+i,"this",4))goto L1;
if(!strncmp(s+i,"that",4))goto L1;
}
}
L1:cout<<s<<endl;
}
return 0;
}

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

int main(){
    int N, M;  cin >> N >> M;
    vector<int> A(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<pair<int,int>> P(M); // C,B
    for(int i=0; i<M; i++){
        cin >> P[i].second >> P[i].first;
    }
    sort(P.begin(), P.end());
    int idx = 1;
    for(int i=M-1; i>=0; i--){
        int B = P[i].second;
        int C = P[i].first;
        while(A[idx]<C && B > 0){
            A[idx] = C;
            idx++;
            B--;
        }
    }

    ll ans = 0;
    for(int i=1; i<=N; i++){
        ans += A[i];
    }
    cout << ans << endl;
}

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

using namespace std;
#define int long long int

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;


signed main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	int a,b;
	cin>>a>>b;
	if(a>9 || b>9)cout<<-1;
	else cout<<a*b;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
int d[maxn];
int fi(int x) {
    return d[x] == x ? x : d[x] = fi(d[x]);
}
int main()
{
    int n, k;
    cin >> n >> k;
    int v[n + 5] = {};
    f1(n) {
        d[i] = i;
        cin >> v[i];
    }
    f(k) {
        int x, y;
        cin >> x >> y;
        int a = fi(x);
        int b = fi(y);
        d[a] = b;
    }
    int ans = 0;
    f1(n) {
        int x = fi(v[i]);
        int y = fi(i);
        if (x == y) {
            ans++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int n; cin >> n;
  vector<int> a(n),idx(n);
  rep(i,n) cin >> a[i],a[i]--;
  rep(i,n) idx[a[i]] = i;
  set<int> s={-1,n};
  
  ll ans = 0;
  rep(x,n){
    int pos = idx[x];
    s.insert(pos);
    auto itr = s.find(pos);
    
    //left
    itr--;
    int l = *itr;
    
    //right
    itr++;itr++;
    int r = *itr;
    
    ans += (ll)(pos - l)*(r - pos)*(x+1);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;

int main(){
    int a=1000000000;
    int b=0;
    for(int i=1;i<=a;i++)b++;
    int alice,bob;cin>>alice>>bob;
    if(alice==1)alice+=100;if(bob==1)bob+=100;
    if(alice==bob)printf("Draw");
    else if(alice<bob)printf("Bob");
    else printf("Alice");
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int h,w,n;
      cin>>h>>w>>n;
      int i=0;
      while(i>=0)
      {
        if(max(h,w)*i>=n)
          break;
        i++;
      }
      cout<<i<<endl;
    }

Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let x = it.next().unwrap();
    let y = it.next().unwrap();
    println!("{}", x + y / 2);
}


Measured memory_bytes: 4352
import java.io.*;
 
class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int a = Integer.parseInt(strArr[0]);
        int b = Integer.parseInt(strArr[1]);
        int c = Integer.parseInt(strArr[2]);
        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24208
#include<cctype>
#include<cstdio>
int main(){
    char ch;
    int counter[26] = {0};
    
    while(scanf("%c", &ch) != EOF){
        if(isupper(ch)){
            ch = tolower(ch);
        }
        if('a'<=ch && ch <= 'z'){
            int num = ch - 'a';
            counter[num] ++;
        }
    }for ( int i = 0; i < 26; i++){
        printf("%c : %d\n", i + 'a', counter[i]);
    }return 0;
}



Measured memory_bytes: 2608
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n,m;
	cin >> n;
	for(int i = n; i < 1000; ++i) {
		if(i % 111 == 0) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans=0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}

//最大公約数
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

int sum(vector<int> x) {
	int ans = 0;
	rep(i, x.size()) {
		ans += x[i];
	}
	return ans;
}


int main() {
	string s;
	cin >> s;
	if (s[5] == '0' && (s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4')) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = sum(P[0:K])
tmp = sum(P[0:K])

for i in range(1, N-K+1):
    tmp = tmp - P[i-1] + P[i+K-1]
    ans = max(tmp, ans)
print((ans + K)/2)


Measured memory_bytes: 25060
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int num[15];
    int sum = 0;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>num[i];
    }
    sort(num, num+n);
    for(int i = 0; i < n-1; i++){
        sum += num[i];
    }
    sum += num[n-1]/2;
    cout<<sum;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  ll ab = a + b;

  if ( ab < k ) {
    cout << a - (k-ab) << endl;
  }else {
    if (a >= k) {
      cout << k << endl;
      return 0;
    }
    cout << a << endl;
  }

  return 0;
} 


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a/b)*x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

// m is a large prime integer. Usually 1000000007 is used.
int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x%m)%m;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, x; cin >> n >> x;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());

  ll fact = 1;
  for(int i=2; i<=n; i++) {
    fact *= i;
    fact %= mod;
  }
  vector<ll> modinv(n+1);
  for(int i=1; i<=n; i++) {
    modinv[i] = mod_inverse(i, mod);
  }

  unordered_map<int, ll> mp;
  unordered_map<int, ll> mp2;
  mp[x] = fact;

  bool flag = true;
  while(flag) {
    flag = false;
    for(auto e: mp) {
      auto r = e.first;
      auto it = upper_bound(s.begin(), s.end(), r);
      auto k = distance(s.begin(), it);
      if (k==0) {
        mp2[e.first] += mp[e.first];
        mp2[e.first] %= mod;
      }
      for(int i=0; i<k; i++) {
        flag = true;
        auto pos = r%s[i];
        mp2[pos] += e.second * modinv[k];
        mp2[pos] %= mod;
      }
    }
    swap(mp, mp2);
    mp2.clear();
  }

  ll ans = 0;
  for(auto e: mp) {
    ans += e.second*e.first;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int X, ans;
    cin >> X;
    ans = floor(X/500) * 1000 + floor((X%500)/5) * 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 

  string s; cin >> s;
  bool char_found[26] = {0};

  for (char c: s) {
    char_found[c - 'a'] = true;
  }

  for (int i = 0; i < 26; ++i) {
    if (!char_found[i]) {
      cout << static_cast<char>('a' + i) << "\n";
      return 0;
    }
  }

  cout << "None" << "\n";
}


Measured memory_bytes: 3788
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 30;
int n, m, x, y,q;ll z, w=0, sum = 0, ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
	int n, m, k; cin >> n; vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(ALL(a)); sort(ALL(b)); sort(ALL(c));
	rep(i, n) {
		sum += 1LL * (lower_bound(ALL(a), b[i]) - a.begin()) *( n - (lower_bound(ALL(c), b[i] + 1) - c.begin()));
	}cout << sum << endl;
}

Measured memory_bytes: 4580