akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()

k,s = [tmp.pop(0) for i in range(2)]

c=0
for i in range(k,-1,-1):
    if i<=s:
        for j in range(k,-1,-1):
            if 0<=s-i-j and s-i-j<=k:
                c += 1

print(c)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	LL A, B, N;
	cin >> A >> B >> N;

	LL best = 0;

	for (LL x = 0; x <= min(A + 1, N); x++) {
		best = max(best, (A * x) / B - A * (x / B));
	}

	LL x = min(B - 1, N);
	best = max(best, (A * x) / B - A * (x / B));
	cout << best << endl;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, K;
int x[100], y[100];
Pll p[100];

bool check(int top, int bottom, int right, int left) {
  int cnt = 0;
  rep(k, 0, N) {
    int cx = x[k];
    int cy = y[k];
    if (left <= cx && cx <= right && bottom <= cy && cy <= top) {
      ++cnt;
    }
  }

  return cnt >= K;
}

int dummy[1000000];

int main() {
  cin >> N >> K;
  rep(i, 0, N) {
    cin >> x[i] >> y[i];
    p[i] = Pll(x[i], y[i]);
  }

  sort(p, p + N);

  ll ans = numeric_limits<ll>::max();
  rep(i, 0, N) {
    rep(j, 0, N) {
      ll top = p[i].second;
      ll bottom = p[j].second;
      if (bottom > top) continue;

      ll cnt = 0;
      if (bottom <= p[0].second && p[0].second <= top) {
        ++cnt;
      }

      ll r = 1;
      ll right;
      rep(l, 0, N - 1) {
        auto pl = p[l];
        ll left = pl.first;
        bool left_included = false;
        if (bottom <= pl.second && pl.second <= top) {
          left_included = true;
        }

        while (r < N && cnt < K) {
          auto pr = p[r];
          right = pr.first;
          if (bottom <= pr.second && pr.second <= top) {
            ++cnt;
          }
          ++r;
        }
        if (cnt >= K) {
          chmin(ans, (top - bottom) * (right - left));
        }
        if (left_included) {
          --cnt;
        }
      }
    }
  }

  cout << ans << endl;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int h,w;
    cin >> h>>w;
    vector<string> a(h);
    REP(i, h) { cin >> a[i]; }
    int ans=0;
    queue<pint> q;
    vector<vector<int>> painted(h, vector<int>(w));

    REP(i,h)REP(j,w){
        if(a[i][j]=='#'){
            q.push(make_pair(i, j));
            painted[i][j] = 1;
        }
    }
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    int count = 0;
    while(!q.empty()){
        pint x = q.front();
        q.pop();
        REP(i,4){
            int ny = x.first + dy[i];
            int nx = x.second + dx[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h&&painted[ny][nx]==0){
                q.push(make_pair(ny, nx));
                painted[ny][nx] = painted[x.first][x.second]+1;
                //ans = max(ans, painted[ny][nx]);
            }
        }
        count++;
    }

    REP(i, h){
    REP(j, w)
    {
        //cout << painted[i][j] << " ";
        ans = max(ans, painted[i][j]);
    }
    //cout << "\n";
    }

    cout << ans-1 <<"\n";

    return 0;
}

Measured memory_bytes: 13456
#include<iostream>

using namespace std;

int main(){
  int i,j,n,ab=0,Bo=0,oA=0,BA=0;
  string buf;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>buf;

    if(buf[buf.size()-1]=='A'){
      if(buf[0]=='B') BA++;
      else oA++;
    }
    else if(buf[0]=='B') Bo++;

    for(j=0;j<buf.size()-1;j++){
      if(buf.substr(j,2)=="AB"){
        ab++;
      }
    }
  }

  if(BA>0){
    ab=ab+BA-1;
    if(oA>0){
      ab++;
      oA--;
    }
    if(Bo>0){
      ab++;
      Bo--;
    }
  }

  if(Bo>oA) ab+=oA;
  else  ab+=Bo;

  cout<<ab<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int A, B;
	cin >> A >> B;
	if (A >= 13)cout << B;
	else if (A >= 6 && A <= 12)cout << B / 2;
	else cout << 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<fstream>
