akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct P {
	int x, y;
};

struct Edge {
	int to, cost;
};

const int inf = 1e9;

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

int W, H;
int dist[20][20];
bool m[20][20];
bool inRange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}
void bfs(P s) {
	fill(dist[0], dist[20], inf);
	dist[s.y][s.x] = 0;
	queue<P> Q; Q.push( (P){s.x, s.y} );
	while ( !Q.empty() ) {
		P p = Q.front(); Q.pop();
		for (int d = 0; d < 4; ++d) {
			int nx = p.x+dx[d];
			int ny = p.y+dy[d];
			if (inRange(nx, ny) && !m[ny][nx] && dist[p.y][p.x]+1 < dist[ny][nx]) {
				dist[ny][nx] = dist[p.y][p.x]+1;
				Q.push((P){nx, ny});
			}
		}
	}
}
int main() {
	while (cin >> W >> H, W || H) {
		fill(m[0], m[20], false);
		int sx = -1, sy = -1;
		vector<P> target;
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x) {
				switch (str[x]) {
					case '.': break;
					case 'o': sx = x, sy = y; break;
					case '*': target.push_back( (P){x, y} ); break;
					case 'x': m[y][x] = true; break;
				}
			}
		}
		target.push_back((P){sx, sy});
		int cost[20][20];
		int N = target.size();
		for (int i = 0; i < N; ++i) {
			bfs(target[i]);
			for (int j = 0; j < N; ++j) {
				cost[i][j] = dist[target[j].y][target[j].x];
//				cout << i << " " << j << " " << cost[i][j] << endl;
			}
		}

		int dp[12][1 << 11]; fill(dp[0], dp[12], inf); dp[N-1][1<<(N-1)] = 0;
		for (int w = 1; w <= N; ++w) {
			for (int i = 0; i < N; ++i) {
				for (int j = 1; j < (1 << N); ++j) {
					for (int to = 0; to < N; ++to) {
						if ( (j & (1 << to)) == 0 && dp[i][j] != inf ) {
//							cout << i << " " << j << " " << to << " " << dp[i][j] << " " << cost[i][to] << endl;
							dp[to][j|(1<<to)] = min(dp[to][j|(1<<to)], dp[i][j]+cost[i][to]);
						}
					}
				}
			}
		}
		int ans = inf;
		for (int i = 0; i < N; ++i) {
			ans = min(ans, dp[i][(1<<N)-1]);
		}
		if (ans == inf) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}

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

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b,k;
    cin >> a >> b >> k;
    if(a<k){
    	
    	k-=a;
    	a=0;
    	if(b<k){
    		b=0;
    		cout << a << " " << b << endl;
    	}
    	else{
    		b-=k;
    		cout << a << " " << b << endl;

    	}

    }
    else{
    	a-=k;
    	cout << a << " " << b << endl;
    }

    

	return 0;
}

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

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"

const int N = 2e5;
const int INF = 2e9;

int n, v[N], w[N], W;
ll dp[N][200];

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n >> W;
	for(int i = 1; i <= n; ++i) {
		cin >> w[i] >> v[i];
	}
	//for(int k = 1; k <= n; ++k) {
		for(int s = 1; s <= W; ++s) {
		    for(int k = 1; k <= n; ++k) {
			if(s >= w[k]) {
				dp[s][k] = max(dp[s][k - 1], dp[s - w[k]][k - 1] + v[k]);		
			}
			else {
				dp[s][k] = dp[s][k - 1];	
			}
			//show(s);
			//show(k);
			//show(dp[s][k]);			
		}
	}
	cout << dp[W][n];
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int d, t, s;
    cin >> d >> t >> s;
    cout << ((d + s - 1) / s > t ? "No" : "Yes");
}


Measured memory_bytes: 3648
t[9999][999],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}} 

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a>=k){
    cout << k;
  }
  else if(a+b>=k){
    cout << a;
  }
  else{
    cout << a - (k-(a+b));
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else if (a == b) {
		printf("a == b\n");
	}
	return 0;

}

