akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    

    
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int odd=0;
    int even=0;
    rep(i,n){
        if(a[i]%2==0)even++;
        else odd++;
    }
    if(odd%2==1)fin("NO");
    else {
        fin("YES");
        
    }
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n+1);
    for(int i=0; i<n; i++){
        int a; cin >> a;
        v[a]++;
    }
    sort(v.begin(), v.end());
    int kind = 0;
    for(int i=0; i<v.size(); i++){
        if(v[i] != 0) kind++;
    }
    int ans = 0;
    for(int i=0; i<kind-k; i++){
        ans += v[n-kind+i+1];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector<int> p(3);
  cin >> p.at(0) >> p.at(1) >> p.at(2);
  sort(p.begin(), p.end());
  cout << p.at(2)*10+p.at(1)+p.at(0) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n, a, b, c = rl()
    moves = []
    ans = []
    abc = [a,b,c]
    for i in range(n):
        moves.append(input())
    moves.append(moves[-1])

    for i in range(len(moves) - 1):
        curr = moves[i]
        nxt = moves[i + 1]
        x = {"A":0, "B":1, "C":2}[curr[0]]
        y = {"A":0, "B":1, "C":2}[curr[1]]
        nx = {"A":0, "B":1, "C":2}[nxt[0]]
        ny = {"A":0, "B":1, "C":2}[nxt[1]]

        if abc[x] == 0 and abc[y] == 0:
            print ("No")
            return
        elif abc[x] == 0:
            abc[x] += 1
            abc[y] -= 1
            ans.append(curr[0])
        elif abc[y] == 0:
            abc[x] -= 1
            abc[y] += 1
            ans.append(curr[1])
        elif x == y and nx == ny:
            abc[x] += 1
            abc[y] -= 1
            ans.append(curr[0])
        else:
            common = list(set([x,y]).intersection(set([nx,ny])))[0]
            if x == common:
                other = y
                ans.append(curr[0])
            else:
                other = x
                ans.append(curr[1])
            abc[common] += 1
            abc[other] -= 1

    print ("Yes")
    for l in ans:
        print (l)


mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 91740
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int ret = 0;

    for (int i = 0; i < N - 1; i++) {
        if (a[i] == (i+1)) {
            swap(a[i], a[i+1]);
            ret++;
        }
    }

    if (a[N-1] == N) ret++;

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int h, w;
  cin>>h>>w;
  vector<string> s(h);
  int N = h * w ;
  REP(i, h){
    cin>>s[i];
  }
  auto conv = [&](int i, int j) -> int{
    int res = w * i + j;
    return res;
  };
  vector<vector<int>> dp(h, vector<int>(w, 1'000'000'000));
  REP(i, h){
    REP(j, w){
      if(i == 0 && j == 0){
        if(s[i][j] == '#'){
          dp[i][j] = 1;
        }else{
          dp[i][j] = 0;
        }
        continue;
      }
      if(i - 1 >= 0){
        if(s[i-1][j] == '.' && s[i][j] == '#'){
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
        }else{
          dp[i][j] = min(dp[i][j], dp[i - 1][j]);
        }
      }
      if(j - 1 >= 0){
        if(s[i][j-1] == '.' && s[i][j] == '#'){
          dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);
        }else{
          dp[i][j] = min(dp[i][j], dp[i][j-1]);
        }
      }
    }
  }
  int ans = dp[h-1][w-1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    long long count = 0;

    long long b_num = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            b_num++;
        } else {
            count += b_num;
        }
    }

    cout << count << endl;

    return 0;
}


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

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

    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'o') {
            cnt++;
        }
    }

    cout << 700 + 100 * cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool ChooseInteger(int a, int b, int c) {
	bool result = false;
	for (int i = 0; i < b; i++) {
		if (a * i % b == c) {
			result = true;
			break;
		}
	}
	return result;
}

