akhauriyash/Code-Regression huggingface dataset:
import collections
N, M = map(int, input().split())
A = collections.Counter(list(map(int, input().split())))

for _ in range(M):
  B, C = map(int, input().split())
  A[C] += B

A = sorted(A.items(), key=lambda x:x[0], reverse=True)

ans = 0
for key, count in A:
  if N > count:
    ans += key * count
    N -= count
  else:
    ans += key * N
    break

print(ans)


Measured memory_bytes: 42656
#include<bits/stdc++.h>
using namespace std;
char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main(){
	long long n,x=26,i=0,now,next;
	
	cin>>n;
	--n;
	
	while(n-x>=0){
		n-=x;
		x*=26;
		i++;
	}
	
	next=n;
	
	if(i==0){
		cout<<a[n]<<endl;
		return 0;
	}
	if(n==0)
	for(int j=1;j<=i+1;j++) cout<<'a';
	else
	for(int j=1;j<=i+1;j++){
		x/=26;
		now=next/x,next%=x;
		cout<<a[now];
	}
	
	return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

long long mod_pow(long long a, long long n, long long mod) {
	long long ret = 1;
	while(n != 0) {
		if(n % 2) {
			ret = (ret * a) % mod;
		}
		a = (a * a) % mod, n /= 2;
	}
	return ret;
}

// modの逆元
long long mod_inv(long long n, long long mod) {
	return mod_pow(n, mod - 2, mod);
}

ll mod_sub(ll a, ll b) {
	ll retval = a - b;
	if(retval < 0) {
		retval += MODNUM;
	}
	return retval;
}

ll mod_comb(ll n, ll r) {
	int retval = 1;
	chmin(r, n - r);
	REP(i, r) {
		retval = MOD(MOD(retval * (n - i)) * mod_inv((i + 1), MODNUM));
	}
	return retval;
}

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	ll all = mod_sub(mod_pow(2, n, MODNUM), 1);
	printf("%lld\n", mod_sub(mod_sub(all, mod_comb(n, a)), mod_comb(n, b)));
	return 0;
}

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

ll func1(ll n,int p){
    if(n==0) return 0;
    return n/p + func1(n/p,p);
}

ll func2(ll n,int p){
    if(n%2==1) return 0;
    ll r=func1(n/2,p);
    if(p==2) r+=n/2;
    return r;
}

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

    cout<<min(func2(n,2),func2(n,5))<<endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