using namespace std;
int main()
{
    char s[1000008]={0};
    int sj=0,st=0,ss=0;
    scanf("%s",s);
    int i,j,k;
    for(i=0;s[i]!=0;i++)
    {
        if(s[i]=='S')ss++;
        else if(s[i]=='T')
        {
            if(ss==0)st++;
            else
            {
                ss--;
            }
        }
    }
    printf("%d\n",ss+st);
    return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int> v(N);

  for(int i=0; i < N; i++){
    cin >> v.at(i) ;
    if(N % 2 == 0){
      v.at(i) = v.at(i) -1;
    }
  }

  if(N % 2 == 1){
    v.push_back(0);
  }

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

  bool chk = true;
  for(int i = 0; i < v.size(); i+=2){
    cerr << "i: " << i << " v: " << v.at(i) << " " << v.at(i+1) << endl;

    if(v.at(i) != v.at(i+1) || v.at(i) != i){
      chk = false;
      //break;
    }
  }
  long long ans = 1;
  long long MOD = 1000000000 + 7;

  for(int i=0; i < N/2; i++){
    ans = ans * 2;
    ans %= MOD;
  }

  if(chk) cout << ans << endl;
  else cout << 0 << endl;

  
}


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

int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector< vector<int> > C(N+1, vector<int>(N+1,0));
  for(int i = 0; i < M; ++i){
    int l, r;
    cin >> l >> r;
    ++C[l][r];
  }
  for(int i = 0; i <= N; ++i)
    for(int j = 0; j < N; ++j)
      C[i][j+1] += C[i][j];
  for(int i = 0; i < N; ++i)
    for(int j = 0; j <= N; ++j)
      C[i+1][j] += C[i][j];
  for(int i = 0; i < Q; ++i){
    int p, q;
    cin >> p >> q;
    --p;
    cout << C[q][q] - C[p][q] - C[q][p] + C[p][p] << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
s=input()
sdic={}
flag=False
for i in range(len(s)):
  if(s[i] in sdic):
    sdic[s[i]]+=1
  else:
    sdic[s[i]]=1
for i in sdic:
  if(sdic[i]%2==1):
    flag=True
    break
if(flag):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
#define ll long long
ll dp[101][100005];
int main()
{
  fin;
  int n,mod=1000000007,i,j,k;
  cin>>n>>k;
  int a[n+1];
  for(i=1;i<=n;i++)
  {
    cin>>a[i];
    dp[i][0]=1;
  }

  for(i=1;i<100005;i++)
  {
    if(i<=a[1])
      dp[1][i]=dp[1][i-1]+1;
    else
      dp[1][i]=dp[1][i-1];
  }
  for(i=2;i<=n;i++)
  {
    for(j=1;j<100005;j++)
    {
      if(j<=a[i])
      {
        dp[i][j]=dp[i][j-1]+dp[i-1][j];
        dp[i][j]%=mod;
      }
      else
      {
        dp[i][j]=dp[i][j-1]+dp[i-1][j];
        dp[i][j]%=mod;
        dp[i][j]-=dp[i-1][j-a[i]-1];
        if(dp[i][j]<0)
          dp[i][j]+=mod;
      }
    }
  }
/*  for(i=1;i<5;i++)
  {
    for(j=1;j<5;j++)
      cout<<dp[i][j]<<" ";
    cout<<"\n";
  }*/
  if(k==0)
    cout<<1;
  else
  {
    ll ans=dp[n][k]-dp[n][k-1];
    if(ans<0)
      ans+=mod;
   	else
      ans%=mod;
    cout<<ans;
  }
}


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

int main () {
  int coin[3], n;
  cin >> coin[0] >> coin[1] >> coin[2] >> n;
  
  int dp[10000];
  memset(dp, sizeof(dp), 0);
  dp[0] = 1;
  
  for (int i = 0; i < 3; i++) {
    for (int j = coin[i]; j < 4000; j++) {
      dp[j] += dp[j - coin[i]];
    }
  }
  
  cout << dp[n] << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char x[2];
	int n[2],i;
	scanf("%c %c",&x[0],&x[1]);
	for(i=0;i<=1;i++){
		if(x[i]=='A')n[i]=10;
		else if(x[i]=='B')n[i]=11;
		else if(x[i]=='C')n[i]=12;
		else if(x[i]=='D')n[i]=13;
		else if(x[i]=='E')n[i]=14;
		else if(x[i]=='F')n[i]=15;
	}
	if(n[0]<n[1])printf("<\n");
	else if(n[0]==n[1])printf("=\n");
	else if(n[0]>n[1])printf(">\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

namespace C___Divide_the_Problems
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var di = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

            Console.WriteLine(di[N / 2] - di[N / 2 - 1]);
        }
    }
}