Measured memory_bytes: 2552
N = int(input())
a = list(map(int, input().split(" ")))
a_list = [[i, 0] for i in range(N+1)]
a_comb = [[i, 0] for i in range(N+1)]
a_comb_sub = [[i, 0] for i in range(N+1)]

for i in a:
    a_list[i][1] +=1

for i in a_list:
    a_comb[i[0]][1] = i[1]*(i[1]-1) // 2

ans =0
for i in a_comb:
    ans+= i[1]


for i in a_list:
    if i[1] >=2:
        a_comb_sub[i[0]] = i[1]-1
    else:
        a_comb_sub[i[0]] = 0

for i in a:
    print(ans - a_comb_sub[i])

Measured memory_bytes: 92416
#include <bits/stdc++.h>
using namespace std;
using pll = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()

int main(){
  int N, M; cin >> N >> M;
  vector<pll> A(M);
  rep(i, M){
    int a, b; cin >> a >> b;
    A[i] = {a, b};
  }
  
  sort(all(A), [](pll l, pll m){return l.second < m.second;});
  int cur = -1000;
  int res = 0;
  rep(i, M){
    if (cur > A[i].first) continue;
    res++;
    cur = A[i].second;
  }
  
  cout << res << endl;
}


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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< pii,vector<pii> ,greater< pii >>

using namespace std;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}*/
//const int md = 998244353;

int solve(int x){

    int ans = 0LL;
    FOR(i,0,40){
        if(x < (1LL<<i))break;
        int y = (x+1)%(1LL<<(1+i));
        int z = (x+1)/(1LL<<(i+1));
        if(i == 0 && z&1)ans |= 1LL;
        else if(i > 0){
            if(y <= (1LL<<i))continue;
            int p = y-(1LL<<i);
            if(p&1)ans |= (1LL<<i);
        }
    }
    return ans;
}

signed main()
{
    showoff;
    int a,b;
    cin >> a >> b;
    cout << (solve(b)^solve(a-1)) << "\n";
    return 0;
}
//*->for large size of matrix +around 1e7 memory take int not long long ......

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include <bits/stdc++.h>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
using namespace std;

typedef long long ll;
 
const int N = 200005;

char s[N];
ll cnt[1000];
int n;
ll ans = 1;
 
int main()
{
 
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; i++) {
		ans += i - cnt[s[i]];
		cnt[s[i]]++;
	}
	printf("%lld\n", ans);
 
	return 0;
}

Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
ans=0
d=0
flag=True
if sum(a)<sum(b):
    print(-1)
else:
    flag=False
    for i in range(n):
        c.append(a[i]-b[i])
        if a[i]<b[i]:
            d-=a[i]-b[i]
            ans+=1
            
c.sort()
c.reverse()
e=0

for i in range(n):
    if e>=d:
        break
    else:
        e+=c[i]
        ans+=1
if not flag:
    print(ans)


Measured memory_bytes: 18492
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    if(n < s){
        cout << -1 << endl; return 0;
    }
    for(int i = 2; i * i <= n; i++){
        int sum = 0, a = n;
        while(a > 0){
            sum += a % i;
            a /= i;
            // cout << sum << " " << a << endl;
        }
        if(sum == s){
            cout << i << endl; return 0;
        }
    }
    for(int a0 = sqrt(n) + 1; a0 >= 1; a0--){
        int b = (n - s) / a0 + 1;
        int a1 = s - a0;
        // if(a0 <= 10) cout << a0 << " " << a1 << " " << b <<' ' << ((n - s) % a0) << ' ' << ((a0 + a1) == s) << " " << (b * b > n) << " "<<  ((a0 * b + a1) == n) << " "<<  (a0 > 0 && a0 < 0 && a1 >= 0 && a1 < b) <<  endl;
        if((n - s) % a0 == 0 && (a0 + a1) == s && (a0 * b + a1) == n && a0 >= 0 && a0 < b && a1 >= 0 && a1 < b){
            cout << b << endl;
            return 0;
        }
    }
    if(n == s){
        cout << n + 1 << endl; return 0;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let h: u64 = s.trim().parse().unwrap();

    println!("{}", f(h) - 1);
}

