akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1], inv[1];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

ll vec[200001];
int n;

int solve(int l, int r) {
    int le = l, ri = r - 1, mid;
    ll nn = vec[r] - vec[l - 1];

    while (le <= ri) {
        mid = (le + ri) / 2;
        ll sum = vec[mid] - vec[l - 1];
        if (sum < nn / 2) le = mid + 1;
        else ri = mid - 1;
    }

    return max(l, ri);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &vec[i]);
        vec[i] += vec[i - 1];
    }

    // 왼쪽구간 끝
    ll ans = 1e18;
    for (int i = 2; i <= n - 2; i++) {
        int le = solve(1, i);
        int ri = solve(i + 1, n);

        for (int j = 0; j < 2 - (le+1 == i); j++) {
            for (int k = 0; k < 2 - (ri+1 == n); k++) {
                ll miv = 1e18, mav = 0;
                if (j == 0) {
                    mav = max(mav, vec[le]);
                    miv = min(miv, vec[le]);
                    mav = max(mav, vec[i] - vec[le]);
                    miv = min(miv, vec[i] - vec[le]);
                }
                else {
                    mav = max(mav, vec[le + 1]);
                    miv = min(miv, vec[le + 1]);
                    mav = max(mav, vec[i] - vec[le + 1]);
                    miv = min(miv, vec[i] - vec[le + 1]);
                }

                if (k == 0) {
                    mav = max(mav, vec[ri] - vec[i]);
                    miv = min(miv, vec[ri] - vec[i]);
                    mav = max(mav, vec[n] - vec[ri]);
                    miv = min(miv, vec[n] - vec[ri]);
                }
                else {
                    mav = max(mav, vec[ri + 1] - vec[i]);
                    miv = min(miv, vec[ri + 1] - vec[i]);
                    mav = max(mav, vec[n] - vec[ri + 1]);
                    miv = min(miv, vec[n] - vec[ri + 1]);
                }
                ans = min(ans, mav - miv);
            }
        }
    }

    printf("%lld", ans);
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<string, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct UnionFind
{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

struct Edge
{
    int from, to, cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

bool operator<(const Edge &e, const Edge &f)
{
    return e.cost > f.cost;
}

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

    int n;
    cin >> n;
    priority_queue<Edge> es;
    int res = 0;
    UnionFind uf(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int a;
            cin >> a;
            if (a == -1)
                continue;
            if (j <= i)
                continue;
            es.push(Edge{i, j, a});
        }
    }
    while (!es.empty())
    {
        Edge e = es.top();
        es.pop();
        if (uf.find(e.from, e.to))
            continue;
        res += e.cost;
        uf.unite(e.from, e.to);
    }
    cout << res << endl;
}



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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	string s;
	set<char> st;
	bool flag = false;

	cin >> s;

	REP(i, s.size()) {
		if (st.count(s[i]) == false) {
			st.insert(s[i]);
		}
		else {
			flag = true;
			break;
		}
	}

	if (flag == false) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
}


Measured memory_bytes: 256
N = int(input())
ST = [list(input().split()) for i in range(N)]
X = input()
S = [ ST[i][0] for i in range(N)]
time = [int(ST[i][1]) for i in range(N)]
# print(ST)
# print(time)
idx = S.index(X)
# print(idx)
print(sum(time[idx+1:]))


Measured memory_bytes: 3060
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

//res.first*a+res.second*b == 1 となるresを返す (a,bは互いに素)
pair<long long, long long> extgcd(long long a,long long b)
{
	if(b==1){
		return pair<long long, long long>(0,1);
	}
	pair<long long, long long> t=extgcd(b,a%b);
	return pair<long long, long long>(t.second,t.first-a/b*t.second);
}

//modの逆元を返す
long long inverse(long long a,long long mod)
{
	return (extgcd(mod,a).second+mod)%mod;
}

//xCyを返す
long long Cinv(long long x, long long y, const long long mod){
	long long n = 1 ,r = 1;
	for(int i = 0; i < y; i++){
		n = n*(i+1)%mod;
		r = r*(x-i)%mod;
	}
	return r*inverse(n,mod)%mod;
}
const LL mod = 1e9+7;

