akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#define F first
#define S second
#define PB push_back
#define MP make_pair


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vii;
typedef set<int> si;
typedef map<string, int> msi;

#define INF 2000000000

const int max_n=1e9+1;
const ll mod=998244353;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vi a(n);
    int i;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    double sum,ax;
    ax=a[0]+a[1];
    sum=ax/2;
    for(i=2;i<n;i++){
        ax=sum+a[i];
        sum=(ax)/2;
    }
    cout<<setprecision(9)<<sum;
}


Measured memory_bytes: 256
#include <cstdio>

int w[] = { 2, 3, 5, 10, 12, 15 };
int v[] = { 380, 550, 850, 1520, 1870, 2244 };
int n = 6;
#define M 50
#define INF 10000000
#define min(x, y) ((x) < (y) ? (x) : (y))
int dp[M+10];

int main()
{
	for (int i = 0; i <= M; ++i) dp[i] = INF;
	for (int i = 0; i < n; ++i) dp[w[i]] = v[i];

	for (int i = 6; i <= M; ++i)
		for (int j = 0; j < n; ++j)
			for (int k = 1; k * w[j] <= i; ++k)
				dp[i] = min(dp[i], dp[i-k*w[j]] + k*v[j]);

	int m;
	while (scanf("%d", &m), m) printf("%d\n", dp[m/100]);
	return 0;
}

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

int main() {
  char s[10];
  scanf("%s",s);
  sort(s,s+4);
  if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) == t.at(i))ans++;
	}
	cout << s.length()-ans << endl;
}

Measured memory_bytes: 3912
/*
By Tianyi Chen. All rights reserved.
Date: 2017-04-15
*/
#include<bits/stdc++.h>
using namespace std;
int n,m,s,t,vis[100001];
vector<pair<int,int>>e[100001];
deque<int>ans;
int main(){
 scanf("%d%d",&n,&m);
 for(int i=1;i<=m;++i){
  scanf("%d%d",&s,&t);e[s].emplace_back(t,i);
  e[t].emplace_back(s,i);
 }
 vis[s]=vis[t]=1;ans.push_back(s);ans.push_back(t);
a: for(auto&&x:e[s])if(!vis[x.first]){
 vis[s=x.first]=1;ans.push_front(s);goto a;
 }
b: for(auto&&x:e[t])if(!vis[x.first]){
 vis[t=x.first]=1;ans.push_back(t);goto b;
 }
 printf("%d\n",int(ans.size()));
 for(auto&&x:ans)printf("%d ",x);
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char in[12];
int main(){
  rd(in);
  in[3]++;
  wt_L(in);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// char in[12];
// {
//   rd(in);
//   in[3]++;
//   wt(in);
// }


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    int a, b;
    cin >> a >> b;
    vector<string> s(2);
    rep(i, b)
    {
        s[0] += to_string(a);
    }
    rep(i, a)
    {
        s[1] += to_string(b);
    }
    sort(s.begin(), s.end());
    cout << s[0] << endl;
}


Measured memory_bytes: 256
/*      ex3_2
        Tarara  */
#include <stdio.h>

int main(void)
{
    int pencils; //鉛筆の本数
    scanf("%d", &pencils);

    int digit = pencils % 10; //鉛筆の本数の一の位の数
    if (digit == 3)
        printf("bon\n");
    else if (digit == 0 || digit == 1 || digit == 6 || digit == 8)
        printf("pon\n");
    else // 0, 1, 6, 8の時
        printf("hon\n");
}

Measured memory_bytes: 1656
#[derive(Debug)]
struct UnionFind {
    roots: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut roots = vec![];
        for i in 0..n {
            roots.push(i);
        }
        UnionFind { roots: roots }
    }
    fn root(&mut self, i: usize) -> usize {
        if self.roots[i] == i {
            i
        } else {
            let tmp_i = self.roots[i];
            self.roots[i] = self.root(tmp_i);
            self.roots[i]
        }
    }
    fn unite(&mut self, i: usize, j: usize) {
        let root_i = self.root(i);
        let root_j = self.root(j);
        self.roots[root_i] = root_j;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        abs: [(usize, usize); m],
    }
    let mut union_find = UnionFind::new(n);
    for (a, b) in abs {
        union_find.unite(a - 1, b - 1);
    }
    let mut set = std::collections::HashSet::new();
    for i in 0..n {
        set.insert(union_find.root(i));
    }
    let ans = set.len() - 1;
    println!("{}", ans);
}


Measured memory_bytes: 5736
n = int(input())
data = list(map(int, input().split()))

total = sum(data)
x = 0
ans = 2 * 10**9 + 1
last = data[-1]
for i in range(len(data)-1):
    x += data[i]
    score = abs(2*x - total)
    if score < ans:
        ans = score