fn f(n: u64) -> u64 {
    if n == 0 {
        1
    } else {
        f(n / 2) * 2
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char s[11];
	scanf("%s",s);
	if(strcmp(s,"ani")==0)	printf("square1001\n");
	else printf("e869120\n");
	return 0;
}


Measured memory_bytes: 2620
#include<stdio.h>

int main(void){
  double a, b,  c, d, e, f, x, y;
  while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
    y = (c*d - f*a)/(b*d - a*e);
    x = (c - b*y)/a;
    printf("%.3f %.3f\n", x, y); 
  }
    return 0;
}

Measured memory_bytes: 652
#include <stdio.h>

int main(){
    int i ; 
    unsigned count[26] ;

    for (i=0 ;i<26 ;i++){
        count[i] = 0 ;
    }
    do {
        i = getchar();
        if ( i >= 'A' && i <= 'Z' ){
            count[i-'A'] ++ ;
        } else if ( i >= 'a' && i <= 'z' ){
            count[i-'a'] ++ ;
        } else if ( ( i >= 0x81 && i <= 0xa0 ) || ( i >= 0xe0 && i <= 0xfd ) ){
            getchar();
        }
    } while ( i != EOF ) ;
    for (i=0 ;i<26 ;i++){
        printf("%c : %d\n",'a'+i,count[i]);
    }
}


Measured memory_bytes: 2068
#include<iostream>
int main(){
  int n;
  std::cin >> n;
  long h[n];
  int i;
  int cnt = 0;
  int max = 0;;
  for(i=0;i<n;i++){
    std::cin >> h[i];
  }
  
    int tmp = h[0];
  for(i=1;i<n;i++){
    if(h[i] <= tmp){
      tmp = h[i];
      cnt ++;
    }else{
      tmp = h[i];
      if(max<cnt) max = cnt;
      cnt = 0;
    }
  }
   if(max<cnt) max = cnt;
  std::cout << max;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

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

	ll count = 1;
	ll ans = 0;

	while(true) {
		if (h == 1) {
			ans += count;
			break;
		}
		ans += count;
		h /= 2;
		count *= 2;
	}
	cout << ans << endl;
	

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
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;
  }
};

// h(n, r) = c(n+r-1, r)
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];
  }
};

int main()
{
  string s, t;
  cin >> s >> t;
  ll n = s.size(), m = t.size();
  set<char> st;
  rep(i, n) st.insert(s[i]);
  rep(i, m) {
    if(st.find(t[i]) == st.end()) {
      cout << -1 << endl;
      return 0;
    }
  }
  map<char, set<int>> mp;
  rep(i, n) mp[s[i]].insert(i+1);

  ll tearm = 0;
  ll now = 0;
  rep(i, m) {
    auto it = mp[t[i]].upper_bound(now);
    if(it == mp[t[i]].end()) {
      ++tearm;
      now = *mp[t[i]].begin();
    }
    else {
      now = *it;
    }
  }
  cout << tearm*n + now << endl;
}

Measured memory_bytes: 5120
class Main{
	/*
	 * ???????????¨???
	 */
    public static void main(String[] a){
    	for(int i=1; i<10; i++){
    		for(int j=1; j<10; j++){
    			System.out.println(i + "x" + j + "=" + i * j);
    		}
    	}
    }
}

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