int main()
{
	ios_init();
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	w--; h--; a--; b--;
	b++;
	LL ans = 0;
	LL c1 = -1, c2 = -1;
	REP(i,h-a){
		if(i == 0){
			c1 = Cinv(b-1+i,i,mod);
			c2 = Cinv(h-i+w-b,w-b,mod);
		}else{
			c1 = c1*(b-1+i)%mod*inverse(i,mod)%mod;
			c2 = c2*inverse(h-(i-1)+w-b,mod)%mod*(h-i+1)%mod;
		}
		ans += c1*c2%mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int D;
	double E;
	cin >> D >> E;
	while (D != 0) {
		double ans = INF;
		REP(y, D + 1) {
			int x = D - y;
			double dx = x;
			double dy = y;
			double cur = abs(sqrt(dx * dx + dy * dy) - E);
			chmin(ans, cur);
		}
		printf("%.5f\n", ans);
		cin >> D >> E;
	}
	return 0;
}



Measured memory_bytes: 3200
import java.io.*;
import java.util.*;

public class Main {

	static int[] a, b, memo[], pow[];
	static int MOD = (int) 1e9 + 7;

	static int dp(int idx, int rem) {
		if (idx == a.length)
			return rem == 0 ? 1 : 0;
		if (memo[idx][rem] != -1)
			return memo[idx][rem];
		int ans = 0;
		for (int take = 0; take <= rem; take++) {
			int tmp = pow[b[idx]][take] - pow[a[idx] - 1][take];
			if (tmp < 0)
				tmp += MOD;
			ans += tmp * 1L * dp(idx + 1, rem - take) % MOD;
			if (ans >= MOD)
				ans -= MOD;
		}
		return memo[idx][rem] = ans;

	}

	private static int pow(long b, int e) {
		// TODO Auto-generated method stub
		long ans = 1;
		while (e > 0) {
			if (e % 2 == 1)
				ans = ans * b % MOD;
			e >>= 1;
			b = b * b % MOD;
		}
		return (int) ans;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), C = sc.nextInt();
		a = new int[n];
		memo = new int[n][C + 1];
		pow = new int[401][401];
		for (int b = 1; b <= 400; b++) {
			int curr = 1;
			for (int e = 0; e <= 400; e++) {
				pow[b][e] = curr + pow[b - 1][e];
				if (pow[b][e] >= MOD)
					pow[b][e] -= MOD;
				curr = (int) (curr * 1L * b % MOD);
			}
		}
		b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			Arrays.fill(memo[i], -1);
		}
		for (int i = 0; i < n; i++)
			b[i] = sc.nextInt();
		System.out.println(dp(0, C));
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 23740
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline






def main():
    def segfunc(x, y):
        return x + y

    def init(init_val):
        for i in range(n):
            seg[i + num - 1] = init_val[i]

        for i in range(num - 2, -1, -1):
            seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k - 1) // 2
            seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = segfunc(res, seg[p])
            if q & 1 == 1:
                res = segfunc(res, seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

    N, Q = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    # seg tree初期値 (単位元)
    n = N
    ide_ele = 0
    num = 2 ** (n - 1).bit_length()
    seg = [ide_ele] * 2 * num

    init(A)

    for _ in range(Q):
        q, p, x = [int(x) for x in input().split()]
        if q == 0:
            A[p] += x
            update(p, A[p])
        else:
            print(query(p, x))





if __name__ == '__main__':
    main()



Measured memory_bytes: 67728
#include <stdio.h>
void trace(int a[],int N)
{
	int i;
	for(i=0;i<N;i++)
	{
		if(i>0) printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
}
void insertionSort(int a[],int N)
{
	int i,j,v;
	for(i=1;i<=N-1;i++)
	{
		v=a[i];
		j=i-1;
		while(j>=0&&a[j]>v)
		{
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		trace(a,N);
	}
}
int main()
{
	int i,j,N;
	int a[100];
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&a[i]);
	trace(a,N);
	insertionSort(a,N);
	return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
  int k,c,i,total,kai,t;

  for(t=0; t<100; t++){
    scanf("%d",&k);

    if(k ==0 ) break;

    total=0;
    for(i=0; i<(k*k-k)/2; i++){
      scanf("%d",&c);

      total+=c;
    }

    kai=total/(k-1);
    printf("%d\n",kai);
  }

    return 0;
}
	  

Measured memory_bytes: 600
import java.io.*;

public class Main {

  static long n, ans;

  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    ans = 0L;

    for(long i = 1; i <= n; i++){
      if(i % 3 != 0 && i % 5 != 0) ans += i;
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 32604
H, W = map(int, input().split())
A = [input() for _ in range(H)]
ans = []
ans.append('#'*(W+2))
for i in range(H):
    ans.append('#'+A[i]+'#')
ans.append('#'*(W+2))
for a in range(H+2):
    print(ans[a])

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
//#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main()
{
	int a,b;
	
	cin >> a >> b ;
	cout << a*b << "\n";

	return 0;
}

Measured memory_bytes: 3636
input_line = input().split()
#print(input_line)
count5 = 0
count7 = 0
#print(input_line[0])
#print(len(input_line))
for i in range(len(input_line)):
#  print(input_line[i])
  if int(input_line[i]) == 5:
#    print(input_line[i])
    count5 += 1
#    print(count5)
  elif int(input_line[i]) == 7:
    count7 += 1
#    print(count7)
if count5 == 2 and count7 == 1:
  print("YES")
#  print(count5,count7)
else:
#  print(count5,count7)
  print("NO")

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

using namespace std;

int main() {
	int n, m;

	cin >> n >> m;

	vector< vector< int > > map(n, vector< int >(n, -1 << 30));
	
	for(int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		map[a][b] = c;
	}

	for(int k = 0; k < n; k++) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				map[i][j] = max(map[i][j], map[i][k] + map[k][j]);
			}
		}
	}

	cout << map[0][n - 1] << endl;
}

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

int RoundUp(int Integer, int Power)
{
	int Place = pow(10, Power);
	if(Integer % Place != 0){
		Integer = Place * (Integer / Place + 1);
	}
	return Integer;
}

int main()
{
	int Debt = 100000;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		Debt = RoundUp(1.05 * Debt, 3);//?????¬???????????????????????±????????§??????????????????????????????????????????
	}
	cout << Debt << endl;
	return 0;
}

