akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

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

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
vector<ll> vec(55);
ll num(ll n){
    if(n == 0)return vec[n] = 1;
    else if (vec[n] != 0)return vec[n];
    else return vec[n] = 3 + 2 * num(n - 1);
}
ll solve(ll n,ll m){//Pの数
    if(n == 0){
        if(m == 0)return 0;
        else return 1;
    }
    else{
        if(m <= 1)return 0;
        else if(m <= 1 + vec[n - 1])return solve(n - 1,m - 1);
        else if(m == 2 + vec[n - 1])return 1 + solve(n - 1,vec[n - 1]);
        else if(m != vec[n])return 1 + solve(n - 1,vec[n - 1]) + solve(n - 1,m - vec[n - 1] - 2);
        else{
            return 1 + 2 * solve(n - 1,vec[n - 1]);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    num(N + 1);
    cout << solve(N,M) << endl;
    //vecout(vec);
}
//B + (-1) + P + (-1) + B

Measured memory_bytes: 3612
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int a, b;
	a = b = 0;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == 'A')a++;
		else if (s[i] == 'B')b++;
	}
	if (a==3 || b==3)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>


int main() {
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	long double length; std::cin >> length;
	std::cout << std::setprecision(15) << std::fixed << (length / 3) * (length / 3) * (length / 3) << std::endl;
}

Measured memory_bytes: 1016
import sys
N, X = map(int,input().split())
x = 0
L = list(map(int,input().split()))
count = 1
for i in range(N):
    if x + L[i] <= X:
        count = count + 1
        x = x + L[i]
    else:
        print(count)
        sys.exit()
print(count)


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

using namespace std;

typedef pair<string, int> PI;
typedef map<int, int> MI;

int main()
{
    int n, p;

    string s;

    vector<PI> vec; // vector pair

    map<string, MI> mp; // 2D map

    cin >> n;

    for(int i=1; i<=n; i++)
    {
        cin >> s >> p;

        mp[s][p] = i; // tracking key and value

        vec.push_back(make_pair(s,p));
    }

    // custom sorting algorithm with key and value comparison

    sort(vec.begin(),vec.end(),[](pair<string,int>& e1, pair<string, int>& e2)
    {

        return (e1.first < e2.first) || ((e1.first==e2.first)&&(e1.second > e2.second));

    });

    string t;

    int f;

    for(auto i: vec)
    {
        t = (i).first;

       f = (i).second;

        cout << mp[t][f] << endl;

    }

    return 0;
}


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

int main(){

    int n;
    cin >> n;

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

    vector<int> d(n+1);
    for(int i = 0; i < n ; i++){
        d[i] = abs(v[i+1] - v[i]);
    }
    d[n] = abs(v[n]);

    /*
    for(int i = 0; i <= n; i++){
        cout << d[i] << " ";
    }
    cout << endl;
    */

    long long sum = accumulate(d.begin(), d.end(), 0);
    for(int i = 1; i < n; i++){
        cout << sum - d[i] - d[i-1] + abs(v[i+1] - v[i-1]) << endl;
    }
    cout << sum - d[n] - d[n-1] + abs(v[n-1]) << endl;





}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, P; cin >> N >> P;
    int odd = 0;
    rep(i,N) {
        int a; cin >> a;
        if (a % 2 == 1) odd++;
    }
    ll res = 0;
    res = (odd == 0) ? ((P == 1) ? 0 : 1LL << N) : 1LL << N-1;
    cout << res << endl;
}


Measured memory_bytes: 3556
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
    long long n;
    cin>>n;
    long long t=n%50;
    long long c=n/50;
    c+=49;
    cout<<"50"<<endl;
    for(int i=1;i<=50;i++){
        if(i<=(50-t)){
            cout<<c-t<<" ";
        }
        else {
            cout<<c+50-t<<" ";
        }
    }
    return 0;
}


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

#define max(a, b) (a)>(b)?(a):(b)

using namespace std;

int main(){
	int d, x, y, idx = 0, ans[21][14] = { 0 };
	int po[20][2];
	string input;
	cin >> d;
	cin >> x;
	for (int i = 0; i < x; i++){
		int p;
		char ch;
		cin >> ch >> p;
		if (ch == 'D'){
			po[idx][0] = p;
			po[idx++][1] = 1;
		}
	}
	cin >> y;
	for (int i = 0; i < y; i++){
		int p;
		string ch;
		cin >> ch >> p;
		if (ch[0] == 'D' && ch[1] == 'D'){
			po[idx][0] = p;
			po[idx++][1] = 2;
		}
	}

	for (int i = 1; i <= idx; i++){
		for (int j = 0; j <= d; j++){
			if (po[i - 1][1] <= j){
				ans[i][j] = max(ans[i - 1][j], ans[i - 1][j - po[i - 1][1]] + po[i - 1][0]);
			} else{
				ans[i][j] = ans[i - 1][j];
			}
		}
	}
	cout << ans[idx][d] << endl;
	return 0;
}

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

