akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    cin >> a;
    
    //高橋くんがk番目の数を先に取れるか
    auto is_ok = [&](int k, ll x){
        int l = lower_bound(a.begin(), a.end(), x - (a[k] - x)) - a.begin();
        int r = k;
        return r - l + 1 >= n - k;
    };
    
    //高橋くんが連続して取る最小のindex
    auto get = [&](ll x){
        int ng = -1;
        int ok = n + 1;
        
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;

            if (is_ok(mid, x)) ok = mid;
            else ng = mid;
        }
        return ok;
    };
    
    vector<ll> sum(n + 1), even_sum(n + 1);
    rep(i, n) sum[i + 1] = sum[i] + a[i];
    rep(i, n) even_sum[i + 1] = even_sum[i] + i % 2 * a[i];
    
    rep(_q, q) {
        ll x;
        cin >> x;
        int lt = get(x);
        int la = max(0, n - (n - lt) * 2);
        //cout << la << " " << lt << endl;
        ll ans = sum[n] - sum[lt] + (n % 2 ? sum[la] - even_sum[la] : even_sum[la]);
        cout << ans << endl;
    }
}

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

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

	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	if (a[0] == a[1] && a[1] == a[2])cout << "Yes";
	else cout << "No";

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int p3[13];
int main(){
	int a;scanf("%d",&a);
	p3[0]=1;
	for(int i=1;i<13;i++)p3[i]=p3[i-1]*3;
	for(int i=0;i<p3[12];i++){
		int cur=0;
		for(int j=0;j<12;j++){
			if(i/p3[j]%3==1)cur+=p3[j];
			if(i/p3[j]%3==2)cur-=p3[j];
		}
		if(cur==a){
			bool ok=false;
			for(int j=11;j>=0;j--){
				if(!ok&&i/p3[j]%3==0)continue;
				if(i/p3[j]%3==0)printf("0");
				if(i/p3[j]%3==1)printf("+");
				if(i/p3[j]%3==2)printf("-");
				ok=true;
			}
			printf("\n");
			break;
		}
	}
}

Measured memory_bytes: 1000
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,c,t;
vector<ll> s;
int main(void){
    cin>>n>>c>>t;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        s.push_back(a);
    }
    sort(s.begin(),s.end());
    ll bus=0;
    ll cnt=0;
    ll ch=0;
    for(int i=0;i<n;i++){
        if(ch==0){
            ch=s[i];
            cnt++;
        }
        else if(ch+t>=s[i]&&cnt<c){
            cnt++;
        }
        else{
            ch=s[i];
            cnt=1;
            bus++;
        }
    }
    if(ch!=0)bus++;
    cout<<bus<<endl;
}


Measured memory_bytes: 1400
//////https://atcoder.jp/contests/abc178/tasks/abc178_d
#include <bits/stdc++.h>

using namespace std;

const int MO=1e9+7;
const int MAXN=2e3+2;
long long ans[MAXN];

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

    //初始化ans
    ans[0]=1;

    for (int i=3; i<=s; i++) {
        ans[i]=(ans[i-1]+ans[i-3])%MO;
    }

    cout<<ans[s]<<"\n";

    return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 55
#define MAX (1LL << 31) -1
//#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
//#define F function<T(T,T)>

const int MOD = 998244353;

struct ModInt{
    ll a;
    ModInt() : a(0) {}
    ModInt(ll x) {
        x%=MOD;
        if(x<0) x+=MOD;
        a=x;
    }

    ModInt operator+=(const ModInt p){
        a+=p.a;
        if( a>=MOD ) a-=MOD;
        return *this;
    }
    ModInt operator-=(const ModInt p){
        a-=p.a;
        if(a<0) a+=MOD;
        return *this;
    }
    ModInt operator*=(const ModInt p){
        a=(a*p.a)%MOD;
        return *this;
    }
    ModInt operator/=(const ModInt p){
        *this*=p.inverse();
        return *this;
    }

    ModInt operator+(const ModInt p){
        ModInt x(a);
        return x+=p;
    }
    ModInt operator-(const ModInt p){
        ModInt x(a);
        return x-=p;
    }
    ModInt operator*(const ModInt p){
        ModInt x(a);
        return x*=p;
    }
    ModInt operator/(const ModInt p){
        ModInt x(a);
        return x*=p.inverse();
    }

    ModInt operator=(ll p){
        p%=MOD;
        if(p<0) p+=MOD;
        a=p;
        return *this;
    }

    bool operator==(const ModInt p){
        return a==p.a;
    }

    bool operator!=(const ModInt p){
        return a!=p.a;
    }

