akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int r, g, b, n, cnt = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i * r <= n; i++) {
    for (int j = 0; i * r + j * g <= n; j++) {
      if ((n - i * r - j * g) % b == 0) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3592
import numpy as np
# たいてい全部良い符号でとれる
N = int(input())
A = np.array(input().split(),dtype = np.int32)
# インデックス要らないので
A.sort()
A = A[::-1] # desc

positive = (A > 0).sum()
negative = (A <= 0).sum()

A = list(A)
operations = []

if positive == 0:
  # 全部negative
  # 最大値だけプラスでとって、あとは全部引く
  x = A[0]
  for y in A[1:]:
    operations.append((x,y))
    x -= y
  answer = x
elif negative == 0:
  x = A[-1]
  for y in A[1:-1]:
    operations.append((x,y))
    x -= y
  operations.append((A[0],x))
  answer = A[0] - x
else:
  x = A[0] # positive
  y = A[-1] # negative
  for z in A[1:-1]:
    if z > 0:
      operations.append((y,z))
      y -= z
    else:
      operations.append((x,z))
      x -= z
  operations.append((x,y))
  answer = x - y
  
print(answer)
for x,y in operations:
  print(x,y)

Measured memory_bytes: 30276
#include <stdio.h>
int prime(int);
int main(){
  int n,i,j,s,sum=0,a[10000];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  for(i=0; i<n; i++){
    s=prime(a[i]);
    if(s==1) sum++;
  }
  printf("%d\n",sum);
  return 0;
}
int prime(int a){
  int i;
  if(a<2) return 0;
  else if(a==2) return 1;
  if(a%2==0) return 0;
  for(i=3; i<=a/i; i+=2){
    if(a%i==0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2056
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int r, g, b, n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> r>>g>>b>>n;
    ll ans=0;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=n/g;j++){
            if((n-r*i-g*j)%b==0&&(n-r*i-g*j)/b>=0){
                    ans++;
                }
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int c=0,a,n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(mp.count(a)==0){
        mp[a]=1;
        c++;
        }
    }
    cout<<c<<endl;
     return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
road=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)
ischecked=[0]*(N)
ans=0
for i in range(N):
    if ischecked[i]==1:
        continue
    ischecked[i]=1
    q=[i]
    while q:
        now=q.pop()
        nex=road[now]
        for j in nex:
            if ischecked[j]!=0:
                continue
            q.append(j)
            ischecked[j]=1
    ans+=1
print(ans-1)

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

using namespace std;

int main() {
	unordered_map<string, int> map;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		map[s]++;
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		string s;
		cin >> s;
		map[s]--;
	}
	int res = 0;
	for (auto i = map.begin(); i != map.end(); i++) {
		res = max(res, i->second);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n;
    cin>>n;
    vector<string>x;
    x.push_back("3");
    x.push_back("5");
    x.push_back("7");
    int lower = 0;
    int upper = 2;
    while(true){
        for(int i=lower;i<=upper;i++){
            x.push_back(x[i]+"3");
            x.push_back(x[i]+"5");
            x.push_back(x[i]+"7");
        }
        lower+=3;
        upper+=3;
        if(x[x.size()-1].length()>10){
            break;
        }
    }
    int ans = 0;
    for(int i=0;i<x.size();i++){
       int counter=0;
       bool found3=false;
       bool found5=false;
       bool found7=false;
       string s = x[i];
       for(int j=0;j<s.length();j++){
            if(s[j]=='3'&&!found3){
                found3=true;
                counter++;
            }
            if(s[j]=='5'&&!found5){
                found5=true;
                counter++;
            }
            if(s[j]=='7'&&!found7){
                found7=true;
                counter++;
            }
       }

       long long int u=stoll(s);
       if(counter==3&&u<=n){
         ans++;
       }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5364
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
    double a, b, c;
    double s1, l1, h1;
    double temp1;
    
    s1=0;
    l1=0;
    h1=0;
    
    cin >> a >> b >> c;
    
    //cout << M_PI << endl;
    temp1=sin(M_PI/180 * c);
    
    //cout << temp1 << endl;
    
    s1 = 0.5 * a * b * temp1;
    l1 = a + b + sqrt(a*a+b*b-2*a*b*cos(M_PI/180 * c));
    //cout << s1 << endl;
    h1 = b * temp1;
    
    printf("%-20.8f\n",s1);
    printf("%-20.8f\n",l1);
    printf("%-20.8f\n",h1);
    
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  for(int i=0;i<=N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  long long sum=0;
  long long M=0;
  for(int i=0;i<N;i++){
    M=min(A.at(i),B.at(i));
    sum += M;
    B.at(i) = B.at(i) - M;
    M=min(B.at(i),A.at(i+1));
    sum += M;
    A.at(i+1) = A.at(i+1) - M;
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N, M;
  cin >> N >> M;
  if (N == M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import math
N,D=map(int,input().split())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

ans=0
for j in range(N):
    if D>=math.sqrt(x[j]**2+y[j]**2):
        ans+=1
print(ans)

Measured memory_bytes: 116748
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
#define fi first
#define se second
#define debug if(DEBUG)
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

bool DEBUG=true;

int main(){
  int N; cin>>N;
  vec<int> A(N); cin>>A;
  vec<ll> s(N+1,0);
  rep(i,N) s[i+1]=s[i]+A[i];
  
  ll ans=LLONG_MAX;
  int l=1,r=3;
  for(int c=2; c<N-1; ++c){
    valarray<ll> sum(4);
    while(l+1<c&&abs(2*s[l]-s[c])>abs(2*s[l+1]-s[c])) ++l;
    while(r+1<N&&abs(2*s[r]-s[c]-s[N])>abs(2*s[r+1]-s[c]-s[N])) ++r;
    sum[0]=s[l]     ,sum[1]=s[c]-s[l];
    sum[2]=s[r]-s[c],sum[3]=s[N]-s[r];
    ans=min(ans,sum.max()-sum.min());
    if(c+1==r) ++r;
  }
  cout<<ans;
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


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

    if(n%2==1){
            cout << 0 << endl;
    }else{
            ll np = n / 2;
            ll co = 0;
            ll j = np /5;
            while (j > 0) {
                co += j;
                j /= 5;
            }
            cout << co << endl;
    }
}



Measured memory_bytes: 256
N = int(input())
D,X = map(int,input().split(' '))
A = list(int(input()) for i in range(N))
num = 0
for i,j in enumerate(A):
  x = 1
  y = j
  while y+1  <= D:
    x += 1
    y += j
  num += x
print(num + X)  
  

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string s;
	vector<vector<char>>v(7, vector<char>(7));
	char a = 'a';
	rep(j, 1, 7) {
		rep(i, 1, 6) {
			v[i][j] = a++;
		}
	}

	v[2][6] = '.'; v[3][6] = '?'; v[4][6] = '!'; v[5][6] = ' ';
	rep(i, 0, 6)dumpc(v[i]);
	while (cin >> s) {
		string ans;
		if (s.size() & 1) {
			cout << "NA" << endl;
			continue;
		}
		bool f(false);
		rep(i, 0, s.size()) {
			if (!('1' <= s[i] && s[i] <= '6')) {
				cout << "NA" << endl;
				goto here;
			}
		
		}
		for (int i = 0; i + 1 < s.size(); i += 2) {
			if (s[i + 1] == '6') {
				cout << "NA" << endl;
				goto here;
			}
			ans += v[s[i + 1] - '0'][s[i] - '0'];
		}
		cout << ans << endl;
	here:
		;
	}
	return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int MAXW = 100005;
const int inf = 1.01e9;
using lint = long long;
using pi = pair<lint, lint>;

int n, x, d;
int m[MAXN], p[MAXN], sz[MAXN];
lint dp[MAXW]; 

struct backtrack{
	lint cost, value, index, howmuch;
};

int frm[MAXW];
struct item{
	int cost, profit, amount, fuck;
	bool operator<(const item &i)const{
		return 1ll * profit * i.cost > 1ll * i.profit * cost;
	}
}gord[MAXN];

int greedy(vector<item> &v, int budget){
	int ret = 0;
	for(auto &i : v){
		int pos_ord = min(budget / i.cost, i.amount);
		ret += pos_ord * i.profit;
		budget -= pos_ord * i.cost;
	}
	return ret;
}

int main(){
	cin >> n >> x >> d;
	for(int i=1; i<=n; i++){
		cin >> m[i];
		if(i > 1) cin >> p[i];
		sz[i] = 1;
	}
	for(int i=n; i>1; i--){
		m[p[i]] += m[i];
		sz[p[i]] += sz[i];
		m[p[i]] = min(m[p[i]], inf);
	}
	vector<backtrack> v;
	for(int i=1; i<=n; i++){
		lint cost = sz[i];
		lint val = m[i];
		int amnt = (i > 1 ? d : ((1<<30) - 1));
		int aamnt = amnt;
		amnt = min(amnt, 50);
		for(int j=0; (1 << j) <= amnt; j++){
			if((cost << j) >= MAXW) break;
			v.push_back({cost << j, val << j, i, 1 << j});
			amnt -= (1 << j);
		}
		if(amnt && cost * amnt < MAXW){
			v.push_back({cost * amnt, val * amnt, i, amnt});
		}
		gord[i-1] = {(int)val, (int)cost, aamnt, i};
	}
	sort(gord, gord + n);
	for(auto &i : v){
		for(int j=0; j<n; j++){
			if(gord[j].fuck == i.index){
				i.index = j;
				break;
			}
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	int FUCK = 0;
	for(auto &j : v){
		for(int k=MAXW - 1; k >= j.cost; k--){
			if(dp[k] > dp[k - j.cost] + j.value){
				dp[k] = dp[k - j.cost] + j.value;
				frm[k] = FUCK;
			}
		}
		FUCK++;
	}
	int ret = 0;
	for(int i=0; i<MAXW; i++){
		if(dp[i] <= x){
			vector<item> idkidkidk(gord, gord + n);
			for(auto &j : idkidkidk) j.amount = max(0, j.amount - 50);
			ret = max(ret, i + greedy(idkidkidk, x - dp[i]));
		}
	}
	cout << ret << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

using namespace std;
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

int main(void) {
	LL N;
	cin >> N;
	VI six(10),nine(10);
	vector<long> dp(N+1,1);
	six[0] = 6;nine[0] = 9;
	FOR(i,1,10) {
		six[i] = six[i-1]*6;
		nine[i] = nine[i-1]*9;
	}

	//dump1d_arr(six);
	//dump1d_arr(nine);

	if (N >= 6) REP(i,6) dp[i] = i;
	else {
		cout << N << endl;
		exit(0);
	}

	FOR(i,6,N+1) {
		dp[i] = dp[i-1] + 1;
		REP(j,10) {
			if (i - six[j] >= 0) dp[i] = min(dp[i-six[j]]+1,dp[i]);
			if (i - nine[j] >= 0) dp[i] = min(dp[i-nine[j]]+1,dp[i]);
		}
	}
	//dump1d_arr(dp);
	cout << dp[N] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

lli n;
lli a[410];
lli b[410];

lli dp[410][410];
lli vis[410][410];

void init(){
	b[0]=a[0];
	REP(i,1,n)b[i] = b[i-1]+a[i];
}

lli get(lli l,lli r){
	lli res = b[r];
	if(l)res-=b[l-1];
	return res;
}

lli calc(lli l,lli r){
	if(l==r)return 0;
	if(vis[l][r])return dp[l][r];
	vis[l][r]=1;

	lli minA = INF;
	REP(c,l,r+1){
		minA = min(minA,calc(l,c)+calc(c+1,r)+get(l,r));
	}

	return dp[l][r] = minA;
}

signed main(){

	cin>>n;
	REP(i,0,n)cin>>a[i];
	lli cost = 0;

	init();
	cout<<calc(0,n-1)<<endl;

	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(void){
  ll n;
  cin >> n;
  n%=1000;
  cout << (1000-n)%1000;
}

Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	while (N) {
		int num[21][21] = {};
		for (int i = 0; i < N; i++) {
			int a, b;
			cin >> a >> b;
			num[a][b]++;
		}
		cin >> M;
		int x = 10;
		int y = 10;
		if (num[x][y]) {
			num[x][y]--;
			N--;
		}
		for (int i = 0; i < M; i++) {
			string c;
			cin >> c >> K;
			if (c == "N") {
				for (int j = y + 1; j <= y + K; j++) {
					if (num[x][j]) {
						num[x][j]--;
						N--;
					}
				}
				y += K;
			}
			if (c == "S") {
				for (int j = y -1; j >= y - K; j--) {
					if (num[x][j]) {
						num[x][j]--;
						N--;
					}
				}
				y -= K;
			}
			if (c == "E") {
				for (int j = x + 1; j <= x + K; j++) {
					if (num[j][y]) {
						num[j][y]--;
						N--;
					}
				}
				x += K;
			}
			if (c == "W") {
				for (int j = x -1; j >= x - K; j--) {
					if (num[j][y]) {
						num[j][y]--;
						N--;
					}
				}
				x -= K;
			}
		}
		if (!N) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 3196
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;
struct node{
    LL w;
    int id;
}a[N<<2];
bool cmp(node a, node b){
    return a.w < b.w;
}
int cnt;
int r, c, n;
bool ok(int x, int id){
    if(id == 1){
        return x==0 || x==r;
    }
    else{
        return x==0 || x==c;
    }
}
LL get(LL x, LL y)
{
    if(x==0 || y==c) return x+y;
    else if(x == r){
        return -(x+y)+1LL*(r+c)*100;
    }
    else if(y == 0){
        return -(x+y)+1LL*(r+c)*1000;
    }
}
stack<int>s;
int vis[N];
int main()
{


    SCCC(r, c, n);
    FF(i, 1, n)
    {
        int x1, y1, x2, y2; SCC(x1, y1); SCC(x2, y2);
        if((ok(x1, 1)||ok(y1, 2)) && (ok(y2, 2)||ok(x2, 1))){
            a[++cnt].w = get(x1, y1); a[cnt].id = i;
            a[++cnt].w = get(x2, y2); a[cnt].id = i;
        }
    }
    sort(a+1, a+1+cnt, cmp);
    int yes = 1;
    FF(i, 1, cnt)
    {
        int id = a[i].id;
        if(!vis[id])
            s.push(id), vis[id] = 1;
        else{
            if(s.top() == id)
                s.pop();
            else{
                yes = 0; break;
            }
        }
    }
    if(yes) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 4480
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sun Apr 19 17:55:02 2020

*/ 
#include<bits/stdc++.h>
using namespace std;


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 int arr[N];
 
int solve() {
 

 	int n=Int;
 	
 	For(n-1) {
 		int x=Int;
 		arr[x]++;
 	}
 	for(int i=1;i<=n;i++){
 		cout<<arr[i]<<endl;
 	}
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 4540
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
    for(int i=19;i<=89;i+=10)
    {
        a[i]=1;
    }
    for(int i=90;i<=99;i++)
        a[i]=1;
    int n;
    cin>>n;
    if(a[n])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
#define Maxn 200010
bool vis[Maxn];
int cnt[Maxn][2],p[Maxn],fa[Maxn];
struct Node{
	int x,v0,v1;
	Node(){x=v0=v1=0;}
	Node(int _x,int _v0,int _v1){x=_x;v0=_v0;v1=_v1;}
	bool operator <(const Node &t)const{return 1ll*v1*t.v0>1ll*t.v1*v0;}
};
priority_queue<Node> Q;

int getroot(int x){
	if(fa[x]!=x)fa[x]=getroot(fa[x]);
	return fa[x];
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	ll Ans=0;
	rd(n);
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=2;i<=n;++i)rd(p[i]);
	int t;
	for(int i=1;i<=n;++i){
		rd(t);
		cnt[i][t]=1;
		Q.push(Node(i,cnt[i][0],cnt[i][1]));
	}
	int sum1=0;
	while(!Q.empty()){
		Node tmp=Q.top();Q.pop();
		if(vis[tmp.x]||cnt[tmp.x][0]!=tmp.v0||cnt[tmp.x][1]!=tmp.v1)continue;
		vis[tmp.x]=true;
		int anc=getroot(p[tmp.x]);
		if(tmp.x==1||vis[anc]){
			Ans+=1ll*sum1*cnt[tmp.x][0];
			sum1+=cnt[tmp.x][1];
			continue;
		}
		Ans+=1ll*cnt[anc][1]*tmp.v0;
		cnt[anc][0]+=tmp.v0;cnt[anc][1]+=tmp.v1;
		fa[tmp.x]=anc;
		Q.push(Node(anc,cnt[anc][0],cnt[anc][1]));
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 8596
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    c = Counter(A)
    ans = 0
    for k, v in c.items():
        if k < v:
            ans += v - k
        elif k > v:
            ans += v

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22740
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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


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

const int MAXN = 1e5 + 5;

int N;
int a[MAXN];
int indeg[MAXN];
int ans[MAXN];

struct cmp {
	bool operator()(const int &lhs, const int &rhs) const {
		if (indeg[lhs] != indeg[rhs])
			return indeg[lhs] > indeg[rhs];
		return lhs < rhs;
	}
};

set <int, cmp> sorted;

void load() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", a + i);
		indeg[a[i]]++;
	}
}

void solve() {
	if (N == 2) {
		puts("-1");
		return;
	}
	
	set <int> rest;
	for (int i = 1; i <= N; i++) {
		rest.insert(i);
		sorted.insert(i);
	}
	
	for (int i = 1; i <= N - 3; i++) {
		int node = *sorted.begin();
		if (indeg[node] == N - i) 
			ans[i] = node;
		else {
			auto it = rest.begin();
			if (*it == a[ans[i - 1]])
				it++;
			ans[i] = *it;
		}
		rest.erase(ans[i]);
		sorted.erase(ans[i]);
		int dad = a[ans[i]];
		if (rest.count(dad)) {
			sorted.erase(dad);
			indeg[dad]--;
			sorted.insert(dad);
		}
	}
	
	vector <int> v;
	for (auto it : rest)
		v.push_back(it);
	
	do {
		for (int i = 0; i < v.size(); i++)
			ans[max(N - 3, 0) + i + 1] = v[i];
		bool ok = true;
		for (int i = 1; i < N; i++)
			ok &= ans[i + 1] != a[ans[i]];
		if (ok)
			break;
	} while (next_permutation(v.begin(), v.end()));
	
	for (int i = 1; i <= N; i++)
		printf("%d ", ans[i]);
	puts("");
}

int main() {
	load();
	solve();
	return 0;
}

Measured memory_bytes: 11392
#include <stdio.h>
#define change(x,y) {int t = x; x = y; y = t;}
int main(int argc, const char * argv[])
{

    int line;
    int cross;
    int i;
    int input1, input2;
    int num[31] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
        16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
    
    scanf("%d", &line);
    scanf("%d", &cross);
    
    for (i = 0; i < cross; i++) {
        scanf("%d,%d", &input1, &input2);
        change(num[input1],num[input2]);
    }
    for (i = 1; i <= line; i++) {
        printf("%d\n", num[i]);
    }
    return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<sstream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<stack>
#include<functional>
#include<utility>
#include<numeric>
#include<bitset>
#include<iterator>
#define INF (int)1e9
#define MOD 1000000007
#define tr(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define debug(x) cout<<#x" = "<<(x)<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz size
#define ll long long
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MEM(a, b) memset(a, (b), sizeof(a))
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?"\n":" ")
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?"\n":" ")
#define PRE(i, m, n, in) for(int (i)=(m);(i)<(n);i+=in)
#define RFOR(i, n) for(int i=n ; i>=0 ; i--)
#define RPRE(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define ERS(A, P) A.erase(A.begin() + P)
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define toint(a) atoi(a.c_str())
using namespace std;
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector<string> VS;
typedef vector <VS> VSS;
typedef vector <II> VII;
typedef vector <LL> VLL;
typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VII> VVII;
typedef vector <VLL> VVLL;
typedef map<int,int> MPII;
typedef map<ll,ll> MPLL;
typedef map<string, int>MPSI;
typedef map<string, ll>MPSL;
typedef map<int, string>MPIS;
typedef map<ll, string> MPLS;
typedef map<string, string> MPSS;
typedef set<int> SETI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  int n; cin >> n;
  int w; cin >> w;
  VI weight(n); VL val(n);
  FOR(i, n) {
    cin >> weight[i] >> val[i];
  }
  VVL dp(n + 1, VL(w + 1, 0));
  // print2d(dp, n + 1, w + 1);
  PRE(i, 1, n + 1, 1) {
    // weight[i], val[i]
    PRE(j, 1, w + 1, 1) {
      dp[i][j] = dp[i - 1][j];
      if(j >= weight[i - 1]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i - 1]] + val[i - 1]);
      }
    }
  }
  // print2d(dp, n + 1, w + 1);
  cout << dp[n][w] << endl;
  return 0;
}


Measured memory_bytes: 81140
sx, sy, tx, ty = map(int, input().split())
nx = ny = 0
dx = tx - sx
dy = ty - sy

ans = "R" * dx + "U" * dy + "L" * dx + "D" * dy  # 1回目
ans += "D" + "R" * (dx + 1) + "U" * (dy + 1) + "LU" + "L" * (dx + 1) + "D" * (dy + 1) + "R"  # 2回目
print(ans)


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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



int main()
{
	FASTIO;

	int n;
	cin >> n ;

	int mat[n][3];
	for(int i = 0;i<n;i++)
	{
		cin>>mat[i][0]>>mat[i][1]>>mat[i][2];
	}

	vector<int> dp(3);

	dp[0] = mat[n-1][0];
	dp[1] = mat[n-1][1];
	dp[2] = mat[n-1][2];

	for(int i = n-2;i>=0;i--)
	{
		vector<int> cur = dp;

		dp[0] = mat[i][0] + max(cur[1],cur[2]);
		dp[1] = mat[i][1] + max(cur[0],cur[2]);
		dp[2] = mat[i][2] + max(cur[0],cur[1]);

        // cout<<dp[0]<<" "<<dp[1]<<" "<<dp[2]<<endl;

	}

	int ans = max(dp[0],max(dp[1],dp[2]));
	cout<<ans;


}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
// cout<<fixed<<setprecision(10);
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 INF = 1LL << 60;
const int vm = 100100;
const int NM = 110;
ll dp[NM][vm]; // 価値がVとなるように選んだときの重さの最小値
ll w[NM], v[NM];

int main() {
    ll nn, ww; cin >> nn >> ww;
    rep(i, nn) {
        cin >> w[i] >> v[i];
    }

    rep(i, NM) {
        rep(j, vm) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for(int i=0; i<nn; i++) {
        for(int value=0; value<vm; value++) {
            // i番目を取得する時
            if(value - v[i] >= 0) {
                chmin(dp[i+1][value], dp[i][value-v[i]] + w[i]);
            }
            chmin(dp[i+1][value], dp[i][value]);
        }
    }
    ll ans = 0;
    for(int value = 0; value < vm; value++){
        if(dp[nn][value] <= ww) {
            ans = value;
        }
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 86272
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    cnt = r * g * b
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = j + j - i
            if k < n:
                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                    cnt -= 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 68060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int n, a[26], b[26] = {};
	string s[55];
	cin >> n;
	for (int i = 0; i < 26; i++) {
		a[i] = 3000;
	}
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < s[i].size(); j++) {
			b[s[i][j] - 'a']++;
		}
		for (int j = 0; j < 26; j++) {
			if (a[j] > b[j])a[j] = b[j];
			b[j] = 0;
		}
	}
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < a[i]; j++) {
			char f = 'a' + i;
			cout << f;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int n;
int a[100010];

int gcf(int a, int b){
    if (a>b) return gcf(b, a);

    if (a==0) return b;
    
    return gcf(b%a, a);
}

int main(){
    cin >> n;

    int output;
    cin >> output;
    REP(i, n-1) {
        int a;
        cin >> a;
        output = gcf(output, a);
    }

    cout << output << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int ans=0;
		for(int i=0;i<n-1;i++){
			int min=i;
			for(int j=i;j<n;j++){
				if(a[j]<a[min])
					min=j;
			}
			int temp=a[i];
			a[i]=a[min];
			a[min]=temp;
			if(i!=min)
				ans++;
		}
		cout<<a[0];
		for(int i=1;i<n;i++)
			cout<<' '<<a[i];
		cout<<endl;
		cout<<ans<<endl;
	}
	return 0;
} 


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int i,j;
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[0]+a[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 177, task a, 2020/09/010
//ms,
/*
*/

#define EPS DBL_EPSILON

bool spill_or_not(double, double, double, double);

bool spill_or_not(double theta, double a, double b, double x){
  double v;
  if(b-tan(theta)*a>=0) v=a*a*(2.0*b-tan(theta)*a)/2.0;
  else v= a*b*b/tan(theta)/2.0;

  if(x>v) return true;
  else return false;
}

int main(void){
  int a, b, x;
  cin >>a >>b >>x;

  double ng=0.0-EPS;
  double ok=M_PI/2.0+EPS;
  while(abs(ok-ng)>0.00000001){
    double mid=(ok+ng)/2.0;
    if(spill_or_not(mid, a+0.0, b+0.0, x+0.0)) ok=mid;
    else ng=mid;
  }

  printf("%2.15f", ok/M_PI*180.0);
  return 0;
}
/*
*/


Measured memory_bytes: 4144
def max(a,b); a > b ? a : b; end

Child = Struct.new(:value, :pos)
N = gets.to_i
A = gets.split.map(&:to_i).each_with_index.map{|a,i| Child.new(a, i + 1) }.sort_by(&:value).reverse
dp = Array.new(N + 1){ Array.new(N + 1, 0) }

ans = 0
A.each.with_index(1) do |c, n|
  x = c.pos
  v = c.value
  
  # padding all from left
  dp[n][0] = dp[n - 1][0] + v * (n - x).abs

  # padding all from right
  dp[0][n] = dp[0][n - 1] + v * (N + 1 - n - x).abs

  (1 ... n).each do |l|
    r = n - l
    dp[l][r] = max(dp[l][r - 1] + v * (N + 1 - r - x).abs, dp[l - 1][r] + v * (l - x).abs)
    ans = max(ans, dp[l][r])
  end
end
puts ans


Measured memory_bytes: 45788
/*
				C++
				encoding: UTF-8
				Last Modified: 2019/09/01 17:51:50

*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		 ll                     long long
#define		 ve                     vector
#define		 pb                     push_back
#define		 endl                   "\n";
#define		 ff                     first
#define		 ss                     second
#define		 pii                    pair<int, int>
#define		 len(v)                 int(v.size())
#define		 all(v)                 v.begin(), v.end()
#define		 reset(a, b)            memset(a, b, sizeof(a));
#define		 fr(i, s, n)            for (ll i = s ; i < n ; ++i)
#define		 dfr(i, s, n)           for (ll i = s ; i > n ; --i)

void pr () {
    cout << "\n";
}

template < typename T, typename... ARGS > void pr (const T& t, ARGS... args) {
    cout << t << " ";
    pr (args...);
}

// clang-format on

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	ll n;
	cin >> n;
	ll ans = 0;
	fr (i, 1, n) ans += i;
	pr (ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int s; cin >> s;
  vector<ll> d(s + 1);

  d[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= i; j++) {
      d[i] += d[i - j];
      d[i] %= MOD;
    }
  }
  cout << d[s] << endl;
  return 0;
}


Measured memory_bytes: 3624
import math

a, b, C = map(float, input().split())

h = b * math.sin(math.radians(C))
S = a * h * 0.5
L = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))) ** 0.5 + a + b

for i in [S, L, h]: print('%10f' % i)



Measured memory_bytes: 5704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if (n == 1) {
			System.out.println("Hello World");
			sc.close();
		} else {

			int a = sc.nextInt();
			int b = sc.nextInt();

			System.out.println(a + b);
			sc.close();
		}
	}
}

Measured memory_bytes: 21076
/*package whatever //do not write package name here */

import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 

class Main {
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
    }
	public static void main (String[] args) {
		FastReader ob = new FastReader();
		int n = ob.nextInt();
		int m = ob.nextInt();
		if(n==m){
		    System.out.println("Yes");
		    return;
		}
		System.out.println("No");
	
	}
}

Measured memory_bytes: 21332
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class EGluttony {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        long long int n, k;
        cin >> n >> k;
        vector<long long int> a_vec(n);
        vector<long long int> f_vec(n);
        for (int i = 0; i < n; ++i)
            cin >> a_vec[i];
        sort(a_vec.begin(), a_vec.end());
        for (int i = 0; i < n; ++i)
            cin >> f_vec[i];
        sort(f_vec.begin(), f_vec.end(), greater<>());
        long long int k_min = -1;
        long long int k_max = *max_element(f_vec.begin(), f_vec.end()) * *max_element(f_vec.begin(), f_vec.end()) * n;
        long long int ans = 10000000000000;
        while (k_min + 1 < k_max) {
            long long int mid = (k_min + k_max) / 2;
            long long int tmp_cost = 0;
            for (int j = 0; j < n; ++j) {
                if (mid > f_vec[j] * a_vec[j]) {
                    continue;
                } else {
                    long long int tmp = f_vec[j] * a_vec[j] - mid;
                    tmp_cost += ceil(static_cast<double>(tmp) / static_cast<double>(f_vec[j]));
                }
            }
            if (tmp_cost <= k) {
                k_max = mid;
            } else {
                k_min = mid;
            }
        }
        cout << ((accumulate(a_vec.begin(), a_vec.end(), 0ll) <= k) ? 0 : k_max) << endl;
    }
};


int main() {
    EGluttony solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int h , w;
	cin >> h >> w;
	int in[h][w];
	for(int i = 0 ; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin >> in[i][j];
		}
	}
	vector <pair < pii , pii > > ans;
	for(int i = 0 ; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if (in[i][j] % 2 != 0 && j != w - 1)
			{
				ans.push_back({{i , j},{i , j + 1}});
				in[i][j + 1]++;
			}
			else if (j == w - 1 && in[i][j] % 2 != 0 && i != h - 1)
			{
				ans.push_back({{i , j},{i + 1 , j}});
				in[i+1][j]++;
			}
		}
	}
	int len = ans.size();
	cout << len << endl;
	for (int i = 0; i < len; i++)
	{
		cout << ans[i].first.first + 1 << " " << ans[i].first.second + 1 << " " << ans[i].second.first  + 1<< " " << ans[i].second.second + 1 << endl;
	}
    return 0;
}


Measured memory_bytes: 5232
#![allow(unused_imports)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let m: usize = scan.next();
    let h: Vec<i32> = scan.next_vec(n);
    let mut ok: Vec<i32> = vec![1; n];

    for _ in 0..m {
        let a: usize = scan.next();
        let b: usize = scan.next();
        let (a, b) = (a - 1, b - 1);

        if h[a] <= h[b] {
            ok[a] = 0;
        }
        if h[a] >= h[b] {
            ok[b] = 0;
        }
    }
    println!("{}", ok.iter().fold(0, |sum, x| sum + x));
}


Measured memory_bytes: 10088