akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int x,y,z,d;
   cin>>x>>y>>z>>d;
   if(abs(x-z)<=d || (abs(x-y)<=d && abs(y-z)<=d)){
    cout<<"Yes"<<endl;
   }
   else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){
  VI c(3);
  
  FOR(i,0,3){
    cin >> c[i];
  }
  SORT(c);

  if(c[0] + c[1] == c[2]){
    FINA("Yes");
  }
  else{
    FINA("No");
  }

 return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int h, w;
  cin >> h >> w;
  if(h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  if(h%2 == 0 || w %2 == 0) {
    cout << w * h / 2;
  } else {
    cout << w * h / 2 + 1;
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main(){
    int n, k;
    cin >> n >> k;
    if( n*500 >= k ){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}
/*
7 2
0 1 0 0 0 1 0
*/


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define CENTINEL 2000000000
#define MAX 200000
typedef long long int llong;
int n,A[200000];
int L[MAX/2+2],R[MAX/2+2];
llong merge(int A[],int left,int mid,int right){
  int na=mid-left;
  int nb=right-mid;
  llong sum=0;
  for(int i=0;i<na;i++)L[i]=A[left+i];
  for(int i=0;i<nb;i++)R[i]=A[mid+i];
  L[na]=R[nb]=CENTINEL;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j])A[k]=L[i++];
    else {A[k]=R[j++];sum+=na-i;}
  }
  return sum;
}
llong mergesort(int A[],int left,int right){
  llong v1,v2,v3;
  if(left+1<right){
    int mid=(left+right)/2;
    v1=mergesort(A,left,mid);
    v2=mergesort(A,mid,right);
    v3=merge(A,left,mid,right);
    return v1+v2+v3;
  } else return 0;
}
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  llong cnt;
  cnt=mergesort(A,0,n);
  printf("%lld\n",cnt);
  return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
bool ok[10] = {false};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int a; cin >> a;
    ok[a] = true;
  }
  for (;;) {
    int x = n;
    while (x>0) {
      if (ok[x%10] == true) break;
      x /= 10;
    }
    if (x == 0) {
      cout << n << '\n';
      break;
    }
    n++;
  }
}


Measured memory_bytes: 256
S = input()
l = len(S)
x = 0
for i in range(l):
    j = i + x + 1
    while(j <= l):
        k = i
        flag = True
        while(k < j):
            if S[k] not in ['A', 'C', 'G', 'T']:
                flag = False
                break
            else:
                k += 1
        if flag:
            x = j - i
        j += 1
print(x)


Measured memory_bytes: 3060
N,W=map(int,input().split())
from collections import*
d=defaultdict(int)
d[0]=0
for i in range(N):
    w,v=map(int,input().split())
    for k,b in d.copy().items():
        if k+w<=W:
            d[k+w]=max(d[k+w],b+v)
print(max(d.values()))

Measured memory_bytes: 4016
<?php
fscanf(STDIN,"%d %d",$x,$n);
$p = explode(" ",trim(fgets(STDIN)));
$tmp = 100;

if ($n == 0) {
    echo $x.PHP_EOL;
    exit;
}

for ($i = 0;$i <= 101;++$i) {
    if (!in_array($i,$p) and $tmp > abs($x - $i)) {
        $tmp = abs($x - $i);
        $ans = $i;
    }
}
echo $ans.PHP_EOL;