Measured memory_bytes: 3004
while True:
    a,b,c=map(str,input().split())
    n1=int(a)
    n2=int(c)
    if b=="+":
        r=n1+n2
    elif b=="-":
        r=n1-n2
    elif b=="*":
        r=n1*n2
    elif b=="/":
        r=n1//n2
    else:
        break
    print(r)


Measured memory_bytes: 5592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

typedef tuple<double, double, double> T;
int n, m;
double ans = 0;
vector<T> vt;

vector<vector<int> > vvi;

double dist_d(double a, double b) {
	return (a - b)*(a - b);
}
double dist(T a, T b) {
	return dist_d(get<0>(a), get<0>(b))
		+ dist_d(get<1>(a), get<1>(b))
		+ dist_d(get<2>(a), get<2>(b));
}

int main() {
	cin >> n >> m;
	rep(i, n) {
		double l, a, b;
		cin >> l >> a >> b;
		vt.push_back(T(l, a, b));
	}
	rep(i, (1 << n)) {
		int cnt = 0;
		rep(j, n) {
			if(i&(1 << j))cnt++;
		}
		if (cnt == m) {
			double sum = 0;
			rep(j, n) {
				FOR(k, j + 1, n) {
					if (i&(1 << j) && i&(1 << k)) {
						sum += dist(vt[j], vt[k]);
					}
				}
			}
			ans = max(ans, sum);
		}
	}
	printf("%.20lf\n", ans);
}



