akhauriyash/Code-Regression huggingface dataset:
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		char[] s = S.toCharArray();
		char[] t = T.toCharArray();

		String ans = "";

		for(int i=0;i<N;i++) {
			ans += Character.toString(s[i]);
			ans += Character.toString(t[i]);
		}
		System.out.println(ans);
	}
}

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

using namespace std;

int main()
{
	const int M = 20;
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto &x : A) {
		cin >> x;
	}

	vector<vector<int>> v(M, vector<int>(N, 0));

	for (int j = 0; j < M; ++j) {
		if (A[0] & (1 << j)) {
			v[j][0] = 1;
		}
	}

	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			v[j][i] = v[j][i - 1];
			if (A[i] & (1 << j)) {
				++v[j][i];
			}
		}
	}

	long long ans = 0;

	for (int l = 0; l < N; ++l) {
		int r = N;
		for (int j = 0; j < M; ++j) {
			if (A[l] & (1 << j)) {
				int i = upper_bound(v[j].begin() + l, v[j].end(), v[j][l]) - v[j].begin();
				r = min(r, i);
			}
			else {
				int i = upper_bound(v[j].begin() + l, v[j].end(), v[j][l] + 1) - v[j].begin();
				r = min(r, i);
			}
		}
		ans += r - l;
	}

	cout << ans << endl;
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
int main()
{
	int d, t, s;
	cin >> d >> t >> s;
	if(t * s >= d) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <array>

using namespace std;

void dfs(int cur, int cur_cnt, const vector<vector<int> > &child, vector<int> &ans, const vector<int> &cum_sum)
{
    cur_cnt += cum_sum.at(cur);
    ans.at(cur) = cur_cnt;

    vector<int> nexts = child.at(cur);
    if (nexts.empty())
    {
        return;
    }
    else
    {
        for (int n : nexts)
        {
            dfs(n, cur_cnt, child, ans, cum_sum);
        }
    }
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    vector<vector<int> > child(N);
    int a, b;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> a >> b;
        child[a - 1].push_back(b - 1);
    }

    vector<int> cum_sum(N);
    int p, x;
    for (int i = 0; i < Q; i++)
    {
        cin >> p >> x;
        cum_sum[p - 1] += x;
    }

    vector<int> ans(N);
    dfs(0, 0, child, ans, cum_sum);
    for (int i = 0; i < N; i++)
    {
        cout << ans[i];
        if (i == N - 1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

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

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

    ull a, b, x;
    cin >> a >> b >> x;
    ull res;

    if (a == 0)
        res = b/x + 1;
    else 
        res = (b/x + 1) - ((a-1)/x + 1);

    cout << res << "\n";
}

Measured memory_bytes: 256
class SegmentTree(object):
    INIT = 2 ** 31 - 1
    DIVIDED = -1

    def __init__(self, n: int) -> None:
        size = 1
        while size < n:
            size *= 2
        self.size = 2 * size - 1
        self.data = [-1] * self.size
        self.data[0] = self.INIT

    def set_range(self, l: int, h: int, v: int) -> None:
        def _set_range(r, i: int, j: int, vv: int) -> None:
            if (j < l or i > h):
                if vv != self.DIVIDED:
                    self.data[r] = vv
            elif (l <= i and j <= h):  # noqa: E741
                self.data[r] = v
            else:
                if self.data[r] != self.DIVIDED:
                    if vv == self.DIVIDED:
                        vv = self.data[r]
                    self.data[r] = self.DIVIDED
                mid = i + (j - i) // 2
                _set_range(r * 2 + 1, i, mid, vv)
                _set_range(r * 2 + 2, mid + 1, j, vv)

        _set_range(0, 0, self.size // 2, self.DIVIDED)

    def min(self, i: int, j: int) -> int:
        def _min(r, l: int, h: int) -> int:
            if (j < l or i > h):
                return self.INIT
            elif self.data[r] != self.DIVIDED:
                return self.data[r]
            else:
                mid = l + (h - l) // 2
                return min(_min(r * 2 + 1, l, mid),
                           _min(r * 2 + 2, mid + 1, h))

        return _min(0, 0, self.size // 2)


if __name__ == "__main__":
    n, q = map(lambda x: int(x), input().split())
    segtree = SegmentTree(n)

    for _ in range(q):
        com, *v = map(lambda x: int(x), input().split())
        if (0 == com):
            segtree.set_range(v[0], v[1], v[2])
        else:
            print(segtree.min(v[0], v[1]))



Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
const int MOD=1e9+7;
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
    LL g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
    LL x, y;
    if (extgcd(a, MOD, x, y) == 1)return (x + MOD) % MOD;
    else return 0; // unsolvable
}
// 階乗
// O(n)
#define SZ 1000010
LL fact[SZ];
struct fact_{
    fact_(){
        fact[0]=1;
        for(int i=1;i<SZ;i++)
            fact[i]=fact[i-1]*i%MOD;
    }
}fact_init;


// 組み合わせnCk (mod MOD)
// O(log n)
LL Comb(LL n,LL k){
    LL u=fact[n];
    LL d=(fact[k]*fact[n-k])%MOD;
    return (u*invMod(d))%MOD;
}


int main(){
    int n;cin>>n;
    V a(n+1);
    cin>>a;
    V cnt(n);
    V pos;
    REP(i,n+1){
        a[i]--;
        cnt[a[i]]++;
    }
    REP(i,n+1)if(cnt[a[i]]==2)pos.pb(i);
    int x=pos.front();
    int y=pos.back()-pos.front()-1;
    int z=n-pos.back();
    FOR(k,1,n+2){
        LL res=0;
        if(k>=2)res+=Comb(n-1,k-2);
        if(k<n)res+=Comb(n-1,k);
        if(k>=1&&k<=n){
            if(x+z>=k-1)res+=Comb(x+z,k-1);
            if(y>0){
                res+=2*Comb(n-1,k-1);
                if(x+z>=k-1)res+=2*MOD-2*Comb(x+z,k-1);
            }
        }
        cout<<res%MOD<<endl;
    }
    return 0;
}


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

using namespace std;

int main(){
	int n,m,t;
	cin >> n >> m >> t;
	t++;
	vector<bool> v(t);
	for(int i=0;i<t;i++) v[i] = false;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		v[a] = true;
	}
	int count = 0;
	for(int i=0;i<t;i++){
		if(v[i]) count = m+1;
		else count=max(count-1,0);
		if(count) v[i]=true;
	}
	count = 0;
	for(int i=t-1;i>=0;i--){
		if(v[i]) count = m+1;
		else count=max(count-1,0);
		if(count) v[i]=true;
	}
	int ans = 0;
	for(int i=0;i<t-1;i++){
		if(!v[i] || !v[i+1]){
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

    vector<string> s(N);

    rep(i,N){
        cin >> s[i];
    }

    rep(i,N){
        sort(s[i].begin(),s[i].end());
    }

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

    ll sum = 0;
    ll count = 1;
    irep(i,1,N){
        if(s[i-1]==s[i]){
            count++;
        }else{
            sum += count * (count - 1) / 2;
            count = 1;
        }
    }

    sum += count * (count - 1) / 2;

    cout << sum << endl;

}

Measured memory_bytes: 7296
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while(cin>>n){
		int a[n][3];
		int dp[n+1][3];
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)
			for(int j=0;j<3;j++)
				cin>>a[i][j];
		for(int i=1;i<=n;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					if(j!=k)
						dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i-1][j]);
		int ans=0;
		for(int i=0;i<3;i++)
			ans=max(ans,dp[n][i]) ;
		cout<<ans<<endl;
	}
}




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

int main()
{
    int n,sum=0;cin>>n;
    ll arr[n+5];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        if(i%2==1&&arr[i]%2==1)
            sum++;
    }
    cout<<sum;

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int SIZE = 2123456;
int fact[SIZE];

const int MAX_N = 1123456;
int a[MAX_N];
int x[MAX_N];

int choose_mod2(int n, int r) {
  int t = 0;
  t += fact[n];
  t -= fact[n-r];
  t -= fact[r];
  return t >= 1 ? 0 : 1;
}

int solve_small(int N) {
  int M = N - 1;
  while (M >= 1) {
    REP(i, M) x[i] = abs(a[i] - a[i+1]);
    REP(i, M) a[i] = x[i];
    M--;
  }
  return a[0];
}

int solve(int N) {

  if (N <= 8) {
    return solve_small(N);
  }

  int c[3] = {0, 0, 0};
  REP(i, N) ++c[ a[i] ];
  int marker = (c[1] >= 1) ? 1 : 2;
  ll s = 0;
  for (int i = 0; i < N; i++) {
    int w = choose_mod2(N-1, i);
    if (a[i] == marker) {
      s += w;
    }
  }
  return s % 2 ? marker : 0;
}


int main2() {
  int N = nextInt();
  string s; cin >> s;
  REP(i, N) a[i] = s[i] - '0' - 1;

  // int ans = solve_small(N);
  int ans = solve(N);
  cout << ans << endl;

  return 0;
}

int main() {

  for (int i = 2; i < SIZE; i *= 2) {
    for (int j = 1; i * j < SIZE; j++) {
      fact[i * j]++;
    }
  }
  for (int i = 2; i < SIZE; i++) fact[i] += fact[i-1];

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 14340
<?php
/*
  http://abc044.contest.atcoder.jp/tasks/abc044_b
*/

function is_even($value) {
  return $value % 2 === 0 ? true : false;
}

$stdin = trim(fgets(STDIN));
$str_hash = [];

foreach (str_split($stdin) as $key => $value) {
  if (isset($str_hash[$value])) {
    $str_hash[$value] += 1;
  } else {
    $str_hash[$value] = 1;
  }
}

$is_beautiful = true;
foreach ($str_hash as $key => $value) {
  if (!is_even($value)) {
    $is_beautiful = false;
    break;
  }
}

echo $is_beautiful ? "Yes" : "No";

?>


Measured memory_bytes: 4088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;

	cin >> N;

	int ans = N * N * N;

	printf("%d",ans);

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e17 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int cnt(int n) {
	int res = 0;
	for (int i = 1; i <= n; ++ i)
		if (n % i == 0)
			++res;
	return res;
}

int main () {
    to_pray();
    
    
    int n;
   	cin >> n;
   	
   	int sum = 0;
   	
   	for (int i = 1; i <= n; ++ i) {
   		if (cnt(i) == 8 and i & 1)
   			++sum;
   	}
   	cout << sum;
    
    //eprllf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

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

P = []

for _ in range(N):
    s,t = input().split()
    t = int(t)
    P.append([s,t])

X = input()

end_index = -1

for i in range(N):
    p = P[i]

    if p[0]==X:
        end_index = i
        break

count = 0

for i in range(end_index+1, N, 1):
    count = count + P[i][1]
print(count)

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

int main(){
  int N;
  cin >> N;
  constexpr int INF = 1e9;
  vector<int> A(N+2,-INF);
  for(int i = 0; i < N; ++i) cin >> A[i+1];
  int M = N+2;
  vector<int> F = A, B = A;
  for(int i = 1; i < M; ++i) F[i] = max(F[i],F[i-1]);
  for(int i = M-2; i >= 0; --i) B[i] = max(B[i],B[i+1]);
  for(int i = 0; i < N; ++i){
    cout << max(F[i],B[i+2]) << endl;
  }

}


Measured memory_bytes: 3968
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x=I()
a=x%100
b=x//100
if a>b*5:
    print("0")
else:
    print("1")

Measured memory_bytes: 65432
import sys
from collections import deque

input = sys.stdin.readline


def bfs(G, v, p, counter):
    queue = deque([(v, p)])
    while queue:
        v, p = queue.popleft()
        for c in G[v]:
            if c == p:
                continue
            counter[c] += counter[v]
            queue.append((c, v))


def main():
    N, Q = map(int, input().split())

    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        counter[p] += x

    bfs(G, 0, -1, counter)

    print(*counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61780
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    h[0]--;
    for(int i = 1; i < n; i++) {
        if(h[i - 1] < h[i]) h[i]--;
    }

    for(int i = 0; i < n - 1; i++) {
        if(h[i] > h[i + 1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(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)

using namespace std;
int n;
vector<string> ud;
vector<map<int,LL> >memo;
//memo[ind][down]
const LL p=1000000007;
LL solve(int ind,int up){
  if(up<0) return 0;
  if(ind==n)
    if(up==0) return 1;
    else return 0;
  if(memo[ind].count(up)) return memo[ind][up];
  if(ud[ind]=="-") return solve(ind+1,up);
  if(ud[ind]=="U"){
    LL answer=(up+1)*solve(ind+1,up+1);
    answer+=up*solve(ind+1,up);//baton
    answer%=p;
    memo[ind][up]=answer;
  }
  if(ud[ind]=="D"){
    LL answer=up*solve(ind+1,up-1);
    answer+=up*solve(ind+1,up);//baton
    answer%=p;
    memo[ind][up]=answer;
  }
  return memo[ind][up];
}

int main(void)
{
  cin >> n;
  ud.resize(n);
  memo.assign(n,map<int,LL>());
  REP(i,n) cin >> ud[i];
  cout << solve(0,0) << endl;
  return 0;
}

Measured memory_bytes: 3792
#include <iostream>

using namespace std;
int main(){
    int N;
    char S[300000];
    scanf("%d", &N);
    int w = 0;
    int e = 0;
    for(int i=0; i<N; i++){
        scanf(" %c", &S[i]);
        if(S[i] == 'W'){
            w++;
        }else{
            e++;
        }
    }

    int min = 300000;
    int wc_west=0;
    int ec_west=0;
    int wc_east=0;
    int ec_east=0;
    for(int i=0; i<N; i++){
        wc_east = w - wc_west;
        ec_east = e - ec_west;
        int sum = 0;
        if(S[i] == 'W'){
            wc_east = w - wc_west - 1;
            ec_east = e - ec_west;
            sum = wc_west + ec_east;
            wc_west++;
        }else{
            wc_east = w - wc_west;
            ec_east = e - ec_west - 1;
            sum = wc_west + ec_east;
            ec_west++;
        }
        if(sum < min){
            min = sum;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 330000
using namespace std;
inline char gc(){
    /*static char now[1<<16],*T,*S;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;*/return getchar();
}
inline int read(){
    int x=0;char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
struct node{
    int l,r;
}line[N];
inline bool cmp(node a,node b){return a.l<b.l;}
struct node1{
    int left,right,v;
}tree[N*20];
int num,n,m,root[N];
inline void insert1(int &x,int l,int r,int p){
    tree[++num]=tree[x];x=num;tree[x].v++;if (l==r) return;
    int mid=l+r>>1;if (p<=mid) insert1(tree[x].left,l,mid,p);else insert1(tree[x].right,mid+1,r,p);
}
inline int query(int rt1,int rt2,int l,int r,int l1,int r1){
    if (l1<=l&&r1>=r) return tree[rt2].v-tree[rt1].v;
    int mid=l+r>>1;int tmp=0;if (l1<=mid) tmp+=query(tree[rt1].left,tree[rt2].left,l,mid,l1,r1);
    if (r1>mid) tmp+=query(tree[rt1].right,tree[rt2].right,mid+1,r,l1,r1);return tmp;
}
int main(){
    n=read();m=read();
    for (int i=1;i<=n;++i) line[i].l=read(),line[i].r=read();
    sort(line+1,line+n+1,cmp);int tot=0;printf("%d\n",n);
    for (int i=1;i<=m;++i){root[i]=root[i-1];
    while(line[tot+1].l==i) insert1(root[i],1,m,line[tot+1].r),++tot;}
    for (int len=2;len<=m;++len){
        int j=len,tmp=0,now=m%len;now=m-now;
        for (;j<=m;j+=len) tmp+=query(root[j-len],root[j-1],1,m,j-len+1,j-1);
        if(now<m) tmp+=query(root[now],root[m],1,m,now+1,m);
        printf("%d\n",n-tmp);
    }
    return 0;
}

Measured memory_bytes: 68608
A, B, C = map(int, input().split())

res = -1
for i in range(10 ** 6):
    tmp1 = B//2 + C//2
    tmp2 = A//2 + C//2
    tmp3 = B//2 + C//2
    if A%2 == 1 or B%2 == 1 or C%2 == 1:
        res = i
        break
    A = tmp1
    B = tmp2
    C = tmp3
    
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 100000
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

vector< int > graph[3 * MAX_N];

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  int u[m], v[m];
  for(int i = 0; i < m; i++){
    cin >> u[i] >> v[i];
    --u[i]; --v[i];
  }
  int s, t;
  cin >> s >> t;
  --s; --t;

  for(int i = 0; i < m; i++){
    int u0 = 3 * u[i], u1 = u0 + 1, u2 = u0 + 2;
    int v0 = 3 * v[i], v1 = v0 + 1, v2 = v0 + 2;
    graph[u0].push_back(v1);
    graph[u1].push_back(v2);
    graph[u2].push_back(v0);
  }

  int dist[3 * n];
  queue< int > que;
  fill(dist, dist + 3 * n, INF_INT);
  dist[3 * s] = 0;
  que.push(3 * s);
  while(!que.empty()){
    int vv = que.front(); que.pop();
    for(int w: graph[vv]){
      if(dist[w] == INF_INT){
        dist[w] = dist[vv] + 1;
        que.push(w);
      }
    }
  }

  if(dist[3 * t] != INF_INT) cout << (dist[3 * t] / 3) << endl;
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 18688
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	sc.close();
    	long ans = 0;
    	for(int i = 1; i <= N; i++){
    		if(i % 3 != 0 && i % 5 != 0){
    			ans+=i;
    		}
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
typedef pair<ll, l_l> lll;

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    map<ll, ll> mp;
    for(int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        ans += mp[A-i];
        mp[-A-i]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26124
#include <iostream>
#include <string>

using namespace std;

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

	cin >> a >> b >> c;

	if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

int main() {
	int m1,d1,m2,d2;
	cin>>m1>>d1>>m2>>d2;
	unordered_map<int,int> mp;
	mp[1]=31;mp[2]=28;mp[3]=31;mp[4]=30;mp[5]=31;mp[6]=30;mp[7]=31;mp[8]=31;mp[9]=30;mp[10]=31;mp[11]=30;mp[12]=31;
	cout<<(mp[m1]==d1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a [9] = {1,400,800,1200,1600,2000,2400,2800,3200};
int getC(int x){
	int i=0;
	while(i<9){
		if(a[i]>x) return i;
		i++;
	}
	return i;
}
int b[9];
int main(){
	int N;
	int x;cin >> N;
	for(int i=0;i<N;++i){
		cin >> x;
		b[getC(x)]++;
	}
	int mi=0,mx=0;
	for(int i=0;i<9;++i){
		if(b[i]) ++mi,++mx;
	}
	mx += b[9];
	cout << max(mi,1) << " " << mx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  vector<int64_t> h(n);
  int64_t i;
  for(i=0;i<n;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  int64_t mini=100000000000;
  for(i=0;i<n-k+1;i++){
    int64_t a=h.at(i+k-1)-h.at(i);
    mini=min(a,mini);
  }
  cout << mini;
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	int n, a, b;
	cin >> n >> a >> b;

	string S;
	cin >> S;

	int as = 0, bs = 0;

	EACH(c, S){
		//cout << as << " " << bs << endl;
		if(c == 'a'){
			if(as + bs < a + b){
				as++;
				cout << "Yes" << endl;
				continue;
			}
		}
		else if(c == 'b'){
			if(as + bs < a + b && bs < b){
				bs++;
				cout << "Yes" << endl;
				continue;
			}
		}
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int N, M;

int main() {
    cin >> N >> M;
    map<int, vector<int>> B;
    priority_queue<int> Q;
    
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        B[a].push_back(b);
    }
    long long ans = 0;
    for (int m = 1; m < M + 1; m++) {
        vector<int> A = B[m];
        for (int i = 0; i < A.size(); i++) {
            Q.push(A[i]);
        }
        if (Q.size() > 0) {
            ans += 1LL * Q.top();
            Q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10880
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

/*long rec(vector<int> adj[], int n, int id, bool vis[], long mem[])
{
  if(id==n+1)
    return 0;
  if(vis[id])
    return mem[id];
  if(mem[id]!=-1)
    return mem[id];
  vis[id]=true;
  long ans=-1;
  for(int i=0;i<adj[id].size();i++)
  {
    long a=rec(adj,n,adj[id][i],vis,mem);
    ans=max(ans,a);
  }
  mem[id]=ans+1;
  return mem[id];
}*/

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> adj[n+1];
  int indegree[n+1]={0};
  for(int i=0;i<m;i++)
  {
    int x,y;
    cin>>x>>y;
    adj[x].push_back(y);
    indegree[y]++;
  }
  /*bool vis[n+1];
  for(int i=0;i<=n;i++)
	vis[i]=false;
  long mem[n+1];
  for(int i=0;i<=n;i++)
    mem[i]=-1;
  long mx=0;
  for(int i=1;i<=n;i++)
  {
  	if(!vis[i])
  	  mx=max(mx,rec(adj,n,i,vis,mem));
  }
  cout<<mx;*/
  
  
  bool vis[n+1]={0};
  long dp[n+1]={0};
  long ans=0;
  for(int i=1;i<=n;i++)
  {
    if(vis[i] or indegree[i]!=0)
      continue;
    vis[i]=true;
    queue<int> q;
    q.push(i);
    dp[i]=0;
    while(!q.empty())
    {
      int id=q.front();
      q.pop();
      vis[id]=true;
      for(int j=0;j<adj[id].size();j++)
      {
        dp[adj[id][j]]=max(dp[adj[id][j]],dp[id]+1);
        indegree[adj[id][j]]--;
        if(indegree[adj[id][j]]==0)
          q.push(adj[id][j]);
        ans=max(ans,dp[adj[id][j]]);
      }    
    }
  }
  cout<<ans;
}

Measured memory_bytes: 7040
#include<stdio.h>
#include<string.h>
int N,M,R,Q,t,n,m,s,D[10001][1500],L[1001],r,i,j,f;
int main()
{
	for(;scanf("%d%d%d",&N,&M,&R),N;)
	{
		memset(D,0,sizeof(D));
		memset(L,0,sizeof(L));
		for(;R--;)
		{
			scanf("%d%d%d%d",&t,&n,&m,&s);
			if(s)L[n]=t;
			else for(i=L[n];i<t;i++)D[m][i]=1;
		}
		for(scanf("%d",&Q);Q--;)
		{
			scanf("%d%d%d",&s,&t,&m);
			for(i=s,r=0;i<t;i++)
				if(D[m][i])r++;
			printf("%d\n",r);
		}
	}
	return 0;
}

Measured memory_bytes: 59212
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };


int main() {
	int n,i,j;
	cin >> n;
	string s[2];
	cin >> s[0] >> s[1];
	ll ans;
	bool flag;
	if (s[0][0] == s[1][0]) {
		ans = 3;
		flag = true;
		i = 1;
	}else{
		ans = 6;
		flag = false;
		i = 2;
	}
	while (i<s[0].size()) {
		if (flag) {
			if (s[0][i] == s[1][i]) {
				ans = (ans * 2) % MOD;
				flag = true;
				i++;
			}
			else {
				ans = (ans * 2) % MOD;
				flag = false;
				i += 2;
			}
		}
		else {
			if (s[0][i] == s[1][i]) {
				flag = true;
				i++;
			}
			else {
				ans = (ans * 3) % MOD;
				flag = false;
				i += 2;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
int n, ans;
int a[107];

int main() {
	cin >> n;
	int sum = 0;
	double aver;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	aver = sum * 1.0 / n;
	double minT = Inf * 1.0;
	for(int i = 0; i < n; i++) {
		double dd = fabs(a[i] * 1.0 - aver);
		if(dd < minT) minT = dd, ans = i;
	}
	cout << ans << endl;
}

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

int main ()
{
    int n;
    while (cin >> n, n) {
        vector<string> name(n);
        vector<int> price(n);
        vector<int> sold(n);
        vector<int> times(n);
        vector<int> m(n);
        vector<int> count(n);
        for (int i = 0; i < n; i++) {
            int a, b, c, d, e;
            cin >> name[i] >> price[i] >> a >> b >> c >> d >> e >> count[i] >> sold[i] >> m[i];
            times[i] = a + b + c + (d + e) * m[i]; 
        }

        vector<pair<double,string> > res;
        for (int i = 0; i < n; i++) {
            double p = (double)(m[i] * sold[i] * count[i]- price[i]) / (double)times[i];
            res.push_back(pair<double,string>(-p, name[i]));
        }

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

        for (int i = 0; i < n; i++) {
            cout << res[i].second << endl;
        }
        cout << "#" << endl;
    }

    return 0;
}

Measured memory_bytes: 1228
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if 1 in a:
  ans=[1,0]
else:
  ans=[1,1]

@lru_cache(maxsize=None)
def cnt(x):
  if x<2:
    return ans[x]
  if x in a:
    return 0
  else:
    return (cnt(x-1)+cnt(x-2))%MOD

print(cnt(n))

Measured memory_bytes: 129076
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll L = 0;
	ll P = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 1;
	ll dist1 = 0;
	ll dist2 = 0;
	ll now = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	
	
	
	cin >> A >> B >> C;
	
	
	if((A<=C)&&(B>=C))
	cout << "Yes" << endl;
	else
		cout << "No" << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);
    int ans=0,id;
    int N,M;
    int a[52],b[520],c[52],d[52];

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,N)cin>>a[i]>>b[i];
    REP(i,M)cin>>c[i]>>d[i];
    REP(i,N){
        REP(j,M){
            int temp=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(j==0){ans=temp;id=j;}
            else{
                if(temp<ans){
                    ans=temp;id=j;
                }
            }
        }
        cout<<id+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
int tab[MAX];
int dp[MAX];
int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> tab[i];
        dp[i] = 1e9 + 5;
    }
    dp[1] = 0;
    dp[0] = 1e9;
    for(int i = 2; i <= n; i++)
        for(int j = 1; j <= k; j++){
            if(i - j < 0)
                break;
            dp[i] = min(dp[i-j] + abs(tab[i-j] - tab[i]), dp[i]);
        }
    cout << dp[n] << '\n';
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    int n = s.size();
    map<char, int> cnt;
    for(auto c : s) cnt[c]++;
    string ans = "YES";
    for(auto kv : cnt){
        if(kv.second > (n+2)/3) ans = "NO";
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}



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

int main(){
	int N;
	int xp[200], yp[200];
	int dx[] = {-1, 0, 1, 0};
	int dy[] = { 0, -1, 0, 1};
	while(cin >> N, N){
		int idx = 1;
		xp[0] = 0;
		yp[0] = 0;
		int left = 0;
		int right = 0;
		int top = 0;
		int bottom = 0;
		int n, d;
		for(int i = 1; i < N; i++){
			cin >> n >> d;
			xp[i] = xp[n] + dx[d];
			yp[i] = yp[n] + dy[d];
			left = min(left, xp[i]);
			right = max(right, xp[i]);
			top = max(top, yp[i]);
			bottom = min(bottom, yp[i]);
		}
		cout << (right - left + 1) << " " << (top - bottom + 1) << endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for (int i=0;i<n;i++)d[i] = INFTY;
  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front();
    q.pop();
    for(int v = 0;v< n;v++){
      if(M[u][v] == 0)continue;
      if(d[v] != INFTY)continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " "<<((d[i] == INFTY)?(-1) : d[i]) << endl;
  }
}

int main(){
  int u,k,v;

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

    for(int i=0;i<n;i++){
      cin >> u >> k;
      u--;
      for(int j=0;j<k;j++){
	cin >> v;
	v--;
	M[u][v] = 1;
      }
    }

    bfs(0);
    return 0;
  }



Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define CHECK cout<<"ok"<<endl
#define ECHO(x) cout<<x<<endl
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int N;
  cin>>N;
  LL a[N];
  map<LL, int> count;
  REP(i, N){
    cin>>a[i];
    ++count[a[i]];
  }
  if(N==1){
    cout<<0<<endl;
    return 0;
  }

  sort(a, a+N);

  LL w, x;
  int ans=0;
  for(int i=N-1; i>-1; --i){
    if(count[a[i]]==0) continue;
    w=1;
    for(int j=0; j<40; ++j){
      w*=2;
      if(lower_bound(a, a+N, w-a[i])==upper_bound(a, a+N, w-a[i])) continue;
      x = *lower_bound(a, a+N, w-a[i]);
      if(x==a[i] && count[x]>=2){
        ++ans;
        count[x]=count[x]-2;
        break;
      }
      else if(x!=a[i] && count[x]>=1 && count[a[i]] >= 1){
        ++ans;
        --count[x];
        --count[a[i]];
        break;
      }
    }
  }

  cout<<ans<<endl;



  return 0;
}


Measured memory_bytes: 14336
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    hn = input[0].split(" ");
    aaa = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var h = parseInt(hn[0], 10);
    var n = parseInt(hn[1], 10);

    var total= 0;
    for(i=0;i<n;i++){
        var a = parseInt(aaa[i], 10);
        total+=a;
        if(h<=total){console.log('Yes');
                     break;}
     // else{console.log('No');}
    }
  if(i>=n){console.log('No');}



}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


public class my
{
	public static void Main()
	{
		var w = my.GetInt();
		var n = my.GetInt();

		var A = Enumerable.Range(1, w).ToArray();

		for(int i = 0; i < n; i++) {
			var B = my.GetIntArray(',');
			
			my.Swap(A, B[0]-1, B[1]-1);
		}
		
		foreach(var a in A) {
			Console.WriteLine(a);
		}
	}

	private static void Swap(ref string a, ref string b) 
	{
		string tmp = a;
		a = b;
		b = tmp;
	}
	
	private static void Swap(ref int a, ref int b) 
	{
		int tmp = a;
		a = b;
		b = tmp;
	}
	
	private static void Swap(int[] A, int i, int j) 
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}
		
	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');
		
		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 9500
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int [] xArray = new int [n];
		int [] yArray = new int [m];
		int xmax = -100;
		int ymin = 100;
		for(int i = 0; i < n; i++) {
			xArray[i] = sc.nextInt();
			if(xArray[i] > xmax) xmax = xArray[i];
		}
		for(int i = 0; i < m; i++) {
			yArray[i] = sc.nextInt();
			if(yArray[i] < ymin) ymin = yArray[i];
		}
		boolean judge = false;//合意不成立＝戦争
		for(int i = x+1; i <= y; i++) {//条件達成
			if(xmax < i && i <= ymin)judge = true;//合意成立＝No戦争
		}
		if(judge) System.out.println("No War");
		else System.out.println("War");
		
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdbool.h>

int bubbleSort(int A[],int N){
	int tag;
	int sw=0;
	bool flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				tag=A[j];
				A[j]=A[j-1];
				A[j-1]=tag;
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void){
	int N,sw;
	int A[100];
	
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	
	sw=bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i>0){
			printf(" ");
		}
		printf("%d",A[i]);
	}
	
	printf("\n");
	printf("%d\n",sw);
	return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define N 100006
#define inf 100000007
using namespace std;
int n,b[N];char a[N];
inline int read()
{
	int x=0,c=getchar();while(c<48)c=getchar();
	while(c>47)x=x*10+c-48,c=getchar();return x;
}
void print(int x)
{
	if(x>9LL)print(x/10LL);putchar(x%10LL+48LL);
}
int main()
{
	n=read();
	scanf("%s",a+1);
	for(int i=0;i<=1;i++)
		for(int j=0;j<=1;j++){
			b[1]=i;b[2]=j;
			for(int k=3;k<=n;k++){
				if(b[k-1]==0){
					if(a[k-1]=='o')b[k]=b[k-2];
					else b[k]=b[k-2]^1;
				}else{
					if(a[k-1]=='o')b[k]=b[k-2]^1;
					else b[k]=b[k-2];
				}
			}
			bool f=1;
			if(b[n]==0){
				if(a[n]=='o'&&b[n-1]!=b[1])f=0;
				if(a[n]=='x'&&b[n-1]==b[1])f=0;
			}else{
				if(a[n]=='o'&&b[n-1]==b[1])f=0;
				if(a[n]=='x'&&b[n-1]!=b[1])f=0;
			}
			if(b[1]==0){
				if(a[1]=='o'&&b[n]!=b[2])f=0;
				if(a[1]=='x'&&b[n]==b[2])f=0;
			}else{
				if(a[1]=='o'&&b[n]==b[2])f=0;
				if(a[1]=='x'&&b[n]!=b[2])f=0;
			}
			if(f){
				for(int i=1;i<=n;i++)if(b[i]==0)printf("S");else printf("W");
				return 0;
			}
		}
	puts("-1");
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long D = sc.nextLong();
        int count = 0;
        for (int i = 0; i < N; i++) {
            long X = sc.nextLong();
            long Y = sc.nextLong();
            double root = Math.sqrt(X*X+Y*Y);
            if (root <= D) {
                count++;
            }
        }
        System.out.println(count);
    }
}

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

using namespace std;

struct edge
{
	int v,nxt;
}e[250];

int ecnt,head[105];

void adde(int u,int v)
{
	e[++ ecnt].v = v;
	e[ecnt].nxt = head[u];
	head[u] = ecnt;
}

int maxn[105];
int sz[105],depx[105];
long long vl[105];
int fk;

void dfs(int pos,int dep,int lst)
{
	fk = max(fk,dep);
	depx[pos] = dep;
	sz[pos] = 0;
	for(int i = head[pos];i;i = e[i].nxt)
	{
		int v = e[i].v;
		if(v != lst)
		{
			dfs(v,dep + 1,pos);
			sz[pos] ++;
		}
	}
	maxn[dep] = max(maxn[dep],sz[pos]);
}

int uu[105],vv[105];
int n;

int main()
{
	scanf("%d",&n);
	for(int i = 1;i < n; ++ i)
	{
		scanf("%d%d",&uu[i],&vv[i]);
		adde(uu[i],vv[i]),adde(vv[i],uu[i]);
	}
	long long ans = 1000000000000000000ll;
	long long shi = 1050;
	for(int i = 1;i <= n; ++ i)
	{
		fk = 0; memset(maxn,0,sizeof(maxn));
		dfs(i,0,0);
		if(fk > shi) continue;
		vl[fk - 1] = maxn[fk - 1];
		for(int j = fk - 2;j >= 0; -- j)
			vl[j] = vl[j + 1] * maxn[j];
		if(fk < shi) shi = fk,ans = vl[0];
		else ans = min(ans,vl[0]);
	}
	for(int i = 1;i < n; ++ i)
	{
		fk = 0; memset(maxn,0,sizeof(maxn));
		dfs(uu[i],0,vv[i]);
		dfs(vv[i],0,uu[i]);
		if(fk > shi) continue;
		vl[fk - 1] = maxn[fk - 1];
		for(int j = fk - 2;j >= 0; -- j)
			vl[j] = vl[j + 1] * maxn[j];
		if(fk < shi) shi = fk,ans = vl[0] * 2;
		else ans = min(ans,vl[0] * 2);
	}
	printf("%lld %lld\n",shi + 1,ans);
}

Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main () {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let x: u32 = buf.trim().parse().unwrap();
    println!("{:032b}", x);
    println!("{:032b}", !x);
    println!("{:032b}", x << 1);
    println!("{:032b}", x >> 1);
}


Measured memory_bytes: 5020
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210000;

vector<tuple<ll, ll, ll>> vv;

int n;
ll x;

ll sma;

ll get(tuple<ll, ll, ll> a) {
	ll b, l, u;
	tie(b, l, u) = a;
	return b * l + (x - b) * u;
}

ll sm[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		ll b, l, u;
		cin >> b >> l >> u;
		sma += b * l;
		vv.emplace_back(b, l, u);
	}
	sort(ALL(vv), [] (tuple<ll, ll, ll> a, tuple<ll, ll, ll> b) -> bool {
				return get(a) > get(b);
			});
	for (int i = 0; i < n; ++i)
		sm[i + 1] = sm[i] + get(vv[i]);
	ll l = 0;
	ll r = x * n;
	while (r != l) {
		ll m = (l + r) >> 1;
		ll ans = 0;
		int go = min(ll(n) - 1, m / x);
		for (int i = 0; i < n; ++i) {
			ll now = sm[go];
			if (i < go)
				now = sm[go + 1] - get(vv[i]);
			ll lf = m - go * x;
			ll b, l, u;
			tie(b, l, u) = vv[i];
			now += l * min(b, lf);
			if (lf > b)
				now += (lf - b) * u;
			ans = max(ans, now);
		}
		if (ans >= sma)
			r = m;
		else
			l = m + 1;
	}
	cout << r << "\n";
	return 0;
}




Measured memory_bytes: 4980