akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

void solve() {
    ll n, m;
    cin >> n >> m;
    
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.rbegin(), a.rend());
    
    vector<ll> pref(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i - 1];
    
    ll l = 0, r = 3e5, mid;
    while(r - l > 1) {
        mid = (r + l) / 2;
        
        ll elems = 0;
        // pick every one : a[i] + a[j] >= mid
        for (int i = 0; i < n; ++i) {
            auto pos = lower_bound(a.rbegin(), a.rend(), mid - a[i]);
            ll ind = n - (pos - a.rbegin()) - 1;
            if (ind >= i)
                elems += 2 * (ind - i) + 1;
        }
        
        if (elems >= m)
            l = mid;
        else
            r = mid;
    }
    
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        auto pos = lower_bound(a.rbegin(), a.rend(), r - a[i]);
        ll ind = n - (pos - a.rbegin()) - 1;
        if (ind >= i) {
            m -= 2 * (ind - i) + 1;
            sum += 2 * a[i] + 2 * ((ind - i) * a[i] + pref[ind + 1] - pref[i + 1]);
        }
    }
    sum += m * l;
    cout << sum << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll b[1001] = {};

	repe(k, 1, N) {
		ll t = k;
		repe(i, 2, N) {
			while (t % i == 0) {
				t = t / i;
				b[i]++;
			}
		}
	}
	ll ans = 1;
	repe(i, 2, 1000) {
		if (b[i] != 0) {
			ans = ans * (b[i] + 1) % 1000000007;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

int gcd(int a, int b){
  if(a % b == 0) return b;
  else return gcd(b, a%b);
}

//最小公倍数
int lcm(int a, int b){
  int g = gcd(a, b);
  return a / g * b;
}

int main() {
  int x;
  cin >> x;
  int ans = 360/x;
  if (360%x != 0) ans = lcm(x, 360)/x;
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mx=100100;
ll h[mx];
int main()
{
	ll x;cin>>x;
	h[0]=0;
	for(ll i=1;i<=1000;i++)
	{
		h[i]=i*i*i*i*i;
	}
	int f=-1;
	ll y;
	for(int i=0;i<=1000;i++)
	{
		if(h[i]<x)
		{
			y=x-h[i];
			for(int j=0;j<=1000;j++)
			{
				if(h[j]==y){
					f=j;break;
				}
			}
			if(f>=0){
				f=-f;
				cout<<i<<" "<<f<<"\n";
				break;
			}
		}
		else{
			y=h[i]-x;
			for(int j=0;j<=1000;j++)
			{
				if(h[j]==y){
					f=j;break;
				}
			}
			if(f>=0){
				cout<<i<<" "<<f<<"\n";
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {

    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    sc.nextLine()
    val s = sc.nextLine().split("").filter(_ != "")


    var rcnt = 0L
    var gcnt = 0L
    var bcnt = 0L
    val rgb = s.map {
      case "R" => rcnt += 1
      case "G" => gcnt += 1
      case "B" => bcnt += 1
    }

    var sum = rcnt * gcnt * bcnt

    (for {
      j <- 0 until n
      i <- 0 until j
      k = 2 * j - i
      if k < n
      if s(i) != s(j)
      if s(i) != s(k)
      if s(k) != s(j)
    } yield (sum -= 1))

    println(sum)
  }

}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,i,j;
	int a[29];
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	int cnt = 0;
	for(i=1;i<n-1;i++){
		if(a[i] > a[i-1] && a[i] < a[i+1]){
			cnt++;
		}else if(a[i] < a[i-1] && a[i] > a[i+1]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
};

Measured memory_bytes: 256
x;
int pal(int n){
	char s[9],t[9];
	sprintf(s,"%d",n);
	strcpy(t,s);
	for(x=0;x<strlen(s);x++)if(s[x]!=s[strlen(s)-x-1])return 1;
	return 0;
}
main(){
	int n,i;
	scanf("%d",&n);
	for(i=0;;i++){
		if(!pal(n-i)){printf("%d\n",n-i);return 0;}
		if(!pal(n+i)){printf("%d\n",n+i);return 0;}
	}
	exit(0);
}

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

long long i, n;
int main(){
	cin >> n;
	long long h[n];
	for (i = 0; i < n; i++) cin >> h[i];
	for (i = 1; i < n; i++){
		if (h[n - i - 1] > h[n - i]){
			h[n - i - 1]--;
			if (h[n - i - 1] > h[n - i]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
ll mod = 1e9 + 7;
ll modpow(ll m, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void printInBase(int x, int y) {
    if (x < y) {
        cout << x;
        return;
    }
    int rem = x % y;
    printInBase(x / y, y);
    cout << rem;
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}

int main() {
    ll n;
    cin >> n;
    rep(i, 1, n + 1) { primeFactors(i); }
    ll sum = 1;
    REP(i, n + 1) {
        // cout << cnt[i] + 1 << endl;
        sum = sum * (cnt[i] + 1) % mod;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int n;
double dp[304][304][304];
double expected(int three,int two,int one){
	int zero = n - three-two-one;
	double& ret = dp[three][two][one];
	if(ret != 0.0)	return ret;
	if(zero == n)	return 0.0;
	if(three>0)
		ret += (expected(three-1,two+1,one)+1)*three;
	if(two>0)
		ret += (expected(three,two-1,one+1)+1)*two;
	if(one>0)
		ret += (expected(three,two,one-1)+1)*one;
	ret = ret/(one+two+three)+1.0*(n-one-two-three)/(one+two+three);
	return ret;
}
int main() {
	cin>>n;
	int a[3] = {0,}, k;
	for(int i = 0 ; i <n;i++){
		cin>>k;
		a[k-1]++;
	}
	memset(dp,0,sizeof(dp));
	cout<<fixed;
	cout.precision(10);
	cout<<expected(a[2],a[1],a[0]);
	return 0;
}

Measured memory_bytes: 219776
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int k,n;
    in>>k>>n;
    vector<int> a(n);
    for(auto&i:a) in>>i;
    int ans=a[0]+k-a[n-1];
    fr(i,n-1) ans=max(ans,a[i+1]-a[i]);
    cout<<k-ans<<endl;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
A=list(sorted(map(int,input().split())))
B=[] #置き換え(整数,個数)
for i in range(m):
    b,c=map(int,input().split())
    B.append([c,b])
B=list(reversed(sorted(B)))

C=[]
cnt=0
for i in range(m):
    b=B[i][1]
    c=B[i][0]
    if cnt+b>n:
        for i in range(n-cnt):
            C.append(c)
        cnt=n
        break
    for i in range(b):
        C.append(c)
    cnt+=b

for i in range(cnt):
    if C[i]>A[i]:
        A[i]=C[i]
    else:
        break
print(sum(A))

Measured memory_bytes: 25512
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, k: i64, q: i64,
        a: [usize1; q],
    }
    let mut cnt = vec![0i64; n];
    for i in 0..q {
        cnt[a[i as usize]] += 1;
    }

    for i in 0..n {
        if k - (q - cnt[i]) > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B >> C;
    if (A + B + C > 21) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  s.erase(unique(s.begin(), s.end()), s.end());
  cerr << s << endl;
  cout << s.size() << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ld>x(n);
  vector<string>u(n);
  rep(i,0,n)cin>>x[i]>>u[i];
  ld ret=0;
  rep(i,0,n){
    if(u[i]=="JPY")ret+=x[i];
    else ret+=380000*x[i];
  }
  printf("%.10Lf\n",ret);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int a[200];
int main()
{
      int n, m;
      cin >> n>>m;
      int sum=0;
      for (int i=0; i<n; i++)
      {
            cin>>a[i];sum+=a[i];
      }
      int flag=0;
      for (int i=0; i<n; i++)
      {
            if (a[i]*4*m>=sum) flag++;
      }
      if (flag>=m) cout << "Yes" << endl;
      else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    string s1,s2; cin>>s1>>s2;
    if(s1[0]==s2[2] && s1[2]==s2[0] && s1[1]==s2[1]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define FORL(i,a,b) for(ll i=(a);i<(b);++i)
#define REPL(i,n) FORL(i,0,n)

using namespace std;

int main(){
	int N;
	long long A[200000],sum[200001] = { 0 }, ans = 0;

	scanf("%d", &N);
	REP(i, N){
		scanf(" %lld", &A[i]);
		sum[i + 1] = sum[i] + A[i];
	}
	sort(sum, sum + N + 1);
	long long left = 0;
	REPL(i, N){
		if (sum[i] != sum[i + 1]){
			ans += (i - left + 1)*(i - left) / 2;
			left = i + 1;
		}
		else {
			if (i == N - 1){
				ans += (i + 1 - left + 1)*(i + 1 - left) / 2;
			}
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int MAXN = 100005;
typedef long long ll;
struct Poi{
    int id,x;
    bool operator < (const Poi &b)const
    {
        return x>b.x;
    }
}a[2][MAXN];
int n,vis[MAXN];
ll ans;
inline bool cmp(int x1,int x2,int Sta)
{
    if(Sta==0){
        return x2<=x1;
    }else
        return x2>=x1;
}
inline void move(int Sta)
{
    memset(vis,0,sizeof(vis));
    int p[2]={0},pos=0,k[2];
    k[0]=1,k[1]=-1;
    ll now=0;
    while(p[Sta]<n){
        while(p[Sta]<n && vis[a[Sta][p[Sta]+1].id])++p[Sta];
        if(p[Sta]==n)break;
        ++p[Sta];
        if(!cmp(k[Sta]*a[Sta][p[Sta]].x,pos,Sta))break;
        now+=abs(pos-k[Sta]*a[Sta][p[Sta]].x);
        pos=k[Sta]*a[Sta][p[Sta]].x;
        vis[a[Sta][p[Sta]].id]=1;
        Sta^=1;
    }
    ans=max(ans,now+abs(pos));
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&a[0][i].x,&a[1][i].x); 
        a[1][i].x=-a[1][i].x;
        a[0][i].id=a[1][i].id=i;
    }
    sort(a[0]+1,a[0]+n+1);
    sort(a[1]+1,a[1]+n+1);
    move(0);move(1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>

using namespace std;

#define MAXN 110
#define MAXV 100010
#define INF 0x3f3f3f3f

int n, w;
int value[MAXN], weight[MAXN];
long long dp[MAXN][MAXV+5];

void knapsack(){

    for(int j=0; j<=MAXV; j++){
        dp[0][j] = INF;
    }
    dp[0][0] = 0;
    for(int i=1; i<=n; i++) {
        for(int j=0; j<=MAXV; j++){
            dp[i][j] = dp[i-1][j];

            if(j-value[i]>=0) {
                dp[i][j] = min(dp[i][j], weight[i] + dp[i-1][j-value[i]]);
            }
        }
    }
}

int main(){

    cin >> n >> w;
    for(int i=1; i<=n; i++)
        cin >> weight[i] >> value[i];

    knapsack();

    int ans = 0;
    for (int i = 0; i<=MAXV; ++i) {
        if (dp[n][i] <= w) ans = i;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 80128
//標準入力をするときに記述する必要がある
process.stdin.resume();
process.stdin.setEncoding("utf8");

let line_input; //標準入力代入用に宣言
let lines = []; //複数行入力用
let reader = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout
});

//入力, 文字列で受け渡される
reader.on("line", (line) => {
    //line_input = parseInt(line) //単行入力
    let column = line.split(" ");
    let int_column = [];
    for (let i = 0; i < 2; i++){
        int_column.push(parseInt(column[i]))
    }
    lines.push(int_column)
});

//出力
reader.on("close", () => {
    let count = 0;
    let D = Math.pow(lines[0][1], 2);
    for (let i=1; i < lines.length; i++){
        if (Math.pow(lines[i][0], 2) + Math.pow(lines[i][1], 2) <= D){
            count += 1;
        }
    }
    console.log(count)
})

Measured memory_bytes: 99808
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

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

#define PB push_back
#define MP make_pair

#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define R1(a) do{scanf("%d", &(a));}while(0)
#define R2(a, b) do{scanf("%d%d", &(a), &(b));}while(0)
#define R3(a, b, c) do{scanf("%d%d%d", &(a), &(b), &(c));}while(0)
#define SV(vec) do{int s_v_;scanf("%d", &(s_v_));vec.PB(s_v_);}while(0)
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF 1000000007

int n, v[114], c[114], res;

int main ()
{
  R1(n);
  res = 0;
  FOR(i, 0, n) R1(v[i]);
  FOR(i, 0, n) R1(c[i]);
  FOR(i, 0, n) res += max(0, v[i] - c[i]);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int h=0,f,maxv=0;
	for(int i=1;i<=n;i++)
	{
		cin>>f;
		if(f>=maxv)
		{
			h++;
			maxv=f;
		}
	}
	cout<<h<<endl;
	return 0;
} 

Measured memory_bytes: 256
from operator import itemgetter
N, M = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(M)], key=itemgetter(1))

ans = 0
removed = -1

for a, b in ab:
    if a > removed:
        removed = b-1
        ans += 1
print(ans)

Measured memory_bytes: 24624
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sqr(x) (x) * (x)
#define cube(x) (z) * (z) * (x)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}

signed main() {
  int x   = in();
  int ans = x / 11;
  x -= 11 * ans;
  ans *= 2;
  if (x > 0) {
    if (x <= 6) {
      ans += 1;
    } else {
      ans += 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) FOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int X;
    cin >> X;
    if (X == 1) {
        cout << 1 << endl;
        return 0;
    }
    int res = 0;
    for (int b = 2;; ++b) {
        int bp = b * b;
        if (bp > X) {
            break;
        }
        while (bp * b <= X) {
            bp *= b;
        }
        amax(res, bp);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, s[128], sum = 0;
	vector<int> nt;

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		sum += s[i];
		if(s[i] % 10 != 0)
			nt.push_back(s[i]);
	}
	sort(nt.begin(), nt.end());
	
	if(sum % 10 == 0){
		if(nt.empty()){
			cout << "0" << endl;
		}
		else{
			cout << sum - nt[0] << endl;
		}
		
	}
	else{
		cout << sum << endl;
	}
	return 0;
}

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

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

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            sum += A[i]*A[j];
        }
    }
    cout << sum <<endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn exe(x: u32) -> u32 {
    let a = x / 500;

    let x = x % 500;

    let b = x / 5;

    return a * 1000 + b * 5;
}

fn main() {
    input! {
        x: u32,
    }
    let ans = exe(x);
    println!("{}", ans);
}

#[test]
fn test() {
    assert_eq!(exe(1024), 2020);
    assert_eq!(exe(0), 0);
    assert_eq!(exe(1000000000), 2000000000
    );
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <functional>

const int N = 1000;
const int MOD = 1e9 + 7;

int n, m, a[N], b[N];

int solve()
{
    std::sort(a, a + n, std::greater<int>());
    if (std::unique(a, a + n) - a != n) {
        return 0;
    }
    std::sort(b, b + m, std::greater<int>());
    if (std::unique(b, b + m) - b != m) {
        return 0;
    }
    int result = 1, i = 0, j = 0;
    for (int x = n * m; x >= 1; -- x) {
        if (i < n && a[i] == x) {
            if (j < m && b[j] == x) {
                i ++;
                j ++;
            } else {
                i ++;
                result = 1LL * result * j % MOD;
            }
        } else {
            if (j < m && b[j] == x) {
                j ++;
                result = 1LL * result * i % MOD;
            } else {
                result = 1LL * result * (i * j - (n * m - x)) % MOD;
            }
        }
    }
    return result;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
    }
    for (int i = 0; i < m; ++ i) {
        scanf("%d", b + i);
    }
    printf("%d\n", solve());
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    long long sum = 0;
    int N, M;
    int P[200];
    int T[200];
    int X[200];

    scanf("%d",&N);//問題数
    for(int i=1; i<=N; i++) scanf("%d",&T[i]);//問題を解く時間
    scanf("%d",&M);//ドリンク数 
    for(int i=1; i<=M; i++) scanf("%d %d",&P[i], &X[i]);//何問目が何秒で解けるようになる 

    for(int i=1; i<=M; i++){
        sum=0;

        for(int j=1; j<=N; j++){
            if(P[i] == j){
                sum += X[i];
            } else {
                sum += T[j];
            }
        }

        printf("%lld\n",sum);
    }



    return 0;
}

Measured memory_bytes: 1700
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1e15;
const ld eps = 1e-6;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

int main() {
	ll A, B;
	cin >> A >> B;
	bool gua = A % 4 <= 1;
	bool gub = B % 4 == 0 || B % 4 == 3;
	ll ans = 0;
	ans += gua != gub;
	ll a = A / 2;
	ll b = B / 2;
	ll now = 2;
	while (b > 0) {
		bool gl = a % 2 == 0 || (a % 2 == 1 && A % 2 == 0);
		bool gr = b % 2 == 0 || (b % 2 == 1 && B % 2 == 1);
		ans += (gl != gr) * now;
		now *= 2;
		a /= 2;
		b /= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
	int a,b,c,x=0;
	scanf("%d %d %d", &a, &b, &c);
	for (int i = a; i <= b; i++) {
		if (c % i == 0) {
			x++;
		}
	}
	printf("%d\n", x);
	return 0;
}

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

int main()
{
  int a,c,b;
  while(~scanf("%d %d %d",&a,&b,&c))
  {
      if(a<=c)
      {
          if(a+b>=c)
            printf("YES\n");
          else
            printf("NO\n");
      }
      else
        printf("NO\n");
  }
}


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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

using ll = long long;
using LL = long long;

class Edge{
public:
    int from,to;
    ll value, konzatu;
    Edge(int a,int b,ll c, ll d){
        from = a;
        to = b;
        value = c;
        konzatu = d;
    }
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

ll mod = 1e9+7;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long 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 main(){
    ll N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    COMinit();

    for(int i = 0;i < N;i++){
        for(int j = 0;j < M;j++){
            ll a = i;
            ll b = (N - i - 1);
            ll c = j;
            ll d = (M - j - 1);
            ans += M * ((a * (a + 1)) / 2 + (b * (b + 1)) / 2);
            ans += N * ((c * (c + 1)) / 2 + (d * (d + 1)) / 2);
            ans %= mod;
        }
    }
    ans *= modinv(2, mod);
    ans %= mod;
    cout<<(ans * COM(N * M - 2, K - 2)) % MOD<<endl;
}


Measured memory_bytes: 12160
import java.util.*;
import java.io.*;
public class Main {
    
    static ArrayList<Integer> al[];
    static boolean vis[];
    static int max;
    
    static void DFS(int node)
    {
        vis[node] = true;
        max++;
        for(int i : al[node])
        {
            if(vis[i] == false)
            {
                DFS(i);
            }
        }
    }
    
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      PrintWriter w = new PrintWriter(System.out);
      
      int n = sc.nextInt();
      int m = sc.nextInt();
      al = new ArrayList[n];
      Arrays.setAll(al, e->new ArrayList());
      vis = new boolean[n];
      for(int i = 0; i < m; i++)
      {
          int temp1 = sc.nextInt() - 1;
          int temp2 = sc.nextInt() - 1;
          al[temp1].add(temp2);
          al[temp2].add(temp1);
      }
      int fin_max = 0;
      for(int i = 0; i < n; i++)
      {
          if(vis[i] == false)
          {
              max = 0;
              DFS(i);
              fin_max = Math.max(fin_max, max);
          }
      }
      w.println(fin_max);
      w.close();
    }
}

Measured memory_bytes: 116656
#include <iostream>

/*
[x^Ny^K]  \sum_{t=0}^\infty [(M-1)(x+yx^2+y^2x^3+...)]^t
[x^Ny^K]  1/[1- (M-1)(x+yx^2+y^2x^3+...)]
[x^Ny^K]  1/[1- (M-1)x/(1-yx)]
[x^Ny^K]  (1-yx)/[1-yx - (M-1)x]
[x^Ny^K]  (1-yx) \sum_{i=0}^\infty (yx+(M-1)x)^i

[y^K]  (y+(M-1))^N - y (y+(M-1))^{N-1}
\binom{N}{K} (M-1)^{N-K} - \binom{N-1}{K-1} (M-1)^{N-K}
(M-1)^{N-K} \binom{N-1}{K}

\sum_{i=0}^K (M-1)^{N-i} \binom{N-1}{i}
*/

int n, m, k;

constexpr int mod = 998244353;

int fact[200001];
int ifact[200001];

using u64 = unsigned long long int;

int modpow(int a, int n){
  int r = 1;
  for(; n; n >>= 1){
    if(n & 1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}

int main(){
  std::cin >> n >> m >> k;
  fact[0] = 1;
  for(int i = 1; i <= n; i++) fact[i] = (u64) fact[i-1] * i % mod;
  ifact[n] = modpow(fact[n], mod - 2);
  for(int i = n-1; i >= 0; i--) ifact[i] = (u64) ifact[i+1] * (i+1) % mod;

  u64 ans = 0;
  for(int i = 0; i <= k; i++){
    ans += (u64) modpow(m-1, n-i-1) * fact[n-1] % mod * ifact[i] % mod * ifact[n-i-1] % mod;
  }
  ans %= mod;
  ans = ans * m % mod;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 5184
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int w[11][11], v[11][11];
int A, B;
struct Edge {
	int a, b, c;
}E[10100];
int cnt;
int main() {
	int i, j, k, l;
	scanf("%d%d", &A, &B);
	for (i = 1; i <= 100; i++) {
		E[cnt++] = { i,i + 1,-2 };
	}
	for (i = 102; i < 202; i++) {
		E[cnt++] = { i,i + 1,-1 };
	}
	for (i = 1; i <= A; i++)for (j = 1; j <= B; j++)scanf("%d", &w[i][j]);
	for (i = 0; i <= 100; i++)for (j = 0; i + j <= 100; j++){
		int Mx = 0;
		for (k = 1; k <= A; k++) {
			for (l = 1; l <= B; l++) {
				Mx = max(Mx, w[k][l] - i*k - j*l);
			}
		}
		if (Mx < 0)continue;
		int chk = 0;
		for (k = 1; k <= A; k++) {
			for (l = 1; l <= B; l++) {
				if (w[k][l] == i*k + j*l + Mx && !v[k][l])chk = 1, v[k][l] = 1;
			}
		}
		if (!chk)continue;
		E[cnt++] = { i + 1, 202 - j, Mx };
	}
	for (i = 1; i <= A; i++)for (j = 1; j <= B; j++)if (!v[i][j]) {
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	printf("%d %d\n", 202, cnt);
	for (i = 0; i < cnt; i++) {
		printf("%d %d ", E[i].a, E[i].b);
		if (E[i].c < 0)printf("%c\n", E[i].c + 'Z');
		else printf("%d\n", E[i].c);
	}
	printf("%d %d\n", 1, 202);
}

Measured memory_bytes: 128
R, G, B, N = map(int, input().split())
# print("(N,R,G,B)=({},{},{},{})".format(N,R,G,B))

ans = 0
for i in range(N+1):
    if R*i > N:
        break
    for j in range(N+1):
        tmp = R*i + G*j
        # print("i={},j={},tmp={}".format(i,j,tmp))
        if tmp > N:
            break
        if (N-tmp)%B == 0:
            ans += 1
            # print("(i,j,k)=({},{},{})".format(i,j,(N-tmp)//B))
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;

	vector<int> ans(n);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;

		a--;
		b--;
		ans[a]++;
		ans[b]++;

	}

	for (int i : ans) {
		cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<double> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    double ok  = 1000000000;
    double ng  = 0;
    auto check = [&](double mid) {
        lint cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += lint(a[i] / mid + 0.999999999) - 1;
        }
        return cnt <= k;
    };
    int num = 1000;
    while (num--) {
        double mid             = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << lint(ok + 0.999999999) << "\n";
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

bool comb(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;

	sort(all(p));

	ll sum = 0;
	rep(i, n) {
		if (k <= p[i].second + sum) {
			out(p[i].first);
			return 0;
		}
		sum += p[i].second;
	}

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
//typedef std::pair<int,int> P;

    string S;
    deque<int> Q;
    ll ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>S;
    REP(i,S.size()-1){
        if(S[i]!=S[i+1])Q.push_back(i);
    }
    while(!Q.empty()){
        if(Q.front()>=Q.back()){
            Q.pop_front();
        }else Q.pop_back();
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, k; cin >> a >> b >> c >> k;
    int n = 0;
    while (b <= a) {
        n++; b *= 2;
    }
    while (c <= b) {
        n++; c *= 2;
    }
    cout << (n <= k ? "Yes\n" : "No\n");
    return 0;
}

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

using namespace std;

int main(){  
  int H, W;
  while(1){
    cin >> H >> W;
    if( (H == 0) && (W == 0)){
      break;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if( i%2 != 0 ){
          if( j%2 != 0){
            cout << "#";          
          } else {
            cout << ".";
          }
        } else {
          if( j%2 != 0){
            cout << ".";          
          } else {
            cout << "#";
          }
        }
      }
      cout << "" << endl;
    }
    cout << "" << endl;
  }
  return 0;
}


Measured memory_bytes: 3076
#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>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  string S;
  string cs[10];
  cs[0] = " ";
  cs[1] = "',.!?";
  cs[2] = "abcABC";
  cs[3] = "defDEF";
  cs[4] = "ghiGHI";
  cs[5] = "jklJKL";
  cs[6] = "mnoMNO";
  cs[7] = "pqrsPQRS";
  cs[8] = "tuvTUV";
  cs[9] = "wxyzWXYZ";
  while(cin >>S){
    stringstream ss;
    int b = S[0] - '0', cnt = 0, sl = S.length();
    FOR(i, 1, sl){
      int n = S[i] - '0';
      if(b == 0 && n == 0){
        ss <<cs[0][0];
      } else if(b == n){
        cnt = (cnt + 1) % (int)(cs[b].length());
      }else if(b != 0) {
        ss << cs[b][cnt];
        cnt = 0;
      }
      b = n;
    }
    if(S.length() > 1 && (S[sl - 1] != '0' || (S[sl - 1] == '0'  && S[sl - 2] == '0'))) ss << cs[b][cnt];
    cout <<ss.str() <<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
// A.

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b;
	cin >> a >> b;
	bool ans = (a % 3) == 0 || (b % 3) == 0 || ((a + b) % 3) == 0;
	cout << (ans ? "Possible" : "Impossible") << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
#include <iomanip>
using namespace std;

//??°?????????????????°

void function()
{
	//??¢??°
}

int main()
{
	int H, W;
	while (cin >> H >> W)
	{
		if (H==0 && W==0)
		{
			break;
		}


		for (int i = 0; i <W; i++)
		{
			cout << "#";
		}

		for (int i = 0; i <H-2; i++)
		{
			cout << endl << "#";

			for (int j = 0; j < W-2; j++)
			{
				cout << ".";

			}
			cout << "#";
		}

		cout << endl;

		for (int i = 0; i <W; i++)
		{
			cout << "#";
		}
		cout << endl <<endl;

	}
	return 0;
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);

			 System.out.println(a==b?a*2
					 		   :a>b?a+a-1
					 		   :b+b-1);
		}
	}
}

Measured memory_bytes: 25232
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		string s; cin >> s;
		int i = 0;
		int ans = 0;
		while (i < n - 2) {
			int j = i;
			if (s[i] == 'A') {
				if (s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
			}
			i++;
		}
		cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N; cin >> N;
    for (ll i=sqrt(N);i>=1;i--) {
        if (N%i==0) {
            cout << i+(N/i)-2 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a[][7] = {{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}};
  int x, y;
  string ans="No";
    cin >> x >> y;
    if(y<x) swap(x,y);
    if(x==y){
      ans = "Yes";
    }else{
      int key;
      for(int i=0;i<2; i++){
        for(int j=0; j<7; j++){
          if(a[i][j] == x) key = i;
          if(a[i][j]==y && key==i) ans = "Yes";
        }
      }
    }
    cout << ans << endl;



}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

template<class T>
bool compare(const vector<T>& a, const vector<T>& b)
{
    return  a[0] < b[0];
}

signed main(void) {
  int N, M;
  cin >> N >> M;

  vector< vector <int> > energy;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    vector<int> tmp;
    tmp.pb(a);
    tmp.pb(b);
    energy.pb(tmp);
  }

  sort(energy.begin(), energy.end(), compare<int>);

  int ans = 0;
  rep(i, energy.size()){
    if (energy[i][1] <= M) {
      ans += energy[i][0] * energy[i][1];
      M -= energy[i][1];
      if (M == 0) {
        break;
      }
    } else {
      ans += energy[i][0] * M;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6324