int main()
{
	int inputs[3]{};
	cin >> inputs[0] >> inputs[1] >> inputs[2];
	cout << (ChooseInteger(inputs[0], inputs[1], inputs[2]) ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

// 逆元 | a と mod は互いに素
int inv_mod(int a, int m = MOD) {
  int b = m, x = 1, y = 0, t;
  while (b > 0) {
    t = a / b;
    swap(a -= t * b, b);
    swap(x -= t * y, y);
  }
  x %= m;
  if (x < 0) x += m;
  return x;
}

// 逆元(配列) | 1...n-1 は mod と互いに素, n <= mod
int fac[200010], invfac[200010], inv[200010];
void init(int n, int mod = MOD) {
  fac[0] = 1;
  for (int i = 1; i < n; i++) fac[i] = fac[i-1]*i%mod;
  invfac[n-1] = inv_mod(fac[n-1]);
  for (int i = n-2; i >= 0; i--) invfac[i] = invfac[i+1]*(i+1)%mod;
  for (int i = 1; i < n; i++) inv[i] = invfac[i]*fac[i-1]%mod;
}

// 二項係数 | n,k < mod, mod は素数
int nCk(int n, int k, int mod = MOD) {
  if (!(0 <= k && k <= n)) return 0;
  return fac[n] * invfac[k] % mod * invfac[n-k] % mod;
}

int calc(int n, int m, int k) {
  int res = 0;
  REP(d,n) (res += d*(n-d)%MOD) %= MOD;
  (res *= m*m%MOD) %= MOD;
  (res *= nCk(n*m-2,k-2)) %= MOD;
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  init(200010);
  int N,M,K;
  cin >> N >> M >> K;
  cout << (calc(N,M,K) + calc(M,N,K)) % MOD << endl; 

  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define all(in) in.begin(),in.end()
#define pb(in,a) in.push_back(a)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    char s[100]={'\0'};
    cin>>s;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[n-i-1]>>b[n-i-1];

    rep(i,n){
      int m=b[i]-a[i];
      swap(s[a[i]-1],s[b[i]-1]);
      s[a[i]-1]=(s[a[i]-1]-'a'+m+26)%26+'a';
      s[b[i]-1]=(s[b[i]-1]-'a'+m+26)%26+'a';


      //if(s[a[i]-1]+m>'z')s[a[i]-1]+=m%26-26;
      //else s[a[i]-1]+=m;
      //if(s[b[i]-1]+m>'z')s[b[i]-1]+=m%26-26;
      //else s[b[i]-1]+=m;
            
      //s[b[i]-1]+=abs(a[i]-b[i]);
      //if(s[b[i]-1]>'z')s[b[i]-1]-=26;
      //cout<<s<<endl;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;

bool sorting(int &a, int &b) {
    return abs(a) < abs(b);
}

signed main() {
    int N, L;
    cin >> N >> L;
    vector<int> apple(N, 0);
    for (int i = 0; i < N; i++) apple[i] = i + L;
    int ans = accumulate(apple.begin(), apple.end(), 0L);
    sort(apple.begin(), apple.end(), sorting);
    cout << ans - apple[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;

ll mod = 1000000007;

ll modpow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll modcmb(int n, int r) {
    ll ans = 1;
    rep(i, r) {
        ans *= (n-i) * modpow(i+1, mod-2) % mod;
        ans %= mod;
    }
    return ans;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    ll all_sum = modpow(2, n);
    ll exclusion = ( modcmb(n, a) + modcmb(n, b) ) % mod;
    ll ans = all_sum - exclusion;
    ans = (ans+mod)%mod;
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 3604
import sys

sys.setrecursionlimit(100000)


def check(i, xs, checked):
    xi = xs[i]
    children = set()
    for j, d in links[i]:
        if checked[j]:
            continue
        if j not in xs:
            xs[j] = xi + d
        elif xi + d != xs[j]:
            return False
        children.add(j)
    checked[i] = True
    for j in children:
        if not check(j, xs, checked):
            return False
    return True


def solve():
    checked = [False] * n
    for i in range(n):
        if not checked[i]:
            xs = {}
            xs[i] = 0
            if not check(i, xs, checked):
                return False
    return True


n, m = map(int, input().split())
links = [set() for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    links[l].add((r, d))
    links[r].add((l, -d))
print('Yes' if solve() else 'No')


Measured memory_bytes: 169256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            money = 500 * a + 100 * b + 50 * c
            if X == money:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
#include <fstream>
using namespace std;
ll par[200005],rnk[200005];
ll findp(ll x)
{
    if(par[x]==x)
        return x;
    else
        return par[x]=findp(par[x]);
}
void mrge(ll x,ll y) {
  ll p1=findp(x);
  ll p2=findp(y);
  if(p1==p2)
    return ;
  if(rnk[p1]<rnk[p2])
    par[p1]=p2;
  else if(rnk[p2]<rnk[p1])
    par[p2]=p1;
  else
  {
      par[p2]=p1;
      ++rnk[p1];
  }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--) {
    ll n,m,i,j;
    cin>>n>>m;
    ll x,y;
    for(i=1;i<=n;i++) {
        par[i]=i;
        rnk[i]=0;
    }
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        mrge(x,y);
    }
    map<ll,ll> mp;
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        x=findp(i);
        ++mp[x];
        ans=max(ans,mp[x]);
    }
    cout<<ans;
}
}


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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

ll N;
ll A[101010];

void solve() {
    cin >> N;
    rep(i,N) cin >> A[i];
    sort(A, A+N);
    ll cur = A[0];
    ll ans = 1;
    REP(i,1,N) {
        if (A[i] <= cur * 2) { 
            ans++;
        } else {
            ans = 1;
        }
        cur += A[i];
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll cnt[100010];


// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    ll ma=0;
    ll d[n];
    rep(i,n){
        cin>>d[i];
        ma=max(ma,d[i]);
        cnt[d[i]]++;
    }

    if(cnt[0]!=1 || d[0]!=0){
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;
    
    for(int i=1;i<=ma;i++){
        ans=(ans*modpow(cnt[i-1],cnt[i],998244353))%998244353;
    }
    cout<<ans%998244353<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

constexpr int MOD = 1000000007;

int main()
{
    int N, J = 0, K = 0, L = 0;
    cin >> N;

    vector<int> st(N * 2 + 1);
    REP(_, N)
    {
        int A, B;
        cin >> A >> B;
        if (A < 0 and B > 0) st[B] = 1, K++;
        else if (A > 0 and B < 0) st[A] = 1, K++;
        else if (A > 0 and B > 0) st[A] = st[B] = 2, L++;
        else J++;
    }

    vector<vector<int>> dp;
    ndarray(dp, K + 1, N - L + 1);
    dp[0][0] = 1;

    int G = 0, H = 0;

    REP(i, 2 * N)
    {
        int s = st[2 * N - i];
        if (s == 2) continue;
        else if (s)
        {
            IREP(k, K + 1) REP(j, N - L + 1)
            {
                dp[k][j] = (j < N - L ? dp[k][j + 1] : 0) + (k ? dp[k - 1][j] : 0);
                if (dp[k][j] >= MOD) dp[k][j] -= MOD;
            }
            H++;
        }
        else
        {
            REP(k, K + 1)
            {
                vector<int> tmp = dp[k];
                REP(j, N - L + 1)
                {
                    int pa2 = G - H - (j + 1) + k;
                    dp[k][j] = ((j < N - L ? dp[k][j + 1] * (long long int)(J - pa2 / 2) : 0LL) + (k < K ? dp[k + 1][j] * (long long int)(k + 1) : 0LL)) % MOD;
                }
                FOR(j, 1, N - L + 1) (dp[k][j] += tmp[j - 1]) %= MOD;
            }
            G++;
        }
    }
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static int max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.next();
		boolean ok = true;
		boolean checkA = false;
		boolean checkB = false;
		boolean checkC = false;
		if(in.length() < 6) ok = false;
		else {
			for(int i = 0; i < in.length(); i++) {
				if(in.charAt(i) >= '0' && in.charAt(i) <= '9') {
					checkA = true;
				}
				if(in.charAt(i) >= 'a' && in.charAt(i) <= 'z') {
					checkB = true;
				}
				if(in.charAt(i) >= 'A' && in.charAt(i) <= 'Z') {
					checkC = true;
				}
			}
		}
		if(ok && checkA && checkB && checkC) {
			System.out.println("VALID");
		}
		else {
			System.out.println("INVALID");
		}
	}
}


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

typedef long long ll;
//#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 MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
 
using namespace std;
int arr[100001];
int s[100001] = {0};


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

    int N = 100001;
    
    for(int i = 0; i < N; i++) arr[i] = 1;
    for(int i = 2; i < sqrt(N); i++){
	    if(arr[i]){
	    	for(int j = 0; i * (j + 2) < N; j++){
	    		arr[i *(j + 2)] = 0;
	    	}
	    }
    }
    arr[0] = 0;
    arr[1] = 0;

    for(int i = 3; i <= 100000; i += 2){
        if(arr[i] == 1 && arr[(i+1)/2] == 1) s[i] = s[i-2] + 1;
        else s[i] = s[i-2];
        //if(i < 200)cerr << i << "  " << s[i] << endl;
    }

    REP(i,q){
        int l,r;
        cin >> l >> r;
        if(l == 1) l++;
        if(r == 1) r++;

        cout << s[r] - s[l-2] << endl;
    }
    
    return 0;
}
//g++ -std=c++14 code1.cpp



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,a,b,c=0,i;
  scanf("%lld",&n);
  for(i=0;i<n;i++)
  {
      scanf("%lld",&a);
      if(a%2==0)
      {
          while(a%2==0)
          {
              c++;
              a=a/2;

          }
      }
  }
  printf("%lld\n",c);
}


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

ll MOD = 1e9 + 7, n, k, a[109], dp[109][100009], pref[109][100009];

long long solve(long long n, long long k)
{
    if(n == 1)
        return((k <= a[1])? 1: 0);
    if(k == 0)
        return 1;
    long long& res = dp[n][k];
    if(res != -1)
        return res;
    res = 0;
    for(int i = 0; i <= a[n]; i++)
    {
        if(k - i >= 0)
            res = (res + solve(n - 1, k - i)) % MOD;
    }
    cout<<"n = "<<n<<" k = "<<k<<" dp = "<<res<<"\n";
    return res;
}

main()
{
    cin>>n>>k;
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n; i++)
    {
        cin>>a[i];
    }
    //cout<<solve(n, k);

    /*for(int i = 0; i <= a[1]; i++)
        dp[1][i] = 1;

    for(int i = 0; i <= k; i++)
        pref[1][i] = i + 1;

    for(int i = 1; i <= n; i++)
        dp[i][0] = 1, pref[i][0] = 1;*/
    dp[0][0] = 1;
    for(int i = 0; i <= k; i++)
    {
        pref[0][i] = 1;
    }

    for(int i = 1; i <= n; i++)
    {
        //cout<<dp[i][0]<<" ";
        for(int j = 0; j <= k; j++)
        {
            if(j - a[i] - 1 >= 0)
            {
                dp[i][j] = ((pref[i - 1][j] - pref[i - 1][j - a[i] - 1] + MOD) % MOD) % MOD;
            }
            else
            {
                dp[i][j] = pref[i - 1][j] % MOD;
            }
            if(j > 0)
                pref[i][j] = (pref[i][j - 1] + dp[i][j]) % MOD;
            else
                pref[i][0] = dp[i][0];
            //cout<<dp[i][j]<<" ";
        }
        //cout<<"\n";
    }
    cout<<dp[n][k];
}


Measured memory_bytes: 166528
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef unsigned long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
ll h[MX], base[MX];
inline ll calc(int i, int j){
	return (h[j] - h[i]) * base[MX - j - 1];
}
bool eq(int s, int t, int u, int v, const string &r){
	if(t - s != v - u) return 0;
	while(s < t) if(r[s++] != r[u++]) return 0;
	return 1;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	base[0] = 1;
	rep(i, MX - 1) base[i + 1] = base[i] * 31;
	
	string s; cin >> s;
	int n = s.size();
	rep(i, n) h[i + 1] = h[i] + (s[i] - '0' + 1) * base[i];
	
	int ans = 8;
	//more than 2
	for(int len = 3; len * 2 <= n; len++) if(n % len == 0){
		int mx = 0, mn = 99, d;
		for(int i = 0; i < n; i += len){
			if(!eq(i, i + len - 2, 0, len - 2, s)) goto SKIP;
			d = (s[i + len - 2] - '0') * 10 + (s[i + len - 1] - '0');
			mx = max(mx, d);
			mn = min(mn, d);
			if(mx - mn >= ans) goto SKIP;
		}
		ans = min(ans, mx - mn);
		SKIP:;
	}
	
	for(int mn = 1; mn <= 99; mn++){
		int mx = mn, lp = 0;
		for(int i = 0; i < n; i++){
			lp++;
			int d = s[i] - '0';
			while(d < mn){
				if(i + 1 >= n) goto SKIP2;
				d *= 10;
				d += s[++i] -'0';
			}
			mx = max(mx, d);
			if(mx - mn >= ans) goto SKIP2;
		}
		if(lp > 1) ans = min(ans, mx - mn);
		SKIP2:;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4876
#include<stdio.h>
int main(void){
  int a;
  char s[11];
  
  scanf("%d", &a);
  scanf("%s", s);
  
  if(a >= 3200){
    printf("%s\n", s);
  }
  else{
    printf("red\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll K,A,B; cin>>K>>A>>B;
  ll dis=B-A;
  ll st=A%K;
  if(K==1 || st==0) cout<<"OK"<<endl;
  else if((st+dis)>=K) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}

Measured memory_bytes: 3632
/*
 * main.c
 *
 *  Created on: 2019/03/09
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int A[20][20] = {0};
int B[20] = {0};

int main()
{
	int N, M, C;
	int i = 0; // for N
	int j = 0; // for M
	int ans = 0;
	int temp = 0;
	scanf("%d %d %d", &N, &M, &C);
    // B
	for(j = 0; j < M; j++) {
		scanf("%d", &B[j]);
	}
    // A
	for(i = 0; i < N; i++) {
		for(j = 0; j < M; j++) {
			scanf("%d", &A[i][j]);
		}
	}

	// A * B
	for(i = 0; i < N; i++) {
		temp = C;
		for(j = 0; j < M; j++) {
			temp += A[i][j] * B[j];
		}
		if (temp > 0) {
			ans++;
		}
	}
	printf("%d\n",ans);

	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int L = 18;

ll sub[60][60];
ll way[60];

int main() {
    int N, K, S, T;
    cin >> N >> K >> S >> T;
    V<int> A(N);
    rep(i, N) cin >> A[i];

    rep(i, 60) {
        sub[i][0] = sub[i][i] = 1;
        for (int j = 1; j < i; ++j) {
            sub[i][j] = (sub[i - 1][j - 1] + sub[i - 1][j]);
        }
    }

    rep(i, 60) {
        for (int j = 1; j <= K; ++j) {
            way[i] += sub[i][j];
        }
    }

    if ((S & T) != S) {
        puts("0");
        return 0;
    }

    {
        V<int> B;
        for (int x : A) {
            if ((x & S) == S && (x & T) == x) {
                B.pb(x);
            }
        }
        A = B;
        N = A.size();
    }
    debug(A);

    V<int> bt;
    rep(i, L) {
        if ((S >> i & 1) != (T >> i & 1)) {
            bt.pb(i);
        }
    }

    // ll ans = 1ll << A.size();
    ll ans = 0;

    V<int> mask(1 << bt.size());
    rep(i, 1 << bt.size()) {
        int msk = 0;
        rep(j, bt.size()) if (i >> j & 1) { msk |= (1 << bt[j]); }
        mask[i] = msk;
    }

    debug(bt);

    rep(i, 1 << bt.size()) {
        int msk = mask[i];
        map<int, int> cnt;
        rep(j, N) cnt[A[j] & msk]++;

        ll u = 0;
        for (auto p : cnt) {
            u += way[p.se];
        }
        if (__builtin_popcount(i) & 1) {
            u = -u;
        }
        ans += u;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4304
import collections, re, itertools, copy

S = input()
T = input()

# 文字リストとcollections.Counterを渡すと、同じ文字が存在するインデックスの集合を返す関数
def same_letter_index_set(A, cA):
    output = []
    for s in cA.keys():
        match_index_list = [m.span() for m in re.finditer(s, A)]
        output.append(list(itertools.chain.from_iterable([m.span() for m in re.finditer(s, A)])))
    return output

# 2重リストを2つ与えると、それらの要素が一致しているかどうかを関数
def same_multi_list(A_input,B_input):
    A = copy.deepcopy(A_input)
    B = copy.deepcopy(B_input)
    for i in A:
        try:
            B.remove(i)
        except:
            return False
    if len(B) == 0:
        return True
    else:
        return False

# それぞれの文字列において、同じ文字が存在するインデックスの集合を考える。それらが完全一致すれば置き換え可能
cS = collections.Counter(S)
cT = collections.Counter(T)
print("Yes" if same_multi_list(same_letter_index_set(S, cS), same_letter_index_set(T, cT)) else "No")

Measured memory_bytes: 61820
#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>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int in[10];
		for(int j=0;j<10;j++){
			cin >> in[j];
		}
		bool ok=true;
		int low=0,hi=0;
		for(int j=0;j<10;j++){
			if(in[j]<=low){
				ok=false;
				break;
			}
			if(in[j]<hi){
				low=in[j];
			}
			else{
				hi=in[j];
			}
		}
		if (ok){
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n, a[3007], L, R, res, now;
vector<ll> b;

int main () {
    fastIO;
    cin >> n;
    if(n==1) { cin >> L; cout << L; return 0; }
    for(li i = 0; i < n; i ++) cin >> a[i];
    for(li i = 1; i < n; i ++) b.push_back(max(a[i], a[i-1])-min(a[i], a[i-1]));
    now = 2;
    while(b.size()>1) {
        L=0;
        R=now;
        for(li i = 1; i < b.size(); i++) {
            b[i-1] = max(a[L]-b[i], a[R]-b[i-1]);
            L++;
            R++;
            //cout << b[i] << " ";
        }
        b.pop_back();
        now++;
    }
    cout << b.back();
}


Measured memory_bytes: 384
'''
問題：
    今、日本は 9 月 9 日です。
    二桁の整数 N が与えられるので、十進法で N に 9 が含まれるか答えてください。
'''
'''
制約：
10 ≦ N ≦ 99
'''

# 標準入力から N を取得する
n = int(input())

result = ""
if n % 10 == 9: # 1の位が 9
    result = "Yes"
elif 90 <= n % 100 < 100:   # 10の位が 9
    result = "Yes"
else:
    result = "No"

print(result)


Measured memory_bytes: 9168
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

const int MOD=1000000007;
typedef long long int ll;
const ll LLINF=1ll<<60;

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}

ll pot(ll n,ll k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

ll divide(ll a,ll b)
{
	return mult(a,pot(b,MOD-2));
}

ll sub(ll a,ll b)
{
	return (a-b+MOD)%MOD;
}

ll add(ll a,ll b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

int n;
ll a[10001],b[10001];
ll d2,d1;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;++i) cin>>a[i];
	for (int i=0;i<n;++i)
	{
		cin>>b[i];
		if (b[i]<a[i]) d1+=a[i]-b[i];
		else if (a[i]<b[i])
		{
			if ((b[i]-a[i])%2) ++d1;
			d2+=(b[i]-a[i]+1)/2;
		}
	}
	if (d1<=d2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct S{
	int len;
	char s;
	bool del;
}T[1000010];int tot;
int n;
char str[1000010];
int cnt[233];
int main()
{
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		if(str[i]!=str[i-1])
			cnt[str[i]]++;
	char ca='A',cb='B',cc='C';
	if(cnt[ca]>cnt[cb])swap(ca,cb);
	if(cnt[cb]>cnt[cc])swap(cb,cc);
	if(cnt[ca]>cnt[cb])swap(ca,cb);
	tot=1;
	int s1=0,s2=0,s3=0;
	for(int i=1;i<=n;i++)
	{
		if(str[i]==str[i-1])continue;
		if(str[i]==ca){
			if(T[tot].len==1){
				if(T[tot].s==cb)s2++;
				else s3++;
			}
			else if(T[tot].len>1)s1++;
			tot++;
		}
		else{
			T[tot].len++;
			if(T[tot].len==1)
				T[tot].s=str[i];
		}
	}
	if(T[tot].len==1){
		if(T[tot].s==cb)s2++;
		else s3++;
	}
	else if(T[tot].len>1)s1++;
	
	if(s1+s2<s3)
	{
		if(T[tot].s==cc&&T[tot].len==1)
		{
			T[tot].len--;
			s3--;
			cnt[cc]--;
		}
	}
	for(int i=1;i<tot&&s1+s2<s3;i++)
		if(T[i].len==1&&T[i].s==cc)
		{
			s3--;
			if(i!=1&&i!=tot){
				cnt[ca]--;
				T[i].del=true;
			}
			else T[i].len--;
			cnt[cc]--;
		}
	int now=1;
//	if(cnt[cb]>cnt[cc]){
//		printf("A\n");
//		return 0;
//	}
	while(now<=tot&&cnt[cb]!=cnt[cc])
	{
		if(T[now].del){
			now++;
			continue;
		}
		if(T[now].len<=1)now++;
		else if(T[now].s==cc){
			T[now].len--;
			T[now].s=cb;
			cnt[cc]--;
		}
		else if(T[now].len%2==0)
		{
			T[now].len--;
			cnt[cc]--;
		}
		else now++;
	}
	now=1;
//	if(cnt[ca]>cnt[cb]){
//		printf("A\n");
//		return 0;
//	}
	while(now<=tot&&cnt[ca]!=cnt[cb])
	{
		if(T[now].del||T[now].len<=1){
			now++;
			continue;
		}
		if(T[now].len>2){
			T[now].len-=2;
			cnt[cb]--;
			cnt[cc]--;
		}
		else if(T[now].len==2&&(now==1||now==tot))
		{
			T[now].len-=2;
			cnt[cb]--;
			cnt[cc]--;
		}
		else now++;
	}
//	printf("ABC\n");
//	return 0;
	for(int i=1;i<=tot;i++)
	{
		if(T[i].del)continue;
		if(i!=1)putchar(ca);
		for(int j=0;j<T[i].len;j++)
		{
			if(j&1)putchar(cb+cc-T[i].s);
			else putchar(T[i].s);
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMAX）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int lb(int l,int r,long long n,int *d){
  if(n>(1<<29))return r;
  while(l-r){
    int m=(l+r)/2;
    n<=d[m]?(r=m):(l=m+1);
  }
  return l;
}

int n,i,j,s=0,b[200010],d[200010];
long long k,c,a[200010];
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%lld",&a[i]);
  for(i=0;i<n;i++)scanf("%d",&b[i]);
  for(i=0;i<30;i++){
    R=C=1;
    k=(1<<i);//printf("%d\n",k);
    for(j=0;j<n;j++)hin((int)(b[j]&((2LL<<i)-1)));
    for(j=0;j<n;j++)d[j]=N[hout()];
    //for(j=0;j<n;j++)printf("%d ",d[j]);printf("\n");
    for(j=c=0;j<n;j++)c+=((lb(0,n,2*k-(a[j]&((2LL<<i)-1)),d)-
			   lb(0,n,1*k-(a[j]&((2LL<<i)-1)),d))%2+
			  (n-
			   lb(0,n,3LL*k-(a[j]&((2LL<<i)-1)),d))%2)%2;
    s+=c%2*k;
    /*or(j=0;j<n;j++)printf("%d %d %d %d\n",s,
			   lb(0,n,2*k-(a[j]&((2<<i)-1)),d),
			   lb(0,n,1*k-(a[j]&((2<<i)-1)),d),
			   lb(0,n,3*k-(a[j]&((2<<i)-1)),d));//*/
  }
  printf("%d\n",s);
  return 0;
}


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

int main()
{
  int a;
  int b;
  int c;
  int d = 0;
  int e = 0;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  d = a * b;
 
  if(c > d){
    cout<<d<<endl;
  }else{
    cout<<c<<endl;
  }
}





Measured memory_bytes: 256
N = int(input())
A = []
C2 = [0] * N
C5 = [0] * N

P = 1000000000
for i in range(N):
    tmp = input().split(".")
    if len(tmp) == 2:
        a = int(tmp[1])
        for j in range(9-len(tmp[1])):
            a *= 10
        A.append(int(tmp[0]) * P + a)
    else:
        A.append(int(tmp[0]) * P)

for i in range(N):
    tmpp = A[i]
    tmp2 = A[i]
    while tmpp > 0:
        if tmpp % 2 == 0:
            tmpp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp2 % 5 == 0:
            tmp2 //= 5
            C5[i] += 1
        else:
            break

Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[min(18, C2[i])][min(18, C5[i])]+=1

ans = 0
for i in range(N):
    if C2[i] >= 9 and C5[i] >= 9:
        ans -= 1
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]

print(ans//2)

Measured memory_bytes: 87604
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

"""
・中心が同型不変であることを利用して考える。
・カラフル度はだいたい直径の半分。
・中心が頂点になる場合は、中心を隣接する辺に持ってこれる。Nが小さいので全部計算してもよい
・そもそもすべての辺、頂点に対して、そこを中心とする場合の(色数、葉数)を計算してもよい
"""

N,*AB = map(int,read().split()) 

AB = tuple(zip(*[iter(AB)]*2))

AB

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
deg = [len(x) for x in graph]

graph,deg

def F(centroids):
    """
    ・中心とする1点または2点を与える
    ・できる木の(深さ,葉の数)を返す
    """
    Ncent = len(centroids)
    depth = [None] * (N+1)
    q = centroids
    for x in q: depth[x] = 0
    while q:
        x = q.pop()
        for y in graph[x]:
            if depth[y] is None:
                depth[y] = depth[x] + 1
                q.append(y)
    D = max(depth[1:])
    sep = [1] * (D+1)
    for x in range(1,N+1):
        d = depth[x]
        n = deg[x] - 1
        sep[d] = max(sep[d],n)
    if Ncent == 1:
        sep[0] += 1
    x = 1
    for s in sep[:D]:
        x *= s
    if Ncent == 2:
        x *= 2
    return D+1,x

arr = [F([v]) for v in range(1,N+1)] + [F([a,b]) for a,b in AB]
arr.sort()
answer = arr[0]
print(*answer)

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int sum = 0;
        for(int i = 0 ; i < M ; i ++){
            sum += sc.nextInt();
        }

        int ans = N >= sum ? N - sum : -1;
        System.out.println(ans);
    }
}


Measured memory_bytes: 46596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int S = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        Arrays.sort(A);
        long[][] dp = new long[N+1][S+1];
        for (int i = 0; i <= N; i++) {
            Arrays.fill(dp[i], 0);
        }
        dp[0][0] = 1;
        long mod = 998244353;
        for (int i = 1; i <= N; i++) {
            for (int j = S; 0 <= j; j--) {
                if (dp[i-1][j] == Long.MAX_VALUE) {
                    continue;
                }
                dp[i][j] += dp[i-1][j] * 2;
                dp[i][j] %= mod;
                if (S < j + A[i-1]) {
                    continue;
                }
                dp[i][j + A[i-1]] += dp[i-1][j];
                dp[i][j + A[i-1]] %= mod;
            }
        }
        System.out.println(dp[N][S]);
    }
}


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

counter = 0
remainder = 0

while True:
    for i in range(len(A)):
        remainder += (A[i] % 2)
        A[i] /= 2
    if remainder != 0:
        break
    else:
        counter += 1

print(counter)

Measured memory_bytes: 2940
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i]+rest, M[i])
  rest = min(H[i]+rest-killed, H[i])
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)


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