    ModInt pow(ll N) const{
        ModInt ans(1),p(a);
        while(N>0){
            if(bit(N,0)){
                ans*=p;
            }
            p*=p;
            N>>=1;
        }
        return ans;
    }
    ModInt inverse() const{
        return pow(MOD-2);
    }

};

ModInt Mr(ll p){
    p%=MOD;
    if(p<0) p+=MOD;
    ModInt x(p);
    return x;
}


const int CMAX = 310000;
ModInt fac[CMAX],finv[CMAX],inv[CMAX];

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

ModInt COM(int n,int k){
    if(n<k) return Mr(0);
    if(n<0 || k<0) return Mr(0);
    return fac[n]*finv[k]*finv[n-k];
}


signed main(){
    ll N,A,B;
    ll K;
    cin>>N>>A>>B>>K;
    ModInt ans(0);
    COMinit();
    for(ll a=0;a<=N;a++){
        if((K-a*A)%B!=0) continue;
        ll b=(K-a*A)/B;
        ans+=COM(N,a)*COM(N,b);
    }
    cout<<ans.a<<endl;
}

Measured memory_bytes: 7552
a = input()
b = str()
l = len(a) 
for i in range(1, l):
    b += (a[i])
p = str(9) * (l-1)
if b == p:
    ans = 9 * (l-1) + int(a[0])
else:
    ans = 9 * (l-1) + int(a[0]) - 1
print(ans)


Measured memory_bytes: 3316
# 蟻本1-6-1例題相当
# 続いて、x、yを確定した際、zは一意に決まるか値が存在しないかのいずれかであることに着目する。
# よって2重のfor文で回してみる
# 最大で2500^2≒600万となる
# また、条件分岐による打ち切りもしない(x+y<s-kなら、zの値に関係なく不成立だが、それを考慮しない)

count = 0
k, s = map(int,input().split())
for x in range(k+1):
  for y in range(k+1):
    if 0 <= s-x-y and s-x-y <= k:
        count += 1
print(count)

Measured memory_bytes: 3064
def test():

	while True:

		count = 0
		inputs = list(map(int,input().split()))

		n = inputs[0]
		x = inputs[1]

		if n == 0 and x == 0:
			break

		for i in range(1,n+1):
			for j in range(i,n+1):
				for k in range(j,n+1):
					if i != j and j != k and k != i:
						if i + j + k == x:
							count += 1
		print(f"{count}")

if __name__ == "__main__":
	test()


Measured memory_bytes: 5608
N, Y = (int(i) for i in input().split())

#Y = 10000*a + 5000*b + 1000*c
#a + b + c = N

a = 0
b = 0
c = 0
sum = 0
list = []

for a in range(N+1):
    b = 0
    for b in range(N - a + 1):
        c = N - a - b
        sum = 10000*a + 5000*b + 1000*c
        if(sum == Y):
            list = list + [a, b, c]

if(list == []):
    print(-1, -1, -1)
else:
    print(list[0], list[1], list[2])





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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()

int main() {
	double n, sum = 0;
	cin >> n;
	FOR(i, 1, n) {
		double a;
		cin >> a;
		sum += 1 / a;
	}
	double res = 1 / sum;
	cout << setprecision(15) << res << endl;
	return(0);
}

Measured memory_bytes: 256
N = int(input())
P = [int(i) for i in input().split()] 
Q = [int(i) for i in input().split()] 
import itertools
N_list = list(itertools.permutations(list(range(1,N+1))))
cnt = 0
a = 0
b = 0
for i in N_list:
    #print(i)
    if list(i) == P:
        a = cnt + 1
    if list(i) == Q:
        b = cnt +1
    cnt += 1
print(abs(a-b))

Measured memory_bytes: 46448
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	   cin>>h[i];
	vector<int>dp(n,INT_MAX);
	   dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k && (i+j)<n;j++)
		{
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,k,*h=map(int,open(0).read().split());h.sort();print(min(y-x for x,y in zip(h,h[k-1:])))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 14528
#include <bits/stdc++.h>
using namespace std;
int main(){
    int ans=0;
    string s;
    cin >> s;
    for(int i=0;i<s.size();){
       int j=i;
       while(j<s.size()&&s[j]==s[i]) j++;
       ans++;
       i = j;
    }
    cout << ans-1 << endl;
}


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

int arr[105];

int main(){
    int n, x, i, ans=1;

    cin>>n>>x;
    for(i=1; i<= n; i++){
        cin>>arr[i];
        arr[i]+= arr[i-1];
        if (arr[i]<=x) ans++;
    }

    cout<<ans<<endl;


}



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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll N, K;

/*==================================================*/
class FermatCombination {
private:
	long long factrial[101010]; //階乗を保持
	long long inverse[101010];  //逆元を保持
	long long MOD;

public:
	FermatCombination(int size, long long mod);
	long long combine(int n, int k);
	long long fast_pow(long long x, int n);
};

FermatCombination::FermatCombination(int size, long long mod) {

	MOD = mod;

	factrial[0] = 1;
	inverse[0] = 1;

	for (int i = 1; i <= size; i++) {
		factrial[i] = (factrial[i - 1] * i) % MOD;  // 階乗を求める
		inverse[i] = fast_pow(factrial[i], (int)MOD - 2) % MOD; // フェルマーの小定理で逆元を求める
	}
}

long long FermatCombination::combine(int n, int k) {
	return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

long long FermatCombination::fast_pow(long long x, int n) { // x^n 計算量O(logn)
	long long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x % MOD;
		}
		x = x * x % MOD; // 一周する度にx, x^2, x^4, x^8となる
		n >>= 1;         // 桁をずらす n = n >> 1
	}
	return ans;
}