Measured memory_bytes: 3280
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <chrono>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef tuple<ll,ll,ll> tll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	int N;
	cin>>N;
	vint P;
	for(int i=0;i<N;i++){
		int p;
		cin>>p;
		P.pb(p);
	}
	sort(P.begin(),P.end(),greater<int>());
	P[0]/=2;
	int ans=0;
	for(int p:P)
		ans+=p;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    ll a1,ans,b1,a2,a3,b2,b3;
    cin>>a1>>ans>>b1>>a2>>a3>>b2>>b3;
    ll c1=min({a1,a2,a3});
    ans+=2*(a1/2);
    a1=a1%2;
    ans+=2*(a2/2);
    ans+=2*(a3/2);
    a2%=2;
    a3%=2;
    if(a1==1 && a2==1 && a3==1)
    {
        ans+=3;
    }
    else
    {
        if(a1+a2+a3>0 && c1>0)
        {
            ans+=a1+a2+a3-1;
        }
    }
    
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3784
n = int(input())
numbers = input()

numbers = [int(x)  for x in numbers.split()]

smallest = set()
for i in range(1,len(numbers) - 1):
    #print(numbers[i])
    if (numbers[i] < numbers[i -1] and numbers[i] > numbers[i + 1] ) or (numbers[i] < numbers[i +1] and numbers[i] > numbers[i - 1] ):
        if not(numbers[i] in smallest):
            smallest.add(numbers[i])
    
        
