akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; 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;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    priority_queue<ll> que;
    ll n;
    rep(i,N){
        cin >> n;
        que.push(n);
    }
    rep(i,M){
        ll m = que.top();que.pop();
        que.push(m / 2);
    }
    ll ans = 0;
    rep(i,N){
        ans += que.top();que.pop();
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    long long int N,K,S;
    cin >> N >> K >> S;

    if(S!=1e9){
        for(int i=0;i<N;i++){
            if(i<K){
                cout << S << " ";
            }else{
                cout << 1000000000 << " ";
            }
        }
    }else{
        for(int i=0;i<N;i++){
            if(i<K){
                cout << S << " ";
            }else{
                cout << 1 << " ";
            }
        }
    }
}

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

int main()
{
    ll K,A,B;
    cin >> K >> A >> B;

    for(ll i = A; i <= B; i++)
    {
        if(i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3620
n = int(input())
card_list = list(map(int,input().split(" ")))

card_list_ex = sorted(card_list, reverse=True)


alice,bob = 0,0
for i,j in enumerate(card_list_ex):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
res = alice - bob
print(res)

Measured memory_bytes: 3060
#include <stdio.h>
int m[101][101];
int main()
{
  int n,k,l,a,b,c,i,j;
  for(;;){
    scanf("%d%d",&n,&k);
    if(n == 0 && k == 0) break;
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	if(i == j) m[i][j] = 0;
	else m[i][j] = 0x1fffffff;
      }
    }
    while(k-- > 0){
      scanf("%d",&l);
      if(l == 0){
	scanf("%d%d",&a,&b);
	printf("%d\n",m[a][b] >= 0x1fffffff ? -1 : m[a][b]);
      }else{
	scanf("%d%d%d",&a,&b,&c);
	if(m[a][b] > c){
	  m[a][b] = c; m[b][a] = c;
	  for(i=1;i<n;i++){
	    for(j=i+1;j<=n;j++){
	      if(m[i][j] > m[i][a] + m[a][b] + m[b][j]){
		m[i][j] = m[i][a] + m[a][b] + m[b][j];
		m[j][i] = m[i][j];
	      }
	      if(m[i][j] > m[i][b] + m[b][a] + m[a][j]){
		m[i][j] = m[i][b] + m[b][a] + m[a][j];
		m[j][i] = m[i][j];
	      }
	    }
	  }
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int N;
int a[210];
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> a[i];
	int counter = 0;
	while (true) {
		bool odd = false;
		for (int i = 0; i < N; i++) {
			if (a[i] % 2 == 1) odd = true;
			a[i] /= 2;
		}
		if (odd) break;
		counter += 1;
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
# coding=utf-8
from collections import deque
n = int(input())
deque = deque()
input_lines = [input() for x in range(n)]

for i in range(n):
    inp = input_lines[i].split()
    if inp[0] == 'insert':
        deque.appendleft(inp[1])
    elif inp[0] == 'deleteFirst':
        deque.popleft()
    elif inp[0] == 'deleteLast':
        deque.pop()
    else:
        if inp[1] in deque:
            deque.remove(inp[1])

print(*deque)

Measured memory_bytes: 214360
N=int(input())
A=list(map(int,input().split()))
B={}
for i in A:
  if i not in B:
    B[i]=0
  B[i]+=1
c=0
for v in B.values():
    c+=v*(v-1)/2
for i in range(N):
  print(int(c-B[A[i]]+1))

Measured memory_bytes: 24748
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<' '<<y<<endl
#define p3(x,y,z)               out<<x<<' '<<y<<' '<<z<<endl
#define p4(x,y,z,w)             out<<x<<' '<<y<<' '<<z<<' '<<w<<endl
#define pl(x)                   out<<x
#define pll(x)                  out<<x<<' '
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
    in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
    EACH(a, x)
        read_v(a, in);
}

bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T>
T factmod(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
int powmod(T a,T b,int m){ int ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}

int dfs(int node, vector<vector<int>>& edges, vector<int>& dp, vector<bool>& visited){
    if (visited[node]){return dp[node];}
    visited[node] = true;
    for (int connected_nodes: edges[node]){
        dp[node] = max(dp[node], dfs(connected_nodes, edges, dp, visited) + 1);
    }
    return dp[node];
}

void ssolve(std::istream& in, std::ostream& out){
    int n, m;
    in >> n >> m;
    vector<vector<int>> edges(n + 1);
    vector<int> dp(n + 1, 0);
    vector<bool> visited(n + 1, false);
    for(int i = 1; i < m + 1; i++){
        int x, y;
        in >> x >> y;
        edges[x].emplace_back(y);
    }

    int ans = 0;
    for(int i = 1; i < n + 1; i++){
        ans = max(ans, dfs(i, edges, dp, visited));
    }
    out << ans << '\n';
    return;
}

class GLongestPath {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);out.tie(nullptr);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    GLongestPath solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 12092
/******************************************
* AUTHOR : SHASHANK *
* NICK : lance_lot *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
ll dp[1005][1005];
char a[1005][1005];
ll rec(ll i,ll j,ll n,ll m) {
  if(i == n-1 && j == m-1)
    return 1;
  if(i >= n || j >= m)
    return 0;
  if(dp[i][j] != -1)
    return dp[i][j]%MOD;
  if(a[i+1][j] == '.' && a[i][j+1] == '.')
    dp[i][j] = (rec(i+1,j,n,m)%MOD+rec(i,j+1,n,m)%MOD)%MOD;
  else if(a[i+1][j] == '.')
    dp[i][j] = rec(i+1,j,n,m)%MOD;
  else if(a[i][j+1] == '.')
    dp[i][j] = rec(i,j+1,n,m)%MOD;
  else
    return 0;
  return dp[i][j]%MOD; 
}

int main() {
fast;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n,m;
    cin>>n>>m;
    for(ll i = 0;i < 1005;i++) {
      for(ll j = 0;j < 1005;j++)
        dp[i][j] = -1;
    }
    for(ll i = 0;i < n;i++) {
      for(ll j = 0;j < m;j++)
        cin>>a[i][j];
    }
    ll ans = 0;
    if(a[0][0] == '.' && a[n-1][m-1] == '.')
       ans = rec(0,0,n,m);
    ans %= MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	char w[110];
	cin >> w;
	int x = strlen(w);
	if (x % 2 == 1){
		cout << "No" << endl;
		return 0;
	}
	char tmp = 'A';
	int cnt = 0;
	for (int i = 0; i < x; i++){
		if (w[i] == 'B'){
			continue;
		}
		tmp = w[i];
		for (int j = i; j < x; j++){
			if (w[j] == tmp){
				w[j] = 'B';
				cnt++;
			}
		}
		if (cnt % 2 == 1){
			cout << "No" << endl;
			return 0;
		}
		cnt = 0;
		tmp = 'A';
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	
	cnt = 0
	ave = x / 3
    for i in ( 1 .. ave-1 )
        for j in ( i+1 .. n-1 )
            for k in ( j+1 .. n )
                s = ( i + j + k )
                if x < s
                    break
                elsif x == s
                    cnt += 1
                    break
                end
            end
        end
    end

	puts( cnt )
end

Measured memory_bytes: 6108
n = gets.to_i
arr = []
arr << gets.split(" ").map(&:to_i)
arr << gets.split(" ").map(&:to_i)
max = 0

for i in 0..n-1 do
  l1 = arr[0][0..i].inject(:+)
  l2 = arr[1][i..-1].inject(:+)
  max = [l1+l2, max].max
end

puts max


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N, sum=0, itido=0; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i],sum+=A[i],itido+=(i+1);
    if(sum%itido!=0) {cout<< "NO"<<"\n"; return;}
    rep(i,N) if((sum/itido-(A[(i+1)%N]-A[i]))%N!=0 or sum/itido-(A[(i+1)%N]-A[i])<0) {cout<< "NO"<<"\n"; return;}
    cout<< "YES" <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1024
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e3 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	vector<pair<int, int>> vp;
	int n;
	cin >> n;
	while (n--)
	{
		int a, b;
		cin >> a >> b;
		vp.emplace_back(-b, a);
	}
	sort(vp.begin(), vp.end());
	LL cur = -INF * INF;
	for (auto& p : vp)
	{
		int a, b;
		tie(b, a) = p;
		cur = max(cur, 1LL * b);
		cur += a;
	}
	if (cur > 0) puts("No");
	else puts("Yes");
	return 0;
}

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

using namespace std;

typedef long long ll;

vector<pair<ll, ll>> factor(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll ex = 0;
      while (n % i == 0) {
        ex++;
        n /= i;
      }
      res.push_back({i, ex});
    }
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << n << ": ";
  vector<pair<ll, ll>> fa = factor(n);
  bool flag = 1;
  for (const auto& f : fa) {
    for (int i = 0; i < f.second; i++) {
      if (flag) {
        cout << f.first;
        flag = 0;
      } else {
        cout << " " << f.first;
      }
    }
  }
  cout << '\n';
  return 0;
}



Measured memory_bytes: 3232
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        s: String
    }

    let mut pass_num = 0;
    for x in 0..10 {
        for y in 0..10 {
            for z in 0..10 {
                let ix = '0' as u8 + x as u8;
                let iy = '0' as u8 + y as u8;
                let iz = '0' as u8 + z as u8;
                let cx = ix as char;
                let cy = iy as char;
                let cz = iz as char;
                let pass = [cx, cy, cz];

                let mut test_idx = 0;
                for ss in s.chars() {
                    if ss == pass[test_idx] {
                        if test_idx == 2 {
                            pass_num += 1;
                            break;
                        }
                        test_idx += 1;
                    }
                }
            }
        }

    }

    println!("{}", pass_num);
}


Measured memory_bytes: 2248
#include<stdio.h>
#include<string.h>

int main(){
    char s[200001], t[200001];
    scanf("%s", s);
    scanf("%s", t);
    int a[26], b[26];
    for(int i=0; i<26; i++){
        a[i] = -1;
        b[i] = -1;
    }
    int f=1;
    int len = strlen(s);
    for(int i=0; i<len; i++){
        int x=s[i]-'a', y=t[i]-'a';
        if(a[x] == -1){
            a[x] = y;
        }else{
            if(a[x] != y){
                f=0;
                break;
            }
        }
        if(b[y] == -1){
            b[y] = x;
        }else{
            if(b[y] != x){
                f=0;
                break;
            }
        }
    }
    printf(f?"Yes":"No");

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    int ans=0;
    string s;
    rep(i,a,b){
        s = to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import numpy as np

stdin = open(0)
data = np.fromstring(stdin.read(), np.int32, sep=' ')
N, M = data[:2]
AB = data[2:2 + N + N]
LR = data[2 + N + N:]
A = AB[::2]
B = AB[1::2]
L = LR[::2]
R = LR[1::2]

ind = np.argsort(A)
A = A[ind]
B = B[ind]

L = np.searchsorted(A, L, 'left').tolist()
R = (np.searchsorted(A, R, 'right')).tolist()
B = np.append(B, 0)
C = np.zeros(len(B), np.int64)
C[1:] = B[:-1] ^ B[1:]
C[0] = B[0]
C = C.tolist()

graph = [[] for _ in range(N + 1)]
for i, (l, r) in enumerate(zip(L, R)):
    if l < r:
        graph[l].append(r)
        graph[r].append(l)

order = []
parent = [0] * (N+1)
close = [0] * (N+1)
for v in range(N):
    if close[v]:
        continue
    stack = [v]
    order.append(v)
    parent[v] = -1
    close[v] = 1
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if close[w]:
                continue
            stack.append(w)
            order.append(w)
            close[w] = 1
            parent[w] = v


E = []
failed = False
for v in order[::-1]:
    if C[v]:
        p = parent[v]
        if p == -1:
            failed = True
            break
        E.append((p, v))
        C[v] = 0
        C[p] ^= 1


if failed:
    print(-1)
else:
    I = {lr: i for i, lr in enumerate(zip(L, R),1)}
    answer = []
    for v, w in E:
        if v > w:
            v, w = w, v
        answer.append(I[(v, w)])
    answer.sort()
    print(len(answer))
    print(*answer)


Measured memory_bytes: 93968
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  int K,S;cin>>K>>S;
  ll cnt=0; 
  rep(x,K+1){
    rep(y,K+1){
      int z =S-x-y;
      if(z<=K && z>=0){
        cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}




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

#define INF 99999

int main(){
    int input[5];
    cin >> input[0];
    cin >> input[1];
    cin >> input[2];
    cin >> input[3];
    cin >> input[4];
    
    int time=0;
    const int N = 5;
    vector<int> v(N);
    iota(v.begin(), v.end(), 0);
    
    int min = INF;
    do {
        time = 0;
        int count = 0;
        for(auto x : v){
            time += input[x];
            int addnum = 10 - time % 10;
            if(addnum == 10)addnum = 0;
            if(count != 4)time += addnum;
            
            count++;
        }
        
        min = std::min(min, time);
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout << min << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    vi a(n),num;
    rep(i,n) cin >> a.at(i);
    sort(a.begin(), a.end());
    int64_t count = 1;
    rep(i,n-1){
        if(a.at(i+1)!=a.at(i)){
            num.push_back(count);
            count = 0;
        }
        count++;
    }
    num.push_back(count);
    int64_t res = 0;
    if(num.size()>k){
        sort(num.begin(), num.end());
        for(int i=0; i<num.size(); i++){
            if(num.size() - i <= k) break;
            res += num.at(i);
        }

    }
    cout << res << endl;
}


Measured memory_bytes: 3956
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();

        char[] s2 = s.toCharArray();
        char[] t2 = t.toCharArray();

        Arrays.sort(s2);
        Arrays.sort(t2);

        String s3 = "";
        String t3 = "";

        for (int i = 0; i < s.length(); i++) {
            s3 += s2[i];
        }
        for (int i = 0; i < t.length(); i++) {
            t3 += t2[t.length() - i - 1];
        }

        if (s3.compareTo(t3) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 22868
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
static const int MAX_H = 30;
static const int MAX_W = 30;

int h, w, n;
string str[MAX_H];

char s[MAX_H][MAX_W + 1];
bool vanish[MAX_H][MAX_W];

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

bool c(int y, int x){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			s[i][j] = str[i][j];
		}
	}
	swap(s[y][x], s[y][x + 1]);
	for(;;){
		bool flag = false;
		for(int j = 0; j < w; j++){
			for(int i = h - 2; i >= 0; i--){
				if(s[i][j] != '.' && s[i + 1][j] == '.'){
					flag = true;
					for(int k = i; k <= h - 2; k++){
						if(s[k][j] != '.' && s[k + 1][j] != '.') break;
						swap(s[k][j], s[k + 1][j]);
					}
				}
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++) vanish[i][j] = false;
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(s[i][j] == '.') continue;
				char ch = s[i][j];
				int cy = i;
				int cx = j;
				for(int k = 0; k < 4; k++){
					bool flag2 = true;
					for(int l = 0; l < n; l++){
						int ny = cy + dy[k] * l;
						int nx = cx + dx[k] * l;
						if(ny < 0 || ny >= h || nx < 0 || nx >= w || s[ny][nx] != ch) flag2 = false;
					}
					if(flag2){
						flag = true;
						for(int l = 0; ; l++){
							int ny = cy + dy[k] * l;
							int nx = cx + dx[k] * l;
							if(ny < 0 || ny >= h || nx < 0 || nx >= w || s[ny][nx] != ch) break;
							vanish[ny][nx] = true;
						}
					}
				}
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(vanish[i][j]) s[i][j] = '.';
			}
		}
		if(!flag) break;
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] != '.') return false;
		}
	}
	return true;
}

int main(){
	scanf("%d %d %d", &h, &w, &n);
	for(int i = 0; i < h; i++) cin >> str[i];
	bool flag = false;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w - 1; j++){
			if(str[i][j] == str[i][j + 1]) continue;
			flag |= c(i, j);
		}
	}
	printf(flag ? "YES\n" : "NO\n");
	return 0;
}



Measured memory_bytes: 3360
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

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


#include <iostream>

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    cout<< min(A,B)+min(C,D) << endl;
}


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n;
	std::vector<int> hist(101, 0);

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> n){
#else
	while(std::cin >> n){
#endif
		hist[n]++;
	}

	int max_val = 0;
	for(int i = 1; i < hist.size(); i++){
		max_val = std::max(max_val, hist[i]);
	}
	
	for(int i = 1; i <hist.size(); i++){
		if(hist[i] == max_val){
			std::cout << i << std::endl;
		}
	}
	return 0;
}


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

using namespace std;

int main(){

    string a, b, c;
    cin >> a >> b >> c;

    bool ans1 = a[a.size()-1] == b[0];
    bool ans2 = b[b.size()-1] == c[0];

    cout << ((ans1 && ans2) ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    ll n, k , s;
    cin >> n >> k >> s;
    rep(i, k) cout << s << " ";
    ll ii = 1e9, iii = 1;
    for(ll i = k; i < n; i++) cout << (s < ii ? ii: iii) << " ";
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

const int MAX_N = 100000;
int n;
string s;

int main()
{
  cin >> n;
  map<string,ll> cnt;
  forn(i,n) {
    cin >> s;
    sort(s.begin(),s.end());
    cnt[s]++;
  }

  ll res = 0;
  for (auto p : cnt) {
    res += p.snd*(p.snd-1)/2;
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int H, W, d;
vector<vector<int> > che;

void init()
{
	cin >> H >> W >> d;
	int n = H + W - 1;
	che.resize(n);
	rep(i, n) {
		che[i].resize(n);
	}
	int col[2][2] = {{0, 1}, {2, 3}};
	rep(i, n) {
		int rcol = (i / d) % 2;
		rep(j, n) {
			int ccol = (j / d) % 2;
			che[i][j] = col[rcol][ccol];
		}
	}
}

void solve()
{
	char col[4] = {'R', 'B', 'G', 'Y'};
	int r = 0;
	int c = H - 1;
	rep(i, H) {
		rep(j, W) {
			cout << col[che[r][c]];
			r++;
			c++;
		}
		r = i + 1;
		c = H - i - 2;
		cout << endl;
	}
}




Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
   int n;
   cin >> n;
   vector<pair<int,int>> p(n);
   
   for(int i = 0;i < n;i++){
         int x,l;
         cin >> x >> l;
         p[i].first = x + l;
         p[i].second = x - l;
         
   }
   sort(p.begin(),p.end());
   int ans = 1;
   int t = p[0].first;
   for(int i = 1;i < n;i++){
         if(t <= p[i].second){
               ans++;
               t = p[i].first;
         }
   }
   cout << ans << endl;
}


Measured memory_bytes: 4052
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i).tally
m.times do
  b, c = gets.split.map(&:to_i)
  if h.key?(c)
    h[c] += b
  else
    h[c] = b
  end
end
ans = 0
cnt = 0
h.sort{_2 <=> _1}.each do |k, v|
  if cnt + v < n
    ans += k * v
    cnt += v
  else
    ans += k * (n - cnt)
    break
  end
end
puts ans

Measured memory_bytes: 34416
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
# define rep(i,n) for(int i=0;i<n;i++)
void solve(){
    int n;
    cin>>n;
    lli a[n];
    lli sum =0 ;
    lli mod =1e9+7;
    rep(i,n)
    {
        cin>>a[i];
        sum+=a[i];
        sum%=mod;
    }
    lli ans =0;
    for(int i=0;i<n;i++){
        sum-=a[i];
        if(sum<0)
        sum+=mod;
        ans+=(sum*a[i]);
        ans%=mod;
    }
    cout<<ans<<endl;
    
    


}
int main()
{
    int t;
    //cin>>t;
    
    t=1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5100
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define ll long long
int N=INT_MAX;
map<int ,int>my;
//vector<PII>v[1000005];

int main(){
    int n,w;
    cin>>n>>w;
    ll f[n][2];
    for(int i=0;i<n;i++){
        cin>>f[i][0]>>f[i][1];
    }
    ll dp[n][w+1];
    for(int i=0;i<n;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=1;j<w+1;j++){
            if(j < f[i][0]){
                if(i>0)
                dp[i][j]=dp[i-1][j];
                else{
                    dp[i][j]=0;
                }
            }
            else{
                if(i>0)
                dp[i][j]=max((f[i][1]+dp[i-1][j-f[i][0]]),dp[i-1][j]);
                else{
                    dp[i][j]=f[i][1];
                }
            }
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<w+1;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[n-1][w];
    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int A[4]= {s[0]-'0',s[1]-'0',s[2]-'0',s[3]-'0'};
    string ope[2]= {"+","-"};
    int sum= 0;
    string ans;
    REP(i,2){
        REP(j,2){
            REP(k,2){
                sum= A[0]+((ope[i]=="+")?A[1]:-A[1]) +((ope[j]=="+")?A[2]:-A[2]) +((ope[k]=="+")?A[3]:-A[3]);
                if(sum==7){
                    ans= to_string(A[0])+ope[i]+to_string(A[1])+ope[j]+to_string(A[2])+ope[k]+to_string(A[3])+"=7";
                    break;
                } 
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

bool calc(){
  string s;
  int l;
  map<string,int> ss;
  
  
  cin >> s >> l;
  
  if(l==0) return false;

  while(s.size()<l) s = "0"+s;

  ss[s] = 0;

  for(int i=1;;i++){
    string s1 = s,s2;

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

    s2 = s1;

    reverse(s2.begin(),s2.end());

    s = to_string(stoi(s2) - stoi(s1));
    
    while(s.size()<l) s = "0"+s;

    auto it = ss.find(s);
    
    
    if(it!=ss.end()){
      printf("%d %d %d\n",it->second,stoi(s),i-it->second);
      break;
    }
    
    ss[s] = i;
  }
  
  
  return true;
}

int main(){
    
  while(calc());
  
  return 0;
}

Measured memory_bytes: 3284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
int main(){
    int n;scanf("%d",&n);
    cout<<2*3.14159265*n<<endl;
    return 0;
}


Measured memory_bytes: 3292
#include<iostream>
using namespace std;
int main(void) {
	int n, x, y;
	cin >> n >> x >> y;
	int matrix[2001][2001] = { 0 };
	//センターのみ
	for (int i(x); i < y; i++) {
		for (int j(i+1); j <= y; j++) {
			if ((j-i)<=(y-x+1)/2) {
				matrix[i][j] = (j - i);
				matrix[j][i] = (j - i);
			}
			else {
				matrix[i][j] = (y - x + 1 - j + i);
				matrix[j][i] = (y - x + 1 - j + i);
			}
		}
	}
	//左のみ
	for (int i(1); i < x; i++) {
		for (int j(i + 1); j <= x; j++) {
			matrix[i][j] = (j - i);
			matrix[j][i] = (j - i);
		}
	}
	//左とセンター
	for (int i(1); i < x; i++) {
		for (int j(x); j <= y; j++) {
			matrix[i][j] = x - i + matrix[x][j];
			matrix[j][i] = x - i + matrix[x][j];
		}
	}
	//右のみ
	for (int i(y); i < n; i++) {
		for (int j(i+1); j <= n; j++) {
			matrix[i][j] = (j - i);
			matrix[j][i] = (j - i);
		}
	}
	//左とセンター
	for (int i(x); i <= y; i++) {
		for (int j(y+1); j <= n; j++) {
			matrix[i][j] = j - y + matrix[y][i];
			matrix[j][i] = j - y + matrix[y][i];
		}
	}
	//右と左
	for (int i(1); i <= x; i++) {
		for (int j(y); j <= n; j++) {
			matrix[i][j] = x - i + 1 + j - y;
			matrix[j][i] = x - i + 1 + j - y;
		}
	}
	//集計
	int answer[2001] = { 0 };
	for (int i(1); i <= n - 1; i++) {
		for (int j(i + 1); j <= n; j++) {
			answer[matrix[i][j]] ++;
		}
	}
	//出力
	for (int i(1); i < n; i++) {
		cout << answer[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,n;
    cin >> d >> n;
    if(d==0 && n<100)cout << n << endl;
    else if(d==0)cout << 101 << endl;
    else if(d==1 && n<100)cout << n*100 << endl;
    else if(d==1)cout << 10100 << endl;
    else if(d==2 && n==100)cout << 1010000 << endl;
    else cout << n*10000 << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main (){
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	int jwbn;
	if (z/x >z/y){
		
		if(z%y == 0){
			jwbn = z/y;
			
		}else {
			jwbn = z/y+1;
			
		}
	}else {
		if(z%x== 0){
			jwbn = z/x;
		}else{
			jwbn= z/x+1;
		}
	}
	printf("%d\n",jwbn);
	return 0;
	
	
	
	
}

Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {

	static int N, M, Q;
	static int[] A;
	static int[] a, b, c, d;
	static int ans = 0;

	static void dfs(int cu, int n){
		if(cu == N){
			int tmp = 0;
			for(int i = 0; i < Q; i++){
				if(A[b[i]] - A[a[i]] == c[i]){
					tmp += d[i];
				}
			}
			ans = Math.max(ans, tmp);
			return;
		}
		for(int i = n; i < M+1; i++){
			A[cu] = i;
			dfs(cu+1, i);
		}
	}

    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);
        N = sc.nextInt();
        M = sc.nextInt();
        Q = sc.nextInt();
        a = new int[Q];
        b = new int[Q];
        c = new int[Q];
        d = new int[Q];
        A = new int[N];
        for(int i = 0; i < Q; i++){
        	a[i] = sc.nextInt()-1;
        	b[i] = sc.nextInt()-1;
        	c[i] = sc.nextInt();
        	d[i] = sc.nextInt();
        }
        sc.close();
        dfs(0, 1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 37276
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;

void chmax(lint &a, lint b){
    a = max(a, b);
}

void chmin(lint &a, lint b){
    a = min(a, b);
}

class BPowersOfTwo {
public:
    int N;
    vi A;
    map<int, int> mp;

    void input(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in>>N;
        A = vi(N);
        REP(i, N) in>>A[i], mp[A[i]]++;
    }

    int dif(int x){
        int cur = 1;
        while(cur<=x){
            cur <<= 1;
        }
        return cur - x;
    }

    void solve(std::istream& in, std::ostream& out){
        input(in, out);
        int ans = 0;
        sort(RALL(A));
        for(auto u : A){
            if(not mp[u]) continue;
            mp[u]--;
            int v = dif(u);
            if(mp[v]){
                ans++;
                mp[v]--;
            }
        }
        out<<ans<<'\n';
    }
};


int main() {
	BPowersOfTwo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int n;
set<string> s;

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		string st;
		cin>>st;
		s.insert(st);
	}
	cout<<s.size()<<endl;
	
	return 0;
}

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

int main(void){
    int a,b;
    cin>>b>>a;
    vector<string> c(100);
    rep(i,100){
        c[i] = string(100,(i<50 ? '.' : '#'));
    }
    rep(i,a-1){
        int x = (i%50)*2;
        int y = (i/50)*2;
        c[y][x] = '#';
    }
    rep(i,b-1){
        int x = (i%50)*2;
        int y = 99 - (i/50)*2;
        c[y][x] = '.';
    }

    cout<<"100 100"<<endl;
    for(string line : c){
        cout<<line<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {

	var str string
	var n int
	fmt.Scan(&str, &n)
	// fmt.Println(str)

	for i := 0; i < n; i++ {
		var cmd string
		var a, b int
		fmt.Scan(&cmd, &a, &b)
		// fmt.Println(cmd, a, b)

		switch cmd {
		case "replace":
			var s  string
			fmt.Scan(&s)
			str=str[:a] + s + str[b+1:]
		case "reverse":
			var tmp string
			for i := b; i >= a; i-- {
				tmp += string(str[i])
			}
			str = strings.Replace(str, str[a:b+1], tmp, 1)
		case "print":
			fmt.Println(str[a : b+1])
		}
	}
}



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

int main()
{
  int64_t N,M ;
  cin>>N>>M ;
  vector<pair<int64_t,int64_t>>P(N) ;
  for(int64_t i=0;i<N;i++) cin>>P.at(i).first>>P.at(i).second ;
  sort(P.begin(),P.end()) ;
  
  int64_t min_money=0 ;
  for(int64_t i=0;i<N;i++){
    if(M>P.at(i).second){
      M-=P.at(i).second ;
      min_money+=P.at(i).first*P.at(i).second ;
    }else{
      min_money+=M*P.at(i).first ;
      M=0 ;
      break ;
    }
  }
  cout<<min_money<<endl ;
  
  return 0 ; 
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
        public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
          
          int N =sc.nextInt();
          long a =0;
          for(int i=1;i<=N;i++){
           if(i%3!=0&&i%5!=0){
             a=a+i;   
           } 
          }
           System.out.print(a);
        }
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int d[6] = {5, 7, 5, 7, 7, 114514};
        int ans = -1;
        rep(i, 0, n){
            int now = 0;
            int tmp = 0;
            rep(j, i, n){
                if(a[j] + tmp < d[now]){
                    tmp += a[j];
                }else if(a[j] + tmp == d[now]){
                    now++;
                    tmp = 0;
                }else{
                    break;
                }
                // cout << now << " " << tmp << endl;
                if(now == 5){
                    cout << i + 1 << endl;
                    i = n;
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif

#define GETTYPE(i) 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  ll k;
  int ans;
  while(cin >> a >> b >> c >> k){
    if(k % 2 == 0){
      ans = a - b;
    }else{
      ans = b - a;
    }

    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

inline int read() {
    int cnt = 0, opt = 1;
    char ch = getchar();

    for (; ! isalnum(ch); ch = getchar())
        if (ch == '-')  opt = 0;
    for (; isalnum(ch); ch = getchar())
        cnt = cnt * 10 + ch - 48;

    return opt ? cnt : -cnt;
}

int n, m;

int main() {
	n = read(), m = read();
	
	printf("%s", n == m ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    map<int,int>P;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        P[a]++;
    }
    vector<int> z;
    for(auto x:P){
        z.push_back(x.second);
    }
    if(z.size()<=m){
        cout<<0<<endl;
        return 0;
    }
    sort(z.begin(),z.end(),greater<>());
    for(int i=0;i<m;i++){
        n-=z[i];
    }
    
     cout<<n<<endl;
}


Measured memory_bytes: 10748
using System;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0, y = 0;
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                x = int.Parse(str[0]);
                y = int.Parse(str[1]);

                if (x == 0 && y == 0) { 
                                break;
                }

                if (x < y)
                    Console.WriteLine("{0} {1}", x, y);

                else
                    Console.WriteLine("{0} {1}", y, x);
            }
        }
    }
    
}



Measured memory_bytes: 9376
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<float.h>
#include<cmath>
using ll = unsigned long long;
using namespace std;

int main(void) {

    int n;

    // 問題文を読んで，型の定義に気をつける
    double t, a;

    cin >> n;
    cin >> t >> a;

    double *h = new double[n];

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

    // sol
    double minv = DBL_MAX;
    int min_position = 0;

    for (int i = 0 ; i < n ; ++ i) {

        double cand = std::abs(a - (t - h[i] * 0.006));

        if (cand < minv) {
            minv = cand;
            min_position = i;
        }
    }

    cout << min_position + 1 << endl;

    return 0;
}

Measured memory_bytes: 256