int main(){
	cin >> N >> K;
	FermatCombination fm(2010, MOD);  // 1から1010までの分割数
	REP(i,1,K+1){
		p(fm.combine(N-K+1, i)*fm.combine(K-1, i-1)%MOD);
	}



	return 0;
}

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

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



Measured memory_bytes: 3068
a=gets.to_i
n=gets.split.map(&:to_i)
m=gets.split.map(&:to_i)
result=[]
for i in 0.. a-1
 
    v=[]
    v.concat(n[0..i])
    v.concat(m[i..a-1])
  
    result<<v.inject(&:+)
    
    
end
puts result.max

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
const int mx=3e5+5;

using ll=long long; 

ll myhash(int x,int y){
 return 1LL*x*1e6 + y;
}

int cntx[mx],cnty[mx];
int main()
{
  int H,W,h,w,m;
  cin>>H>>W>>m;
  unordered_set<ll> st;
  int x,y;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    st.insert(myhash(x,y));
    cntx[x]++;
    cnty[y]++;
  }
  int mx_X=0,mx_Y=0;
  for(int i=1;i<=H;i++)mx_X=max(cntx[i],mx_X);
  for(int i=1;i<=W;i++)mx_Y=max(mx_Y,cnty[i]);
  
  vector<int> candidatex,candidatey;
  
  for(int i=1;i<=H;i++){
    if(cntx[i]==mx_X)candidatex.push_back(i);
  }
  for(int i=1;i<=W;i++){
    if(cnty[i]==mx_Y)candidatey.push_back(i);
  }
  
  int ans=mx_X + mx_Y -1;
  bool flag=0;
  for(int x:candidatex){
    for(int y:candidatey){
      if(flag)break;
      if(st.find(myhash(x,y))==st.end()){
        ans++;
        flag=1;
        break;
      }
    }
  }
  cout<<ans<<"\n";
}  

Measured memory_bytes: 23228
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli sum[1000005] = {};
lli basep[1000005] = {};

lli mod = 1e9 + 7;
lli base = 97;

lli dp[5005][5005] = {};

  string s;
  int n;
lli calc(int i,int j){
  if(s[i]!=s[j])return 0;
  if(j==n) return 0;
  lli&ret = dp[i][j];
  if(ret)return ret;
  lli tmp = calc(i+1,j+1);
  if(i + tmp >= j){
    ret = tmp;
  }else{
    ret = tmp + 1;
  }
  return ret;
}
int main() {
  cin >> n >> s;
  basep[0] = 1;
  rep(i, n) {
    sum[i + 1] = (sum[i] * base + s[i] - 'a') % mod;
    basep[i + 1] = (basep[i] * base) % mod;
  }
  lli ans = 0;
  rep(i,n)rep(j,i){
    ans= max(calc(j,i),ans);
  }
  cout << ans << endl;

//   rep(i, n) {
//     rep(j, i) {
//       lli ma = i - j;
//
//       if (ans > ma)
//         break;
//       if (s[i] != s[j])
//         continue;
//       lli low = 0, high = ma;
//       while (high - low > 1) {
//         lli mid = (high + low) / 2;
//         lli h1 =
//             ((sum[i + mid + 1] - sum[i + 1] * basep[mid]) % mod + mod) % mod;
//         lli h2 =
//             ((sum[j + mid + 1] - sum[j + 1] * basep[mid]) % mod + mod) % mod;
//         if (h1 == h2) {
//           low = mid;
//         } else {
//           high = mid;
//         }
//       }
// //      cout << j << " " << i << " " << low << " " << high << endl;
//       ans = max(ans, high);
//     }
//   }
//   cout << ans << endl;
}