Measured memory_bytes: 21600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int a[10];
    int k;

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

    cin >> k;

    if (a[4] - a[0] > k)
    {
        cout << ":(" << endl;
        return 0;
    }

    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d', $x, $y);

$group = [
    1 => 1,
    2 => 3,
    3 => 1,
    4 => 2,
    5 => 1,
    6 => 2,
    7 => 1,
    8 => 1,
    9 => 2,
    10 => 1,
    11 => 2,
    12 => 1,
];

if ($group[$x] === $group[$y]) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;


Measured memory_bytes: 15740
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int x;
	cin>>x;
	vector<bool> expo(x+1);
	expo[1]=1;
	for(int i=2;i<=int(sqrt(x));i++){
		int v=i*i;
		while(v<=x){
			expo[v]=1;
			v*=i;
		}
	}
	for(int i=x;i>=1;i--)
		if(expo[i]){
			cout<<i<<endl;
			return 0;
		}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int,int> a[100005];
int main(){
    iostream::sync_with_stdio(0);
    long long res = 0;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i].first >> a[i].second, res += a[i].first;
    long long tmp = res;
    for(int i=1;i<=n;i++){
        if (a[i].first > a[i].second)
            tmp = min(tmp, (long long)a[i].second);
    }
    cout << res - tmp;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int M = 35;
int d[M][M], cnt[3][M];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, C;
	cin>>n>>C;
	for(int i = 1; i <= C; i++){
		for(int j = 1; j <= C; j++){
			cin>>d[i][j];
		}
	}
	memset(cnt, 0, sizeof(cnt));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			int x; cin>>x;
			cnt[(i+j)%3][x]++;
		}
	}
	int col[3];
	ll ans = LLONG_MAX;
	for(col[0] = 1; col[0] <= C; col[0]++){
		for(col[1] = 1; col[1] <= C; col[1]++){
			for(col[2] = 1; col[2] <= C; col[2]++){
				if(col[0] == col[1] || col[1] == col[2] || col[2] == col[0])continue;
				ll cost = 0;
				for(int i = 0; i < 3; i++){
					for(int j = 1; j <= C; j++){
						cost += cnt[i][j]*1LL*d[j][col[i]];
					}
				}
				ans = min(ans, cost);
			}
		}
	}
	cout<<ans<<'\n';

	return 0;
}

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

