akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x; cin >> n >> m >> x;
  vector<int> A(m);
  rep(i, m) cin >> A[i];
  int j = lower_bound(all(A), x) - begin(A);
  cout << min(j, m-j) << endk;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    int a, b, c, k;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    if (k <= a) {
        printf("%d\n", k);
    } else if (k <= a + b) {
        printf("%d\n", a);
    } else {
        printf("%d\n", (a + b + c - k) + a - c);
    }
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long 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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(void){
    int n, m, t;
    int x;
    cin >> n >> m >> t;
    int b[10101] = {};
    for (int i = 0; i < n; i++) {
        cin >> x;
        b[x-m]--;
        if (x+m <= t) b[x+m]++;
    }
    int ans = 0;
    if (b[0] == 0) ans++;
    for (int i = 1; i < t; i++) {
        b[i] += b[i-1];
        if (b[i] == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3136
#include <stdio.h>

int main(long long n, long long k, long long x)
{
    scanf("%lld%lld",&n,&k);
    n = n%k;

    x = (n-k)>=0 ? n-k : (n-k)*-1;
    printf("%lld\n", n>x?x:n);
    return 0;
}

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

char S[ 20 ];

int main()
{
int i;
int iChk;
int iMax;
char C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	i = 0;
	iChk = 0;
	iMax = 0;
	while( ( C = S[ i ] ) != '\0' )
	{
		i++;
		if( C == 'A' || C == 'C' || C == 'G' || C == 'T' )
		{
			iChk++;
			iMax = max( iChk, iMax );
		}
		else
			iChk = 0;
	}

	cout << iMax << endl;

	return 0;
}


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

int N;
string s[310];

bool check(int A, int B) {
  string t[310];
  for (int i = 0; i < N; i++) t[i] = s[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      t[i][j] = s[(i+A)%N][(j+B)%N];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (t[i][j] != t[j][i]) return false;
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (check(0, i)) ans += N;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif

void brute(){
    int n ; cin>>n;
    vi v(n);
    rep(i,0,n) cin>>v[i];
    int cnt = 0;
    for(int i = 0  ; i<n ; ++i){
		for(int j = i +1 ; j<n ;++j){
			for(int k = j +1 ; k<n ; ++k){
				if(v[i]<(v[j]+v[k])  and (v[k]<(v[j]+v[i]))  and (v[j]<(v[i]+v[k])))
					cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}

const int N =5000;
int arr[N];

int bs(int l , int r ,int val){
	int ans = l-1;
	while(l<=r){
		int mid = (l+r)/2;
		if(arr[mid]<val){
			ans = mid;
			l=mid+1;
		}
		else r = mid-1;
	}
	return ans ;
}


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	int n ; cin>>n;
	int ans = 0;
	for(int i = 1 ; i<=n  ;++i) cin>>arr[i];
	sort(arr+1,arr+1+n);
	for(int i =1 ; i<=n ;++i){
		for(int j = i+1 ; j<=n ; ++j){
			int k = bs(j+1,n,arr[i]+arr[j]);
			ans += k-j;
		}
	}
	cout<<ans<<endl;

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
ll N, K;
ll w[100000], d[100000];

ll cnt(ll c){
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll rem = w[i]%d[i];
        if(c < w[i]) continue;
        ans += (c-rem+d[i])/d[i] - (w[i]-1-rem+d[i])/d[i];
        if(ans >= K) return ans;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> w[i] >> d[i];
    ll l = 0, r = 2e18;
    while(r-l > 1){
        ll c = (l+r)/2;
        if(cnt(c) >= K) r = c;
        else l = c;
    }
    cout << r << endl;
}

Measured memory_bytes: 5216
S = input()


def is_palindrome(s):
    return s == s[::-1]


N = len(S)

if not is_palindrome(S):
    print('No')
    exit()

if not is_palindrome(S[:(N - 1) // 2]):
    print('No')
    exit()

if not is_palindrome(S[(N + 3) // 2 - 1:]):
    print('No')
    exit()

print('Yes')


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


int cmp(const void *p, const void *q) {
  return *(long *)p - *(long *)q;
}

long Abs(long);

int main (void){
	long N,i,j,tmp;
	long b=0;
	long ans=0;
	scanf("%ld",&N);
	long A[N];
	for(i=0;i<N;i++){
		scanf("%ld",&tmp);
		tmp -= (i+1);
		A[i] = tmp;
	}
	qsort(A,N,sizeof(long),cmp);
	b = A[N/2];

	for(i=0;i<N;i++){
		ans += abs( A[i] - b );
	}
	printf("%ld",ans);
	return 0;
}

long Abs(long a) {
  if (a < 0) a *= -1;
  return a;
}

Measured memory_bytes: 3324
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    int n = k/2;
    int m = k - n;
    cout << n*m;
    return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    rep(i, 0, N)
    {
        cin >> l[i];
    }

    sort(l.begin(), l.end(), greater<int>());

    int ans = 0;
    rep(i, 0, K)
    {
        ans += l[i];
    }

    cout << ans << endl;
    return 0;
}


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

int main()
{
    int x, a, b;
    
    cin >> x >> a >> b;
    
    if(abs(x - a) >= abs(x - b)) {
        cout << "B\n";
    } else {
        cout << "A\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int r;
	cin >> r;
	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r < 2800){
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
N, K = map(int, raw_input().split())
a = [0]*N
b = [0]*N
c = [0]*N
for i in range(N):
  a[i], b[i] = map(int, raw_input().split())
  c[i] = i
c.sort(key=lambda i:a[i])
s = 0
for j in range(N):
  s += b[c[j]]
  if s>=K:
    print a[c[j]]
    break

Measured memory_bytes: 15604
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#pragma warning(disable:4996)

using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

set<string> s1;
char str[100], last[100];

int main() {
	int n, i;
	bool flag;
	while (scanf("%d", &n) != EOF) {
		flag = 1;
		s1.clear();
		scanf("%s", str);
		s1.insert(str);
		for (i = 2; i <= n; i++) {
			strcpy(last, str);
			scanf("%s", str);
			if (s1.count(str) || str[0] != last[strlen(last) - 1])
				flag = 0;
			s1.insert(str);
		}
		if (flag)
			printf("Yes\n");
		else
			printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ;
	ll k ;
	cin >> s >> k ;
	vvll dp1(s.size()+1,vll(4,0)),dp2(s.size()+1,vll(4,0)) ;
	dp2.at(0).at(0) = 1 ;
	for(int i=1;i<=s.size();i++){
		ll n = s.at(i-1)-'0' ;
		if(n==0){
			dp1.at(i).at(0) = dp1.at(i-1).at(0) ;
			dp1.at(i).at(1) = dp1.at(i-1).at(0)*9+dp1.at(i-1).at(1) ;
			dp1.at(i).at(2) = dp1.at(i-1).at(1)*9+dp1.at(i-1).at(2) ;
			dp1.at(i).at(3) = dp1.at(i-1).at(2)*9+dp1.at(i-1).at(3) ;
			dp2.at(i).at(0) = dp2.at(i-1).at(0) ;
			dp2.at(i).at(1) = dp2.at(i-1).at(1) ;
			dp2.at(i).at(2) = dp2.at(i-1).at(2) ;
			dp2.at(i).at(3) = dp2.at(i-1).at(3) ;
		}else{
			dp1.at(i).at(0) = dp1.at(i-1).at(0)+dp2.at(i-1).at(0) ;
			dp1.at(i).at(1) = dp1.at(i-1).at(0)*9+dp1.at(i-1).at(1)+dp2.at(i-1).at(0)*(n-1)+dp2.at(i-1).at(1) ;
			dp1.at(i).at(2) = dp1.at(i-1).at(1)*9+dp1.at(i-1).at(2)+dp2.at(i-1).at(1)*(n-1)+dp2.at(i-1).at(2) ;
			dp1.at(i).at(3) = dp1.at(i-1).at(2)*9+dp1.at(i-1).at(3)+dp2.at(i-1).at(2)*(n-1)+dp2.at(i-1).at(3) ;
			dp2.at(i).at(0) = 0 ;
			dp2.at(i).at(1) = dp2.at(i-1).at(0) ;
			dp2.at(i).at(2) = dp2.at(i-1).at(1) ;
			dp2.at(i).at(3) = dp2.at(i-1).at(2) ;
		}
	}
//	for(int i=0;i<=s.size();i++){
//		cout << dp1.at(i).at(0) << " " << dp1.at(i).at(1) << " " << dp1.at(i).at(2) << " " << dp1.at(i).at(3) ;
//		cout << " " << dp2.at(i).at(0) << " " << dp2.at(i).at(1) << " " << dp2.at(i).at(2) << " " << dp2.at(i).at(3) << endl ;
//	}
	cout << dp1.at(s.size()).at(k)+dp2.at(s.size()).at(k) << endl ;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
    
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

inline int norm_man(int a, int b, int c, int d) {
	return std::abs(a - c) + std::abs(b - d);
}

int main(void) {
	// in
	int n, m;
	std::cin >> n >> m;
	std::vector<int> a(n), b(n);
	for(int i = 0; i < n; ++i) {
		std::cin >> a[i] >> b[i];
	}
	std::vector<int> c(m), d(m);
	for(int i = 0; i < m; ++i) {
		std::cin >> c[i] >> d[i];
	}

	for(int i = 0; i < n; ++i) {
		std::vector<std::pair<int, int>> dist(m);
		for(int j = 0; j < m; ++j) {
			dist[j] = std::make_pair(j+1, norm_man(a[i], b[i], c[j], d[j]));
		}
		std::sort(dist.begin(), dist.end(), [](std::pair<int, int> &lhs, std::pair<int, int> &rhs){ return lhs.second < rhs.second; });
		std::cout << dist[0].first << std::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;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 29;
 
int main() {
	int n, l;
	cin >> n >> l;
	vector<string> d(n);
	rep(i, n) cin >> d[i];
	sort(d.begin(), d.end());
	rep(i, n) {
		cout << d[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    // Here your code !
    
    double a,b,c;
    double pi=3.14159265358979323846  ;
    cin>>a;
    b=2*a*pi;
    c=a*a*pi;
    
    std::printf("%.6f %.6f",c,b);
    
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[200009], m = 1e9 + 7, dir[200009];

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	
	f[1] = 1;
	for(ll i = 2; i <= n; i++){
		f[i] = f[i-1]*i;
		f[i] %= m;
	}
	
	dir[0] = 0;
	ll x = 1, y = 0;
	for(ll i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]){
			dir[i] = dir[i-1]^1;
		}
		else{
			dir[i] = dir[i-1];
		}
		if(dir[i] == 0){
			x++;
		}
		else{
			y++;
		}
	}
	ll pos = 1;
	
	if(s[0] == s[s.size()-1] and s[0] == 'B' and dir[s.size() - 1] == 1){
		
	}
	else{
		pos = 0;
	}
	if(x != y){
		pos = 0;
	}
	ll op = 1, cl = 0, tot = 1;
	for(ll i = 1; i < s.size(); i++){
		if(dir[i] == 1){
			if(op <= 0){
				pos = 0;
			}
			tot *= op;
			op--;
			tot %= m;
		}
		else{
			op++;
		}
	}
	tot*= f[n];
	tot %= m;
	tot *= pos;
	cout<<tot;
}

Measured memory_bytes: 2948
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int main() {
    string s;
    cin >> s;
    if (s[0] == 'S')
        cout << "Cloudy" << endl;
    else if (s[0] == 'R')
        cout << "Sunny" << endl;
    else
        cout << "Rainy" << endl;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 10;
int a[N];
int b[N];
int n;

int compute(ll k){
  vector<ll> ai, bi;
  ll mod = 2 * k;
  for(int i = 0 ; i < n; i ++ ){
    ai.push_back(a[i] % mod);
    bi.push_back(b[i] % mod);
  }
  sort(ai.begin(), ai.end());
  sort(bi.begin(), bi.end());
  ll li = k;
  ll ri = 2 * k;
  ll ans = 0;
  ll cl, cr;
  for(auto x : ai){
    cl = lower_bound(bi.begin(), bi.end(), li - x) - bi.begin();
    cr = lower_bound(bi.begin(), bi.end(), ri - x) - bi.begin();
    ans += cr - cl;
  }
  li += mod;
  ri += mod;
  for(auto x : ai){
    cl = lower_bound(bi.begin(), bi.end(), li - x) - bi.begin();
    cr = lower_bound(bi.begin(), bi.end(), ri - x) - bi.begin();
    ans += cr - cl;
  }
  return (ans & 1);
}

int main(){
  fastIO;
  cin >> n;
  for(int i = 0 ; i < n ; i ++ ){
    cin >> a[i];
  }
  for(int i = 0 ; i < n ; i ++ ){
    cin >> b[i];
  }
  ll ans = 0;
  for(int bit = 0; bit < 31 ; bit ++ ){
    ans += compute((1ll << bit)) * (1ll << bit);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 6972
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int res = 0;
    rep(i, N - 2) {
        if(S.substr(i, 3) == "ABC")
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//
// Created by inoue on 2019-11-09.
//

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

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

    vint A(N);
    rep(i, N) cin >> A[i];
    map<int, int> tmap;
    rep(i, N) {
        tmap[A[i]]++;
    }

    vint V;
    for(pair<int, int> x: tmap) {
        V.PB(x.se);
    }
    sort(ALL(V));
    vint sum(V.size());

    rep(i, V.size()) {
        if (i) sum[i] = sum[i-1];
        sum[i] += V[i];
    }

    rep(t, 1, N+1) {
        int l = 0;
        int r = INF;

        while(r-l > 1) {
            ll mid = (r + l) / 2;
            int id = upper_bound(ALL(V), mid) - V.begin();

            ll tsum = 0;
            if (id) {
                tsum += sum[id-1];
            }
            tsum += mid * (V.size() - id);

            if (tsum >= mid * t) {
                l = mid;
            }
            else {
                r = mid;
            }
        }

        cout << l << endl;
    }

}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

typedef long long ll;
const int N(409);
const ll inf(1e15);

int n, m;
int a[N];
ll f[N][N], sum[N];

int main()
{
	cin>>n;
	for (int i = 1; i <= n; i++)
	{
		cin>>a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = 1;i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i == j) f[i][j] = 0;
			else f[i][j] = inf;
		}
	}
	for (int i = 1; i <= n ;i++)
	{
		for (int j = i - 1; j >= 1; j--)
		{
			for (int k = j; k < i; k++)
			{
				f[j][i] = min(f[j][i], f[j][k] + f[k + 1][i] + sum[i] - sum[j - 1]);
			}
		}
	}
	/*for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cout<<f[i][j]<<' ';
		}
		cout<<endl;
	}*/
	cout<<f[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 1536
N,M = map(int,input().split())
table = [int(i) for i in input().split()]
tsum = sum(table)       ##相得票の和
a = tsum/4/M            ##得票数の1/4M
b = [i for i, x in enumerate(table) if x>=a]
c = len(b)      ##a以上の要素の数
if c >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n, c, k= map(int, input().split())
T = [int(input()) for _ in range(n)]
T.sort()

bus_t = -k - 100
bus_c = c
ans = 0

for t in T:
    bl = (bus_t + k >= t) and (bus_c + 1 <= c)
    if bl:
        bus_c += 1
        continue
    ans += 1
    bus_t = t
    bus_c = 1
print(ans)

Measured memory_bytes: 7420
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

int main(){
    std::ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    ll cnt[n] = {};
    ll ret[n] = {};
    bool visited[n] = {};
    map<int, vector<int>> m;
    int tmpa, tmpb;
    for(int i=0;i<n-1;++i)
    {
        cin >> tmpa >> tmpb;
        tmpa--;
        tmpb--;

        m[tmpa].push_back(tmpb);
        m[tmpb].push_back(tmpa);
    }

    for(int i=0;i<q;++i)
    {
        cin >> tmpa >> tmpb;
        tmpa--;
        cnt[tmpa] += tmpb;
    }

    // traverse
    stack<pair<ll,ll>> st;
    st.push(MP(0, cnt[0]));
    while(!st.empty())
    {
        pair<ll,ll> node = st.top();
        st.pop();
        ret[node.first] = node.second;
        visited[node.first] = true;
        for(int ind : m[node.first])
        {
            if(!visited[ind])
            {
                st.push(MP(ind, node.second + cnt[ind]));
            }

        }
    }

    for(int i=0;i<n;++i)
    {
        cout << ret[i];
        if(i != n-1)
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }
}

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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if (x-r < 0 || x + r > W || y-r < 0 || y+r > H){ cout << "No" <<endl;}
	else cout << "Yes" << endl;
	return 0;
}

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

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

int main() {

  int N;
  string S;
  cin >> N >> S;

  int Num = S.size();
  rep(i,Num){
    S.at(i) = (S.at(i) - 'A'+N)%26 + 'A';
  }


  cout << S << endl;
  return 0;
}



Measured memory_bytes: 256
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut sum = 0;
    for i in 0..n {
        sum ^= a[i];
    }

    let mut ans = Vec::with_capacity(n);
    for i in 0..n {
        ans.push(a[i] ^ sum);
    }
    println!("{}", ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
}

Measured memory_bytes: 18772
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n,k; cin >> n ;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];

    vector<ll> tmp = x;
    sort(tmp.begin(), tmp.end());
    long double median = (tmp[n/2-1] + tmp[n/2]) / 2.0;

    rep(i,n) {
        if(x[i] < median) {
            cout << tmp[n/2] << endl;
        } else {
            cout << tmp[n/2-1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int k;
string s;

int main(){
    cin >> k;
    cin >> s;
    if(s.size() <= k) cout << s << endl;
    else{
        for(int i=0; i<k; i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int n,a[N],cnt[2][N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),cnt[i&1][a[i]]++;
    int mx=0,mx2=0,p=0,ans=0;
    for(int t=0;t<2;t++) {
        mx=mx2=p=0;
        for(int i=1;i<=100000;i++) if(chkmax(mx,cnt[t][i])) p=i;
        for(int i=1;i<=100000;i++) if(i!=p) chkmax(mx2,cnt[t^1][i]);
        ans=max(ans,mx+mx2);
    }
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n <= k){
        cout << n * x << nl;
    }
    else{
        int res = k * x;
        int diff = (n - k) * y;
        cout << res + diff << nl;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


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

int main() {
	int a,b,c,t,s=0,jwb=0;
	cin >> a >> b >> c;	
	t = max(a, max(b, c));
	if ((t+a+b+c)&1) ++t;
	jwb += ((t-a)>>1)+((t-a)&1);
	s = (t-a)&1;
	if (b<t) {
		b += s;
		s = 0;
	}
	jwb += ((t-b)>>1)+((t-b)&1);
	s += (t-b)&1;
	if (c<t) {
		c += s;
	}
	jwb += ((t-c)>>1)+((t-c)&1);
	cout << jwb << endl;
	return 0;
}

Measured memory_bytes: 256
h,w,m=map(int,input().split())
x=[0]*h
y=[0]*w
c=[]
for _ in range(m):
  a,b=map(int,input().split())
  x[a-1]+=1
  y[b-1]+=1
  c+=[(a-1,b-1)]
mx=max(x)
my=max(y)
cnt=0
for i,j in c:
  if x[i]==mx and y[j]==my:cnt+=1
print(mx+my-(cnt==x.count(mx)*y.count(my)))

Measured memory_bytes: 106860
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstring>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int h[N];
    for (int i=0; i<N; i++) {
        cin >> h[i];
    }
    int m[N];
    memset(m, 0, N);
    m[0] = 0;
    m[1] = abs(h[1] - h[0]);
    
    for (int i=2; i<N; i++) {
        int mv = m[i-1] + abs(h[i] - h[i-1]);
        for (int j=min(i,K); j>1; j--) {
            mv = min(mv, m[i-j] + abs(h[i] - h[i-j]));
        }
        m[i] = mv;
    }
    
    cout << m[N-1] << "\n";
    
    return 0;
}



Measured memory_bytes: 1024
S=input()
Q=int(input())

R=0
S1=""
S2=""
for i in range(Q):
    temp=list(input().split())

    if int(temp[0])==1:
        S=S1+S+S2
        S1=""
        S2=""
        R+=1
    elif int(temp[0])==2:
        F=int(temp[1])
        c=temp[2]
        if F==1:
            if R%2==0:
                S1=c+S1
            else:
                S2=S2+c
        elif F==2:
            if R%2==0:
                S2=S2+c
            else:
                S1=c+S1
S=S1+S+S2

if R%2==1:
    ans=S[-1::-1]
    print(ans)
else:
    print(S)



Measured memory_bytes: 4432
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val line = scanner.nextLine()
    val stack = Stack<Int>()
    for (s in line.split(" ")) {
        when(s) {
            "+" -> {
                val a = stack.pop()
                val b = stack.pop()
                stack.push(b + a)
            }
            "-" -> {
                val a = stack.pop()
                val b = stack.pop()
                stack.push(b - a)
            }
            "*" -> {
                val a = stack.pop()
                val b = stack.pop()
                stack.push(b * a)
            }
            else -> {
                stack.push(s.toInt())
            }
        }
    }
    println(stack.pop())
}



Measured memory_bytes: 33424
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int s = 1;
vector<int> dat, lazy;

void init(int n_) {
	while (s < n_)s *= 2;
	dat.resize(2 * s - 1, 0);
	lazy.resize(2 * s - 1, 0);
}

void eval(int k, int l, int r) {
	if (lazy[k]) {
		dat[k] += lazy[k];
		if (r - l > 1) {
			lazy[2 * k + 1] += lazy[k] / 2;
			lazy[2 * k + 2] += lazy[k] / 2;
		}
		lazy[k] = 0;
	}
}

void add(int a, int b, int x, int k = 0, int l = 0, int r = s) {
	eval(k, l, r);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		lazy[k] += (r - l)*x;
		eval(k, l, r);
		return;
	}
	add(a, b, x, 2 * k + 1, l, (l + r) / 2);
	add(a, b, x, 2 * k + 2, (l + r) / 2, r);
	dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
}

int query(int a, int b, int k = 0, int l = 0, int r = s) {
	if (r <= a || b <= l)return 0;
	eval(k, l, r);
	if (a <= l && r <= b)return dat[k];
	int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
	int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
	return vl + vr;
}

int n, m, a[100010];
int cnt;
int ans = 10000000000;

signed main() {
	cin >> n >> m;
	init(m + 2);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 1; i < n; i++) {
		if (a[i - 1] <= a[i])cnt += a[i] - a[i - 1];
		else cnt += a[i];
	}
	ans = cnt;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] <= a[i]) {
			if (a[i] == a[i - 1] + 1)continue;
			add(a[i - 1] + 2, a[i] + 1, -1);
			add(a[i] + 1, a[i] + 2, a[i] - a[i - 1] - 1);
		}
		else {
			if (a[i - 1] == m && a[i] == 1)continue;
			if (a[i - 1] < m - 1)add(a[i - 1] + 2, m + 1, -1);
			if (a[i - 1] == m)add(2, a[i] + 1, -1);
			else add(1, a[i] + 1, -1);
			add(a[i] + 1, a[i] + 2, m + a[i] - a[i - 1] - 1);
		}
	}
	for (int i = 2; i <= m; i++) {
		cnt += query(i, i + 1);
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

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

llint n;
llint x[200005], y[200005];
llint u[200005], v[200005];
vector<P> uvec, vvec;

llint dist(llint i, llint j)
{
	return abs(x[i]-x[j]) + abs(y[i]-y[j]);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> y[i];
		u[i] = x[i] + y[i];
		v[i] = x[i] - y[i];
		uvec.push_back(P(u[i], i));
		vvec.push_back(P(v[i], i));
	}
	
	sort(uvec.begin(), uvec.end());
	sort(vvec.begin(), vvec.end());
	
	cout << max(dist(uvec.front().second, uvec.back().second), dist(vvec.front().second, vvec.back().second)) << endl;
	
	
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    ll ans = 0;
    ll cnt = 0;
    rep(i, s.length() - 1)
    {
        if (s[i] == 'A')
        {
            cnt++;
        }
        else if (s[i] == 'B' && s[i + 1] == 'C')
        {
            ans += cnt;
            i++;
        }
        else
        {
            cnt = 0LL;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(input().split(" "))
b = [0 for i in range(n+1)]
for i in range(n):
    b[int(a[i])] += 1
sum = 0
for j in range(n+1):
        sum += b[j]*(b[j]-1)/2
for i in range(n):
    print(int(sum)-b[int(a[i])]+1)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ans = -1;
  if (A < 10 && B < 10) ans = A * B;
  else ans = -1;
  cout << ans << endl;
}


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

using namespace std;

pair<char, char> a[222222];
int main() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	for (int i = 0; i < q; i++) {
		char t, d;
		scanf(" %c %c", &t, &d);
		a[i] = { t,d };
	}
	int l = 0, r = n + 1;
	while (l + 1 < r) {
		int m = (l + r) / 2, k = m;
		for (int i = 0; i < q; i++) {
			if (a[i].first == s[k - 1])
				a[i].second == 'L' ? k-- : k++;
			if (!k || k > n) break;
		}
		if (k) r = m;
		else l = m;
	}
	int x = l;
	l = 0, r = n + 1;
	while (l + 1 < r) {
		int m = (l + r) / 2, k = m;
		for (int i = 0; i < q; i++) {
			if (a[i].first == s[k - 1])
				a[i].second == 'L' ? k-- : k++;
			if (!k || k > n) break;
		}
		if (k > n) r = m;
		else l = m;
	}
	cout << r - x - 1 << endl;
	return 0;
}


Measured memory_bytes: 1028
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		List<Integer> cost = new ArrayList<Integer>();
		for (int i = 0; i < m; i++) {
			cost.add(sc.nextInt());
		}

		int temp = 0;
		for (int i = 0; i <= x; i++) {
			if (cost.contains(i)) {
				temp++;
			}
		}

		int op = 0;
		for (int i = x; i <= n; i++) {
			if (cost.contains(i)) {
				op++;
			}
		}
		System.out.println(Math.min(op, temp));
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
vector <int> p(MAXN);
void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    for (ll c=1;c<n;c++)
    {
        ll x=n-c;
        ll add=1;
        while (x>1)
        {
            ll cnt=0;
            ll y=p[x];
            while (x%y==0)
                cnt++,x/=y;
            add*=cnt+1;
        }
        ll d=floor(sqrt(n-c+0.5));
      //  cout<<add<<'\n';

       // cout<<add<<'\n';
        ans+=add;
    }
    cout<<ans<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
    p[1]=1;
    for (int i=2;i<MAXN;i++)
    {
        if (p[i])
            continue;
        p[i]=i;
        for (ll j=1ll*i*i;j<MAXN;j+=i)
        {
            if (p[j])
                p[j]=min(p[j],i);
            else
                p[j]=i;
        }
    }
//    cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

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

int main(){
  int N;
  cin >> N;
  int64_t ans = 0;
  vector<int> count(200001,0);
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    if(i > A)
     ans += count[i-A];
    if(i+A < 200001)
      count[i+A]++;
  }
  cout << ans << endl;   
}

Measured memory_bytes: 4020
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int x = sc.nextInt();
        
        if((a <= x) && (x <= (a+b))){
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    int H, W, i;
    string a[102];

    cin >> H >> W;

    for(i=1; i<=H; i++){
        cin >> a[i];
    }

    for(i=1; i<=W+2; i++){
        cout << '#';
    }
    cout << endl;

    for(i=1; i<=H; i++){
        cout << '#' << a[i] << '#' << endl;
    }

    for(i=1; i<=W+2; i++){
        cout << '#';
    }
    cout << endl;

    return 0;
}

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

main(){
  cout<<fixed<<setprecision(10);
  ll n;
  cin>>n;
  vector<double> a(n);
  rep(i,n)cin>>a[i];

  sort(a.begin(),a.end());
  double ans=a[0]+a[1];
  ans/=2;
  for(ll i=2;i<n;++i){
    ans+=a[i];
    ans/=2;
  }
  cout<<(ans)<<endl;

}

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

vector<int> R;
vector<int> B;
vector<int> T;

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for(int i = 0; i < a; i++){
        int p;
        cin >> p;
        R.push_back(p);
    }
    for(int i = 0; i < b; i++){
        int q;
        cin >> q;
        B.push_back(q);
    }
    for(int i = 0; i < c; i++){
        int r;
        cin >> r;
        T.push_back(r);
    }
    sort(R.begin(), R.end(), greater<int>());
    sort(B.begin(), B.end(), greater<int>());
    for(int i = 0; i < x; i++)T.push_back(R[i]);
    for(int i = 0; i < y; i++)T.push_back(B[i]);
    sort(T.begin(), T.end(), greater<int>());
    long long int ans = 0;
    for(int i = 0; i < x+y; i++)ans += T[i];
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> time(M);
    for(int i = 0; i < M; i++){
        cin >> time.at(i);
    }

    int day = 0;

    for(int i = 0; i < M; i++){
        day += time.at(i);
    }

    if(day <= N){
        cout << N - day << endl;
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define maxn 3000
using namespace std;
typedef long double LD;
LD f[maxn][maxn / 2];
LD p[maxn];
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i += 1) cin >> p[i];
	f[0][0] = 1;
	for(int i = 1; i <= N; i += 1)
		for(int j = 0; j <= N / 2; j += 1)
			f[i][j] = p[i] * f[i - 1][j] + (j ? (1 - p[i]) * f[i - 1][j - 1] : 0);
	LD ans = 0;
	for(int j = 0; j <= N / 2; j += 1) ans += f[N][j];
	cout << setprecision(10) << ans;
} 

Measured memory_bytes: 70656
from collections import defaultdict

mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod

import sys
input = sys.stdin.readline
n,X,Y = map(int,input().split())
cw = [list(map(int,input().split())) for i in range(n)]
cw.sort()
mnls = []
graph = [[] for i in range(n)]
notmn = set()
for i in range(n):
  if i == 0 or cw[i-1][0] != cw[i][0]:
    mnls.append((i,cw[i][0],cw[i][1]))
  else:
    if cw[i][1]+mnls[-1][2] <= X:
      graph[i].append(mnls[-1][0])
      graph[mnls[-1][0]].append(i)
    else:
      notmn.add(i)
mnls.sort(key = lambda x:x[2])
for i,x in enumerate(mnls):
  if i == 0:
    continue
  if x[2]+mnls[0][2] <= Y:
    graph[x[0]].append(mnls[0][0])
    graph[mnls[0][0]].append(x[0])
for i in notmn:
  if mnls[0][1] != cw[i][0]:
    if mnls[0][2]+cw[i][1] <= Y:
      graph[i].append(mnls[0][0])
      graph[mnls[0][0]].append(i)
  else:
    if len(mnls) >= 2 and mnls[1][2]+cw[i][1] <= Y:
      graph[i].append(mnls[1][0])
      graph[mnls[1][0]].append(i)
vis = [0 for i in range(n)]
ans = 1
for i in range(n):
  if vis[i]:
    continue
  vis[i] = 1
  stack = [i]
  color = defaultdict(int)
  while stack:
    x = stack.pop()
    color[cw[x][0]] += 1
    for y in graph[x]:
      if vis[y] == 0:
        vis[y] = 1
        stack.append(y)
  sm = sum(color.values())
  for v in color.values():
    ans = ans*cmb(sm,v)%mod
    sm -= v
print(ans)

Measured memory_bytes: 129948
import sys
import itertools
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = tuple([int(i) for i in input().split()])
    q = tuple([int(i) for i in input().split()])
    seq = tuple(range(1, n+1))
    num_p = 0
    num_q = 0
    cnt = 0
    for i in itertools.permutations(seq):
        cnt += 1
        if i == p:
            num_p = cnt
        if i == q:
            num_q = cnt
    print(abs(num_p-num_q))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;

void solve() {
    int N; cin >> N;
    vi DP(3);
    for(int d = 0; d < N; d++) {
        vi N_DP(3);
        vi c(3);
        for(int i = 0; i < 3; i++) cin >> c[i];
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if(i != j) {
                    N_DP[j] = max(N_DP[j], DP[i] + c[j]);
                }
            }
        }
        DP = N_DP;
    }
    cout << max ({DP[0], DP[1], DP[2]}) << "\n";
}

int main() {
    fast 
    // input output
    int t=1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define speed ios::sync_with_stdio(false), cin.tie(0);

using namespace std;

int main()
{
  speed;
  int n,d,i,j,k;
  cin>>n>>d;
  int l[n][d],ans=0;
  double temp=0;
  for (i=0;i<n;i++)
  {
    for (j=0;j<d;j++)
      cin>>l[i][j];
  }
  for (i=0;i<n-1;i++)
  {
    for (j=i+1;j<n;j++)
    {
      temp=0;
      for (k=0;k<d;k++)
        temp+=pow((l[i][k]-l[j][k]),2);
      temp=sqrt(temp);
      if ((temp-floor(temp))==0)
        ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int N;
  std::cin >> N;

  std::vector<int> as;
  for (int i = 0; i < N; ++i) {
    int a;
    std::cin >> a;
    as.push_back(a);
  }

  std::vector<int> bs;
  for (int i = 0; i < N; ++i) {
    int b;
    std::cin >> b;
    bs.push_back(b);
  }

  long long ab_diff = 0;
  for (int i = 0; i < N; ++i) {
    long long diff = bs[i] - as[i];
    if (diff < 0)
      ab_diff += diff;
    else
      ab_diff += diff / 2;
  }
  if (ab_diff >= 0)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int rectangle(int tate,int yoko);
int main(void){
	int H[1000],W[1000],a,j;
	j=0;
	while(1){
		scanf("%d %d",&H[j] ,&W[j]);
			if((H[j]==0)&&(W[j]==0)){
			break;
	}
		j++;
	}
	for(a=0;a<j;a++){
		rectangle(H[a],W[a]);
		printf("\n");
	}
	return 0;
}
	
	int rectangle(int tate,int yoko){
		int h,i;
		for(h=0;h<tate;h++){
			for(i=0;i<yoko;i++){
				if(((h%2==0)&&(i%2==0))||((h%2!=0)&&(i%2!=0))){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		return 0;
	}


Measured memory_bytes: 2048