print(ans)

Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fa(i,a,b) for(i=a;i<b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define clr(x) memset(x, 0, sizeof(x))
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;


int main()
{
	/*#ifndef OMLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	

		int n;
		cin >> n;
		if (n == 1)
			cout << "0\n";
		else if (n == 0)
			cout << "1\n";
	




}

Measured memory_bytes: 3644
from  math import gcd

 
k = int(input())
sum_c = 0
 
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum_c += gcd(gcd(a, b), c)
            
print(sum_c)

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,s1;
    int n,i,a;
    cin>>n;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]+n <=90)
        s1=s[i] + n;
        else
        {
          s1='A'+s[i]+n-91  ;
        }
        cout<<s1;
    }
    
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    string s; cin>>s; 
    int len=sz(s),c=0;
    map <char,bool> mp;
    for (int i=0;i<len;i++){
        if (!mp[s[i]]) c++;
        mp[s[i]]=true;
    }
    if (c==len) cout << "yes" << endl;
    else cout << "no" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3488
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int N=400005;

int a[N],b[N],s[N<<2];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):(v),ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

void modify(int now,int tl,int tr,int x,int v) {
	s[now]+=v; if (tl==tr) return ;
	int mid=(tl+tr)>>1;
	if (x<=mid) modify(now<<1,tl,mid,x,v);
	else modify(now<<1|1,mid+1,tr,x,v);
}

int ask(int now,int tl,int tr,int k) {
	if (tl==tr) return tl;
	int w=s[now<<1],mid=tl+tr>>1;
	if (w>=k) return ask(now<<1,tl,mid,k);
	else return ask(now<<1|1,mid+1,tr,k-w);
}

int main(void) {
	int n=read();
	rep(i,1,n) b[i]=a[i]=read();
	std:: sort(b+1,b+n+1);
	int size=std:: unique(b+1,b+n+1)-b-1;
	rep(i,1,n) a[i]=std:: lower_bound(b+1,b+size+1,a[i])-b;
	rep(i,1,n) modify(1,1,size,a[i],1);
	rep(i,1,n) {
		modify(1,1,size,a[i],-1);
		printf("%d\n", b[ask(1,1,size,n/2)]);
		modify(1,1,size,a[i],1);
	}
	return 0;
}

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

struct foo {
	string s;
	int a;
};

int main(){
	int n, v, time = 0;
	foo f[100000];
	cin >> n >> v;
	for (int i = 0; i < n; i++) {
		cin >> f[i].s >> f[i].a;
	}
	int j = n, b = 0, flag = n;
	while (flag > 0) {
		f[b].a -= v,time += v;
		if (f[b].a > 0) {
			f[b+j] = f[b];
		}else {
			time += f[b].a, j--, flag--;
			cout << f[b].s << " " << time << endl;
		}
		b++;
		if (b > 99999)b = 0;
		if (j + b > 99999)j -= 100000;
		if (j + b < 0)j += 100000;
	}

	return 0;
}

Measured memory_bytes: 6924
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = ((1e9) + 7) ;
const LD EPS = 0.0000001 ;

int D;
int SZ;
vector<int> arr;
LL cache[10000 + 1][101][2];
//bool done[10000 + 1][101][2];
LL pows(LL a, LL b)
{
	if (b == 0)
		return 1;
	LL temp = pows(a, b / 2);
	temp = (temp * temp) % MOD;
	if (b % 2)
		temp = (temp * a) % MOD;
	return temp;
}

LL solve(int idx, int rem, int can){
	if (idx == SZ){
		return rem == 0;
	}
//	cout << idx << " " << rem << " " << can << endl;
	LL &ans = cache[idx][rem][can];
	if (ans != -1)
		return ans;
	ans = 0;
	if (can){
		for (int i = 0; i <= 9; i++){
			ans = (ans + solve(idx + 1, (rem + i) % D, can) ) % MOD;
		}
	} else {
		for (int i = 0; i < arr[idx]; i++){
			ans = (ans + solve(idx + 1, (rem + i) % D, 1) ) % MOD;
		}
		ans = (ans + solve(idx + 1, (rem + arr[idx]) % D, 0)) % MOD;
	}
//	cout << idx << " " << rem << " " << can << " " << ans << endl;
	return ans;
}

LL compute(string s)
{
	for (int i = 0; i < s.size(); i++){
		arr.PB(s[i] - '0');
	}
//	reverse(arr.begin(), arr.end());
	SZ = arr.size();
    memset(cache, -1, sizeof(cache));
	return (solve(0, 0, 0) - 1 + MOD) % MOD;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s; cin >> s;
    cin >> D;
   // cout << ((MOD + 2) * (MOD + 3)) % MOD << endl;
    cout << compute(s) << endl;


	return 0;
}

Measured memory_bytes: 16896
#include <stdio.h>

int main(void)
{
	char last_week[4];
	char this_week[] = "ABC";

	scanf("%s", last_week);

	this_week[1] = (last_week[1] == 'B') ? 'R' : 'B';

	printf("%s\n", this_week);

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a, b;
    cin >> a >> b;
    vector<string>s(a);
    rep(i, a)cin >> s[i];
    sort(all(s));
    for (auto ss : s)cout << ss;
    cout << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    map<ll,ll> mp;
    ll sum = 0;
    mp[0] = 1;
    REP(i,N) {
        sum += A[i];
        if (mp.find(sum) != mp.end()) {
            mp[sum] ++;
        }
        else {
            mp[sum] = 1;
        }
    }
    ll ans = 0;
    for (auto t : mp) {
        ans += t.se * (t.se - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
string S;
cin>>S;
int n=S.size()-1;long long ans=0;
for(int bit=0;bit<(1<<n);bit++)
{
  long long sum=S[n]-'0',reset=1;
  for(int i=n-1;i>-1;i--)
  {
    if(bit&(1<<i))reset=1;
    else reset*=10;
    sum+=(S[i]-'0')*reset;   
  }
  ans+=sum;
}
printf("%lld\n",ans);
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N, K;
  cin >> N >> K;
  
  set<int> num;
  for( int i = 0; i < K; i++ ){
    int D;
    cin >> D;
    for( int j = 0; j < D; j++ ){
      int A;
      cin >> A;
      num.insert(A);
    }
  }
  cout << N - num.size() << endl;
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  string S_origin = S;

  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());

  if(S.size() == S_origin.size()){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        args = Console.ReadLine().Split(' ');
        int a = int.Parse(args[0]);
        int b = int.Parse(args[1]);
        a = (a == 1 ? 14 : a);
        b = (b == 1 ? 14 : b);
        Console.WriteLine(a > b ? "Alice" : a < b ? "Bob" : "Draw");
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		int cnt=0;
		
		for(int i=0;i<3;i++) {
			if(s.charAt(i)=='o')cnt++;
		}
		
		System.out.println(700+cnt*100);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
void fact(int gcd, vi &fac) {
	for (int i = 1; i * i <= gcd; i++) {
		if (i * i == gcd) {
			fac.pb(i);
		}
		else {
			if (gcd % i == 0) {
				fac.pb(i);
				fac.pb(gcd / i);
			}
		}
	}
}
bool check(int d, vi &a, int x) {
	rep(i, 0, a.size()) {
		int dist = abs(a[i] - x);
		if (dist % d == 0) {
			return true;
		}
	}
	return false;
}
void solve() {
	int n, x;
	cin >> n >> x;
	vi a(n);
	rep(i, 0, n)cin >> a[i];
	if (n == 1) {
		cout << abs(x - a[0]);
		return;
	}
	sort(all(a));
	vi dist;
	rep(i, 1, n) {
		dist.pb(a[i] - a[i - 1]);
	}
	int gcd = dist[0];
	rep(i, 1, dist.size()) {
		gcd = __gcd(gcd, dist[i]);
	}
	trace(gcd)
	vi fac;
	fact(gcd, fac);
	sort(all(fac));
	int d = 1;
	rep(i, 0, fac.size()) {
		if (check(fac[i], a, x)) {
			d = fac[i];
		}
	}
	cout << d;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 4176
#include <stdio.h>

int main(void){
    int A,B;

    scanf("%d%d",&A,&B);

    if (1 <= A && A <= 9 && 1 <= B && B <= 9){
        printf("%d",A*B);
    }

    else{
        printf("-1");
    }

    return 0;
}

Measured memory_bytes: 128
import Control.Monad

main = do
  [n,c] <- fmap (map read . words) getLine
  xs <- replicateM n (fmap ((\(x:v:_)->(x,v)) . map read . words) getLine)
  print (solve c xs)


-- MaxState, CurrentState, CurrentX
type State = (Int, (Int, Int))

solve :: Int -> [(Int,Int)] -> Int
solve c xs =
  solveTurn roundR roundL
  where
    roundR = scanl f (0,(0,0)) xs
    roundL = scanr (flip f) (0,(0,0)) [(c-x,v)|(x,v)<-xs]

    f (m,(s,y)) (x,v) = let s' = s-(x-y)+v in s' `seq` (max m s', (s', x))


solveTurn :: [State] -> [State] -> Int
solveTurn ss1 ss2 =
  max (go ss1 ss2 0) (go ss2 ss1 0)
  where
    go :: [State] -> [State] -> Int -> Int
    go [(m1,(s1,x1))]     _                  a = max a m1
    go ((m1,(s1,x1)):tt1) ((m2,(s2,x2)):tt2) a = let a' = max a $! (s1+m2-x1) in a' `seq` go tt1 tt2 a'

Measured memory_bytes: 225660
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc159
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc159C();
        }

        public static void solve_abc159C()
        {
            double l = Convert.ToDouble(Console.ReadLine());
            double d = l / 3;
            Console.WriteLine("{0:F12}", d * d * d);
            /*
            long max = 0; 
            for (int a = 1; a < 32; a++)
            {
                for (int b = 1; b < 32; b++)
                {
                    for (int c = 1; c < 32; c++)
                    {
                        if (a * a + b * b + c * c <= l)
                        {
                            max = Math.Max(max, a * b * c);
                        }
                    }
                }
            }*/

            //Console.WriteLine(max);
        }

        public static void solve_abc159B()
        {
            string s = Console.ReadLine();
            bool ok = true;

            int l = 0;
            int r = s.Length - 1;
            ok = isPalindrom(s, l, r);
            if (ok)
            {
                ok = isPalindrom(s, 0, ((s.Length - 1) / 2) - 1);
            }
            if (ok)
            {
                ok = isPalindrom(s, ((s.Length + 3) / 2) - 1, s.Length - 1);
            }
            if (ok)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public static bool isPalindrom(string s, int l, int r)
        {
            bool ok = true;
            while (l < r)
            {
                if (s[l] != s[r])
                {
                    ok = false;
                    break;
                }
                l++;
                r--;
            }
            return ok;
        }

        public static void solve_abc159A()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long even = 0;
            if (nm[0] > 1)
            {
                even = combs(nm[0], 2);
            }
            long odd = 0;
            if (nm[1] > 1)
            {
                odd = combs(nm[1], 2);
            }
            Console.WriteLine(even + odd);
        }
        public static long combs(int n, int k)
        {
	        int res = 1;
	        for (int i = n - k + 1; i <= n; i++)
            {
		        res *= i;
            }
	        for (int i = 2; i <= k; i++)
            {
		        res /= i;
            }
            return res;
            /*double res = 1;
	        for (int i = 1; i <= k; i++)
            {
		        res = res * (n - k + i) / i;
            }
	        return (long) (res + 0.01);
            */
        }
    }
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    ll  n, hei= 0;
    cin>> n;
    int a[n+1];
    cin>> a[0];
    for (int i= 1; i<n; i++)
    {
        cin>> a[i];
        hei += (max (0, (a[i-1]- a[i])));
        a[i]+= (max (0, (a[i-1]- a[i])));
    }

    cout << hei << '\n';

    return 0;
}