print(len(smallest))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n,k;
int ans=0;
int tri(int n){
    return n*(n+1)/2;
}
signed main(){
    cin>>n>>k;
    for(int i=k;i<=n+1;i++){
        int mini=tri(i-1);
        int maxi=i*(2*n-i+1)/2;
        ans+=maxi-mini+1;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=[0]*n
even=[0]*n

if a[0]%2==0:
    even[0]=2
else:
    odd[0]=1
    even[0] = 1

for i in range(n-1):
    if a[i+1]%2==0:
        odd[i+1]+=odd[i]*2
        even[i+1]+=even[i]*2
    else:
        odd[i+1]+=even[i]+odd[i]
        even[i+1]+=odd[i]+even[i]

if p==0:
    print(even[n-1])
else:
    print(odd[n-1])


Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

// N <= 10^5
const int MAX_N = 1e5 + 10;
int N;
//int dp[30][MAX_N];              // stack内には取り切れない

int main()
{
  cin >> N;

  // 10^5 のコイン
  vector<int> coins;
  coins.push_back(1);
  for(int k = 6; k <= MAX_N; k *= 6)
    coins.push_back(k);
  for(int k = 9; k <= MAX_N; k *= 9)
    coins.push_back(k);

  sort(coins.begin(), coins.end()); // 小さい順
  // for(auto it = coins.begin(); it != coins.end(); ++it)
  //   cout << *it << endl;

  // dp[i] = i円を払う最小枚数
  vector<int> dp(N+1, 1e8);
  dp[0] = 0;
  REP(i,1,N+1) {
    REP(j,0, coins.size()) {
      if (i - coins[j] >= 0) {
        // i - value[j] 円払えるなら、それに value[j] 円を 1 枚足して i 円を払える
        dp[i] = min(dp[i - coins[j]] + 1, dp[i]);
      }
    }
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        s[i] = 'x';
    }
    out(s);
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(){
    
    int a,b,sum,keta=0;
    while(scanf("%d %d",&a,&b)!=-1){
        keta=0;
        sum=a+b;
        
        while(sum>0){
            sum/=10;
            keta++;
        }
        printf("%d\n",keta);
    }
    
    return 0;
}

Measured memory_bytes: 600
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

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); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pii> vec(n);
	rep(i,n){
		cin >> vec[i].second >> vec[i].first;
	}
	sort(all(vec));
	int now = 0;
	rep(i,n){
		now += vec[i].second;
		if(now > vec[i].first) return cout << "No\n",0;
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 3328
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        R: usize,
        G: usize,
        B: usize,
        N: usize,
    }
    let mut count = 0;
    let mut balls = vec![R, G, B];
    balls.sort_by(|a, b| b.cmp(a));
    for a in 0..N/balls[0]+1 {
        for b in 0..(N-a*balls[0])/balls[1]+1 {
            let cc = N - (a*balls[0] + b*balls[1]);
            if cc % balls[2] > 0 { continue; }
            count += 1;
        }
    }
    println!("{}", count)
}

Measured memory_bytes: 4352
N = int(input())
W = [int(x) for x in input().split()] 
s = [0]*(N+1)

for i in range(N):
  s[i+1] = s[i]+W[i]

a =  [abs(s[N] - 2 * s[i]) for i in range(N)]
print (min(a))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0 ; i<(n) ; ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair <ll, ll> P;

int main(){
  string s,t;
  cin >> s >> t;
  int flag = 1;
  rep(i,s.size()){
    if(s[i] != t[i]) flag=0;
  }
  if(t.size()-s.size()!=1) flag=0;

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl; 
  return 0;
}


Measured memory_bytes: 3616
from collections import deque
import copy


def bfs(start, s):
    h = len(s)
    w = len(s[0])
    distance = 0
    maze = [[-1] * w for _ in range(h)]
    maze[start[0]][start[1]] = 0
    s[start[0]][start[1]] = "#"
    drcs = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    q = deque()
    q.append(start)
    while(q):
        cr, cc = q.popleft()
        for dr, dc in drcs:
            nr, nc = cr + dr, cc + dc
            if nr < 0 or nc < 0 or nr >= h or nc >= w:
                continue
            if s[nr][nc] == ".":
                q.append([nr, nc])
                s[nr][nc] = "#"
                maze[nr][nc] = maze[cr][cc] + 1
                if maze[nr][nc] > distance:
                    distance = maze[nr][nc]
                    goal = [nr, nc]
    return goal, distance
    


def main():
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    for r in range(h):
        if "." in s[r]:
            start = [r, s[r].index(".")]
    goal, distance = bfs(start, copy.deepcopy(s))
    _, res = bfs(goal, s)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3436
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

H, W = map(int, raw_input().split())

a = []
for i in range(H):
    a.append(map(int, raw_input().split()))

N = 0
ls = []
for i in range(H - 1):
    for j in range(W):
        if a[i][j] % 2:
            N += 1
            a[i + 1][j] += 1
            ls.append((i + 1, j + 1, i + 2, j + 1))

for j in range(W - 1):
    if a[H - 1][j] % 2:
        N += 1
        a[H - 1][j + 1] += 1
        ls.append((H, j + 1, H, j + 2))

print N
for p in ls:
    print " ".join(map(str, p))


Measured memory_bytes: 24440
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define rem_space(x) remove(all(x),' ')
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
typedef long long ll;
using namespace std;

int main() {
  int a[] = {1,3,5,7,8,10,12};
  int b[] = {4,6,9,11};
  int c[] = {2};

  int x,y;
  scanf("%d%d",&x,&y);

  if(count_if(a, a + len(a), [&x,&y](int i){return i == x || i == y;}) >= 2){
    puts("Yes\n");
  }else if(count_if(b, b + len(b), [&x,&y](int i){return i == x || i == y;}) >= 2){
    puts("Yes\n");
  }else if(count_if(c, c + len(c), [&x,&y](int i){return i == x || i == y;}) >= 2){
    puts("Yes\n");
  }else{
    puts("No\n");
  }

  return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: N
  integer,allocatable :: A(:)
  integer,allocatable :: A2(:)
  integer :: i
  integer :: mloc_tmp(1)
  integer :: mval, mloc
  read(*,*) N
  allocate(A(N))
  allocate(A2(N-1))
  do i = 1,N
     read(*,*) A(i)
  end do
  mloc_tmp = maxloc(A)
  mval = maxval(A)
  mloc = mloc_tmp(1)
  !
  do i = 1,mloc-1
     A2(i) = A(i)
  end do
  do i = mloc+1,N
     A2(i-1) = A(i)
  end do
  !
  do i = 1,N
     if ( i == mloc ) then
        write(*,'(i0)') maxval(A2)
     else
        write(*,'(i0)') mval
     end if
  end do

  deallocate(A2,A)
  stop
end program main


Measured memory_bytes: 3200
// 2011/09/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int a, b, c;
		cin >> a >> b >> c;
		if(a==0&&b==0&&c==0)
			break;

		int n = a+b+c;

		int P[301];
		P[0] = 1;
		for(int i=1; i<=n; i++)
			P[i] = 2;

		int N;
		cin >> N;

		int A3[1000][3];
		int N3 = 0;

		for(int i=0; i<N; i++){
			int I, J, K, R;
			cin >> I >> J >> K >> R;

			if(R==1){
				P[I] = P[J] = P[K] = 1;
				continue;
			}

			if(P[I]*P[J]*P[K]==0)
				continue;

			if(P[I]*P[J]*P[K]==2){
				if(P[I]==2)
					P[I] = 0;
				else if(P[J]==2)
					P[J] = 0;
				else
					P[K] = 0;
				continue;
			}

			if(P[I]*P[J]*P[K]==4){
				if(P[I]==1){
					A3[N3][0] = 0;
					A3[N3][1] = J;
					A3[N3][2] = K;
					N3++;
				}
				else if(P[J]==1){
					A3[N3][0] = 0;
					A3[N3][1] = I;
					A3[N3][2] = K;
					N3++;
				}
				else{
					A3[N3][0] = 0;
					A3[N3][1] = I;
					A3[N3][2] = J;
					N3++;
				}
				continue;
			}

			if(P[I]*P[J]*P[K]==8){
				A3[N3][0] = I;
				A3[N3][1] = J;
				A3[N3][2] = K;
				N3++;
			}

		}


		while(true){
			int flg = false;

			for(int i=0; i<N3; i++){
				if(P[A3[i][0]]*P[A3[i][1]]*P[A3[i][2]]==0){
					for(int j=i; j<N3-1; j++){
						A3[j][0] = A3[j+1][0];
						A3[j][1] = A3[j+1][1];
						A3[j][2] = A3[j+1][2];
					}
					N3--;
					flg = true;
					continue;
				}

				if(P[A3[i][0]]*P[A3[i][1]]*P[A3[i][2]]==2){
					if(P[A3[i][0]]==2)
						P[A3[i][0]] = 0;
					else if(P[A3[i][1]]==2)
						P[A3[i][1]] = 0;
					else
						P[A3[i][2]] = 0;
					for(int j=i; j<N3-1; j++){
						A3[j][0] = A3[j+1][0];
						A3[j][1] = A3[j+1][1];
						A3[j][2] = A3[j+1][2];
					}
					N3--;
					flg = true;
					continue;
				}

				if(P[A3[i][0]]*P[A3[i][1]]*P[A3[i][2]]==4){
					if(P[A3[i][0]]==1&&A3[i][0]!=0){
						A3[i][0] = 0;
						flg = true;
					}
					else if(P[A3[i][1]]==1&&A3[i][1]!=0){
						A3[i][1] = 0;
						flg = true;
					}
					else if(P[A3[i][2]]==1&&A3[i][2]!=0){
						A3[i][2] = 0;
						flg = true;
					}
				}
			}

			if(!flg)
				break;
		}

		for(int i=1; i<=n; i++)
			cout << P[i] << endl;
/*
		for(int i=0; i<N3; i++)
			cout << A3[i][0] << ' ' << A3[i][1] << ' ' << A3[i][2] << endl;
*/
	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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;}

class FloydWarshall {
public:
    const int size;
    vector<vector<int>> distance;

    FloydWarshall(const vector<vector<int>>& dist) :
        size(dist.size()),
        distance(dist) {
        for (int k = 0; k < size; ++k) {
            for (int i = 0; i < size; ++i) {
                for (int j = 0; j < size; ++j) {
                    if (distance[i][j] <= distance[i][k] + distance[k][j]) continue;
                    distance[i][j] = distance[i][k] + distance[k][j];
                }
            }
        }
    }
};

signed main() {
    int n, m, r;
    cin >> n >> m >> r;

    vi vr;
    rep(i, r) {
        capi(x); --x;
        vr.push_back(x);
    }

    vector<vector<int>> vc(n, vector(n, 1ll << 40));
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;

        vc[a][b] = c;
        vc[b][a] = c;
    }
    rep(i, n) {
        vc[i][i] = 0;
    }

    FloydWarshall fw(vc);

    sort(all(vr));
    int ans = 1ll << 40;

    do {
        int res = 0;
        rep(i, r - 1) {
            res += fw.distance[vr[i]][vr[i + 1]];
        }

        chmin(ans, res);
    } while(next_permutation(all(vr)));

    cout << ans;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
	string s, t;
	cin >> s >> t;
	int minn = 1000;
	for (int i = 0; i < sz(s) - sz(t) + 1; i++) {
		int ans = 0;
		for (int x = 0; x < sz(t); x++) {
			if (s[x + i] != t[x]) ans++;
		}
		minn = min(ans, minn);
	}
	cout << minn;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

ul check(ul n) {
  ul ans = 1;
  ul n_c = n;
  while (n_c>0) {
    ans = ans << 1;
    n_c = n_c >> 1;
  }
  return ans-n;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n;
  cin >> n;
  unordered_map< ul, ul > cnt;
  vector< ul > items(n);
  for (ul i=0; i<n; ++i) {
    ul ai;
    cin >> ai;
    if (cnt.count(ai)>0) cnt[ai]++;
    else cnt[ai]=1;
    items[i] = ai;
  }
  sort(items.begin(), items.end(), greater< int >());
  ul ans = 0;
  for (ul i=0; i<n; ++i) {
    if (cnt[items[i]]==0) continue;
    cnt[items[i]]--;
    ul c = check(items[i]);
    if (cnt[c]>0) {
      //cerr << c << " + " << items[i] << " = " << c+items[i] << endl;
      ans++;
      cnt[c]--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18420
#include <stdio.h>
int sum_c(int t[],int h[],int n,int m,int i,int j){
	int a,st=0,sh=0;
	for(a=0;a<n;a++){
		if(a==i)
			st+=h[j];
		else
			st+=t[a];
	}
	for(a=0;a<m;a++){
		if(a==j)
			sh+=t[i];
		else
			sh+=h[a];
	}
	return st==sh;
}
int main(void){
	int n,m,i,j,k,t[100],h[100],sum,anst,ansh;
	while(1){
		scanf("%d %d",&n,&m);
		if(!(n+m))
			break;
		sum=201;
		anst=ansh=101;
		for(i=0;i<n;i++)
			scanf("%d",&t[i]);
		for(i=0;i<m;i++)
			scanf("%d",&h[i]);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(sum_c(t,h,n,m,i,j)&&sum>t[i]+h[j]){
					anst=t[i];
					ansh=h[j];
					sum=anst+ansh;
				}
			}
		}
		if(sum!=201)
			printf("%d %d\n",anst,ansh);
		else
			puts("-1");
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 25;
char mat[N][N];
int h,w;

int dist[N][N];
int n,m;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int ok(int l,int c){
  return l>=1 and l<=n and c>=1 and c<=m and mat[l][c]!='#';
}

int BFS(pii ini){
  queue<pii> q;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      dist[i][j]=-1;
    }
  }
  dist[ini.ff][ini.ss]=0;
  q.push(ini);
  while(!q.empty()){
    pii cur = q.front();
    q.pop();
    for(int k=0;k<4;k++){
      int l = cur.ff + dx[k];
      int c = cur.ss + dy[k];
      if(ok(l,c) and dist[l][c]==-1){
        dist[l][c] = dist[cur.ff][cur.ss] + 1;
        q.push(pii(l,c));
      }
    }
  }
  int best=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      best = max(best,dist[i][j]);
    }
  }
  return best;
}