int main() {
    int n, a;
    cin >> n >> a;

    if (a == 0 && n % 500 != 0) {
        cout << "No" << endl;
    } else {
        if (n % 500 <= a) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s, t;
    cin >> s >> t;
    char sames[26], samet[26];
    for( int i = 0; i < 26; ++i ) {
        sames[i] = samet[i] = 0;

    }

    for( int i = 0; i < s.size(); ++i ) {
        if( sames[s[i] - 'a'] != 0 ) {
            if( sames[s[i] - 'a'] != t[i] ) {
                cout << "No" << endl;
                return 0;

            }

        } else {
            sames[s[i] - 'a'] = t[i];

        }
        
        if( samet[t[i] - 'a'] != 0 ) {
            if( samet[t[i] - 'a'] != s[i] ) {
                cout << "No" << endl;
                return 0;

            }

        } else {
            samet[t[i] - 'a'] = s[i];

        }
    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("A.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
int a[100002];
int main(){
	init();
	int n=readint();
	while(n--)
		a[readint()]++;
	int ans=0;
	for(int i=0;i<=100000;i++){
		int now=a[i];
		if (i)
			now+=a[i-1];
		now+=a[i+1];
		ans=max(ans,now);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1152
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
left = 0
right = 0
for i in range(len(S)):
  if S[i] == ">":
    left += 1
  else:
    break
for i in range(len(S)):
  if S[len(S)-i-1] == "<":
    right += 1
  else:
    break
# print(left)
# print(right)

if right != 0:
  S = S[left:-right]
else:
  S = S[left:]

ruiseki = [0] * len(S)
r, l = 0, 0

# for i in range(len(S)):
#   if S[i] == "<":
#     # l += 1
#     ruiseki[i+] = ruiseki[i]
#   elif S[i] == ">":
#     # r += 1
#     ruiseki[i] += 1
# print(ruiseki)

left_box = []
right_box = []
# left
count = 0
for i in range(len(S)):
  if S[i] == "<":
    count += 1
  else:
    if count != 0:
      left_box.append(count)
    count = 0
if count != 0:
  left_box.append(count)
      
# print(left_box)

for i in range(len(S)):
  if S[i] == ">":
    count += 1
  else:
    if count != 0:
      right_box.append(count)
    count = 0
if count != 0:
  right_box.append(count)


# print(right_box)
  
m = []
for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  m.append(max(r, l))
# print(m)
count = 0

for i in range(len(m)):
  for j in range(1, m[i]+1):
    count += j
# print(count)

# for i in range(len(m))
ans = 0

def wa(num):
  wa = 0
  for i in range(1,num+1):
    wa += i
  return wa

def small_wa(num):
  wa = 0
  for i in range(0, num):
    wa += i
  return wa

for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  b = max(r, l)
  s = min(r, l)
  a = small_wa(s) + wa(b)
  ans += a
  # print(a)


# nokori
ans += wa(left) + wa(right)
print(ans)




Measured memory_bytes: 13244
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
long long moduloMultiplication(long long a,
                               long long b,
                               long long mod)
{
    long long res = 0; // Initialize result

    // Update a if it is more than
    // or equal to mod
    a %= mod;

    while (b)
    {
        // If b is odd, add a with result
        if (b & 1)
            res = (res + a) % mod;

        // Here we assume that doing 2*a
        // doesn't cause overflow
        a = (2 * a) % mod;

        b >>= 1; // b = b / 2
    }

    return res;
}
int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans;
    ans = max({a * c, b * d, a * d, b * c});
    if ((b == 0 and c > 0) or (d == 0 and a > 0))
    {
        ans = 0;
    }
    cout << ans;
}


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

using namespace std;
#define fordebug int hogeko;cin>>hogeko;
#define DEKAI 1000000007
#define INF 1000000000
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
signed main(){
	int dp[100200];
	int n,k;
	cin>>n>>k;
	int a[100000];
	lp(i,n+200){
		dp[i]=INF;
	}
	lp(i,n){
		cin>>a[i];
	}
	dp[0]=0;
	lp(i,n-1){
		lps(j,1,k+1){
			dp[i+j]=min(dp[i]+abs(a[i]-a[i+j]),dp[i+j]);
		}
	}
	cout<<dp[n-1]<<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();

        for (int i = 1; i <= n; i++) {
            float tmp = (float) (i * 1.08);
            if (Math.floor(tmp) == n) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(":(");
    }
}

Measured memory_bytes: 21972
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
bool pal(string s)
{
    string tmp = s;
    reverse(tmp.begin() , tmp.end());
    return tmp == s;
}
int main()
{
    abdelrahman010
    string s;
    cin >> s;
    string p1 = s.substr(0 , s.size() / 2);
    string p2 = s.substr(s.size() / 2 + 1);
    if(pal(s) && pal(p1) && pal(p2))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int main() {
  ioinit();
  string s;
  int K,N;
  cin >> N >> K >> s;
  s[K-1] += 32;
  
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  double n;
  cin >> n;
  double x = n/1.08;
  int a = x;
  double b = a;
  int c = b*1.08;
  int d = (b+1)*1.08;
  if(c==n){
    cout << b << endl;
  }else if(d==n){
    cout << b+1 << endl;
  }else{
    cout << ":(" << endl;
  }
  // cout << c << endl;
  // cout << d << endl;
  return 0;
}


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

using namespace std;

#define ll  long long
#define ld long double
#define f first
#define s second
#define matrix vector<vector<char>>
#define zero(n,m) matrix(n , vector<char>(m,'0'))
#define one(n,m) matrix(n , vector<ll>(m,1))
#define pii pair<int,int>
#define point complex<ld>
#define angle(a) (atan2((a).imag() , (a).real() ))
#define pi acos(-1)
#define X real()
#define Y imag()
const int N = 2e5+5;

vector< pair<int,int> > v;
ll n , k , dp[N] , mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;
    for(int i=1; i<=k; i++)
    {
        int x,y;
        cin >> x >> y;
        v.push_back({x,y});
    }

    dp[1]=1;
    for(int i=2; i<=n; i++)
    {
        ll l , r , tmp;
        for(int j=0; j<v.size(); j++)
        {
            l = i-v[j].s-1 , r = i-v[j].f;
            l = max(l , (ll)0);

            if (l < r)
            {
                tmp = (dp[r]-dp[l]+mod)%mod;
                dp[i] = (dp[i]+tmp)%mod;
            }
        }

        dp[i] = (dp[i]+dp[i-1])%mod;
    }

    cout << (dp[n]-dp[n-1]+mod)%mod << '\n';

    return 0;
}

Measured memory_bytes: 5216
#include<stdio.h>

int main(void){

int i,n;

int number;


long long int sum=0;


int min=0;


int max=0;


scanf("%d",&n);


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


scanf("%d",&number);


if(i==0){


min=number;


max=number;


}


if(number<min)min=number;


if(number>max)max=number;


sum+=number;


}


printf("%d %d %lld\n",min,max,sum);


return 0;


}

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

int main() {
    int a1, a2, a3;
    scanf("%d%d%d", &a1, &a2, &a3);
    if(a1+a2+a3>=22)
        printf("bust\n");
    else
        printf("win\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
map<long long,int> mp;
int main(){
	long long i,n,p,ans = 1,t;
	cin >> n >> p;
	for(i=2;i*i<=p;i++){
		while(p%i==0 && p!=1){
			p /= i;
			mp[i]++;
		}
	}
	if(p!=1){
		mp[p]++;
	}
	for(auto x:mp){
		long long k = x.second/n;
		t = 1;
		for(i=0;i<k;i++){
			t *= x.first;
		}
		ans *= t;
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define MAX_N 8
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int G[MAX_N][MAX_N];
int N;

int dfs(int flags, int now) {
    if (flags == (1 << (N-1)) - 1) return 1;
    int score = 0;
    for (int i = 1; i < N; i++) {
        score += ((flags & (1 << (i-1))) == 0 && G[now][i] > 0) ? dfs(flags + (1 << (i-1)), i) : 0;
    }
    return score;
}

int main() {
    int M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a][b] = 1;
        G[b][a] = 1;
    }

    cout << dfs(0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e5+10;
const int N = 1e5+10;
const int E = 2e5+10;  
ll n,m; 
ll x;

int main(){
	ll sum = 0;
	cin>>n>>m;
	F(i,1,m){
		cin>>x;
		sum+=x; 
	} 
	n-=sum;
	if(n<0) n = -1;
	cout<<n<<endl;
}
/*
double r;
	cin>>r;
	r = acos(-1)*2.0*r;
	printf("%.10lf\n",r);
	*/

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=1e9+7; 
void cint(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	pf("%lld %lld %lld\n",c,a,b);
}
int main(){
  	cint();
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int n,m; cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n;

	int a[3]={0,0,0};



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

	}

	

		for(int j=1;j<=100000000;j++)
		{

			if(a[0]%j==0&&a[1]%j==0&&a[2]%j==0)
			{

			cout<<j<<endl;
			}
		}


		return 0;

	}






Measured memory_bytes: 3096
#include<stdio.h>

int main(void){

int a,b;

scanf("%d %d",&a,&b);

if(a<=b){for(int i=0;i<b;i++){printf("%d",a);}}
if(b<a){for(int i=0;i<a;i++){printf("%d",b);}}

return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}

bool det(int n) {
    int cnt=0;
    while(n!=0) {
        cnt++;
        n/=10;
    }
    if(cnt%2!=0)return true;
    return false;
}

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n;
    cin>>n;
    int count=0;
    for(int i=1;i<=n;++i) {
        if(det(i))++count;
    }

    cout<<count<<endl;
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o') {
    cout << "vowel" << endl;
  }
  
  else {
    cout << "consonant" << endl;
  }
}
  
  


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))
d_lis=sorted(d)
ans=0
if d_lis[n//2-1]==d_lis[n//2]:
  ans=0
else:
  ans=d_lis[n//2]-d_lis[n//2-1]
print(ans)

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int res = 0;

    for (int i = 0; i <= (n+r-1)/r; ++i){
        for (int j = 0; j <= (n+g-1)/g; ++j){
            if((n - (r*i + g*j)) >= 0 && ((n - (r*i + g*j)) % b == 0)) {
                ++res;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	static HashSet<String>HS;
	static int a[];
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int k=in.nextInt();
			int p[]=new int[k];
			boolean f[]=new boolean[n];
			a=new int[n];
			HS=new HashSet<String>();
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			permutation(0,p,f);
			System.out.println(HS.size());
		}
	}

	static void permutation(int n,int p[],boolean f[])
	{
		if(n==p.length)
		{
			String str="";
			for(int x:p)
				str+=x;
			HS.add(str);
		}
		else 
		{
			for(int i=0;i<a.length;i++)
			{
				if(f[i]) 
					continue;
				p[n]=a[i];
				f[i]=true;
				permutation(n+1,p,f);
				f[i]=false;
			}
		}
	}
}

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

int main(void)
{
    long X ;
    cin >> X;
    long K;
    cin >> K;
    long D;
    cin >> D;

    if(abs(K * D) >= abs(X)){
        if((X >= 0 && D >= 0) || (X < 0 && D < 0)){
            long amari = X / D;
            long kaisuu = K - amari;
            if(kaisuu % 2 == 0){
                X = X - (amari * D);
            }else{
                X = X - ((amari + 1) * D);
            }
        }else{
            long amari = -1 * X / D;
            long kaisuu = K - amari;
            if(kaisuu % 2 == 0){
                X = X + (amari * D);
            }else{
                X = X + ((amari + 1) * D);
            }
        }
    }else{
        if((X >= 0 && D >= 0) || (X < 0 && D < 0)){
            X = X - (D * K);
        }else{
            X = X + (D * K);
        }
    }

    X = abs(X);

    cout << X << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int d,n,i,j=1;
  scanf("%d%d",&d,&n);
  for(i=0;i<d;i++)
    j*=100;
  if(n!=100)
    printf("%d\n",n*j);
  else
    printf("%d\n",(n+1)*j);
  return 0;
}


Measured memory_bytes: 128
import bisect
N = int(input())
l = list(map(int, input().split()))
ans = 0
tmp = 0
l.sort()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        tmp = bisect.bisect_left(l, l[i] + l[j])
        ans += tmp - j - 1

print(ans)


Measured memory_bytes: 44588
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int a[105];

int main()
{
	IO_OP;
	
	int n, k, mx = 0;
	cin >> n >> k;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int take=0;take<=k && take<=n;take++) {
		int put = k - take;
		for(int left=0;left<=take;left++) {
			int right = take - left;
			vi v;
			for(int i=0;i<left;i++)
				v.PB(a[i]);
			for(int i=n-1;i>=n-right;i--)
				v.PB(a[i]);
			sort(v.begin(), v.end());
			int ps = 0, csm = 0;
			for(int i:v)
				csm += i;
			for(int i=0;i<put&&i<v.size();i++)
				if(v[i] < 0)
					ps+=v[i];
			mx = max(mx, csm - ps);
		}
	}
	cout << mx << endl;
	
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <sstream> //string stream
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector>
#include <algorithm>    // swap,sort,binary_search
#include <functional>   //greater
#include <map> //map
#include<set> //set
#include<queue>
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include<bitset>
#include <iomanip> //cout<<setprecision
using namespace std;
typedef long long ll;
#define rep(i,s,t) for(int i = s; i<t;i++)
const ll wari = 1000000007;

//omajinai yukue humei

int main(){
    int n,k; cin>>n>>k;
    vector<int> d(k);
    for(int i = 0 ; i<k;i++) cin>>d[i];
    int ans;
    for(int i = n;;i++){
        string x = to_string(i);
        if(all_of(x.begin(),x.end(),[d](char c){
            int i = c - '0';
            return(none_of(d.begin(), d.end(), [i](int j){ return j == i;}));
        })){ans = i; break;}
    }
    cout<<ans<<endl;
    
}


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

int main() {
  int n;
  cin >> n;

  if (n/10%10 < n/100%10 || (n/10%10  == n/100%10 && n%10 <= n/100%10)) {
    cout << n/100%10*100 + n/100%10*10 + n/100%10 << endl;
  }
  else {
    cout << (n/100%10+1)*100 + (n/100%10+1)*10 + n/100%10+1 << endl;
  }

}


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

using namespace std;

int main() {
    string str; cin >> str;
    int ascii[26] = {};
    for (char s: str) ++ascii[s - 97];
    bool isBeautiful = true;
    for (auto e: ascii) {
        isBeautiful = e % 2 == 0 ? true : false;
        if (!isBeautiful) break;
    }

    cout << (isBeautiful ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>

int selectionSort(int A[], int N) {
  int cnt = 0;
  for ( int i = 0; i < N; i++ ) {
    int min = i;
    for ( int j = i; j < N; j++ ) {
      if ( A[min] > A[j]) min = j;
    }
    if ( min != i ) {
      int t = A[min]; A[min] = A[i]; A[i] = t;
      cnt++;
    }
  }
  return cnt;
}



int main() {
  int N, cnt = 0;
  int A[100];

  scanf("%d", &N);
  for ( int i = 0; i < N; i++ ) scanf("%d", &A[i]);

  cnt = selectionSort(A, N);

  for ( int i = 0; i < N; i++ ) {
    if ( i ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");

  printf("%d\n", cnt);

  return 0;
}



Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           bool ok=0;
           while(n){
             if(n%10==9)ok=true;
            n/=10; 
           }
           Yes(ok);
}

Measured memory_bytes: 3628
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    string S, T;

    cin >> S >> T;

    auto check = [&](const string& s, const string& t) {
        int n = s.length();
        if (n == t.length()) {
            for (int i = 0; i < n; ++i) {
                if (s[i] == t[i] || s[i] == '?') {

                } else {
                    return false;
                }
            }
            return true;
        }
        return false;
    };


    string res;
    int n = S.length(), m = T.length();
    for (int i = 0; i + m <= n; ++i) {
        if (check(S.substr(i, m), T)) {
            string s = S.substr(0, i);
            s += T;
            s += S.substr(i + m);
            for (auto& c : s) {
                if (c == '?') {
                    c = 'a';
                }
            }
            if (res.empty()) {
                res = s;
            } else {
                res = min(res, s);
            }
        }
    }

    if (res.empty()) {
        cout << "UNRESTORABLE" << '\n';
    } else {
        cout << res << '\n';
    }


    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,ans=0,num,maki;
    cin>>n;
    multiset<ll> ms;
    for(int i=0;i<n;i++){
        cin>>a;
        ms.insert(a);
    }
    while(!ms.empty()){
        num=*ms.rbegin();
        ms.erase(ms.find(num));
        maki=1;
        while(maki<=num)maki*=2;
        if(ms.count(maki-num)){
            ms.erase(ms.find(maki-num));
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9600
N = int(input())
p = list(map(int, input().split()))

cnt = 0

for i in range(len(p)):
    if p[i] == i+1:
        if p[i] == N:
            p[i-1], p[i] = p[i], p[i-1]
        else:
            p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
    
print(cnt)


Measured memory_bytes: 53036
#include "iostream"
#include "algorithm"

using namespace std;
typedef long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  int h[100010];
  for (int i = 0; i < n; i++)
  {
    cin >> h[i];
  }
  sort(h, h + n);
  int min = h[k - 1] - h[0];
  for (int i = 0; i < n - k + 1; i++)
  {
    if (min > (h[i + k - 1] - h[i]))
    {
      min = (h[i + k - 1] - h[i]);
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 768
# -*- codnig utf-8 -*-
n = int(input())
chars = list(input())

for i, c in enumerate(chars):
    code = ord(c)+n
    if code >90:
        chars[i] = chr(ord(c)+n-26)
    else:
        chars[i] = chr(ord(c)+n)
print("".join(chars))


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

int main() {
  int n;
  cin >> n;

  int count = 0;

  rep2(i, n) if (to_string(i).length() % 2 == 1) count++;

  cout << count << endl;
  return 0;
}


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

int main()
{
    int a, b, c, cn = 0, max = -1;
    cin >> a;
    for (int i = 0; i < a; i++)
    {
        cin >> b >> c;
        if (b == c) cn++;
        if (b != c) 
        {
            if (max < cn) max = cn;
            cn = 0;
        }
    }
    if (max >= 3 || cn >= 3) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3640
n, m, point = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
reverse_graph = Array.new(n+1) { [] }
edges = []

abc.each do |a, b, c|
  edges << [a, b, (c-point)*-1]
  graph[a] << [b, (c-point)*-1]
  reverse_graph[b] << [a, (c-point)*-1]
end

def reachable(graph, s)
  visit = []
  visit.push(s)
  q=[s]
  until q.empty?
    u=q.shift
    graph[u].each do |n, _|
      next if visit.include?(n)
      visit.push(n)
      q.push(n)
    end
  end
  visit
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
retrenched_nodes = (1..n).to_a.select {|t| reachable_from_s.include?(t) && reachable_to_g.include?(t) }

edges = edges.select {|from, to,  _| retrenched_nodes.include?(from) && retrenched_nodes.include?(to) }

INF = 10**9
dist = Array.new(n+1, INF)
dist[1]=0
c=0

loop do
  updated = false
  edges.each do |from, to, cost|
    if dist[from] != INF && dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated=true
    end
  end
  break unless updated
  c+=1
  if c==n
    p -1
    exit
  end
end

p [-dist[n], 0].max


Measured memory_bytes: 3324
#include <iostream>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;
    
    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
    void Rotation(){
        int t=n2;
        n2 = n3;
        n3 = n5;
        n5 = n4;
        n4 = t;
    }
};

int main() {
    Dice d1;
    Dice d2;
    
    cin >> d1.n1 >> d1.n2 >> d1.n3 >> d1.n4 >> d1.n5 >> d1.n6;
    cin >> d2.n1 >> d2.n2 >> d2.n3 >> d2.n4 >> d2.n5 >> d2.n6;
 
    if(d1.n3==d2.n1 || d1.n4==d2.n1){
        d1.East();
    }
        for(int i=0; i<4; i++){
            if(d2.n1==d1.n1)break;
            d1.North();
        }
        for(int i=0; i<4; i++){
            if(d2.n2==d1.n2)break;
            d1.Rotation();
        }
        
        if(d1.n1==d2.n1 && d1.n2==d2.n2 && d1.n3==d2.n3 && d1.n4==d2.n4 && d1.n5==d2.n5 && d1.n6==d2.n6){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    
    return 0;
}

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

int n, k, x[100];

int getpoint() {
	if (n < k) { return 0; }
	int sum = 1, maxd = 1;
	for (int i = 0; i < k; i++) {
		sum *= x[i];
	}
	maxd = sum;
	for (int i = 0; i < n - k; i++) {
		sum /= x[i];
		sum *= x[i + k];
		maxd = max(maxd, sum);
	}
	return maxd;
}

int main() {
	while (true) {
		cin >> n >> k;
		if (n == 0 && k == 0) { break; }
		for (int i = 0; i < n; i++) { cin >> x[i]; }
		int point = getpoint();
		int maxn = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int a = x[i], b = x[j];
				x[j] = a; x[i] = b;
				maxn = max(maxn, getpoint());
				x[i] = a; x[j] = b;
			}
		}
		if (point > maxn) { cout << "NO GAME" << endl; }
		else { cout << maxn - point << endl; }
	}
	return 0;
}

Measured memory_bytes: 1164
ans = Array.new(3){Array.new(3)}
ans[0][0] = gets.to_i
ans[0][1] = gets.to_i
ans[1][1] = gets.to_i

s = 3 * ans[1][1]

ans[2][1] = s - ans[0][1] - ans[1][1]
ans[0][2] = s - ans[0][0] - ans[0][1]
ans[2][0] = s - ans[0][2] - ans[1][1]
ans[2][2] = s - ans[0][0] - ans[1][1]
ans[1][0] = s - ans[0][0] - ans[2][0]
ans[1][2] = s - ans[0][2] - ans[2][2]

ans.each do |row|
    puts row.join(' ')
end

Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cake = 4;
        int donuts = 7;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j ++) {
                int total = cake * i + donuts * j;
                if (total == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 22868