Measured memory_bytes: 16200
//////////////////////////////////////////////
//root@NULLCT$(☝ ՞ਊ ՞)☝  << "Be accept!!"//
//////////////////////////////////////////////
//#define BOOST
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int66_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setfill(char)
#include <ios>       //left,right
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp> // cpp_int
using namespace boost::multiprecision;
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int setup(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }
int lenght(char* str) { int i = 0; while (str[i])i++; return i; }
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int iinput(void) { int a = 0; cin >> a; return a; }
int dinput(void) { double a = 0; cin >> a; return a; }
string sinput(void) { string a = ""; cin >> a; return a; }
int kuriup(double a) { int b = int(a); if (a != b) { return b + 1; } else { return b; } }
int kuridown(double a) { int b = int(a); return b; }
int run(void);
int main() { setup(); run(); return 0; }
#define SIZE 15
int run(void) {

	vector<int> a(9);
	rep(i, 9)cin >> a[i];
	int n = 0;
	cin >> n;
	vector<int> b(n);
	rep(i, n)cin >> b[i];
	for (int i = 0; i < n; i++) {
		for (int w = 0; w < 9; w++) {
			if (b[i] == a[w]) {
				a[w] = 0;
			}
		}
	}
	
	bool tr = false;
	for (int i = 0; i < 3; i++) {
		if (a[i * 3] == 0 && a[1 + i * 3] == 0 && a[2 + i*3] == 0) {
			tr = true;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (a[i] == 0 && a[i+3] == 0 && a[i+6] == 0) {
			tr = true;
		}
	}
	if (a[0] == 0 && a[4] == 0 && a[8] == 0) {
		tr = true;
	}
	if (a[2] == 0 && a[4] == 0 && a[6] == 0) {
		tr = true;
	}
	if (tr) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/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;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B;
  cin>>A>>B;
  if(A>B) A--;
  cout<<A;
return 0;}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1002;

ll n,c;
vector<ll> D1,D2,D3;
vector<vector<ll> > cc;
vector<ll> d1,d2,d3;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>c;
	FOR(i,0,c){
		vector<ll> pp;
		cc.pb(pp);
		FOR(j,0,c){
			ll k;cin>>k;
			cc[i].pb(k);
		}
	}
	FOR(i,0,n){
		FOR(j,0,n){
			ll k;cin>>k;k--;
			if((i+j)%3==0)D1.pb(k);
			if((i+j)%3==1)D2.pb(k);
			if((i+j)%3==2)D3.pb(k);
		}
	}
	FOR(i,0,c){
		ll k=0;
		FOR(j,0,D1.size()){
			k+=cc[D1[j]][i];
		}
		d1.pb(k);
	}
	FOR(i,0,c){
		ll k=0;
		FOR(j,0,D2.size()){
			k+=cc[D2[j]][i];
		}
		d2.pb(k);
	}
	FOR(i,0,c){
		ll k=0;
		FOR(j,0,D3.size()){
			k+=cc[D3[j]][i];
		}
		d3.pb(k);
	}

	ll ans=INF;
	FOR(i,0,c){
		FOR(j,0,c){
			if(i==j)continue;
			FOR(k,0,c){
				if(i==k||j==k)continue;
				ans=min(ans,d1[i]+d2[j]+d3[k]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

vector<ll> fact;
vector<ll> fact_inv;

void init_fact(int n) {
  fact.resize(n + 1);
  fact_inv.resize(n + 1);
  fact[0] = fact_inv[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  init_fact(2 * n);
  vector<ll> sum(n + 1);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = (sum[i] + mod_inv(i + 1)) % MOD;
  }
  ll ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    ll res = (x[i + 1] - x[i] + MOD) % MOD;
    res = (res * sum[i + 1]) % MOD;
    ans = (ans + res) % MOD;
  }
  ans = (ans * fact[n - 1]) % MOD;
  cout << ans << endl;
  return 0;
}

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

void Main()
{
	vector<int> arr(5);
	rep(i,5) cin >> arr[i];
	int k; cin >> k;
	cout << (arr[4] - arr[0] > k ? ":(" : "Yay!") << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

const ll mod = 1000000007;
const int INF = 1001001001;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s, t; cin >> s >> t;
	int ans = INF;
	for(int i = 0; i < s.size() - t.size() + 1; i++){
		int tmp = 0;
		for(int j = 0; j < t.size(); j++){
			if(s[i + j] != t[j]) tmp++;
		}
		ans = min(tmp, ans);
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) : s(s), d(d), w(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

auto bfs = [&](const Graph &g, int s, Array &dist) {
	int n = g.size();
	vector<bool> vis(n);
	vector<int> prev(n, -1);
	dist.assign(n, INF); dist[s] = 0;
	using State = tuple<Weight, int, int>;
	queue<State> q;
	q.emplace(0, s, -1);
	while (q.size()) {
		Weight d; int v, p; tie(d, v, p) = q.front(); q.pop();
		vis[v] = true;
		prev[v] = p;
		for (auto &e : g[v]) {
			if (vis[e.d])continue;
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				q.emplace(dist[e.d], e.d, v);
			}
		}
	}
	return prev;
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int K; cin >> K;
	Graph g(N);
	vector<int> a(N - 1), b(N - 1); rep(i, 0, N - 1) {
		cin >> a[i] >> b[i]; a[i]--, b[i]--;
		addEdge(g, a[i], b[i]);
	}
	int ans = INF;
	if (K % 2 == 0) {
		rep(i, 0, N) {
			Array dist;
			bfs(g, i, dist);
			int c = 0;
			rep(j, 0, N) {
				if (dist[j] > K / 2) {
					c++;
				}
			}
			chmin(ans, c);
		}
	}
	else {
		rep(i, 0, N - 1) {
			Array dist1, dist2;
			bfs(g, a[i], dist1);
			bfs(g, b[i], dist2);
			dump(a[i], b[i]);
			int c = 0;
			rep(j, 0, N) {
				int d = min(dist1[j], dist2[j]);
				dump(d);
				if (d > K / 2) {
					c++;
				}
			}
			chmin(ans, c);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    int M = 1 + (N & 1);
    constexpr ll inf = 1e+17;
    // (is_used, max(unused - used))
    vector<vector<ll>> dp(2, vector<ll>(M + 1, -inf));
    dp[0][0] = 0;
    for(int loop = 0; loop < N; ++loop){
        int A;
        cin >> A;
        vector<vector<ll>> nxt_dp(2, vector<ll>(M + 1, -inf));
        for(int i = 0; i < 2; ++i){
            for(int j = 0; j <= M; ++j){
                if(dp[i][j] == -inf)    continue;
                if(i)   chmax(nxt_dp[0][j], dp[1][j]);
                else{
                    if(j < M)   chmax(nxt_dp[0][j + 1], dp[0][j]);
                    chmax(nxt_dp[1][j], dp[0][j] + A);
                }
            }
        }
        dp = move(nxt_dp);
    }
    ll ans = -inf;
    for(int i = 0; i < 2; ++i){
        for(int j = (N & 1 ? 1 : 0); j <= M; ++j){
            chmax(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> V(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	sort(V.begin(), V.end());
	int a = 0, b = 0;
	for (int i = 0; i < V.size(); i++) {
		if (i % 2)a += V[i];
		else b += V[i];
	}
	cout << abs(a - b) << endl;
	return 0;
}

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

int main() {
    int n, count=0, ans=0, ansmax=0; 
    cin >> n;
    vector<int> vec(n);
    vector<int> rate(9);

    for(int i=0; i<n; i++) {
        cin >> vec.at(i);
        
        if(1<=vec.at(i) && vec.at(i)<=399) rate.at(0)++;
        else if(400<=vec.at(i) && vec.at(i)<=799) rate.at(1)++;
        else if(800<=vec.at(i) && vec.at(i)<=1199) rate.at(2)++;
        else if(1200<=vec.at(i) && vec.at(i)<=1599) rate.at(3)++;
        else if(1600<=vec.at(i) && vec.at(i)<=1999) rate.at(4)++;
        else if(2000<=vec.at(i) && vec.at(i)<=2399) rate.at(5)++;
        else if(2400<=vec.at(i) && vec.at(i)<=2799) rate.at(6)++;
        else if(2800<=vec.at(i) && vec.at(i)<=3199) rate.at(7)++;
        else if(3200<=vec.at(i) && vec.at(i)<=4800) rate.at(8)++;
    }

    for(int i=0; i<8; i++) {
        if(rate.at(i)>0) ans++;
    }

    ansmax=ans+rate.at(8);

    if(ans==0) ans++;

    cout << ans << " " << ansmax << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(long long A, long long B, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> x, std::vector<long long> y, std::vector<long long> c){
	LL ma=a[0];
	LL mb=a[0];
	for(auto i:a){
		ma=min(ma,i);
	}
	for(auto i:b){
		mb=min(mb,i);
	}
	LL ret=ma+mb;
	for(int i=0;i<M;i++){
		ret=min(ret,a[x[i]-1]+b[y[i]-1]-c[i]);
	}
	cout << ret << endl;

}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&b[i]);
    }
    std::vector<long long> x(M);
    std::vector<long long> y(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&c[i]);
    }
    solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y), std::move(c));
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<n;i++){
    if(n-i>i&&n-i>1&&n){
      ans++;
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int Max = 100010;
typedef pair<int, int> P;

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

int n;
int v[Max], cnt[Max];
P best[2][2];

void Get(int from){
    fill(cnt, cnt + Max, 0);
    for (int i = from; i < n; i += 2){
        cnt[v[i]]++;
    }
    for (int i = 1; i < Max; i++){
        if (P(cnt[i], i) > best[from][0]){
            best[from][1] = best[from][0];
            best[from][0] = P(cnt[i], i);
        }else if (P(cnt[i], i) > best[from][1]) best[from][1] = P(cnt[i], i);
    }
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> v[i];
    Get(0);
    Get(1);
    int res = 0;
    if (best[0][0].second != best[1][0].second) res = best[0][0].first + best[1][0].first;
    else{
        res = max(best[0][0].first + best[1][1].first, best[0][1].first + best[1][0].first);
    }

    cout << n - res << endl;    

    return 0;
}

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

using namespace std;

int main(){
    vector <char> a(26);
    for(char i = 0; i<26; i++){
        a.at(i) = 'a' + i;
    }

    char ch;
    vector <int> a_count(26);
    while(cin >> ch){
        if('A'<= ch && ch <= 'Z') ch += 32; 
        for(int i = 0; i<26; i++){
            if(a.at(i) == ch) a_count.at(i)++;
        }
    }
    
    // output
    for(int i = 0; i<26; i++){
        cout << a.at(i) << " : " << a_count.at(i) << endl; 
    }

    return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int dfs(int N,int k,string s){
  if(N==0) cout<<s<<endl;
  else{
    for(int i=0;i<=k;i++){
      int l=k;
      if(i==k) l++;
      if(i==0) dfs(N-1,l,s+'a');
      if(i==1) dfs(N-1,l,s+'b');
      if(i==2) dfs(N-1,l,s+'c');
      if(i==3) dfs(N-1,l,s+'d');
      if(i==4) dfs(N-1,l,s+'e');
      if(i==5) dfs(N-1,l,s+'f');
      if(i==6) dfs(N-1,l,s+'g');
      if(i==7) dfs(N-1,l,s+'h');
      if(i==8) dfs(N-1,l,s+'i');
      if(i==9) dfs(N-1,l,s+'j');
    }
  }
  return 0;
}
int main(){
  int N;
  cin>>N;
  string s="a";
  dfs(N-1,1,s);
  
  return 0;
}

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

using namespace std;

vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;

      vector<vector<int>> grid(H, vector<int>(W, -1));

      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      grid[i][j] = 0;

      while (!que.empty()) {
        auto q = que.front();
        que.pop();
        int y = q.first, x = q.second;
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k], nx = x + dx[k];
          if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
          if (S[ny][nx] == '#' || grid[ny][nx] != -1) continue;
          grid[ny][nx] = grid[y][x] + 1;
          que.push(make_pair(ny, nx));
        }
      }

      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          res = max(res, grid[y][x]);
        }
      }
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
n=int(input())
k=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(k[n-1])

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a;
  b = a;
  int sum = 0;
  while(a>0){
    sum += a%10;
    a /= 10;
  }
  if(b%sum==0) cout << "Yes";
  else cout << "No";
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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 pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, M; cin >> N >> M;
	vector<vint> G(N);
	REP(i, M){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].eb(b); G[b].eb(a);
	}

	queue<pint> que; que.push({0, -1});
	vector<bool> visit(N, 0);
	visit[0] = 1;
	vint ans(N);
	while(!que.empty()){
		pint p = que.front(); que.pop();
		int pos = p.first;
		ans[pos] = p.second+1;
		for(int nx: G[pos]){
			if(!visit[nx]){
				visit[nx] = 1;
				que.push({nx, pos});
			}
		}
	}

	cout << "Yes" << ln;
	RANGE(i, 1, N){
		cout << ans[i] << ln;
	}
}

Measured memory_bytes: 10644
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);CIN(K);
    if(N % K == 0){
        COUT(0);
    }else{
        COUT(1);
    }
    return 0;
}


Measured memory_bytes: 764
//semicolon less Java
class Main{
    public static void main(String[] args){
        for(String[] str : new String[][]{{"CODEFESTIVAL2016",
            new java.util.Scanner(System.in).next()}}){

            for(int[] var : new int[][]{{0, 0}}){
                while(var[0] < str[0].length()){
                    if(str[0].charAt(var[0]) != str[1].charAt(var[0])){
                        var[1]++;
                    }
                    if(var[0]++ > 0){}
                }
                if(System.out.printf("%d\n", var[1]) == null){}
            }
        }
    }
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;

	int cnt = 0;
	while (N != 0)
	{
		N /= K;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

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

int main(){
    int A, B;
    std::cin >> A >> B;
    int min8 = std::ceil(A / 0.08);
    int max8 = std::ceil((A+1) / 0.08) - 1;
    int min10 = std::ceil(B / 0.1);
    int max10 = std::ceil((B+1) / 0.1) - 1;
    
    int min = min8>min10?min10:min8;
    int max = max8>max10?max8:max10;
    
    bool find = false;
    int i;
    for(i=min; i<=max; i++){
        if(i >= min8 && i <= max8 && i >= min10 && i <= max10){
            find = true;
            break;
        }
    }
    if(find){
        std::cout << i << std::endl;
    }else{
        std::cout << -1 << std::endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
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();
    if(a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vector <int> A(N);
    vector <int> additions(N+1, 0);
    for (int i=0; i<N; ++i)
    {
        cin >> A[i];
    }
    while (K--)
    {
        queue < pair < pair <int, int>, long long > > Q;
        for (int i=0; i<N; ++i)
        {
            long long val = A[i];
            if (val) 
            {
                additions[max(i-val,0ll)] += 1;
                additions[i]-=1;
                additions[i+1] += 1;
                additions[min((ll)N, i+val+1)] -=1;
            }
            additions[i]+=(1-val);
            additions[i+1]-=(1-val);
        }
        bool finished = true;
        A[0]=A[0]+additions[0];
        for (int i=1; i<N; ++i)
        {
            additions[i]+=additions[i-1];
            A[i] = A[i]+additions[i];
        }
        additions.assign(N+1, 0);

        for (int i=0; i<N; ++i)
        {
            if (A[i]!=N) {finished=false; break;}
        }
        if (finished) break;
    }
    for (int i=0; i<N; ++i) cout << A[i] << " "; cout << "\n";
    return 0;
}

Measured memory_bytes: 4744
def cal(XL):
    N = len(XL)
    XL.sort(key = lambda x:x[0])
    for i in range(N):
        XL[i] = [XL[i][0],XL[i][0]-XL[i][1],XL[i][0]+XL[i][1]]
    OP = [XL[0]]

    for i in range(1,N):
        if OP[len(OP)-1][2] > XL[i][1]:
            if OP[len(OP)-1][2] < XL[i][2]:
                #右方向により腕が伸びている方がより邪魔
                pass
            else:
                OP.pop()
                OP.append(XL[i])
        else:
            OP.append(XL[i])

    return len(OP)

def main():
    N = int(input())
    XL = [list(map(int,input().split())) for _ in range(N)]
    ans = cal(XL)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 30732
from math import factorial
from itertools import permutations

n=int(input())

np=factorial(n)

def eratosthenes(n):
 is_p=[1]*n
 p_list=[]

 is_p[0]=0
 is_p[1]=0

 for i in range(2,n):
  if is_p[i]:
   p_list.append(i)
   for j in range(i*i,n,i):
    is_p[j] = 0

 return is_p, p_list

lim=10**2+1
is_p, p_list=eratosthenes(lim)

cnt=0
ans=[]
l=len(p_list)
for i in range(l):
  for j in range(i+1,l):
    for k in range(j+1,l):
      for s,t,u in permutations([p_list[i],p_list[j],p_list[k]],3):
        num1=(s**4)*(t**4)*(u**2)
        num2=(s**14)*(t**4)
        num3=(s**24)*(t**2)
        num4=s**74
        for z in [num1,num2,num3,num4]:
          if np%z==0:
            ans.append(z)

print(len(set(ans)))

Measured memory_bytes: 3188
K, N = map(int, input().split())
A = list(map(int, input().split()))

dist = [0] * (N)

for i in range(N-1):
  dist[i] = A[i+1] - A[i]
dist[N-1] = A[0] - A[-1] + K

print(K - max(dist))

Measured memory_bytes: 26444
#include<iostream>

int main(){
    while(1){
        int h, w;
        std::cin >> h >> w;
        
        if(h == 0 && w ==0) break;
        
        //line1
        for(int i = 0; i < w; i++){
            std::cout << '#';
        }
        std::cout << "" << std::endl;
        
        //lin2~lineh-1
        for(int i = 1; i < h - 1; i++){
            std::cout << '#';
            for(int j = 1; j <= w-2; j++){
                std::cout << '.';
            }
            std::cout << '#' << std::endl;
        }
        
        //last
        for(int i = 0; i < w; i++){
            std::cout << '#';
        }
        std::cout << "" << std::endl;
        std::cout << "" << std::endl;
    }
}


Measured memory_bytes: 3092
<?php
fscanf(STDIN, '%s', $input);
$nums = str_split($input);
$len = count($nums);
$ans = $input;
$memo = [];
if ($len <= 1) {
    echo $ans."\n";
    exit;
} else {
    for ($idx=0; $idx < (1 << ($len-1)); $idx++) {
        $nums = str_split($input);
        for ($plus=0; $plus < $len; $plus++) { 
            if($idx >> $plus & 1){
                $nums[$plus] .= '+';
                $str = implode($nums);
                if (!in_array($str, $memo)) {
                    $memo[] = $str;
                }
            }
        }
    }
}
foreach ($memo as $eval) {
    $ans += eval("return $eval;");
}
echo $ans."\n";

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

using namespace std;

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

const long long int MOD=1000000007;



int main(){
	
	vector<int>v(1000001,1);
	v[0]=0;
	v[1]=0;
	for(int i=2;i<=1000000;i++){
		for(int j=i*2;j<=1000000;j+=i){
			v[j]=0;
		}
	}
	while(cin>>N>>M>>K,N){
		N-=M;
		while(K){
			N+=M;
			K-=v[N];
		}
		cout<<N<<endl;
	}
	return 0;
}


Measured memory_bytes: 6576
while True:
    try:
        a,b = map(int, raw_input().split())
        x,y = (a,b) if a > b else (b,a)
        
        while x%y:
            m = x % y
            x,y = y,m

        print "%d %d" % (y, a*b/y)
    except (EOFError):
        break

Measured memory_bytes: 6432
#include<iostream>
#include<cstdio>

using namespace std;
static const int N = 100;

struct Card { char suit, value; };

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

void printArray(struct Card a[], int n){
    int k = 0;
    while(1){
        if(k==n-1) break;
        else{
            printf("%c%c ", a[k].suit, a[k].value);
        }
        k++;
    }
    printf("%c%c\n", a[n-1].suit, a[n-1].value);
}

void selectionSort(struct Card a[], int n){
    int minj;
    Card t;
    for (int i = 0; i < n; ++i)
    {
        minj = i;
        for (int j = i; j < n; ++j)
        {
            if(a[j].value < a[minj].value){
                minj = j;
            }
        }
        if (i!=minj)
        {
            t = a[i]; a[i] = a[minj]; a[minj] = t;
        }
    }
}

void bubbleSort(struct Card a[], int n){
    int flag = 1;
    Card t;
    while(flag){
        flag = 0;
        for (int j = n-1; j >= 1; j--)
        {
            if (a[j].value<a[j-1].value){
                t = a[j-1];
                a[j-1] = a[j];
                a[j] = t;
                flag = 1;
            }
        }
    }
}

bool isStable(struct Card C1[], struct Card C2[], int n){
    for (int i = 0; i < n; ++i)
    {
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(int argc, char const *argv[])
{
    Card C1[N], C2[N];
    int N;
    char ch;

    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i = 0; i < N; ++i)
    {
        C2[i] = C1[i];
    }

    bubbleSort(C1,N);
    selectionSort(C2,N);

    printArray(C1,N);
    cout << "Stable" << endl;

    printArray(C2,N);
    if (isStable(C1, C2, N))
    {
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

const int maxn=2e5+5;

ll a[maxn];

ll f[maxn];

int main(){
	int n;ll k;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",a+i);
	}
	
	for(int i=0;i<n;i++){
		scanf("%lld",f+i);
	}
	
	sort(a,a+n);sort(f,f+n,[](int x,int y){return x>y;});
	ll l=0,r=0;
	for(int i=0;i<n;i++){
		r=max(r,a[i]*f[i]);
	}
	
	ll ans=0;
	while(l<=r){
		ll mid=(l+r)>>1;
		ll cnt=0;
		for(int i=0;i<n;i++){
			if(a[i]*f[i]>mid){
				cnt+=(a[i]*f[i]-mid-1)/f[i]+1;	
			}
		}
		if(cnt>k){
			l=mid+1;
		}
		else{
			ans=mid;
			r=mid-1;
		}
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 100010;
typedef long long ll;

int n, m;

inline int add(int x, int y){return (x+=y)>=m?x-m:x;}
inline int mul(int x, int y){return 1ll*x*y%m;}

struct edge{
	int next, to;
	edge(int N=0,int T=0):next(N),to(T){}
}e[MAXN<<1];
int fir[MAXN], num = 0;
inline void join(int a, int b)
{
	e[++num].next = fir[a];
	fir[a] = num;
	e[num].to = b;
}

int f[MAXN], g[MAXN], ans[MAXN];
vector<int> in[MAXN], pre[MAXN], suf[MAXN];

void dfs1(int u, int fa)
{
	int cnt = 0;
	f[u]    = 1;
	in[u].push_back(1);
	for(int i=fir[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v == fa) continue;
		dfs1(v, u);
		f[u] = mul(f[u], add(f[v], 1));
		cnt++;
		in[u].push_back(v);
	}
	in[u].push_back(1);
	pre[u].resize(cnt + 2); suf[u].resize(cnt + 2);
	pre[u][0] = suf[u][cnt+1] = 1;
	for(int i=1; i<=cnt; i++)
		pre[u][i] = mul(pre[u][i-1], add(f[in[u][i]], 1));
	for(int i=cnt; i>=1; i--)
		suf[u][i] = mul(suf[u][i+1], add(f[in[u][i]], 1));
}
void dfs2(int u, int fa)
{
	int cnt = 0;
	for(int i=fir[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v == fa)continue;
		++cnt;
		g[v] = add(mul(g[u], mul(pre[u][cnt-1], suf[u][cnt+1])), 1);
		ans[v] = mul(g[v], f[v]);
		dfs2(v, u);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,a,b;i<n;i++)
		scanf("%d%d",&a,&b), join(a, b), join(b, a);
	dfs1(1, 0);
	g[1] = 1; ans[1] = f[1];
	dfs2(1, 0);
	for(int i=1;i<=n;i++)
		printf("%d\n" ,ans[i]);
	return 0;
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
 
int secs = 0, station = 0, transit=0, n;
vector<int> c, s, f, wait;
 
void step(int t) {
	// t is either wait[station] or transit
	secs+=t;
	if (t == transit) {
		wait[station]-=secs;
		transit=0;
	}
	else wait[station]=0;
 
	if (wait[station]<=0) {
		wait[station] = ((wait[station]%f[station]) + f[station])%f[station];
	}
	if (wait[station]==0) {
		transit=c[station];
		station++;
	}
}
 
void reset() {
	secs=0;
	station=0;
	transit=0;
	for (int i=0; i<n; i++)
		wait[i]=s[i];
}
 
int main() {
	cin>>n;
	c.resize(n);
	s.resize(n);
	f.resize(n);
	wait.resize(n);
 
	for (int i=0; i<n-1; i++)
		cin>>c[i]>>s[i]>>f[i];
 
	//simulate v99
	for (int i=0; i<n; i++) {
		reset();
		station=i;
		while (station < n-1) {
			if (transit > 0) step(transit);
			else step(wait[station]);
		}
		cout << secs+transit << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	 long long a,b,c,d,e;
	scanf("%lld %lld %lld",&a,&b,&c);
	d=4*a*b;
	e=c-a-b;
	e*=e;
	if(d>=e||c<=a+b)printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6)


def exec(a, b, c, cnt, k):
    if cnt > 0 and b > a and c > b:
        return True
    ans = False
    if cnt < k:
        ans |= exec(a*2, b, c, cnt+1, k)
        ans |= exec(a, b*2, c, cnt+1, k)
        ans |= exec(a, b, c*2, cnt+1, k)
    return ans


def main(input, print):
    A, B, C = map(int, input().split())
    K = int(input())

    if exec(A, B, C, 0, K):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 67800
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N;
	cin >> N;
	set<int> A;
	string ans = "YES";
	rep(i, N) {
		int a;
		cin >> a;
		if (A.find(a) == A.end())
			A.insert(a);
		else {
			ans = "NO";
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<iomanip>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2010;
int n,k,du[N],d1[N],head[N],z1;
struct node
{
    int u,v,nxt;
}e1[N*2];
void add_e1(int u,int v)
{
    z1++;
    e1[z1].u=u;e1[z1].v=v;
    e1[z1].nxt=head[u];
    head[u]=z1;
}
void dfs(int u,int fa,int d)
{
    d1[u]=d;
    for(int i=head[u];i;i=e1[i].nxt)
	{
        int v=e1[i].v;
        if(v==fa)continue;
        dfs(v,u,d+1);
    }
}
int main()
{ 
	int u,v;
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++)
	{
       
        scanf("%d%d",&u,&v);
        add_e1(u,v);add_e1(v,u);
        du[u]++;du[v]++;
    }
    int ans=n;
    if(k&1)
        for(int u=1;u<=n;u++)
            for(int i=head[u];i;i=e1[i].nxt)
			{
                int v=e1[i].v;
                if(v<u)continue;
                dfs(u,v,0);
                dfs(v,u,0);
                int cnt=0;
                for(int j=1;j<=n;j++)
                    if(d1[j]>k/2)cnt++;
                ans=min(ans,cnt);
            }
    else
    for(int u=1;u<=n;u++)
	{
       dfs(u,0,0);
       int cnt=0;
       for(int j=1;j<=n;j++)
          if(d1[j]>k/2)
          cnt++;
    	ans=min(ans,cnt);
    }
    printf("%d\n",ans);
}

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

#define int long long

using namespace std;

char a[701][701];

 main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= n;j ++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1;i < n + n;i ++) {
		for (int j = 1;j < n + n;j ++) {
			int ii = i;
			int jj = j;
			if (ii > n) ii -= n;
			if (jj > n) jj -= n;
			a[i][j] = a[ii][jj];
		}
	}
	int ans = 0;
	for (int i = 1;i <= 1;i ++) {
		for (int j = 1;j <= n;j ++) {
			int ok = 1;
			for (int ii = i;ii < i + n;ii ++) {
				for (int jj = j;jj < j + n;jj ++) {
					int x = ii - i + 1;
					int y = jj - j + 1;
					if (a[ii][jj] != a[y + i - 1][x + j - 1]) {
						ok = 0;
						ii = i + n;
						break;
					}
				}
			}
			//cout << i << ' ' << j << ' ' << ok << endl;
			ans += ok;
		}
	}
	cout << ans * n;
	return 0; 
}


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

ll aca[105000] = {0};
ll waa[105000] = {0};

int main()
{
    ll N, M;
    ll ac = 0, wa = 0;
    cin >> N >> M;

    for (ll i = 0; i < M; ++i)
    {
        ll p;
        string S;
        cin >> p >> S;
        if (S == "AC")
        {
            if (!aca[p])
            {
                ++ac;
                wa += waa[p];
                aca[p] = 1;
            }
        }
        else
        {
            ++waa[p];
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 1664
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    H, W = map(int, input().split())
    d = defaultdict(int)
    for y in range(H):
        for c in input():
            d[c] += 1

    four, two, one = (H // 2) * (W // 2), 0, 0
    if H % 2 == 0 and W % 2 == 0:
        pass
    elif H % 2 != 0 and W % 2 == 0:
        two = W // 2
    elif H % 2 == 0 and W % 2 != 0:
        two = H // 2
    elif H % 2 != 0 and W % 2 != 0:
        two = H // 2 + W // 2
        one = 1

    for k, v in d.items():
        if v >= 4 and four > 0:
            n = v // 4
            four -= n
            d[k] -= 4 * n
    for k, v in d.items():
        if v >= 2 and two > 0:
            n = v // 2
            two -= n
            d[k] -= 2 * n
    for k, v in d.items():
        if v >= 1 and one > 0:
            one -= 1
            d[k] -= 1

    if one == 0 and two == 0 and four == 0 and sum(d.values()) == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 4216