akhauriyash/Code-Regression huggingface dataset:
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  n :: Int <- readLn
  xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length $ filter id $ zipWith3 (\x y z -> min x z < y && y < max x z) xs (tail xs) (drop 2 xs)


Measured memory_bytes: 508
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    H, W = map(int, readline().split())

    grid = ["." * (W + 2)]

    for _ in range(H):
        s = "." + input() + "."
        grid.append(s)
    grid.append("." * (W + 2))

    res = []
    for row in range(1, H + 1):
        cur = ""
        for col in range(1, W + 1):
            if grid[row][col] == "#":
                cur += "#"
            else:
                cnt = 0
                for r in (row - 1, row, row + 1):
                    for c in (col - 1, col, col + 1):
                        if grid[r][c] == "#":
                            cnt += 1
                cur += str(cnt)
        res.append(cur)

    for x in res:
        print(x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n;
    cin >> k >> n;
    vector<int>a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int sho = 0;
    for (int i=0; i<n-1; i++){
        if (a[i+1]-a[i] > sho) sho = a[i+1]-a[i];
    }
    if (a[0]+k-a[n-1] > sho) sho = a[0]+k-a[n-1];
    cout << k-sho;
}

Measured memory_bytes: 4028
k = int(input())
a,b=input().split()
a = int(a)
b = int(b)
i=0
s = ""
while (a+i <= b):
  if((a+i)%k==0):
  	s=  "OK"
  i += 1
if (s != "OK"):
	s= "NG"
print(s)

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

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int d[N];
vector < int > v[N];

pair < int, int > bfs(int x)
{
        for(int i = 1; i <= n; i++){
                d[i] = 1e9;
        }
        queue < int > q;
        d[x] = 0;
        q.push(x);
        while(!q.empty()){
                x = q.front();
                q.pop();
                for(int y: v[x]){
                        if(d[x] + 1 < d[y]){
                                d[y] = d[x] + 1;
                                q.push(y);
                        }
                }
        }
        pair < int, int > res = {0, 0};
        for(int i = 1; i <= n; i++){
                res = max(res, make_pair(d[i], i));
        }
        return res;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i < n; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        auto p = bfs(1);
        p = bfs(p.se);

        int g = p.fi;
        d[0] = 1;
        for(int i = 1; i <= g; i++){
                d[i] = 0;
                if(d[i - 1] == 0){
                        d[i] = 1;
                } else if(i - 2 >= 0 && d[i - 2] == 0){
                        d[i] = 1;
                }
        }
        if(d[g]){
                cout << "First" << "\n";
        } else{
                cout << "Second" << "\n";
        }
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
//#define sz 2

using namespace std;

char s[ 110 ], t[ 110 ];

int main() {
	int n;
	scanf( "%d", &n );
	scanf( "%s%s", s, t );
	for( int i = 0; i < n; ++i )
		printf( "%c%c", s[ i ], t[ i ] );
	return 0;
}

Measured memory_bytes: 3748
#include<cstdio>
char s[15];
int main(){
	int a,b;scanf("%d%d%s",&a,&b,s);
	for(int i=0;s[i];i++){
		if(i==a){
			if(s[i]!='-'){
				printf("No");return 0;
			}
		}
		else if(s[i]>'9'||s[i]<'0'){
			printf("No");return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())

s=[list(str(input())) for _ in range(n)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(n):
    for j in range(m):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                exit()

print('Yes')

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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0; i<n; ++i){
    int x; cin>>x;
    a[i]=x-i-1;
  }

  sort(a.begin(), a.end());
  int p=a[n/2]; long long ans=0LL;
  for(int i=0; i<n; ++i)ans+=abs(a[i]-p);

  cout<<ans<<endl;
  
}


Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

struct Node {
  int a;
  int b;
  Node *child;
  Node(int _a, int _b) : a(_a), b(_b) {
    child = nullptr;
  }
    Node(int _a, int _b, Node *_child) : a(_a), b(_b), child(_child) {
  }
};

bool check(ll ci, ll cj, ll v, const vector<ll>& x, const vector<ll>& y, const vector<ll>& c) {
  int n = x.size();
  REP(i, n) {
    if(max(v - abs(x[i] - ci) - abs(y[i] - cj), 0LL) !=  c[i]) {
      return false;
    }
  }
  return true;
}
signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> x(n), y(n), c(n);
  REP(i, n) cin >> x[i] >> y[i] >> c[i];
  int pindex = -1;
  REP(i, n) if(c[i]) {
    pindex = i;
    break;
  }
  REP(i, 101) {
    REP(j, 101) {
      ll v = abs(x[pindex] - i) + abs(y[pindex] - j) + c[pindex];
       if(check(i, j, v, x, y, c)) {
        cout << i << " " << j << " " << v << endl;
        return 0;
      }
    }
  }
  return 0;
}

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


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	int n; cin >> n;
	int m = 1;
	while (1000*m<n)
	{
		m++;
	}
	cout << 1000 * m - n << endl;

	return 0;
}

