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

int main() {
	// your code goes here
	int k;
	int a,b;
	int flag =0;
	cin>>k;
	cin>>a>>b;
	for(int i=a; i<=b; i++){
	    if(i%k ==0){
	        flag =1;
	        break;
	    }
	}
	if(flag == 1){
	    cout<<"OK"<<endl;
	}
	else{
	    cout<<"NG"<<endl;
	}
	return 0;
}


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

int main() {
    string str;

    while(1){
        cin >> str;
        if(str == "0") break;
        
        int a=0,b=0;
        for(int i=0;i<str.length();i++){
            a = str[i] - '0';
            b += a;
        }
        cout << b << endl;
    }
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u)
    {
        cout << max(a - 1ll, 0ll) << " " << b << endl;
    }
    else if (u == t)
    {
        cout << a << " " << max(b - 1ll, 0ll) << endl;
    }
    else
    {
        cout << a << " " << b << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c[4], d[4];
  scanf("%s", c);
  scanf("%s", d);
  int ans=0;
  for(int i=0; i<3; i++) 
  	if(c[i]==d[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vvi vector<vi>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const ll inf=0x3f3f3f3f3f3f3f3f;
void print(vi v){
	ll n = v.size();
	for(ll i = 0; i < n; i++)
	    cout<<v[i]<<" ";
	cout<<endl;
}
ll power(ll a, ll b){
	ll res = 1;
	while(b != 0) {
		if(b & 1)
		  res *= a;
		a = a * a;
		b /= 2;
	}
	return res;
}
int main() {
    SPEED;
    ll x;
    cin>>x;
    if(x >= 30LL) {
    	cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n+1);
	vector<ll> pref(n+1);
	for (int q = 1; q <= n; q++)
	{
		cin >> a[q];
		pref[q] = pref[q-1] + a[q];
	}
	ll dp[n+1][n+1];
	for (int q = 1; q <= n; q++)
	{
		dp[q][q] = a[q];
	}
	for (int q = 2; q <= n; q++)
	{
		for (int w = 1; w+q-1<= n; w++)
		{
			dp[w][w+q-1] = max(a[w] + pref[w+q-1] - pref[w] - dp[w+1][w+q-1], a[w+q-1] + pref[w+q-2] - pref[w-1] - dp[w][w+q-2]);
		}
	}
	cout << (2 * dp[1][n] - pref[n]) << "\n";
	return 0;
}


Measured memory_bytes: 70400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	int ok = p, ng = n;
	while(ng - ok > 0){
		int mid = (ok + ng + 1) / 2;
		ll cost = 0;
		rep(i,n){
			if(i < p-1 || mid-1 <= i) cost += m;
			else{
				if(a[mid-1] + m < a[i]){
					cost = -1;
					break;
				}
				cost += (a[mid-1] + m) - a[i];
			}
		}
		if(cost < m*v) ng = mid - 1;
		else ok = mid;
	}
	cout << ok << endl;
	return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    ll k;
    cin >> s >> k;
    ll ans = 0;
    ll start = 0;
    ll end = s.size() - 1;
    bool d = 0;
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[0] != s[i])
        {
            d = 1;
            break;
        }
    }
    if (!d)
    {
        cout << (s.size() * k) / 2;
        return 0;
    }
    ll f = 0;
    ll b = 0;
    ll t = 0;
    if (s[0] == s[s.size() - 1])
    {
        while (s[start] == s[0])
        {
            f++;
            start++;
        }
        while (s[end] == s[s.size() - 1])
        {
            b++;
            end--;
        }
        t = b + f;
    }

    for (ll i = start; i <= end; i++)
    {
        ll count = 0;
        ll j = i;
        while (j < s.size() && s[i] == s[j])
        {
            count++;
            j++;
        }
        ans += count / 2;
        i = j - 1;
    }
    cout << ans * k + f / 2 + b / 2 + (k >= 2 ? ((t / 2) * (k - 1)) : 0) << endl;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, K;
std::vector< PII > p;

int main() {
    std::cin >> N >> K;
    std::map<int,int> map;

    REP(i, N) {
        int A;
        std::cin >> A;

        if(map.count(A) == 0) map[A] = 1;
        else map[A] = map[A] + 1;
    }

    p.reserve(map.size());
    EACH(it, map) {
        p.push_back(std::make_pair(it->second, it->first));
    }
    SORT(p);

    int l = p.size()-K;
    if(l <= 0) {
        std::cout << 0 << std::endl;
    } else {
        LL ans = 0;
        REP(i, l) {
            ans += p[i].first;
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 11136
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>v(60, 0);
	rep(i, N) {
		int A;
		cin >> A;
		rep(j, 60) {
			v[j] += A % 2;
			A /= 2;
		}
	}
	int ans = 0;
	rep(i, 60) {
		int num = v[i] * (N - v[i]);
		rep(j, i) {
			num *= 2;
			num %= MOD;
		}
		ans += num;
		ans %= MOD;
	}
	cout << ans;
}

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

using namespace std;

long long solveKnapsack(vector<int> &weights, vector<int> &profits, int capacity) {
    // basic checks
    if (capacity <= 0 || profits.empty() || weights.size() != profits.size()) {
      return 0;
    }

    int n = profits.size();
    vector<vector<long long >> dp(n, vector<long long >(capacity + 1));

    // populate the capacity=0 columns, with '0' capacity we have '0' profit
    for (int i = 0; i < n; i++) {
      dp[i][0] = 0;
    }

    // if we have only one weight, we will take it if it is not more than the capacity
    for (int c = 0; c <= capacity; c++) {
      if (weights[0] <= c) {
        dp[0][c] = profits[0];
      }
    }

    // process all sub-arrays for all the capacities
    for (int i = 1; i < n; i++) {
      for (int c = 1; c <= capacity; c++) {
        long long  profit1 = 0, profit2 = 0;
        // include the item, if it is not more than the capacity
        if (weights[i] <= c) {
          profit1 = profits[i] + dp[i - 1][c - weights[i]];
        }
        // exclude the item
        profit2 = dp[i - 1][c];
        // take maximum
        dp[i][c] = max(profit1, profit2);
      }
    }

    // maximum profit will be at the bottom-right corner.
    return dp[n - 1][capacity];
  }

int main(){
	
  int N, W;
  cin >> N >> W;
  
  vector<int> v(N);
  vector<int> w(N);
  
  for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
  
 // vector<vector<long long>> memo(N, vector<long longa>(W+1, 0));
  long long res = solveKnapsack(w, v, W);
  cout << res << endl; 
  
}
  


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

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

  int west = 0, east = 0;
  for (int i = 0; i < n; i ++) {
    if (s.at(i) == 'E') east ++;
  }

  int ans = east;
  for (int i = 0; i < n; i ++) {
    if (s.at(i) == 'E') east --;
    int tmp = west + east;
    ans = min(ans, tmp);
    if (s.at(i) == 'W') west ++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
set <int> st;
int main(){
    long long n , a[200001];
    cin >> n;
    for(int i = 0; i < n; i++){
     cin >> a[i];  
     st.insert(a[i]);
    }
    if(n > st.size()){
     cout << "NO";   
    }
    else {
     cout << "YES";   
    }
 return 0;   
}

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

const long long int DENOMI = 1000000007;

int main()
{
	long long int n, m;
	cin >> n >> m;
	if(abs(n - m) > 1){
		cout << 0 << endl;
	}else{
		long long int a = 1, b = 1;
		for(auto i = 2; i <= n; ++i){
			a = a * i % DENOMI;
		}
		for(auto i = 2; i <= m; ++i){
			b = b * i % DENOMI;
		}
		cout << a * b % DENOMI * (n == m ? 2 : 1) % DENOMI << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef long long int ll;

int main()
{	
	priority_queue<ll> q;
	ll n,m; cin>>n>>m; for(ll i=0;i<n;i++){ ll x; cin>>x; q.push(x);}

	while(m>0) {
		ll x = q.top(); q.pop();
		x /= 2;
		q.push(x);
      	m--;
	}

	ll s=0; 
	while(!q.empty()) {
		s += q.top(); q.pop();
	}

	cout<<s<<endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;
	ll n , k ;
	cin>>n>>k ;
	ll arr[n];
	long double sum=0;
	for(ll i=0;i<n;i++)cin>>arr[i];
	for(ll i=0;i<k;i++){
		sum+=(arr[i]*(arr[i]+1))/(2*(long double )arr[i]);
	}
	long double mx=sum;
	for(ll i=k;i<n;i++){
		sum+=(arr[i]*(arr[i]+1))/(2*(long double )arr[i]);
		sum-=(arr[i-k]*(arr[i-k]+1))/(2*(long double )arr[i-k]);
		mx=max(mx,sum);
	}
	cout<<fixed<<setprecision(15)<<mx<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void bfs(vector<int>&sign,vector<vector<int>>&v,vector<int>&vis,int i)
{
 queue<int> q;
 q.push(i);
 while(!q.empty())
 {
 	int top =q.front();
 	q.pop();
 	vis[top]=1;
 	for(int j=0;j<(int)v[top].size();j++)
 	{
 		if(!vis[v[top][j]])
 		{
 			sign[v[top][j]]=top;
 			vis[v[top][j]]=1;
 			q.push(v[top][j]);
 		}
 	}
 }
}
int main() {
  int n,m;
  cin>>n>>m;
  vector<int> sign(n+1,0);
  vector<vector<int>> v(n+1);
  for(int i=0;i<m;i++)
  {
  	int a,b;
  	cin>>a>>b;
  	v[a].push_back(b);
  	v[b].push_back(a);
  }
  vector<int> vis(n+1,0);
  bfs(sign,v,vis,1);
  for(int i=2;i<=n;i++)
  {
  	if(sign[i]==0)
  	{
  		cout<<"No"<<endl;
  		return 0;
  	}
  }
  cout<<"Yes"<<endl;
  for(int i=2;i<=n;i++)
  cout<<sign[i]<<endl;
  return 0;
}

Measured memory_bytes: 10664
#include<stdio.h>

int partition(int *A, int p, int r){
  int i, j, a, x;

  a = A[r];
  i = p - 1;

  for(j = p; j < r; j++){
    if(A[j] <= a){
      i++;

      x = A[i];
      A[i] = A[j];
      A[j] = x;
    }
  }

  x = A[i + 1];
  A[i + 1] = A[r];
  A[r] = x;

  return i + 1;
}

int main(){
  int A[100000];
  int n, i, j;

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  j = partition(A, 0, n - 1);

  for(i = 0; i < j; i++) printf("%d ",A[i]);

  printf("[%d] ",A[j]);

  for(i = j + 1; i < n; i++){
    printf("%d",A[i]);
    if(i != n - 1) printf(" ");
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


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

  int h,w;
  static const int size = 50;
  char bomb[size+2][size+2];
  int cnt[size+2][size+2] = {};
  string S;
  cin >> h >> w;
  REP(i,h){
      cin >> S;
      REP(j,S.size()){
      bomb[i+1][j+1] = S[j];
      if (S[j]=='#'){
        REP(k,8){
            cnt[i+1+DX[k]][j+1+DY[k]]++;
        }
      }
      }
  }
  REP(i,h){
      REP(j,w){
        if (bomb[i+1][j+1] == '#'){
            cout << '#';
        }else{
            cout << cnt[i+1][j+1];
        }
      }
      cout << endl;
  }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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

int main(void){
    int n, m;
    int count = 0;
    cin >> n >> m;
    int a, b;
    int last = -1;
    vector<pair<int, int>> pa(m);
    FOR(i,1,m){
        cin >> a >> b;
        pa[i - 1].first = b;
        pa[i - 1].second = a;
    }
    sort(pa.begin(), pa.end());
    FOR(i,0,m-1){
        if(pa[i].first>=last&&pa[i].second<last){

        }else{
            count++;
            last = pa[i].first;
        }
    }

    cout << count << endl;
}

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

typedef struct {
	int P, Y, tmp1, tmp2;
} s;

int compare1(const void *x, const void *y)
{
	return ((s*)x)->Y - ((s*)y)->Y;
}

int compare2(const void *x, const void *y)
{
	return ((s*)x)->tmp1 - ((s*)y)->tmp1;
}

int main(void)
{
	int N, M, P, Y, tmp2[100000] = {0}, i;
	s tmp1[100000];
	scanf("%d%d", &N, &M);
	for (i = 0; i < M; ++i) {
		scanf("%d%d", &tmp1[i].P, &tmp1[i].Y);
		tmp1[i].tmp1 = i;
	}
	qsort(tmp1, M, sizeof(s), compare1);
	for (i = 0; i < M; ++i) {
		++tmp2[tmp1[i].P - 1];
		tmp1[i].tmp2 = tmp2[tmp1[i].P - 1];
	}
	qsort(tmp1, M, sizeof(s), compare2);
	for (i = 0; i < M; ++i) printf("%06d%06d\n", tmp1[i].P, tmp1[i].tmp2);
	return 0;
}

Measured memory_bytes: 4972
#include <iostream>

int main() {
    while(true) {
        int n{}, x{}, count{};
        std::cin >> n >> x;
        if((n|x) == 0) break;
        for(auto i=1; i<=n && x>=(3*i+3); i++) {
            for(auto j=i+1; j<=n && x>=(i+2*j+1); j++) {
                for(auto k=j+1; k<=n; k++) {
                    if((i+j+k) != x) continue;
                    count++;
                    break;
                }
            }
        }
        std::cout << count << std::endl;
    }
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#define rep(i,n) for (int i=0; i<(n);i++)
using namespace std;
using ll = long long;

ll choose2(ll n){
    return n*(n-1)/2;
}

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

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> cnt(n);
    rep(i,n) cnt[a[i]]++;

    ll sum = 0;
    rep(i,n){
        sum += choose2(cnt[i]); 
    }

    ll anssum;
    rep(i,n){
        anssum = sum;
        if (cnt[a[i]] > 1){
         anssum = sum - cnt[a[i]] + 1;
        }
        cout << anssum << "\n";
    }
}


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

using namespace std;

int main() {
    string N;
    vector<string> vec;
    cin >> N;
    
    for (int i = 0; i < N.size(); ++i) {
        if (N[i] == '0'){
            vec.push_back("0");
        } else if (N[i] == '1') {
            vec.push_back("1");
        } else if (vec.size() > 0){
            vec.pop_back();
        } else {
            // スルー
        }

    }

    for (int j = 0; j < vec.size(); ++j) {
        cout << vec[j];
    }

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let x: i32 = read();
    let a: i32 = read();
    let b: i32 = read();
    if abs(x-a) < abs(x-b) {
        println!("A");
    } else {
        println!("B");
    }
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    cin >> N;
    ll P = 1;
    rep(i,N){
        P *= i+1;
        P %= mod;
    }
    cout << P << endl;
}

Measured memory_bytes: 384
import copy
import random
import time


memo = {}
def down(d, last, c):
    result = 0
    if d in memo:
        return memo[d]
    for i in range(26):
        result += c[i] * (d - last[i])
    memo[d] = result
    return result


def calc_score_of_the_day(S, d, t, last, C):
    return S[d][t] - down(d+1, last, C) + C[t] * (d+1 - last[t])


def main():
    start = time.time()
    D = int(input())
    C = [int(c) for c in input().split()]

    S = [0] * D

    for d in range(D):
        S[d] = [int(s) for s in input().split()]

    last = [0] * 26
    scores = [float('-inf')] * D

    result = 0
    T = [0] * D
    for d in range(D):
        next_t = 0
        score = float('-inf')
        for t in range(26):
            s = calc_score_of_the_day(S, d, t, last, C)
            if s > score:
                score = s
                next_t = t
        last[next_t] = d + 1
        result += score
        scores[d] = result
        T[d] = next_t + 1


    while time.time() - start < 1.9:
        result = scores[D-1]
        change_date = random.randint(0, D-1)
        change_from = T[change_date]
        change_to = random.randint(1, 26)
        delta = result - scores[change_date-1] if change_date > 0 else result

        if change_from == change_to:
            continue

        delta_to = 0
        last_of_the_day = [t if t <=change_date else 0 for t in last]
        copied_scores = copy.copy(scores)
        copied_T = copy.copy(T)
        for d in range(change_date, D):
            next_t = 0
            score = float('-inf')
            for t in range(26):
                s = calc_score_of_the_day(S, d, t, last_of_the_day, C)
                if s > score:
                    score = s
                    next_t = t
            last_of_the_day[next_t] = d + 1
            delta_to += score
            copied_scores[d] = copied_scores[d-1] + delta_to
            copied_T[d] = next_t + 1
        if delta_to >= delta:
            scores = copied_scores
            T = copied_T


    for t in T:
        print(t)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10136
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
No=2**12
tree=[0]*(2*No)
ans=0
def add(k,x):
    k+=No-1
    while k>=0:
        tree[k]+=x
        k=(k-1)//2
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=0
    while L<=R:
        if R&1:
            s+=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s+=tree[L]
        L>>=1;R>>=1
    return s
for i in a:
    ans+=query(i+1,2001)
    ans%=mod
    add(i,1)
import collections
c=collections.Counter(a)
l=sorted(c.items())
t=l[0][1]
ans*=k
ans%=mod
for i,j in l[1:]:
    ans+=j*t*k*(k-1)//2
    ans%=mod
    t+=j
print(ans)

Measured memory_bytes: 3572
arr = [int(input()) for _ in range(5)]
k = int(input())

can = True
for i in range(5):
  for j in range(i+1,5):
    if abs(arr[i] - arr[j]) > k:
      can = False
      break
  if not can:break
    
if can:print('Yay!')
else:print(':(')
    

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<string> s(n);
    for(i = 0;i < n;++i){
        cin >> s.at(i);
    }
    ll k;
    ll ans = 0;
    rep(k, n){
        bool flag = true;
        for(i = 0;i < n;++i){
            rep(j,n){
                if(s.at((i+k)%n).at(j) != s.at((j+k)%n).at(i)){
                    flag = false;
                    break;
                }
                
            }
            if(!flag) break;
        }
        if(flag) ans += n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
X,K,D = map(int,input().split())

X = abs(X)

if X >= K*D:
    print(X-K*D)
else:
    tmp = X - D*(X//D)
    res_count = K - (X//D)
    if res_count%2 == 0:
        print(tmp)
    else:
        print(D-tmp)

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

using namespace std;

int main(){

    int N;
    cin >> N;

    vector <int> cnt(1000);
    for (int i = 1; i <= N; i++){
        int num = i;
        for (int j = 2; j <= i ; j++){
            if (num == 1){
                break;
            }else{
                while(num % j == 0){
                    cnt[j]++;
                    num = num / j;
                }
            }
        }
    }
    
    long long ans = 1;
    for (int i = 0; i < 1000; i++){
        ans = ans * (cnt[i] + 1);
        ans = ans % 1000000007;
    }
    
    cout << ans << endl;

    return 0;
}

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

int main(){
	int n,q;
	cin>>n>>q;
	vector<vector<int>> graph(n);
	int ta,tb;
	for (int i = 0; i < n-1; i++) {
		cin>>ta>>tb;
		graph[ta-1].push_back(tb-1);
		graph[tb-1].push_back(ta-1);
	}
	vector<int> p(q);
	vector<int> x(q);
	vector<long long int> c(n,0);
	for (int i = 0; i < q; i++) {
		cin>>p[i]>>x[i];
		c[p[i]-1]+=x[i];
	}
	queue<int> qu;
	qu.push(0);
	int task;
	int child;
	vector<int> checked(n,0);
	checked[0]=1;
	while (qu.size()>0) {
		task=qu.size();
		for (int i = 0; i < task; i++) {
			for (int j = 0; j < graph[qu.front()].size(); j++) {
				child=graph[qu.front()][j];
				if (checked[child]==0) {
					c[child]+=c[qu.front()];
					checked[child]=1;
					qu.push(child);
				}
			}
			qu.pop();
		}
	}
	for (int i = 0; i < n; i++) {
		cout<<c[i]<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 18676
import java.util.*;
import java.lang.*; 
class Main{
	public static void main(String[] args){
		int x=0;
		Scanner input=new Scanner(System.in);
	int a[]=new int [3];
	for(int i=0; i<3; i++)
	{
		a[i]=input.nextInt();
	}
	for(int j=0;j<3;j++)
	{
		x=x+a[j];
	}
		if(x==17)
		{
			System.out.println("YES");
		}
		else{System.out.println("NO");}
	}
	
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int N, K;
  cin >> N >> K;

  int sum = 0;
  sum = K;
  for (int i=1; i < N; i++) {
    sum *= (K-1);
  }

  cout << sum << endl;
  
  return 0;
}


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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int taka;
    int ao;

    taka = A / D;
    if (A % D != 0){
        taka++;
    }
    ao = C / B;  
    if (C % B!= 0){
        ao++;
    }

    if (ao <= taka){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

bool is753(int n){
    string s = to_string(n);
    vi a(3,0);
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '3') {
            a[0]++;
        }else if (s[i] == '5'){
            a[1]++;
        }else if (s[i] == '7'){
            a[2]++;
        }else{
            return false;
        }
    }

    for (int i = 0; i < 3; i++) {
        if (a[i] == 0) {
            return false;
        }
    }
    return true;
}

int count_753(int n){
    int digit = to_string(n).size();
    int cand[3] = {3, 5, 7};

    int ans = 0;
    for (int i = 0; i < (int)pow(3,digit); i++) {
        int x = 0;
        int t = i;
        for (int j = 0; j < digit; j++) {
            x += cand[t % 3] * (int)pow(10,j);
            t /= 3;
        }
        if (x <= n && is753(x)) {
            ans++;
        }
    }

    return ans;
}


void solve(){
    int N;
    cin >> N;

    int digit = to_string(N).size();
    int ans = 0;
    for (int i = 3; i < digit; i++) {
        ans += count_753((int)pow(10,i) - 1);
    }
    ans += count_753(N);
    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc091/tasks/arc092_a
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

struct BipartiteMatching {
    vector<vector<int>> graph;
    vector<int> match, alive, used;
    int timestamp;

    BipartiteMatching(int n)
        : graph(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}

    void add_edge(int u, int v) {
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    bool dfs(int idx) {
        used[idx] = timestamp;
        for (auto &to : graph[idx]) {
            int to_match = match[to];
            if (alive[to] == 0)
                continue;
            if (to_match == -1 ||
                (used[to_match] != timestamp && dfs(to_match))) {
                match[idx] = to;
                match[to] = idx;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching() {
        int ret = 0;
        for (int i = 0; i < graph.size(); i++) {
            if (alive[i] == 0)
                continue;
            if (match[i] == -1) {
                ++timestamp;
                ret += dfs(i);
            }
        }
        return ret;
    }

    void output() {
        for (int i = 0; i < graph.size(); i++) {
            if (i < match[i]) {
                cout << i << "-" << match[i] << endl;
            }
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pii> a(n), b(n);
    REP(i, n) cin >> a[i].first >> a[i].second;
    REP(i, n) cin >> b[i].first >> b[i].second;
    // xとyを区別するため、yのノード番号にnを加える
    BipartiteMatching bm(2 * n);
    REP(i, n) REP(j, n) {
        if (a[i].first < b[j].first && a[i].second < b[j].second) {
            bm.add_edge(i, n + j);
        }
    }
    cout << bm.bipartite_matching() << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()][::-1]

ng = []
for i in range(n):
    if a[i] == b[i]:
        ng.append(i)

if len(ng) == 0:
    print('Yes')
    print(*b)
    sys.exit()

min_ng = min(ng)
max_ng = max(ng)

left = 0
right = n - 1

for i in ng:
    if b[i] != b[left] and a[left] != b[i]:
        b[i], b[left] = b[left], b[i]
        left += 1
        continue
    if b[i] != b[right] and a[right] != b[i]:
        b[i], b[right] = b[right], b[i]
        right -= 1

flag = 1

for i in range(n):
    if a[i] == b[i]:
        flag = 0

if flag:
    print('Yes')
    print(*b)
else:
    print('No') 



Measured memory_bytes: 112988
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    
    for(int i = 0; i < n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    
    while(1) {
        minv = INFTY;
        u = -1;
        for(int i = 0; i < n; i++) {
            if(minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v = 0; v < n; v++) {
            if(color[v] != BLACK && M[u][v] != INFTY) {
                if(d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        if(p[i] != -1) sum += M[i][p[i]];
    }
    
    return sum;
}

int main() {
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }
    
    cout << prim() << endl;
    
    return 0;
}


Measured memory_bytes: 3116
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*n
for a in A:l[a]=1
b=0;c=0
for i in range(0,x):b+=l[i]
for i in range(x,n):c+=l[i]
print(min(b,c))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string n;
    cin >> n;
    string n2 = n;
    reverse(n.begin(),n.end());
    cout << (n==n2?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,m,h,k;
  while(cin>>n>>m>>h>>k&&n+m+h+k){
    int a[1000];
    for(i=0;i<n;i++)
      cin>>a[i];
    pair<int,int> b[100000];
    for(i=0;i<m;i++){
      int p,q;
      cin>>p>>q;
      b[i]=make_pair(q,p);
    }
    sort(b,b+m);
    int c[1000];
    for(i=0;i<n;i++)
      c[i]=i;
    for(i=0;i<m;i++){
      int p;
      p=c[b[i].second-1];
      c[b[i].second-1]=c[b[i].second];
      c[b[i].second]=p;
      b[i]=make_pair(c[b[i].second],c[b[i].second-1]);
    }
    pair<int,int> d[1000];
    for(i=0;i<n;i++)
      d[i]=make_pair(c[i],a[i]);
    sort(d,d+n);
    int sm=0;
    for(i=0;i<k;i++)
      sm+=d[i].second;
    int mn=sm;
    for(i=0;i<m;i++){
      if(b[i].first<k&&b[i].second>=k){
	if(d[b[i].first].second>d[b[i].second].second)
	  mn=min(mn,sm-d[b[i].first].second+d[b[i].second].second);
      }
      if(b[i].first>=k&&b[i].second<k){
	if(d[b[i].first].second<d[b[i].second].second)
	  mn=min(mn,sm+d[b[i].first].second-d[b[i].second].second);
      }
    }
    cout<<mn<<endl;
  }
  return 0;
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> pls(n);
  vector<long long> mns(n);
  for (int i = 0; i < n; i++) {
    if ((i + 1) + a[i] < n) {
      pls[(i + 1) + a[i]]++;
    }
    if ((i + 1) - a[i] > 0 && (i + 1) - a[i] < n) {
      mns[(i + 1) - a[i]]++;
    }
  }
  debug(pls, mns);
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += pls[i] * mns[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7128
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), x(n);
    rep(i, n)
    {
        cin >> a[i];
        x[i] = a[i];
    }
    sort(x.begin(), x.end());

    int result = 0;
    rep(i, n)
    {
        if (i % 2 == 0) {
            int j = lower_bound(x.begin(), x.end(), a[i]) - x.begin();
            if (j % 2 != 0) {
                result++;
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0)
  {
    a -= d;
    c -= b;
    if(c<=0)
    {
      cout<<"Yes"<<endl;
      break;
      }
    if(a<=0){
      cout<<"No"<<endl;
      break;
      }
  }
  
  return 0;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m) = (v[0] as usize, v[1]);
    let mut a = read_vec::<i64>();
    a.sort();
    let criterion = |aa: i64| -> bool {
        let mut found = 0;
        for i in 0..n {
            let search = a.lower_bound(&(aa - a[i]));
            found += (a.len() - search) as i64;
        }
        found >= m
    };
    let search_max = 2 * a.iter().max().unwrap() + 1;
    let (ok, ng) = binary_search(0, search_max, criterion);
    debug!(search_max, ok, ng);

    let aa = ok;
    let mut ans = 0;
    let mut found = 0;
    for i in 0..n {
        let search = a.lower_bound(&(aa - a[i]));
        ans += (a.len() - search) as i64 * a[i] * 2;
        found += (a.len() - search) as i64;
    }
    assert!(found >= m);
    ans -= ok * (found - m);

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn binary_search<F>(lb: i64, ub: i64, criterion: F) -> (i64, i64)
where
    F: Fn(i64) -> bool,
{
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}


Measured memory_bytes: 8444
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val bb = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    var aExtra = 0L
    aa.forEachIndexed { idx, a ->
        if (a > bb[idx]) {
            aExtra += 2L * (a - bb[idx])
            bb[idx] = a
        }
    }

    aa.forEachIndexed { idx, a ->
        if (a < bb[idx]) {
            aExtra -= (if ((bb[idx] - a) % 2 == 0) (bb[idx] - a) else (bb[idx] - a) - 1)
            aa[idx] = bb[idx]
        }
    }

    println(if (aExtra > 0L) "No" else "Yes")
}

Measured memory_bytes: 40540
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int main() {
	int H, W;
	cin >> H >> W;
	int cnt[26] = { 0 };
	rep(i, H) {
		string line;
		cin >> line;
		rep(j, W) {
			cnt[line[j] - 'a']++;
		}
	}
	bool OK = 1;
	if (H % 2 == 1 && W % 2 == 1) {
		int four = 0;
		rep(i, 26) {
			int t = min((W - 1) / 2 * (H - 1) / 2 - four, cnt[i] / 4);
			cnt[i] -= t * 4;
			four += t;
		}
		if (four < (W - 1) / 2 * (H - 1) / 2) OK = 0;
		int two = 0;
		rep(i, 26) {
			int t = min((W - 1) / 2 + (H - 1) / 2 - two, cnt[i] / 2);
			cnt[i] -= t * 2;
			two += t;
		}
		if (two < (W - 1) / 2 + (H - 1) / 2) OK = 0;
	}
	else if (H % 2 == 1 && W % 2 == 0) {
		int four = 0;
		rep(i, 26) {
			int t = min(W / 2 * (H-1) / 2 - four, cnt[i] / 4);
			cnt[i] -= t * 4;
			four += t;
		}
		if (four < W / 2 * (H - 1) / 2) OK = 0;
		int two = 0;
		rep(i, 26) {
			int t = min(W/2 - two, cnt[i] / 2);
			cnt[i] -= t * 2;
			two += t;
		}
		if (two < W/2) OK = 0;
	}
	else if (H % 2 == 0 && W % 2 == 1) {
		int four = 0;
		rep(i, 26) {
			int t = min((W-1) / 2 * H / 2 - four, cnt[i] / 4);
			cnt[i] -= t * 4;
			four += t;
		}
		if (four < (W-1) / 2 * H / 2) OK = 0;
		int two = 0;
		rep(i, 26) {
			int t = min(H / 2 - two, cnt[i] / 2);
			cnt[i] -= t * 2;
			two += t;
		}
		if (two < H / 2) OK = 0;
	}
	else {
		int four = 0;
		rep(i, 26) {
			int t = min(W / 2 * H / 2 - four, cnt[i] / 4);
			cnt[i] -= t * 4;
			four += t;
		}
		if (four < W / 2 * H / 2) OK = 0;
	}
	if (OK) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	while(1){
		double r,w,C,R;
		cin >> r >> w >> C >> R;
		if(!r&&!w&&!C&&!R)	break;
		if(r>=C*w)	cout << 0 << endl;
		else{
			cout << int((C*w-r)/R+0.999) << endl;
		}
	}
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか) */

  int n;

  int a,b,c;


  while(1){
    cin>>n;

    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
    

      if(a==100||b==100||c==100){
	cout<<'A'<<endl;
      }else if((a+b)/2>=90){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=80){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=70){
	cout<<'B'<<endl;
      }else if((a+b+c)/3>=50&&(a>=80||b>=80)){
	cout<<'B'<<endl;
      }else{
	cout<<'C'<<endl;
      }
    }

  }
    return 0;

  }



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  rep(i, n){
    int t, x, y;
    cin >> t >> x >> y;
    if(x + y > t || (t - x - y) % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import heapq
from heapq import heapify, heappush, heappop

global G

def input_graph(M, uvab):
  global G
  for i in range(M):
    u, v, a, b = uvab[i]
    G[u-1] += [[v-1, (a, b)]]
    G[v-1] += [[u-1, (a, b)]]
  
def dijkstra(N, S, flag):
  global G
  dist = [float('inf') for _ in range(N)]
  dist[S] = 0
  Q = [(0, S)]
  while Q:
    c, v = heappop(Q)
    if dist[v] < c:
      continue
    for t, cost in G[v]:
      yen, snuuk = cost
      if flag:
        if dist[v] + yen < dist[t]:
          dist[t] = dist[v] + yen
          heappush(Q, (dist[t], t))
      else:
        if dist[v] + snuuk < dist[t]:
          dist[t] = dist[v] + snuuk
          heappush(Q, (dist[t], t))
  return dist

def main():
  global G, dist
  N, M, S, T = map(int, input().split())
  S -= 1
  T -= 1
  uvab = [list(map(int, input().split())) for _ in range(M)]
  G = [[] for _ in range(N)]
  dist = [float('inf') for _ in range(N)]
  dist[S] = 0
  input_graph(M, uvab)
  yen_dist = dijkstra(N, S, True)
  snuuk_dist = dijkstra(N, T, False)
  #print(yen_dist)
  #print(snuuk_dist)
  dist = [yen_dist[i]+snuuk_dist[i] for i in range(N)]
  for i in range(N-2, -1, -1):
    dist[i] = min(dist[i+1], dist[i])
  for i in range(N):
    print(10**15-dist[i])

if __name__ == "__main__":
  main()
  

Measured memory_bytes: 98124
peopleCounts = int(input())
gameCounts = int(input())
targets = list(map(int, input().split()))

result = [0] * peopleCounts

for i in range(gameCounts):
  judges = list(map(int, input().split()))
  
  ans = targets[i]

  for judgeIndex in range(len(judges)):
    if ans == judges[judgeIndex]:
      result[judgeIndex] += 1
    else:
      result[ans - 1] += 1

for v in result:
  print(v)



Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int XMAX = 1000000;
const int SQRTXMAX = sqrt(XMAX);

bool is_prime[XMAX + 1];
bool dp[XMAX + 1];
int cost[30];

int main() {
  // prime
  memset(is_prime, true, sizeof(is_prime));
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= SQRTXMAX; i++) {
    if (is_prime[i]) {
      int current = i * i;
      for (int j = i * i; j <= XMAX; j += i) {
        is_prime[j] = false;
      }
    }
  }

  int n, x;
  while (cin >> n >> x, n) {
    for (int i = 0; i < n; i++) cin >> cost[i];

    // dp
    int r = 0;
    dp[0] = true;
    for (int i = 1; i <= x; i++) {
      dp[i] = false;
      for (int j = 0; j < n; j++) {
        int k = i - cost[j];
        if (k >= 0 && dp[k]) {
          dp[i] = true;
          if (is_prime[i]) r = i;
          break;
        }
      }
    }

    if (r == 0) {
      cout << "NA" << endl;
    } else {
      cout << r << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3120
n = gets.to_i
a = gets.split.map(&:to_i)

ara = a.inject(:+)
snu = 0
ans = 10 ** 9 * n
(n-1).times do |i|
    snu += a[i]
    ara -= a[i]
    ans = (snu - ara).abs if ans > (snu - ara).abs
end

puts ans

Measured memory_bytes: 15236