akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int n;
    int a[300000];
    cin>>n;
    for(int i=0; i<3*n; i++) cin>>a[i];
    priority_queue<int> s;
    multiset<int, greater<int> > fn;
    long long int sumf=0, sums=0;
    {
        int ta[200000];
        for(int i=0; i<2*n; i++) ta[i]=a[i];
        sort(ta, ta+2*n, greater<int>());
        for(int i=0; i<n; i++) sumf+=ta[i];
        for(int i=n; i<2*n; i++) fn.insert(ta[i]);
    }
    for(int i=2*n; i<3*n; i++){
        sums+=a[i];
        s.push(a[i]);
    }

    long long int ans=sumf-sums;
    for(int i=2*n-1; i>=n; i--){
        //cout<<"a"<<i<<"="<<a[i]<<" fn_top="<< *(fn.begin())<<" s_top="<<s.top()<<endl;
        if(a[i] > *(fn.begin())){
            sumf=sumf-a[i]+ *(fn.begin());
            fn.erase(fn.begin());
        }
        else{
            fn.erase(fn.find(a[i]));
        }
        if(a[i]<s.top()){
            sums=sums-s.top()+a[i];
            s.pop();
            s.push(a[i]);
        }
        ans=max(ans, sumf-sums);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 7552
import Foundation

let inputs = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let N = inputs[0]
let M = inputs[1]
let Aarray = readLine()!.components(separatedBy: " ").map{ Int($0)! }

var voteNumber = 0
var popularProdact = 0

for i in 0...N - 1 {
    voteNumber += Aarray[i]
}

for i in 0...N - 1 {
    if Double(Aarray[i]) < Double(voteNumber) / 4.0 / Double(M) {
        
    }else{
        popularProdact += 1
    }
}

if popularProdact >= M {
    print("Yes")
}else{
    print("No")
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x < k + 1; x++) {
    for (int y = 0; y < k + 1; y++) {
      int z = s - x - y;
      if (z > k || z < 0) {
        continue;
      }
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val mod = 1000000007
    var (A, B) = readLongList()

    println(if (A*B%2 == 0) "No" else "Yes")
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 35972
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}


int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    lli r=0,g=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
        
    }
    lli ans=r*g*b;
    //cout<<r<<" "<<g<<" "<<b<<endl;
    for(int i=1;i<=(n-1)/2;i++){
        for(int j=0;j<=n-2*i-1;j++){
            //cout<<i<<" "<<j<<endl;
            if(s[j]!=s[j+i] && s[j+i]!=s[j+i+i] && s[j]!=s[j+i+i]){
                ans--;
                //cout<<j<<" "<<j+i<<" "<<j+i+i<<endl;
                //cout <<s[j] << " " << s[j + i] << " " << s[j + i + i] << endl;
            }
        }
    }
    // for(int j=0;j<=n-3;j++){
    //     for(int i=1;i<=((n-i)/3);i++){
    //         if (s[j] != s[j + i] && s[j + i] != s[j + i + i] && s[j] != s[j + i + i])
    //             ans--;
    //     }
    // }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split())

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t <= ss:
        return dfs(eki+1, ss+cc)
    else:
        return dfs(eki+1, -(-t//ff)*ff+cc)

for i in range(n):
    print(dfs(i,0))



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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> P(N), C(N);
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> C[i];
  rep(i,N) P[i]--;

  ll ans = -1e18;
  rep(si, N) {
    ll tot = 0;
    vector<ll> cyc;
    ll cur = si;
    while (1) {
      cur = P[cur];
      tot += C[cur];
      cyc.push_back(C[cur]);
      if (cur == si) break;
    }

    ll t = 0;
    rep(i, cyc.size()) {
      t += cyc[i];
      if (i + 1 > K) break;
      ll now = t;
      if (tot > 0) {
        ll e = (K - (i + 1)) / cyc.size();
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3812
import copy
 
kaisu = int(input())
 
s_suji_list = input().split(' ')
suji_list = []
count = 1
continue_flg = True
for suji in s_suji_list:
  i_suji = int(suji)
  if i_suji % 2 == 0:
    suji_list.append(i_suji / 2)
  else:
    continue_flg = False
    count = 0
    break
 
while(continue_flg):
  temp_list = copy.copy(suji_list)
  suji_list.clear()
  count += 1
  for suji in temp_list:
    if suji % 2 == 0:
      suji_list.append(suji / 2)
    else:
      count -= 1
      continue_flg = False
      break
 
print(count)

Measured memory_bytes: 9360
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n,x = list(map(int,input().split()))
x_list = list(map(int,input().split()))
#xとx_listをまとめて考える。
x_list.append(x)
x_list.sort()
x_dif_list = [i-j for i,j in zip(x_list[1::],x_list)]

#最大公約数
import fractions

ret = min(x_dif_list)
#最大公約数を取る
for i in x_dif_list:
    ret = fractions.gcd(ret, i)
    if ret==1:
        break
print(ret)

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

using namespace std;
using ll = long long;
const ll neg_max = pow(10, 9) * pow(10, 5) * -5;

ll solve(vector<ll> &va, int skip, array<vector<optional<ll>>, 3> &memo,
         int offset = 0) {
  if (offset >= va.size()) {
    return va.size() % 2 == 0 || skip < 2 ? 0 : neg_max;
  }

  if (!memo[skip][offset].has_value()) {
    ll ans = solve(va, skip, memo, offset + 2) + va[offset];
    if (skip > 0) {
      ans = max(ans, solve(va, skip - 1, memo, offset + 1));
    }

    memo[skip][offset] = ans;
  }

  return memo[skip][offset].value();
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  array<vector<optional<ll>>, 3> memo;
  fill(memo.begin(), memo.end(), vector<optional<ll>>(va.size() + 1));

  if (va.size() % 2 == 0) {
    cout << solve(va, 1, memo) << '\n';
  } else {
    cout << solve(va, 2, memo) << '\n';
  }

  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, k, a[5000], sum, ans;

int main() {
	cin >> n >> k;
	rep(i,n) cin >> a[i];
	sort(a, a+n);
	
	// 大きい要素から順にsumに足してkを超えるまでに何個の要素が必要かカウント
	// これで選んだ要素の中の最小値がa[i]だとすると、a[i-1]以下の要素は明らかに一つも必要ないのでi-1(0-based) + 1でansを更新
	// 単体でk以上の要素はそれ単体からなる「良い集合」が存在して、その集合が成り立つために絶対必要なのでスルー
	ans = n;
	repr(i,n-1) {
		if (sum+a[i]<k) sum += a[i];
		else ans = i;
	}
	cout << ans << ln;
}

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

#define int long long

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

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

signed main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H-h)*(W-w)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100]={0},cou=0,flag=0;
ll k,ans;
set<ll>se;
queue<ll>que;
void bfs(ll step){
    que.push(step);
    ll m;
    while(!que.empty()){
        m=que.front();que.pop();
        //cout<<m<<"\n";
        for(int i=0;i<=9;i++){
            if(abs(i-m%10)<=1||m==0){
                if(m*10+i!=0){
                que.push(m*10+i);
                cou++;
                }
            }
            if(cou==k){
                ans=m*10+i;
                return;
            }
        }
    }
}
int main(){
    cin>>k;
    cou=0;
    bfs(0);
    cout<<ans;
    return 0;
}

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

template <class T>
vector<pair<T, T>> prime_factorization(T n) {
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        T cnt = 0;
        while(n % i == 0) { n /= i; cnt++; }
        if(cnt != 0) ret.emplace_back(i, cnt);
    }
    if (n != 1) ret.emplace_back(n, 1);
    return ret;
}
int main(){
    int n, g; cin >> n;
    vector<int> a(n); vector<int> cnt(1e6 + 1, 0);
    for (auto i = 0; i < n; i++) {
        cin >> a[i];
        g = (i == 0) ? a[i] : gcd(g, a[i]);
    }
    for (auto i = 0; i < n; i++) {
        auto p = prime_factorization(a[i]);
        for (auto & elm : p) cnt[elm.first]++;
    }
    sort(cnt.begin(), cnt.end(), greater<>());
    if(cnt.front() <= 1) cout << "pairwise coprime" << endl;
    else if(g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 11164
#include<iostream>
using namespace std;
int N,A,B,C;
long mod=1e9+7;
long F[5050],I[5050];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long comb(long a,long b){return F[a]*I[b]%mod*I[a-b]%mod;}
long H(long a,long b){return a==0?b==0:comb(a-1+b,b);}
main()
{
	cin>>N>>A>>B>>C;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	I[N]=power(F[N],mod-2);
	for(int i=N;i--;)I[i]=I[i+1]*(i+1)%mod;
	if(B%2)
	{
		cout<<0<<endl;
		return 0;
	}
	long ans=0;
	for(int i=0;i<=C;i++)
	{
		for(int j=0;j<=A&&j+i<=C;j++)
		{
			if((C-i-j)%3)continue;
			(ans+=F[(C-i-j)/3+j+A-j+B/2]*I[(C-i-j)/3]%mod*I[j]%mod*I[A-j]%mod*I[B/2]%mod*H(B/2,i)%mod)%=mod;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define PB push_back
#define MOD 10000007
#define PI 3.14159265359

using namespace std;

int main(){

    int n;
    vector<string> s{20000000};
    cin >> n;
    rep(i,n) cin >> s[i];

    int count = 0;

    sort(s.begin(),s.begin()+n);

    for(int i = 0;i < n;i ++){

        if(s.at(i) == s.at(i + 1)){
            count += 0;
        }else{
            count++;
        }
    }
    cout << count <<"\n";
}


Measured memory_bytes: 628412
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ar array
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define w(t) ll t;cin>>t;while(t--)
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll x,k,d;
  cin>>x>>k>>d;
  x=abs(x);
  if(x>0){
    ll p=x/d;
    p=min(p,k);
    ll q=x-(p*d);
    k=k-p;
    if(k>0){
        if(k%2) cout<<abs(q-d);
        else cout<<q;
    }
    else
        cout<<q;
  }
  else if(x==0){
    if(k>0){
        if(k%2) cout<<d;
        else cout<<0;
    }
    else cout<<0;
  }
  return 0;
}

Measured memory_bytes: 3656
//close stdin
//https://codeforces.com/problemset?order=BY_RATING_ASC&tags=binary+search%2C1300-
#include <bits/stdc++.h>
using namespace std;
long long  gcd(long long  a, long long b){ 
	if (a == 0) 
		return b;  
	return gcd(b % a, a);  
	} 
long long lcmm(long long a,long long b){
	
return (a*b)/gcd(a, b);
}
	
int mod=998244353;
long long summ(long long x){
	long long ans=0;
	while(x!=0){
		ans+=(x%10);
		x=x/10;
	}
	return ans;
	
}
bool prime[1000003]; 
void SieveOfEratosthenes() 
{ 
	int n=1000002;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 

} 

int main(){
	//freopen ("t.txt","r",stdin);
	int n;
	scanf("%d",&n);
	vector<int> arr(n),cost(n,INT_MAX);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cost[0]=0;
	for(int i=0;i<n-1;i++){
		if(i==n-2){
			cost[i+1]=min(cost[i+1],abs(arr[i]-arr[i+1])+cost[i]);
			continue;
		}
		cost[i+1]=min(cost[i+1],abs(arr[i]-arr[i+1])+cost[i]);
		cost[i+2]=min(cost[i+2],abs(arr[i]-arr[i+2])+cost[i]);
	
	}
	cout<<cost[n-1];
	



return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
static ll imin = std::numeric_limits<ll>::min() / 10;
static ll imax = std::numeric_limits<ll>::max() / 10;
#define rep(i, n) for (ll i = 0; (i) < (n); ++(i))
#define rep1(i, n) for (ll i = 1; (i) < (n); ++(i))
#define rev_rep(i, n) for (ll i = (n)-1; (i) >= 0; --(i))
#define range(a, i, b) for (ll i = (a); (i) < (b); ++(i))

#ifdef LOCAL
#define dump(x) cout << #x << ":" << x << "\n";
#endif
#ifndef LOCAL
#define dump(x)
#endif

#define all(v) v.begin(), v.end()
#define readl(N) \
  ll N;          \
  cin >> N;
#define readlv(N, vec) \
  vector<ll> vec(N);   \
  rep(i, N) { cin >> vec[i]; }
#define greater_than [](ll l, ll r) { return l > r; }
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::map<T1, T2>& mp);
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& pair);
template <class T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec);
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& pair) {
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template <class T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec) {
  std::size_t n = vec.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (ll i = 0; i < n - 1; ++i) {
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::map<T1, T2>& mp) {
  std::size_t n = mp.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (auto&& x : mp) {
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template <class T>
std::ostream& operator<<(std::ostream& os, std::set<T>& mp) {
  std::size_t n = mp.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (auto&& x : mp) {
    os << x << " ";
  }
  os << std::endl;
  return os;
}

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

ll fact(ll n) {
  ll res = 1;
  while (n > 0) {
    res *= n;
    n--;
  }
  return res;
}

ll pow(ll i, ll n) {
  ll res = 1;
  while (n >= 0) {
    res *= i;
    n--;
  }
  return res;
}

ll gcd(ll l, ll r) {
  if (l < r) {
    return gcd(r, l);
  }
  if (r == 0) {
    return l;
  }
  return gcd(r, l % r);
}

template <class T>
vector<T> accum_sum(vector<T> const& a) {
  vector<T> b(a.size() + 1);
  b[0] = 0;
  rep(i, a.size()) { b[i + 1] = b[i] + a[i]; }
  return b;
}
constexpr ll mod = 1e9 + 7;
int main(int argc, char const* argv[]) {
  readl(s);
  readl(c);

  if (s * 2 >= c) {  // S is enough
    cout << c / 2 << endl;
    return 0;
  } else {  // S is not enough
    cout << (2 * s + c) / 4 << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;
    set<int> wat, sug;
    for(int i = 0; i <= 30; i++){
        for(int j = 0; j <= 30; j++){
            int sum = a * i + b * j;
            if (sum != 0 && sum <= f) wat.insert(sum);
            else break;
        }
    }
    for(int i = 0; i <= 3000; i++){
        for(int j = 0; j <= 3000; j++){
            int sum = c * i + d * j;
            if (sum <= f) sug.insert(sum);
        }
    }

    double con = -1;
    int ansWat = 0, ansSug = 0;
    for(int w: wat){
        for(int s: sug){
            if (w + s > f) continue;
            if (s <= e * (w/100)){
                double c = ((double)100 * s) / (w + s);
                if (chmax(con, c)){
                    ansWat = w;
                    ansSug = s;
                }
            }
        }
    }
    printf("%d %d\n", ansWat+ansSug, ansSug);
    return 0;
}

Measured memory_bytes: 3808
/**
  @file a.cpp
  @title A - 753
  @url https://atcoder.jp/contests/abc114/tasks/abc114_a
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

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

  if (X == 3 || X == 5 || X == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[0] == 'A'){
    int idxC = -1;
    rep3(i, 2, sz(s)-1){
      if(s[i] == 'C'){
        if(idxC == -1){
          idxC = i;
        }else{
          cout << "WA" << endl;
          return 0;
        }
      }
    }
    if(idxC == -1){
      cout << "WA" << endl;
      return 0;
    }
    rep3(i, 1, sz(s)){
      if(i == idxC) continue;
      char c = s[i];
      if('a' <= c && c <= 'z'){
        continue;
      }else{
        cout << "WA" << endl;
        return 0;
      }
    }
    cout << "AC" << endl;
    return 0;
  }

  cout << "WA" << endl;

  return 0;
}



Measured memory_bytes: 256
"""
a, b, c, d, e, f = map(int, input().split())
ans = [pow(10, 9), 1]
a *= 100
b *= 100
for w1 in range(31):
    for w2 in range(31):
        water = w1 * a + w2 * b
        if water > f or water == 0:
            continue
        for s1 in range(min(water, 3000 - water)):
            for s2 in range(min(water, 3000 - water)):
                sugar = s1 * c + s2 * d
                if water + sugar > f or e / 100 < sugar / water:
                    break
                if ans[1] / ans[0] <= sugar / (water + sugar):
                    ans = [water + sugar, sugar]
print(ans[0], ans[1])
"""


a, b, c, d, e, f = map(int, input().split())
sugar = [0] * (f + 5)
for i in range(f + 1):
    if i * c > f:
        break
    for j in range(f + 1):
        if i * c + j * d > f:
            break
        sugar[i * c + j * d] = 1
water = [0] * (f // 100 + 5)
for i in range(f // 100 + 1):
    if i * a > f // 100:
        break
    for j in range(f // 100 + 1):
        if i * a + j * b > f // 100:
            break
        water[i * a + j * b] = 1
m = 0
ans1, ans2 = a * 100, 0
for i in range(1, f // 100 + 1):
    if water[i] == 0:
        continue
    t = 0
    for j in range(i * e, 0, -1):
        if sugar[j] == 1:
            if 100 * i + j <= f and m <= 100 * j / (i + j):
                ans1, ans2 = 100 * i + j, j
                m = 100 * j / (i + j)
                t = 1
        if t == 1:
            break
print(ans1, ans2)

Measured memory_bytes: 9176
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double r=sc.nextDouble();
		double area=r*r*Math.PI;
		double ensyu=2*r*Math.PI;
		System.out.printf("%f %f",area,ensyu);

	}

}



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

const int N=1005;
const int MOD=1e9+7;
 
 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


  int n,h;
  cin>>h>>n;
  int dp[n+1][h+1];
  for(int i=0;i<=h;i++)
  {
  	dp[0][i]=INT_MAX;
  }
  for(int i=0;i<=n;i++)
  {
  	dp[i][0]=0;
  }
  for(int i=1;i<=n;i++)
  {
  	int a,b;
  	cin>>a>>b;
  	for(int j=1;j<=h;j++)
  	{
      
      if(j-a<=0)
      {
         dp[i][j]=min(dp[i-1][j],b);
      }
      else
      	{
      		dp[i][j]=min(dp[i-1][j],b+dp[i][j-a]);
      	}
  	}
  }

  cout<<dp[n][h];


  

  
}




Measured memory_bytes: 78464
# -*- coding: utf-8 -*-

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

numf=0
nums=0
for i in range(0,3):
	if hoge[i]==5:
		numf +=1
	if hoge[i]==7:
		nums +=1

if (numf == 2) and (nums==1):
	print("YES")
else:
	print("NO")




Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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



int main(){
    int N; std::cin >> N;
    long double ans(0.0);
    std::vector<int> x(N), y(N);
    for(int i(0); i < N; ++i) std::cin >> x[i] >> y[i];
    for(int i(0); i < N; ++i){
        for(int j(i+1); j < N; ++j){
            ans += 2 * std::sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j])) / N;
        }
    }
    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
    return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

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

    rep2(i, (int)100/0.08) {
        if ( (int)(i*0.08) == a && (int)(i*0.1) == b ) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
const int maxn = 20;

int e[maxn][maxn],n,m,bin[1<<15];
LL dp[1<<15][maxn];
LL cs[1<<15][maxn]; 
LL cst[1<<15],sum;
void upd(LL &x,LL y) {if (x<y) x=y;}
int main()
{
	#ifdef LOCAL_JUDGE
		freopen("mine.in","r",stdin);
		freopen("mine.out","w",stdout);
	#endif
	scanf("%d %d",&n,&m);
	for (int i=0;i<n;i++) bin[1<<i]=i;
	for (int u,v,w,i=1;i<=m;i++)
		scanf("%d %d %d",&u,&v,&w),
		u--,v--,e[u][v]=e[v][u]=w,sum+=w;
	for (int i=0;i<n;i++)
	for (int j=1;j<(1<<n);j++)
		cs[j][i]=cs[j^(j&-j)][i]+e[bin[j&-j]][i];
	for (int i=1;i<(1<<n);i++)
		cst[i]=cst[i^(i&-i)]+cs[i^(i&-i)][bin[i&-i]];
	memset(dp,-1,sizeof dp);
	dp[1][0]=0;
	for (int s=0;s<(1<<n);s++)
	for (int u=0;u<n;u++)
	if ((s>>u&1)&&dp[s][u]!=-1) {
		for (int t=0;t<n;t++)
		if (!(s>>t&1)&&e[u][t])
			upd(dp[s^(1<<t)][t],e[u][t]+dp[s][u]);
		int o=((1<<n)-1)^s;
		for (int t=o;t;t=t-1&o)
			upd(dp[s^t][u],dp[s][u]+cst[t]+cs[t][u]);
	}
	printf("%lld",sum-dp[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 10752
#!/usr/bin/env python3
import sys


def solve(s: str):
    print(len(s) // 2 - s.count('p'))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 26;
	static int MOD = 998244353;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int h = in.nextInt(), w = in.nextInt();
			int[][] g = new int[10][10];
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					g[i][j] = in.nextInt();
				}
			}

			for (int k = 0; k < 10; k++) {
				for (int i = 0; i < 10; i++) {
					for (int j = 0; j < 10; j++) {
						g[i][j] = Math.min(g[i][j], g[i][k]+g[k][j]);
					}
				}
			}

			Map<Integer, Integer> map = new HashMap<>();
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int l = in.nextInt();
					map.merge(l, 1, Integer::sum);
				}
			}

			long ans = 0;
			for (Entry<Integer, Integer> e : map.entrySet()) {
				int f = e.getKey();
				if (f == -1) continue;
				ans += e.getValue() * g[f][1];
			}

			out.println(ans);
		}
	}



	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}
}

Measured memory_bytes: 28628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var x = Console.ReadLine().ToInt();
		
		if(x >= 400 &&x <= 599) Console.WriteLine("8");
		else if(x >= 600 &&x <= 799) Console.WriteLine("7");
		else if(x >= 600 &&x <= 999) Console.WriteLine("6");
		else if(x >= 800 &&x <= 1199) Console.WriteLine("5");
		else if(x >= 1000 &&x <= 1399) Console.WriteLine("4");
		else if(x >= 1200 &&x <= 1599) Console.WriteLine("3");
		else if(x >= 1400 &&x <= 1799) Console.WriteLine("2");
		else if(x >= 1600 &&x <= 1999) Console.WriteLine("1");
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27528
n, m = gets.split.map{|s|s.to_i}
islands = [n+1] * n

m.times do |ai|
  src, target = gets.split.map{|s|s.to_i}
  islands[src-1] = target if islands[src-1] > target
end

count = 0

(n-1).times do |i|
  if islands[i] == i+2
    count += 1
  else
    islands[i+1] = islands[i] if islands[i+1] > islands[i]
  end
end

puts count

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    map<int,int> m;
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;++i){
        int d;
        cin>>d;
        for(int j=0;j<d;++j){
            int di;cin>>di;
            m[di]++;
        }
    }
    cout << n-m.size() << endl;
    return 0;
}

Measured memory_bytes: 3664
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int M = keyboard.nextInt();
		int[] A= new int[N];
		int sum = 0;
		
		for(int i=0; i<N;i++) {
			int a = keyboard.nextInt();
			sum += a;
			A[i] = a*4*M;
		}
		
		int count = 0;
		for(int j=0; j<N;j++) {
			if(A[j]>=sum) {
				count++;
			}
		}
		
		if(count >= M) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		keyboard.close();	
		
	}
}

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

typedef long long ll;
#define fore(i,ii,iii) for(int i=ii;i<iii;i++)
#define mset(a,b) memset(a,b,sizeof(a))

const ll N=405,INF=1e15;
ll n,a[N],dp[N][N],sp[N];

ll solve(int l,int r) {
  if(l==r)return 0;
  if(dp[l][r]!=-1)return dp[l][r];
  ll res=INF;
  fore(m,l,r) {
    res=min(res,sp[r]-sp[l-1]+solve(l,m)+solve(m+1,r));
  }
  return dp[l][r]=res;
}

int main() {
  ios::sync_with_stdio(false);
  mset(dp,-1);
  cin>>n;
  fore(i,1,n+1)cin>>a[i];
  fore(i,1,n+1)sp[i]=sp[i-1]+a[i];
  //fore(i,1,n+1)cout<<sp[i]<<" ";cout<<endl;
  cout<<solve(1,n)<<endl;
  /*
  fore(i,1,n+1) {
    fore(j,i,n+1) {
      cout<<i<<" "<<j<<" "<<solve(i,j)<<endl;
    }
  }
  */
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

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

    {
        myui ats[5];
        for(myui i = 0; i < 5; i++) cin >> ats[i];

        myui k;
        cin >> k;

        cout << ((ats[4]-ats[0] > k) ? ":(" : "Yay!") << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, M = NMI()
    A = NLI()

    match_dict = {i+1: m for i, m in enumerate([2,5,5,4,5,6,3,7,6])}
    usable_list = [[a, match_dict[a]] for a in A]
    usable_list.sort(key=lambda x: (x[1], -x[0]))

    # dp[i] はi本使った時の最大数
    dp = [-1]*(N+10)
    dp[0] = 0

    for i in range(N+1):
        for num, m in usable_list:
            dp[i+m] = max(dp[i+m], dp[i]*10+num)
    print(dp[N])



if __name__ == "__main__":
    main()

Measured memory_bytes: 20660
ab = [list(map(int, input().split())) for _ in range(3)]

for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            if i==j or i==k or j==k:
                continue
            tmp = set([1,2,3,4])
            tmp.remove(i)
            tmp.remove(j)
            tmp.remove(k)
            l = list(tmp)[0]
            if [i,j] in ab or [j,i] in ab:
                if [j,k] in ab or [k,j] in ab:
                    if [k,l] in ab or [l,k] in ab:
                        print('YES')
                        exit()
print('NO')



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <sstream>
#include <string>
using namespace std;
#define out(X) cerr << #X << ": " << (X) << endl
#define SZ(X) ((int)(X.size()))
#define REP(I,N) for (int I = 0; I < (N); ++I)
#define FOR(I,L,H) for (int I = (L); I < (H); ++I)
#define MP(X,Y) make_pair((X),(Y))
#define PB push_back
#define ALL(X) X.begin(), X.end()
template <typename T> inline bool checkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline bool checkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
typedef long long lint;

const int MAXN = 100 + 10;

struct node {
    int lx, rx, ly, ry;
    string to;
    void input() {
        cin >> lx >> ly >> rx >> ry >> to;
    }
    bool is_in(int x, int y) {
        return (x >= lx && x <= rx) && (y >= ly && y <= ry);
    } 
};

map<string, int> id;
string _id[MAXN];
vector<node> butt[MAXN];
int buff[100000];

int main() {
    int n, w, h;
    while (scanf("%d", &n), n) {
        scanf("%d%d", &w, &h);
        REP(i, n) {
            string name;
            int nn;
            cin >> name >> nn;
            id[name] = i;
            _id[i] = name;
            butt[i].clear();
            REP(j, nn) {
                node tmp;
                tmp.input();
                butt[i].PB(tmp);
            }
        }
        int m;
        scanf("%d", &m);
        buff[0] = 0;
        int p = 0, sz = 1;
        REP(i, m) {
            string op;
            cin >> op;
            int now = buff[p];
             //out(_id[now]);
            if (op == "click") {
                int x, y;
                cin >> x >> y;
                REP(j, SZ(butt[now])) {
                    if (butt[now][j].is_in(x, y)) {
                        buff[p + 1] = id[butt[now][j].to];
                        p = p + 1;
                        sz = p + 1;
                        break;
                    }
                }
            } else if (op == "show") {
                cout << _id[now] << endl;
            } else if (op == "back") {
                if (p - 1 >= 0) {
                    p = p - 1;
                }
            } else if (op == "forward") {
                if (p + 1 < sz) {
                    p = p + 1;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>

int main(int argc, char *argv[]){
    unsigned int N;
    std::cin >> N;
    int A[N];
    for(auto &a : A){
        std::cin >> a;
    }

    int i;
    for(i=0; i<N-1; ++i){
        A[N-1] += (2*(i&1)-1)*A[i];
    }

    A[N-1] /= 2;

    for(i=N-2; i>=0; --i){
        A[i] -= A[i+1];
    }
    
    for(auto &a : A){
        std::cout << 2*a << " ";
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f3f3f3f3f
const int maxn=2e5+10;
ll A[maxn];
ll D;
struct Edge
{
	int u,v;
	ll cst;
	Edge(){}
	Edge(int u,int v,ll cst):u(u),v(v),cst(cst){}
	bool operator < (const Edge &t)const
	{
		return cst<t.cst;
	}
};
vector<Edge> edge;
void solve(int l,int r)
{
	if(l==r)return;
	int mid=(l+r)>>1;
	
	int v1=0;
	ll mn=inf;
	for(int i=l;i<=mid;i++)
	{
		ll vl=A[i]-D*1ll*i;
		if(vl<mn)
		{
			mn=vl;
			v1=i;
		}
	}
	
	int v2=0;
	mn=inf;
	
	for(int i=mid+1;i<=r;i++)
	{
		ll vl=A[i]+D*1ll*i;
		if(vl<mn)
		{
			mn=vl;
			v2=i;
		}
	}
	
	for(int i=l;i<=mid;i++)
	{
	//	cout<<(A[v2]+A[i]+D*(v2-i))<<" "<<v2<<" "<<i<<endl;
		edge.push_back(Edge(v2,i,A[v2]+A[i]+D*1ll*(v2-i)));
	}
	
	for(int i=mid+1;i<=r;i++)
	{
	//	cout<<(A[v1]+A[i]+D*(i-v1))<<" "<<i<<" "<<v1<<endl;
		edge.push_back(Edge(v1,i,A[v1]+A[i]+D*1ll*(i-v1)));
	}
//	system("pause");
	
	solve(l,mid);
	solve(mid+1,r);
}
int fa[maxn];
inline int getfa(int x)
{
	return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main()
{
	int n;
	scanf("%d%lld",&n,&D);
	for(int i=0;i<n;i++)scanf("%lld",&A[i]);
	
	solve(0,n-1);
	
	sort(edge.begin(),edge.end()); 
	
	for(int i=0;i<n;i++)fa[i]=i; 
	ll ans=0;
	for(int i=0;i<edge.size();i++)
	{
		int u=edge[i].u,v=edge[i].v;
		if(getfa(u)==getfa(v))continue;
	//	cout<<u<<" "<<v<<endl;
		fa[getfa(u)]=getfa(v);
		ans+=edge[i].cst;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 69472
import java.io.*;
public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String input = br.readLine();
			String[] score = input.split(" ");
			Integer m = Integer.parseInt(score[0]);
			Integer f = Integer.parseInt(score[1]);
			Integer r = Integer.parseInt(score[2]);
			Integer total = m + f;
			if(m == -1 && f == -1 && r == -1){
				break;
			}
			if(m == -1 || f == -1){
				System.out.println("F");
			}
			else if(total >= 80){
				System.out.println("A");
			}
			else if(total >= 65 && total < 80){
				System.out.println("B");
			}
			else if(total >= 50 && total < 65){
				System.out.println("C");
			}
			else if(total >= 30 && total < 50){
				if(r >= 50){
					System.out.println("C");
				}
				else{
					System.out.println("D");
				}
			}
			else if(total < 30){
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 17076
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

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

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> a(n);
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll cnt = 0;
    for(i=2;i<n;i++){
        for(j=1;j<i;j++){
            auto x = upper_bound(a.begin(),a.begin()+j,a[i]-a[j]);
            ll y = x-a.begin();
            cnt+=j-y;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
ans=float("INF")
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(n):

        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  char S[100001];
  scanf("%s", S);
  int B = 0;
  int W = 0;
  for(int i = 0; S[i] != '\0'; i++) {
    if(i % 2) {// odd
      if(S[i] == '0') {// Black
	W++;
      } else {// White
	B++;
      }
    } else {// even
      if(S[i] == '0') {// Black
	B++;
      } else {// White
	W++;
      }
    }
  }

  printf("%d\n", (B < W)? B : W);
  return 0;
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int n;
	cin>>n;
	map<string,int> mp;
	ll ans = 0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11264
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Silver Fox vs Monster
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

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

/* global variables */

pli ps[MAX_N];
ll ds[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, d, a;
  scanf("%d%d%d", &n, &d, &a);
  int w = 2 * d + 1;

  for (int i = 0; i < n; i++) scanf("%lld%d", &ps[i].first, &ps[i].second);
  sort(ps, ps + n);

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    ll xi = ps[i].first;
    int hi = ps[i].second;

    if (hi > ds[i] * a) {
      hi -= ds[i] * a;
      int c = (hi + a - 1) / a;
      int j = lower_bound(ps, ps + n, pli(xi + w, 0)) - ps;
      ds[i] += c, ds[j] -= c;
      cnt += c;
    }
    ds[i + 1] += ds[i];
  }

  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n, a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> a >> b;
		cout << a + b << endl;
	}
}




Measured memory_bytes: 256