Measured memory_bytes: 3664
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
X=[0]*26
for i in range(D):
  SC+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SC-=sum(X)
YY=[]
Y=[]
for i in range(D):
  for k in range(2):
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 84824
#include<bits/stdc++.h>
#define ll long long
#define Everyone Input();
#define Has solve();
#define A print();
#define Dream return 0;
using namespace std;
const int maxn=9e5+20,mod=1e9+7;
ll N,M,K,Pow[maxn],fac[maxn],inv[maxn],ans=0;
inline long long read()
{
    long long s=0,f=1; char ch;for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+ch-'0';return s*f;
}
void Prepare(int Max)
{
    fac[0]=inv[0]=Pow[0]=inv[1]=1LL;
    for(int i=2;i<=Max;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=Max;++i)
    {
        fac[i]=(ll)fac[i-1]*i%mod;
        inv[i]=(inv[i]*inv[i-1])%mod;
        Pow[i]=(ll)Pow[i-1]*3%mod;
    }
}
ll C(int n,int m){return (fac[n]*inv[m])%mod*inv[n-m]%mod;}
void Input()
{
    N=read(),M=read(),K=read();
    Prepare(N+M+K);
}
void solve()
{
    if(M<K) swap(M,K); ll res=1LL;
    for(int i=0;i<=M+K;++i)
    {
        ans=(ans+(C(N-1+i,N-1)*Pow[M+K-i]%mod)*res%mod)%mod;
        if(i<K) res<<=1,res%=mod;
        else if(i>=M) res=(res+res-C(i,K)-C(i,i-M))%mod;
        else res=(res-C(i,K)+res)%mod;
    }
}
void print(){printf("%lld\n",(ans+mod)%mod);}
int main(){ Everyone Has A Dream }


Measured memory_bytes: 21376
s=input()
n=len(s)
h=n//2

ans = "Yes"
for i in range(h):
  if s[i] != s[-i-1]:
    ans = "No"