int32_t main(){
 fastio;
 cin >> h >> w;
 n = h,m =w;
 for(int i=1;i<=h;i++){
  for(int j=1;j<=w;j++){
    cin >> mat[i][j];
  }
 }
 int res=0;
 for(int i=1;i<=n;i++){
  for(int j=1;j<=m;j++){
    if(mat[i][j]=='.') res = max(res,BFS(pii(i,j)));
  }
 }
 cout << res << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))  #葉の数

    s=[0]*(n+1)
    for i in range(n,-1,-1):
        if i==n:
            s[i]=a[i]
        else:
            s[i]+=a[i]+s[i+1]

    b=[0]*(n+1)  #葉でない頂点数
    res=0
    flag=True
    for i in range(n+1):
        if i==0:
            if a[i]>=2:
                flag=False
                break
            if a[i]==1: b[i]=0
            else: b[i]=1
            res+=1
        else:
            v_max=min(s[i],2*b[i-1])
            if v_max<a[i]:
                flag=False
                break
            else:
                b[i]=v_max-a[i]
                res+=v_max
    
    if flag:
        print(res)
    else:
        print(-1)

if __name__=="__main__":
    main()

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

vector<int> v;

int n,arr[1002];
bool flag;

int main()
{
    flag = true;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    for(int i=0;i<n;i++)
        if(arr[i]%2==0)
            v.push_back(arr[i]);

    for(auto it:v)
    {
        if(it%3!=0 and it%5!=0)
        {
            flag=false;
            break;
        }
    }

    if(flag)
        cout<<"APPROVED";
    else
        cout<<"DENIED";



}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>