Measured memory_bytes: 4368
#include <iostream> // ★
#include <algorithm> // max
#include <cstring> // memset
using namespace std; // ★

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

int N,date[111],point[111]; // 男の数、各男のデートの時間帯、各男の満足度
int dp[111][1<<16]; // Dynamic Programming で使うメモ。
					// 関数 f(cur,mask) の返り値を dp[cur][mask]に保存する。
					// 男は100人までだが、cur=100もありうるので1つ目の[]の中は101以上必要

// 【デート日程の整数での表し方】
// 例1: 000000000000111(2進数) は「6時〜9時」の意味
// 例2: 000011110011000(2進数) は「10時〜12時と14時〜18時」の意味
// 最下位の桁が6時〜7時、最上位の桁が21時〜22時に対応

int f(int cur,int mask){
	// cur番以降の男とだけデートするとき、maskの時間帯で得られる最大の満足度
	// (番号は0番〜N-1番。ただし、cur=Nもありうる)
	int& res=dp[cur][mask]; // 答えをメモする場所
	if(res>-1)return res; // メモに書かれている数が-1でなかった
						  // = すでに計算されていた。メモされた返り値を返して終了
	
	// ここまで来た場合、関数 f(cur,mask) が呼ばれたのは初めて。
	// 最大の満足度を計算し、その結果を dp[cur][mask] (res) に書き込む
	if(cur==N)return res=0; // N番以降には誰もいないので、誰ともデートできない
							// メモに0と書き、0を返して終了
	
	// ここまで来た場合、cur番の男が実在する。
	// 選択肢1.「cur番の男とデートしない」
	// 選択肢2.「cur番の男とデートする」(maskがcur番の男のデート日程を含んでいる場合のみ)
	res=f(cur+1,mask);
	// 選択肢1。この場合、「cur+1番以降の男とデートして得られる最大の満足度」を得る。
	// 結果はメモに書き込んでおく
	if((date[cur]&mask)==date[cur]){ // mask は date[cur] を含むか？
		res=max(res,point[cur]+f(cur+1,mask^date[cur]));
		// 選択肢2。この場合、「cur番の男の満足度」+
		// 「残った時間帯でcur+1番以降の男とデートして得られる最大の満足度」を得る。
		
		// max(a,b) でaとbのうち大きい方が返る。
		// 選択肢2の結果が現在のメモの値(選択肢1の結果)を上回ったら、メモを上書きする
	}
	return res; // ここでメモに書き込まれているのが最大の満足度。それを返す
}