p1 = s[0:h]
for i in range(len(p1)//2):
  if p1[i] != p1[-i-1]:
    ans = "No"

p = int((n+3)/2)-1
p2 = s[p:]
for i in range(len(p2)//2):
  if p2[i] != p2[-i-1]:
    ans = "No"
    
print(ans)

Measured memory_bytes: 3064
A = input()
if A=="MON":
    print(6)
elif A=="TUE":
    print(5)
elif A =="WED":
    print(4)
elif A =="THU":
    print(3)
elif A =="FRI":
    print(2)
elif A =="SAT":
    print(1)
elif A =="SUN":
    print(7)

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

using namespace std;
typedef long long ll;

int main() {
    int n, p;
    string s;
    cin >> n >> p >> s;
    if (p == 2) {
        ll ret = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % 2 == 0)ret += i + 1;
        }
        cout << ret << endl;
    } else if (p == 5) {
        ll ret = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % 5 == 0)ret += i + 1;
        }
        cout << ret << endl;
    } else {
        reverse(s.begin(), s.end());

        ll now = 0;
        int times = 1;
        vector<ll> remain(p);
        remain[0] = 1;
        for (int i = 0; i < n; i++) {
            now += (s[i] - '0') * times, now %= p;
            times *= 10, times %= p;
            remain[now % p]++;
        }

        ll ret = 0;
        for (auto x:remain)ret += x * (x - 1) / 2;
        cout << ret << endl;
    }
    return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

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

    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; ++i) cin >> v[i];

    map<int,int> l, r;
    l[-1] = 0; l[-2] = 0;
    r[-3] = 0; r[-4] = 0;
    for (int i=0; i<n; ++i) {
        if (i % 2 == 1) {
            l[v[i]] ++;
        } else {
            r[v[i]] ++;
        }
    }

    vector<pair<int, int>> l2; // count, vi
    for (auto it=l.begin(); it!=l.end(); ++it) {
        l2.emplace_back(it->second, it->first);
    }
    sort(l2.rbegin(), l2.rend());

    vector<pair<int, int>> r2;
    for (auto it=r.begin(); it!=r.end(); ++it) {
        r2.emplace_back(it->second, it->first);
    }
    sort(r2.rbegin(), r2.rend());

    int ans = INT_MAX;
    for (int i=0; i<2; ++i) {
        for (int j=0; j<2; ++j) {
            auto p1 = l2[i];
            auto p2 = r2[j];
            if (p1.second == p2.second) continue;
            ans = min(ans, n - p1.first - p2.first);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6524
#include <stdio.h>

int main(void) {
	int A, B, C;
	int asumikana;
	if (scanf("%d%d%d", &A, &B, &C) != 3) return 1;
	asumikana = B / A;
	if (asumikana > C) asumikana = C;
	printf("%d\n", asumikana);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

		Scanner scnr = new Scanner(System.in);
		int numSheep = scnr.nextInt();
		int numWolf = scnr.nextInt();

		if (numSheep > numWolf) {
			System.out.print("safe");
		}
		else if (numSheep < numWolf) {
			System.out.print("unsafe");
		}
		else {
			System.out.print("unsafe");
		}
	}
}


Measured memory_bytes: 26940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,k,n) for(int i = k; i <= n; i++) 
#define per(i,k,n) for(int i = k; i >= n; i--)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii; 
typedef vector<ii> vii;
typedef vector<char> vchar;
typedef vector<int> vi;
#define ff first
#define ss second

#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"


   //=\/=\/=\/=\/=\/=\/=\/=\/=\/=\        Jai Hind Dosto        /=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\
  //=\/=\/=\/=\                    ̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿                             /=\/=\/=\/=\\
 //=\/=\/=\/=\                                                                               /=\/=\/=\/=\\
//=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\



int modPow(int a, int b);           

                
void solve(){
    int x,y;
    cin >> x >> y;
    if(y<=4*x && y>=2*x && y%2==0)cout << "Yes";
    else cout << "No";
}






signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed;
    //cout <<setprecision(6);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
   // int test=1; cin >> test; while(test--)
    solve();
}

