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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int n, q;
vector<int> com, x, y;
/**********************************************/

class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ
    public:
        UnionFind(int n);          // n要素で初期化
        int Find(int x);           // 木の根を返す
        void Unite(int x, int y);  // xとyの属する集合を併合
        bool Same(int x, int y);   // xとyが同じ集合に属するか否か
};

UnionFind::UnionFind(int n) : parent(vector<int>(n)), rank(vector<int>(n)) 
{
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

int UnionFind::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        return parent[x] = Find(parent[x]);
    }
}

void UnionFind::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool UnionFind::Same(int x, int y) { return Find(x) == Find(y); }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> q;
    com.assign(q, 0);
    x.assign(q, 0);
    y.assign(q, 0);
    
    REP(i, q) cin >> com[i] >> x[i] >> y[i];

    UnionFind uf(n);
    REP(i, q){
        if(com[i] == 0) uf.Unite(x[i], y[i]);
        else cout << (uf.Same(x[i], y[i]) ? 1 : 0) << endl;
    }

}



Measured memory_bytes: 4296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

//-----------------------------------------


int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  int ans = a[0];
  rep(i,N) ans = gcd(a[i],ans);
  cout << ans << endl;
  return 0;
}




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

using ll = long long;

constexpr ll INF = 1e18;

int main() {
    ll H, W;
    cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll res = INF;
    for(ll h = 1; h < H; ++h) {
        ll s1 = W * h;

        ll s2 = (H - h) * (W / 2);
        ll s3 = (H - h) * W - s2;
        ll ma = max(s1, max(s2, s3));
        ll mi = min(s1, min(s2, s3));
        res = min(res, ma - mi);

        s2 = (H - h) / 2 * W;
        s3 = (H - h) * W - s2;
        ma = max(s1, max(s2, s3));
        mi = min(s1, min(s2, s3));
        res = min(res, ma - mi);
    }

    swap(H, W);
    for(ll h = 1; h < H; ++h) {
        ll s1 = W * h;

        ll s2 = (H - h) * (W / 2);
        ll s3 = (H - h) * W - s2;
        ll ma = max(s1, max(s2, s3));
        ll mi = min(s1, min(s2, s3));
        res = min(res, ma - mi);

        s2 = (H - h) / 2 * W;
        s3 = (H - h) * W - s2;
        ma = max(s1, max(s2, s3));
        mi = min(s1, min(s2, s3));
        res = min(res, ma - mi);
    }

    cout << res << endl;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B, C; cin >> A >> B >> C;
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
    cout << 0 << endl;
  }else {
    cout << min(A*B, min(B*C, C*A)) << endl;
  }


  return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* subroutines */

int count_rec(int pi, int qi, int ai, int ni, int q0) {
  int a1, c, g, p1, q, q1;

  if (pi == 0) return 1;
  if (ni <= 0) return 0;

  c = 0;

  for (q = q0; q <= ai; q++) {
    p1 = pi * q - qi;
    if (p1 < 0) continue;
    q1 = qi * q;
    a1 = ai / q;
    c += count_rec(p1, q1, a1, ni - 1, q);
  }

  return c;
}


/* main */

int main(int argc, char **argv) {
  int ai, c, ni, pi, qi;

  for (;;) {
    scanf("%d%d%d%d", &pi, &qi, &ai, &ni);
    if ((pi | qi | ai | ni) == 0) break;

    c = count_rec(pi, qi, ai, ni, 1);
    printf("%d\n", c);
  }

  return 0;
}

Measured memory_bytes: 600
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

a,b = 0,0
flag = 0

ix = list(itertools.permutations(range(1,1+n)))

if (p != q):
    for i in range(len(ix)):
        t = list(ix[i])
        if (p == t):
            a = i
            flag += 1
        elif (q == t):
            b = i
            flag += 1
        if (flag == 2):
            break
print(abs(a-b))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,k,q,i;
cin>>n>>k>>q;
long long a[n]={0};
for(i=0;i<q;i++){
    long long m;
    cin>>m;
    a[m-1]++;

}for(i=0;i<n;i++){
    a[i]=a[i]+k-q;
    if(a[i]<=0)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
}
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