fn main() {
    input!{
        n: u32,
        m: usize,
        ab: [u32; 2*m],
    };
    let mut map = HashMap::new();
    ab.iter().map(|x| *map.entry(x).or_insert(0) += 1).count();
    (1..n+1).map(|x| println!("{}", map.get(&x).unwrap_or(&0))).count();
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

void no() {
  puts("NO");
  exit(0);
}

void putVer(int i, int j, vector<string>& ret) {
  ret[i][j] = '^';
  ret[i+1][j] = 'v';
}

void putHor(int i, int j, vector<string>& ret) {
  ret[i][j] = '<';
  ret[i][j+1] = '>';
}

void solve(int N, int M, int A, int B, vector<string>& ret) {
  bool odd = N%2 && M%2 && N >= 3 && M >= 3;

  if (N % 2 == 1) {
    for (int i = 0; i + 1 < M; i += 2) {
      if (odd && i >= M-3) continue;
      if (A > 0) putHor(N-1, i, ret), A--;
    }
  }
  if (M % 2 == 1) {
    for (int i = 0; i + 1 < N; i += 2) {
      if (odd && i >= N-3) continue;
      if (B > 0) putVer(i, M-1, ret), B--;
    }
  }

  for (int i = 0; i + 1 < N; i += 2) {
    for (int j = 0; j + 1 < M; j += 2) {
      if (odd && i+1 >= N-3 && j+1 >= M-3) continue;
      if (A >= 2 && A >= B) {
        putHor(i, j, ret);
        putHor(i+1, j, ret);
        A -= 2;
      } else if (B >= 2) {
        putVer(i, j, ret);
        putVer(i, j+1, ret);
        B -= 2;
      } else if (A >= 1) {
        putHor(i, j, ret);
        A--;
      } else if (B >= 1) {
        putVer(i, j, ret);
        B--;
      }
    }
  }

  if (odd) {
    if (A <= 1) {
      if (B > 3) no();
      REP(i, B) putVer(N-3, M-3+i, ret);
      if (A == 1) putHor(N-1, M-3, ret);
    } else if (B <= 1) {
      if (A > 3) no();
      REP(i, A) putHor(N-3+i, M-3, ret);
      if (B == 1) putVer(N-3, M-1, ret);
    } else if (A == 2 && B == 2) {
      putHor(N-3, M-3, ret);
      putVer(N-3, M-1, ret);
      putVer(N-2, M-3, ret);
      putHor(N-1, M-2, ret);
    } else {
      no();
    }
  } else {
    if (A > 0 || B > 0) no();
  }
}

int main(void) {
  int N, M, A, B;
  scanf("%d %d %d %d", &N, &M, &A, &B);
  vector<string> ret(N, string(M, '.'));

  solve(N, M, A, B, ret);

  puts("YES");
  REP(i, N) puts(ret[i].c_str());
  return 0;
}


Measured memory_bytes: 2304
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

M =998244353

n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]* (s+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = pow(2,i,M)
for i in range(1,n+1):
    for j in range(1,s+1):
        dp[i][j] = dp[i-1][j]*2
        if j>=a[i-1]:
             dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= M
print(dp[n][s])

Measured memory_bytes: 132512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

char b;

int main(){
  cin >> b;
  switch (b){
    case 'A':
      cout << 'T' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
  }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string a;
int main(){
    cin>>a;
    for(int i=0;i<a.size();i++){
    	if(i%2){
    		if(a[i]=='L'||a[i]=='U'||a[i]=='D')continue;
    		else{
    			printf("No\n");return 0;
			}
		}
		else{
			if(a[i]=='R'||a[i]=='U'||a[i]=='D')continue;
    		else{
    			printf("No\n");return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";t.__esModule=!0;var r=n(1),o=n(2),u=r.readFileSync("/dev/stdin","utf8").split("\n");console.log(o.solveA(u))},function(e,t){e.exports=require("fs")},function(e,t,n){"use strict";t.__esModule=!0,t.solve=function(e){var t=e[0],n=e[1],r=e[2],o=Number(t),u=n.split(" ").map(Number);return o+u[0]+u[1]+" "+r},t.solveA=function(e){return e[0].split("").filter(function(e){return"2"===e}).length}}]);

Measured memory_bytes: 21064
s = input()
ans = 'WA'
if s[0] == 'A' and s[2:len(s)-1].count('C') == 1:
  s = s.replace('A', '').replace('C', '')
  if all([i in [chr(i) for i in range(97, 97+26)] for i in s]):
    ans = 'AC'
print(ans)

Measured memory_bytes: 9004
from collections import Counter

n=int(input())
v=list(map(int,input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
c1=[(0,0)]+sorted(Counter(v1).items(), key=lambda x:x[1])
c2=[(0,0)]+sorted(Counter(v2).items(), key=lambda x:x[1])

if c1[-1][0]!=c2[-1][0]:
    print(len(v1)-c1[-1][1] + len(v2)-c2[-1][1])
else:
    if c1[-2][1]<=c2[-2][1]:
        print(len(v1)-c1[-1][1] + len(v2)-c2[-2][1])
    else:
        print(len(v1)-c1[-2][1] + len(v2)-c2[-1][1])

Measured memory_bytes: 21212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int mod = 998244353;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
int main(){
    int n;cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int mx=0;
    rep(i,n) mx=max(mx,d[i]);
    vector<int> num[mx+1];
    rep(i,n){
        num[d[i]].push_back(i+1);
    }
    if(d[0]!=0||(int)num[0].size()!=1){
        cout << 0 << endl;
        return 0;
    }
    mint ans=1;
    rrep(i,mx){
        mint x=mint(num[i-1].size()).pow(num[i].size());
        ans*=x;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 6144
<?php
$s = trim(fgets(STDIN));
$s_array = array_map("trim", str_split($s));
$ans = "Good";
for($i=0; $i<3; $i++){
	if($s_array[$i] === $s_array[$i+1]){
		$ans = "Bad";
	}
}
echo $ans . "\n";
?>

Measured memory_bytes: 4728
import bisect
import  collections

N = int(input())
A = [int(input()) for _ in range(N)]

x = collections.deque()

for i, a in enumerate(A):
    if i == 0:
        x.append(a)
    else:
        r = bisect.bisect_left(x, a)
        if r == 0:
            x.appendleft(a)
        else:
            x[r - 1] = a

print(len(x))


Measured memory_bytes: 8060
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353//1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 2005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int x;
   cin>>x;
   int g=__gcd(x,360LL);
   cout<<(360/g)<<endl;

}


Measured memory_bytes: 3612
import numpy as np
N, L = map(int, input().split())

a = np.array(range(1,N+1))
t = a + L - 1

s = t.sum()

min = 90000000
min_ans = -90000000
for i in range(len(t)):
    x = abs(s - (s - t[i]))
    if x < min:
        min = x
        min_ans = s - t[i]

print(min_ans)


Measured memory_bytes: 12764
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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


int main(void) {
    int i,j;
    int n;
    string s;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int sum = 0;
    rep(i,n)sum += a[i];
    int diff = INF, ans;
    rep(i,n)if(abs(a[i]*n-sum)<diff){
        diff = abs(a[i]*n-sum);
        ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 764
n,q=map(int,input().split())
s=input()
t=[0]*n
for i in range(1,n+1):
    if s[i-1:i+1]=='AC':
        t[i]+=1
# print(t)
t_sum=[0]*n
for i in range(n):
    if i==0:
        t_sum[i]=t[0]
        continue
    t_sum[i]=t_sum[i-1]+t[i]
# print(t_sum)
for i in range(q):
    l,r=map(int,input().split())
    print(t_sum[r-1]-t_sum[l-1])

Measured memory_bytes: 8436
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll A, B, C, K;
    scanf("%lld %lld %lld %lld", &A, &B, &C, &K);

    if (A >= K)
        printf("%lld", K);
    else if (A + B >= K)
        printf("%lld", A);
    else
        printf("%lld", A - (K - A - B));
}


Measured memory_bytes: 3828
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<=a){
		printf("%d",k);
	}
	else if(k<=a+b){
		printf("%d",a);
	}
	else if(k>a+b){
		printf("%d",a-(k-a-b));
	}
	
}


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

int main() {
	int n, k;
	cin >> n >> k;
	int a; 
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += min(a * 2, abs(k - a) * 2);
	}
	cout << ans << endl;
	return 0;
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec a(N);
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }

  sort(ALL(a), greater<int>());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (mp[a[i]] == 0) continue;

    int num = 1;
    while (num <= a[i]) {
      num *= 2;
    }

    if (num - a[i] == a[i] && mp[a[i]] == 1) continue;

    if (mp[num - a[i]] >= 1) {
      ans++;
      mp[num - a[i]]--;
      mp[a[i]]--;
    }
  }

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


Measured memory_bytes: 26752
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int[][] a = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		boolean[][] open = new boolean[3][3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (b[i] == a[j][k]) {
						open[j][k] = true;
					}
				}
			}
		}
		for (int i = 0; i < 3; i++) {
			boolean bin = true;
			for (int j = 0; j < 3; j++) {
				if (!open[i][j]) {
					bin = false;
					break;
				}
			}
			if (bin) {
				System.out.println("Yes");
				return;
			}
		}
		for (int i = 0; i < 3; i++) {
			boolean bin = true;
			for (int j = 0; j < 3; j++) {
				if (!open[j][i]) {
					bin = false;
					break;
				}
			}
			if (bin) {
				System.out.println("Yes");
				return;
			}
		}
		if ((open[0][0] && open[1][1] && open[2][2]) || (open[0][2] && open[1][1] && open[2][0])) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 23124
<?php
// Your code here!
fscanf(STDIN,"%d",$n);
$s = [];
for($i=0; $i<$n; $i++){
    $s[trim(fgets(STDIN))] += 1;
}
arsort($s);
$max = max($s);
$ss = [];
foreach($s as $k =>$t){
    if($max == $t){
        $ss[] = $k;
    }
}
sort($ss);

echo implode("\n", $ss);
?>

Measured memory_bytes: 31220
c=[list(map(int,input().split())) for _ in [0]*3]

x=[[c[i][0]-c[i][1],c[i][1]-c[i][2]] for i in range(3)]
y=[[c[0][j]-c[1][j],c[1][j]-c[2][j]] for j in range(3)]

def f(l):
    return l[0]==l[1] and l[1]==l[2]
  
print(['No','Yes'][f(x) and f(y)])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define M 1000000007
#define all(v) v.begin(), v.end()

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  for(int i=1;i<s.size();i++){
      if(s[i]==s[i-1]){
          cout<<"Bad"<<el;
          return 0;
      }
  }
  cout<<"Good";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int a[100010];
int main()
{
	int N, L;
	cin >> N >> L;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N - 1; i++) {
		if (a[i] + a[i + 1] >= L) {
			cout << "Possible" << endl;
			for (int j = 0; j < i; j++) {
				cout << j + 1 << endl;
			}
			for (int j = N - 2; j > i; j--) {
				cout << j + 1 << endl;
			}
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << "Impossible" << endl;
}

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

//最後がAだったときの幸福度のmaxを覚えておく

int main(){
    int N; cin >> N;
    int a[100100], b[100100], c[100100];
    for(int i=0; i<N; i++){
        cin >> a[i+1] >> b[i+1] >> c[i+1];
    }

    int dp[100100][3];
    dp[1][0] =a[1];
    dp[1][1] =b[1];
    dp[1][2] =c[1];
    for(int i=2; i<=N; i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout << max( {dp[N][0],dp[N][1],dp[N][2]} ) << endl;
}

Measured memory_bytes: 2560
#include <array>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_set>

using namespace std;

int main()
{
    string S;
    cin >> S;
    string a = "CODEFESTIVAL2016";
    int count = 0;
    for(int i=0; i<S.size(); i++)
        if(a[i] != S[i]) count++;
    cout << count << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int x; std::cin >> x;
    for (int i = 1; i <= 1000; i++) {
        if (i * 100 <= x && x <= i * 100 + i * 5) {
            std::cout << 1 << std::endl;
            return 0;
        }
    }
    std::cout << 0 << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)



int main() {
	lint H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) {
		cout << 1 << endl;
	}
	else if (H % 2 == 0) {
		cout << H * W / 2 << endl;
	}
	else {
		cout << (H - 1) * W / 2 + W / 2 + bool(W % 2) << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
using graph = vector<vector<int>>;

int main(){
    string s; cin >> s;
    if(s=="AAA" || s=="BBB"){
        cout << "No" << endl; return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {

    ll k,a,b;
    cin>>k>>a>>b;
    if(a>=b-2){
        cout<<k+1<<endl;
        return 0;
    }
    ll ans=1;
    if(k>a-1){
        k-=(a-1);
        ans=a;
    }
    else {
        cout<<k+1<<endl;
        return 0;
    }
    if(k%2==1){
        ans++;
        k--;
    }
    ans+=(k/2)*(b-a);
    fin(ans);
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        n: u32,
        m: usize,
        sc: [(u32, i32); m],
    }
    if m == 0 {
        if n == 1 {
            println!("{}", 0);
            return;
        } else {
            println!("{}", 10i32.pow(n - 1));
            return;
        }
    }
    let mut sc = sc;
    sc.sort();
    sc.dedup();
    let m = sc.len();
    if (0..(m - 1)).any(|i| sc[i].0 == sc[i + 1].0 )
        || (n != 1 && sc[0] == (1, 0)) {
        println!("-1");
        return;
    }
    let mut ans = 0;
    for (s , c) in sc { ans += c * 10i32.pow(n - s); }
    if n > 1 && ans < 10i32.pow(n - 1) { println!("{}", ans + 10i32.pow(n - 1)) }
    else { println!("{}", ans) }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long ln[] = {sc.nextLong() - 1, sc.nextLong()};
		boolean odd[] = {ln[0] % 2 == 1, ln[1] % 2 == 1};
		boolean odd4[] = {ln[0] % 4 == 1 || ln[0] % 4 == 2, ln[1] % 4 == 1 || ln[1] % 4 == 2};
		boolean bit[][] = new boolean[2][42];
		for(int i = 0; i < 2; i ++) {
			for(int j = 0; j < 42; j ++) {
				if(ln[i] == -1) {
					bit[i][j] = false;
					continue;
				}
				bit[i][j] = (ln[i] & (1L << j)) != 0;
				if(j == 0) {
					bit[i][j] = odd4[i];
				}else {
					bit[i][j] &= !odd[i];
				}
			}
		}
		long ans = 0;
		for(int j = 0; j < 42; j ++) {
			ans += (bit[0][j] ^ bit[1][j] ? 1 : 0) * (1L << j);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25300
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

//マクロ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
//定数
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

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

    cout << a * b << endl;
}

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

int main(){
  int h,w,count=0;
  cin >> h >> w;
  char a;
  r(i,h*w){
    cin >> a;
    if(a=='#')count++;
  }
  if(count==h+w-1)cout << "Possible"<<endl;
  else cout << "Impossible"<<endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#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<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,l,t,a[100010];
long long cnt;
int main()
{
	scanf("%d%d%d",&n,&l,&t);
	for (int i=0;i<n;i++)
	{
		int x,w;
		scanf("%d%d",&x,&w);
		if (w==1)
		{
			x+=t;
		}
		else
		{
			x-=t;
		}
		cnt+=x/l;
		x%=l;
		if (x<0)
		{
			cnt--;
			x+=l;
		}
		a[i]=x;
	}
	cnt=(cnt%n+n)%n;
	sort(a,a+n);
	for (int i=0;i<n;i++)
	{
		printf("%d\n",a[(cnt+i)%n]);
	}
    return 0;
}
//石壕村里夫妻别，泪比长生殿上多。
//——袁枚《马嵬》

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int n,m,w[105],v[105];
long long f[105][100005];
main()
{
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
		cin >> w[i] >> v[i];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
		{
			f[i][j] = f[i-1][j];
			if(j-w[i] >= 0)
				f[i][j] = max(f[i][j],f[i-1][j-w[i]] + v[i]);
		}
	cout<<f[n][m];
}

Measured memory_bytes: 79360
#include <stdio.h>

#define HMax 200000 //配列の上限？
#define YES puts("Yes");
#define NO puts("No");

void fs(int count, int*);//1種の数列入力(数列) scanf("%d", &count); fs(a); n = 要素数 a = 数列
int fs_2(int*, int*);//2種の数列入力(数列) n = fs(a); n = 要素数 a = 数列
void soto(int count, int*);

int main(void) {
  int n, flag = 1, i;
  char s[100003];

  scanf("%d %s", &n, s);

  for(i=0;i<n-1;i++) {
    if(s[i] != s[i+1])
      flag++;
  }

  printf("%d\n", flag);
}

void fs(int count, int *suretu) {
  int i;
  for (i = 0; i < count; i++) {
    scanf("%d", &suretu[i]);
  }
}

int fs_2(int *suretu, int *suretu_2) {
  int i, count;
  scanf("%d", &count);
  for (i = 0; i < count; i++) {
    scanf("%d %d", &suretu[i], &suretu_2[i]);
  }
  return count;
}

void soto(int count, int *number) {
  int i, j, tmp;
  for (i = 0; i < count; ++i) {
    for (j = i + 1; j < count; ++j) {
      if (number[i] < number[j]) {
        tmp =  number[i];
        number[i] = number[j];
        number[j] = tmp;
      }
    }
  }
}


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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));

    for(int i = 0; i < N; i++) {
        cin >> C.at(i);
        for(int j = 0; j < M; j++) {
            cin >> A.at(i).at(j);
        }
    }

    int n = 1;
    for(int i = 0; i < N; i++) {
        n *= 2;
    }

    int ans = -1;
    for(int i = 0; i <= n; i++) {
        int p = 0;
        vector<int> KNOWN(M, 0);
        for(int j = 0; j < N; j++) {
            if((i >> j) & 1 == 1) {
                for(int k = 0; k < M; k++) {
                    KNOWN.at(k) += A.at(j).at(k);
                }
                p += C.at(j);
            }
        }
        bool all_ok = true;
        for(int k = 0; k < M; k++) {
            if(KNOWN.at(k) < X) {
                all_ok = false;
                break;
            }
        }
        if(all_ok) {
            if(ans == -1) {
                ans = p;
            } else {
                ans = min(p, ans);
            }
        }
    }

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

Measured memory_bytes: 3596
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
constexpr ll INF = 1000000000000000000;

struct PartSums {
	vector<ll> part;
	int n;
	PartSums() {}
	PartSums(vector<ll> &orig) : part(orig.size() + 1), n(orig.size()) {
		for (int i = 1; i <= n; ++i) part[i] = part[i-1] + orig[i-1];
	}
	ll query(int i, int j) {
		return part[j+1] - part[i];
	}
};

int main() {
	int n; scanf("%d", &n);
	vector<ll> arr(n);
	for (int i = 0; i < n; ++i) scanf("%lld", &arr[i]);
	PartSums snuke(arr);
	ll ans = INF;
	for (int qed = 1; qed < n - 2; ++qed) {
		// printf("attempting q split %d\n", qed);
		ll pqSum = snuke.query(0, qed);
		ll rsSum = snuke.query(qed + 1, n - 1);
		int lo = 0;
		int hi = qed;
		while (lo < hi) {
			int mid = (lo + hi) / 2;
			ll prefVal = snuke.query(0, mid);
			if (prefVal >= pqSum - prefVal) hi = mid;
			else lo = mid + 1;
		}
		// printf("pq lo val %d\n", lo);
		vector<pair<ll, ll>> pqValues;
		if (lo < qed) pqValues.emplace_back(snuke.query(0, lo), snuke.query(lo + 1, qed));
		if (lo > 0) pqValues.emplace_back(snuke.query(0, lo - 1), snuke.query(lo, qed));
		lo = qed + 1;
		hi = n - 1;
		while (lo < hi) {
			int mid = (lo + hi) / 2;
			ll prefVal = snuke.query(qed + 1, mid);
			if (prefVal >= rsSum - prefVal) hi = mid;
			else lo = mid + 1;
		}
		// printf("rs lo val %d\n", lo);
		vector<pair<ll, ll>> rsValues;
		if (lo < n - 1) rsValues.emplace_back(snuke.query(qed + 1, lo), snuke.query(lo + 1, n - 1));
		if (lo > qed + 1) rsValues.emplace_back(snuke.query(qed + 1, lo - 1), snuke.query(lo, n - 1));
		for (auto p1_p2 : pqValues) {
			for (auto p3_p4 : rsValues) {
				vector<ll> finalSplit{p1_p2.first, p1_p2.second, p3_p4.first, p3_p4.second};
				sort(finalSplit.begin(), finalSplit.end());
				// printf("pot split: %lld %lld %lld %lld\n", p1_p2.first, p1_p2.second, p3_p4.first, p3_p4.second);
				ans = min(ans, *finalSplit.rbegin() - *finalSplit.begin());
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip> 
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
char s[100000+10];
int main()
{
//	freopen("C.in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	int len=strlen(s);
	ll k=read();
	Rep(i,len) {
		if (s[i]=='a') continue;
		if ('z'-s[i]+1<=k) {
			k-='z'-s[i]+1;
			s[i]='a';
		}
	}
	if (k>0) {
		int i=len-1;
		k%=26;
		s[len-1]+=k;
		if (s[i]>'z') s[i]-=26;
	}
	cout<<s<<endl;
	
	
	return 0;
}


Measured memory_bytes: 384
n = int(input())
w = []
for i in range(n):
    w.append(str(input()))
check = 'Yes'
for i in range(n-1):
    a = w[i][-1]
    b = w[i+1][0]
    if a != b:
        check = 'No'
def is_unique(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) == len(unique_list)
if not is_unique(w):
    check = 'No'
print(check)

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

int main(){
  int x, y;
  cin >> x >> y;
  for(int i = 0; i <= x; i++){
    int t = x - i;
    int asi = i * 2 + t * 4;
    if(asi == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 #define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=1e5+2;
const int inf= 1e19;
void solve(){
 int X;
 sl(X);
 int v500=X/500;
 int rem=X-500*(v500);
 int ans500=1000*v500;
 int v5=rem/5;
 int ans5=5*v5;
 cout<<(ans500+ans5)<<endl;

		
}
 
signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();
 
   }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

const double r = 1.0;
const double PI = acos(-1.0);

struct Point {
    double x, y;
    Point() {}
    Point(double x, double y) : x(x), y(y) {}
};
Point operator+(const Point &a, const Point &b) {
    return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
    return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, double b) {
    return Point(a.x * b, a.y * b);
}
inline double Distance2(const Point &a, const Point &b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
// p1??¨??????p1p2???theta?????¢?????????????????£????????????????????????????????????????????????
Point Circle(const Point &p1, const Point &p2, double theta) {
    Point p12 = p2 - p1;
    Point rp(p12.x * cos(theta) - p12.y * sin(theta), p12.x * sin(theta) + p12.y * cos(theta));
    double len = sqrt(p12.x * p12.x + p12.y * p12.y);

    return (rp * (1.0 / len)) + p1;
}

int main()
{
    int n;

    while (true) {
        // Input
        scanf("%d", &n);
        if (n == 0) break;
        vector<Point> p(n);
        for (int i = 0; i < n; ++i)
            scanf("%lf %lf", &p[i].x, &p[i].y);

        // Solve
        // 2???????????????????§£???????£???¨??????
        int ans = 1;
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j) {
                double d = Distance2(p[i], p[j]);

                if (d <= 4.0 * r * r) {
                    double theta = (PI - acos((2.0 - d) * 0.5)) * 0.5;

                    for (int s = -1; s <= 1; s += 2) {
                        Point c = Circle(p[i], p[j], s * theta);

                        int num = 2;
                        for (int k = 0; k < n; ++k) {
                            if (k != i && k != j && Distance2(c, p[k]) <= 1.0)
                                ++num;
                        }

                        ans = max(ans, num);
                    }
                }
            }

        // Output
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1148
#include<iostream>
using namespace std;
int main()
{
	int d, n;
	cin >> d >> n;
	if(d == 0){
		if(n != 100) cout << n << endl;
		else cout << "101" << endl;
	}
	if(d == 1){
		if(n != 100) cout << 100 * n << endl;
		else cout << "10100" << endl;
	}
	if(d == 2){
		if(n != 100) cout << 10000 * n << endl;
		else cout << "1010000" << endl;
	}
	return 0;
}
	

Measured memory_bytes: 764
a, b, k = map(int,input().split())

if a > k:
    a = a - k
    k = 0
    print(str(a) + ' ' + str(b))
else:
    k = k - a
    a = 0
    if b > k:
        b = b - k
        k = 0
        print(str(a) + ' ' + str(b))
    else:
        b = 0
        print(str(a) + ' ' + str(b))

Measured memory_bytes: 3064
def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


m = 1000000007

S = int(input())

fac = make_factorial_table(S + 10)
#print(fac)
#print(len(fac))

result = 0
for i in range(1, S // 3 + 1):
    result += mcomb(S - i * 3 + i - 1, i - 1)
    result %= m
print(result)

Measured memory_bytes: 9108