akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,P;
	cin>>N>>P;
	vector<int> ans(N,inf);
	vector<vector<int>> node(N, vector<int>());
	vector<int> value(N,0);
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		--a; --b;
		node[a].push_back(b); 
		node[b].push_back(a);
	}
	rep(i,P){
		int p,x;
		cin>>p>>x;
		value[--p] += x;
	}
	queue<int> Q;
	Q.push(0);
	ans[0] = 0;
	while(!Q.empty()){
		int n = Q.front();
		ans[n] += value[n];
		Q.pop();
		for(auto x: node[n]){
			if(ans[x] == inf){
				ans[x] = ans[n];
				Q.push(x);
			}
		}
	}
	for(auto x : ans)cout<<x<<' ';
		cout<<endl;
	return 0;
}

Measured memory_bytes: 16372
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_N = 100005;
vector<pair<int, int>> v;

//[1, n]
int bit[MAX_N + 1] = {0}, n;

int sum(int i){
    int s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x){
    while(i <= n){
        bit[i] += x;
        //bit[i] = max(bit[i], x);
        i += i & - i;
    }
}

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

    rep(i,q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com){
            cout << sum(y) - sum(x - 1) << endl;
        }else{
            add(x,y);
        }
    }
}

Measured memory_bytes: 3452
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


bool is_overflow(ll a, ll b)
{
	if ((a * b) / b != a)
	{
		return true;
	}
	else
	{
		return false;
	}
}


ll RepeatSquaring(ll base, ll sisuu) {
	if (sisuu == 0) return 1;
	if (sisuu % 2 == 0) {
		ll t = RepeatSquaring(base, sisuu / 2) % MOD;
		return (t * t) % MOD;
	}
	return base * RepeatSquaring(base, sisuu - 1) % MOD;
}



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N, K;
	cin >> N >> K;

	vll n_gcd(K + 1); // n(gcd=i)
	for (ll i = 0; i <= K; i++)
	{
		n_gcd[i] = 0;
	}


	vint temp;
	for (ll i = K; i >= 1; i--)
	{

		ll n_g = RepeatSquaring(K / i, N);
		temp.emplace_back(n_g);
		for (ll j = 2; j <= K; j++)
		{
			if (i * j <= K)
			{
				n_g -= n_gcd[i * j];
			}
			else
			{
				break;
			}
		}

		n_gcd[i] = (n_g%MOD+MOD) % MOD;
	}

	sort(temp.begin(), temp.end());

	ll ans = 0;
	for (ll i = 1; i <= K; i++)
	{
		ans += ((i * n_gcd[i]) % MOD + MOD) % MOD;
		ans %= MOD;

		if (is_overflow(i, n_gcd[i]))
		{
			cout << "not answer :" << i << endl;
		}


	}

	cout << ans;

}





Measured memory_bytes: 4672
#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i,a,n) for(i=a;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    int a,b,i = 0;
    cin>>a>>b;
    bool hoe = true;
    while(hoe){
        if((a*i)-(i-1)>= b) hoe = 0;
        else i++;
    }
    cout<<i;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int n,m;
bool can=false;
vector<vector<ll>> graph;
void dfs(int bfo,int now,ll times){
    if(times>2)return;
    if(can||now==n-1){
        can=true;
        return;
    }
    for(int i=0;i<graph.at(now).size();i++){
       if(graph.at(now).at(i)==bfo)continue;
        dfs(now,graph.at(now).at(i),times+1);
    }
    return;
}
int main(){
cin>>n>>m;
graph.resize(n);
for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
}

dfs(0,0,0);
if(can)cout<<"POSSIBLE"<<endl;
else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 12776
#include <stdio.h>

long double dp[302][302][302] = {};

