akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = (int) 1e9;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.00001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int adp = 0;
	int bdp = 0;
	int cdp = 0;
	{
		int a, b, c;
		cin >> a >> b >> c;
		adp = max(b, c);
		bdp = max(c, a);
		cdp = max(a, b);
	}
	for (int i = 1; i < n; i++) {
		int a, nadp;
		int b, nbdp;
		int c, ncdp;
		cin >> a >> b >> c;
		nadp = max(bdp + a, cdp + a);
		nbdp = max(cdp + b, adp + b);
		ncdp = max(adp + c, bdp + c);
		adp = nadp;
		bdp = nbdp;
		cdp = ncdp;
	}
	cout << max({ adp, bdp, cdp }) << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    string s;
    cin>>n>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]+n>90)
            cout<<char((n-(90-s[i]))+64);
        else
            cout<<char(s[i]+n);
    }
    cout<<endl;
}


Measured memory_bytes: 3624
d, n = map(int, input().split())
if d == 0 and n == 100:
  print(101)
elif d == 0:
  print(n)
elif d == 1 and n == 100:
  print(10100)
elif d == 2 and n == 100:
  print(1010000)
else:
  print(100**d*n)

Measured memory_bytes: 2940
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)

int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
char c;
char wr[15];
char *w = wr;
main() {
    char c;
    while(1) {
        c = getwchar_unlocked();
        if(c != '\n')
            nn = nn * 10 + c - '0';
        else
            break;
    }
    const int_least32_t n = nn;
    if(n == 1){
        putchar_unlocked('1');
        return 0;
    }
    const int_fast32_t sqrtN = sqrt(n);
    ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    for(int i = 1; i <= sqrtN; ++i) {
        const int_fast32_t a = n / i;
        ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
    }
    while(ans) {
        *w = ans % 10 + '0';
        ans /= 10;
        w++;
    }
    while(1) {
        w--;
        putwchar_unlocked(*w);
        if(w == wr) break;
    }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int K,X,S,E;
    cin >> K >> X;
    S = X - K + 1;
    E = X + K - 1;
    for (int i=S; i<=E; i++) {
        if (i >= -1000000 && i <= 1000000)
            cout << i << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) {
    return a < b ? b = a, true : false;
}
template<typename T> bool chmax(T a, T &b) {
    return a > b ? b = a, true : false;
}

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*----------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll n, h;
    std::cin >> n >> h;

    vll a(n), b(n);
    for (ll i = 0; i < n; i++)
        std::cin >> a[i] >> b[i];

    std::sort(b.begin(), b.end());

    ll a_max = *std::max_element(a.begin(), a.end());

    ll ans = 0;
    for (ll i = n - 1; i >= 0 && b[i] > a_max; i--)
        if (h > 0) { h -= b[i]; ans++; }
        else break;
    if (h > 0) { ans += (h + a_max - 1) / a_max; }

    std::cout << ans << '\n';
}


Measured memory_bytes: 4644
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,x;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    i=0;
    x=1;
    while (i<n)
    {
        x*=100;
        i++;
    }
    if (m==100)
    {
        x*=m+1;
    }
    else
    {
        x*=m;
    }
    cout << x;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll DP[2019], Dig[int(2e5 + 5)];
