akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

void solution()
{
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> as(n);
    vector<int> bs(m);
    cin >> as >> bs;

    vector<int64_t> sa(n);
    sa[0] = as[0];
    for(int i = 1; i < n; ++i){
        sa[i] = sa[i-1] + as[i];
    }

    vector<int64_t> sb(m);
    sb[0] = bs[0];
    for(int i = 1; i < m; ++i){
        sb[i] = sb[i-1] + bs[i];
    }

    int cb = m;
    int count = 0;
    for(int ca = 0; ca <= n; ++ca){
        int64_t t = ca > 0 ? k - sa[ca-1] : k;
        if(t < 0){
            break;
        }
        for(; cb > 0; --cb){
            if(t >= sb[cb-1]){
                count = max(count, ca + cb);
                break;
            }
        }
        count = max(count, ca);
    }
    cout << count << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 7948
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();
	
	int H, W; cin >> H >> W;
	vector<vector<string>>vec(H, vector<string>(W));
	rep(i, 0, H)rep(j, 0, W)cin >> vec[i][j];
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (vec[i][j] == "snuke") {
				char ch = 'A';
				ch += j;
				cout << ch << i + 1 << "\n";
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 1e5+9;
using namespace std;
deque<pair<int, long long> > q;
int k;
bool vis[N];

int main() {
  scanf("%d", &k);
  q.push_back({1, 1});
  while(!q.empty()) {
    pair<int, long long> tp = q.front(); q.pop_front();
    if(!tp.first) {
      printf("%d\n", tp.second);
      break;
    }
    if(vis[tp.first]) continue;
    vis[tp.first] = 1;
    q.push_front({tp.first*10%k, tp.second});
    q.push_back({(tp.first+1)%k, tp.second+1});
  }
  return 0;
}


Measured memory_bytes: 2048
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
   
        int ans = calcNum(a, b);  
      
		//出力
		Console.WriteLine(ans);
	}
  
    static int calcNum(int A, int B)
    {
        int rNum = 0;

        // Aの値を確認(四捨五入)
        // Aが2の場合minAは25、maxAは37
        // Aが8の場合minAは100、maxAは112
        // Aが19の場合minAは238、maxAは249
        int minA = (int)Math.Floor(A / 0.08 + 0.5);
        int maxA = (int)Math.Floor(((A+1) / 0.08) + 0.5) - 1;

        // Bの値を確認(四捨五入)
        // Bが2の場合minAは20、maxAは37
        // Bが10の場合minBは100、maxBは109
        // Bが99の場合minBは990、maxBは999
        int minB = (int)Math.Floor(B / 0.1 + 0.5);
        int maxB = (int)Math.Floor(((B+1) / 0.1) + 0.5) - 1;

        // 最小値の範囲で比較
        if(minA <= minB)
        {
            if(minB <= maxA)
            {
                rNum = minB;
            }
            else
            {
                rNum = -1;
            }
        }
        else
        {
            if(minA <= maxB)
            {
                rNum = minA;
            }
            else
            {
                rNum = -1;
            }
        }

        return rNum;
    }

}

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

int dx[5] = {0,0,0,1,-1};
int dy[5] = {0,1,-1,0,0};
vector<vector<int> > solve(vector<vector<int> > m_){
	vector<vector<int> > ans = m_;
	
	// 0..1023 ツづδ仰ーツプ, iツづ個各ツビツッツトツづ債暗ェツ氾板湘」ツづ個猟アツ子ツづ個督鳴づ陛サツづーツ表ツつキ
	for(int i=0 ; i < 1024 ; i++ ){
		vector<vector<int> > m = m_;
		int d[10][10] = {0};
		
		for(int x=0 ; x < 10 ; x++ ){
			// i ツづ警ツ氾板姪堋づ個ビツッツトツづーツ偲ヲツづィツ出ツつキ
			if( i & (1 << x) ){
				d[0][x] = 1;
				for(int j=0 ; j < 5 ; j++ ){
					int mx = x + dx[j];
					int my = 0 + dy[j];
					if( mx < 0 || my < 0 || mx >= 10 || my >= 10 ) continue;
					m[my][mx] = (m[my][mx])? 0 : 1 ;
				}
			}
		}
		
		for(int y=1 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				if( m[y-1][x] == 1 ){
					d[y][x] = 1;
					for(int j=0 ; j < 5 ; j++ ){
						int mx = x + dx[j];
						int my = y + dy[j];
						if( mx < 0 || my < 0 || mx >= 10 || my >= 10 ) continue;
						m[my][mx] = (m[my][mx])? 0 : 1 ;
					}
				}
			}
		}
		
		bool flag = true;
		for(int y=0 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				if( m[y][x] ){
					flag = false;
					break;
				}
			}
		}
		if( flag ){
			for(int y=0 ; y < 10 ; y++ ){
				for(int x=0 ; x < 10 ; x++ ){
					ans[y][x] = d[y][x];
				}
			}
			break;
		}
	}
	return ans;
}

