akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;

using qul = queue<ll>;

int main() {
    string T, T2,T3;
    char mae = 'P';
    cin >> T;
    ll len = T.size();
    T = T + 'S';
    T2 = T;
    ll count1 = 0, count2 = 0;

    REP(i, len + 1) {
        if(mae == 'P' && T[i] == '?') {
            T[i] = 'D';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == '?') {
            T[i] = 'P';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'D') {
            T[i] = 'P';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'P') {
            T[i] = 'D';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'S') {
            T[i] = 'D';
        }

        mae = T[i];
    }

    mae = 'D';
    REP(i,len){
        if(mae == 'D' && T[i] == 'D')
            count1++;
        if(mae == 'P' && T[i] == 'D')
            count1++;

        mae = T[i];
    }





    T3 = T;

    mae = 'D';
    T = T2;

    REP(i, len + 1) {
        if(mae == 'P' && T[i] == '?') {
            T[i] = 'D';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == '?') {
            T[i] = 'P';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'D') {
            T[i] = 'P';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'P') {
            T[i] = 'D';
        } else if(mae == 'D' && T[i] == '?' && T[i + 1] == 'S') {
            T[i] = 'D';
        }

        mae = T[i];
    }

    mae = 'D';
    REP(i, len) {
        if(mae == 'D' && T[i] == 'D')
            count2++;
        if(mae == 'P' && T[i] == 'D')
            count2++;

        mae = T[i];
    }

    if(count1 > count2){
        cout << T3.erase(len) << endl;
    } else {
        cout << T.erase(len) << endl;
    }
}

Measured memory_bytes: 4024
#include<iostream>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
using namespace std;
using ll=long long;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef std::pair<ll, ll> ipair;
bool lP(const ipair& l, const ipair& r){return l.second < r.second;}