#define double long double
#define int long long
#define ALL(x) x.begin(),x.end()
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb(x) push_back(x)
#define eb emplace_back
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend()) 
#define mp(x, y) make_pair(x, y)
#define INF 1000000000
#define MOD 998244353 
#define F(i, a, n) for(i=a;i<n;i++)
#define SI(x) cin>>x
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z
#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<< "\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


int32_t main(void)
{
    FASTER;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int i, j;
    int x;
    SI(x);
    x = (x - 400)/200;
    SO(8-x);
    
    
    #ifdef LOCAL
    	cout<<endl<<endl<<"Time: "<<(float)clock()/CLOCKS_PER_SEC<<" seconds"<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main() {
	int A,B,C,X;
  cin>>A>>B>>C>>X;
  int res=0;
  for(int a=0;a<=A;++a){
    for(int b=0;b<=B;++b){
      for(int c=0;c<=C;++c){
        int total=500*a+100*b+50*c;
        if(total==X)res++;
      }
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

#define ll long long
using namespace std;

int main(){
    ll N, cnt = 0;
    ll a,b;
    cin >> N;
    vector <ll> A(N+1), B(N);
    for(int i = 0; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N; i++){
        if(A[i] <= B[i]){
            cnt += A[i];
            B[i] -= A[i];
            if(A[i+1] <= B[i]){
                cnt += A[i+1];
                A[i+1] = 0;
            }else{
                cnt += B[i];
                A[i+1] -= B[i];
            }
        }else{
            cnt += B[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
// AtCoder Grand Contest 012
// B - Splatter Painting

#include <cstdio>
#include <cstring>
#include <vector>
#define MAX_N 100000
#define MAX_Q 100000
#define MAX_D 10
using namespace std;
typedef long long int ll;


int N, M, Q;
vector<int> G[MAX_N];
int dp[MAX_D + 1][MAX_N];
int C[MAX_Q + 1];

int main() {

  int a, b, v, d;

  memset(dp, 0, sizeof(dp));
  scanf("%d%d", &N, &M);
  for (int j = 0; j < M; j++) {
    scanf("%d%d", &a, &b);
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  scanf("%d", &Q);
  C[0] = 0;
  for (int k = 1; k <= Q; k++) {
    scanf("%d%d%d", &v, &d, &C[k]);
    dp[d][v - 1] = max(dp[d][v - 1], k);
  }

  for (int l = MAX_D; l > 0; l--) {
    for (int i = 0; i < N; i++) {
      dp[l - 1][i] = max(dp[l - 1][i], dp[l][i]);
      for (int &to: G[i]) {
        dp[l - 1][to] = max(dp[l - 1][to], dp[l][i]);
      }
    }
  }

  for (int i = 0; i < N; i++) {
    printf("%d\n", C[dp[0][i]]);
  }

  return 0;

}




Measured memory_bytes: 11128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    long long s, c;
    cin >> s >> c;

    if(2 * s >= c){
        cout << c / 2 << endl;
        return 0;
    }

    long long ans = 0;
    c -= 2 * s;
    ans += s;
    ans += c / 4;

    cout << ans << endl;

}

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

int DP[20010][256];
int N, M;
int B[17];
int X[20010];
int intMax = 1000000000;

int solve() {
	
	for(int i = 0; i <= N; i++) for(int j = 0; j <= 255; j++) DP[i][j] = intMax;
	for (int m = 0; m < M; m++) {
		cin >> B[m];
	}
	for (int n = 1; n <= N; n++) {
		cin >> X[n];
	}
	DP[0][128] = 0;
	for (int n = 0; n < N; n++) {
		for (int i = 0; i <= 255; i++) {
			for (int m = 0; m < M; m++) {
				int c = min(255, max(i + B[m], 0));
				int s = X[n + 1] - c;
				s = s * s;
				DP[n + 1][c] = min(DP[n][i] + s, DP[n + 1][c]);
			}
		}
	}
	int ans = intMax;
	for(int i = 0; i <= 255; i++) {
		ans = min(ans, DP[N][i]) ;
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> M;
	while(N) {
		solve();
		cin >> N >> M;
	}
}



Measured memory_bytes: 23116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0041
{
    class Program
    {
        static void Main(string[] args)
        {
            var rStr = Console.ReadLine();

            long a = long.Parse(rStr.Split(' ')[0]);
            long b = long.Parse(rStr.Split(' ')[1]);

            if (a <= b)
            {
                Console.WriteLine(a);
            }
            else
            {
                Console.WriteLine(a - 1);
            }

        }
    }
}


Measured memory_bytes: 27020
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

x,n = I2()
if n != 0:
    p = Intl()
else:
    p = []
p.sort()
if not x in p:
    print(x)
else:
    b,e = 0,n-1
    r = []
    s = []
    for i in range(min(p)-1,max(p)+2):
        if i not in p:
            r.append(i)
            s.append(abs(x-i))
    print(r[s.index(min(s))])

Measured memory_bytes: 9256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	string s;
	int ans = 0, t = 0;
	cin >> s;
	bool z = 1;
	for (int i = 0; i < s.size(); ++i){
		if (z && s[i] == '1')
			t++;
		if (!z && s[i] == '0')
			t++;
		z = !z;
	}
	z = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (z && s[i] == '1')
			ans++;
		if (!z && s[i] == '0')
			ans++;
		z = !z;
	}
	cout << min(t, ans) << '\n';
	return 0;
}

Measured memory_bytes: 512
s = input()
t = input()
q = int(input())

ss, tt = [0], [0]
for i in range(len(s)):
    ss.append(ss[i] + (1 if s[i] == 'A' else 2))
for i in range(len(t)):
    tt.append(tt[i] + (1 if t[i] == 'A' else 2))

for i in range(q):
    a, b, c, d = map(int, input().split())
    s_score = (ss[b] - ss[a-1]) % 3
    t_score = (tt[d] - tt[c-1]) % 3
    print('YES' if s_score == t_score else 'NO')

Measured memory_bytes: 11588
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int M = 1010;

int main(){
    int m, n;
    while(cin >>m >>n && (n || m)){
        bool human[M] = {false};
        FOR(i, 1, m + 1) human[i] = true;

        int h = m, now = 1;
        FOR(i, 1, n + 1){
            string str; cin >>str;
            if(h == 1) continue;
            while(!human[now]){
                now++;
                if(now > m) now = 1;
            }
            if(i % 3 == 0 && i % 5 == 0){
                if(str != "FizzBuzz"){
                    human[now] = false;
                    h--;
                }
            } else if(i % 3 == 0){
                if(str != "Fizz"){
                    human[now] = false;
                    h--;
                }
            } else if(i % 5 == 0){
                if(str != "Buzz"){
                    human[now] = false;
                    h--;
                }
            } else{
                int tmpInt = atoi(str.c_str());
                if(tmpInt == 0 || i != tmpInt){
                    human[now] = false;
                    h--;
                }
            }
            now++;
        }
        stringstream ss;
        bool firFlg = true;
        REP(i, m + 1){
            if(human[i]){
                if(firFlg){
                    firFlg = false;
                    ss <<i;
                } else{
                    ss <<" " <<i;
                }
            }
        }
        cout <<ss.str() <<endl;
    }
    return 0;
}

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

using namespace std;

const int maxn=1e6+500;
int a[maxn];

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[n/2]-a[n/2-1];
	return 0;
} 

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, a, b;
  cin >> n >> a >> b;
  ll p = (n / (a + b)) * (a);
  p += min(n % (a + b), a);
  cout << p << '\n';
  return 0;
}


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int T;

ll a,b,c,d;
bool solve(){
	read(a);read(b);read(c);read(d);
	if(a<b || b>d)return false;
	if(c+1>=b) return true;
	ll cp = ((a-b)+b-c-1)%b,diff = d%b;
	ll cd = __gcd(diff,b);
	ll ub = b-c-1;
	ll minp = cp%cd;
	return (minp>=ub);
}

int main() {
	read(T);
	while(T--){
		if(solve()){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int n;

int main(){
    cin >> n;

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

    long long int min = 10000000000;
    long long int max = 0;

    for(int i=0;i<n;i++){
        if(min > A[i]) min = A[i];
        if(max < A[i]) max = A[i];
    }

    cout << max - min << endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e9)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}

int main()
{
  int a,b;
  cin>>a>>b;
  if(gcd(a,b) == a)cout<<a+b;
  else cout<<b-a;
  
  
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int N; cin >> N;
    VVI n(N,VI(26,0));
    REP(i,N){
        string s; cin >> s;
        for(char c : s) n[i][c-'a']++;
    }

    ll ans = 0;
    map<VI,int> m;
    REP(i,N){
        if(EXIST(m,n[i])){
            ans += m[n[i]];
            m[n[i]]++;
        }
        else m[n[i]] = 1;
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b,c; cin>>a>>b>>c;
  int ans = c-min(c, a-b);
  cout<<ans;
  

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	for sc.Scan() {
		s := strings.Split(sc.Text(), " ")
		H, _ := strconv.Atoi(s[0])
		W, _ := strconv.Atoi(s[1])

		if H == 0 && W == 0 {
			return
		}

		for h := 0; h < H; h++ {
			for w := 0; w < W; w++ {
				fmt.Print("#")
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1092
#include <iostream>

using namespace std;

int n,k,r,p,t[100005],i,rs,S;
string s,q;

char potentially(char c){
    if (c=='r') return 'p'; else
        if (c=='s') return 'r'; else
            return 's';
}

char antichar(char c)
{
    if (c=='r') return 's'; else
        if (c=='s') return 'p'; else
            if (c=='p') return 'p';
}

char anti(int ipk, int imk){
    char nextchr,prevchr;
    prevchr=q[imk];
    if (ipk>=s.size()) nextchr=antichar(prevchr); else nextchr=s[ipk];
    return nextchr;
    
}

int main() 
{
    cin>>n>>k;
    cin>>r>>S>>p;
    cin>>s;
    
    for (i=0; i<s.length(); i++)
    {
        if (i<k){
            if (s[i]=='r') rs+=p,q+='p'; else
                if (s[i]=='s') rs+=r,q+='r'; else rs+=S,q+='s';
        } else
        {
            if (q[i-k]!=potentially(s[i]))
            {
                if (s[i]=='r') rs+=p,q+='p'; else
                if (s[i]=='s') rs+=r,q+='r'; else rs+=S,q+='s';
            } else q+=anti(i+k,i-k);
        }
    }
    cout<<rs;
}

Measured memory_bytes: 640
X = int(input())

def soi(n,l):
  if n ==1:
    l.append(1)    
    return l
  else:
    for i in range(2,n+1):
      if n%i == 0:
        l.append(i)
        break
    soi(n//i,l)
    return l
  

for i in range(X,10**9,1):
  l = soi(i,[])
  #print(l)
  if (len(l)==2):
    print(i)
    break

Measured memory_bytes: 3064
n,m=map(int,input().split())
ans_e=0
ans_o=0
if n<=1:
  ans_e=0
if m<=1:
  ans_o=0
if n>=2:
  ans_e=n*(n-1)//2
if m>=2:
  ans_o=m*(m-1)//2
print(ans_e+ans_o)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef int ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n;ll d; ll x[1 << 17], y[1 << 17];
ll c[1000][1000];
ll ly[1000] = {};
vector<P> vv;
ll calc(ll i,ll mid) {
	ll co = 1 + (mid + i) / d;
	rep(aa, (int)vv.size()) {
		int j = vv[aa].first; int k = vv[aa].second;
		ll num = co;
		if (j < i)num--;
		if ((mid + i) % d < j)num--;
			if (num<=0) {
				return mod;
			}
			else {
				ll ad = (c[j][k] + num - 1) / num-1;
				ly[k] = max(ly[k], ad);
			}
	}
	ll ma = 0;
	rep(j, d) {
		ma = max(ma, ly[j]);
	}
	vector<ll> v;
	rep(j, d) {
		if (ma == ly[j]) {
			v.push_back(j);
		}
	}
	ll rest = 0;
	int llen = v.size();
	if (llen >= 2) {
		rest = v[llen - 1] - v[0];
		Rep(j, 1, llen) {
			rest = min(rest, v[j - 1] + d - v[j]);
		}
	}
	return rest + ma * d;
}
int main() {
	cin >> n >> d;
	rep(i, n) {
		cin >> x[i] >> y[i];
		c[x[i] % d][y[i] % d]++;
	}
	ll rang = 0;
	rep(i, d) {
		rep(j, d) {
			if (c[i][j]) {
				vv.push_back({ i,j });
				ll x = sqrt(c[i][j]);
				if (x*x != c[i][j])x++;
				rang=max(rang, x);
			}
		}
	}
	rang *= d;
	ll out = mod;
	rep(i, d) {
		ll le = rang-d-1; ll ri = rang;
		while (ri - le > 1) {
			fill(ly, ly + d, -1);
			ll mid = (ri + le) >> 1;
			ll y = calc(i, mid);
			if (y > mid) {
				le = mid; out = min(out, y);
			}
			else {
				ri = mid; out = min(out, mid);
			}
		}
		//out = min(out, max(le,calc(i, le)));
		//out = min(out, max(calc(i, ri),ri));
		//cout << le << endl;
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define int long long
long long c[55][55];
int a[55],fl[55],cnt[1<<18];
set<int>::iterator it;
signed main(){
	c[0][0]=1;
	for(int i=1;i<=50;++i){
		c[i][0]=1;
		for(int j=1;j<=i;++j)
			c[i][j]=c[i-1][j-1]+c[i-1][j];
	}
	int n,k,S,T;
	cin>>n>>k>>S>>T;
	for(int i=0;i<=50;++i)
		for(int j=1;j<=k;++j)
			c[i][j]+=c[i][j-1];
	for(int i=1;i<=n;++i)
		cin>>a[i],fl[i]=1;
	for(int i=0;i<18;++i){
		int bit1=(S>>i)&1,bit2=(T>>i)&1;
		if(bit1==1 && bit2==0) return cout<<0,0;
	}
	vector<int> vec;
	set<int> se;
	for(int i=1;i<=n;++i)
		if(((S&a[i])==S) && ((a[i]&T)==a[i]))vec.push_back(a[i]);
	//cout<<vec.size()<<endl;
	int ans=0,sum=0;
	for(int mask=0;mask<(1<<18);++mask){//容斥,至多i位不合法 
		int fl=0;se.clear();
		for(int i=0;i<18;++i)
			if(((mask>>i)&1) && ((S>>i)&1)==((T>>i)&1)){
				fl=1;break;
			}
		if(fl) continue;
		for(int i=0;i<vec.size();++i)
			cnt[vec[i]&mask]++,se.insert(vec[i]&mask);
		sum=0;
		for(it=se.begin();it!=se.end();++it)
			sum+=c[cnt[*it]][k]-1;
		for(int i=0;i<vec.size();++i)
			cnt[vec[i]&mask]=0;
		for(int i=0;i<18;++i)
			if((mask>>i)&1) sum=-sum;
		ans+=sum; 
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 5700
import java.util.*;
import java.io.*;
/**
 *  @author citizen11
 *  Problem C
 *  Cat Snuke and a Voyage
 */
public class Main {
    public static void main(String[] args) {
        Reader.init(System.in);
        try {
            int N = Reader.nextInt();
            int M = Reader.nextInt();
            int[][] pairs = new int[M][2];
            for (int i = 0; i < M; i++) {
                pairs[i][0] = Reader.nextInt();
                pairs[i][1] = Reader.nextInt();
            }
            solve(N, M, pairs);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    static class Island {
        public int number;
        public int distanceFromOne;

        public Island(int number, int distance) {
            this.number = number;
            this.distanceFromOne = distance;
        }
    }

    public static void solve(int N, int M, int[][] pairs) {
        Map<Integer, List<Integer>> graph = createGraph(N, M, pairs);
        Set<Integer> visited = new HashSet<>();
        Deque<Island> queue = new LinkedList<>();
        queue.add(new Island(1, 0));
        boolean isPossible = false;
        while (!queue.isEmpty()) {
            Island island = queue.poll();
            if (!visited.contains(island.number)) {
                if (island.number == N && island.distanceFromOne <= 2) {
                    isPossible = true;
                    break;
                }
                visited.add(island.number);
                if (island.distanceFromOne > 2) {
                    continue;
                }
                for (int v : graph.get(island.number)) {
                    int dist = island.distanceFromOne;
                    queue.add(new Island(v, dist + 1));
                }
            }
        }
        if (isPossible) {
            System.out.println("POSSIBLE");
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }

    private static Map<Integer, List<Integer>> createGraph(int N, int M, int[][] pairs) {
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            graph.put(i, new ArrayList<Integer>());
        }
        for (int i = 0; i < pairs.length; i++) {
            graph.get(pairs[i][0]).add(pairs[i][1]);
            graph.get(pairs[i][1]).add(pairs[i][0]);
        }
        return graph;
    }
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                   reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 110996
a,b = map(int,input().split())

def myoutput(ls):
    if len(ls)==0:
        print(" ")
    elif type(ls[0])==str:
        print(" ".join(ls))
    elif type(ls[0])==int:
        print(" ".join(map(str,ls)))
    else:
        print("Output Error")

from collections import defaultdict,Counter
# from math import gcd

# 拡張ユークリッド互除法
# gcd(a,b) と ax + by = gcd(a,b) の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        x -= (b // a) * y
        return g, x, y

if a==b:
    # 問題に合わせて出力を調整すべし
    print(0,1)
    exit()
else:
    g,x,y = egcd(a,b)
    myoutput([x,y])
    exit()


Measured memory_bytes: 5996
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll i, j;
    ll pKN = modpow(K, N, MOD);
    vll gk_v(K);
    vll pkn_v(K);
    for(i = 0; i < K; i++) {
        pkn_v[i] = modpow(i + 1, N, MOD);
    }
    ll ans = 0;
    for(i = K; i >= 1; i--) {
        ll nk = modpow((K / i), N, MOD);
        ll ne = i;
        while(1) {
            ne += i;
            if(ne > K) {
                break;
            }
            nk = (nk - gk_v[ne - 1] + MOD) % MOD;
        }
        gk_v[i - 1] = nk;
        ll ans_sub = (i * nk) % MOD;
        ans = (ans + ans_sub) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4400
#include <cstdio>
using namespace std;

int main() {
  int n; scanf("%d", &n);
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int temp; scanf("%d", &temp);
    for (int i = 0; i < 40; i++) {
      if (temp % 2 == 0) {
        temp /= 2;
        ans++;
      } else {
        break;
      }
    }
  }
  
  printf("%d", ans);
}

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

constexpr double eps = 1e-10;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    vector<string> name(n);
    vector<double> eff(n);
    for (int i = 0; i < n; ++i) {
      cin >> name[i];
      int p, a, b, c, d, e, f, s, m;
      cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      double t = a + b + c + m * (d + e);
      eff[i] = (f * s * m - p) / t;
    }
    vector<int> idx(n);
    iota(begin(idx), end(idx), 0);
    sort(begin(idx), end(idx), [&](int i, int j) {
      return abs(eff[i] - eff[j]) > eps ? eff[i] > eff[j] : name[i] < name[j];
    });
    for (int i : idx) {
      cout << name[i] << '\n';
    }
    cout << "#\n";
  }
}



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

int main()
{
        int n;
        while(cin>>n)
        {
            while(n>0)
            {
                  if(n%10 == 9){cout<<"Yes"<<endl;break;}
                  else{n = n/10;}
            }
            if(n==0){cout<<"No"<<endl;}
        }
        return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str,com,p;
	int q,a,b;

	cin>>str>>q;

	for (int i=0;i<q;i++){
		cin>>com>>a>>b;
		if(com=="print"){
			cout<<str.substr(a,b-a+1)<<endl;
		}
		else if(com=="reverse"){
			string T=str.substr(a,b-a+1);
			int n=T.size();
			for (int j=0;j<n;j++){
				str[j+a]=T[n-j-1];
			}
		}
		else if(com=="replace"){
			cin>>p;
			str=str.replace(a,b-a+1,p);
		}
	}

	return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
int main()
{
	while(1)
	{
		int i,s=-1,e,d[7]={10,27,3,17,11,19,9};
		for(i=0;i<72;i++)
		{
			char t; 
			if(scanf("%c",&t)==EOF)
				return 0;
			if(t=='1')
			{
				if(s<0)
					s=i;
				else
					e=i;
			}
		}
		for(i=0;i<7;i++)
		{
			if(e-s==d[i])
			{
				printf("%c\n",'A'+i);
				break;
			}
		}
		if(scanf("\n")==EOF)
				return 0;
	}
	return 0;
}

Measured memory_bytes: 548
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 700;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'o') ans += 100;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	ll sum[n+1];
	sum[0]=0;
	rep(i,n+1){
		if(i==0)continue;
		sum[i]=sum[i-1]+a[i-1];
	}
	map<ll,ll>m;
	rep(i,n+1){
		m[sum[i]]++;
	}
	ll ans =0;
	for(auto x:m){
		ans+=(x.second*(x.second-1))/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 15872
//In the Name of God
//Let Our Voices Echo
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
#define int long long 
int n,a[MAX],k=0,ans=0,f=0;
int32_t main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>a[i],k+=a[i],f+=a[i];
	k/=(n+1)*n/2;
	if (f%((n+1)*n/2)!=0) return cout<<"NO",0;
	for (int i=0;i<n;i++)
	{
		int p=(i+1)%n;
		int y=(a[i]-a[p]+k);
		if (y%n!=0 || y<0) return cout<<"NO",0;
		ans+=y/n;
	}
	if (ans!=k) cout<<"NO";
	else cout<<"YES";
	return 0;
}


Measured memory_bytes: 1152
N = int(input())
S = input()
dp = [0]*(N+1)
for i in S:
    if i == '.':
        dp[0] += 1
for i in range(1, N+1):
    if S[i-1] == '.':
        dp[i] = dp[i-1] - 1
    else:
        dp[i] = dp[i-1] + 1
print(min(dp))

Measured memory_bytes: 11240
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int Q,H,S,D;
    int N;
    cin>>Q>>H>>S>>D;
    cin>>N;
    
    long long tmp;
    long long sum;
    if(N>=2){
        tmp=min({8*Q,4*H,2*S,D});
        sum=N/2*tmp;
        if(N%2!=0){
            tmp=min({4*Q,2*H,S});
            sum+=tmp;
        }
    }else{
        tmp=min({4*Q,2*H,S});
        sum=tmp;
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
int main(){    
int i, j, n;    
char mark;    
char marks[4]={'S', 'H', 'C', 'D'};    
int num;    
bool cards[4][13]={false};    
scanf("%d ", &n);   
 for(i=0;i<n;i++){        
scanf("%c %d ", &mark, &num);        
for(j=0;j<4;j++){            
if(mark==marks[j]){                
cards[j][num-1]=true;                
break;            
}        
}    
}    
for(i=0;i<4;i++){        
for(j=0;j<13;j++){            
if(!cards[i][j]){                
printf("%c %d\n", marks[i], j+1);            
}        
}    
}    
return 0;
}


Measured memory_bytes: 2140
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    vector<int> a(9);
    for(auto &x : a){
        cin >> x;
    }
    int k = a[0] + a[4] + a[8];
    if(k == a[1] + a[6] + a[5] && k == a[2] + a[7] + a[3]){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    if(n%2==0){
      System.out.println(n*n/4);
    }else{
      System.out.println((n/2+1)*(n/2));
    }
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k;
  cin >> n >> k;
   vector<long long int> a(n);
  vector<long long int> f(n);
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.begin(),f.end());
  long long int ans = 0;
  long long int ans_max = 1e12;
  long long int ans_min = -1;
  long long int now = 5e10;
  long long int zero = 0;
  while(ans_max - 1 != ans_min){
    now = (ans_max + ans_min)/2;
    long long int k_count = 0;
    for(int i=0; i<n; i++){
      if(a[n-1-i]*f[i] > now){
        k_count += a[n-1-i] - now/f[i];
       // cout << a[n-i-1] << "と" << f[i] << "において" << "max" << now << "以内にするために" << a[n-1-i] - now/f[i] << "回の修業が必要" << endl;
      }
    }
    if(k >= k_count){
      ans_max = now;
    }
    if(k < k_count){
      ans_min = now;
    }
    //cout << ans_max << endl << ans_min << endl;
  }
  cout << ans_max << endl;
}

Measured memory_bytes: 3328
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    r,g,b = LI()
    s = r*100+g*10+b
    if s%4 == 0:
        print("YES")
    else:
        print("NO")
    return

#Solve
if __name__ == "__main__":
    solve()


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll f[200005], fi[200005];

void init(int V) {
    f[0] = 1;
    for (int i = 1; i <= V; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[V] = modpow(f[V], MOD - 2);
    for (int i = V; i > 0; i--) {
        fi[i - 1] = fi[i] * i % MOD;
    }
}

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

ll dp[3005][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, n;
    cin >> H >> W >> n;
    init(H + W);
    vector<int> idxs(n + 2), r(n + 2), c(n + 2);
    r[0] = 1;
    c[0] = 1;
    idxs[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> r[i] >> c[i];
        idxs[i] = i;
    }
    r[n + 1] = H;
    c[n + 1] = W;
    idxs[n + 1] = n + 1;
    sort(idxs.begin(), idxs.end(), [&](const int i1, const int i2){return r[i1] + c[i1] < r[i2] + c[i2];});

    dp[0][0] = 1;
    for (int ii = 0; ii < idxs.size(); ii++) {
        int i = idxs[ii];
        for (int jj = 0; jj < ii; jj++) {
            int j = idxs[jj];
            if (r[j] <= r[i] && c[j] <= c[i]) {
                (dp[i][(i == n + 1)] += dp[j][1] * comb(r[i] - r[j] + c[i] - c[j], r[i] - r[j]) % MOD) %= MOD;
                (dp[i][1 - (i == n + 1)] += dp[j][0] * comb(r[i] - r[j] + c[i] - c[j], r[i] - r[j]) % MOD) %= MOD;
            }
        }
    }
    cout << (dp[n + 1][0] + MOD - dp[n + 1][1]) % MOD << endl;
    return 0;
}

Measured memory_bytes: 3456
import sys

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


def sousa1():
	global count
	global l
	x_min=l.index(min(l))
	x_max=l.index(max(l))
	x_else = 0 if x_min+x_max==3 else 1 if x_min+x_max==2 else 2
	count+=l[x_max]-l[x_else]

	l[x_min]+=l[x_max]-l[x_else]
	l[x_else]=l[x_max]
	

def sousa1_2():
	global count
	global l
	x_min=l.index(min(l))
	x_max=l.index(max(l))
	x_else = 0 if x_min+x_max==3 else 1 if x_min+x_max==2 else 2

	count+=1
	l[x_else]+=1
	l[x_max]+=1

def sousa2():
	global count
	global l
	x_min=l.index(min(l))
	x_max=l.index(max(l))
	count+=(l[x_max]-l[x_min])/2
	l[x_min]=l[x_max]


def judge():
	x_min=l.index(min(l))
	x_max=l.index(max(l))
	x_else = 0 if x_min+x_max==3 else 1 if x_min+x_max==2 else 2
	if l[x_max]!=l[x_else]:
		return 0
	elif (l[x_max]-l[x_min])%2==0:
		return 1
	else:
		return 2

while not(l[0]==l[1] and l[1]==l[2] and l[0]==l[2]):
	hoge=judge()
	if hoge==0:
		sousa1()
	elif hoge==1:
		sousa2()
	else:
		sousa1_2()

print(int(count))


Measured memory_bytes: 3064
#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 popcount(int x)
{
    return __builtin_popcount(x);
}

// 再帰関数によって操作回数をカウント
int f(int x)
{
    if (x==0) return 0;
    return f(x%popcount(x))+1;
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n);
    rep(i, n) x[i] = s[i]-'0';
    int pc=0;
    rep(i, n) pc += x[i];
    vector<int> ans(n);
    // popcountが増える場合と減る場合で分けて考える
    rep(b, 2)
    {
        // 新しいpopcount
        int npc = pc;
        if (b==0) npc++; else npc--;
        // npcが０以下の場合の例外処理
        if (npc <= 0) continue;

        // 元のXに対して操作を行った結果を保持
        int r0 = 0;
        rep(i, n)
        {
            r0 = (r0*2)%npc;
            r0 += x[i];
        }
        // 下の桁から順にXiに対する操作結果を調べる．
        // 各桁ごとにk=2^n%npcを計算してr0と組み合わせて答えを算出．
        int k = 1;
        for (int i = n-1; i >= 0; --i)
        {
            if (x[i] == b)
            {
                int r = r0;
                if (b == 0) r = (r+k)%npc;
                else r = (r-k+npc)%npc;
                ans[i] = f(r) + 1;
            }
            k = (k*2)%npc;
        }
    }
    rep(i, n) cout << ans[i] << endl;

}

Measured memory_bytes: 5244
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int n;
	scanf("%d",&n);
	double s=0;
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		s+=1.0/t;
	}
	printf("%.9f",1.0/s);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef  long long ll;
int main(){
  ll n,x,ans,max,min;
  cin>>n>>x;
  max=min=ans=x;
  for(int i=1;i<n;i++){
    cin>>x;
    ans+=x;
    if(max<x) max=x;
    if(min>x) min=x;
  }
  cout<<min<<" "<<max<<" "<<ans<<"\n";
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int x, y, ac, bc, cc;
    cin >> x >> y >> ac >> bc >> cc;
    vector<int> a(ac), b(bc), c(cc);
    rep(i, ac) cin >> a[i];
    rep(i, bc) cin >> b[i];
    rep(i, cc) cin >> c[i];
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    sort(c.begin(), c.end(), greater<int>());
    vector<int> as(ac + 1), bs(bc + 1);
    rep(i, ac) as[i + 1] = as[i] + a[i];
    rep(i, bc) bs[i + 1] = bs[i] + b[i];

    ll ans = 0;
    int ci = 0, ai = 0, bi = 0;
    rep(i, x + y)
    {
        if (bi >= y || a[ai] > b[bi] && ai < x)
        {
            if (ci < cc && c[ci] > a[ai])
            {
                ans += c[ci];
                ci++;
            }
            else
            {
                ans += a[ai];
                ai++;
            }
        }
        else
        {
            if (ci < cc && c[ci] > b[bi])
            {
                ans += c[ci];
                ci++;
            }
            else
            {
                ans += b[bi];
                bi++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2176