int modPow(int a, int b){
    if(b==0)return 1;
    if(b%2==0){
        int x = a*a;
        x%=mod;
        return modPow(x,b/2);
    }
    return (a*modPow(a,b-1))%mod;
}




Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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 ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  int n; cin >>n;
  rep(i,9){
    rep(j,9){
      if((i+1)*(j+1)==n){
        cout <<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll dp[500][500], a[500], sl[500], sr[500];

ll solve(int l, int r){
    if(r <= l) return 0;
    ll &R = dp[l][r];
    if(R >= 0) return R;
    R = 1e18;
    fore(i,l,r+1){
        R = min(R, sl[i]-sl[l-1] +sr[i+1]-sr[r+1] + solve(l,i) + solve(i+1,r));
    }
    return R;
}

int main(){FIN;
    memset(dp,-1,sizeof(dp));
    int n; cin >> n;
    fore(i,1,n+1) cin >> a[i], sl[i] = sl[i-1]+a[i];
    for(int i = n; i; i--) sr[i] = sr[i+1]+a[i];
    cout << solve(1,n) << "\n";
}

Measured memory_bytes: 2304
i = input().split()
a = float(i[0])
b = float(i[1])
t = float(i[2])
f = True
n = 0
while(f):

    if t  + 0.5 < n * a:
       f = False
       break
    n = n + 1
n = n-1
print(int(n * b))

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

#define MAX 100

int main() {
	int N, A, B;

	cin >> N >> A >> B;

	int ans1 = min( A, B );
	int ans2 = max( 0, A + B - N );

	cout << ans1 << " " << ans2 << endl;

	return 0;
}


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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e5 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

bool comp(ii &a, ii &b) {
  if (a.Y != b.Y) {
    return a.Y > b.Y;
  }
  return a.X < b.X;
}

bool ok[N];

void solve() {
  int n, m;
  scanf("%d %d", &n, &m);
  ii p[n];
  FOR(i, 0, n) {
    scanf("%d %d", &p[i].X, &p[i].Y);
  }
  sort(p, p + n, comp);
  int ans = 0;
  set<int> remain;
  FOR(i, 0, m) {
    remain.insert(-i);
  }
  FOR(i, 0, n) {
    auto it = remain.lower_bound(-(m - p[i].X));
    if (it != remain.end()) {
      remain.erase(it);
      ans += p[i].Y;
    }
  }
  printf("%d\n", ans);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    input();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



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

using namespace std;

bool notok(const string &s, const string &t) {
    set<char> ss;
    for (char c : s) ss.insert(c);
    for (int c : t) {
        if (ss.count(c) == 0) {
            return true;
        }
    }
    return false;
}

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

    string s, t;
    cin >> s >> t;

    if (notok(s, t)) {
        cout << -1 << endl;
        return 0;
    }

    vector<vector<int>> pos(26);
    int n = s.size();
    for (int i = 0; i < n; i++) {
        pos[s[i] - 'a'].push_back(i);
    }

    auto get = [&](int cur, char c) -> int {
        auto it = lower_bound(pos[c - 'a'].begin(), pos[c - 'a'].end(), cur);
        if (it == pos[c - 'a'].end()) return -1;
        return *it + 1;
    };

    long long ans = 0;
    int cur = 0;
    for (char c : t) {
        // cur以降で最初のc
        int nxt = get(cur, c);
        if (nxt == -1) {
            ans += n - cur;
            cur = 0;
            nxt = get(cur, c);
        }
        ans += nxt - cur;
        cur = nxt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int l=55,r,sum=0,m,n,q;
int a[55],b[55],c[55],d[55],p[15];
void dfs(int step)
{
	if(step==n+1)
	{
		int res=0;
		for(int i=1;i<=q;++i)
		{
			if(p[b[i]]-p[a[i]]==c[i])
			res+=d[i];
		}
		sum=max(sum,res);return;
	}
	for(int i=p[step-1];i<=m;++i)
	{
		p[step]=i;
		dfs(step+1);
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=q;++i)
	{
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	}
	p[0]=1;
	dfs(1); 
	printf("%d",sum);
} 

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

ll solve(ll arr[], ll n, ll k)
{
    ll dp[100001]={0};
    dp[1]=0;
    
    for(ll i=2; i<n+1; i++)
    {
        ll ans=INT_MAX;
        for(ll j=1; j<=k; j++)
        {
            if((i-j) > 0)
            {
                ll a = abs(arr[i]-arr[i-j])+dp[i-j];
                ans=min(ans, a);
            }
        }
        dp[i]=ans;
    }
    
    /*for(ll i=1; i<=n; i++)
    {
        cout<<dp[i]<<" ";
    }
    cout<<endl;*/
    return dp[n];
}

int main() {
    ll n, k;
    cin>>n>>k;
    ll arr[100001];
    for(ll i=1; i<n+1; i++)
    {
        cin>>arr[i];
    }
    cout<<solve(arr, n, k)<<endl;
	return 0;
}

Measured memory_bytes: 1792
import itertools
ans=0
N=int(input())
for K in range(1,10):
    S=itertools.product(["3","5","7"],repeat=K)
    for seq in S:
        X=set()
        for i in seq:
            X.add(i)
        if len(X)!=3:
            continue
        T="".join(seq)
        if 1<=int(T)<=N:
            ans+=1
print(ans)


Measured memory_bytes: 3060
n, x, y = [int(i) for i in input().split()]
ans = [0]*n
for i in range(n-1):
    for j in range(i+1, n):
        ans[min(j-i, abs(x-(i+1))+abs((j+1)-y)+1)] += 1

print(*ans[1:], sep='\n')


Measured memory_bytes: 3444
//
//  main.c
//  aojdice2
//
//  Created by 15mac-08 on 2017/05/18.
//  Copyright ?? 2017??´ 15mac-08. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int dice[24][6] = {{2 ,6 ,3 ,4 ,1 ,5},
        {6 ,5 ,3 ,4 ,2 ,1},
        {5 ,1 ,3 ,4 ,6 ,2},
        {4 ,1 ,5 ,2 ,6 ,3},
        {6 ,4 ,5 ,2 ,3 ,1},
        {3 ,6 ,5 ,2 ,1 ,4},
        {1 ,3 ,5 ,2 ,4 ,6},
        {5 ,3 ,6 ,1 ,4 ,2},
        {3 ,2 ,6 ,1 ,5 ,4},
        {2 ,4 ,6 ,1 ,3 ,5},
        {4 ,5 ,6 ,1 ,2 ,3},
        {1 ,5 ,4 ,3 ,2 ,6},
        {2 ,1 ,4 ,3 ,6 ,5},
        {6 ,2 ,4 ,3 ,5 ,1},
        {5 ,6 ,4 ,3 ,1 ,2},
        {4 ,6 ,2 ,5 ,1 ,3},
        {6 ,3 ,2 ,5 ,4 ,1},
        {3 ,1 ,2 ,5 ,6 ,4},
        {1 ,4 ,2 ,5 ,3 ,6},
        {5 ,4 ,1 ,6 ,3 ,2},
        {3 ,5 ,1 ,6 ,2 ,4},
        {2 ,3 ,1 ,6 ,4 ,5},
        {4 ,2 ,1 ,6 ,5 ,3},
        {1 ,2 ,3 ,4 ,5 ,6}};
    
    int num2[6],i,j,count=0,num[6]={0};
    
    for (i = 0; i < 6; i++) {
        scanf("%d",&num[i]);
    }
    
    for (i = 0 ; i < 6; i++) {
        scanf("%d",&num2[i]);
    }
    
    for (i = 0; i < 24; i++) {
        
        for (j = 0; j < 6; j++) {
            if(num[j] != num2[dice[i][j]-1]){
                break;
            }
            count++;
        }
        
        if (count == 6) {
            printf("Yes\n");
            return 0;
        }
        
        count = 0;
    }
    
    printf("No\n");
    
    
    return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]){
    cout << "Yes" << endl;
    return 0;
  }
  if(s[1]==s[2]&&s[2]==s[3]){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for i in a:
    result = []
    for j in zip(*b):
        result.append(sum([x * y for x, y in zip(i, j)]))
    print(*result)



Measured memory_bytes: 6584
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N, K; cin >> N >> K;

	ll ans = 1;
	rep(i, N) {
		if (i == 0) ans *= K;
		else ans *= (K - 1);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define deb(x) cerr <<#x<<" = "<<x<<"\n"
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////



/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for(int i=0;i<s.length();i++){
		if(s[i] != t[i]){
			cnt++;
		}
	}
	cout << cnt <<"\n";
	

}

int main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	/* #ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
    #endif  */
}

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <string>


using namespace std;


int N;
string S;

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

	bool ans = true;
	if (N % 2) { ans = false; }

	for (int i = 0; i < N / 2 && ans; i++) {
		ans = S[i] == S[i+N/2];
	}

	cout << (ans?"Yes":"No") << endl;


	return 0;


}


Measured memory_bytes: 256
#include <math.h>

int main(void){
  double a,b,c,min,tmp;
  int r,n;

  while(1){
    scanf("%lf%lf%lf",&a,&b,&c);
    if(!a && !b && !c) break;

    scanf("%d",&n);
    while(n--){
      scanf("%d",&r);
      min = 999999;
      if((tmp=sqrt(a*a+b*b)/2)<min) min=tmp;
      if((tmp=sqrt(a*a+c*c)/2)<min) min=tmp;
      if((tmp=sqrt(b*b+c*c)/2)<min) min=tmp;

      if(min<r) printf("OK\n");
      else printf("NA\n");
    }
  }

  return 0;
}

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

int main() 
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
            s[i]='9';
        else
            s[i]='1';
    }
    cout << s;
    return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int d;
	cin >> d;
	cout << "Christmas";
	for (int i = 25; i > d; i--) {
		cout << " Eve";
	}
	cout << "\n";
}

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