int main(){
  int N, M; cin>>N>>M;
  vector<ll> A, B;
  vector<pair<ll, ll>> vi;
  REP(i,N){
    ll a, b;
    cin>>a>>b;
    A.push_back(a);
    B.push_back(b);
    vi.push_back(pair<ll, ll>(i, a));
  }

  sort(vi.begin(), vi.end(), lP);

  ll ans=0;
  for(vector<ipair>::iterator it=vi.begin(); it!= vi.end(); ++it){
    if(B[it->first] < M){
      ans += it->second * B[it->first];
      M -= B[it->first];
    }else{
      ans += it->second * M;
      break;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


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

int main(void) {
  string s; cin >> s;
  string c = "abcdefghijklmnopqrstuvwxyz";
  bool find_flag = false;
  
  for (int i=0; i<26; i++) {
    bool target = false;
    for (int j=0; j<s.length(); j++) {
      if (c[i] == s[j]) target = true;
    }
    if (!target) {
      cout << c[i] << endl;
      find_flag = true;
      break;
    }
  }
  
  if (!find_flag) cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 3768
// マニ

#include<bits/stdc++.h>
#define ll        	long long 
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define rrep(i,a,b) for(ll int i=a;i>=b;i--)
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define PI 3.14159265358979323846
#define tr(i, cont) for(auto i=cont.begin();i!=cont.end();i++)
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define trace(x)                 cerr << #x << ": " << x << "\n";
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << "\n";
#define ar array
#define endl "\n"
using namespace std;

int main(){
	ios;
	ll n;
	cin>>n;
	vi res(n+1);
	for(int x=1;x<=100;x++){
		for(int y=1;y<=100;y++){
			for(int z=1;z<=100;z++){
				if(x*x+y*y+z*z+x*y+y*z+z*x <=n)
					res[x*x+y*y+z*z+x*y+y*z+z*x ]++;
			}
		}
	}
	rep(i,1,n+1){
		cout<<res[i]<<endl;
	}
}


Measured memory_bytes: 3720
n=int(input())
s=list(input())
array=[]
array=[0]*(n+1)
if s[0]=="I":
    array[0]=1
else:
    s[0]=-1
for i in range(1,n):
    if s[i]=="I":
        array[i]=array[i-1]+1
    else:
        array[i]=array[i-1]-1
print(max(array))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=2;i<n;i++){
    if(s.at(i) == 'C' && s.at(i-1) == 'B' && s.at(i-2) == 'A') ans++;
  }
  cout << ans;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n, W; cin >> n >> W;
    int dp[n + 1][W + 1];
    int weights[n];
    int values[n];
    for(int i = 0; i < n; i++){
        cin >> weights[i];
        cin >> values[i];
    }
    mm(dp);
    int ans = 0;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= W; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(j >= weights[i - 1]){
                dp[i][j] = max(dp[i - 1][j], values[i - 1] + dp[i  - 1][j - weights[i - 1]]);
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 82480
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    int n[3];
    while(cin>>n[0]>>n[1]>>n[2])
    {
        sort(n,n+3);
        ll cnt=0;
        cnt+=n[2]-n[1];
        n[0]+=n[2]-n[1];
        n[1]=n[2];
        if((n[1]-n[0])%2==0)
            cnt+=(n[1]-n[0])/2;
        else
            cnt+=(n[1]-n[0]+1)/2+1;
        cout<<cnt<<endl;
    }
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> a(N);
  int ans = 0, tmp = 0;
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
    if(i == 0) continue;
    else {
      if(a[i] <= a[i-1]) tmp++;
      else ans = max(ans, tmp), tmp = 0;
    }
  }
  ans = max(ans, tmp);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 640
S = input()
for i in range(len(S)):
    if (i + 1) % 2 == 1 and (S[i] == 'R' or S[i] == 'U' or S[i] == 'D'):
        continue
    elif (i + 1) % 2 == 0 and (S[i] == 'L' or S[i] == 'U' or S[i] == 'D'):
        continue
    print("No")
    break
else:
    print("Yes")

Measured memory_bytes: 38256
N = int(input())
*A, = map(int, input().split())
C = [0]*4
for a in A:
    C[a] += 1

c1, c2, c3 = C[1:]
dp = [[[0]*(c1+c2+c3+1) for i in range(c2+c3+2)] for j in range(c3+2)]
for c in range(c3+1):
    M1 = c2+c3-c
    T = dp[c-1]
    S = dp[c]
    for b in range(M1+1):
        M2 = N-b-c
        X = S[b-1]; Y = S[b]
        Z = T[b+1]
        for a in range(M2==N, M2+1):
            r = N
            if a:
                r += a*Y[a-1]
            if b:
                r += b*X[a+1]
            if c:
                r += c*Z[a]
            Y[a] = r / (a+b+c)
print("%.10f" % dp[c3][c2][c1])

Measured memory_bytes: 499464
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
pair<ll ,ll> p[100001];
ll ans[100000],n,a[100000],l,b;
int main(){
    scanf("%lld",&n);
    for(ll i=0;i<n;i++){
        scanf("%lld",&a[i]);
        p[i]=make_pair(a[i],i+1);
    }
    p[n]=make_pair(0,0);
    sort(p,p+n+1);
    l=n;
    b=n;
    while(l){
        while(p[l].first==p[l-1].first){
            l--;
        }
        b=min(b,p[l].second);
        ans[b-1]+=(n-l+1)*(p[l].first-p[l-1].first);
        l--;
    }
    for(int i=0;i<n;i++){
        printf("%lld\n",ans[i]);
    }
}

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

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3 = x2 + y1 - y2;
	int y3 = y2 + x2 - x1;
	int x4 = x1 + y1 - y2;
	int y4 = y1 + x2 - x1;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	while(true){
	int N;
	cin>>N;
	if(N==0)break;
	int count=0;
	bool na=true;
	int k;
	for(int i=0;i<N;i++){
		cin>>k;
		if(k>1)na=false;
		if(k>0)count++;
		}
		if(na==true)cout<<"NA"<<endl;
		else cout<<count+1<<endl;
	}
	return 0;
}

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

int p[200000];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  /*for (int i = 0; i+k <= n; i++) {
    vector<int> v(n);
    for (int j = 0; j < n; j++)
      v[j] = p[j];
    sort(v.begin()+i, v.begin()+i+k);
    for (int j = 0; j < n; j++)
      cout << v[j] << ' ';
    cout << endl;
  }
  return 0;*/
  set<int> s;
  for (int i = 0; i < k; i++)
    s.insert(p[i]);
  int ans = n-k+1;

  int last_fall = -1;
  vector<int> streak(n,1);
  for (int i = 0; i+1 < n; i++) {
    if (p[i+1] < p[i]) {
      last_fall = i;
    }
    streak[i+1] = i+1-last_fall;
  }
  ans += (*max_element(streak.begin(), streak.end()) >= k);
  /*for (int i = 0; i < n; i++)
    cout << streak[i] << ' ';
  cout << endl;
  return 0;*/

  if (streak[n-1] >= k) ans--;
  for (int i = 0; i+k < n; i++) {
    int mi = *s.begin();
    s.insert(p[i+k]);
    s.erase(p[i]);
    int ma = *s.rbegin();
    if (streak[i+k-1] >= k || p[i] == mi && p[i+k] == ma) ans--;
  }
  cout << ans << endl;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string S, std::string T){
    if (S.size() != T.size()-1) {
        cout << "No" << endl;
        return;
    }
    bool answer = true;
    rep(i,0,S.size()) {
        if (S[i] != T[i]) {
            answer = false;
            break;
        }
    }
    cout << (answer ? "Yes" : "No") << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int a[n],x[n][n],y[n][n];
	for(int i=0;i<n;i++){
		cin >> a[i];
		for(int j=0;j<a[i];j++){
			cin >> x[i][j] >> y[i][j];
		}
	}
	// keisan
	int ans = 0;
	for(int bit = 0;bit < (1<<n);bit++){
		int kari = 0;
		int flag = 1;
		for(int i=0;i<n;i++){
			if(bit & (1<<i)){
				kari++;
				for(int j=0;j<a[i];j++){
					int s = x[i][j] -1;
					if(y[i][j] == 1){
						if(bit & (1<<s)){
							continue;
						}else{
							flag = 0;
						}
					}else{
						if(bit & (1<<s)){
							flag = 0;
						}else{
							continue;
						}
					}
				}
			}
		}
		if(flag){
			ans = max(ans,kari);
		}
	}
	// syutsuryoku
	cout << ans << endl;
}

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

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
 
int main(){

	int n;
	cin>>n;

	PRINT(n*(n+1)/2);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll; 

int s;

int f(int n) {
    if (n % 2 == 0) return n/2;
    else return 3 * n + 1;
}

int main() {
    cin >> s;
    map<int, int> hash;
    int ans = 0;
    while (true) {
        ans++;
        if (hash[s] == 1) break;
        else {
            hash[s]++;
            s = f(s);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n;
	cin>>n;
	string s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j){
				break;
			}
			if(s[i]==s[j]){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	for (int i=0;i<n-1;i++){
		if(s[i][s[i].size()-1]==s[i+1][0]){
		}
		else{
          cout<<"No"<<endl;
          return 0;
	    }
    }	
    cout<<"Yes"<<endl;
}

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

typedef long long ll;
ll a[100005];

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  double d, t, s;
  cin >> d >> t >> s;
  double time = d / s;
  if (time <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    long N;
    cin >> N;
    vector <string> S(N);
    string buf;
    for(long i = 0; i < N; i++){
      cin >> buf;
      S[i] = buf;
    }
    sort(S.begin(), S.end());
  
    long ans = N;
  	for(long i = 1; i < N; i++){
      if(S[i] == S[i - 1]){
        ans--;
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
S = input()
length = 0
tmp = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        tmp += 1
    else:
        tmp = 0
    length = max(length, tmp)
print(length)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int x,a,b;
	cin>>x>>a>>b;
	if(llabs(a-x)<llabs(b-x)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
}

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


void swap(int *a,int *b){

	int t=*a;
	*a = *b;
	*b = t;

}

int main(int argc, char const *argv[])
{
	
	int a,b,c;
	cin>>a>>b>>c;
	swap(&a,&b);
	swap(&a,&c);
	cout << a<<" "<<b<<" "<<c << endl;

	return 0;
		
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


int N, K;
vi a;
VV<int> fp, fs;


int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> N >> K;

	a.assign(N + 1, 0);

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

	fp.assign(N + 2, V<int>(K + 1, 1e9 + 1e6));
	fs.assign(N + 2, V<int>(K + 1, 1e9 + 1e6));

	for (int i = 0; i <= N + 1; ++i)
		fp[i][0] = fs[i][0] = 0;

	for (int i = 1; i <= N; ++i) {
		for (int x = 1; x <= K; ++x) {
			fp[i][x] = min(fp[i - 1][x], a[i] + fp[i - 1][max(x - a[i], 0)]);
		}
	}

	for (int i = N; i >= 1; --i) {
		for (int x = 1; x <= K; ++x) {
			fs[i][x] = min(fs[i + 1][x], a[i] + fs[i + 1][max(x - a[i], 0)]);
		}
	}

//	for (int i = 0; i <= N + 1; ++i) {
//		cout << fp[i] << '\n';
//	}

	int ans = 0;

	for (int i = 1; i <= N; ++i) {
		int mnSum = 1e9 + 1e6;
		int y = max(0, K - a[i]);
		for (int x = 0; x <= y; ++x)
			mnSum = min(mnSum, fp[i - 1][x] + fs[i + 1][y - x]);

		db(mnSum);

		if (mnSum >= K)
			++ans;
	}

	cout << ans << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 196096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long A,B,C,K;
    cin>>A>>B>>C>>K;
    if(A+B>=K){
        if(A<=K){
        cout << A << endl;
        return 0;
        }else{
            cout <<K<<endl;
            return 0;
        }
    }

    cout << A-(K-A-B) << endl;
    return 0;
}

Measured memory_bytes: 3644
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()

ans = 0

for i in range(1,N+1):
    x = i%K
    if -2*x %K ==0:
        s = -x%K
        if s==0: s=K
        ans += ((N-s)//K + 1)**2

print(ans)

Measured memory_bytes: 40300
import math
N,D=map(int,input().split())
ans=0
place=[[0]*D for _ in range(N)]
for i in range(N):
  place[i]=list(map(int,input().split()))
for i in range(N-1):
  for j in range(i+1,N):
    d_squared=0
    for k in range(D):
      d_squared+=(place[i][k]-place[j][k])**2
    if math.sqrt(d_squared)-int(math.sqrt(d_squared))<1/(10**10):
      ans+=1
print(ans)

Measured memory_bytes: 3064
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;



int main()
{




     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

     
     ll a,b,c;
     cin>>a>>b>>c;
     if(c<a+b)
     {
     	cout<<"No";
     }
     else
     {
   ll val=c-a-b;
   val=val*val;
   if(4*a*b<(val))
   {
   	cout<<"Yes";
     }
     else
     {
     	cout<<"No";
     }
   }
   



    ///////////////////////////////////////////////////////////////////////////////////////

     return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main (){
  int d, e, i;
  double diff, min, x, y;
  

  while(1){
    scanf("%d%d", &d, &e);
    if(d==0 && e==0){
      break;
    }
    min=100;
    for(i=0; i<d; i++){
      x = i*i;
      y = (d-i)*(d-i);
      if(sqrt(x+y) > e){
	diff = sqrt(x+y) - e;
      }else{
	diff = e - sqrt(x+y);
      }
      if(min > diff){
	min = diff;
      }
    }

    int number;
    double sum;
    
    number = min;
    sum = min - number;

    if(sum==0)printf("%.0f\n",min);
    else printf("%.10f\n",min);
    
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>

using namespace std;

string S, T;
int sum_S[100001];
int sum_T[100001];
int q;

int main() {
  cin >> S;
  
  for(int i = 0; i < S.length(); i++) {
    if(S[i] == 'A')sum_S[i+1] = sum_S[i] + 1;
    else sum_S[i+1] = sum_S[i] + 2;
  }
				     
  cin >> T;

   for(int i = 0; i < T.length(); i++) {
     if(T[i] == 'A')sum_T[i+1] = sum_T[i] + 1;
    else sum_T[i+1] = sum_T[i] + 2;
  }
 


  cin >> q;
  int a[q],b[q],c[q],d[q];

  for(int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  for(int i = 0; i < q; i++) {
    int tmp,tmp2;
    tmp = sum_S[b[i]]   - sum_S[a[i]-1];
    tmp2 = sum_T[d[i]]   - sum_T[c[i]-1];
    if((tmp % 3) == (tmp2 % 3))cout << "YES" <<endl;
    else cout << "NO" <<endl;
  }
    
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi c(n-1),s(n-1),f(n-1);
	rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
	rep(i,n-1){
		int t = s[i];
		for(int j=i; j<n-1; j++){
			t = max(t,s[j]);
			t += (f[j]-(t%f[j]))%f[j];
			t += c[j];
		}
		cout << t << endl;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N;
bool b[100010];
bool ans[100010];

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		char c;
		scanf(" %c" , &c);
		b[i] = c == 'o';
	}
	repp(k,0,4){
		ans[0] = k % 2 == 0;
		ans[1] = k / 2 == 0;
		repp(i,2,N){
			ans[i] = b[i-1] ^ ans[i-2] ^ ans[i-1];
		}
		if((ans[0] == ans[N-1] ^ ans[N-2] ^ b[N-1]) && (ans[N-1] == ans[0] ^ ans[1] ^ b[0])){
			repp(i,0,N){
				printf("%c" , ans[i] ? 'S' : 'W');
			}
			printf("\n");
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll n,m;
	cin>>n>>m;
	vvi adj(n);
	rep(i,m){
	    int a,b;
	    cin>>a>>b;
	    adj[a-1].push_back(b-1);
	    adj[b-1].push_back(a-1);
	}
	vi depth(n,-1);
	queue<int> q;
	q.push(0);
	bool isOdd=false;
	while(!q.empty()){
	    int p=q.front();
	    q.pop();
	    for(auto&d:adj[p]){
	        if(depth[d]==-1){
	            depth[d]=depth[p]+1;
	            q.push(d);
	        }else{//閉路
	            if(depth[d]%2!=(depth[p]+1)%2){//奇数頂点の閉路
	                isOdd=true;
	            }
	        }
	    }
	}
	if(isOdd){
	    cout<<n*(n-1)/2-m<<endl;
	}else{
	    ll node_even,node_odd,cnt=0;
	    rep(i,n){
	        for(auto&d:adj[i]){
    	        if(depth[i]%2!=depth[d]%2)cnt++;
	        }
	    }
	    node_even=count_if(all(depth),[](int a){return a%2==0;});
	    node_odd=n-node_even;
	    cnt/=2;
	    cout<<node_even*node_odd-cnt<<endl;
	}
	return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 55;

bool check(int ans){
	int arr[8] = {292, 146, 73, 7, 56, 448, 273, 84};
	lp(i, 8){
		if(((arr[i] & ans) == arr[i]))
			return 1;
	}
	return 0;
}

int main()
{
	init();
	map<int, int> m;
	int n, ans = 0;
	lpi(i, 1, 10){
		cin >> n;
		m[n] = i;
	}
	cin >> n;
	lp(i, n){
		int b;
		cin >> b;
		if(m[b]){
			ans |= (1 << (m[b]-1));
		}
	}
	cout << (check(ans)?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A, B, K, i, C;
  scanf("%d %d %d", &A, &B, &K);
  
  C = A + K;
  if(C > B){
    C = B + 1;
  }
  for (i = A; i < C; i++){
    printf("%d\n", i);
  }
  C = B - K + 1;
  if(i > C){
    C = i;
  }
  for (i = C; i <= B; i++){
    printf("%d\n", i);
  }
  
  return 0;
}
    

Measured memory_bytes: 128
import sys
import bisect
nq = int(input())
lines = sys.stdin.readlines()
ans = [None] * nq
arr = []
for i in range(nq):
    q, *arg = lines[i].split()
    x = int(arg[0])
    l_idx = bisect.bisect_left(arr, x)
    r_idx = bisect.bisect_right(arr, x)
    if q == '0':    # insert x
        arr.insert(l_idx, x)
        ans[i] = str(len(arr))
    elif q == '1':   # find x
        ans[i] = r_idx - l_idx
    elif q == '2':           # delete x
        arr[l_idx:r_idx] = []
    else:                   # dump L R
        r_idx = bisect.bisect_right(arr, int(arg[1]))
        ans[i] = '\n'.join(map(str, arr[l_idx:r_idx])) if l_idx != r_idx else None
    #print(q, *arg, '\t', arr, '\t', ans[i])

[print(x) for x in ans if x is not None]


Measured memory_bytes: 51044
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int total = 0;
		for (int i = 0; i < k; i++) {
			total += arr[n - 1 - i];
		}
		
		System.out.println(total);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define sp putchar(' ')
#define en putchar('\n')
#define MOD(x) ((((x)%Mod)+Mod)%Mod)
const int MAXN = 500005 ;
using namespace std ;
class Union_Find_Set
{
static const int N = 2000005;
public:
    int tot/**现有的集合数量*/,cnt[N]/**每个集合有多少人*/,fa[N] ;
    void clear(int n)
    {
        tot = n; ///开始没有合并的时候,每个都是单独的集合.
        iota(fa,fa+n+1,0) ; fill_n(cnt,n+1,1) ;
    }
    int find(int x) ///找x的根
        {return x == fa[x]?x:fa[x] = find(fa[x]) ;}
    int count(int x)///得到元素x所在的集合的人数
        {return cnt[find(x)] ;}
    int size() {return tot ;}
    bool is_same(int a,int b)///判断是不是在同一个集合
        {return find(a)==find(b);}
    int merge(int a,int b)
    {///合并两个集合
        a = find(a);b = find(b) ;
        if(a != b) {
            fa[b] = fa[a] ; cnt[a] += cnt[b];
            -- tot ;
        }
        return tot ;
    }
}S;

int n , m ;
int main()
{
    ios::sync_with_stdio(false) ;
    while(cin >> n >> m) {
        S.clear(n + 3) ;
        for(int i = 0;i < m; ++i) {
            int u,v ;
            cin >> u >> v ;
            S.merge(u, v) ;
        }
        int ans = 0 ;
        for(int i = 1;i <= n; ++ i) {
            ans = max(ans, S.count(i)) ;
        }
        cout << ans << endl ;
    }
}


Measured memory_bytes: 5200
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




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

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;

ll col[100005];

void dfs(ll K, ll dist) {

	
	d[K] = dist;
	vis[K] = 1;

		
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i]] == 0) {
			
			dfs(M[K][i], dist + 1);
			
		}
	}

}



vector<unsigned long long> v;


vector<ll> e[10];


ll kotae;
void dfs3(ll K, ll length, ll m) {
	
	if (length == m) {

		kotae += 1;
	}


	for (int i = 0; i < e[K].size(); i++) {

		if (vis[e[K][i]] == 0) {
			vis[e[K][i]] = 1;
			dfs3(e[K][i], length + 1, m);
			vis[e[K][i]] = 0;
		}
	}

}



int main() {
	ll N, M;
	ll a, b;
	cin >> N >> M;


	rep(i, M) {
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	vis[1] = 1;

	dfs3(1, 1, N);

	
	cout << kotae << endl;

	return 0;
	
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define print(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int n;
	cin>>n;
	int a[n+1],cost[n+1][n+1],sum[n+1][n+1];
	loop(i,1,n+1) 
	{	
		cin>>a[i];
		cost[i][i] = 0;
	}
	
	init(sum,0);
	loop(i,1,n+1)
		loop(j,1,n+1)
		{
			if(i!=j) cost[i][j] = INF;
			if(i<=j)
				sum[i][j] = a[j] + sum[i][j-1];	
		}
	
	loop(j,1,n+1)
		for(int i=j-1;i>0;i--)
			loop(l,0,j-i) 
				cost[i][j] = min(cost[i][j], sum[i][i+l] + sum[i+l+1][j] + cost[i][i+l] + cost[i+l+1][j]);
	cout<<cost[1][n]<<endl;
	return 0;		
}

Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

struct Edge {
public:
	int from, to, cost;
	Edge() {}
	Edge(int _from, int _to, int _cost) {
		from = _from;
		to = _to;
		cost = _cost;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<int, int> P;

vi dijkstra(int s, Graph G) {//s=>始点
	priority_queue<P, vector<P>, greater<P> > que;
	vi D(SZ(G), INF);
	D[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first)continue;

		for (Edge e : G[v]) {
			if (D[e.to] > D[v] + e.cost) {
				D[e.to] = D[v] + e.cost;
				que.push(P(D[e.to], e.to));
			}
		}
	}
	return D;
}

Edge solve(Graph G) {
	vi d = dijkstra(0, G);
	int mind = 0;
	int v = 0;
	REP(i, SZ(G)) {
		if (i == 0)continue;
		if (d[i] > mind) {
			mind = d[i];
			v = i;
		}
	}
	d = dijkstra(v, G);
	mind = 0;
	int vv = 0;
	REP(i, SZ(G)) {
		if (i == v)continue;
		if (d[i] > mind) {
			mind = d[i];
			vv = i;
		}
	}
	return Edge(v, vv, d[vv]);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	Graph G(N);

	REP(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		G[a].push_back(Edge(a, b, 1));
		G[b].push_back(Edge(b, a, 1));
	}
	Edge e = solve(G);
	
	if (e.cost % 3 != 1) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}


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

int main() {
	int N;
	long M=0;
	long A=0;
	long R=0;
	long C=0;
	long H=0;
	cin >>N;
	for (int i=0; i<N; i++) {
		string S;
		cin >>S;
		char s=S.at(0);
		if ('M'==s)
			M++;
		else if ('A'==s)
			A++;
		else if ('R'==s)
			R++;
		else if ('C'==s)
			C++;
		else if ('H'==s)
			H++;
	}
	long SS=0;
	SS +=M*A*(R+C+H);
	SS +=M*R*(C+H);
	SS +=M*C*H;
	SS +=A*R*(C+H);
	SS +=A*C*H;
	SS +=R*C*H;
	cout << SS << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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() {
    int n; cin >> n;
    vector<int> a(n-1);
    rep(i, n-1) cin >> a[i];

    vector<int> buka(n, 0);
    rep(i, n-1) buka[a[i]-1]++;
    rep(i, n) {
        cout << buka[i] << endl;
    }
}


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

#define MAX 100

void show_array(int *a, int n)
{
     int i;
     
     for (i = 0; i < n; i++) {
         if (i > 0) printf(" ");
         printf("%d", a[i]);    
     }
     printf("\n");
}

void bubble_sort(int *a, int n)
{
    int cnt = 0, i, j, t;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n - i - 1; j++) {
            if (a[j] > a[j + 1]) {
               t = a[j];
               a[j] = a[j+1];
               a[j+1] = t;
               cnt++; 
            }    
        }
    }
    show_array(a, n);
    printf("%d\n", cnt);
}

int main(int argc, char *argv[])
{
	int i, n, a[MAX];

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

	bubble_sort(a, n);
  	
	return 0;
}


Measured memory_bytes: 2104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            Map<Integer, Integer> cnt = new HashMap<>();
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                if (cnt.containsKey(a[i])) {
                    cnt.put(a[i], cnt.get(a[i]) + 1);
                } else {
                    cnt.put(a[i], 1);
                }
            }

            Arrays.sort(a);
            long ans = 0;
            long best4 = 0;
            long best1 = 0;
            long best2 = 0;
            for (Map.Entry<Integer, Integer> e : cnt.entrySet()) {
                long k = e.getKey();
                long v = e.getValue();
                if (v >= 4) {
                    if (k > best4) {
                        best4 = k;
                    }
                }
                if (v >= 2) {
                    if (k > best1) {
                        best2 = best1;
                        best1 = k;
                    } else if (k > best2) {
                        best2 = k;
                    }
                }
            }

            ans = Math.max(best4 * best4, best1 * best2);
            out.println(ans);
        }

    }
}



Measured memory_bytes: 67680
A, B, C, D, E, F = map(int, input().split())
ans = 0
answ = A*100
anss = 0
for a in range(30//A+1):
    for b in range((30-a*A)//B+1):
        # print(a, b)
        w = (a*A + b*B) * 100
        if w > F:
            break
        elif w == 0:
            continue
        # print(a, b)
        sc = (w / 100) * E
        # print(E, sc)
        for c in range(int(sc//C)+1):
            for d in range(int((sc-c*C)//D)+1):
                s = c*C + d*D
                if s > sc or w + s > F:
                    break
                tmp = s / (w + s)
                # print(a, b, s, sc, tmp)
                if ans < tmp:
                    ans = tmp
                    answ = w
                    anss = s
print(answ+anss, anss)

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

int main() {
    vector<int> wa(2);
    for (int i = 0; i < 2; i++){
        cin >> wa.at(i);
    }
    int ans = 1;
    for (int i = 0; i < 4; i++){
        if (wa.at(0) == ans || wa.at(1) == ans){
            ans++;
        }
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; ll w; cin >> n >> w;
    vector<vector<int> > ob(4);
    ll a,b; cin >> a >> b;
    a--;
    ob[0].push_back(b);
    rep(i,n-1){
        ll o; int v; cin >> o >> v;
        ob[o-a-1].push_back(v);
    }
    rep(i,4){
        sort(all(ob[i]));
        reverse(all(ob[i]));
    }

    int ans=0;

    rep(i,ob[0].size()+1){
        rep(j,ob[1].size()+1){
            rep(z,ob[2].size()+1){
                rep(k,ob[3].size()+1){
                    int tmp=0;
                    rep(ii,i) tmp+=ob[0][ii];
                    rep(jj,j) tmp+=ob[1][jj];
                    rep(zz,z) tmp+=ob[2][zz];
                    rep(kk,k) tmp+=ob[3][kk];
                    ll tmpw=(ll)(i*(a+1))+(ll)(j*(a+2))+(ll)(z*(a+3))+(ll)(k*(a+4));
                    if(tmpw<=w) ans=max(ans,tmp);
                }
            }
        }
    }

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



Measured memory_bytes: 3640
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

const ll MAX = 1001000;
const ll MOD = 1000000007;

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

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

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

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;cin>>x>>y;
    if((x+y)%3 != 0){
        cout<<"0"<<endl;
        return 0;
    }else{

    ll r = (2*y - x)/3;
    ll l = (2*x - y)/3;
    if(r<0 || l<0){
        cout<< 0<< endl;
        return 0;
    }
    ll  m = l+r;

    COMinit();
    int ans =  COM(m,r);
    cout<<ans<<endl;
    return 0;
    }

}

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

int main() {
  int K, N, ans = 0;
  cin >> N >> K;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    mp[A]++;
  }
  vector<int> v;
  for (auto m : mp) {
    v.push_back(m.second);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < max((int)v.size() - K, 0); i++) {
    ans += v[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 10748
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            input_iter = LazyLoadAllLines();
            //------------------------------------------------//
            //var n = Read<long>();
            //var m = Read<long>();
            var a = Read<long>();
            var b = Read<long>();
            //var c = Read<long>();
            //var x = Read<long>();
            //var als = Read<long>(n);
            //List<long> als = new List<long>(), bls = new List<long>();
            //List<List<long>> cls = new List<List<long>>();
            /*for (int i = 0; i < m; ++i)
            {
                als.Add(Read<long>());
                bls.Add(Read<long>());
                cls.Add(Read<long>(bls[i]));
            }*/




            //als.Sort((l, r) => (int)(r - l));

            Console.WriteLine(Math.Max(a - 2 * b, 0));

        }

        static IEnumerator<string> input_iter;

        static _T Read<_T>() where _T : struct
        {
            input_iter.MoveNext();
            return (_T)Convert.ChangeType(input_iter.Current, typeof(_T));
        }
        static string Read()
        {
            input_iter.MoveNext();
            return input_iter.Current;
        }
        static List<_T> Read<_T>(long num) where _T : struct { return new List<_T>(Enumerate<_T>(num)); }


        static IEnumerable<_T> Enumerate<_T>(long num)
        {
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                yield return (_T)Convert.ChangeType(input_iter.Current, typeof(_T));
            }
        }
        static IEnumerator<string> LazyLoadAllLines()
        {
            string line;
            do
            {
                line = Console.ReadLine();
                foreach (var s in line.Split(' '))
                    yield return s;
            } while (line != null);
        }
    }
}


Measured memory_bytes: 11220