Measured memory_bytes: 199168
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll l,r,d;
  ll ans =0;
  cin >> l >> r >>  d;
  for(ll i=l;i<=r;i++){
    if(i%d==0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#import sys
#sys.setrecursionlimit(10**5)
MOD = 10**9+7

# input
N = int(input())
C = list(map(int, input().split()))
    
# process
C.sort(reverse=True)
ans = 0

if N == 1:
    ans = C[0]*2**N
else:
    for i in range(N):
        ans += C[i]*(2+i)

    ans *= 4**(N-1)

# output
print(ans%MOD)


Measured memory_bytes: 27108
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
	tmp = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
  var getResult = input => {

    console.log(input[0][0]+input[1][1]+input[2][2])
  }
  getResult(tmp)
	//出力

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define setbits                 __builtin_popcount
#define zerobits                __builtin_ctzll
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)               __gcd(a,b)
#define lcm(a, b)               ((a)*(b))/gcd(a,b)
#define watch(x)                cout << (#x) << " is " << (x) << endl
#define TEST_CASES()            ll t;cin>>t;while (t--)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll r;
    cin>>r;
    cout<<fixed<<setprecision(20)<<2*PI*r<<endl;


}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long w,h,a,b;
  cin >> w >> h >> a >> b;
  long long ans=(w*h)/2;
  cout << fixed << setprecision(10);
  if(a+a==w&&b+b==h){
    cout << ans << " 1" << endl;
  }
  else{
    if(w%2==0||h%2==0){
      cout << ans << " 0" << endl;
    }
    else{
      cout << ans << ".500000000 0" << endl;
    }
  }
}


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

int main(){
  long long n,m;
  cin>>n>>m;
  if(n>2&&m>2){
    cout<<(n-2)*(m-2)<<endl;
  }
  else if(n==2||m==2){
    cout<<0<<endl;
  }
  else if(n==1&&m==1){
    cout<<1<<endl;
  }
  else{
    cout<<n*m-2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int l;

        in >> l;

        double r = 1.0;

        out << (r * l * l * l) / 27;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
N, M = list(map(int, input().split()))
LRD = [list(map(int, input().split())) for _ in range(M)]

roots = [(i,0) for i in range(N+1)] #(root, distance_from_i_to_root)

def find_root(a, roots=roots):
  if roots[a][0] == a:
    return (a,0)
  else:
    r, d = find_root(roots[a][0])
    roots[a] = (r, roots[a][1] + d)
  return roots[a]

def unite(l, r, d, roots=roots):
  root_l, d_l = find_root(l)
  root_r, d_r = find_root(r)
  if root_l == root_r:
    if d_l == d + d_r:
      return True
    else:
      return False
  else:
    roots[root_l] = (root_r, d + d_r - d_l)
    return True

for l,r,d in LRD:
  if not unite(l,r,d):
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 65260
#include <stdio.h>

int main()
{
	int n, x, t;
	int count = 0;

	scanf("%d %d %d", &n, &x, &t);

	count = (n / x) *t;
	n %= x;

	if (n != 0)
		count += t;

	printf("%d\n", count);

	return 0;
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	ll n;
	cin >> n;

	ll a;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i==0) {
			a = i;
		}
	}
	ll b = n/a;
	int aa = (int)log10((double)a) + 1;
	int bb = (int)log10((double)b) + 1;
	cout << max(aa,bb) << "\n";

}


Measured memory_bytes: 512
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
 */
#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

void
printv(const vector<string> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

bool
cardcomp(const string a, const string b)
{
    return a.substr(1) < b.substr(1);
}

vector<string>
bubblesort(const vector<string> a)
{
    vector<string> work(a);

    bool flag = true;
    while (flag) {
        flag = false;
        for (auto it = work.rbegin(); it != work.rend() - 1; it++) {
            auto nit = next(it);
            if (cardcomp(*it, *nit)) {
                iter_swap(nit, it);
                flag = true;
            }
        }
    }
    return work;
}

vector<string>
selectionsort(const vector<string> a)
{
    vector<string> work(a);

    for (auto it1 = work.begin(); it1 != work.end(); it1++) {
        auto mini = it1;
        for (auto it2 = it1; it2 != work.end(); it2++) {
            if (cardcomp(*it2, *mini)) {
                mini = it2;
            }
        }
        if (it1 != mini) {
            iter_swap(it1, mini);
        }
    }
    return work;
}

void
checkstable(const vector<string> original, const vector<string> sorted)
{
    vector<string> work(original);
    stable_sort(work.begin(), work.end(), cardcomp);
    auto sit = sorted.begin();
    for (auto oit = work.begin(); oit != work.end(); oit++, sit++) {
        if (*oit != *sit) {
            cout << "Not stable" << endl;
            return;
        }
    }
    cout << "Stable" << endl;
}

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

    vector<string> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i]; cin.ignore();
    }

    vector<string> bubble = bubblesort(A);
    printv(bubble);
    checkstable(A, bubble);

    vector<string> selection = selectionsort(A);
    printv(selection);
    checkstable(A, selection);

    return 0;
}