Measured memory_bytes: 256
s=input()
flag=2
cnt=0
p=[]

for i in range(len(s)):
  if s[i]==">":
    if flag==0 or flag==2:
      cnt+=1
    elif flag==1:
      p.append(cnt)
      cnt=1
    flag=0
  
  elif s[i]=="<":
    if flag==1 or flag==2:
      cnt+=1
    elif flag==0:
      p.append(cnt)
      cnt=1
    flag=1
p.append(len(s)-sum(p))
n=len(p)
ans=0

if n%2==0 and s[0]=="<":
  for i in range(0,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

if n%2==0 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2+p[n-1]*(p[n-1]+1)//2
  for i in range(1,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2) 

if n%2==1 and s[0]=="<":
  ans+=p[n-1]*(p[n-1]+1)//2
  for i in range(0,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)
    
if n%2==1 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2
  for i in range(1,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

print(ans)

Measured memory_bytes: 6436
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

A.sort()
ans = 0
if N % 2 == 0:
    for i in range(N):
        if i < N // 2 - 1:
            ans -= A[i] * 2
        elif i == N // 2 - 1:
            ans -= A[i]
        elif i == N // 2:
            ans += A[i]
        else:
            ans += A[i] * 2
else:
    ans = 0
    for i in range(N):
        if i < N // 2:
            ans -= A[i] * 2
        elif N // 2 <= i <= N // 2 + 1:
            ans += A[i]
        else:
            ans += A[i] * 2
    ans2 = 0
    for i in range(N):
        if i < N // 2 - 1:
            ans2 -= A[i] * 2
        elif N // 2 - 1 <= i <= N // 2:
            ans2 -= A[i]
        else:
            ans2 += A[i] * 2
    # print(ans, ans2)
    ans = max(ans, ans2)
print(ans)

Measured memory_bytes: 51644
def distinct(a):
  d = {}
  for num in a:
    try: d[num] += 1
    except KeyError: d[num] = 1
  for key in d:
    if d[key] > 1: return False
  return True
n = int(input())
a = list(map(int, input().split()))
print('YES' if distinct(a) else 'NO')

Measured memory_bytes: 35252
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long X = sc.nextLong();
        Long Y = sc.nextLong();
        Long sum = X * 2;//A2
        if(sum > Y){
            System.out.println("1");
            System.exit(0);
        }
        int count = 2;
        //Long sum = X * 2;
        //int count = 2;
        /*
        while(true){
            sum = sum * 2;
            if(sum > Y){
                System.out.println(count);
                System.exit(0);
            }
            count++;
            if((X-1) == count){
                System.out.println(count);
                System.exit(0);
            }
            System.out.println("A" + count + "=" + sum);
        }
        */
        while(true){
            sum = sum * 2;
            if(sum > Y){
                if(count == 2){
                    System.out.println("2");
                    System.exit(0);
                }else{
                    System.out.println(count);
                    System.exit(0);
                }
            }
            count++;
            /*
            if(X == count){
                System.out.println(count);
                System.exit(0);
            }
            */
        }
    }
}

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