int main(){
	int n;
	cin >> n;
	for( ; n-- ; ){
		vector<vector<int> > m(10);
		
		for(int y=0 ; y < 10 ; y++ ){
			vector<int> v(10);
			m[y] = v;
			
			for(int x=0 ; x < 10 ; x++ ){
				cin >> m[y][x];
			}
		}
		vector<vector<int> > ans = solve( m );
		for(int y=0 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				cout << ans[y][x];
				if( x != 9 ) 
					cout << " ";
			}
			cout << endl;
		}
	}
}

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

int main() {
    int n, x = 1;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if(a == x)
            x++;
    }
    cout << (x > 1 ? n - x + 1 : -1) << endl;
    return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> c(n-1), s(n-1), f(n-1);
  for(int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
  for(int i = 0; i < n-1; i++){
    int time = 0;
    for(int j = i; j < n-1; j++){
      if(time < s[j]) time = s[j];
      else if(time % f[j]) time = time + f[j] - time%f[j];
      time += c[j];
    }
    cout << time << endl;
  }
  cout << 0 << endl;
}

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

int main()
{
    string o , e;
    cin>>o>>e;
    string ans;

    int index1 =0 , index2 =0;
    int len = o.length() + e.length();
    for(int i=1;i<=len;i++)
    {
        if( i%2==1)
        {
            ans.push_back(o[index1]);
            index1++;
        } else
        {
            ans.push_back( e[index2]);
            index2++;
        }
    }
    cout<<ans;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 11;
const ll INF = 1ll << 60;

ll n,k;

int main(){
  cin >> n >> k;
  if(k == 1){
    cout << 0 << endl;
    return 0;
  }
  if(n < k){
    cout << 1 << endl;
    return 0;
  }
  cout << n-k << endl;
}


Measured memory_bytes: 256
def main():
    s = input()
    #print(s[:2], s[2:4])
    if (int(s[:2]) > 12 or int(s[:2]) == 0)and (int(s[2:4]) >= 1 and int(s[2:4]) <= 12) :
        print("YYMM")
    elif (int(s[2:4]) > 12 or int(s[2:4]) == 0) and (int(s[:2]) >=1 and int(s[:2]) <=12) :
        print("MMYY")
    elif (int(s[:2]) >= 1 and int(s[:2])) <= 12 and (int(s[2:4]) >=1 and int(s[2:4]) <= 12) :
        print("AMBIGUOUS")
    else:
        print("NA")

if __name__ == "__main__":
    main()


Measured memory_bytes: 61856
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> struct BinaryIndexedTree {
    vector<T> node;
    int n;
    BinaryIndexedTree(int n) : n(n) { node.assign(++n, 0); }
    void add(int k, T x) {
        for (++k; k < n; k += k & -k) {
            node[k] += x;
        }
    }
    T sum(int k) {
        T res = 0;
        for (++k; k > 0; k -= k & -k) {
            res += node[k];
        }
        return res;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), sum(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    vector<ll> v;
    v.push_back(0);
    for (int i = 1; i <= n; i++) {
        v.push_back(sum[i] - k * i);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    BinaryIndexedTree<ll> bit(v.size() + 1);
    bit.add(lower_bound(all(v), 0) - v.begin(), 1);
    ll res = 0;
    for (int i = 1; i <= n; i++) {
        int t = lower_bound(all(v), sum[i] - k * i) - v.begin();
        res += bit.sum(t);
        bit.add(t, 1);
    }
    cout << res << endl;
}


Measured memory_bytes: 6124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = a; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)

using namespace std;
using namespace __gnu_pbds; 

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    return a.ss < b.ss;
}

typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 

int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    vll v(n);
    from(i,n)cin>>v[i];
    ll ar[n];
    ar[0]=0;
    ar[1]=abs(v[1]-v[0]);
    for(ll i=2;i<n;i++){
        ar[i]=min(ar[i-1]+abs(v[i]-v[i-1]),ar[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<ar[n-1];
}    

Measured memory_bytes: 4736
N, M = map(int, input().split())
kslist = []
for i in range(M):

    kslist.append(list(map(lambda x: int(x)-1, input().split()))[1:])

plist = list(map(int, input().split()))


ans = 0

for i in range(1 << N):
    for r in range(M):
        on_sum = 0
        for j in range(N):
            if i >> j & 1 and j in kslist[r]:
                on_sum += 1
        if on_sum % 2 != plist[r]:
            break
    else:
        ans += 1


print(ans)


Measured memory_bytes: 40560
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() {

    int64_t N;
    std::cin >> N;

    int64_t max = 0;
    std::map<std::string, int64_t> votes;
    for (int64_t i = 0; i < N; ++i) {
        std::string S;
        std::cin >> S;
        if (votes.count(S) == 0) {
            votes[S] = 1;
        } else {
            votes[S]++;
        }
        if (max < votes[S]) {
            max = votes[S];
        }
    }

    for (auto& vote : votes) {
        if (vote.second != max) continue;
        std::cout << vote.first << std::endl;
    }

    return 0;
}

Measured memory_bytes: 25216
def main():
    n, k = [int(x) for x in input().split(' ')]
    arr = [0] * 100001
    for _ in range(n):
        a, b = [int(x) for x in input().split(' ')]
        arr[a] += b
    foo = 0
    for i, e in enumerate(arr):
        foo += e
        if (foo >= k):
            print(i)
            break

main()


Measured memory_bytes: 5744
N = int(input())
str_to_point = {}
for i in range(N):
    val = input()
    if val in set(list(str_to_point.keys())):
        str_to_point[val] += 1
    else:
        str_to_point[val] = 1

M = int(input())
for i in range(M):
    val = input()
    if val in set(list(str_to_point.keys())):
        str_to_point[val] -= 1
    else:
        str_to_point[val] = -1

ans = max(str_to_point.values())
if ans < 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define M 1000000007

#define pb push_back
#define fs first
#define se second
using namespace std;
// ll changeI(ll a)
// {
//     ll k=1;
//     ll st=0;
//     while(a)
//     {
//         st=(st%D+((a%10)*(k%D))%D)%D;
//         a/=10;
//         k*=100;
//     }
//     return st;
// }
 
long long powe(ll a, ll p , ll r)
{
    if(p==0)
        return 1;
    else if(p==1)
        return a;
    ll q=powe(a,p/2,r)%r;
    q= ((q%r)*(q%r))%r;
    if(p%2 == 1)
    {
        q = ((q%r)*(a%r))%r;
    }
    return q;
 
}
ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
pair<pair<ll,ll>,ll> maxSubArraySum(vector<ll>a, int size) 
{ 
    ll max_so_far = LLONG_MIN, max_ending_here = 0, 
       start =0, end = 0, s=0; 
    ll p=0;
    for (ll i=0; i< size; i++ ) 
    { 
        max_ending_here += a[i]; 
  
        if (max_so_far < max_ending_here) 
        { 
            max_so_far = max_ending_here; 
            start = s; 
            end = i; 
        } 
  
        if (max_ending_here < 0) 
        { 
            max_ending_here = 0; 
            s = i + 1; 
        } 
    } 
      
    return {{max_so_far,end},(end - start + 1)}; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //  #ifndef ONLINE_JUDGE
    //     freopen("mengawasi_sample_1.in", "r", stdin);
    //     freopen("mengawasi_sample_1.out", "w", stdout);
    // #endif
    ll a,b;
    cin>>a>>b;
    ll mn=min(a,b);
    ll mx=max(a,b);
    mx=mx+mn;
    if(mx%2 == 0)
    {
        cout<<mx/2<<endl;
    }
    else
        cout<<"IMPOSSIBLE\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int t = 0;
  for(size_t i = 0; i < s.length(); ++i)
    t += (s[i] == 'o');
  t += 15-s.length();
  if(t >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

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

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	llint n;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	hei(int) a;
	for (llint i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			int sum = 0;
			while (n % i == 0) {
				sum++;
				n /= i;
			}
			a.push_back(sum);
		}
	}
	if (n > 1)a.push_back(1);
	llint ans = 0;
	rep(i, 0, a.size()) {
		for (int j = 1;; j++) {
			a[i] -= j;
			if (a[i] < 0)break;
			ans++;
		}
	}
	if (!ans)ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n,m;
    cin >> n >> m;
    int l,r;
    l = -1;
    r = 100002;
    int a,b;
    while (cin >> a >> b)
    {
        l = max(a,l);
        r = min(b,r);
    }
    cout  << max(0,r-l+1) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            Console.WriteLine(a + a * a + a * a * a);
        }
    }
}

Measured memory_bytes: 27376
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,1,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)
#define pb push_back
#define ALL(a)  (a).begin(),(a).end()
template<typename T> 
void chmax(T &a,T b){ a = max(a, b);};
template<typename T> 
void chmin(T &a,T b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
typedef unsigned int uint;
int n;
int a[200000];
bool b[200000];
multiset<int> s;
void solve(){
	int ans=0;
	sort(a,a+n);
	rep(i,n){
		s.insert(a[i]);
	}
	int r=1<<30;
	while(!s.empty()){
		int x = *s.rbegin();
		while(x < r>>1)
			r=r>>1;
		int d=r-x;
		s.erase(s.find(x));
		auto it = s.find(d);
		if(it==s.end()) continue;
		s.erase(it);
		ans++;
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	rep(i,n) {
		cin>>a[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

ll powe(ll a, ll b){//aのb乗のmod
    ll ret = 1;
    while(0 < b){
        if((b%2) == 0){
            a = (a*a);
            b >>= 1;
        }
        else{
            ret = (ret*a);
            b--;
        }
    }
    return ret;
}
ll keta(ll x){
    ll ret = 0;
    while(x>0){
        ret+=x%10;
        x/=10;
    }
    return ret;
}

int main(){
    ll k; cin >> k;
    if (k<10){
        FOR(i,1,k) cout << i << endl;
        return 0;
    }
    FOR(i,1,9) cout << i << endl;
    k-=9;
    vector<ll> li;
    FOR(i,10,99) li.pb(i);
    FOR(i,0,13) FOR(j,101,1000) li.pb(j*powe(10,i)-1);
    //REP(i,1000) cout << li[i] << endl;
    ll len = li.size();
    vector<ld> limin(len);
    limin[len-1]=(ld)li[len-1]/keta(li[len-1]);
    FORD(i,len-2,0)limin[i]=min(limin[i+1],(ld)li[i]/keta(li[i]));
    FOR(i,0,len-2){
        if ((ld)li[i]/keta(li[i])<=limin[i+1]){
            cout << li[i] << endl;
            k--;
            if (k==0) return 0;
        }
    }
}

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

int main (void) {
    int N, M;
    cin >> N >> M;
    vector<int> ot_h(N);
    vector<int> max_h(N);
    
    for (int i = 0; i < N; i++) {
        int tmp; 
        cin >> tmp;
        ot_h.at(i) = tmp;
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        max_h.at(a-1) = max(max_h.at(a-1), ot_h.at(b-1));
        max_h.at(b-1) = max(max_h.at(b-1), ot_h.at(a-1));
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if(max_h.at(i) < ot_h.at(i))
            ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4060
#pragma GCC optimize(2)
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define temp template<typename T>
#define Re register
#define rt Re int
#define rch Re char
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
temp inline void read(T&res){
    #define num ch-'0'
    char ch;bool flag=0;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=(res<<1)+(res<<3)+num);
    (flag)&&(res=-res);
    #undef num
}
temp inline void write(T x){
    if(x<0)putchar('-'),x=-x;
    if(x==0){putchar('0');return;}
    rt num=0;rch ch[25];
    while(x)ch[++num]=x%10+48,x/=10;
    while(num)putchar(ch[num--]);
}
temp inline void writeln(T x){
    write(x);putchar('\n');
}
namespace HZ{
    #define ld long double
    #define ll long long
    #define rll register ll
    #define up(i,x,y) for(rt i=x;i<=y;i++)
    #define down(i,x,y) for(rt i=x;i>=y;i--)
    temp inline void Max(T&x,T y){if(x<y)x=y;}
    temp inline void Min(T&x,T y){if(x>y)x=y;}
    temp inline void SWAP(T&x,T&y){T t=x;x=y;y=t;}
    inline void Swap(rt&x,rt&y){x^=y^=x^=y;}
}using namespace HZ;
ll n,a,b;
#define r(x) read(x)
int main(){
    r(n);r(a);r(b);
    if(a>b){putchar('0');return 0;}
    if(n==1&&a!=b){putchar('0');return 0;}
    n--,n--;
    write(b*n-a*n+1);
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200005) 
input = sys.stdin.readline
n, q = map(int, input().split())
to = [[] for i in range(n)]
ans = [0 for i in range(n)]
def dfs(v, p = -1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
for i in range(n - 1):
    a, b = map(int, input().split())
    to[a - 1].append(b - 1)
    to[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    ans[p - 1] += x
dfs(0)
print(*ans)

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


int main()
{
    std::vector<int> P;;
    int temp;
    for(int i=0; i<3; i++){
        std::cin >> temp;
        P.push_back(temp);
    }
    std::sort(P.begin(),P.end());
    std::cout << P[0]+P[1] << std::endl;;
    return 0;
}


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


int main(){
    const int MX=2e5+9;
    int n=10, a[MX];
    string s;
    scanf("%d", &n);
    cin>>s;
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            a[1]=i;
            a[2]=j;
            if(s[0]=='o'&&a[1]==0)a[0]=a[2];
            if(s[0]=='o'&&a[1]==1)a[0]=a[2]^1;
            if(s[0]=='x'&&a[1]==0)a[0]=a[2]^1;
            if(s[0]=='x'&&a[1]==1)a[0]=a[2];
            for(int k=3; k<=n+1; k++){
                if(s[k-2]=='o'&&a[k-1]==0)a[k]=a[k-2];
                if(s[k-2]=='o'&&a[k-1]==1)a[k]=a[k-2]^1;
                if(s[k-2]=='x'&&a[k-1]==0)a[k]=a[k-2]^1;
                if(s[k-2]=='x'&&a[k-1]==1)a[k]=a[k-2];
         
            }
            if(a[n+1]==a[1]&&a[0]==a[n]){
                for(int k=1; k<n+1; k++){
                    if(a[k])printf("W");
                        else printf("S");
                }
                printf("\n");
                return 0;
            }
        }
    }
    printf("-1\n");
    return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> data(N + 1);
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Y[i];
        data[P[i]].push_back(Y[i]);
    }

    for (int i = 0; i < N + 1; i++) {
        sort(all(data[i]));
    }

    for (int i = 0; i < M; i++) {
        vector<int> &d = data[P[i]];
        int k = lower_bound(all(d), Y[i]) - d.begin();
        
        printf("%06d%06d\n", P[i], k + 1);
    }

}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 7808
#include <array>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
typedef vector<vector<int>> matrix;

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

inline bool out(int x, int y, int n) {
	return x < 0 || y < 0 || x > y || y >= n;
}

int dfs(int x, int y, int v, const matrix &field, matrix &visited) {
	int res = 1;
	visited[y][x] = true;
	for(int d = 0; d < 6; ++d) {
		const int nx = x + dx[d];
		const int ny = y + dy[d];
		if(out(nx, ny, field.size()) || field[ny][nx] != v || visited[ny][nx])
			continue;

		res += dfs(nx, ny, v, field, visited);
	}

	return res;
}

int calc_score(int x, int y, const matrix &field) {
	const int n = field.size();
	int res = n * (n + 1) / 2;
    matrix visited(n, vector<int>(n, false));

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j <= i; ++j) {
			if(field[i][j] == 0) {
				visited[i][j] = true;
				--res;
				for(int d = 0; d < 6; ++d) {
					const int nx = j + dx[d];
					const int ny = i + dy[d];
					if(out(nx, ny, n) || !field[ny][nx] || visited[ny][nx])
						continue;

					res -= dfs(nx, ny, field[ny][nx], field, visited);
				}
			}
		}
	}

	if(!visited[y][x])
		res -= 2 * dfs(x, y, field[y][x], field, visited);

	return res;
}

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

	for(int n, c; cin >> n >> c && n;) {
		matrix field(n);
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j <= i; ++j) {
				int value;
				cin >> value;
				field[i].emplace_back(value);
			}
		}

		int ans = -INT_MAX;
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j <= i; ++j) {
				if(field[i][j] == 0) {
					field[i][j] = c;
					chmax(ans, calc_score(j, i, field));
					field[i][j] = 0;
				}
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long l = sc.nextLong();
        long r = sc.nextLong();
        if (r - l >= 2019) {
            System.out.println(0);
        } else {
            long min = 100000;
            for (long i = l; i <= r-1; i++) {
                for (long j = i+1; j <= r; j++) {
                    long tmp = ((i % 2019) * (j % 2019)) % 2019;
                    if (tmp < min) {
                        min = tmp;
                    }
                }
            }
            System.out.println(min);
        }
    }

}


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