int main(void) {
    string s;
    while (getline(cin, s)) {
        if (s == ".") break;

        stack<char> paren;
        bool flag = true;
        for (auto i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                paren.push(s[i]);
            } else if (s[i] == ')') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '(') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            } else if (s[i] == ']') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '[') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            }
        }

        if (paren.empty() && flag) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << (b - 1 + (a - 2)) / (a - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
# abc147_a.py
# https://atcoder.jp/contests/abc147/tasks/abc147_a

# A - Blackjack /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 3個の整数 A1, A2, A3が与えられます。
# A1+A2+A3が 22 以上なら bust、21以下なら win を出力してください。

# 制約
#     1≤Ai≤13  (i=1,2,3)
#     入力中のすべての値は整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A1 A2 A3

# 出力
# A1+A2+A3が 22 以上なら bust、21以下なら win を出力せよ。

# 入力例 1
# 5 7 9

# 出力例 1
# win

# 5+7+9=21なので win を出力します。

# 入力例 2
# 13 7 2

# 出力例 2
# bust

# 13+7+2=22なので bust を出力します。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if sum(values) > 21:
        result = 'bust'
    else:
        result = 'win'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 7 9']
        lines_export = ['win']
    if pattern == 2:
        lines_input = ['13 7 2']
        lines_export = ['bust']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = 0, startB = 0, endA = 0, startendBA = 0;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size() - 1; ++j)
      if (s[j] == 'A' && s[j + 1] == 'B') ans++;
    if (s.front() == 'B' && s.back() == 'A')
      startendBA++;
    else if (s.front() == 'B')
      startB++;
    else if (s.back() == 'A')
      endA++;
  }
  if (startendBA > 0) {
    ans += startendBA - 1;
    if (startB > 0) {
      ans++;
      startB--;
    }
    if (endA > 0) {
      ans++;
      endA--;
    }
  }
  ans += min(startB, endA);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


ll N;