int main(){
  string str;
  cin >> str;
  string ans = "CODEFESTIVAL2016";
  int cnt = 0;
  REP(i, 0, str.size()) {
    if(ans[i] != str[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

#define MAX_H   (800)                  // 10^5
#define MAX_N   (100000)                  // 10^5
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

ll H, W, K;
string MAP[MAX_H];
int DIST[MAX_H][MAX_H];

bool is_inside(int i, int j) {
  return 0 <= i && i < H && 0 <= j && j < W;
}

ll min_turn() {
  int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

  queue<Pi> que;
  vector<Pi> cell;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      DIST[i][j] = INFI;
      if (MAP[i][j] == 'S') {
        que.push(Pi(i, j));
        cell.push_back(Pi(i, j));
        DIST[i][j] = 0;
      }
    }
  }

  while (!que.empty()) {
    Pi p = que.front(); que.pop();
    int r = p.FST, c = p.SND;
    for (int i = 0; i < 4; i++) {
      int rx = r + dir[i][0], cx = c + dir[i][1];
      if (is_inside(rx, cx)) {
        int dist = DIST[r][c] + 1;
        if (MAP[rx][cx] == '.' && dist < DIST[rx][cx] && dist <= K) {
          DIST[rx][cx] = dist;
          que.push(Pi(rx, cx));
          cell.push_back(Pi(rx, cx));
        }
      }
    }
  }

  ll mn = INFI;
  for (auto p : cell) {
    int r = p.FST, c = p.SND;
    ll vals[4] = {r, c, H - 1 - r, W - 1 - c};
    for (int i = 0; i < 4; i++) mn = min(mn, vals[i]);
  }

  return (mn + 2 * K - 1) / K;
}

void solve() {
  ll ans = min_turn();
  cout << ans << endl;
}

int main() {
  cin >> H >> W >> K;

  for (int i = 0; i < H; i++) cin >> MAP[i];

  solve();

  return 0;
}
/*
5 5 1
.....
.....
..S..
.....
.....
*/

Measured memory_bytes: 13424
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
  if sum(map(lambda x, y:x*y, a[i], b)) + c > 0:
    cnt += 1
print(cnt)

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

int main(){
    int N, K, n = 1;
    cin >> N;
    cin >> K;

    rep(i, N)
    {
        if(n <= K){
            n *= 2;
        }else{
            n += K;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, M;
    map<string, int> mp;

    cin >> N;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        mp[S] ++;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        string S;
        cin >> S;
        mp[S] --;
    }

    int res = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        res = max(res, itr->second);
    }
    
    cout << res << endl;

    return 0;
}

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

int main()
{
    long long n,a,res;
    cin>>n;
    res=0;
    while(n--)
    {
        cin>>a;
        while(!(a&1))
        {
            a=a>>1;
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
def get_start(tile, h, w):
	for i in range(w):
		for j in range(h):
			if tile[i][j] == '@':
				return (i, j)

dirs = [(-1, 0), (0, -1), (1, 0), (0, 1)]

while True:
	w, h = map(int, input().split())
	if (w,h) == (0,0):
		break
	tile = [list(input()) for i in range(h)]
	start = get_start(tile, w, h)
	count = 0
	q = [start]
	while q:
		(x,y) = q.pop()
		for d in dirs:
			xx = x+d[0]
			yy = y+d[1]
			if (0 <= xx and xx < h) and (0 <= yy and yy < w):
				if tile[xx][yy] == '.':
					tile[xx][yy] = '_'
					count += 1
					q.append((xx,yy))
	print(count+1)
	

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

int main() {
    int n,m=0,ans=0;cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
        cin>>a[i];
        m=max(m,a[i]);
        ans+=a[i];
    }
    ans-=m/2;
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  long long N, w;

  std::cin >> N;

  for (int h = 1; h <= 3500; h ++)
    for (int n = 1; n <= 3500; n ++) {
      long long num   = N * h * n;
      long long denom = 4 * h * n - N * n - N * h;

      if (denom)
        if (num % denom == 0)
          if ((w = num / denom) > 0) {
            std::cout << h << ' ' << n << ' ' << num / denom << std::endl;

            goto endloop;
          }
    }

 endloop:

  return 0;
}


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

ll knapsack(ll pos,ll *wt,ll *val,ll w,ll **dp)
{
    if(w==0)
    {
        return 0;
    }
   
    if(pos<0)
        return 0;
    if(dp[pos][w]!=-1)
    {
        return dp[pos][w];   
    }
    ll ans1 = 0;
    if(w-wt[pos]>=0)
     ans1 = val[pos]+knapsack(pos-1,wt,val,w-wt[pos],dp);
    ll ans2 = knapsack(pos-1,wt,val,w,dp);
    ll ans = max(ans1,ans2);
    dp[pos][w] = ans;
    return ans;
}


int main(){
    ll n,w;
    cin>>n>>w;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }
    ll **dp = new ll*[n];
    for(ll i=0;i<n;i++)
    {
        dp[i] = new ll[w+1];
        for(ll j=0;j<=w;j++)
        {
            dp[i][j]=-1;
        }
    }
    cout<<knapsack(n-1,wt,val,w,dp);
    
}

Measured memory_bytes: 80256
#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;

std::vector<int> G[55];
typedef std::pair<int, int> P;
std::map<P, int> eid;
std::vector<int> eset;
bool dfs(int v, int tv, int p = -1){
  if(v == tv){
    return true;
  }
  for(int nv:G[v]){
    if(nv == p)continue;
    if(dfs(nv, tv, v)){
      eset.push_back(eid[P(v, nv)]);
      return true;
    }else{
      continue;
    }
  }
  return false;
}
    
int main(){
  using namespace std;
  long long n;
  cin>>n;
  int a[n-1], b[n-1];
  REP(i,n-1){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
    eid[P(a[i], b[i])] = eid[P(b[i], a[i])] = i;
  }
  int m;
  cin>>m;
  int u[m], v[m];
  long long condnum[m] = {};
  REP(i,m){
    cin>>u[i]>>v[i];
    u[i]--;v[i]--;
    //eset = vector<int>();
    eset.clear();
    dfs(u[i], v[i]);
    for(int id:eset){
      condnum[i] |= (1LL<<id);
    }
  }
  
  long long ans = 0;
  REP(s, (1<<m)){
    long long mask = 0;
    REP(i, m){
      if(s & (1<<i)){
        mask |= condnum[i];
      }
    }
    long long c = __builtin_popcountll(mask);
    long long num = (1LL<<(n-1-c));
    if(__builtin_popcountll(s) % 2 == 0){
      ans += num;
    }else{
      ans -= num;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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






void stoogesort(vector<int> &a, int l, int r){
    if(a[l] > a[r]){
        swap(a[l], a[r]);
    }
    if(r - l + 1 >= 3){
        int t = (r - l + 1) / 3;
        stoogesort(a, l, r - t);
        stoogesort(a, l + t, r);
        stoogesort(a, l, r - t);
    }
}


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    REP(i, 2000){
        stoogesort(a, 0, n - 1);
        cerr << i << endl;
    }
    cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

long long func(int n)
{
	return (n > 1) ? n * func(n - 1) : 1;
}
int main()
{
	int n;
	cin >> n;

	cout << func(n) << endl;
}


Measured memory_bytes: 3052
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    
    int n, ans;
    double dist, xa, ya, ra, xb, yb, rb;
    
    scanf("%d", &n);
    
    while (n > 0) {
        
        scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
        
        dist = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
        
        if (dist > ra + rb) {
            ans = 0;
        } else if (dist == ra && dist == rb) {
            ans = 1;
        } else if (dist < (ra - rb) && ra > rb) {
            ans = 2;
        } else if (dist < (rb - ra) && rb > ra) {
            ans = -2;
        } else {
            ans = 1;
        }
        
        printf("%d\n", ans);
        
        n--;
        
    }

    return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC084D()
{
	int Q;
	cin >> Q;
	vector<int> primes(100001);
	primes[0] = 1;
	primes[1] = 1;
	for (int i = 2; i < 317; ++i)
	{
		if (primes[i] == 1)
			continue;
		for (int j = 2; j * i < 100001; ++j)
		{
			primes[j*i] = 1;
		}
	}
	vector<int> primeOnly; primeOnly.reserve(1000);
	for (int i = 0; i < 100001; ++i)
		if (primes[i] == 0)
			primeOnly.push_back(i);

	vector<int> prime2Only; prime2Only.reserve(1000);
	for (int i = 0; i < static_cast<int>(primeOnly.size()); ++i)
	{
		int p2 = (primeOnly[i] + 1) / 2;
		auto p = lower_bound(primeOnly.cbegin(), primeOnly.cend(), p2);
		if (p != primeOnly.cend() && *p == p2)
			prime2Only.push_back(primeOnly[i]);
	}

	vector<int> ct(100001);
	for (int i = 0; i < prime2Only.size(); ++i)
		ct[prime2Only[i]] = 1;
	for (int i = 0; i < 100000; ++i)
		ct[i + 1] += ct[i];

	for (int i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;
		cout << ct[r] - ct[l - 1] << endl;
		continue;
		auto pl = lower_bound(prime2Only.begin(), prime2Only.end(), l);
		auto pr = upper_bound(prime2Only.begin(), prime2Only.end(), r);
		if(pl == prime2Only.cend())
		{
			cout << 0 << endl;
			return;
		}
		int x = pr - pl;
		cout << x << endl;
	}
}
int main()
{
	ABC084D();
	return 0;
}

Measured memory_bytes: 1536
#include <string>
#include <iostream>
#include <set>       // 要素数は size() で取得
#include <algorithm> // count_ifに必要
#include <array>     // size固定の配列
#include <queue>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

ll gcd(ll x, ll y)
{
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

template <class InputIterator, class T>
bool contains(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

// =========ここまでテンプレ============

int main()
{
    ll r;
    cin >> r;
    cout << r * 6.283185307179586232;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

const int MAX_N = 2e3 + 10, MAX_A = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, m;
int a[MAX_N], b[MAX_N];
int dp[MAX_N][MAX_N];

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

int rec (int pos1, int pos2) {
  if (pos1 == n or pos2 == m) return 1;
  int& ret = dp[pos1][pos2];
  if (ret != -1) return ret;
  ret = 0;
  ret = add(ret, rec(pos1, pos2 + 1));
  ret = add(ret, rec(pos1 + 1, pos2));
  if (a[pos1] != b[pos2]) {
    ret = add(ret, MOD - rec(pos1 + 1, pos2 + 1));
  }
  return ret;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  cout << rec(0, 0) << endl;
  return (0);
}


Measured memory_bytes: 16512
n = int(raw_input())
minv = int(raw_input())
maxv = 0 - 1000000000
  
for j in range( n-1 ):
  num = int( raw_input( ) )  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
  
print maxv

Measured memory_bytes: 12696
#include <stdio.h>

#define WIDTH 12
#define HEIGHT 12

void del( int, int );

char field[ WIDTH + 2 ][ HEIGHT + 2 ];
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int main( void ) {
	int x, y, sum;

	for ( ; ungetc( getchar(), stdin ) != EOF; printf( "%d\n", sum ) ) {
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				scanf( "%c ", field[ x ] + y );

		sum = 0;
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				if ( field[ x ][ y ] == '1' ) {
					del( x, y );
					sum++;
				}
	}

	return 0;
}

void del( int x, int y ) {
	int i;

	field[ x ][ y ] = '0';

	for ( i = 0; i < 4; i++ ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ] == '1' )
			del( nx, ny );
	}
}

Measured memory_bytes: 548
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	long double l;
 	cin>>l;
 	long double ans=(l*l*l)/27.00;
 	cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		str = str.replaceAll("0", "");
		System.out.println(str.length());
	}
}

Measured memory_bytes: 21076
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val C = Array(N - 1) { 0L }
    val S = Array(N - 1) { 0L }
    val F = Array(N - 1) { 0L }

    for (i in C.indices) {
        val (c, s, f) = readLine()!!.split(" ").map{it.toLong()}
        C[i] = c
        S[i] = s
        F[i] = f
    }

    for (i in 0 until N) {
        var t = 0L
        for (j in i until C.size) {
            if (t < S[j]) {
                t = S[j]
            }
            val ns = (t + F[j] - 1) / F[j] * F[j]
            t = ns + C[j]
        }
        println(t)
    }
}


Measured memory_bytes: 37916
#include <cstdio>
#include <algorithm>
#define SIZE 33554432
char Key[128];
int Hash;
char* c;
#define HASH(A) c = A; Hash = 1; while(*c){ Hash <<= 2; Hash += Key[*c]; ++c;}
using namespace std;
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    Key['A'] = 0;
    Key['C'] = 1;
    Key['G'] = 2;
    Key['T'] = 3;
    bool* dic = new bool[SIZE];
    fill(dic, dic + SIZE, false);
    int n;
    std::scanf("%d\n", &n);
    char str[21];
    for (int i = 0; i < n; ++i) {
        fgets(str, 21, stdin);
        if (str[0] == 'i') {
            HASH(str + 7)
                dic[Hash] = true;
        }
        else {
            HASH(str + 5)
                puts((dic[Hash] ? "yes" : "no"));
        }
    }
    return 0;
}

Measured memory_bytes: 35460
#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 fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e9+7;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}


int32_t main()
{
    fast;
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{

    ll n,m;
    cin>>n>>m;
    ll d=n;
    map<ll,ll>mp;
    ll cnt=0;
    while(d--)
    {
        ll x;
        cin>>x;
        for(int i=0;i<x;i++)
        {
            ll k;
            cin>>k;
            mp[k]++;
        }

    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ll x=it->second;
        if(x==n)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;


}


Measured memory_bytes: 3616
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define piiii pair<pair<int, int>, pair<int, int>>


ll pwm(ll xx, ll pow, ll MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return mlt;
}

int inv(ll r, int _mod) {
    return pwm(r % _mod, _mod - 2, _mod);
}


vector<ll> fact;
vector<ll> invfact;

void factorial(int n, ll mod) {
    fact.resize(n);
    invfact.resize(n);
    fact[0] = 1;
    for (int i = 1; i < n; ++i) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
    invfact[n - 1] = inv(fact[n - 1], mod);
    for (int i = n - 2; i >= 0; i--) {
        invfact[i] = invfact[i + 1] * (i + 1);
        invfact[i] %= mod;
    }
}
ll mod=1e9+7;
void solve() {
    int n,k;
    cin>>n>>k;
    vector<int> min_del(k+1, 1);
    vector<int> mobius(k+1);
    for(ll i=1;i<k+1;i++){
        for(ll j=i*i;j<k+1;j+=i){
            if(min_del[j]==1) min_del[j]=i;
        }
    }
    for(int i=1;i<k+1;i++) {
        if(min_del[i]==1) min_del[i]=i;
    }
    mobius[1]=1;
    for(int i=2;i<k+1;i++){
        if(min_del[i]==min_del[i/min_del[i]]) mobius[i]=0;
        else{
            mobius[i]=-mobius[i/min_del[i]];
        }
    }
    vector<ll> degs(k+1);
    for(int i=1;i<k+1;i++){
        degs[i]=pwm(k/i,n,mod);
    }
    ll ans=0;
    for(int i=1;i<k+1;i++){
        ll summ=0;
        for(int d=1;d<=k/i;d++){
            summ+=degs[i*d]*mobius[d];
            summ%=mod;
        }
        summ*=i;
        summ%=mod;
        ans+=summ;
        ans%=mod;
    }
    cout<<ans<<endl;

}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

Measured memory_bytes: 4848
#include <stdio.h>

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {

  int n; cin >> n;
  for(int i=0; i<=n; i+=4){
    for(int j=0; j<=n; j+=7){
      if( i + j == n ){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}




//


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

using namespace std;

typedef long long int ll;

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

typedef pair<int,int> pair;

int main(){
  char s; cin >> s;
  printf("%c\n",s+1);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define P pair<ll, ll>
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

int main(void)
{
    int n;
    cin >> n;
    vector<P> vec(n);
    rep(i, 0, n)
    {
        ll a, b;
        cin >> a >> b;
        vec[i].first = a + b;
        vec[i].second = a - b;
    }
    sort(all(vec));
    ll ans = 0;
    ll tmp = -INF;
    rep(i, 0, n) if (tmp <= vec[i].second) ans++, tmp = vec[i].first;
    cout << ans << endl;
}

Measured memory_bytes: 4828
#include<iostream>
main(){int n,m,i,a,c[1000001];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, s;
  int ans;
  vi32 v(10);
  function<void(int, int)> rec = [&](int x, int i) {
    if (x == n) {
      int sum = accumulate(all(v), 0);
      if (sum == s) ans++;
      return;
    }
    repic(j, i + 1, 9) {
      v.push_back(j);
      rec(x + 1, j);
      v.pop_back();
    }
  };

  while (true) {
    cin >> n >> s;
    if (n == 0) return;
    ans = 0;
    rec(0, -1);
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3204
N, K = map(int, input().split(' '))
S = input()

lengths = []

if S.startswith('0'):
    lengths.append(0)

cont = 0
for s0, s1 in zip(S, S[1:] + 'x'):
    cont += 1
    if s0 != s1:
        lengths.append(cont)
        cont = 0

if S.endswith('0'):
    lengths.append(0)

window = 2 * K + 1

buf = sum(lengths[0:window])
ans = buf
for i in range(window, len(lengths)):
    buf += lengths[i]
    buf -= lengths[i - window]
    if i % 2 == 0:
        ans = max(ans, buf)

print(ans)


Measured memory_bytes: 10488
#include <iostream>

using namespace std;

int main() {
  int ans,n,s;
  int i=1;
  cin>>n;
  if(n==1 || n==2 ||n==4)
    ans=4;
  else
  {  
    while(n!=4)
  {
	if(n%2==0){
      n=n/2; i++;
    }
    else{
      
      n=(3*n)+1; i++;
    }
	ans=i+3;
  }
  }
  cout<<ans;
  
  return 0;
}
  

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

#define ll long long
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define all(a) (a).begin(),(a).end()


signed main(){
    string st;
    cin>>st;
    cout<<st[0]<<st.length()-2<<st[st.length()-1]<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int x;
    cin >> x;
    int ans = 1;
    for (int i = 1; i <= x; i++) {
        for (int j = 2; j <= x; j++) {
            int tmp = pow(i, j);
            if (tmp <= x) {
                ans = max(tmp, ans);
            } else
                break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4072
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
	
		int N = keyboard.nextInt();
		
		int[]A = new int[N];
		Set<Integer> sp = new HashSet<Integer>();
		
		for(int i = 0; i<N; i++) {
			A[i] = keyboard.nextInt();
			sp.add(A[i]);
		}
		
		boolean flag = false;  
		
		if(sp.size() == 1){
//			aが1種類であるとき1、aは必ず０でないといけない
		if(A[0] == 0) {
			flag = true;
		}
	}
//			Nが３の倍数個であるとき
		if(N % 3 == 0) {
//				aが３種類であるとき
			if(sp.size() == 3) {
//					a1^a2 == a3である、かつ各aの個数が等しい
				Integer[]a = sp.toArray(new Integer[0]);
				if((a[0]^a[1]) == a[2]) {
					Arrays.sort(A); 
					if(A[0] == A[N/3-1] && A[N/3] == A[2*N/3-1] && A[2*N/3] == A[N-1]) {
						flag = true;
					}
				}
			}else if(sp.size() == 2){
//				aが２種類であるとき
				Integer[]a = sp.toArray(new Integer[0]);
				if(a[0]== 0) {
					Arrays.sort(A); 
					if(A[0] == A[N/3-1] && A[N/3] == A[N-1]) {
						flag = true;
					}
				}
			}
		}

		String ans = "";
		if(flag) {
			ans = "Yes";
		}else {
			ans = "No";
		}
		
		System.out.println(ans);
		keyboard.close();	
	}
}


Measured memory_bytes: 63400
marks='SHCD'
n=input()
card=[raw_input().split() for _ in range(n)]
m={}
for mk,rk in card:
    m.setdefault(mk,[0]*14)
    m[mk][int(rk)]=1
for i in range(len(m)):
    k=marks[i]
    v=m[k]
    for j in range(1,14):
        if not v[j]: print k,j

Measured memory_bytes: 4236
#include<stdio.h>


int main(void){
	int a,b;
	int c;
	int d;

	c = 1;
	d = 0;

	scanf("%d %d",&a,&b);
	while(c < b){
		c += (a-1);
		d++;

	};

	printf("%d",d);
	return 0;
}

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

using namespace std;

int main()
{
    map<char,int>m;
    map<char,int>::iterator itr;
    string s;
    cin>>s;
    int i,n=s.length(),chk=0;

    if(n%2!=0) cout<<"No";
    else{
    for(i=0;i<n;i++){
        m[s[i]]++;
    }
    for(itr=m.begin();itr!=m.end();itr++){
        if(itr->second%2!=0){
                chk=1;
            break;
        }}
   if(chk==0){
        cout<<"Yes";
    }
    else cout<<"No";}
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int LCM(int x, int y) { return x * y / GCD(x, y); }

int main(){
    int n;
    cin >> n;
    vi a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    string ans = "No";
    if(a[0] == 0 && a[n-1] == 0){
        ans = "Yes";
    }
    else if(n%3==0){
        if(a[0] == 0 && a[n/3 - 1] == 0 && a[n/3] == a[n-1]){
            ans = "Yes";
        }
        else if((int)(a[0]^a[n/3]^a[n*2/3])==0 && a[0]==a[n/3 - 1] && a[n/3] == a[n*2/3 - 1] && a[n*2/3] == a[n-1]){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
# coding: utf-8
N = int(input())
ans = 0
a_l = {"M":0, "A":0, "R":0, "C":0, "H":0}
a_l = [0] * 5
a_l_char = ["M", "A", "R", "C", "H"]
for _ in range(N):
    tmp = input()
    # a_l[str(tmp[0])] += 1
    for i in range(len(a_l_char)):
        if tmp[0] == a_l_char[i]:
            a_l[i] += 1
ans += a_l[0] * a_l[1] * a_l[2]
ans += a_l[0] * a_l[1] * a_l[3]
ans += a_l[0] * a_l[1] * a_l[4]
ans += a_l[0] * a_l[2] * a_l[3]
ans += a_l[0] * a_l[2] * a_l[4]
ans += a_l[0] * a_l[3] * a_l[4]

ans += a_l[1] * a_l[2] * a_l[3]
ans += a_l[1] * a_l[2] * a_l[4]
ans += a_l[1] * a_l[3] * a_l[4]

ans += a_l[2] * a_l[3] * a_l[4]

print(ans)

Measured memory_bytes: 3064
from collections import deque

h,w=map(int,input().split())
G=[]
for i in range(h):
    G.append(list(str(input())))


#白マス数える
white=0
for i in range(h):
    for j in range(w):
        if G[i][j]=='.':
            white+=1


def sur(v):
    vx=v[0]
    vy=v[1]
    preE=[(vx-1,vy),(vx+1,vy),(vx,vy+1),(vx,vy-1)]
    E=[]
    for nv in preE:
        if 0<=nv[0]<=h-1 and 0<=nv[1]<=w-1:
            if G[nv[0]][nv[1]]=='.':
                E.append(nv)
    return E

#bfs
dist=[[0]*w for i in range(h)]
q=deque()

dist[0][0]=1
q.append((0,0))
while q:
    now=q.popleft()
    for next in sur(now):
        if dist[next[0]][next[1]]>0:
            continue
        q.append(next)
        dist[next[0]][next[1]]=dist[now[0]][now[1]]+1

        if next==(h-1,w-1):
            print(white-dist[h-1][w-1])
            break
    else:
        continue
    break
else:
    print(-1)






Measured memory_bytes: 9484
#5番目までに大きな数値を探すということは、5文字以内の文字列だけを検索すれば良い
s = str(input())
k = int(input())
substring = []

for i in range(len(s)+1):
	for j in range(i,i+6):
		substring.append(s[i:j])

		
sub = list(set(substring))
sub.remove('')
sub.sort()

print(sub[k-1])

Measured memory_bytes: 5044
import collections
import sys
sys.setrecursionlimit(10**6)
def dfs(visited,v,adj):
    visited[v]=True 
    for i in adj[v]:
        if not visited[i]:
            dfs(visited,i,adj)  
adj=collections.defaultdict(list)
n,m=map(int,input().split()) 
visited=[False]*n  
for i in range(m):
    u,v=map(int,input().split()) 
    adj[u-1].append(v-1)  
    adj[v-1].append(u-1) 
c=0 
for i in range(n):
    if not visited[i]:
        dfs(visited,i,adj) 
        c+=1 
print(c-1)

Measured memory_bytes: 53756
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int N, M;
    cin >> N >> M;
    vector< vector <pair<int,int>> > adj(N + 1);
    vector<int> Heights(N + 1);
    rep1(i, N) cin >> Heights[i];
    for (int m = 0; m < M; ++m) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(make_pair(v,Heights[v]));
        adj[v].push_back(make_pair(u,Heights[u]));
    }
    ll ans = 0;
    rep1(i,N){
        int max_element = 0;
        for(auto it : adj[i]){
            int x = it.second;
            max_element = max(max_element, x);
            //deb(it.first); deb(x); deb(max_element);
        }
        if(max_element < Heights[i]) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9460
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
int n,m;
bool V[10000];
int indeg[10000];
VI G[10000];
LI out;

void bfs(int s)
{
	queue<int> Q;
	Q.push(s);
	V[s]=true;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		out.PB(u);
		
		REP(i,SZ(G[u]))
		{
			int v=G[u][i];
			indeg[v]--;
			if(indeg[v]==0&&!V[v])
			{
				V[v]=true;
				Q.push(v);
			}
		}
	}
}

void topologicalS()
{
	REP(u,n)
	{
		if(!indeg[u]&&!V[u])
		{
			bfs(u);
		}
	}
}

int main()
{
	cin>>n>>m;
	REP(i,m)
	{
		int s,t;cin>>s>>t;
		G[s].PB(t);
		indeg[t]++;
	}
	topologicalS();
	
	for(list<int>::iterator it=out.begin();it!=out.end();it++)
	{
		cout<<*it<<endl;
	}
	
	return 0;
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int dp[100001][2];
vector<int>v[100001];
void dfs(int node,int par)
{
    dp[node][0]=1;
    dp[node][1]=1;
    for(auto c:v[node])
    {
        if(c!=par)
        {
            dfs(c,node);
            dp[node][1]=(dp[node][1]*dp[c][0])%mod;
            dp[node][0]=(dp[node][0]*(dp[c][1]+dp[c][0]))%mod;
        }
    }
}
int32_t main() {
    nitin;
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(0,-1);
    cout<<(dp[0][0]+dp[0][1])%mod<<endl;
    return 0;
}

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

// string res = "";

// string fanc(int i, int size,string s){

//   // base case
//   if ( i > size - 2 ) {
//     cout << s << endl;
//     return "end";
//   }

//   // connect
//   // int res;
//   string con;
//   // s.insert(i,"/");
//   con = fanc(i+2,size+1,s = s.insert(i+1,"/"));
//   if (con == "end") res += s;
//   // if (con != "") return s;

//   // disconnect
//   string discon;
//   discon = fanc(i+1,size,s);
//   if (discon == "end") res += s;
//   // if (discon != "") return s;

//   return "end";
// }

int main(){
  string s;
  cin >> s;
  // cout << s << endl;

  // int test = s[0] - '0';
  // cout << s[0] << endl;
  // cout << test << endl;

  // cout << fanc(0,s.size(),s) << endl;
  // cout << s.insert(1,"/") << endl;
  // fanc(0,s.size(),s);
  // cout << res << endl;

  // bit全探査
  int counter;
  int size = s.size();
  long long tmp = 0;
  long long ans = 0;
  long long sum = 0;

  if(s.size() == 1) {
    cout << s[0] << endl;
    return 0;
  }
  
  for (int bit = 0; bit < (1<<(size - 1)); bit++){
    string res = s;
    counter = 1;
    for (int i = 0; i < size; i++){
      if ( bit & ( 1 << i ) ) res.insert(i+counter,"+"), counter ++;
    }
    // cout << res << endl;

    
    int size_res;
    size_res = res.size();
    tmp = res[0] - '0';
    ans = 0;
    for ( int j = 1; j < size_res; j++){

      if ( res[j] == '+' ) ans += tmp, tmp = res[j+1] - '0', j++;
      else {
        tmp = tmp * 10 + (res[j] - '0');
      }

      if (j == (size_res - 1)) ans += tmp, tmp = 0;
    }

    // cout << ans << endl;
    sum += ans;
    ans = 0;
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256