int H;

void max_heapify(int A[], int i) {
  int l, r, largest, tmp;
  l = 2 * i;
  r = 2 * i + 1;

  // i, l, r で値が最大のノードを選ぶ
  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;

  // 子のほうが大きかった場合
  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    // さらに下層に適用
    max_heapify(A, largest);
  }    
}

void build_max_heap(int A[]) {
  for (int i = H / 2; i > 0; i--) {
    max_heapify(A, i);
  }
}

int main() {
  int i, heap[500001];

  cin >> H;
  for (i = 1; i <= H; i++) cin >> heap[i];

  build_max_heap(heap);

  for (i = 1; i <= H; i++) cout << " " << heap[i];
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 5020
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int a = sc.nextInt();
    int b = sc.nextInt();
    // 数値a,bを文字列A,Bに変換
    String A = String.valueOf(a);
    String B = String.valueOf(b);
    // AとBを繋げた文字列を数値に変換
    int testNumber = Integer.parseInt(A + B);
    // 平方数かどうかを判定する変数を定義
    boolean squareNumber = false;
    
    for (int i=1; i<=400; i++) {
      if (testNumber == i * i) {
        squareNumber = true;
      }
    }
    
    if (squareNumber) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}
    

Measured memory_bytes: 27072
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;


int
main(void){  
  ios_base::sync_with_stdio(false);

  ll n;
  cin >> n;

  int itr = 0;
  ll tmp = 0LL;
  while(tmp < n){
    tmp = itr * (itr+1) / 2;
    itr++;
  }

  for(int i=itr-1; i>=0; i--){
    n = n - i;
    if(n < 0) n = n + i;
    else{
      cout << i << endl;
    }
    if(n == 0) break;    
  }

  return 0;
}


