akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
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;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	ll mn=LINF;
	ll ans=0;
	rep(i,n){
		if(mn>v[i])ans++;
		chmin(mn,v[i]);
	}
	puta(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  int mi = INF, ma = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    mp[a[i]]++;
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  bool ok = false;
  if(mp[mi] == 1) {
    ok = mi * 2 == ma;
    for(int i=mi+1;i<ma;++i) {
      if(mp[i] < 2) {
        ok = false;
        break;
      }
    }
  } else if(mp[mi] == 2) {
    ok = mi * 2 == ma + 1;
    for(int i=mi+1;i<ma;++i) {
      if(mp[i] < 2) {
        ok = false;
        break;
      }
    }
  }
  cout << (ok ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int j[30];
int b[30];

int main() {
	int n;
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>j[i]>>b[i];
		}
		int bit=0,sum=0;
		for(i=0;i<n;i++){
			sum+=j[i];
		}
		for(i=0;i<n;i++){
			b[i]-=sum;
		}
		bool update;
		while(bit!=(1<<n)-1){
//cout<<bit<<endl;
//for(int x=0;x<n;x++)cout<<x<<" "<<b[x]<<endl;
//cout<<endl;
			update=false;
			for(i=0;i<n;i++){
				if(b[i]>=0&&!(1<<i&bit)){
					bit|=1<<i;
					int k;
					for(k=0;k<n;k++){
						b[k]+=j[i];
					}
					update=true;
				}
			}
			if(!update)break;
		}
		cout<<(update?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL H[100001];
vector<vector<int>> adj;

LL ans = 0;

void solve(){
	for(int i=1;i<=N;i++){
		int good = 1;
		for(int j=0;j<adj[i].size();j++){
			// cout << i << endl;
			// cout << "comp:" << adj[i][j] << endl;
			if(H[i]<=H[adj[i][j]]) good = 0;
		}
		//cout << ((good)?"good":"not good") << endl;
		ans += good;
	}
}
 
int main(){
    cin >> N >> M;
    for(int i=1;i<=N;i++){
    	cin >> H[i];
    }
    adj = vector<vector<int>>(N+1);
    for(int i=0;i<M;i++){
    	int a,b;cin >> a >> b;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }

    solve();

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

Measured memory_bytes: 8632
#include<iostream>
using namespace std;
int main(){
  int N;
  int ans;
  cin >> N;
  //ans=a;
  if(N>=100 && N<=111) ans=111;
  else if(N>=112 && N<=222) ans=222;
  else if(N>=223 && N<=333) ans=333;
  else if(N>=334 && N<=444) ans=444;
  else if(N>=445 && N<=555) ans=555;
  else if(N>=556 && N<=666) ans=666;
  else if(N>=667 && N<=777) ans=777;
  else if(N>=778 && N<=888) ans=888;
  else if(N>=889 && N<=999) ans=999;
  else if(N>=1000 && N<=1111) ans=1111;
  cout << ans << endl;
}


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

#define int long long
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

using namespace std;

int N, D, X;
int A[101];

signed main()
{
    cin >> N >> D >> X;

    int ans = 0;
    REP(i, N)
    {
        int a;
        cin >> a;

        int day = 1;
        int k = 1;
        while (day <= D)
        {
            ++ans;
            day = k * a + 1;
            ++k;
        }
    }
    cout << X + ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define N 205
#define PAIR pair<int,int>
#define LL long long
using namespace std;
const int mo=1e9+7;
int head[N],len,nxt[N],num[N],ce,cd;
int n,m,k,f[N],C[N][N],pw[N],ans,dfn[N],low[N],clk,cut[N],st[N],top,vis[N],xyk;
int gcd(int x,int y){ return x ? gcd(y%x,x) : y;}
LL fpm(LL x,LL y){ LL s=1; while(y){ if(y&1) s=(s*x)%mo; y>>=1,x=(x*x)%mo;} return s;}
int cir(int n)
{
	int i,ans=0;
	for(i=1;i<=n;i++)
		ans=(ans+pw[gcd(i,n)])%mo;
	ans=(1LL*ans*fpm(n,mo-2))%mo;
	return ans;
}
void calc(int e)
{
	int x,y;
	if(top==1) ans=(1LL*ans*k)%mo,top=0;
	else{
		cd=ce=0,++xyk;
		while(top){
			x=num[st[top]^0];
			y=num[st[top]^1];
			ce++;
			if(vis[x]!=xyk) cd++,vis[x]=xyk;
			if(vis[y]!=xyk) cd++,vis[y]=xyk;
			if(st[top--]==e) break;
		  }
		if(cd==ce) ans=(1LL*ans*cir(cd))%mo;
		else ans=(1LL*ans*C[ce+k-1][k-1])%mo;
	  }
}
void tarjan(int t,int fa)
{
	int i;
	dfn[t]=low[t]=++clk,cut[t]=0;
	for(i=head[t];i;i=nxt[i]){
		if(num[i]==fa) continue;
		if(!dfn[num[i]]){
			st[++top]=i;
			tarjan(num[i],t),low[t]=min(low[t],low[num[i]]);
			if(low[num[i]]>=dfn[t]) cut[t]=1,calc(i);
		  }
		else{
			low[t]=min(low[t],dfn[num[i]]);
			if(dfn[num[i]]<dfn[t]) st[++top]=i;
		  }
	  }
}
int main()
{
	int i,j,x,y; ans=len=1;
	scanf("%d %d %d",&n,&m,&k);
	for(i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		num[++len]=y,nxt[len]=head[x],head[x]=len;
		num[++len]=x,nxt[len]=head[y],head[y]=len;
	  }
	C[0][0]=pw[0]=1;
	for(i=1;i<N;i++){
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	  }
	for(i=1;i<N;i++) pw[i]=(1LL*pw[i-1]*k)%mo;
	for(i=1;i<=n;i++)
		if(!dfn[i])
			tarjan(i,0),top=0;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

struct P {
    ll v, wei, x;
    bool operator<(const P &r) const {
        return v*r.wei > r.v*wei;
    }
};

P addp(const P &l, const P &r) {
    return P{l.v + r.v, l.wei + r.wei, l.x + r.x + l.wei * r.v};
}

using S = multiset<P>;

int n;
VV<int> g;
V<int> wei;

S* dfs(int p) {
    auto s = new S();
    for (int d: g[p]) {
        auto t = dfs(d);
        if (s->size() < t->size()) swap(s, t);
        for (auto p: *t) {
            s->insert(p);
        }
    }
    P nw = P{wei[p], 1, wei[p]};
    while (s->size()) {
        auto p = *(s->begin());
        if (nw < p) {
            break;
        }
        s->erase(s->begin());
        nw = addp(nw, p);
    }
    s->insert(nw);

/*    cout << "DEBUG " << p << " : ";
    for (auto p: *s) {
        cout << "(" << p.v << ", " << p.wei << ", " << p.x << "), ";
    }
    cout << endl;    */
    return s;
}


ll solve() {
/*    cout << "n : " << n << endl;
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        for (int d: g[i]) {
            cout << d << ", ";
        } cout << endl;
    }
    for (int d: wei) cout << d << ", "; cout << endl;*/
    if (n == 0) return 0;

    auto s = dfs(0);

    ll ans = 0, wsm = 0;
    for (auto p: (*s)) {
        ans += wsm * p.v + p.x;
        wsm += p.wei;
    }
    return ans;
}

VV<int> g2;
V<bool> col;

void first(int p, int rid, int b) {
    if (!col[p]) {
        if (rid >= 0) wei[rid]++;
    } else {
        int nrid = n;
        n++;
        g.push_back({});
        if (rid >= 0) g[rid].push_back(nrid);
        wei.push_back(0);
        rid = nrid;
    }
    
    for (int d: g2[p]) {
        if (d == b) continue;
        first(d, rid, p);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    int n;
    cin >> n;
    g2 = VV<int>(n);
    col = V<bool>(n);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p; p--;
        g2[p].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        col[i] = (x == 1);
    }

    ll ans = 0;
    if (col[0] == false) {
        col[0] = true;
        for (int i = 1; i < n; i++) if (!col[i]) ans--;
    }
    first(0, -1, 0);
    cout << ans + solve() << endl;
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define MAX 1000000


ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a=(a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll>&fact, vector<ll>&factinv)
{
    fact[0] = 1;
    factinv[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
        fact[i] = (fact[i-1] * i)%MOD;
    
    for(ll i = 1; i <= MAX; i++)
        factinv[i] = (factinv[i-1] * fastpower(i, MOD -2) )%MOD;

}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,n,m,k,q;
    cin>>n>>m;
    k = n * m;
    cout<<k;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
ll a[N], n, m;
map<ll, ll> freq;

int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  a[0] = 0;
  for (int i = 1; i <= n; i++) a[i] += a[i - 1];
  for (int i = 0; i <= n; i++) freq[a[i] % m]++;
  ll ans = 0;
  for (const auto& p : freq) {
    ll x = p.second;
    ans += x * (x - 1) / 2;
  }
  printf("%lld\n", ans);
}



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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }
    int m = n / 2;
    sort(d.begin(), d.end());
    cout << d.at(m) - d.at(m-1) << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int N, M, Q, ans;
vector<int> a, b, c, d;

void dfs(vector<int> A) {
  if (int(A.size()) == N + 1) {
    int res = 0;
    for (int i = 0; i < Q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        res += d[i];
      }
    }
    ans = max(ans, res);
    return;
  }
  int tail = A.back();
  for (int add_elem = tail; add_elem <= M; add_elem++) {
    A.push_back(add_elem);
    dfs(A);
    A.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  a = b = c = d = vector<int>(Q);

  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector<int> v(1, 1);
  dfs(v);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){
    
    int a, b, t;
    cin >> a >> b >> t;
    cout << b * (t / a) << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef int ll;
const int maxn=1000;
vector<int> a,b,c,d;
int mp[maxn][maxn];
int main()
{
	int cnt=0;
	int h,w,i,j;
	scanf("%d %d",&h,&w);
	for( i=1;i<=h;i++)
		for( j=1;j<=w;j++)
			scanf("%d",&mp[i][j]);
	for( i=1;i<=h;i++){
		if(i%2!=0){
			for( j=1;j<=w;j++){
				if(mp[i][j]%2==0)
					continue;
				if(i==h&&j==w)
					break;
				cnt++;
				a.push_back(i);
				b.push_back(j);
				if(j==w){
					mp[i+1][j]++;
					c.push_back(i+1);
					d.push_back(j);
				}
				else{
					mp[i][j+1]++;
					c.push_back(i);
					d.push_back(j+1);
				}
			}
		
		}
		else{
			for( j=w;j>=1;j--){
				if(mp[i][j]%2==0)
					continue;
				
				if(i==h&&j==1)
					break;
				cnt++;
				a.push_back(i);
				b.push_back(j);
				if(j==1){
					mp[i+1][j]++;
					c.push_back(i+1);
					d.push_back(j);
				}
				else{
					mp[i][j-1]++;
					c.push_back(i);
					d.push_back(j-1);
				}	
			}
			
		}
	
	}
	printf("%d\n",cnt);
	for(int i=0;i<cnt;i++)
		printf("%d %d %d %d\n",a[i],b[i],c[i],d[i]);
	return 0;
}

Measured memory_bytes: 6116
#include<iostream>
#include<cctype>
#include<string>

using namespace std;

int main() {
	string s;
	getline(cin,s);
	for (int i = 0; i < s.length(); i++) {
		if (islower(s[i])) {
			s[i] = toupper(s[i]);
		}
		else if (isupper(s[i])) {
			s[i] = tolower(s[i]);
		}
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e5+5;
vector<int> a[N];
int32_t main(){
    int h,w,n;
    cin>>h>>w>>n;
    forn(i,n){
        int x,y;
        cin>>x>>y;
        a[y].pb(x);
    }
    for(int i=1;i<=w;++i)sort(a[i].begin(), a[i].end());
    int x=1,y=1,ans=h,cur=0;
    while(1){
        int pos=upper_bound(a[y].begin(), a[y].end(),x)-a[y].begin();
        int d=h+1;
        if(pos<sz(a[y]))d=a[y][pos];
        upn(ans,cur+d-x);
        if(x+1==d)break;
        x++;
        cur++;
        if(y<w){
            pos=lower_bound(a[y+1].begin(), a[y+1].end(),x)-a[y+1].begin();
            if(pos==sz(a[y+1])||a[y+1][pos]!=x){
                y++;
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 12292
#include <stdio.h>
int main(void){
	int x, y, r = 0;
	scanf("%d%d", &x, &y);
	r += (x < y ? x : y);
	scanf("%d%d", &x, &y);
	r += (x < y ? x : y);
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h> // Ishaan Gupta
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifdef IG_PC
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
#define pb push_back
using ll = long long;
using ld = long double;
const ll MOD = 1e9l + 7;
const ll INF = 1e18l + 5;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

const ll MAX = 305;
ld dp[MAX][MAX][MAX];
ll n;
ld func(ll ones, ll twos, ll threes)
{
    if(ones<0 || twos < 0 || threes < 0)
        return 0;
    if(ones == 0 && twos == 0 && threes == 0)
        return 0;
    if(dp[ones][twos][threes]>0)
        return dp[ones][twos][threes];
    ld p0 = (ld)(n-ones-twos-threes)/n;
    ld p1 = (ld)ones/n;
    ld p2 = (ld)twos/n;
    ld p3 = (ld)threes/n;
    // cout<<p0<<" "<<p1<<" "<<p2<<" "<<p3<<endl;

    return dp[ones][twos][threes] = (1+p1*func(ones-1, twos, threes) + p2*func(ones+1,twos-1,threes) + p3*func(ones,twos+1,threes-1))/(1-p0);

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    cin >> n;
    ll ones=0,twos=0,threes=0;
    for(ll i=0;i<n;++i)
    {
        ll x;
        cin >> x;
        if(x==1)
            ones++;
        else if(x==2)
            twos++;
        else
            threes++;
    }
    cout<<func(ones,twos,threes);
    
    return 0;
}

Measured memory_bytes: 436608
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 
int N;
vector<int>nums;

void maxheap(const int now) {
	int lid = now * 2;
	int rid = now * 2 + 1;
	int l = -2e9-1, r = -2e9-1;
	if (lid <= N)l = nums[lid];
	if (rid <= N)r = nums[rid];
	int large = -2;
	if (nums[lid] > nums[now]) {
		if (nums[rid] > nums[lid]) {
			large = rid;
		}
		else {
			large = lid;
		}
	}
	else {
		if (nums[rid] > nums[now]) {
			large = rid;
		}
		else {
			large = now;
		}
	}
	if (large != now) {
		swap(nums[large], nums[now]);
		maxheap(large);
	}
}


int main() {
	cin >> N;
	nums.resize(2*N+2);
	fill(nums.begin(), nums.end(), -2e9-1);
	for (int i = 0; i < N; ++i) {
		cin >> nums[i+1];
	}
	for (int i = N / 2; i >= 1; --i) {
		maxheap(i);
	}
	for (int i = 1; i <= N; ++i) {
		cout << " ";
		cout << nums[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 6700
fun main (args:Array<String>){
    val (_ , numOfBuyFruits)  = readLine()!!.split(" ").map(String::toInt)
    val valueList = readLine()!!.split(" ").map(String::toInt).sorted()
    var sumValue = 0
    for (i in 0..numOfBuyFruits-1){
        sumValue += valueList[i]
    }
    print(sumValue)
}

Measured memory_bytes: 40508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x;
int main()
{
    cin >> x;
    for(ll i = -200; i <= 200; i++){
        for(ll j = -200; j <= 200; j++){
            if(i*i*i*i*i-j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3632
using System;

namespace AOJ.ITP
{
    public class CountingCharacters
    {
        public static void Main()
        {
            int[] answer = new int[26];
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                char low = 'a';
                char up = 'A';
                for (int i = 0; i < 26; i++)
                {
                    string tmp = input.Replace(low.ToString(), "");
                    tmp = tmp.Replace(up.ToString(), "");

                    answer[i] +=input.Length-tmp.Length;

                    // 次の文字
                    low++;
                    up++;
                }
            }

            char output = 'a';
            for (int i = 0; i < 26; i++)
            {
                Console.WriteLine(output + " : " + answer[i]);
                output++;
            }
        }
    }
}

Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

// int main() {
//     ll A[6];
//     rep(i,3){
//         cin >> A[i];
//     }
//     //sort(A,A+3);
//     cout << (A[2]>=A[0] && A[2]<=A[1] ? "Yes" : "No") << endl;
// }

int main(){
    char X[108],Y[108],Z[108];cin >> X >> Y >> Z;
    X[0]-=32;Y[0]-=32;Z[0]-=32;
    cout <<X[0]<<Y[0]<<Z[0]<<endl;;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        String s = ns();

        int idxa = 0;
        while (s.charAt(idxa) != 'A') idxa++;

        int idxz = s.length() - 1;
        while (s.charAt(idxz) != 'Z') idxz--;

        out.println(idxz - idxa + 1);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 11732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

map<string, int> city2num;
set<int> LPG;

vector<pair<int, int>> G[6010];
int dist[6010][2010]; // dist[i][j] := ??????i?????§??????LPG???j??§??\????????????????????¢
using tup = tuple<int, int, int>;

void dijkstra(int start, int cap){
	rep(i, 6010)rep(j, 2010) dist[i][j] = INF;
	cap *= 10;
	dist[start][cap] = 0;
	priority_queue<tup, vector<tup>, greater<tup> >  que; // ?????¢ ?????? ?????????LPG
	que.push(make_tuple(0, start, cap));
	while(!que.empty()){
		int cost, u, lpg;
		tie(cost, u, lpg) = que.top(); que.pop();
		if(dist[u][lpg] < cost) continue;
		for (auto& tmp : G[u]){
			int v = tmp.first, di = tmp.second;
			int nlpg = lpg - di;
			int ncost = cost + di;
			if(nlpg < 0) continue;
			if(LPG.count(v)) {
				/*
				for (int i = nlpg; i <= cap; ++i){ ???????????¨TLE(9.0s)
					if(dist[v][i] > ncost) {
						dist[v][i] = ncost;
						que.push(make_tuple(ncost, v, i));
					}
				}
				*/
				if(dist[v][cap] > ncost) {
					dist[v][cap] = ncost;
					que.push(make_tuple(ncost, v, cap));
				}
			}else{
				if(dist[v][nlpg] > ncost) {
					dist[v][nlpg] = ncost;
					que.push(make_tuple(ncost, v, nlpg));
				}
			}
		}
	}
}


string c1[6010], c2[6010];
int d[6010];
string s[6010];
int main(void) {
	while(1){
		city2num.clear(); LPG.clear();
		rep(i, 6010) G[i].clear();

		int N, M, cap; scanf("%d %d %d", &N, &M, &cap);
		if(N == 0 && M == 0 && cap == 0) break;
		string src, dest; cin >> src >> dest;

		rep(i, N) cin >> c1[i] >> c2[i] >> d[i];
		rep(i, M) cin >> s[i];

		set<string> city;
		rep(i, N) city.insert(c1[i]), city.insert(c2[i]);
		int cnt = 0;
		for(auto& u : city) {
			city2num[u] = cnt++;
		}
		rep(i, M) LPG.insert(city2num[s[i]]);

		rep(i, N) G[city2num[c1[i]]].pb(mp(city2num[c2[i]], d[i])), G[city2num[c2[i]]].pb(mp(city2num[c1[i]], d[i]));
		int ns = city2num[src], nd = city2num[dest];

		dijkstra(ns, cap);
		ll ans = INF;
		rep(i, cap * 10 + 1) chmin(ans, dist[nd][i]);
		if(ans != INF)printf("%lld\n", ans);
		else printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 76496
import numpy as np

N, W = map(int, input().split())
WV = np.array([list(map(int, input().split())) for _ in range(N)])
max_v = np.sum(WV[:, 1])
# dp[i]: 価値iを達成するのに必要な重さの最小値
dp = np.full(max_v+1, W+1, dtype="int64") # 1D
dp[0] = 0

for w, v in WV:
  # 価値i(0 <= i <= max_value-v)の時の重さの最小値に対し
  # 次の荷物を入れて、価値i+vの時の重さの最小値を更新
  np.minimum(dp[:-v]+w, dp[v:], out=dp[v:])

# np.where: 条件にあったindexを出力
print(np.max(np.where(dp<=W))) #

Measured memory_bytes: 13932
#include<iostream>
using namespace std;
const double eps=1e-9;
double p,q,a;
int n;
int ans=0;
void dfs(double pq,int s,int depth,int seki){
  if(pq>=-eps&&pq<=eps){
    ans++;
    return;
  }
  for(int i=s;i<=a/2;i++){
    if(seki*i>a)
      break;
    if((pq-(1.0/i))>=-eps&&depth+1<=n){
      dfs((pq-(1.0/i)),i,depth+1,seki*i);
    }
  }
}
int main(){
  while(cin>>p>>q>>a>>n,p+q+a+n){
    ans=0;
    for(int i=1;i<=a/2;i++){
      if((p/q)-(1.0/i)>=-eps)
	dfs((p/q)-(1.0/i),i,1,i);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int H, W;
bitset<160 * 160 + 1> dp[81][81];
int cost[81][81];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> cost[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int tmp;
            cin >> tmp;
            cost[i][j] -= tmp;
        }
    }

    int s = H + W - 1;
    dp[0][0][80 + cost[0][0]] = true;
    dp[0][0][80 - cost[0][0]] = true;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            for(int k = 0; k <= s * 160; k++){
                if(!dp[i][j][k]) continue;
                dp[i + 1][j][k + 80 + cost[i + 1][j]] = true;
                dp[i][j + 1][k + 80 + cost[i][j + 1]] = true;
                dp[i + 1][j][k + 80 - cost[i + 1][j]] = true;
                dp[i][j + 1][k + 80 - cost[i][j + 1]] = true;
            }
        }
    }

    int ans = inf;
    for(int i = 0; i <= s * 160; i++){
        if(!dp[H - 1][W - 1][i]) continue;
        chmin(ans, abs(i - s * 80));
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int dp[500005] = {};

int main(){
  string s;
  cin>>s;
  for (int i=s.size()-1;i>=0;i--) {
    dp[i] = (s[i] == '<' ? 0 : dp[i+1]+1);
  }
  ll ans = 0;
  int cur = dp[0];
  for (int i=0;i<=s.size();i++) {
    ans += cur;
    if (i==s.size()) break;
    if (s[i] == '<') {
      cur = max(cur + 1, dp[i+1]);
    } else {
      cur = dp[i+1];
    }
  }
  cout << ans << endl;
  


  return 0;
}


Measured memory_bytes: 2820
#include <iostream>
#include <cmath>

using namespace std;

typedef struct {
	char c;
	int n;
} Card;

int Bsort(Card *arr,int n) {
	bool flag = true;
	int i = 0;
	int count = 0;
	while (flag) {
		flag = false;
		for (int j=n-1; j>i; j--) {
			if (arr[j].n < arr[j-1].n) {
				Card t = arr[j];
				arr[j] = arr[j-1];
				arr[j-1] = t;
				flag = true;
				count++;
			}
		}
		i++;
	}
	return count;
}
int Ssort(Card *arr,int n) {
	int count = 0;
	for (int i=0; i<n-1; i++) {
		int k = i;
		for (int j=i+1; j<n; j++) {
			if (arr[k].n > arr[j].n) {
				k = j;
			}
		}
		if (k != i) {
			Card t = arr[k];
			arr[k] = arr[i];
			arr[i] = t;
			count++;
		}
	}
	return count;
}

int main() {
	int n;
	cin >> n;
	Card *arr = new Card[n];
	Card *arr2 = new Card[n];
	
	for (int i=0; i<n; i++) {
		cin >> arr[i].c >> arr[i].n;
		arr2[i] = arr[i];
	}
	int c = Bsort(arr,n);
	for (int i=0; i<n; i++) {
		if (i) cout << " ";
		cout << arr[i].c << arr[i].n;
	}
	cout << endl;
	cout << "Stable" << endl;
	c = Ssort(arr2,n);
	for (int i=0; i<n; i++) {
		if (i) cout << " ";
		cout << arr2[i].c << arr2[i].n;
	}
	cout << endl;
	int i;
	for (i=0;i<n;i++) {
		if (arr[i].c != arr2[i].c) {
			cout << "Not stable" << endl;
			break;
		}
	}
	
	if (i == n) {
		cout << "Stable" << endl;
	}
	return 0;
}


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

ll power(ll x,ll y,int p) 
{ 
    ll res=1;   
    x=x%p;  
    while (y > 0) 
    { 
        if (y & 1)  res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    

    int n,m;
    cin>>n>>m;

    vector<string> v;
    ffor(i,0,n)
    {
        string s;
        cin>>s;
        v.pb(s);
    }

    int dp[n][m];
    mem(dp,0);
    if(v[0][0]=='#') dp[0][0]=1;

    ffor(i,0,n)
    {
        ffor(j,0,m)
        {
            if(i+j==0) continue;
            dp[i][j]=100000000;
            if(i-1>=0) 
            {
                if((v[i-1][j]==v[i][j])||v[i][j]=='.') dp[i][j]=min(dp[i][j],dp[i-1][j]);
                else dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
            }
            if(j-1>=0)
            {
                if((v[i][j-1]==v[i][j])||v[i][j]=='.') dp[i][j]=min(dp[i][j],dp[i][j-1]);
                else dp[i][j]=min(dp[i][j],dp[i][j-1]+1);   
            }
        }
    }    
   /* ffor(i,0,n)
    {
        ffor(j,0,m) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<dp[n-1][m-1];
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)


H, W, M = map(int, input().split())

num_bombs_each_row = [0] * H
num_bombs_each_col = [0] * W
bombs = set()

for _ in range(M):
    h, w = map(int, input().split())
    # 0-index
    h -= 1
    w -= 1

    bombs.add((h, w))
    num_bombs_each_row[h] += 1
    num_bombs_each_col[w] += 1

max_bombs_in_row = max(num_bombs_each_row)
max_bombs_in_col = max(num_bombs_each_col)

rows_with_max_bombs = []
for row in range(H):
    if num_bombs_each_row[row] == max_bombs_in_row:
        rows_with_max_bombs.append(row)

cols_with_max_bombs = []
for col in range(W):
    if num_bombs_each_col[col] == max_bombs_in_col:
        cols_with_max_bombs.append(col)

found = False
for row in rows_with_max_bombs:
    for col in cols_with_max_bombs:
        if not (row, col) in bombs:
            found = True
            break

ans = max_bombs_in_row + max_bombs_in_col
if found:
    print(ans)
else:
    print(ans - 1)


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

using namespace std;

#define DIM 200009
#define INF 1e11+9
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pairll pair<long long,long long>
#define fi first
#define se second

long long i,j,k,l,n,m;

long long dp[DIM],a[DIM];

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

    for(i=2;i<=n;i++){
        dp[i]=INF;
        for(j=i-1;j>0 && j>=i-m;j--)dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
    }

    cout<<dp[n]<<endl;

    return 0;
}


Measured memory_bytes: 1792
import math
n = int(input())
s= n**2+n*(n-1)+(n-1)**2
for i in range(2,n+1):
    for j in range(2,n+1):
        x = math.gcd(i,j)
        if x==1:
            s+=n-1
        else:
            for k in range(2,n+1):
                s+=math.gcd(k,x)
print(s)

Measured memory_bytes: 9184
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main() {
	string S;
	ll K;
	cin >> S >> K;

	char c = '1';
	int cnt = 0;
	REP(i, S.size()) {
		if (S[i] == '1') {
			++cnt;
		}
		else {
			c = S[i];
			break;
		}
	}

	cout << ((cnt >= K) && cnt ? '1' : c) << endl;
	return 0;
}

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

int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(x-a)%b<<endl;
	return 0;
}

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

int main() {
	long long n;
	cin >> n;
	long long a[n];
	long long b=0;
	map<long long ,long long > mp;
	for(int i=0;i<n;i++){
		cin >> a[i];
		b=max(b,a[i]);
		mp[a[i]]++;
	}
	sort(a,a+n);
	vector<bool> c(b+1,true);
	for(long long i=0;i<n;i++){
		if(c[a[i]]){
			long long k=2;
			while(a[i]*k<=b){
				c[a[i]*k]=false;
				k++;
			}
		}
	}
	long long ans=0;
	for(long long i=0;i<n;i++){
		if(mp[a[i]]==1&&c[a[i]]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 17684
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

//original problem

int prime[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
string S;
int B;
int decomposition_of_numbers[101];
int prime_filling_up[101];

int main() {
    int N;
    cin >> N;
    int temp;
    int ans = 0;
    rep(i, N) {
        cin >> temp;
        ans += (temp - 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 3e5 + 5;
int a[N], p[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    	a[i]--;
    	p[a[i]] = i;
    }

    bool ok = true;

    int j = n - 1;
    while (j >= 0) {
    	while (j >= 0 && p[j] == j)
    		j--;

    	if (j < 0)
    		break;

    	int i = j;
    	while (i >= 0 && ((p[i] != i) ^ ((j - i) & 1))) {
    		i--;
    	}

    	if (((j - i) & 1) == 0)
    		i++;

		vector<int> v;

		for (int k = 1; k <= j - i; k += 2) {
			v.push_back(a[i + k]);
		}

		if (*min_element(all(v)) != i + 1 ||
			*max_element(all(v)) != j) {
			ok = false;
		}
		else {
			for (int &x : v) {
				x = (x - i - 1) / 2;
			}
			int last[2] = {-1, -1};
			for (int i = 0; i < v.size(); i++) {
				int c = (i < v[i]);
				if (last[c] > v[i])
					ok = false;
				last[c] = v[i];
			}
		}

    	j = i;
    }

    if (ok)
    	cout << "Yes\n";
    else
    	cout << "No\n";

    return 0;   
}

Measured memory_bytes: 3704
fun main(args: Array<String>) {
    val (n, m, x, y) = readLine()!!.split(' ').map(String::toLong)
    val xList = readLine()!!.split(' ').map(String::toLong)
    val yList = readLine()!!.split(' ').map(String::toLong)
    val max = xList.max()!!
    if ((max < yList.min()!!) && (x < max) && (max < y)){
        println("No War")
    }else{
        println("War")
    }
}

Measured memory_bytes: 38336
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
const long long int mod = 1000000007;
const long long int big = 1152921504606846976;

vector <int> W[100010];//誰を直接殺してきたか
int solveF(int ter) {
	int i = 0,max=-1;
	vector<int> ver;//versus
	for (i = 0; i < W[ter].size(); i++) {
		ver.push_back(solveF(W[ter][i]));
	}
	sort(ver.begin(), ver.end(),greater<int>());
	for (i = 0; i < ver.size(); i++) {
		if (max < i + ver[i]) { max = i + ver[i]; }
	}
	return max+1;
}
int main(void) {
	int N, i,ans,a;
	scanf("%d", &N);
	for (i = 2; i <= N; i++) {
		scanf("%d", &a);
		W[a].push_back(i);
	}
	ans = solveF(1);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define fr(i, a, b) for (int i = a; i < b; i++)
double dp[3001][3001];
double solve(vector<double> &ar,int i,int x){
    if(x==0){
        return 1;
    }
    if(i==0){
        return 0;
    }
    if(dp[i][x] > -0.9 )
        return dp[i][x];
    return dp[i][x] = ar[i]*solve(ar,i-1,x-1) + (1-ar[i])*solve(ar,i-1,x);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int n;cin>>n;
    memset(dp,-1,sizeof(dp));
    vector<double> ar(n+1);
    fr(i,1,n+1) cin>>ar[i];
    cout<<fixed<<setprecision(10)<<solve(ar,n,(n+1)/2);
}

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

using namespace std;

int n;
int m[123];

int main()
{
	int best = 1<<29;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> m[i];
	for (int i = -100; i <= 100; i++)
	{
		int cur = 0;
		for (int j = 0; j < n; j++) cur += (m[j] - i)*(m[j] - i);
		best = min(best, cur);
	}
	cout << best << '\n';
	return 0;
}



Measured memory_bytes: 256
/*input
3 3
1 2 3
1 2 3
*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a %= MOD, b %= MOD, a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;
vector < int > v1, v2;
ll dp[2005][2005];

ll func(int n, int m)
{
  if(n <= 0 or m <= 0) {
    return 1;
  }
  if(dp[n][m] > -1) {
    return dp[n][m];
  }
  ll res = 0;
  if(v1[n - 1] == v2[m - 1]) {
    res = add(func(n - 1, m), func(n, m - 1));
  } else {
    res = sub(add(func(n - 1, m), func(n, m - 1)), func(n - 1, m - 1));
  }
  return dp[n][m] = res;
}

ll func2(int n, int m) 
{
  for(int i = 0; i <= n; i ++) {
    dp[0][i] = 1;
  }
  for(int i = 0; i <= m; i ++) {
    dp[i][0] = 1;
  }
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= m; j ++) {
      dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
      if(v1[i - 1] != v2[j - 1]) {
        dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
      }
    } 
  }
  return dp[n][m];
}

int main()
{
  ifalse;
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i ++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  for(int j = 0; j < m; j ++) {
    int x;
    cin >> x;
    v2.push_back(x);
  }
  memset(dp, -1, sizeof(dp));
  cout << func(n, m);
  return 0;
}

Measured memory_bytes: 32000
N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = 10**9 * 15
for bit in range(1<<N):
    cnt = 0
    for i in range(N):
        # print(bin(bit), i, bit>>i, (bit>>i) & 1)
        if (bit>>i) & 1 == 1:
            cnt += 1
    # print(bin(bit), cnt)
    if cnt == K:
        max_height = a[0]
        price = 0
        for i in range(1, N):
            if ((bit>>i) & 1 == 1
                    and a[i] <= max_height):
                price += max_height + 1 - a[i]
                max_height += 1
            max_height = max(max_height, a[i])
        ans = min(ans, price)
print(ans)


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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>k>>n;
    long long int ans=0;
    long long int prev;
    long long int first,last;
    for(long long int i=0;i<n;i++)
    {
        long long int a;
        cin>>a;
        if(i==0)
        first=a;
        if(i==n-1)
        last=a;
        if(i!=0)
        ans=max(ans,a-prev);
        prev=a;
    }
    ans=max(ans,(k-last)+first);
    cout<<k-ans<<"\n";
}

Measured memory_bytes: 3672