int main() {
  int n, m, a, b, i, cnt1 = 0, cnt2 = 0, ck = 0;
  cin >> n >> m;
  vector<int> s1(n + 1, 0), s2(n + 1, 0);
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (a == 1) {
      s1[cnt1] = b;
      ++cnt1;
    }
    if (b == n) {
      s2[a] = 1;
    }
  }
  for (i = 0; i <= cnt1; i++) {
    if (s2[s1[i]] == 1) {
      ck = 1;
      break;
    }
  }
  if (ck) {
    cout << "POSSIBLE"
         << "\n";
  } else {
    cout << "IMPOSSIBLE"
         << "\n";
  }
  return 0;
}

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

int main(){
	int n,k;
	int num[100005];
	while(cin >> n >> k && n && k){
		for(int i=0;i<n;i++) cin >> num[i];
		int ans = 0;
		for(int i=0;i<k;i++) ans += num[i];
		int sum = ans;
		for(int i=1;i<n-k+1;i++){
			sum -= num[i-1];
			sum += num[i+k-1];
			ans = max(ans,sum);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1548
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	x := sc.ReadInt()
	k := sc.ReadInt()
	d := sc.ReadInt()

	absX := Abs(x)
	timesToNear := absX / d
	nearPoint := absX % d

	var ans int
	if timesToNear >= k {
		ans = absX - k*d
	} else if (k-timesToNear)%2 == 0 {
		ans = nearPoint
	} else {
		ans = d - nearPoint
	}
	fmt.Println(ans)
}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, long long M, std::vector<long long> A){
  priority_queue<int> pq;
  REP(x, N) pq.push(A.at(x));

  REP(x, M) {
    int topA = pq.top();
    topA /= 2;
    pq.pop();
    pq.push(topA);
  }
  int sum = 0;
  REP(x, N) {
    sum += pq.top();
    pq.pop();
  }
  cout << sum << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, M, std::move(A));
}


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