Measured memory_bytes: 256
//JI SRI KRISHNA.//
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string m,c,d;
    char b;
    int n,k,j,f,g,p=0,i,a[11],x,y=0;
    cin>>m;
    cin>>k;
    for(i=0;i<10;i++)
    {
        a[i]=0;
    }
    for(i=0;i<k;i++)
    {
        cin>>b;
        d[i]=b;
        x=b-48;
        a[x]++;
    }
    j=0;
    for(i=0;i<10;i++)
    {
       if(a[i]==0)
       {
           c[j]=i+48;
           j++;
       }
    }
    f=j;
    g=f;
    for(i=0;i<m.size();i++)
    {
        f=g;
        for(j=0;j<k;j++)
        {
            if(m[i]==d[j])
            {
               if(f>1)
               {
                   if(m[i]>c[f-1])
                   {
                       p=1;
                       break;
                   }
                   else
                   {
                       f=0;
                       while(m[i]>c[f])
                       {
                           f++;
                       }
                       if(i==0)
                       {
                            m[i]=c[f];
                            y=1;
                            cout<<m[i];
                            break;
                       }
                       if(f>0)
                       m[i]=c[f-1];
                       else
                        m[i]=c[f];
                   }
               }
               else
               {
                   if(m[i]>c[0])
                   {
                       p=2;
                       break;
                   }
                   else
                   {
                       m[i]=c[0];
                   }
               }
            }
        }
    }
    if(p==2||p==1)
    {
        if(c[0]=='0')
           cout<<c[1];
        else
            cout<<c[0];
        for(i=0;i<m.size();i++)
            cout<<c[0];
        cout<<endl;

    }
  else  if(y==1)
    {
        for(i=0;i<m.size()-1;i++)
            cout<<c[0];
        cout<<endl;
    }
  else  if(p==0)
    {
        cout<<m<<endl;
    }
}