Measured memory_bytes: 3164
#include<stdio.h>

int main(void){
    int a,b,c;
	char op;
	while(1){
	scanf("%d %c %d",&a,&op,&b);
		if(op == '+') c=a+b;
		else if(op == '-') c=a-b;
		else if(op == '*') c=a*b;
		else if(op == '/') c=a/b;
		else{break;}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cstdio>
const int mo=1000000007;
int a[105],f[105][105],g[105][105];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<n*2;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+n*2);
	f[1][1]=1;
	for (int i=n-1,m=1;i;i--){
		int p=a[i]!=a[i+1],q=a[n*2-i]!=a[n*2-i-1];
		q+=p;m+=2;
		for (int j=m;j;j--)
			for (int k=j;k;k--)
			if (j>q && k>p) g[j][k]=f[j][k]=f[j-q][k-p];
				else g[j][k]=f[j][k]=0;
		for (int j=1;j<=m;j++)
			for (int k=1;k<=j;k++)
			if (g[j][k]){
				int v=g[j][k];
				for (int l=1;l<k;l++) (f[j+1-k+l][l]+=v)%=mo;
				for (int l=j;l>k;l--) (f[j+1-l+k][k+1]+=v)%=mo;
			}
	}
	int ans=0;
	for (int i=1;i<n*2;i++)
		for (int j=1;j<=i;j++) (ans+=f[i][j])%=mo;
	printf("%d\n",ans);
}

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

int main(){
  int n;
  cin >> n;
  vector<int>vmc(n);
  for(int i=0; i<n; i++)cin >> vmc[i];
  for(int i=0; i<n; i++){
    int c;
    cin >> c;
    vmc[i]-=c;
  }
  sort(vmc.rbegin(), vmc.rend());
  int ret=0, i=0;
  while(i<n && vmc[i]>0){
    ret+=vmc[i];
    i++;
  }
  cout << ret;
  return 0;
}
  

Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  tlst = []
  qlst = []
  for _ in range(n):
    m, a, b = map(int, input().split())
    qlst.append((m, a, b))
    tlst.append(a)
    tlst.append(b)
    tlst.append(b - 1)
  tlst = sorted(list(set(tlst)))
  tlst.sort()
  tdic = {}
  for i, t in enumerate(tlst):
    tdic[t] = i
  lent = len(tlst)
  mp = [0] * lent
  for m, a, b in qlst:
    a, b = tdic[a], tdic[b]
    mp[a] += m
    mp[b] -= m
  
  acc = 0
  for i in range(lent):
    acc += mp[i]
    mp[i] = acc
    if acc > 150:
      print("NG")
      break
  else:
    print("OK")



Measured memory_bytes: 5636
import sys
a,b,k = map(int,input().split())
ans = []
if k > b-a:
    for i in range(a,b+1):
        print(i)
    sys.exit()
    
for i in range(k):
    t1 = a+i
    t2 = b-i
    ans.append(t1)
    ans.append(t2)
A = list(set(ans))
A.sort()

for i in A:
    print(i)

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

int main(){
  int array[500][500],array2[500][500],h,w,ans=0;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>array[i][j];
      array2[i][j]=array[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i==h-1&&j==w-1){
        break;
      }
      if(array[i][j]%2){
        if(j==w-1){
          ans++;
          array[i+1][j]++;
        }else{
          ans++;
          array[i][j+1]++;
        }
      }
    }
  }
  cout<<ans<<endl;
   for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i==h-1&&j==w-1){
        break;
      }
      if(array2[i][j]%2){
        if(j==w-1){
          cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
          array2[i+1][j]++;
        }else{
          cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
          array2[i][j+1]++;
        }
      }
    }
   }
}

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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)

typedef pair<int, int> P;

const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

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

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	
	if (n % k == 0) cout << 0 << endl;
	else cout << 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int x, y;
    while (true){
        std::cin >> x;
        std::cin >> y;
        if(x == 0 && y == 0){
            break;
        }
        if (x < y){
            std::cout << x << " " << y << std::endl;
        }else{
            std::cout << y << " " << x << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
#include <functional>
//#include <Windows.h>
//#include "Library.h"
//#include "Math.h"
using namespace std;
typedef long long int ll; typedef pair <int, int> P; typedef pair<int, P> P1; typedef vector <int> vecint; typedef vector <vecint> dvecint; typedef vector <dvecint> ddvecint;
const int INF = 2000000000;
const double EPS = 10e-9;
vecint a;
ll mergesort(vecint &a)
{
	int n = a.size();
	if (n <= 1) return 0;
	ll res = 0;
	vecint b(a.begin(), a.begin() + n / 2);
	vecint c(a.begin() + n / 2, a.end());
	res += mergesort(b);
	res += mergesort(c);
	int ai = 0, bi = 0, ci = 0;
	while (ai < n)
	{
		if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci]))
		{
			a[ai++] = b[bi++];
		}
		else
		{
			a[ai++] = c[ci++];
			res += n / 2 - bi;
		}
	}
	return res;
}
int main()
{
	int n; cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << mergesort(a) << endl;
	return 0;
}