#define int long long

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

int N, A, B;

signed main() {
    cin >> N >> A >> B;
    if (abs(A - B) % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    vector<vector<Pii>> jst(N);
    for (ll i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        jst[i].resize(ai);
        for (ll j = 0; j < ai; j++) {
            cin >> jst[i][j].first >> jst[i][j].second;
        }
    }

    ll ans = 0;
    Vi oks;
    for (ll mask = 0; mask < (1LL << N); mask++) {
        oks.assign(N, -1);
        bool good = true;
        for (ll i = 0; i < N; i++) {
            if ((mask >> i) & 1) {
                for (const auto& js : jst[i]) {
                    if (oks[js.first - 1] == -1) {
                        oks[js.first - 1] = js.second;
                    }
                    else {
                        if (oks[js.first - 1] != js.second) {
                            good = false;
                            break;
                        }
                    }
                }
            }
            if (!good) break;
        }

        for (ll i = 0; i < N; i++) {
            if ((mask >> i) & 1) {
                if (oks[i] == 0) good = false;
            }
            else {
                if (oks[i] == 1) good = false;
            }
        }

        if (good) {
            ans = max(ans, (ll)__builtin_popcountll(mask));
        }
    }

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

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 256
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N, T = MI()
ct = []

for _ in range(N):
    c, t = MI()
    ct.append([c, t])
    
ct.sort(key = lambda x : x[0])
flg = False
ans = 0

for i in range(N):
    if ct[i][1] <= T:
        ans = ct[i][0]
        flg = True
        break
        
print(ans if flg else "TLE")

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

int main()
{
    string S;
    getline(cin, S);
    int c_count = 0;
    int lowercase = 0;

    if (S[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }
    for (int i = 2; i <= S.size() - 2; i++)
    {
        if (S[i] == 'C') c_count++;
    }

    if (c_count != 1)
    {
        cout << "WA" << endl;
        return 0;
    }

    for (int i = 1; i < S.size(); i++)
    {
        if (S[i] > 'Z') lowercase++;
    }

    if (lowercase != S.size() - 2)
    {
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
//#define local
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    char s[20];
    long long ans=0,sum,t;
    cin>>s;
    int k=strlen(s);
    for(int i=0; i<1<<(k-1); i++)
    {
        sum=0;
        t=s[0]-'0';
        for(int j=0; j<k-1; j++)
        {
            if(i&(1<<j))
            {
                sum+=t;
                t=s[j+1]-'0';
            }
            else t=10*t+s[j+1]-'0';
        }
        ans+=sum+t;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define vi vector<int>
#define vii vector< vector<int> >
#define vpi vector< pair<int,int> >
#define pair <int, int> pii

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
    ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int mod)
{
	x %= mod ;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % mod ;
		x = x * x % mod ;
		n >>= 1 ;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;
const int N = 1e5 + 10 ;

signed main()
{
        ios::sync_with_stdio(false) ;
        cin.tie(0) ;
        cout.tie(0) ; 
        int n;
        cin>>n;
        string s;
        cin>>s;
        int ans=0;
        for(int i=0;i+2<s.length();i++) {
                if(s.substr(i,3)=="ABC") {
                        ans++;
                }
        }
	cout<<ans<<endl;

return 0 ;
}


Measured memory_bytes: 256
import itertools

n, *abc = map(int, input().split())
llst = [int(input()) for _ in range(n)]

ans = 10 ** 10
for abc_lst in itertools.product(range(4), repeat = n):
    tmp = 0
    labc = [[0, 0] for _ in range(3)]
    for i in range(n):
        pos = abc_lst[i]
        if pos == 3:
            continue
        labc[pos][0] += llst[i]
        labc[pos][1] += 1
    if [0, 0] in labc:
        continue
    for i in range(3):
        tmp += abs(abc[i] - labc[i][0])
        tmp += 10 * (labc[i][1] - 1)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9228