int main(){
  cin >> N;
  int k=(int)pow(N,(0.5))+1;
  int ans= 12;
  
  reps(i,k){
    if(N%i==0){
      int m;
      m=max(log10(i)+1,log10(N/i)+1);
      ans=min(ans,m);
    }
  }
  cout << ans;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0)
				break;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ((i + j) % 2 == 0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 36052
#!/usr/bin/env python3

def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []
    for i in range(n):
        if i == 0:
            a.append(b[0])
        elif i == n - 1:
            a.append(b[-1])
        else:
            a.append(min(b[i - 1], b[i]))
    print(sum(a))

if __name__ == "__main__":
    main()


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

    string name[100];
    int score[100];
    vector<pair<string, int>> re(n);
    rep(i, n){
        cin >> name[i] >> score[i];
        re[i] = make_pair(name[i], -score[i]);
    }

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

    rep(i, n){
        rep(j, n){
            if(re[i].first == name[j] && re[i].second == -score[j]){
                cout << j+1 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int n, k;
int a[505];
set< pair<int, int> > bag[505];
int summ;
vector<int> dv;
vector<int> tmp;
ll pos[MAXN], neg[MAXN];

void findDivisors(int x, vector<int> &divisors) {
	int sq = sqrt(x);
	for (int i = 1; i <= sq; ++i)
		if (x % i == 0) {
			divisors.push_back(i);
			if (x/i != i)
				divisors.push_back(x/i);
		}
	sort(divisors.begin(), divisors.end());
}

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n >> k;
	FOR(i, 1, n) {
		cin >> a[i];
		summ += a[i];
	}
	
}


void preprocess() {
	
	findDivisors(summ, dv);
	
}

bool isok(int d) {
	tmp.clear();
	for (int i = 1; i <= n; ++i) {
		tmp.push_back(a[i] % d);
	}
	
	sort(tmp.begin(), tmp.end());
	
	if (tmp[tmp.size()-1] == 0) return 1;
	
	pos[0] = tmp[0];
	for(int i = 1; i < tmp.size(); ++i)
		pos[i] = pos[i-1] + tmp[i];
	
	neg[tmp.size()-1] = d-tmp[tmp.size()-1];
	for (int i = tmp.size()-2; i >= 0; --i)
		neg[i] = neg[i+1] + d-tmp[i];
	
	for (int i = 0; i < tmp.size()-1; ++i) {
		if (pos[i] == neg[i+1] && pos[i] <= k)
			return 1;
		if (pos[i] > k) break;
	}
	
	return 0;
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	int res = 0;
	for(auto d : dv) {
		if (isok(d))
			res = d;
	}
	
	cout << res << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct union_find{
    int N;
    vector<int> rank, par, sz;
    union_find(int n){
        N = n;
        rank.resize(N + 1, 1);
        par.resize(N + 1);
        sz.resize(N + 1, 1);
        for(int i = 1; i <= N; i++) par[i] = i;
    }

    int find(int x){
        return (par[x] == x ? x : par[x] = find(par[x]));
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] > rank[y]){
            sz[x] += sz[y];
            par[y] = x;
        }else{
            sz[y] += sz[x];
            par[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }

    int get_size(int x){
        return sz[find(x)];
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int N, M, K;
int res[100010];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M >> K;
    union_find uf(N);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
        res[a]--;
        res[b]--;
    }
    for(int i = 1; i <= N; i++){
        res[i] += uf.get_size(i);
    }
    for(int i = 0; i < K; i++){
        int c, d;
        cin >> c >> d;
        if(uf.same(c, d)){
            res[c]--;
            res[d]--;
        }
    }
    for(int i = 1; i <= N; i++) cout << res[i] - 1 << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

ll n,ans;

void bfs(ll x){
  if(x!=0&&x<=n){
    ll k=x,a=0,b=0,c=0;
    while(k!=0){
      if(k%10==3){
        a++;
      }
      else if(k%10==5){
        b++;
      }
      else if(k%10==7){
        c++;
      }
      k/=10;
    }
    if(a*b*c>0){
      ans++;
    }
  }
  if(x<=n){
    rep(i,3){
      bfs(10*x+3+2*i);
    }
  }
}

int main(){
  ans=0;
  cin >> n;
  bfs(0);
  cout << ans << endl;
}

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

int main()
{
	int n;
	cin>>n;
	
	int c0=0,c1=0,c2=0,c3=0;
	string s;
	
	for(int i=0;i<n;i++)
	{
		cin>>s;
		
		if(s=="AC")
		{
			c0++;
		}
		else if(s=="WA")
		{
			c1++;
		}
		else if(s=="TLE")
		{
			c2++;
		}
		else
		{
			c3++;	
		}	
	}
	cout<<"AC x "<<c0<<endl;
	cout<<"WA x "<<c1<<endl;
	cout<<"TLE x "<<c2<<endl;
	cout<<"RE x "<<c3<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;
  string temp;
  
  for(int i=0; i<N; i++){
    cin >> temp;
    if(temp == "AC"){
      AC++;
    }
    if(temp == "WA"){
      WA++;
    }
    if(temp == "TLE"){
      TLE++;
    }
    if(temp == "RE"){
      RE++;
    }
  }
  
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n);
  
  rep(x, 2) {
    int cnt = 0;
    rep(i, n) {
      if (s[i] == 'R') cnt++;
      else {
        ans[i] += cnt/2;
        ans[i-1] += (cnt + 1)/2;
        cnt = 0;
      }
    }
    reverse(ans.begin(), ans.end());
    reverse(s.begin(), s.end());
    rep(i, n) {
      if (s[i] == 'L') s[i] = 'R';
      else s[i] = 'L';
    }
  }
  rep(i, n) printf("%d ", ans[i]);
  printf("\n");
}


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

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  
  int ans = 0;
  int res = 0;
  
  rep(i,n-1){
    if(s[i]==s[i+1]){
      ans++;
    }else if(res<2*k){
      res++;
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N,A[5];cin>>N;
    ll ans = -1;
    for(int i=0;i<5;i++) {
        ll c;cin>>c;
        ll t=(N%c==0)?N/c+i:N/c+i+1;
        ans=max(ans+1,t);
    }
    cout<<ans<< "\n";
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;


int main() {

	int N;
	int L[10000];
	cin >> N;

	for (int i = 0; i < N; i++) { cin >> L[i]; }
	sort(L, L + N);

	int ans = 0;

	int jo, ge;


	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {

			if (L[i] + L[j] > L[N - 1]) { ans = ans + N - 1 - j; }
			else if (L[i] + L[j] <= L[j + 1]) { ans = ans; }
			else {

				jo = N - 1;
				ge = j + 1;

				while (jo != ge + 1) {
					if (L[i] + L[j] > L[(jo + ge) / 2]) { ge = (jo + ge) / 2; }
					else { jo = (jo + ge) / 2; }

				}

				ans = ans + ge - j;

				

			}

			


		}
	}

	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 504
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (&mut iter).take(m).map(|x| x.parse().unwrap()).collect();

    let mch = [0,2,5,5,4,5,6,3,7,6];
    let mut dp = vec![None;n+1];
    dp[0] = Some("".to_owned());
    for i in 0..n+1 {
        for &k in &a {
            if i + mch[k] >= n+1 {continue;}
            match (dp[i].clone(), dp[i+mch[k]].clone()) {
                (Some(p), Some(q)) => {
                    dp[i+mch[k]] = Some(cmp_max(&format!("{}{}", p, k), &q));
                },
                (Some(p), None) => {
                    dp[i+mch[k]] = Some(format!("{}{}", p, k));
                },
                _ => ()
            }
        }
    }
    println!("{}", dp[n].clone().unwrap());
}

fn cmp_max(a: &String, b: &String) -> String {
    if a.len() == b.len() {
        std::cmp::max(a.clone(), b.clone())
    } else if a.len() < b.len() {
        b.clone()
    } else {
        a.clone()
    }
}

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

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{ 
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

const tint MOVE = 4;

map<char,tint> mapping = {{'U',0},{'R',1},{'D',2},{'L',3}}; // (x+2)%4 gives the opposite

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	tint H,W,N,sr,sc;
	string s,t;
		
	while (cin >> H >> W >> N  >> sr >> sc >> s >> t)
	{
		
		vector<tint> dir_limit (MOVE);
		dir_limit[0] = sr;     // UP
		dir_limit[1] = W-sc+1; // RIGHT
		dir_limit[2] = H-sr+1; // DOWN
		dir_limit[3] = sc; // LEFT
		vector<tint> dir (MOVE,0);
		//~ imprimirVector(dir_limit);
		bool out_of_board = false;
		forn(i,N)
		{
			dir[mapping[s[i]]]++;
			//~ imprimirVector(dir);
			if (dir[mapping[s[i]]] >= dir_limit[mapping[s[i]]])
				out_of_board = true;
			if (dir[(mapping[t[i]]+2)%4] >= -dir_limit[mapping[t[i]]]+2)
				dir[(mapping[t[i]]+2)%4]--;
			//~ imprimirVector(dir);
			//~ cout << "------" << endl;
		}
		if (out_of_board)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	
	return 0;
}






Measured memory_bytes: 920
/*
ID: jerrywcy
TASK: AtCoder ABC 102 Problem C
LINK: https://abc102.contest.atcoder.jp/tasks/abc102_c
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;
int a[200010];

int main(){
	cin>>n;
	int i,j;
	for (i=1;i<=n;i++)cin>>a[i],a[i]-=i;
	sort(a+1,a+n+1);
	int b=0;
	if(n%2==0)b=(a[n/2+1]+a[n/2])/2;
	else b=a[n/2+1];
	
	long long ans=0;
	for (i=1;i<=n;i++)ans+=fabs(a[i]-b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)



// BFSによる塗りつぶし探索(多地点スタート形式)
#define MAX_H (1000)
#define MAX_W (1000)
typedef char Graph[MAX_H][MAX_W];
Graph graph;
typedef int Dist[MAX_H][MAX_W];
Dist dist;
bool seen[MAX_H][MAX_W];
int H, W; // グラフサイズ
typedef pair<int, int> P;

// 指定されたマスが次のdfsを行う対象かどうかをチェックする関数
// 0 <= h < H, 0 <= w < W を満たすこと
// その他追加条件を満たすこと　を確認
bool willCheck(int h, int w) {

	// グラフサイズ内であることの確認
	if (h < 0) return false;
	if (w < 0) return false;
	if (H <= h) return false;
	if (W <= w) return false;

	// 既に探索済みでないことの確認
	if (seen[h][w]) return false;

	// 問題ごとの条件を満たす確認
	if (graph[h][w] == '.') return true;

	return false;
}

void bfs(vector<P> start) {
	// キューを用意して、初期探索点をセット
	queue<P> que;
	for (int i = 0; i < start.size(); i++) {
		que.push(P(start[i].first, start[i].second)); // 初期点の距離を0
		dist[start[i].first][start[i].second] = 0;
		seen[start[i].first][start[i].second] = true;
	}

	while (!que.empty()) { // BFSループ
		// ★★　この中で迂闊に break しないこと

		// キューの先頭のセルを取得
		P v = que.front(); que.pop();
		int h = v.first;
		int w = v.second;

		// 取得したセルに対する処理

		// そのセルからつながるセルに処理を移行
		if (willCheck(h + 1, w)) {
			dist[h + 1][w] = dist[h][w] + 1;
			seen[h + 1][w] = true; // ここでseenをセットしないと、queに同一アイテムが入る
			que.push(P(h + 1, w));
		}
		if (willCheck(h - 1, w)) {
			dist[h - 1][w] = dist[h][w] + 1;
			seen[h - 1][w] = true;
			que.push(P(h - 1, w));
		}
		if (willCheck(h, w + 1)) {
			dist[h][w + 1] = dist[h][w] + 1;
			seen[h][w + 1] = true;
			que.push(P(h, w + 1));
		}
		if (willCheck(h, w - 1)) {
			dist[h][w - 1] = dist[h][w] + 1;
			seen[h][w - 1] = true;
			que.push(P(h, w - 1));
		}
	}

}

int main() {

	cin >> H >> W;

	vector<P> start;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char tmp;
			cin >> tmp;
			graph[i][j] = tmp;
			if (tmp == '#') start.push_back(P(i, j));
		}
	}

	bfs(start);

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, dist[i][j]);
		}
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 29928
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> h(n);
	for(int& i:h)
		cin>>i;

	vector<int> dp(n,INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j:{i+1,i+2})
			if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
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;
}
int n,l;string a[105];
bool cmp(string a,string b){
	return a<b;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);in(l);
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)cout<<a[i];
	return 0;
}


Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    REP(x, k + 1) {
        REP(y, k + 1) {
            int z = s - x - y;
            if (z >= 0 && z <= k) cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(x,y,a,b,c);
    vl p(a); in1(p);
    vl q(b); in1(q);
    vl r(c); in1(r);
    sort(all(p));
    p.erase(p.begin(),p.begin()+(a-x));
    sort(all(q));
    q.erase(q.begin(),q.begin()+(b-y));
    p.insert(p.end(),all(q));
    p.insert(p.end(),all(r));
    sort(all(p));
    p.erase(p.begin(),p.begin()+p.size()-(x+y));
    ll ans= accumulate(all(p),0ll);
    out(ans);
}

Measured memory_bytes: 5872
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import fractions
lcm = (C * D) // fractions.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Measured memory_bytes: 5204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;

// メインクラス
public class Main {
    // メインメソッド
    public static void main(String[] args) throws IOException {
        ArrayList<String> dataSet = inputDataSet("0"); // データセットを読み込む
        
        // 全てのデータセットに対し、処理を行う
        for(String line : dataSet){
            int n = Integer.parseInt(line);
        
            removeUnluckyNumber.showConvNum(n, 1); // 変換した数字を表示する
            System.out.println();
        }
    }
    
    // データセットを1行毎に格納したリストを返すメソッド
    // 入力の終端か、データセットの終端を示すterminalに達するまで読み込む
    public static ArrayList<String> inputDataSet(String terminal) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        ArrayList<String> dataSet = new ArrayList<String>();
        while(true){
            String line = br.readLine();
            if(line == null || line.equals(terminal))break;
            dataSet.add(line);
        }
        
        return dataSet;
    }
}

// 忌み数除去クラス
class removeUnluckyNumber{
    // 1桁(0~8)の変換表
    private static int[] convTable = {0, 1, 2, 3, 5, 7, 8, 9};
    
    //再帰により変換後の番号を1文字づつ表示していくメソッド
    public static void showConvNum(int n, int d){
        if(n == 0 || d > 10)return; // nが0になったか、深さが10を超えた場合、終了
        
        showConvNum(n >> 3, d + 1); // nを8で割り、再帰呼び出し
        System.out.print(convTable[n & 7]); // 8進数下1桁を変換して出力
    }
}



Measured memory_bytes: 48548
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]


def calc_mp(v):
    if v[0] == 0 or v[1] == 0 or v[2] == 0:
        return 10 ** 9
    return abs(A - v[0]) + abs(B - v[1]) + abs(C - v[2]) - 30


def dfs(n, v):
    if n == N:
        return calc_mp(v)
    ret0 = dfs(n + 1, (v[0] + l[n], v[1], v[2])) + 10
    ret1 = dfs(n + 1, (v[0], v[1] + l[n], v[2])) + 10
    ret2 = dfs(n + 1, (v[0], v[1], v[2] + l[n])) + 10
    ret3 = dfs(n + 1, (v[0], v[1], v[2]))

    return min(ret0, ret1, ret2, ret3)


ans = dfs(0, (0, 0, 0))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,o,p,aa[110000],cntl=0,ab[110000];
pair<int,int> pp[110000];
string s,ss[220000];
char c,cc[5000][5000]={};
queue<int> que;
signed main(){
    cin>>n;
    for(int i=-1000;i<1001;++i){
        aa[i+1000]=i*i*i*i*i;
    }
    rep(i,2001){
        rep(j,i){
            if(aa[i]-aa[j]==n){
                cout<<i-1000<<' '<<j-1000;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 10536
# heap を使ったもの（パフォーマンス良い）
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| push(a)}
  end

  def push(element)
    @data.push(element)
    bottom_up
  end

  def pop
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end

  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def parent_idx(target_idx)
    (target_idx - (target_idx.even? ? 2 : 1)) / 2
  end

  def bottom_up
    target_idx = size - 1
    return if target_idx == 0
    parent_idx = parent_idx(target_idx)
    while (@data[parent_idx] > @data[target_idx])
      swap(parent_idx, target_idx)
      target_idx = parent_idx
      break if target_idx == 0
      parent_idx = parent_idx(target_idx)
    end
  end

  def top_down
    target_idx = 0

    # child がある場合
    while (has_child?(target_idx))

      a = left_child_idx(target_idx)
      b = right_child_idx(target_idx)

      if @data[b].nil?
        c = a
      else
        c = @data[a] <= @data[b] ? a : b
      end

      if @data[target_idx] > @data[c]
        swap(target_idx, c)
        target_idx = c
      else
        return
      end
    end
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
e = a.map{|x| -x}
b = PriorityQueue.new(e)
m.times do
  c = b.pop
  b.push(-(-c / 2))
end
ans = 0
while b.size > 0
  ans -= b.pop
end
puts ans

Measured memory_bytes: 14004
//agc029_b.cpp
//Sat Dec 15 21:47:09 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	sort(a,a+n);
	int beki[n];
	int pair[n];
	fill(pair,pair+n,0);
	for (int i=0;i<n;i++){
		beki[i] = floor(log2(a[i]));
		int sumgoal = pow(2,beki[i]+1)-a[i];
		int* pos = lower_bound(a,a+i-1,sumgoal);
		int temp = (int)(pos-a);
		if (a[temp]==sumgoal){
			pair[i] = sumgoal;
		}
	}

	ll ans = 0;

	for (int i=n-1;i>=0;i--){
		if (pair[i]>0 && samecount[a[i]] > 0 && samecount[pair[i]] > 0){
			if (pair[i]==a[i] && samecount[a[i]]>=2){
				ans++;
				samecount[a[i]] = samecount[a[i]]-2;
			}else if (pair[i] != a[i]){
				ans++;
				samecount[pair[i]]--;
				samecount[a[i]]--;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 10824