Measured memory_bytes: 3600
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

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

using namespace std;
using ll = long long;
const int mod = 1e9+7;
const int INF = 2e9;
int N;
int A,B,C;
vector<int> len;

int dfs(int cur,int a,int b,int c){
    
    if (cur == N){
        if(min(a,min(b,c)) > 0) 
            return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        else
            return INF;//
    }
    int ret0,ret1,ret2,ret3;

    ret0 = dfs(cur+1,a,b,c);//
    ret1 = dfs(cur+1,a+len[cur],b,c)+10;//
    ret2 = dfs(cur+1,a,b+len[cur],c)+10;//
    ret3 = dfs(cur+1,a,b,c+len[cur])+10;//
    return min(ret0,min(ret1,min(ret2,ret3)));
}

int main(){
    cin >> N;
    cin >> A >> B >> C;
    len.resize(N);
    rep(i,N) cin >> len[i];
    
    cout << dfs(0,0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


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


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}



int main() {

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

    vector<int> p(N, 0);
    for(int i = 0; i < N; i++) cin >> p[i];

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

    ll ret = 0;
    for(int i = 0; i < K; i++) ret += p[i];

    cout << ret << endl;

    return 0;    
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; i++) cin >> a.at(i);
    ll tmp, ans;
    ll tmpsum;

    //1つめが負
    tmp = 0;
    tmpsum = 0;
    for (int i = 0; i < N; i++) {
        tmpsum += a[i];
        if(i % 2 == 0){
            if(tmpsum < 0) continue;
            tmp += tmpsum + 1;
            tmpsum = -1;
        }
        else{
            if(tmpsum > 0) continue;
            tmp += 1 - tmpsum;
            tmpsum = 1;
        }
    }
    ans = tmp;

    //1つめが正
    tmp = 0;
    tmpsum = 0;
    for (int i = 0; i < N; i++) {
        tmpsum += a[i];
        if(i % 2 == 1){
            if(tmpsum < 0) continue;
            tmp += tmpsum + 1;
            tmpsum = -1;
        }
        else{
            if(tmpsum > 0) continue;
            tmp += 1 - tmpsum;
            tmpsum = 1;
        }
    }
    ans = min(tmp, ans);

    printf("%lld\n", ans);



}