int main(){
  int N; cin >>N;
  double v[N];
  for(int i=0;i<N;i++){
    cin >>v[i];
  }
  sort(v, v+N);
  for(int i=0; i<N-1; i++){
    v[i+1] = (v[i]+v[i+1])/2;
  }

  cout << v[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	printf("%.10lf\n",(double)a/(double)b);
	return 0;
}


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

typedef  long long ll;
#define mop 1000000007
using namespace std;

vector <ll> a,b;
unordered_map <ll, ll> m;

int main() {
    
    ll n;
    cin >> n;
    for (ll i=0;i<n;i++){
        ll p;
        cin >> p;
        a.push_back(p);
        b.push_back(0);
    }
    sort(a.begin(),a.end());
    for (ll i=0;i<a.size();i++){
        m[a[i]] += 1;
    }

//    for (auto itr = m.begin();itr != m.end();itr++){
//        cout << itr ->first << " " << itr ->second << endl;
//    }

    ll ans = 0;
    int idx = 30;
    for (ll i=a.size()-1;i>=0;i--){
        while(a[i]*2 < pow(2,idx)){
            idx--;
        }
        if(m[pow(2,idx) - a[i]] and m[a[i]]){
            if(pow(2,idx) - a[i] != a[i]) {
                m[a[i]] -= 1;
                m[pow(2, idx) - a[i]] -= 1;
                ans++;
            }else{
                if(m[a[i]] >= 2){
                    m[a[i]] -= 2;
                    ans++ ;
                }
            }


        }
        a.pop_back();
    }
    cout << ans << endl;


}



Measured memory_bytes: 20112
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>
 
using namespace std;
 
 
int main()
{
	int n; 
	cin >> n;
	long long int a[100];
	a[0] = 2;
	a[1] = 1;
	for (int i = 2; i < n+1; i++)
	{
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[n] << endl;
 
}

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

int main() {
  int N;
  scanf("%d", &N);

  vector<int> a(3 * N, 0);
  for (int i = 0; i < 3 * N; i++) {
    scanf("%d", &a.at(i));
  }

  sort(a.begin(), a.end(), greater<int>());

  int count = 0;
  int index = 1;
  long ans = 0;
  while(count < N) {
    ans += (long) a.at(index);
    index += 2;
    count++;
  }

  printf("%ld", ans);
}

Measured memory_bytes: 1408
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll L, R;

int main() {
	cin >> L >> R;
	ll ans = INF;
	int N = min(R - L, (ll)2019);
	REP(i, N) {
		for (int j = i + 1; j <= N; j++) {
			ans = min((L + i) * (L + j) % 2019, ans);
			if (ans == 0) break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

struct Card{
  char suit;
  char value;
};

void BubbleSort(Card C[], int N);
void SelectionSort(Card C[], int N);
void trace(Card C[], int N);
int judge(Card C1[], Card C2[], int N);

int main()
{
  int N;
  int i;
  char c[3];
  struct Card C1[36], C2[36];

  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%s", c);
    C1[i].suit = c[0];
    C1[i].value = c[1];
  }

  for(i = 0; i < N; i++){
    C2[i] = C1[i];
  }
  BubbleSort(C1, N);
  trace(C1, N);
  printf("Stable\n");

  SelectionSort(C2, N);
  trace(C2, N);
  if(judge(C1, C2, N)){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  return 0;
}


void BubbleSort(Card C[], int N){
  int i, j;

  for(i = 0; i < N; i++){
    for(j = N-1; j > i; j--){
      if(C[j].value < C[j-1].value){
        Card t;
        t = C[j];
        C[j] = C[j-1];
        C[j-1] = t;
      }
    }
  }
}

void SelectionSort(Card C[], int N){
  int i, j, minj;

  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(C[j].value < C[minj].value) minj = j;
    }
    Card t;
    t = C[i];
    C[i] = C[minj];
    C[minj] = t;
  }
}

void trace(Card C[], int N){
  int i;
  for(i = 0; i < N; i++){
    printf("%c%c",C[i].suit, C[i].value);
    if(i == N-1){
      printf("\n");
    }else{
      printf(" ");
    }
  }
}

int judge(Card C1[], Card C2[], int N){
  int i;
  for(i = 0; i < N; i++){
    if(C1[i].suit != C2[i].suit)
      return 0;
  }
  return 1;
}



Measured memory_bytes: 3228
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        count = 0
        for a in range(1, n+1):
            for b in range(1, n+1):
                c = x - a - b
                if 0 < a < b < c <= n:
                    count += 1
        print(count)


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(a>b) swap(a,b);
	if(a<c && c<b){
		cout << "Yes";
	}else{
		cout << "No";
	}
	
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n;
  cin>>n;
  int r = 0;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i+=2)
  {
    if(a[i]&1)
      r++;
  }
  cout<<r;
  
return 0;
}

Measured memory_bytes: 3548
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
#define INF(x) numeric_limits<x>::max()
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif   

 	int n; cin >> n;
 	vl h(n); repa(i, n) cin >> h[i];

 	vl dp(n); dp[0] = 0, dp[1] = abs(h[1] - h[0]);
 	rep(i, 2, n) 
 		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
 	  	
 	cout << dp[n - 1] << endl;
 		
    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 4744