int main()
{
	int i, N, a, count[3] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &a);
		count[a-1]++;
	}
	
	int j, k, n;
	for (k = 0; k <= count[2]; k++) {
		for (j = 0; j <= count[1] + count[2] - k; j++) {
			for (i = 0; i <= N - j - k; i++) {
				n = i + j + k;
				if (n > 0) dp[i][j][k] = (long double)N / n;
				if (i > 0) dp[i][j][k] += dp[i-1][j][k] * i / n;
				if (j > 0) dp[i][j][k] += dp[i+1][j-1][k] * j / n;
				if (k > 0) dp[i][j][k] += dp[i][j+1][k-1] * k / n;
			}
		}
	}
	printf("%.10Lf\n", dp[count[0]][count[1]][count[2]]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 211236
#include <stdio.h>
int main(void)
{int N,A,M,B,j,x,i,k,H,W,l,m,flag;
	long long int sum,min;
	scanf("%d",&N);
	int C[500];
	int S[500];
	int F[500];
	int time[500][500];
	int ans[500];
	flag=0;
	sum=0;
	for(i=0;i<=N-2;i++){
		scanf("%d%d%d",&C[i],&S[i],&F[i]);}
		for(i=0;i<=N-2;i++){
			time[i][i]=S[i];
	for(j=i+1;j<=N-2;j++){
		if((time[i][j-1]+C[j-1])<=S[j]){
			time[i][j]=S[j];}	
		else if((time[i][j-1]+C[j-1])%F[j]==0){
		time[i][j]=time[i][j-1]+C[j-1];}
			else{
				time[i][j]=time[i][j-1]+C[j-1]+F[j]-(time[i][j-1]+C[j-1])%F[j];}}}
				for(i=0;i<=N-2;i++){
				printf("%d\n",time[i][N-2]+C[N-2]);}
				printf("0");
				
			

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll f(vll v, vll c, ll k) {
  ll n = v.size();
  rep(i,n) v.push_back(v[i]);
  ll ret1 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    rep(j,min(n,k)) {
      tmp += c[v[i+j]];
      ret1 = max(ret1,tmp);
    }
  }
  ll sum = 0LL;
  rep(i,n) sum += c[v[i]];
  if(sum<0 || k<=n) return ret1;
  ll l = k%n;
  ll m = k/n;
  ll ret2 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    rep(j,l) {
      tmp += c[v[i+j]];
      ret2 = max(ret2,tmp);
    }
  }
  ret2 += sum*m;
  ll ret3 = sum*(m-1) + ret1;
  ll ret = max(ret3,max(ret1,ret2));
  return ret;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vll p(n), c(n);
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i,n) cin >> c[i];
  vector<bool> check(n,false);
  vector<vll> v;
  rep(i,n) {
    if(check[i]) continue;
    check[i] = true;
    ll key = i;
    vll tmp;
    tmp.push_back(key);
    ll a = key;
    while(true) {
      a = p[a];
      if(a==key) break;
      tmp.push_back(a);
      check[a] = true;
    }
    v.push_back(tmp);
  }
  ll ans = -1100000000000000000LL;
  rep(i,v.size()) {
    ll tmp = f(v[i],c,k);
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

const ll INF = 1000000000000000LL;

ll dp[5005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> h(n), p(n);
    vector<int> idxs(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i] >> p[i];
        dp[i + 1] = INF;
        idxs[i] = i;
    }
    sort(idxs.begin(), idxs.end(), [&](const int& i1, const int& i2){return h[i1] + p[i1] < h[i2] + p[i2];});
    for (int i = 0; i < n; i++) {
        int idx = idxs[i];
        for (int j = i; j >= 0; j--) {
            if (dp[j] <= h[idx]) dp[j + 1] = min(dp[j + 1], dp[j] + p[idx]);
        }
    }
    for (int i = n; i >= 0; i--) {
        if (dp[i] < INF) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  for(int i=0; i < k; i++){
    if(b <= a){
      b *= 2;
    }else if(c <= b){
      c *= 2;
    }
  }
    
    if((b > a) && (c > b)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int main() {
  long a, b;
  cin >> a >> b;
  long gcdNum;
  gcdNum = gcd(a, b);
  map<long, int> mp;
  // cout << "gcd: " << gcdNum << endl;
  for (long i = 2; i * i <= gcdNum; i ++) {
    if (gcdNum % i) continue;
    while (gcdNum % i == 0) {
      // cout << i << endl;
      gcdNum = gcdNum / i;
      mp[i] = 1;
    }
  }
  int sum = 0;
  if (gcdNum != 1) sum = 1;
  cout << mp.size() + sum + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
x=int(input())


a=list(map(int,input().split()))
for k in range(x-1):
    print(a[k],end=' ')
print(a[x-1])


for i in range(1,x):
    j=i-1
    b=a[i]
    
    while j >= 0 and a[j] > b:
        a[j+1]=a[j]
        j=j-1
   
        
    a[j+1]=b
    for k in range(x-1):
        print(a[k],end=' ')
    print(a[x-1])






Measured memory_bytes: 5980
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
    priority_queue<int> que;
    P A[110000];
    int N,M;
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>A[i].first>>A[i].second;
    }
    sort(A,A+N);
    int now=0;
    ll ans=0;

    for(int i=1;i<=M;i++){
        while(A[now].first<=i){
            que.push(A[now].second);
            now++;
        }
        if(que.size()){
        ans+=que.top();
        que.pop();

        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1788
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
vector<long long>t;
void dfs(long long a,int b){
	t.push_back(a);
	if(b==10)return;
	int s=a%10;
	if(s){
		dfs(a*10+s-1,b+1);
	}
	if(s<9)dfs(a*10+s+1,b+1);
	dfs(a*10+s,b+1);
}
int main(){
	int a;scanf("%d",&a);
	for(int i=1;i<10;i++){
		dfs(i,1);
	}
	std::sort(t.begin(),t.end());
	printf("%lld\n",t[a-1]);
}

Measured memory_bytes: 2548
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: f64
    }
    println!("{}", 2.0 * r * std::f64::consts::PI);
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;
int main()
{ 
	fast;
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
	  cin>>a[i];
	ll up[n+1][61];
	memset(up,0,sizeof(up));
	for(ll i=1;i<=n;i++)
	  up[i][0]=a[i];
	for(ll j=1;j<61;j++)
	  for(ll i=1;i<=n;i++)
	    up[i][j]=up[up[i][j-1]][j-1];
	ll strt=1,ct=0;
	for(ll i=60;i>-1;i--)
	  if(ct+(1ULL<<i)<=k)
	    strt=up[strt][i],ct=ct+(1ULL<<i);
	cout<<strt;
	return 0;
}

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

int main(void){
	int N;
	cin >> N;
	int T[N];
	for(int i=0;i<N;i++)cin >> T[i];
	int M;
	cin >> M;
	int P[M],X[M];
	for(int i=0;i<M;i++)cin >> P[i] >> X[i];
	int max = 0;
	for(int i=0;i<N;i++)max+=T[i];
	for(int i=0;i<M;i++){
		cout << max - T[P[i]-1] + X[i] << endl;
	}
	return 0;
}

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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000009
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    string s;
    cin >> s;
    vector<int> v(256);
    for(char a : s) {
        v[a]++;
    }
    REP(i, 256) {
        if(v[i] == 0 || v[i] == 2)
            continue;
        cout << "No";
        return 0;
    }

    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np
from collections import deque



def main():
	n,u,v=map(int,input().split())
	A=[[]for i in range(n+1)]
	
	for i in range(n-1):
		a,b=map(int,input().split())
		A[a].append(b)
		A[b].append(a)
		

	q = deque()
	a = [None] * (n + 1)
	b=[None] * (n + 1)
	q=[(u,0)]
	while q:
		now,cnt= q.pop()
		a[now]=cnt
		b[cnt]=now
		if now==v:
			za=b[(cnt-1)//2]
			ccnt=cnt
		for r in A[now]:
			if a[r] == None:
				q.append((r,cnt+1))
			else:
				continue
	
	q = deque()
	c = [None] * (n + 1)
	q=[(za,0)]
	while q:
		now,cnt= q.pop()
		c[now]=cnt
		for r in A[now]:
			if c[r] == None:
				q.append((r,cnt+1))
			else:
				continue
	
	
	zza=za
	q = deque()
	q = [v]
	while q:
		now=q.pop()
		if now==za:
			A[za]=[]
		c[now]=0
		for i in A[now]:
			if c[i]!=0:
				q.append(i)
			else:
				continue
				
	syoki=a[zza]
	
	ans=syoki+max(c[1:])
	if ccnt%2==0:
		ans+=1
	print(ans)
	
	



	
if __name__ == "__main__":
	main()


Measured memory_bytes: 67512
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];

template<class Abel, class OP>
class BIT {
  private:
    int n;
    std::vector<Abel> dat;
    OP op;
    Abel e;

  public:
    BIT(int n , OP op, Abel e = 0) : n(n), op(op), e(e){
		dat.resize(n + 1);
		for(int i = 0;i <= n;++i){
			dat[i] = e;
		}
    }
	void add(int k, Abel val){
		while(k <= n){
			dat[k] = op(val, dat[k]);
			k += k & -k;
		}
	}
	Abel acum(int k){
		Abel sum = e;
		while(k > 0){
			sum = op(sum, dat[k]);
			k -= k & -k;
		}
		return sum;
	}
};

ll n, m;
ll a[114514];

bool solve(ll x){
	vector<ll> b(n), s(n + 1);
	for (int i = 0;i < n;++i) {
		if(a[i] >= x)b[i] = 1;
		else b[i] = -1;
	}
	s[0] = 0;
	for (int i = 1;i <= n;++i) {
		s[i] = s[i - 1] + b[i - 1];
	}
	BIT<ll, function<ll(ll, ll)>> bit(4 * n, [](ll p, ll q){return p + q;}, 0);
	ll ans = 0;
	for(int i = 0;i <= n;++i){
		ll z = s[i] + 2 * n;
		ans += bit.acum(z);
		bit.add(z, 1);
	}
	return ans >= m;
}

signed main(){
	IOS();
	cin >> n;
	m = ceil(n * (n + 1) / 4.0);
	
	for (int i = 0;i < n;++i) {
		cin >> a[i];
	}
	ll left = 0, right = 1e9 + 2;
	while(right - left > 1){
		ll mid = (right + left) / 2;
		if(solve(mid))left = mid;
		else right = mid;
	}
	cout << left << endl;
	return 0;
}

Measured memory_bytes: 7720
#include<vector>
#include<iostream>
using namespace std;
template <class data_t>
class dice{
	int comp_dice_spin(dice<data_t> d2);
public:
	vector<data_t> field;
	dice(){}
	dice(vector<data_t> v);
	void roll(char ch);
	data_t top(){return field[0];}
	int comp_dice_type(dice<data_t> d2);
	int comp_dice(dice<data_t> d2);
	void levorotation_spin(){roll('W');roll('N');roll('E');}
};
template <class data_t>
dice<data_t>::dice(vector<data_t> v){
	typename vector<data_t>::iterator vi = v.begin();
	while(vi!=v.end()){
		field.push_back(*vi);
		vi++;
	}
}
template <class data_t>
void dice<data_t>::roll(char ch){
	data_t tmp;
	switch(ch){
		case 'E':
			tmp = field[0];
			field[0] = field[3];
			field[3] = field[5];
			field[5] = field[2];
			field[2] = tmp;
			break;
		case 'N':
			tmp = field[0];
			field[0] = field[1];
			field[1] = field[5];
			field[5] = field[4];
			field[4] = tmp;
			break;
		case 'S':
			tmp = field[0];
			field[0] = field[4];
			field[4] = field[5];
			field[5] = field[1];
			field[1] = tmp;
			break;
		case 'W':
			tmp = field[0];
			field[0] = field[2];
			field[2] = field[5];
			field[5] = field[3];
			field[3] = tmp;
			break;
	}
	return;
}
template <class data_t>
int dice<data_t>::comp_dice(dice<data_t> d2){
	int c;
	for(c=0;c<6;c++){
		if(field[c] != d2.field[c]){
			return field[c] - d2.field[c];
		}
	}
	return 0;
}
template <class data_t>
int dice<data_t>::comp_dice_type(dice<data_t> d2){
	if(comp_dice_spin(d2) == 0)return 0;
	roll('N');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('N');
	if(comp_dice_spin(d2) == 0)return 0;
	return -1;
}
template <class data_t>
int dice<data_t>::comp_dice_spin(dice<data_t> d2){
	int i;
	for(i=0;i<4;i++){
		if(comp_dice(d2) == 0)
			return 0;
		levorotation_spin();
	}
	return -1;
}
int main(){
	int i, j, n;
	bool not_i_differ_all = false;
	vector<int> v(6);
	cin >> n;
	vector<dice<int> > dv;
	for(i=0;i<n;i++){
		cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]>> v[5];
		dv.push_back(v);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(dv[i].comp_dice_type(dv[j]) == 0){
				i=j=n;
				not_i_differ_all++;
			}
		}
	}
	if(not_i_differ_all){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define il inline
#define ll long long
const int N=1e5+5;
 
int n,s,x[N]; ll p[N];
 
il ll cal(int l,int r,int t)
{
	if (s<x[l]) return x[r]-s; if (x[r]<s) return s-x[l];
	if (p[l]>=p[r]) return p[l]+=p[r],cal(l, r - 1, l)+(t==r)*(x[r]-x[l]);
	return p[r]+=p[l],cal(l+1,r,r)+(t==l)*(x[r]-x[l]);
}
 
int main()
{
	scanf("%d%d",&n,&s); int i;
    for (i=1; i<=n; i++) scanf("%d%lld",x+i,p+i);
	
	printf("%lld", cal(1,n,p[1]<p[n]?1:n));

	return 0;
}

Measured memory_bytes: 10076
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void){
	int x[4][3][10]={0};
	int b,f,r,v;
	int n;
	int i,j,k;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf(" %d %d %d %d",&b,&f,&r,&v);
		x[b-1][f-1][r-1] += v;
	}
	
	for(i = 0;i < 4;i++){
		for(j = 0;j < 3;j++){
			for(k = 0;k < 10;k++){
				printf("%2d",x[i][j][k]);
			}
			printf("\n");
		}
		if(i==3) break;
		for(k = 0;k < 20;k++){
			printf("#");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n,k;
      cin >> n >> k;
      string s;
      cin >> s;
      s[k-1] = tolower(s[k-1]);
      cout << s << endl;
      return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;

int bit[N][26];

void update(int pos, int id, int val) {
	for (int i = pos; i <= N; i += i & (-i))
		bit[i][id] += val;
}

int query(int pos, int id) {
	int res = 0;
	for (int i = pos; i >= 1; i -= i & (-i))
		res += bit[i][id];
	return res;
}

int main() {
	int n; string s; cin >> n >> s;
	for (int i = 1; i <= n; i++)
		update(i, s[i - 1] - 'a', 1);
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int op; cin >> op;
		if (op == 1) {
			int j; char c; cin >> j >> c;
			update(j, s[j - 1] - 'a', -1);
			update(j, c - 'a', 1);
			s[j - 1] = c;
		} else {
			int l, r; cin >> l >> r;
			int ans = 0;
			for (int j = 0; j < 26; j++) 
				if (query(r, j) - query(l - 1, j))
					++ans;
			cout << ans << "\n";		
		}
	}
}

Measured memory_bytes: 51716
// finish date: 2018/01/24
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define bigmod 1000000007
#define INF 500000000

string S;
string ans = "";

void dfs(string op = "") {
    if (ans != "") return;
    if (op.size() == 3) {
        int sum = S[0] - '0';
        rep(i, 3) {
            if (op[i] == '+') sum += S[i + 1] - '0';
            else sum -= S[i + 1] - '0';
        }
        if (sum == 7) {
            ans += S[0];
            rep(i, 3) {
                ans += op[i];
                ans += S[i + 1];
            }
            ans += "=7";
        }
        return;
    }

    dfs(op + "+");
    dfs(op + "-");

}

int main() {
    cin >> S;
    dfs();
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import sys
from collections import deque

readline = sys.stdin.readline
n, m, k = map(int, readline().split())

friend = [set() for i in range(n)]
not_friend = [set() for i in range(n)]
for i in range(m):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    friend[a].add(b)
    friend[b].add(a)
for i in range(k):
    c, d = map(int, readline().split())
    c -= 1
    d -= 1
    not_friend[c].add(d)
    not_friend[d].add(c)

suggest_friends = [-1] * n
for i in range(n):
    if suggest_friends[i] != -1:
        continue
    q = deque(friend[i])
    friend_group = set(friend[i])
    while q:
        p = q.popleft()
        for f in friend[p]:
            if not(f in friend_group):
                q.append(f)
                friend_group.add(f)
    num = len(friend_group)
    for f in friend_group:
        suggest_friends[f] = num - 1 - len(friend[f] | not_friend[f] & friend_group)

for i in range(n):
    if suggest_friends[i] == -1:
        suggest_friends[i] = 0
print(*suggest_friends)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int F = 0, K = 0;
  rep(i, N) {
    int a; cin >> a;
    if (a % 4 == 0) F++;
    if (a % 2 == 1) K++;
  }

  if (N % 2) {
    cout << (K - 1 <= F ? "Yes" : "No") << "\n";
  } else {
    cout << (K <= F ? "Yes" : "No") << "\n";
  }
}


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

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

int main() {
    ll a,b;
    cin>>a>>b;    
    ll lcm = a/gcd(a, b)*b;

    cout <<  lcm << endl;
    
    
    return 0;
}



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

using namespace std;

const int MX = 10000;

string solve(string S, int k) {
	if (k == 0) return S;
	
	while (k--) {
		int i = (int)S.size() - 1, cnt = 0;
		while (i >= 0 && S[i] == S.back()) i--, cnt++;
		
		if (i == -1) break;
		
		S = S.substr(cnt) + string(cnt, S.back());
	}
	
	reverse(S.begin(), S.end());
	
	return S;
}

char s[MX];

int main() {
	int n, k;
	ignore = scanf("%d %d %s", &n, &k, s);
	
	for (int i = n, j = n - 1; i < 2 * n; i++, j--) s[i] = s[j];
	
	string ans(n, 'z');
	for (int i = 0; i <= n; i++) {
		string S(s + i, s + i + n);
		ans = min(solve(S, k - 1), ans);
	}
	
	printf("%s\n", ans.c_str());
	
	return 0;
}


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

constexpr int INF = 1e9;

int G[10010];
int w[1010];
int a[1010];

void swap( int& a, int& b ){
  int tmp = a;
  a = b;
  b = tmp;
}

int Partition( int p, int r ){
  int x = a[r];
  int i = p - 1;
  for( int j = p; j < r; j++ ){
    if( a[j] <= x ){
      i++;
      ::swap( a[i], a[j] ); 
    }
  }
  ::swap( a[i + 1], a[r] );

  return i + 1;
}

void QuickSort( int p, int r ){
  if( p < r ){
    int q = Partition( p, r );
    QuickSort( p, q - 1 );
    QuickSort( q + 1, r );
  }
}

bool seen[10010];
int sum = 0, cnt = 0, pmin = INF;
void rec( int s ){
  if( seen[s] ) return;

  seen[s] = true;
  sum += s;
  pmin = min( pmin, s );
  cnt++;
  rec( G[s] ); 
}

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

  QuickSort( 0, N - 1 );

  for( int i = 0; i < N; i++ ){
    int j;
    for( j = 0; j < N; j++ ){
      if( w[i] == a[j] ) break;
    }
    G[w[i]] = w[j];
  }

  int ans = 0;
  int smin = a[0];
  for( int i = 0; i < N; i++ ){
    sum = 0;
    pmin = INF;
    cnt = 0;

    rec( w[i] );
    if( cnt >= 2 ){
      ans += min( sum + ( cnt - 2 ) * pmin, sum + pmin + ( cnt + 1 ) * smin );
    }
  }

  cout << ans << endl;
  
}



Measured memory_bytes: 3148
/*Author
   SaJiB */

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


#define pb   push_back
#define fi   first
#define se   second
#define all(x)    x.begin(),x.end()

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef long long int ll;
typedef unsigned long long int ull;
const double pi = 2.0*acos(0.0);

#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

char small[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'} ;

ll big_mod(ll BASE, ll POWER, ll MOD){

    if(POWER == 0) return 1;
    else if(POWER %2 ==0){
        ll RESULT = big_mod(BASE,POWER/2,MOD);
        return ((RESULT % MOD)*(RESULT % MOD))% MOD;
    }
    else return ((BASE % MOD)*(big_mod(BASE,POWER-1,MOD)% MOD))% MOD;

}

int main(){

int t;
cin>>t;

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

}


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

using namespace std;

#define ll long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define mod 1000000007 //998244353
#define mii map<int, int>
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word



const long long N = 200005, INF = 2000000000000000000;
//lld pi = 3.1415926535897932;
int lcm(int a, int b)
{
  int g = __gcd(a, b);
  return a / g * b;
}
int power(int a, int b, int p)
{
  if (a == 0)
    return 0;
  int res = 1;
  a %= p;
  while (b > 0)
  { if (b & 1)
      res = (res * a) % p;
    b >>= 1;
    a = (a * a) % p;
  }
  return res;
}

int testcaseva;

int sq(int x) { return 1ll * x * x; }

void rec(int n) {
  int p = n;
  if (n == 0)
    return ;
  cout << p - n << " ";
  return rec(n - 1);


}
ll n,c;
ll ar[100005];
bool valid(int m,int c,int n){
    int cnt =0;
    int pr = INT_MIN;
    for(int i=0;i<n;i++)
    {
        if(ar[i]-pr >= m)
            cnt++ , pr = ar[i];
    }
    if(cnt >= c)
    return true;
    else return false;

}
int main() {
//#ifndef ONLINE_JUDGE
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
//#endif
  // int t;
  // cin >> t;
  // while (t--)
  int t=1;
  //cin >> t;
  while(t--){
     int l,r,d;
    cin>>l>>r>>d;
    int t1=l/d;
    t1*=d;
    if(t1<l)
        t1+=d;
    t1/=d;
    int t2=r/d;
    cout<<t2-t1+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){

  string s;
  cin>>s;
  int k;
  cin>>k;

  vector<string> s_set;

  if(s.length()==1){
    cout << s << endl;
    return 0;
  }

  for(int i=1;i<=s.length() and i <= 5;i++){
    for(int j=0;j<s.length()-i+1;j++){
      s_set.push_back(s.substr(j,i));
    }
  }

  for(string kk:s_set){
    //cout << kk << endl;
  }

  //cout << endl;

  sort(s_set.begin(),s_set.end());

  for(string kk:s_set){
    //cout << kk << endl;
  }

  //cout << endl;

  s_set.erase(unique(s_set.begin(),s_set.end()),s_set.end());

  for(string kk:s_set){
    //cout << kk << endl;
  }

  //cout << endl;

  cout << s_set[k-1] << endl;

  return 0;
}


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

int main()
{
	int n,max,min;
	long long int sum = 0;
	cin >> n;
	int *num=new int[n];

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

	// 配列を昇順に並び替える
	for (int i = 0;i < n - 1;i++)
	{
		for (int j = i + 1;j < n;j++)
		{
			if(num[j]<num[i])
			{ 
				int tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}
		}
	}

	min = num[0];
	max = num[n - 1];

	for (int i = 0;i < n;i++)
	{
		sum += num[i];
	}

	cout << min << ' ' << max << ' ' << sum << '\n';
	delete[] num;
}


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

using namespace std;

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

	int n, current, neww;
	cin >> n >> current;
	int dist = 0, longest= 0;
	while(--n)
    {
        cin >> neww;
        if(neww <= current)
        {
            dist++;
        }
        else{
            if(dist > longest)
                longest = dist;
            dist = 0;
        }
        current = neww;
    }
     if(dist > longest)
                longest = dist;
    cout << longest;
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

int n, m;
vi c;
bool z[100000];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  c.resize(n);
  fill(rng(c), 1);
  z[0] = true;
  FOR(i, 0, m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    z[y] |= z[x];
    c[x]--; c[y]++;
    if(c[x] == 0) z[x] = false;
  }
  int ans = 0;
  FOR(i, 0, n) if(z[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
#define all(a) a.begin(), a.end() 
using namespace std;


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


Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,M;
    cin >> N >> M;
    ll A[N];
    ll out = 0;
    rep(i,N){
        cin >> A[i];
        out += A[i];
    }
    sort(A,A+N);
    vector<pair<ll,ll>> v;
    rep(i,M){
        pair<ll,ll> p;
        cin >> p.second >> p.first;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    ll cnt = 0;
    rep(i,M){
        rep(j,v[M-1-i].second){
            for(ll k=cnt;k<N;k++){
                cnt++;
                if(A[k] < v[M-1-i].first){
                    A[k] = v[M-1-i].first;
                    break;
                }
            }
        }
        if(cnt==N) break;
    }
    out = 0;
    rep(i,N) out += A[i];
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 6124
// 線形探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 10000;
//const int MAX_Q = 500;

bool linearSearch(int A[], int n, int key);

int main(void)
{

    int n, q, key, count = 0;
    int ary_N[MAX_N];

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &ary_N[i]);
    }

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &key);

        if( linearSearch(&ary_N[0], n, key) == true )
        {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}

// 線形探索
bool linearSearch(int A[], int n, int key)
{
    int i = 0;
    // 終了条件の番兵の代入
    A[n] = key;

    while( A[i] != key )
    {
        i++;
    }

    return i != n;
}



Measured memory_bytes: 3208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;


public class Main {
	
	static int n,m,x;
	static int[] a = new int[101];
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
	    BufferedReader in = new BufferedReader(reader);
		
		String s = in.readLine();
		String[] as = s.split(" ");
		n = Integer.parseInt(as[0]);
		m = Integer.parseInt(as[1]);
		x = Integer.parseInt(as[2]);
		
		s = in.readLine();
		String[] as2 = s.split(" ");
		
		for (int i=0; i < m; i++) {
			a[Integer.parseInt(as2[i])] = 1;
		}
		System.out.println(solve());
	}

	private static int solve() {
		int ans0 = 0;
		int ansN = 0;
		for(int i = x; i < n; i++) {
			
			ans0 += a[i];
		}
		if(ans0==0) return 0;
		for(int i = x; i > 0; i--) {
			ansN += a[i];
		}
		if(ans0>ansN) {
			return ansN;
		} else {
			return ans0;
		}
		
	}

	
	
}

Measured memory_bytes: 21332
#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");
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 double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> head;
  vector<int> tail;

  rep (i, n) {
    int a;
    cin >> a;
    
    if (i % 2 == 0 && i != 0) {
      head.push_back(a);
    } else {
      tail.push_back(a);
    }
  }

  vector<int> ans;

  if (n % 2 != 0) {
    reverse(head.begin(), head.end());
    for (auto v : head) ans.push_back(v);
    for (auto v : tail) ans.push_back(v);
  } else {
    reverse(tail.begin(), tail.end());
    for (auto v : tail) ans.push_back(v);
    for (auto v : head) ans.push_back(v);
  }

  for (auto v : ans) {
    cout << v << " ";
  }
  cout << endl;
  return 0;
}


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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;

        if(a == b && b== c && a==c) {
            count = 1;
        }

        else if(a != b && b!= c && a!=c){
            count = 3;

            }
        else{
            count = 2;
        }
        System.out.println(count);


        }
    }

Measured memory_bytes: 9680
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]

S = [0] * (N + 1)
for i in range(N + 1):
    S[i] = abs(A[i + 1] - A[i])

T = [0] * N
for i in range(N):
    T[i] = abs(A[i + 2] - A[i])

cost = sum(S)
for i in range(N):
    print(cost - S[i] - S[i + 1] + T[i])


Measured memory_bytes: 57196
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  string s;
  cin>>n>>s;

  int ans=0;
  repo(i,n){
    int cnt=0;
    int len=0;
    rep(j,n-i){
      if(s[j]==s[j+i]) cnt++;
      else cnt=0;
      chmin(cnt,i);
      chmax(len,cnt);
    }
    chmax(ans,len);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3664
#include<stdio.h>
#include<string.h>

int main(){

	char A[101];
	char B[101];
	int Flag = 0;

	scanf("%s %s",A,B);
	int lenA = strlen(A);
	int lenB = strlen(B);

	if(lenA > lenB){
		printf("GREATER");
	}else if(lenA < lenB){
		printf("LESS");
	}else{
		for(int i=0; i<lenA; i++){
			if( A[i]>B[i] ){
				printf("GREATER");
				Flag = 1;
				break;
			}else if( A[i]<B[i] ){
				printf("LESS");
				Flag = 1;
				break;
			}else{
				/*続行*/
			}
		}
		if(Flag == 0){
			printf("EQUAL");
		}
	}

	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  string s;
  cin >> s;
  if(s[0] == '7' || s[1] == '7' || s[2] == '7')
    cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[n],mi[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
    mi[i]=1e9;
  }
  mi[0]=0;
  for(int i=0;i<n;i++){
    if(i+1<n)mi[i+1]=min(mi[i+1],mi[i]+abs(arr[i+1]-arr[i]));
    if(i+2<n)mi[i+2]=min(mi[i+2],mi[i]+abs(arr[i+2]-arr[i]));
  }
  cout<<mi[n-1]<<endl;
}

Measured memory_bytes: 1024
n = int(input())
a = input().split()

aa = [int (i) for i in a]
check = 0
count = -1

while check == 0:
    for i in range(n):
        if aa[i] % 2 == 0:
            aa[i] = aa[i] / 2
        else:
            check = 1
    count += 1
    if count > 100:
        break

print(count)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int d[101] = {};
int f[101] = {};
int t = 0;
vector<int> G[101];

void dfs(int x){
    t++;
    d[x] = t;
    for(auto y:G[x]){
        if(d[y]==0)dfs(y);
    }
    t++;
    f[x] = t;
}

/*----------------------------------------------------------------*/
signed main(){

    int n;
    cin >> n;
    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(i,k){
            int v;
            cin >> v;
            G[u-1].pb(v-1);
        }
    }
    rep(i,n)if(d[i]==0)dfs(i);
    rep(i,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://arc054.contest.atcoder.jp/tasks/arc054_b


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

int main(){
  long long n, a, b, ans;
  scanf("%ld %ld %ld", &n, &a, &b);
  
  ans += n/(a+b)*a;
  ans += (n%(a+b)<=a)? n%(a+b) : a;
  
  printf("%ld\n", ans);
}

Measured memory_bytes: 256