int main(){
	while(cin>>N && N){ // Nに0が入力されるまで続ける
		rep(i,N){
			int M; // デート回数
			cin>>M>>point[i];
			date[i]=0; // デートの時間帯を初期化
			rep(j,M){
				int S,E; // 開始時刻、終了時刻
				cin>>S>>E;
				rep2(k,S,E)date[i]|=1<<(k-6);
				// 例: S=10, E=13なら, 
				// 下から(10-6=)4番目、5番目、6番目のビットを1にする
			}
		}
		memset(dp,-1,sizeof(dp)); // 配列dpの要素をすべて-1に
		cout<<f(0,(1<<16)-1)<<endl;
		// 答えは「0番以降の男とデートするとき、6時〜22時の間に得られる最大の満足度」。
		// 1111111111111111(2進数,16桁) = 2^16 - 1
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int a;
	cin >> a;
	cout << a + a* a + a* a* a;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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;
  }
 
  // for prime mod
  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;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2000005);

mint g(long long r, long long c) {
  return comb(r + c + 2, r + 1) - 1;
}

int main() {
    long long r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    --r1;
    --c1;

    mint result = g(r2,c2);
    result -= g(r1,c2);
    result -= g(r2,c1);
    result += g(r1,c1);

    cout << result.x << endl;
    return 0;
}

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