Measured memory_bytes: 5332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 100011;

int n, i, j, x, y, R, ans, best;
vector<int> list[maxN];
char s[maxN];
int tp[maxN];
bool on[maxN];

int down[maxN][2];

void dfs(int node, int root) {
    if (tp[node] == 0) on[node] = true;
    for (auto to : list[node])
        if (to != root)
            dfs(to, node), on[node] |= on[to];
}

void solve(int node, int root) {
    down[node][0] = 0;
    down[node][1] = (tp[node] == 0 ? -1 : 1);

    for (auto to : list[node]) {
        if (to == root) continue;
        solve(to, node);
        best = min(best, down[node][0] + down[to][1] - 1);
        best = min(best, down[node][1] + down[to][0] - 1);
        down[node][0] = min(down[node][0], down[to][0] + 
                                           (tp[node] == 0 ? -1 : 1) - 1);
        down[node][1] = min(down[node][1], down[to][1] +
                                           (tp[node] == 0 ? -1 : 1) - 1);
    }
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        scanf("%d%d\n", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    scanf("%s", s + 1);
    for (i = 1; i <= n; i++) 
        tp[i] = (s[i] == 'W' ? 0 : 1);

    for (i = 1; i <= n; i++)
        if (tp[i] == 0) 
            break;

    if (i > n) {
        printf("0");
        return 0;
    }

    R = i;
    dfs(R, 0);

    for (i = 1; i <= n; i++) {
        for (j = 0; j < list[i].size(); j++) {
            if (!on[list[i][j]]) {
                list[i][j] = list[i].back();
                list[i].pop_back();
                j--;
                continue;
            }
        }
    }

    for (i = 1; i <= n; i++) {
        if (!on[i]) continue;
        ans += list[i].size();
        tp[i] = ((tp[i] ^ list[i].size()) & 1);
        if (tp[i] == 0) ans++;
    }

    best = 0;
    solve(R, 0);

    printf("%d", ans + best);


    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 6;
typedef long long ll;
#define INF 0x3f3f3f3f;

int main(){
	int a, b;
	int x, y, z;
	int dp[6];
	cin>>a>>b;
	dp[0] = a + b;
	dp[1] = a - b;
	dp[2] = a * b;
	sort(dp, dp + 3);
	cout<<dp[2]<<endl;
	
	return 0;
}

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

int main(){
  string snake;
  int n,len;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> snake;
    len = snake.size();
    int ans = -1;
    if(snake[0] == '>' && snake[1] == '\''){
      int pos = 2;
      int turn = 0;
      int flag = 0;
      int count = 0;
      do{
	if(turn && snake[pos] == '=')count--;
	else if(snake[pos] == '=') count++;
	else if(snake[pos] == '#')turn = 1;
	else flag = 0;
	if(pos == 2 && count > 0)flag = 1;
	pos++;
      }while(pos < len-1);
      if(count == 0 && flag && snake[pos] == '~')ans = 0;
    }else if(snake[0] == '>' && snake[1] == '^'){
      int pos = 2;
      int flag = 1;
      do{
	if(snake[pos] != 'Q' || snake[pos+1] != '='){
	  flag = 0;
	  break;
	}
	pos += 2;
      }while(pos < len-2);
      if(flag && snake[pos] == '~' && snake[pos+1] == '~')ans = 1;
    }
    if(ans == 0)cout << 'A' << endl;
    else if(ans == 1)cout << 'B' << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
def euclid(a:int,b:int)->(int,int):
    #return x,y s.t ax + by = gcd(a,b)
    #a > b >= 0
    if b == 0:
        return 1,0
    x,y = euclid(b,a%b)
    return y,x - y*(a // b)

def inverse(a:int,mod:int)->int:
    #gcd(p,b) == 1
    if mod > a:
        n,x = euclid(mod,a)
    else:
        x,n = euclid(a,mod)
    return x

def devide_mod(a:int,b:int,mod:int)->int:
    #a // b
    x = inverse(b,mod)
    return  (a*x)%mod

mod = 10**9 + 7


def com_init(mx:int ,mod:int)->list:
    fac = [1]*mx
    inv = [1]*mx
    finv = [1]*mx
    for i in range(2,mx):
        fac[i] = fac[i - 1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    return fac,finv,inv

fac,finv ,inv = com_init(10**5,10**9 + 7)

def com(n:int, k:int):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod

def main():
    N, K = map(int,input().split())
    for i in range(1, K + 1 ):
        print(com(N - K + 1,i)*com(K - 1, i - 1)%mod)
    return


if __name__ == "__main__":
    main()

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

int main()
{
    int a, b, c, x, i, j, k, count=0;
    cin >> a >> b >> c >> x;
    for(i=0; i<=a; i++){
        for(j=0; j<=b; j++){
            for(k=0; k<= c; k++){
                if(500 * i + 100 * j + 50 * k == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    ll a[n];
    ll b[n];
    rep(i,0,n) cin >> a[i] >> b[i]; 
    ll ans = 0;
    rel(i,n,0){
        if((a[i]+ans) % b[i]==0) continue;
        ans += (b[i] - ((a[i]+ans) % b[i]));
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  char a,b;cin>>a>>b;

  if((a=='H'&&b=='D')||(a=='D'&&b=='H'))out('D')
  else out('H')

  return 0;
}


Measured memory_bytes: 256
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n,d;
    cin>>n>>d;
    ll c=0;
    f(i,n)
    {
        ll x,y;
        double ans;
        cin>>x>>y;
        x=x*x;
        y=y*y;
        ans=sqrt(x+y);
        if(ans<=d)
            c++;
    }
    cout<<c;
    return 0;
}

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

using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

    string s;
    cin >> s;

    size_t N = s.length();

    intmax_t res = 0;
    for (size_t bit = 0; bit < (1 << (N - 1)); ++bit) {
        intmax_t num = 0;
        for (size_t i = 0; i < N; ++i) {
            num = 10 * num + (s[i] - '0');
            if (bit & (1 << i)) {
                res += num;
                num = 0;
            }
        }
        res += num;
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    
    if m==-1 and f==-1 and r==-1:
        break
    
    else:
        if m==-1 or f==-1:
            print("F")
        
        else:
            if m+f>=80:
                print("A")
        
            if 65<=m+f<80:
                print("B")
        
            if 50<=m+f<65:
                print("C")
        
            if 30<=m+f<50:
                if r>=50:
                    print("C")
                else:
                    print("D")
    
            if m+f<30:
                print("F")
        
        


Measured memory_bytes: 5596
#include <iostream>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[7][7] = {
	{0, 0, 0, 0, 0, 0, 0},
	{0, 0, 3, 5, 2, 4, 0},
	{0, 4, 0, 1, 6, 0, 3},
	{0, 2, 6, 0, 0, 1, 5},
	{0, 5, 1, 0, 0, 6, 2},
	{0, 3, 0, 6, 1, 0, 4},
	{0, 0, 4, 2, 5, 3, 0}
};

llint get(llint t, llint f, llint r)
{
	llint ret = f;
	for(int i = 0; i < r; i++) ret = a[t][ret];
	return ret;
}

llint h[205][205];
llint c[205][205];
llint cnt[15];
llint dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		
		for(int x = 0; x < 205; x++){
			for(int y = 0; y < 205; y++){
				h[x][y] = 0, c[x][y] = 0;
			}
		}
		
		llint t, f;
		for(int q = 1; q <= n; q++){
			cin >> t >> f;
			
			llint x = 102, y = 102;
			while(1){
				llint mx = 0, dir;
				for(int i = 0; i < 4; i++){
					llint nx = x + dx[i], ny = y + dy[i], front = get(t, f, i);
					if(h[x][y] <= h[nx][ny]) continue;
					if(front < 4) continue;
					if(mx < front){
						mx = front;
						dir = i;
					}
				}
				if(mx == 0) break;
				
				llint nt = get(t, f, (dir+2)%4), nf = f;
				if(dir % 4 == 0) nf = t;
				else if(dir % 4 == 2) nf = 7 - t;
				
				f = nf, t = nt;
				x += dx[dir], y += dy[dir];
				
				//cout << x << " " << y << " " << t << " " << f << endl;
			}
			//cout << "*" << endl;
			h[x][y]++;
			c[x][y] = t;
		}
		
		for(int i = 1; i <= 6; i++) cnt[i] = 0;
		for(int x = 0; x < 205; x++){
			for(int y = 0; y < 205; y++){
				cnt[c[x][y]]++;
			}
		}
		for(int i = 1; i <= 6; i++){
			cout << cnt[i];
			if(i < 6) cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3756
from collections import defaultdict

N,K,Q = map(int, input().split())

dic = defaultdict(lambda:0)
for _ in range(Q):
  dic[int(input())] += 1

for i in range(1,N+1):
  if K + dic[i] - Q > 0:
    print('Yes')
  else:
    print('No')

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int n;
    cin >> n;
    ll A[n],B[n];
    FOR(i,0,n)
        cin >> A[i] >> B[i];
    ll C[n];
    ll cc=-(accumulate(B,B+n,0LL));

    FOR(i,0,n)
        C[i]=A[i]+B[i];
    sort(C,C+n);
    reverse(C,C+n);

    FOR(i,0,n){
        if(i%2==0)
            cc+=C[i];
    }

    cout << cc << endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec.at(i);
  }
  
  int count =0;
  for (int p=0;p<n-2;p++){
    int P = vec.at(p);
    for(int q=p+1;q<n-1;q++){
      int Q = vec.at(q);
      for(int r=q+1;r<n;r++){
        
        
        int R = vec.at(r);
        if(vec.at(p)==vec.at(q) || vec.at(q)==vec.at(r) || vec.at(r)==vec.at(p)){
          continue;
        }
        else if(P<Q+R && Q<R+P && R < Q+P){
          count++;
        }
      }
    }
  }
  cout << count << endl; 
}


Measured memory_bytes: 3644
using System;
using System.Linq;

class A {
    static int[] Haiku = {5, 5, 7};

    public static void Main() {
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Array.Sort(a);
        Console.WriteLine(Haiku.SequenceEqual(a) ? "YES" : "NO");
    }
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int d, t, s;
    cin >> d >> t >> s;
    cout << (d <= t * s ? "Yes" : "No") << newl; 

    return 0;
}

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

#define INF (1<<29)
#define MAX_V 202

struct edge{
	int to,cap,cost,rev;
	edge(int a,int b,int c,int d):to(a),cap(b),cost(c),rev(d){}
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back(edge(to,cap,cost,G[to].size()));
	G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
	int res=0;
	while(f>0){
		fill(dist,dist+V,INF);
		dist[s]=0;
		bool update=true;
		while(update){
			update=false;
			for(int v=0;v<V;v++){
				if(dist[v]==INF)continue;
				for(int i=0;i<G[v].size();i++){
					edge &e=G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.cost){
						dist[e.to]=dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						update=true;
					}
				}
			}
		}
		if(dist[t]==INF)return -1;
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*dist[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}

int main(){
	int n,p[100];
	cin>>n;
	for(int i=0;i<n;i++)cin>>p[i];
	for(int i=0;i<n;i++){
		add_edge(0,1+i,1,0);
		add_edge(1+n+i,1+2*n,1,0);
		for(int j=0;j<n;j++){
			if(p[i]!=j+1){
				add_edge(1+i,n+1+j,1,p[i]*abs(i-j));
			}
		}
	}
	V=2*n+2;
	cout<<min_cost_flow(0,1+2*n,n)<<endl;
	return 0;
}

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

int main()
{
    int a[3][3];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) cin >> a[i][j];
    int n;
    cin >> n;
    int b[n];
    set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        s.insert(b[i]);
    }
    bool ok[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            ok[i][j] = s.count(a[i][j]);
        }
    }
    string ans = "No";
    for (int i = 0; i < 3; i++) {
        if (ok[i][0] && ok[i][1] && ok[i][2]) ans = "Yes";
        if (ok[0][i] && ok[1][i] && ok[2][i]) ans = "Yes";
    }
    if (ok[0][0] && ok[1][1] && ok[2][2]) ans = "Yes";
    if (ok[0][2] && ok[1][1] && ok[2][0]) ans = "Yes";
    cout << ans << "\n";
}


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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  if (s[0] == '1') ++cnt;
  if (s[1] == '1') ++cnt;
  if (s[2] == '1') ++cnt;
  cout << cnt << endl;
}


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

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    vector<int> a(5);
    cin >> n;
    rep(i, 5) cin >> a[i];

    int mini = *min_element(ALL(a));

    cout << (n + mini - 1) / mini + 4 << endl;

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int count = 0;

    for(int i=0; i<N; i++)
    {
        int l,r;
        cin >> l >> r;
        count += r-l+1;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
int gcd(int a , int b){ return b ? gcd(b,a%b) : a;}
signed main(){
  int n,tmp;
  cin>>n;
  vector<pair<int,int>>inp(n);
  f(i,n)cin>>inp[i].first>>inp[i].second;
  f(i,n){
    tmp=inp[i].first;
    inp[i].first=inp[i].second;
    inp[i].second=tmp;
  }
  sort(inp.begin(),inp.end());
  for(int i=1;i<n;i++)inp[i].second+=inp[i-1].second;
  f(i,n)if(inp[i].first<inp[i].second){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3328