int n;
vector<P>t;

int main(){
    cin>>n;

    rep(i,n){
        int x,l;
        cin>>x>>l;
        t.pb(mp(x+l,x-l));
    }
    sort(t.begin(),t.end());

    int tmp=-pow(10,9)*2;
    int cnt=0;
    rep(i,n){
        int l,r;
        r=t[i].first,l=t[i].second;
        if(tmp<=l){
            tmp=r;
            cnt++;
        }
    }

    cout<<cnt<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  N = N % 10;
  
  if(N == 3){
    cout << "bon" <<endl;
  }else if(N == 0 || N == 1|| N == 6 || N == 8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }  
}


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

int main(int argc, char const *argv[]) {
  int a[3];
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  int ans;
  ans=a[2]*10+a[1]+a[0];
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  int tmp = n % 10;
  if (tmp == 3) {
    puts("bon");
  } else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8) {
    puts("pon");
  } else {
    puts("hon");
  }
  return 0;
}



Measured memory_bytes: 3592
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if (a%2==0||b%2==0) {
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 21844
import heapq
h = []
N, M = map(int, input().split())
As = list(map(int, input().split()))
for i in As:
    heapq.heappush(h, -i)
for _ in range(M):
    i = heapq.heappop(h)
    i = -1 * (-i // 2)
    heapq.heappush(h, i)
 
print(sum([-1 * heapq.heappop(h) for i in range(len(h))]))

Measured memory_bytes: 14180
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll j,mx[263005][2],mx2[263005][2],ans[263005],n,i,a[263005];
void update(ll a,ll b,ll c)
{
	if(mx[a][1]==c||mx2[a][1]==c)return;
	if(mx[a][0]<b)
	{
		mx2[a][0]=mx[a][0];
		mx2[a][1]=mx[a][1];
		mx[a][0]=b;
		mx[a][1]=c;
	}
	else if(mx2[a][0]<b)
	{
		mx2[a][0]=b;
		mx2[a][1]=c;
	}
}
int main()
{
	cin>>n;
	for(i=0;i<(1<<n);i++)cin>>a[i];
	memset(mx,-1,sizeof(mx));
	memset(mx2,-1,sizeof(mx2));
	ans[1]=a[0]+a[1];
	cout<<ans[1]<<endl;
	update(0,a[0],0);
	update(1,a[0],0);
	update(1,a[1],1);
	for(i=2;i<(1<<n);i++)
	{
		ans[i]=ans[i-1];
		update(i,a[i],i);
		for(j=0;j<n;j++)
		{
			if((1<<j)&i)
			{
				update(i,mx[i-(1<<j)][0],mx[i-(1<<j)][1]);
				update(i,mx2[i-(1<<j)][0],mx2[i-(1<<j)][1]);
			}
		}
		ans[i]=max(ans[i],mx[i][0]+mx2[i][0]);
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 15360