int main(){
  string S; cin >> S;

  ll ten = 1;
  for (int i = S.length() - 1; i >= 0; i--){
    ll now = S[i] - '0';
    Dig[i] = now * ten % 2019;
    ten *= 10; ten %= 2019;
  }
  
  ll now = 0;
  for (int i = S.length() - 1; i >= 0; i--){
    now += Dig[i]; now %= 2019;
    DP[now]++;
  }

  DP[0]++;
  ll ans = 0;
  for (int i = 0; i < 2019; i++){
    ans += DP[i] * (DP[i] - 1) / 2;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 5332
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e6 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], a[MXN], cnt;

int main () {
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
        a[i] = b[i];
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++){
        if(a[i] != b[i]) cnt++;
    }
    if(cnt <= 2) cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 2304
import itertools

N=int(input())
L=[0,0,0,0,0]
T="MARCH"

for i in range(N):
    S=input()
    for i in range(5):
        if S[0]==T[i]:
            L[i]+=1
            
ans=0
for itr in itertools.combinations(range(5), 3):
    ans+=L[itr[0]]*L[itr[1]]*L[itr[2]]
    
print(ans)
    

Measured memory_bytes: 45784
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N
for idx, val in enumerate(h):
    if idx == 0:
        continue
    if idx == 1:
        dp[idx] = abs(h[idx] - h[idx - 1])
    else:
        dp[idx] = min((dp[idx - 2] + abs(h[idx] - h[idx - 2])),(dp[idx - 1] + abs(h[idx] - h[idx - 1])))

print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long ll;
const ll mod=(1e9)+7;
string A,B,C;

ll mem[100][10],used[100][10];
ll dfs(int idx,int pre){
  if(idx==-1) return pre==0;
  if(used[idx][pre]++)return mem[idx][pre];
  
  ll res=0,u[10][10][10]={},f=idx==0;
  for(int i=f;i<10;i++)
    for(int j=f;j<10;j++)
      for(int k=f;k<10;k++){
	int a=A[idx]=='?'? i:A[idx]-'0';
	int b=B[idx]=='?'? j:B[idx]-'0';
	int c=C[idx]=='?'? k:C[idx]-'0';
	if(u[a][b][c]++||(a+b+pre)%10!=c) continue;
	res=(res+dfs(idx-1,(a+b+pre)/10))%mod;
      }
  return mem[idx][pre] = res;
}

int main(){
  while(1){
    cin>>A;
    if(A=="0")break;
    cin>>B>>C;
    memset(used,0,sizeof(used));
    cout <<dfs(A.size()-1,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
#define debug(x) cerr << #x << " = " << x << endl

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    a.push_back(0);
    int c1 = 0, c2 = inf;
    for(int i = n-2; i >= 0; i--){
        int t = min(c1 + abs(a[i] - a[i+1]), c2 + abs(a[i] - a[i+2]));
        c2 = c1;
        c1 = t;
    }
    cout << c1 << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int N,i,ans=0;
    cin>>N;
    long long int A[N],B[N];
    for(i=0;i<N;i++)
        cin>>A[i];
    B[N-1]=0;
    B[N-2]=abs(A[N-1]-A[N-2]);
    for(i=N-3;i>=0;i--)
        B[i]=min((abs(A[i]-A[i+1])+B[i+1]), (abs(A[i]-A[i+2])+B[i+2]));
    cout<<B[0]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, lint>> pair(M);
    REP(i, M) {
        int L, R;
        lint C;
        cin >> L >> R;
        cin >> C;
        pair[i] = make_tuple(L-1, R-1, C);
    }
    sort(pair.begin(), pair.end(),
       [](auto const &a, auto const &b) { return get<0>(a) < get<0>(b); });
    vector<lint> dp(N, 1e15);
    priority_queue<lint, vector<lint>, greater<lint> > pq;
    dp[0] = 0;
    int i = 0;
    REP(k, N) {
        int L = get<0>(pair[i]);
        if(L > k) {
            k++;
            if(pq.empty()) {

                if(dp[N-1] == 1e15) {
                    cout << -1 << endl;
                } else {
                    cout << dp[N-1] << endl;
                }
                return 0;
            }
            lint tmp = pq.top();
            if(dp[k] > tmp) {
                lint min = 1e15;
                int idx = -1;
                FOR(j, k+1, N) {
                    if(dp[j] < min) {
                        min = dp[j];
                        idx = j;
                    }
                    
                } 
                if(dp[k] >= min) {
                    FOR(j, k, idx) {
                        dp[j] = min;
                    }
                    
                }
                pq.pop();
            } else if(dp[k] == tmp) {
                pq.pop();
            }

            k--;
            continue;
        }
        //cout << dp[L]+get<2>(pair[i]) << " " << dp[get<1>(pair[i])] << endl;
        if(dp[L]+get<2>(pair[i]) < dp[get<1>(pair[i])]) {
            dp[get<1>(pair[i])] = dp[L]+get<2>(pair[i]);
            pq.push(dp[L]+get<2>(pair[i]));
        }
        k--;
        i++;
        if(i == M) break;
    }
    if(dp[N-1] == 1e15) {
        cout << -1 << endl;
    } else {
        cout << dp[N-1] << endl;
    }
}

Measured memory_bytes: 3196
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+12
#define PI acos(-1)
#define MOD 100000009
using ll = long long;
using ull = unsigned long long;

bool isACGT(char c){
    if(c == 'A' || c == 'C' || c == 'G' || c == 'T'){
        return true;
    }
    return false;
}

int main(){
    string s;
    cin >> s;

    int ans = 0;
    int len = size(s);
    rep(i, len){
        string tmp;
        for(int j = i; j < len; ++j){
            if(isACGT(s[j])){
                tmp += s[j];
            }else{
                break;
            }
        }
        ans = max(ans, (int)size(tmp));
    }

    println(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	double N,x,y,b,p,temp = 0;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> x >> y;
		cin >> b >> p;
		temp = x*b+y*p;
		if(b>=5 && p>=2) temp = min(temp,temp*0.8);
		if(b < 5 && p < 2){
			temp =min(temp,((b+(5-b))*x+(p+(2-p))*y)*0.8);
		}
		else if(b < 5){
			temp = min(temp,((b+(5-b))*x+p*y)*0.8);
		}
		else if(p < 2){
			temp = min(temp,(b*x+(p+(2-p))*y)*0.8);
		}
	cout << temp << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n;ll k;
  cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  ll s=0;
  for(int i=0;i<n-k;i++)
    s+=a[i];
  cout<<s<<"\n";
  return 0;
}

Measured memory_bytes: 1792
N, Y = list(map(int, input().split()))
flag = False
for n in range(N+1):
  for m in range(N+1 - n):
    if 10000 * n + 5000 * m + 1000 * (N - n - m) == Y:
      print(n, m , N - n- m)
      flag = True
      break
  if flag:
    break

if flag == False:
  print("-1 -1 -1")


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

 
int main() {
  int n, k, d, a, ans = 0;
  cin >> n >> k;
  vector<int> v(n, 0);
  
  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> a;
      v.at(a - 1) = 1;
    }
  }
  
  for (int i = 0; i < n; i++) {
    if (v.at(i) == 0)
      ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
n = int(input())
words = {}
for _ in range(n):
    word = input()
    if word in words:
        words[word] += 1
    else:
        words[word] = 1

words_sorted = sorted(words.items(), key=lambda x: x[1], reverse=True)
max_keys = [words_sorted[0][0]]
init = words_sorted[0][1]
for word in words_sorted[1:]:
    if word[1] == init:
        max_keys.append(word[0])
    else:
        break
max_keys.sort()
for i in max_keys:
    print(i)


Measured memory_bytes: 46556
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

MOD = 10**9 + 7

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]


cnt = 0

for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            cnt += 1

cnt = cnt % MOD

cnt2 = 0

if K >= 2:
    for i in range(N):
        for j in range(N):
            if A[i] > A[j]:
                cnt2 += 1

    cnt2 = cnt2 % MOD

ans = cnt*K + cnt2*((K*(K-1))//2)
ans %= MOD
print(ans)

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n) {
        if(s[i] == '?') {
            if(i == 0) {
                if(s[i+1] == 'D') {
                    s[i] = 'P';
                } else {
                    s[i] = 'D';
                }
            }
            else if(i == n-1) {
                s[i] = 'D';
            }
            else {
                if(s[i-1] == 'D' && s[i+1] == 'D') {
                    s[i] = 'P';
                } else {
                    s[i] = 'D';
                }
            }
        }
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int sum;
int ma;
int a, b, c;
int k;

int main(){
	cin>>a>>b>>c;
	cin>>k;
	ma = max( a, max( b, c ) );
	if( ma == a ){
		sum = (a<<k)+b+c;
	}
	else if( ma == b ){
		sum = (b<<k)+a+c;
	}
	else{
		sum = (c<<k)+a+b;
	}
	
	cout<<sum<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = 0;
    int tap = 1;

    while(tap < B){
      tap += A - 1;
      ans++;
    }
    System.out.print(ans);
  }
}


Measured memory_bytes: 23764
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

ll n, m;
//ll a[100010], b[100010];
pair<ll, ll> ab[100010];

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

  cin >> n >> m;
  REP(i, n) {
    //cin >> a[i] >> b[i];
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab, ab+n);

  ll ans = 0LL;
  REP(i, n){
    //if(m <= 0) break;
    if(ab[i].second >= m){
      //cout << "hoge" << endl;
      //m -= ab[i].second;
      //m = 0;
      ans += m*ab[i].first;
      break;
    }
    else{
      m -= ab[i].second;
      ans += ab[i].first*ab[i].second;
    }
    //cerr << "m:" << m << " ans: " << ans << endl; 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,L;
int sum=0;
int a=1000;

int main(){
	cin>>N>>L;
	REP(i,N){
		int b=L+i;
		sum+=b;
		if(abs(a)>abs(b)){
			a=b;
		}
	}
	cout<<sum-a<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

foods = [0 for i in range(M)]

for i in range(N):
    inputs = list(map(int, input().split()))

    for j in range(inputs[0]):
        foods[inputs[j + 1] - 1] += 1

ans = 0
for food in foods:
    if food == N:
        ans += 1

print(ans)


Measured memory_bytes: 3060
/* Ford-Fulkerson O((E+V)F*) time
O(E) memory
*/
#include<bits/stdc++.h>


using namespace std;
const int maxN=1e3+10;

int n,st,fn,m;
bool mark[maxN];
int cap[maxN][maxN],parent[maxN];
vector<int> g[maxN],path;
#define PB push_back
/*

4 5
1 3

1 2 5
1 4 3
2 4 2
2 3 3
4 3 5
*/

void input()
{
  cin>>n>>m;
  //cin>>st>>fn;
  st=0;
  fn=n-1;
  for(int i=1;i<=m;i++)
    {
      int k1,k2,val;
      cin>>k1>>k2>>val;
      g[k1].push_back(k2);
      g[k2].push_back(k1);
      cap[k1][k2]=val;
    }
}
bool BFS(int v)
{
  queue<int> q;
  q.push(v);
  mark[v]=true;
  parent[v]=v;
  
  while(q.size()>0)
    {
      v=q.front();
      q.pop();
      if(v==fn)//found
	break;
      for(auto u :g[v])
	if(!mark[u] && cap[v][u]>0)
	  {
	    mark[u]=true;
	    parent[u]=v;
	    q.push(u);
	  }
    }
  if(mark[fn]==false)
    return false;
  v=fn;
  while(parent[v]!=v)
    {path.PB(v);
      v=parent[v];}
  path.PB(v);
  reverse(path.begin(),path.end());
  return true;
}
int Edmonds_Karp()
{
  int MaxFlow=0;
  while(BFS(st))
    {
      int minCap=INT_MAX;
      for(int i=1;i<path.size();i++)
	minCap=min(minCap,cap[path[i-1]][path[i]]);
      for(int i=1;i<path.size();i++)
	{
	  cap[path[i-1]][path[i]]-=minCap;
	  cap[path[i]][path[i-1]]+=minCap;
	}
      MaxFlow+=minCap;
      path.clear();
      memset(mark,0,sizeof(mark));
    }
  return MaxFlow;
}
int main()
{
  input();
  int ans=Edmonds_Karp();
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int ab=abs(a-b);
    int bc=abs(b-c);
    int ac=abs(c-a);

    if(ac<=d||ab<=d&&bc<=d){
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n, m, i, j, k;
	char s[10][10]; //m, n
	char p[10];
	memset(s, 0, sizeof(s));
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++){
		scanf("%d", &k);
		for(j=0; j<k; j++){
			int S;
			scanf("%d", &S);
			s[i][S-1]=1;
		}
	}
	for(i=0; i<m; i++){
		int P;
		scanf("%d", &P);
		p[i]=P;
	}
	int ans=0;
	int l=(1<<n);
	for(i=0; i<l; i++){
		char f=1;
		for(j=0; j<m; j++){
			int g=p[j];
			for(k=0; k<n; k++){
				if((i&(1<<k))!=0 && s[j][k]!=0) g++;
			}
			if(g%2!=0){f=0; break;}
		}
		if(f!=0) ans++;
	}
	printf("%d\n", ans);
}


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

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

const int MOD = 1e9 + 7;
const int MX = 2e6 + 5;

LL expo(LL a, LL x) {
	if(x == 0) {
		return 1;
	}
	LL ret = expo(a, x/2);
	ret = (ret * ret)%MOD;
	if(x%2 != 0) {
		ret = (ret * (a%MOD))%MOD; 
	}
	return ret;
}

LL fact[MX], ifact[MX];
void aux() {
	fact[0] = 1;
	// ifact[0] = 1;
	for(int i=1;i<MX;i++) {
		fact[i] = (fact[i-1] * i)%MOD;
		// ifact[i] = expo(fact[i], MOD-2);
	}
	ifact[MX-1] = expo(fact[MX-1], MOD-2);
	for(int i=MX-2;i>=0;i--) {
		ifact[i] = (ifact[i+1] * (i+1))%MOD;
	}
}

LL ncr(int n, int r) {
	if(r > n || r < 0) return 0;
	LL ret = ((fact[n] * ifact[n-r])%MOD * ifact[r])%MOD;
	return ret;
}

LL calc(int r, int c) {
	LL ret = 0;
	for(int i=0;i<=r;i++) {
		ret = (ret + ncr(i + 1 + c, c))%MOD;
	}
	return ret;
}

int main() {
	aux();
	int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	LL ans = 0;
	ans = (calc(r2, c2) - calc(r1 - 1, c2) + MOD - calc(r2, c1 - 1) + MOD + calc(r1 - 1, c1 - 1))%MOD;

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


Measured memory_bytes: 34860
#include<bits/stdc++.h>
#define ll long long int
#define INF INT_MAX
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
	chutiyaap;
	string str;
	ll n,t;
	cin>>n;
	vector<pair<pair <string,ll>,ll> >names;
	for(ll i=0;i<n;i++)
	{
		cin>>str>>t;
		names.push_back(make_pair(make_pair(str,-t),i));
	}
	sort(names.begin(),names.end());
	for(ll i=0;i<n;i++)cout<<names[i].second+1<<endl;
}


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

int main(){
  int a=0,b=0,c=0;
  string S;
  cin >> S;
  for(int i=0;i<S.length();i++){
    if(S[i]=='a'){a++;}
    else if(S[i]=='b'){b++;}
    else{c++;}
  }
  if((abs(a-b)<=1) && (abs(a-c)<=1) && (abs(b-c)<=1)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	int n, t, a, H, BH, HI;
	scanf("%d %d %d", &n, &t, &a);
	t *= 1000, a *= 1000;
	scanf("%d", &BH);
	HI = 0;
	for (int i = 1; i < n; i++) {
		scanf("%d", &H);
		if (abs((t - H * 6) - a) < abs((t - BH * 6) - a))
			BH = H, HI = i;
	}
	printf("%d\n", HI + 1);
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
#define LL	long long
const int MAXN = 2e5+10;

int N;
int c[MAXN];
//vector<int> G[MAXN];
int tot = 0;
int head[MAXN], Next[2*MAXN], to[2*MAXN];

// 
// sub[i]: 顶点i下子树顶点的个数
int sub[MAXN];
// cnt[i]: 颜色为i的顶点下子树顶点的个数
int cnt[MAXN]; 
// ans[i]: 颜色为i的顶点下不经过颜色i的顶点数
LL ans[MAXN];

// 一开始起名count结果和c++ count()冲突，调试了半天, md
inline LL count(int n) {
	// C(n,2) + n
	return 1LL*n*(n+1)/2;
}

void dfs(int v, int fa) {
	int tmp = cnt[c[v]];
	sub[v] = 1;
	for(int i=head[v]; i; i=Next[i]) {
		int u = to[i];
		if(u == fa) continue;
		cnt[c[v]] = 0;	// 置0重新计数
		dfs(u, v);
		sub[v] += sub[u];
		ans[c[v]] += count(sub[u] - cnt[c[v]]);
	}
	cnt[c[v]] = tmp + sub[v];
}
inline void add(int a, int b) {
	++tot;
	Next[tot] = head[a];
	to[tot] = b;
	head[a] = tot;
}

/*
void dfs(int v, int fa) {
	int tmp = cnt[c[v]];
	sub[v] = 1;
	for(int u:G[v]) {
		if(u==fa) continue;
		cnt[c[v]] = 0;
		dfs(u, v);
		sub[v] += sub[u];
		ans[c[v]]+=cal(sub[u]-cnt[c[v]]);
	}
	cnt[c[v]] = tmp + sub[v];
}
* */

int main() {
	std::ios::sync_with_stdio(false);
	cin>>N;
	for(int i=1; i<=N; i++) {
		cin >> c[i];
	}
	int a, b;
	for(int i=1; i<N; i++) {
		cin>>a>>b;
	
		add(a, b);
		add(b, a);
		
		//G[a].push_back(b);
		//G[b].push_back(a);
	}

	//dfs1(1, 0);
	dfs(1, 0);
	for(int i=1; i<=N; i++) {
		cout << count(N) - ans[i] - count(N-cnt[i]) << endl;
	}
	return 0;
}


Measured memory_bytes: 27064
#include<stdio.h>

int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i!=n;
}

int main(){
	int i,n,A[10000+1],q,key,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(search(A,n,key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}


Measured memory_bytes: 2088
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    int n;cin>>n;
    if(n>=30) cout<<"Yes";
    else cout<<"No";
}

signed  main() {
    lets_go

      int t;
      t=1;
// cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}


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

int32_t main()
{
	int a1,a2,a3;
	cin>>a1>>a2>>a3;
	int res = a1+a2+a3;
	if(res >= 22)
		cout<<"bust"<<endl;
	else
		cout<<"win"<<endl;
	
}
	


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b,c; cin>>a>>b>>c;
    cout<<a[0]<<b[1]<<c[2]<<endl;
    return 0;
}


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

int main()
{
  int M, N;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;

  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    sum += A.at(i);
  }

  int cnt = 0;
  //double border = sum / (4.0 * M);

  for(int i = 0; i < N; i++){
    if(A.at(i) >= ceil(sum / (4.0 * M))){
      cnt++;
    }
  }
  if(cnt >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    L, R, d = iim()

    a, b = divmod(L, d)
    if b == 0:
        a -= 1
    print(R//d - a)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 61620
#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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    ll cnt=0;
    rep(i,n+1){
        string s=to_string(i);
        int mn;
        int mx;
        int a;
        int b;
        a=s[sz(s)-1]-'0';
        b=s[0]-'0';
      	//cerr << a << b << endl;
      	if(!a)continue;
        if(a==b && a<=n)cnt++;
        int round=1;
        while(true){
            mn=a*pow(10,round)+b;
            mx=(a+1)*pow(10,round)-10+b;
            round++;
            if(mn>n)break;
            if(mx>n){
                cnt+=(n-mn)/10+1;
                break;
            }
            cnt+=(mx-mn)/10+1;
        }
      	//cerr << cnt << endl;
    }
    cout << cnt;
    


}

/*



 */





Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n;
    cin >>n;
    ans=n*800-200*(n/15);
    
    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long long n;
  cin>>n;
  long long int temp=n%500;
  n-=temp;
  long long int count=n/500;
  long long int hap=1000*count;
  
 
  long long int count1=(temp/5);
  hap+=(count1*5);
  cout<<hap;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int a, b;
  std::cin >> a >> b;
  if(a > b) {std::cout << "a > b" << std::endl;
  }
  else if(a < b) {std::cout << "a < b" << std::endl;
  }
  else if(a == b) {std::cout << "a == b" << std::endl;
}
}



Measured memory_bytes: 3072
n=int(input())

dp=[0]*(n+1)

for i in range(n+1):
    cnt=0
    j=i
    for exp6 in range(6,0,-1):
        curcnt=j//(6**exp6)
        j-=curcnt*(6**exp6)
        cnt+=curcnt
    dp[i]=j+cnt

for i in range(9**6):
    j=i
    paynine=0
    cnt=0
    exp9=1
    while j>0:
        bit=j%9
        j//=9
        cnt+=bit
        paynine+=bit*(9**exp9)
        exp9+=1
    
    if paynine>n:
        break

    dp[n]=min(dp[n],dp[n-paynine]+cnt)

print(dp[n])

Measured memory_bytes: 41820
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
#include<set>
#include<iostream>

using namespace std;

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

const int MX = 2005;
const int MM = 1000000007;

int main()
{
	string S;
	cin >> S;
	int ch = 0;
	for(char c : S){
		if( c == 'S' ) ch |= 1;
		if( c == 'N' ) ch |= 2;
		if( c == 'E' ) ch |= 4;
		if( c == 'W' ) ch |= 8;
	}
	if( (ch&3) == 1 || (ch&3) == 2 ) return !printf("No\n");
	if( (ch&12) == 8 || (ch&12) == 4 ) return !printf("No\n");
	printf("Yes\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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


ll e() { return 0; }

int main() {
	ll N, K;
	cin >> N >> K;
	vll A(N);
	rep(i, N)cin >> A[i];

	ll M = 300001;
	segtree<ll, max, e> seg(M);

	rep(i, N) {
		ll x = seg.prod(max(0, A[i] - K), min(M, A[i] + K+1));
		seg.set(A[i], x + 1);
	}

	cout << seg.all_prod() << endl;
}


Measured memory_bytes: 16228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int a,b; cin>>a>>b;
	cout<<max({a+b, a-b, a*b})<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

N,Q = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c,d = map(int,input().split())
    graph[a].append((b,c,d))
    graph[b].append((a,c,d))
query = [[int(x) for x in input().split()] for _ in range(Q)]

def set_ancestor(x=1, d=0, parent=0):
    depth[x] = d
    ax = ancestor[x]
    ax[0] = parent
    for i in range(d.bit_length() - 1):
        ax[i+1] = ancestor[ax[i]][i]
    for y, _, _ in graph[x]:
        if y == parent:
            continue
        set_ancestor(y, d+1, x)

depth = [0] * (N+1)
U = 17
ancestor = [[0] * (U+1) for _ in range(N+1)] # 2**i だけ遡った頂点の番号、行き過ぎは0
set_ancestor()

def LCA(x,y):
    dx = depth[x]
    dy = depth[y]
    if dx > dy:
        x,y = y,x
        dx,dy = dy,dx
    diff = dy - dx
    while diff:
        step = diff & (-diff)
        y = ancestor[y][step.bit_length() - 1]
        diff -= step
    while x != y:
        j = 0
        while ancestor[x][j] != ancestor[y][j]:
            j += 1
        if j == 0:
            return ancestor[x][0]
        x = ancestor[x][j-1]
        y = ancestor[y][j-1]
    return x

tasks = [[] for _ in range(N+1)]
for i,(x,y,u,v) in enumerate(query):
    tasks[u].append((i,x,y,1))
    tasks[v].append((i,x,y,1))
    tasks[LCA(u,v)].append((i,x,y,-2))

answer = [0] * Q# 頂点、色に対して、距離、自色距離、自色個数)を入れる

def dfs(x, sums = defaultdict(int), nums = defaultdict(int), total = 0, parent = 0):
    for i,c,d,coef in tasks[x]:
        answer[i] += coef * (total - sums[c] + nums[c] * d)
    for y,c,d in graph[x]:
        if y == parent:
            continue
        sums[c] += d
        nums[c] += 1
        total += d
        dfs(y, sums, nums, total, x)
        sums[c] -= d
        nums[c] -= 1
        total -= d
    return

dfs(1)

print('\n'.join(map(str,answer)))

Measured memory_bytes: 222048
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,min=99890287,sum=0,l,x,h;cin>>n;cin>>k;
	for(int i=1;i<=n;i++){
		cin>>x;
		l=abs(k-x);
		h=x;
		if(l<min)min=l;
		if(h<min) min=h;
		sum=sum+min;
		min=99899999;
	}
		cout<<2*sum;
	return 0;
}

Measured memory_bytes: 256
import sys

Ball = list(map(str, input().split()))
Quantity = list(map(int,input().split()))
U = str(input())

S = Ball[0]
T = Ball[1]
A = Quantity[0]
B = Quantity[1]

if not 1 <= len(S) or not len(S) <= 10:
    print("error:S_length")
    sys.exit()    
if not 1 <= len(T) or not len(T) <= 10:
    print("error:T_length")
    sys.exit()   
if S == T:
    print("error:S==T")
    sys.exit()
if S != U and T != U:
    print("error:S=U or S=T")
    sys.exit()
if not 1<= A or not B <= 10:
    print("error:A,B")
    sys.exit()

if U == S:
    A -= 1
if U == T:
    B -= 1
print(A,B)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(void)
{
char s[7],s1[7]="Sunny",s2[7]="Cloudy",s3[7]="Rainy";
scanf("%s",s);
if(!(strcmp(s,s1)))
    printf("Cloudy");
if(!(strcmp(s,s2)))
    printf("Rainy");
if(!(strcmp(s,s3)))
    printf("Sunny");
return 0;
}



Measured memory_bytes: 128
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N, M;
vector<int> edge[100010];

vector<bool> visited(100010);
vector<int> l(100010, -1);

int dfs(int v){
	if(l[v] != -1) return l[v];
	visited[v] = 1;
	int res = 0;
	for(int i = 0; i < edge[v].size(); i++){
		res = max(res, dfs(edge[v][i])+1);
	}
	return l[v] = res;
}

int main(void){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		edge[x].push_back(y);
	}
	for(int i = 0; i < N; i++){
		if(visited[i]) continue;
		dfs(i);
	}
	cout << *max_element(l.begin(), l.end()) << endl;
}


Measured memory_bytes: 8192
from collections import deque
readline = open(0).readline
writelines = open(1, 'w').writelines
N, Q = map(int, readline().split())
ans = []
A = [deque() for i in range(N)]
def push(t, x):
    A[t].append(str(x))
def dump(t):
    ans.append(" ".join(A[t]))
    ans.append("\n")
def splice(s, t):
    if A[s]:
        if A[t]:
            if len(A[s]) == 1:
                A[t].append(A[s][0])
            elif len(A[t]) == 1:
                A[s].appendleft(A[t][0])
                A[t] = A[s]
            else:
                A[t].extend(A[s])
        else:
            A[t] = A[s]
        A[s] = deque()

C = [push, dump, splice].__getitem__
for i in range(Q):
    t, *a=map(int, readline().split())
    C(t)(*a)
writelines(ans)


Measured memory_bytes: 45624
# -*- coding: utf-8 -*-
import sys
'import math'
while(1):
    n,m=input().split()
    if n=='0' and m=='0':
        sys.exit()
    n=int(n)+1
    m=int(m)
    cnt=0
    for a in range(1,n):
        for b in range(a+1,n):
            for c in range (b+1,n):
                if a+b+c==m:
                    cnt+=1
    print(cnt)


Measured memory_bytes: 5600
#include <iostream>

namespace detail
{
    struct node
    {
        int n;
        node* prev;
        node* next;

        node(int x)
            : n(x), prev(nullptr), next(nullptr) {}
    };

    struct list
    {
        node* head;
        node* tail;

        list()
            : head(nullptr), tail(nullptr) {}

        void insert(int n) {
            node* x = new node(n);
            x->next = head;
            if (head != nullptr) {
                head->prev = x;
            } else {
                tail = x;
            }
            head = x;
        }

        node* find(int x) {
            node* it = head;
            while (it != nullptr) {
                if (it->n == x) {
                    return it;
                }
                it = it->next;
            }
            return it;
        }

        void remove(node* it) {
            if (it == nullptr) {
                return;
            }
            if (it == head) {
                head = it->next;
            }
            if (it == tail) {
                tail = it->prev;
            }
            if (it->prev != nullptr) {
                it->prev->next = it->next;
            }
            if (it->next != nullptr) {
                it->next->prev = it->prev;
            }
            delete it;
        }

        void remove(int x) {
            remove(find(x));
        }

        void removeFirst() {
            remove(head);
        }

        void removeLast() {
            remove(tail);
        }
    };
}

using namespace std;

void print_list(detail::list& list)
{
    detail::node* node = list.head;
    while (node != list.tail) {
        cout << node->n << " ";
        node = node->next;
    }
    if (list.tail != nullptr) {
        cout << list.tail->n << endl;
    }
}

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

    detail::list list;

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int x;
        string c;
        cin >> c;
        if (c == "insert") {
            cin >> x;
            list.insert(x);
        } else if (c == "delete") {
            cin >> x;
            list.remove(x);
        } else if (c == "deleteFirst")
            list.removeFirst();
        else if (c == "deleteLast")
            list.removeLast();
    }
    print_list(list);

    return 0;
}

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

int main() {
    //
    int num;
    string str;
    int str1 = 0;
    int str2 = 0;
    int str3 = 0;
    int str4 = 0;

    cin >> num;

    for (int i = 0; i < num; i++) {
        cin >> str;
        if (str == "AC") str1++;
        else if(str == "WA") str2++;
        else if(str == "TLE") str3++;
        else if(str == "RE") str4++;
    }

    cout << "AC x " << str1 << endl;
    cout << "WA x "  << str2 << endl;
    cout << "TLE x "  << str3 << endl;
    cout << "RE x "  << str4 << endl;
    //
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  int n, d;
  cin >> n >> d;

  int ans = 0;
  ans += n / (d * 2 + 1);
  if(n % (d * 2 + 1)) ans++;


  cout << ans << endl;

}


Measured memory_bytes: 256