using namespace std;

int main() {
	vector<int>a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[0]+a[1]<< endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  
  int N,X,T;
  scanf("%d %d %d",&N,&X,&T);
  
  int C=0;
  while(N>0){
    N=N-X;
    C=C+1;
  }
  
  printf("%d\n",C*T);
  return 0;
}

Measured memory_bytes: 1692
#pragma GCC optimize("O3")
 #pragma GCC optimize("unroll-loops")
 #pragma GCC optimize("fast-math")
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}


signed main() {
    accell();
    int n;
    cin >> n;
    string s;
    string t;
    cin >> s >> t;
    int ans = 1e9;
    for (int i = 0; i <= n; ++i) {
        string c = s;
        for (int j = n - i; j < n; ++j)
            c += t[j];
        if (c.substr((int)c.size() - n, n) == t)
            ans = min(ans, (int)c.size());
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections

def solve(N,M,H,A,B):
    total = 0
    dic = {key:[] for key in range(N)}
    for a,b in zip(A,B):
        dic[a-1].append(H[b - 1])
        dic[b-1].append(H[a - 1])
    for n,h in enumerate(H):
        target = dic[n]
        for t in target:
            if(h <= t):break
        else:
            total+= 1

    return total
def main():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    A = []
    B = []
    for _ in range(M):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)

    # solve()
    print(solve(N,M,H,A,B))

if __name__ == "__main__":
    main()


Measured memory_bytes: 40096
#include<bits/stdc++.h>
using namespace std;
//int INF =1e9+99;
#define f(i,j,n) for(int i=j;i<n;i++)
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	f(i,0,n)cin>>a[i];
	
	bool dp[k+1];
	dp[0]=false;
	f(i,1,k+1)
	{
		dp[i]=false;
		f(j,0,n)
		{
			if(a[j]<=i)
			{
			
				if(!dp[i-a[j]])
				{
				dp[i]=true;
				
				break;}
			
			}
		}
	}
	if(dp[k])cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
  int a,b,c,m,n;
  
  scanf("%d%d",&a,&b);
    
  if(a < b){
    m = a;
    n = b;
  }
  else {
    m = b;
    n = a;
  }
  
  while(1){
    c = m % n;
    if(c == 0) break;
    else {
      m = n;
      n = c;
    }
    
  }
  printf("%d\n",n);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e6+5;

const ll mod=1e9+7;

char s[maxn];

int main(){
	scanf("%s",s+1);
	int flg=0,flg2=0;
	for(int i=1;i<=3;i++){
		if(s[i]=='A') flg=1;
		else flg2=1;
	}
	if(flg&&flg2) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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;}

int n, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> y;
    y /= 1000;
    erep(a, 0, 2*1000) {
        erep(b, 0, 4*1000) {
            int c = n - a - b;
            if (c >= 0 && y == 10 * a + 5 * b + c) {
                printf("%d %d %d\n", a, b, c);
                return 0;
            }
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	  			public static void main(String args[]){
				@SuppressWarnings("resource")
				Scanner sc = new Scanner(System.in);

				int k = sc.nextInt();				
				int x = sc.nextInt();
				if(500*k>=x) {
					System.out.println("Yes");
				}else {
					System.out.println("No");
				}
	  	}
}

Measured memory_bytes: 20948
#define _CRT_SECURE_NO_WARNINGS

#define N (1<<17)
#define MODULO (1000000007)

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <vector>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;

int n;
long long a[N], b[N];
long long inc;

int main()
{
	scanf("%d", &n);
	for (int i = 0;i < n;i++)
	{
		scanf("%lld%lld", &a[i], &b[i]);
	}
	for (int i = n - 1;i >= 0;i--)
	{
		long long ct = a[i] + inc;
		long long cn = b[i] - (ct%b[i]);
		if (cn == b[i])
		{
			cn = 0LL;
		}
		inc += cn;
	}
	printf("%lld\n", inc);
	//system("pause");
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX / 2)
#define VEC2(type,name,w,h) vector<vector<type>>name(h,vector<type>(w))

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    cout << max({(n-1)/a,(n-1)/b,(n-1)/c,(n-1)/d,(n-1)/e})+5<<endl;
}
/*
*/

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>

int count(int bits) {
    if (bits == 0) return 0;
    return count(bits >> 1) + (bits & 1);
}

int main() {
    int N;
    int A[16];
    int x[16][16];
    int y[16][16];

    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
        for (int j = 1; j <= A[i]; j++) {
            std::cin >> x[i][j] >> y[i][j];
        }
    }

    int result = 0;
    for (int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for (int i = 1; i <= N; i++) {
            if ( !( bits & ( 1 << (i-1) ) ) ) continue;
            for (int j = 1; j <= A[i]; j++) {
                if ( ( ((bits >> (x[i][j]-1)) & 1) ^ y[i][j] ) ) ok = false;
            }
        }
        if (ok) result = std::max(result, count(bits));
    }

    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 888
def sort(a, k):
    c = [0]*k
    for x in a:
        c[x] += 1
    b = []
    for i in range(len(c)):
        y = c[i]
        for _ in range(y):
            b.append(i)
    return b

n = int(raw_input())
a = map(int, raw_input().split(' '))
b = sort(a, 10001)

print ' '.join(map(str, b))

Measured memory_bytes: 202652
#include<stdio.h>

int main(void){
  int a,b,k;
  long count = 1;
  scanf("%d" "%d" "%d",&k,&a,&b);

  if(a>=b-2 | k <= a){
    count = count + k;
  }else{
    count = a;
    for(int i = 0;i < (k-a+1)/2;i++){
      count = count + b - a;
    }
    if((k-a+1)%2==1){
      count++;
    }
  }
  printf("%ld\n",count);

  return(0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int a,b,c,x;cin>>a>>b>>c>>x;
    int ans = 0;
    rep(i,a+1)rep(j,b+1)rep(k,c+1)if(500*i+100*j+50*k==x)ans++;
    co(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int H, W; cin >> H >> W;
  for (int _ = 0; _ < H; ++_) {
    vector<char> row(W);
    for (auto& cell : row) { cin >> cell; }
    for (const auto& c : row) { cout << c; }
    cout << CRLF;
    for (const auto& c : row) { cout << c; }
    cout << CRLF;
  }
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#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 int ll;

const ll mod=1e9+7;

int N;
char c[5]={' ','A','G','C','T'};

ll mem[110][5][5][5];

bool check(string s){
    if(s.find("AGC")!=string::npos)return false;
    for(int j=0;j<s.size();++j){
        string t=s;
        swap(t[j],t[j+1]);
        if(t.find("AGC")!=string::npos)return false;
    }
    return true;
}

//A=0,G=1,C=2,T=3;
ll calc(int n,int pc,int ppc,int pppc){
    if(mem[n][pc][ppc][pppc]!=-1)return mem[n][pc][ppc][pppc];
    if(n==N)return 1;
    ll res=0;
    string s="";
    if(pppc!=0)s+=c[pppc];
    if(ppc!=0)s+=c[ppc];
    if(pc!=0)s+=c[pc];
    for(int i=1;i<=4;++i){
        string t=s+c[i];
        if(check(t))res+=calc(n+1,i,pc,ppc)%mod;
    }
    return mem[n][pc][ppc][pppc]=res%mod;
}

int main(){
    for(int i=0;i<110;++i)for(int j=0;j<5;++j)for(int k=0;k<5;++k)for(int l=0;l<5;++l)mem[i][j][k][l]=-1;
    cin>>N;
    cout<<calc(0,0,0,0)<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
int a,i;
while(1){
scanf("%d\n",&a);
if(a==0){
break;
}
else{
for(i=0;a!=1;i++){
if(a%2==0){
a=a/2;
}
else{
a=a*3+1;
}
}
}
printf("%d\n",i);
}
return 0;
}



Measured memory_bytes: 2052
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    a,b,c=map(int,input().split())
    for i in range(1000):
        for j in range(1000):
            if i*a==j*b+c:
                print('YES')
                exit()
    print('NO')

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	int n;
	cin >> n;
	stack<int> s, tmp, ans;
	for(int i = 0; i < n; ++i){
		int num;
		cin >> num;
		s.push(num);
	}
	while(!s.empty()){
		int num = s.top();
		s.pop();
		if(num == (int)s.size() + 1){
			ans.push(num);
			while(!tmp.empty()){
				s.push(tmp.top());
				tmp.pop();
			}
		}
		else{
			tmp.push(num);
		}
	}
	if(tmp.empty()){
		while(!ans.empty()){
			cout << (ans.top()) << "\n";
			ans.pop();
		}
	}
	else{
		cout << -1;
	}
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>n;
    vl beki;
    multiset<ll> A;
    beki.push_back(1);
    rep(i,40){
        beki.push_back(beki.back()*2);
    }
    rep(i,n){
        cin>>x;
        A.insert(x);
    }

    while(!A.empty()){
        auto ite=A.end();
        ite--;
        x=*ite;
      	A.erase(ite);
        k=upper_bound(all(beki),x*2)-beki.begin()-1;
        if(!A.empty()&&A.count(beki[k]-x)>0){
            auto ite2=A.lower_bound(beki[k]-x);
            A.erase(ite2);
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9600
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();

                if (s == "0 0")
                {
                    break;
                }

                var row = s.Split(' ').Select(e => int.Parse(e)).ToArray();

                string[] tiles = new String[row[0]];

                for (int i = 0; i < row[0]; i++)
                {
                    tiles[i] = Console.ReadLine();
                }

                bool[,] check = new Boolean[row[0],row[1]];

                int x = 0, y = 0;
                while (true)
                {
                    char current = tiles[x][y];
                    
                    if (current == '.')
                    {
                        Console.WriteLine("{0} {1}", y, x);
                        break;
                    }

                    if (check[x,y])
                    {
                        Console.WriteLine("LOOP");
                        break;
                    }

                    check[x,y] = true;
                    switch (current)
                    {
                    case '>':
                        y++;
                        break;
                    case '<':
                        y--;
                        break;
                    case '^':
                        x--;
                        break;
                    case 'v':
                        x++;
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    }
}

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

int N; int P[100010];
int next[100010];
bool vis[100010];
int dfs(int now) {
    if(vis[now]) return next[now] = -2;
    if(next[now] != -1) return next[now];
    vis[now] = true;
    return next[now] = P[now] == 0 ? now : dfs(now + P[now]);
}

int dist[100010]; 
int solve() {
    rep(i, N) dist[i] = INF; dist[0] = 0;
    queue<int> que; que.push(0);
    while(!que.empty()) {
        int now = que.front(); que.pop();
        if(now == N - 1) return dist[now];
        REP(i, 1, 7) {
            memset(vis, 0, sizeof(vis));
            int nxt = dfs(min(now + i, N - 1));
            if(nxt == -2) continue;
            if(dist[nxt] != INF) continue;
            dist[nxt] = dist[now] + 1;
            que.push(nxt);
        }
    }
}
int main() {
    scanf("%d", &N);
    rep(i, N) scanf("%d", P + i);
    memset(next, -1, sizeof(next));
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 3780
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
const int inf = 1 << 30;

int main() {
    ll N; cin >> N;
    vector<ll> A(N);

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= (ll)(i + 1);
    }

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

    if (N == 1) {
        cout << 0 << endl;
    }
    else {
        ll b = A[(N + 1) / 2 - 1];
        ll ans = 0LL;
        for (ll i = 0; i < N; ++i) {
            ans += abs(A[i] - b);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1792
from itertools import product
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for bit in range(1<<(W-1)):
        if "11" in bin(bit): continue
        for w in range(W):
            if w > 0 and (bit>>(w-1))&1:
                dp[h+1][w-1] += dp[h][w]
                dp[h+1][w-1] %= MOD
            elif (bit>>w)&1:
                dp[h+1][w+1] += dp[h][w]
                dp[h+1][w+1] %= MOD
            else:
                dp[h+1][w] += dp[h][w]
                dp[h+1][w] %= MOD

print(dp[-1][K-1] % MOD)


Measured memory_bytes: 41840
#include<stdio.h>

int main()
{
	int i,ans;
	char s[5];

	scanf("%s", s);

	ans = 0;
	for (i = 0; i < 4; i++)
	{
		if (s[i] == '+')
			ans++;
		else
			ans--;
	}

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

	return 0;
}

Measured memory_bytes: 128
use std::env;
    
fn main() {

    let s = {
    let mut s = String::new(); // バッファを確保
        std::io::stdin().read_line(&mut s).unwrap(); // 一行読む。失敗を無視
        s.trim_right().to_owned() // 改行コードが末尾にくっついてくるので削る
    };

    let (n, m) = {
        let mut ws = s.split_whitespace(); // 空白区切りの単語に分解する
        let n: i64 = ws.next().unwrap().parse::<i64>().unwrap(); // イテレータから値を取り出して整数に
        let m: i64 = ws.next().unwrap().parse::<i64>().unwrap();
        (n, m)
    };

    let ret:i64 = n-m*2;
    if ret < 0{
        println!("{}",0);
    }else{
        println!("{}",ret);
    }

}

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



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

  string ans = "";

  vector<ll> xs;

  ll x = 1;
  ll length = 0;
  while(n >= x) {
    xs.push_back(x);
    x = x * 26 + 1;
    length++;
  }

  length = length - 1;
  n -= xs[length];
  while(length >= 0) {
    ll div = pow(26, length);
    ll x = n / div;
    if(x > 26) {
      x = 25;
    }
    ans += 'a' + x;

    // printf("n: %lld, div: %lld, x: %lld\n", n, div, x);

    n = n - (div * x);
    length--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4040
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <complex>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef long double D;
typedef complex<D> P;
struct Event{
  double arg;
  int idx;
  bool out;
  Event() {}
  Event(double a, int i, bool b) : arg(a), idx(i), out(b) {}
  bool operator < (const Event& e) const {
    if(arg != e.arg) return arg < e.arg;
    return (int) out < (int) e.out;
  }
  void print(){
    //printf("arg=%lf idx=%d out=%d\n", arg, idx, out);
  }
};

int main(){
  int N;
  while(cin>>N && N){
    vector<Event> events;
    bool ison[2000] = {};
    REP(iter, N){
      int x[2], y[2];
      REP(i, 2) cin>>x[i]>>y[i];
      vector<double> args;
      REP(i, 2)REP(j, 2){
        args.push_back(arg(P(x[i], y[j])));
      }
      bool plus = false, minus = false;
      //printf("(%d, %d), (%d, %d)\n", x[0], y[0], x[1], y[1]);
      REP(i, 4){
        //printf("args[%d]=%lf\n", i, args[i]);
        if(args[i] > M_PI/2 - EPS) plus = true;
        if(args[i] < -M_PI/2 + EPS) minus = true;
      }
      if(plus && minus) REP(i, 4) if(args[i] < -M_PI/2 + EPS) args[i] += 2 * M_PI;
      if(plus && minus) ison[iter] = true;
      sort(args.begin(), args.end());
      events.push_back(Event(args[0], iter, false));
      events.push_back(Event(args[3] - ((plus && minus) ? 2 * M_PI : 0 ), iter, true));
    }
    sort(events.begin(), events.end());
    REP(i, events.size()) events[i].print();
    bool attacked[2000][2000] = {};
    vector<int> out_idx;
    REP(i, events.size()){
      int idx = events[i].idx;
      if(events[i].out){
        REP(i, N) if(ison[i]) attacked[idx][i] = true;
        ison[idx] = false;
        out_idx.push_back(idx);
      }else if(!events[i].out){
        ison[idx] = true;
      }
    }
    int ans = INF;
    REP(i, out_idx.size()){
      int sub_ans = 0;
      bool used[2000] = {};
      REP(j, out_idx.size()){
        int idx = out_idx[(i + j) % out_idx.size()];
        if(!used[idx]){
          sub_ans++;
          REP(k, out_idx.size()) if(attacked[idx][k]) used[k] = true;
        }
      }
      ans = min(ans, sub_ans);
    }
    cout<<ans<<endl;;
  }
  return 0;
}

Measured memory_bytes: 5276
n=int(input())
num=[list(map(int,input().split())) for _ in range(n)]
n1=[]
num1=10**9
ans=0
for i in range(n):
    n1.append(num[i][0]+num[i][1])
ans=max(ans,max(n1)-min(n1))
n1=[]
for i in range(n):
    n1.append(num1-num[i][0]+num[i][1])
ans=max(ans,max(n1)-min(n1))
print(ans)


Measured memory_bytes: 53560