Measured memory_bytes: 1024
import math

N, D = map(int, input().split(" "))
X = []
Y = []

for i in range(N):
    x, y = map(int, input().split(" "))
    X.append(x)
    Y.append(y)

counter = 0

for i in range(N):
    if math.sqrt(X[i]**2 + Y[i]**2) <= D:
        counter = counter + 1

print(counter)

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

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


Measured memory_bytes: 26624
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n);
  int s=0;
  rep(i,n){
    cin>>a[i];
    s+=a[i];
  }
  sort(a.rbegin(),a.rend());
  int cnt=0;
  rep(i,m){
    if(a[i]>=(s+4*m-1)/(4*m))cnt++;
  }
  if(cnt==m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}


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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define fora(i, x) for (auto i : x)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back
#define _1 first
#define _2 second

typedef long long ll;

const int N3 = 1e3 + 5;
const int N4 = 1e4 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int N7 = 1e7 + 5;
const int N8 = 1e8 + 5;
const int N9 = 1e9 + 5;
const int mod = N9 + 2;

int ans, n, x, a[N5], used[N5];

int main()
{
    cin >> n;
    forn (i, 1, n)
    {
        cin >> a[i];
    }
    x = 1;
    used[1] = 1;
    while (x != 2)
    {
        x = a[x];
        if (used[x])
        {
            cout << -1;
            return 0;
        }
        used[x] = 1;
        ++ans;
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int k, a, b;
    cin >> k >> a >> b;
    REP(i, a, b + 1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<ll> nums(n); FOR(i,n) cin >> nums[i];
    sort(nums.begin(),nums.end(),greater<int>());
    ll ans = nums[0];
    FOR(i,n-2){
        ans += nums[(i/2)+1];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string abc = "abcdefghijklmnopqrstuvwxyz";
    int n; cin >> n;
    vector< map<char,int> > CharCntPerString(n);
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        int L = (int)s.size();
        for (int j = 0; j < L; j++) {
            CharCntPerString[i][s[j]]++;
        }
    }
    
    map<char,int> DubiousDocument{};
    
    
    for (int i = 0; i < 26; i++) {
        
        
        
        vector<int> V{};
        for (int j = 0; j < n; j++) V.push_back(CharCntPerString[j][abc[i]]);
        DubiousDocument[abc[i]] = *min_element(V.begin(),V.end());
        
    }
    
    string Ans;
    
    rep(i,26){
        for (int j = 0; j < DubiousDocument[abc[i]]; j++) {
            Ans += abc[i];
        }
    }
    
    cout << Ans << endl;
    
    
    
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using pp = pair<int, int>;
const int INF = 1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans = B - A + 1;
    ll div = 0;
    div += (B / C - (A-1) / C);
    div += (B / D - (A-1) / D);
    ll CD = C * D / __gcd(C, D);
    div -= (B / CD - (A-1) / CD);
    cout << ans - div << endl;
}

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

#define ll long long
class Item
{
public:
    ll int weight;
    ll int value;
};

bool compare(Item i1,Item i2){
    return i1.weight < i2.weight;
}

//ll int maximum = 0;
vector<vector<int>> dp;
vector<Item> items;

ll int getMinWeight(ll int value,int index){
    if(index == items.size()) return ((value == 0) ? 0 : INT_MAX);
    if(dp[index][value] != -1) return dp[index][value];
    ll int ans = getMinWeight(value,index + 1);
    if(items[index].value <= value){
        ans = min(ans,items[index].weight + getMinWeight(value - items[index].value,index + 1));
    }
    dp[index][value] = ans;
    return ans; 
}


int check(int totalSum, int capacity){
    //cout<<totalSum<<" ";
    while(totalSum >= 0){
        int res = getMinWeight(totalSum,0);
    //cout<<res <<" "<< capacity<<endl;

        if(res <= capacity){
        //cout<<"hi"<<" ";
            return totalSum;
        }
        totalSum--;
    }
    return 0;
}

int main()
{

    ll int N, capacity, totalValues = 0;
    cin >> N >> capacity;
    vector<Item> val;
    dp = vector<vector<int>>(N,vector<int>(100009,-1));
    for (int i = 0; i < N; i++)
    {
        Item item;
        cin >> item.weight >> item.value;
        val.push_back(item);
        totalValues += item.value;
    }
   // sort(items.begin(),items.end(),compare);
    items = val;
    cout << check(totalValues,capacity);
}

Measured memory_bytes: 42856
/*
 * I won't be broken
 * I won't be tortured
 * I won't be beaten down
 * I have the answer
 * I can take the pressure
 * I will turn it all around
 * Lift me up above this
 * The flames and the ashes
 * Lift me up and help me to fly away
*/
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	printf("%d%d%d\n",(10-n/100),(10-((n%100)/10)),(10-(n%10)));
        return 0;
}




Measured memory_bytes: 256