akhauriyash/Code-Regression huggingface dataset:
import heapq

n = int(input())
alist = list(map(int, input().split()))

ante, post = alist[:n], alist[-n:]
antesums = [0 for _ in range(n+1)]
postsums = [0 for _ in range(n+1)]
antesums[0] = sum(ante)
postsums[0] = sum(post)
post = list(map(lambda x: -x, post))
heapq.heapify(ante)
heapq.heapify(post)

for k in range(n):
  minante = heapq.heappushpop(ante, alist[n+k])
  antesums[k+1] = antesums[k] + alist[n+k] - minante
  maxpost = heapq.heappushpop(post, -alist[2*n-k-1])
  postsums[k+1] = postsums[k] + alist[2*n-k-1] + maxpost

ans = -sum(alist)
for k in range(n+1):
  if ans < antesums[k] - postsums[-k-1]:
    ans = antesums[k] - postsums[-k-1]
print(ans)


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

int main() {
	string S;
	cin >> S;
	char a, b, c, d;
	a = S.at(0);
	c = S.at(1);
	b = S.at(2);
	d = S.at(3);
	if (a == '0') {
		if (b == '0') {
			if (c == '0' && d == '0')
				cout << "NA" << endl;
			else if (c == '0')
				cout << "YYMM" << endl;
			else if (d == '0')
				cout << "MMYY" << endl;
			else
				cout << "AMBIGUOUS" << endl;
		}

		else if (b == '1') {
			if (d == '0' || d == '1' || d == '2') {
				if (c != '0')
					cout << "AMBIGUOUS" << endl;
				else
					cout << "YYMM" << endl;
			}

			else if (c != '0')
				cout << "MMYY" << endl;
			else
				cout << "NA" << endl;
		}

		else {
			if (c == '0')
				cout << "NA" << endl;

			else
				cout << "MMYY" << endl;
		}
		
	}

	else if (b == '0') {
		if (a == '1'){
			if (c == '0' || c == '1' || c == '2') {
				if (d != '0')
					cout << "AMBIGUOUS" << endl;
				else
					cout << "MMYY" << endl;
			}

			else if (d != '0')
				cout << "YYMM" << endl;
			else
				cout << "NA" << endl;
		}
		else {
			if (d != 0)
				cout << "YYMM" << endl;
			else
				cout << "NA" << endl;
		}
	}
	
	else if (a == '1' && b == '1') {
		if (c == '0' || c == '1' || c == '2') {
			if (d == '0' || d == '1' || d == '2')
				cout << "AMBIGUOUS" << endl;
			else
				cout << "MMYY" << endl;
		}

		else if (d == '0' || d == '1' || d == '2')
			cout << "YYMM" << endl;
		else
			cout << "NA" << endl;
	}

	else
		cout << "NA" << endl;
}

Measured memory_bytes: 256
int main(void)
{
  int a;
  int b;
  int sum=0;
 scanf("%d%d",&a,&b);
 for(int i=0;i<2;i++)
 {
   if(a>b)
   {
     sum+=a;
     a--;
   }
   else
   {
     sum+=b;
     b--;
   }
}
  printf("%d",sum);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e7;
const int maxn = 2e5 + 5;
ll mod = 1e9 + 7;

int n;
ll s[maxn], A, B;

ll f[maxn], g[maxn];
void add(int x, ll d, ll *t)
{
	if (x == 0)
	{
		(t[x] += d) %= mod;
		return;
	}
	while (x <= n)
	{
		(t[x] += d) %= mod;
		x += lowbit(x);
	}
}
ll sum(int x, ll *t)
{
	if (x < 0) return 0;
	ll ans = 0;
	while (x)
	{
		(ans += t[x]) %= mod;
		x -= lowbit(x);
	}
	return (ans + t[0]) % mod;
}
ll query(int x, ll *t)
{
	return (sum(x, t) - sum(x - 1, t) + mod) % mod;
}

int pf[maxn], pg[maxn], tot1, tot2;
int main()
{
	scanf("%d%lld%lld", &n, &A, &B);
	for (int i = 1; i <= n; i++) scanf("%lld", s + i);

	s[0] = -1e18;
	s[n + 1] = 2e18;
	add(0, 1, f); add(0, 1, g);
	pf[++tot1] = 0; pg[++tot2] = 0;
	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i-1, mid;
		while (l < r)
		{
			mid = (l + r) / 2 + 1;
			if (s[i + 1] - s[mid] >= B) l = mid;
			else r = mid - 1;
		}
		ll tmp1 = sum(r, f);
		if (s[i + 1] - s[i] < A)
		{
			while (tot1)
			{
				add(pf[tot1], -query(pf[tot1], f), f);
				//visf[pf[tot1]] = 0;
				--tot1;
			}
		}

		l = 0; r = i - 1;
		while (l < r)
		{
			mid = (l + r) / 2 + 1;
			if (s[i + 1] - s[mid] >= A) l = mid;
			else r = mid - 1;
		}
		ll tmp2 = sum(r, g);
		if (s[i + 1] - s[i] < B)
		{
			while (tot2)
			{
				add(pg[tot2], -query(pg[tot2], g), g);
				//visg[pg[tot2]] = 0;
				--tot2;
			}
		}

		add(i, tmp1, g);
		pg[++tot2] = i;
		add(i, tmp2, f);
		pf[++tot1] = i;
	}

	printf("%lld", sum(n, f));
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int d[n], s1=0, s2=0;
	for(int i=0; i<n; i++){
		cin >> d[i];
		s1+=d[i];
		s2+=d[i]*d[i];
	}
	cout << (s1*s1-s2)/2 << endl;
	return 0;
}

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

using namespace std;

const int N = 123456;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % ((long long) n * (n + 1) / 2)) {
    cout << "NO" << '\n';
    exit(0);
  }
  long long maxb = 0;
  for (int i = 1; i <= n; ++i) {
    b[i] = a[i] - a[i == 1 ? n : i - 1];
    maxb = max(maxb, (long long) b[i]);
  }
  long long all = 0;
  for (int i = 1; i <= n; ++i) {
    if ((maxb - b[i]) % n) {
      cout << "NO" << '\n';
      exit(0);
    }
    all += (maxb - b[i]) / n;
  }
  long long diff = sum / ((long long) n * (n + 1) / 2) - all;
  cout << (all == maxb && diff >= 0 && diff % n == 0 ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = in.nextInt();
        long a[] = new long[n];
        long s[] = new long[n - 1];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }

        for (int i = 0; i < n - 1; i++) {
            s[i] = a[i] + a[i + 1];
        }

        long count = 0;
        for (int i = 0; i < n - 2; i++) {
            if (s[i] > x && s[i + 1] > x) {
                long sub = Math.min(a[i + 1], Math.min(s[i] - x, s[i + 1] - x));
                s[i] -= sub;
                s[i + 1] -= sub;
                count += sub;
            }
        }

        for (int i = 0; i < n - 1; i++) {
            if (s[i] > x) {
                count += s[i] - x;
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 61580
#include <stdio.h>

int main() {
    int count = 0;
    char S[3],T[3];
    scanf("%s",S);
    scanf("%s",T);
    if (S[0] == T[0]) count++;
    if (S[1] == T[1]) count++;
    if (S[2] == T[2]) count++;
    printf("%d",count);
}

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

int main() {
   int A;
   cin >> A;
   cout << A / 100 + (A - A / 100 * 100) / 10 + (A - A / 100 * 100 - (A - A / 100 * 100) / 10 * 10) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (b >= a * c) {
        cout << c << endl;
    } else {
        cout << b / a << endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import math

def main():
    N = int(input())
    
    k = math.ceil(((1+8*N)**(1/2)-1)/2)
    
    ans = [i+1 for i in range(k)]
    
    if N != (k*(k+1))//2:
        ans.remove((k*(k+1))//2-N)
        
    print(*ans,sep="\n")
    
if __name__ == "__main__":
    main()


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

int main(){
    int X, A, B;
    cin >> X >> A >> B;

    if(A - B >= 0){
        cout << "delicious" << endl;
    }
    else if(A - B + X < 0){
        cout << "dangerous" << endl;
    }
    else{
        cout << "safe" << endl;
    }

}

Measured memory_bytes: 3588
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

vector<pair<ll, int>> factorize(ll x) {
  ll tmp = x;
  vector<pair<ll, int>> ret;
  for (ll i = 2ll; i * i <= x; i++) {
    int cnt = 0;
    while (tmp % i == 0ll) {
      tmp /= i;
      cnt++;
    }
    if (cnt > 0) ret.push_back(pair<ll, int>(i, cnt));
  }
  if (tmp != 1ll) ret.push_back(pair<ll, int>(tmp, 1));
  return ret;
}

void solve() {
  int N;
  cin >> N;
  ll ans = 0ll;
  for (int i = 1; i <= N; i++) {
    ans += N / i;
    if (N % i == 0) ans--;
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
 
int main(void)
{
    int min, middle, max;
    int sum;
    int n, x;
    int cnt;
 
    while (1){
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0){
            break;
        }else{
            cnt = 0;
            for (min = 1; min <= (x / 3); min++){
                for (middle = min + 1; middle < (x - min) / 2.0; middle++){
                    /*max = x - min - middle > middle => middle < (x - min) / 2*/
                    for (max = middle + 1; max <= n; max++){
                        sum = min + middle + max;
                        if (sum == x){
                            cnt++;
                        }
                    }
                }
            }
            printf("%d\n", cnt);
        }
    }
 
    return 0;
}



Measured memory_bytes: 2016
class _Node {
  constructor(id, parentId, leftId, rightId) {
    this.id = id;
    this.parentId = parentId;
    this.leftId = leftId;
    this.rightId = rightId;
  }
}

class BinaryTree {
  constructor() {
    this.nodes = [];
  }

  static get Node() {return _Node;}

  get root() { return this.nodes.find(n => n.parentId === -1); }

  add(id, leftId, rightId) { this.nodes[id] = new BinaryTree.Node(id, -1, leftId, rightId); }

  find(id) { return this.nodes[id]; }

  connect() {
    this.nodes.forEach(n => {
      if (n.leftId !== -1) this.nodes[n.leftId].parentId = n.id;
      if (n.rightId !== -1) this.nodes[n.rightId].parentId = n.id;
    });
  }

  preorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    process.stdout.write(` ${id}`);
    this.preorder(n.leftId);
    this.preorder(n.rightId);
  }

  inorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    this.inorder(n.leftId);
    process.stdout.write(` ${id}`);
    this.inorder(n.rightId);
  }

  postorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    this.postorder(n.leftId);
    this.postorder(n.rightId);
    process.stdout.write(` ${id}`);
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let tree = new BinaryTree();
  lines.map(l => l.split(' ').map(Number)).forEach(line => tree.add(...line));
  tree.connect();
  console.log('Preorder');
  tree.preorder();
  console.log('\nInorder');
  tree.inorder();
  console.log('\nPostorder');
  tree.postorder();
  console.log();
})();



Measured memory_bytes: 16096
#include<stdio.h>
int main(){
int H,W,N,a,b,c;
scanf("%d",&H);
scanf("%d",&W);
scanf("%d",&N);
if(H<W)
a=W;
else
a=H;
b=N%a;
c=N/a;
if(b==0)
printf("%d",c);
else
printf("%d",c+1);
return 0;




}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;


namespace mp = boost::multiprecision;
 
int main() {
  mp::cpp_int h,w;
  cin>>h>>w;
    if(h==1|w==1){cout<<1<<endl;}else{cout<<(h/2)*(w/2)+(h-h/2)*(w-w/2)<<endl;}

}

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

int main() {
  int N;
  cin >> N;
  if(N % 2 == 0) {
    cout << 0.5 << endl;
  }
  else if(N % 2 == 1) {
    double M;
    M = N;
    cout << (N / 2 + 1) / M << endl;
  }
}

Measured memory_bytes: 256
x, y, a, b, c = [int(i) for i in input().split(" ")]
p = sorted([int(i) for i in input().split(" ")], reverse=True)[0:x]
q = sorted([int(i) for i in input().split(" ")], reverse=True)[0:y]
r = sorted([int(i) for i in input().split(" ")], reverse=True)

l = sorted(p + q + r, reverse=True)

r = 0
for i in range(x+y):
  r += l[i]
print(r)

Measured memory_bytes: 112296
import sys


k, n = map(int, sys.stdin.readline().split())
homes = list(map(int, sys.stdin.readline().split()))
M = -1
for i in range(n-1):
    if homes[i+1] - homes[i] > M:
        M = homes[i+1] - homes[i]
if homes[0] + k - homes[-1] > M:
    M = homes[0] + k - homes[-1]

print(k - M)

Measured memory_bytes: 25880
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] dx = new long[n-1];
		long[] dy = new long[m-1];
		long tmp = sc.nextLong();
		for(int i = 0; i < n-1; i++){
		    long x = sc.nextLong();
		    dx[i] = x - tmp;
		    tmp = x;
		}
		tmp = sc.nextLong();
		for(int i = 0; i < m-1; i++){
		    long y = sc.nextLong();
		    dy[i] = y - tmp;
		    tmp = y;
		}
		
		// 計算
		long result = 0;
		int MOD = 1000000007;
		long sumX = 0;
		long sumY = 0;
		for(int i = 0; i < n-1; i++){
		    sumX += dx[i]*(i+1)%MOD*(n-1-i)%MOD;
		    sumX %= MOD;
		}
		for(int j = 0; j < m-1; j++){
		    sumY += dy[j]*(j+1)%MOD*(m-1-j)%MOD;
		    sumY %= MOD;
		}
		result = sumX*sumY%MOD;
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 90196
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
ll n;
ll a[100010], b[100010];
vector<ll> c;
struct  choten{
    ll weight;
    vector<ll> child;
};
choten g[100010];
bool used[100010] = {false};
void dfs(ll p){
    g[p].weight = c.back();
    c.pop_back();
    used[p] = true;
    rep(i, g[p].child.size()){
        ll c = g[p].child[i];
        if(used[c])continue;
        dfs(c);
    }
}
int main(){
    cin >> n;
    rep(i, n-1){
        cin >> a[i] >> b[i];
        g[a[i]].child.push_back(b[i]);
        g[b[i]].child.push_back(a[i]);
    }
    rep(i, n){
        ll c_i;
        cin >> c_i;
        c.push_back(c_i);
    }
    sort(ALL(c));
    ll sum = 0;
    rep(i, n-1)sum+=c[i];
    cout << sum << endl;
    dfs(a[0]);
    rep(i, n) cout << g[i+1].weight << " ";
}

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

int main(){
    int n, cnt=0;
    string s;
    char t;
    cin >> n >> s;
    int l = 0, r = n-1;
    for(;;){
        while(l < n && s[l] == 'R')l++;
        while(r >= 0 &&s[r] == 'W')r--;
        if(r < l || (r==-1 && l==n)) break;
        cnt++;
        t = s[r];
        s[r] = s[l];
        s[l] = t;
        l++;
        r--;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3684
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;cin>>n;
  map<string,ll> mp;
  rep(i,n){
    string s;cin>>s;
    mp[s]++;
  }
  ll m;cin>>m;
  vector<string> w(m);
  rep(i,m) cin>>w[i];
  ll flag=0;
  rep(i,m){
    if(mp[w[i]]>=1){
      if(flag%2==0){
        cout<<"Opened by "<<w[i]<<endl;
        flag++;
      }else{
        cout<<"Closed by "<<w[i]<<endl;
        flag++;
      }
    }else{
      cout<<"Unknown "<<w[i]<<endl;
    }
  }
  
}


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[n/2] - a[n/2-1] << endl;
    return 0;
}


Measured memory_bytes: 3708
// Problem : A - Study Scheduling
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
void solve()
{
	int h1,m1,h2,m2,k;
	cin >>h1>> m1>>h2>>m2>>k;
	if(h2 < h1 || (h2==h1 and m1 > m2))
		h2+=24;
	int min= (h2-h1)*60;
	min -= m1;
	min += m2;
	min-=k;
	cout << min;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)


#ifdef LOCAL
string to_string(const string& s){
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(T v){
    bool first = true;
    string res = "{";
    for(const auto& x: v){
        if(!first) res+=", ";
        first = false;
        res+=to_string(x);
    }
    res+="}";
    return res;
}
void bug() { cerr << endl; }
template<typename Head, typename... Tail>
void bug(Head H, Tail... T) {
    cerr << " " << to_string(H);
    bug(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__);
#endif


const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 2e18 + 12;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void solve(){
    int n;
    cin >> n;
    int a[n+1];
    for(int i=1; i<=n; i++) cin >> a[i];
    vector<int> dp(n+1, INF);
    dp[1] = 0;
    for(int i=2; i<=n; i++){
        dp[i] = min(dp[i-1] + abs(a[i] -  a[i-1]), dp[i]);
        if(i>2)
            dp[i] = min(dp[i] , dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout << dp[n] << endl;
}
signed main(){
    FAST
#ifdef LOCAL
    clock_t start;
    double duration;
    start = clock();
#endif
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
//        cout << "Case #" << t << ": ";
        solve();
    }
#ifdef LOCAL
    duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    cerr <<"\nTotal time elapsed: "<< duration <<"sec\n";
#endif
}

Measured memory_bytes: 3992
#include<stdio.h>
#include<stdlib.h>

int main(){

int N,x,min,s,t;
int ans=0;
scanf("%d%d",&N,&x);
int a[N];
for (int i = 0; i < N; i++)
{
  scanf("%d",&a[i]);
}

  for (int i = 0; i < N; i++)
  {
    min=a[i];
    s=i;
    for (int j = i+1; j < N; j++)
    {
      if (a[j]<min)
      {
        min=a[j];
        s=j;
      }
    }
    t=a[i];                 
    a[i]=a[s];
    a[s]=t;
    if (a[i]>x)
    {
      printf("%d",ans);
      exit(0);
    }else if (a[i]<=x)
    {
      x -= a[i];
      ans++;
      if (x==0)
      {
        printf("%d",ans);
        exit(0);
      }
    }
  }
if(x>0)ans--;
printf("%d",ans);
return 0;

}


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

int main() {
  int64_t A, B, C, D;
  int64_t a, b, c, d;
  cin >> A >> B >> C >> D;
  a = A * C;
  b = A * D;
  c = B * C;
  d = B * D;
  cout << max(a, max(b, max(c, d))) << endl;
  
}


Measured memory_bytes: 3632
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
int inv[1000005];
int main()
{
	int n;
	scanf("%d", &n);
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
	int cur = inv[n], ans = 0;
	for (int i = 0; i < n; i++)
	{
		cur = (ll)cur * (MOD + 1) / 3 % MOD;
		ans = (ans + (ll)cur * inv[n - i]) % MOD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号  (例) par[3] = 2 : 3の親が2
    vector<ll> rank; // 木の深さ
    vector<ll> siz; // 集合のサイズを表す配列

    UnionFind(ll N) : par(N), rank(N), siz(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        x = root(x);
        y = root(y);
        if (x == y) return; //xとyの根が同じ(=同じ木にある)時はそのまま

        if(siz[x] < siz[y]){
            swap(x, y);
        }

        siz[x] += siz[y];
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x){ // xが属する集合の要素数
        return siz[root(x)];
    }
};

int main(void)
{
    ll N, M, i, j, H[100001], A[100001], B[100001], ans=0, judge[100001];

    cin >> N >> M;

    for(i=1; i<=N; i++){
        cin >> H[i];

        judge[i] = 1;
    }

    for(i=1; i<=M; i++){
        cin >> A[i] >> B[i];

        if(H[A[i]] > H[B[i]]) judge[B[i]] = 0;
        else if(H[A[i]]<H[B[i]]) judge[A[i]] = 0;
        else{
            judge[A[i]] = 0;
            judge[B[i]] = 0;
        }
    }

    for(i=1; i<=N; i++){
        if(judge[i]==1) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define ref(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef pair<int,int> P;

int a[200003],n,x[200003],m1[200003],m2[200003],ans[200001];


int main()
{
    cin>>n;
    int sum=0;
    for(int i=n-1;i>=0;i--){
        char h;
        cin>>h;x[i]=h-'0';
        sum+=x[i];
    }
    a[0]=0;
    ref(i,200001){
        int b=0;
        for(int j=0;j<=18;j++) b+=(i>>j)&1;
        a[i]=a[i%b]+1;
    }

    int d1=0,d2=0;
    m1[0]=1;m2[0]=1;
    for(int i=0;i<=n-1;i++){
        d1=(d1+m1[i]*x[i])%(sum+1);
        m1[i+1]=(m1[i]*2)%(sum+1);
    }
    if(sum>1){
        for(int i=0;i<=n-1;i++){
            d2=(d2+m2[i]*x[i])%(sum-1);
            m2[i+1]=(m2[i]*2)%(sum-1);
        }
    }

    for(int i=n-1;i>=0;i--){

        if(!x[i]){
            int u=(d1+m1[i])%(sum+1);
            if(u==0)ans[i]=1;
            else ans[i]=a[u]+1;
        }
        else if(sum==1) ans[i]=0;
        else {
            int u=(d2-m2[i])%(sum-1);
            if(u<0)u+=(sum-1);
            if(u==0)ans[i]=1;
            else ans[i]=a[u]+1;
        }
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main(){
	string S;
	cin >> S;
	int count1=0,count2=0;
	for(int i=0;i<S.length();i++){
		if(i%2==0){
			if(S[i]=='0') count1++;
			else count2++;
		}else{
			if(S[i]=='1') count1++;
			else count2++;
		}
	}
	cout << min(count1,count2);
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
	int n, a, b, c, i;

	scanf("%d", &n);
	
	for( i=0; i<n; i++ ){
		
		scanf("%d %d %d", &a, &b, &c);
		
		if( a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b )
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}
	

Measured memory_bytes: 576
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main()
{
       ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
       int n, k, a[1005];
       cin >> n >> k;
       for (int i=0; i<n; i++)cin>>a[i];
       sort(a, a+n);
       int ans=0;
       for (int i=0; i<k; i++)
       {
             ans+=a[i];
       }cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3648
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

#include<iostream>

using namespace std;

typedef long long ll;

struct data{
  int id;
  ll sum;
};

int main(void)
{

  int n;
  ll num, cost;
  data d[10000];

  while(cin >> n && n){
    int flag = true;
    for(int i = 0; i < n; i++){
      cin >> d[i].id >> cost >> num;
      d[i].sum = cost*num;
    }

    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j < n; j++){
        if(d[i].id == d[j].id && d[j].id){
          d[i].sum += d[j].sum;
          d[j].id = false;
        }
      }
    }

    for(int i = 0; i < n; i++){
      if(d[i].sum >= 1000000 && d[i].id){
        cout << d[i].id << endl;
        flag = false;
      }
    }
    if(flag){
        cout << "NA" << endl;
    }
  }

  return 0;
}

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

int main(){
    ll  n ;
    cin >> n ;
    vector<ll> A(n) ;
    rep(i,n) cin >> A[i] ;
    sort(A.begin(),A.end()) ;
    ll ans = A[n-1] ;
    for(ll i = 0 ; i < n-2 ; i++ ){
      ans += A[ n - 2 - i/2 ] ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 4784
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
     Scanner sc=new Scanner(System.in);
     String inp=sc.next();
     deployA obj=new deployA();
     obj.solve(inp);
 	}
    
}
class deployA
{
    public void solve(String inp)
    {
      int l=inp.length();
      StringBuffer ans=new StringBuffer(inp);
      if(inp.charAt(l-1)=='s')
      {
        ans.append("es");
      }
      else
      {
        ans.append("s");
      }
      System.out.println(ans.toString());
    }
    
}


Measured memory_bytes: 27016
#include <bits/stdc++.h>
using namespace std;
map<long,long>mp;
int main()
{
    long i,j,t,a,b,n,c,y,m,prev,sum,ans=1,count,k;
    t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n>>k;
        long arr[n+1];
        for(i=1;i<=n;i++)
        cin>>arr[i];
        ans=0;
        for(i=1;i<=n;i++)
        {
            ans+=2*min(arr[i],abs(k-arr[i]));
        }
        cout<<ans;
    }
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n;
    cin >> n;
    ll a= 1;
    for(ll i = 1; i*i <= n; i++)
    {

        if(n % i==0)
        {

            a=i;
        }
    }
    cout << -2+a+n/a;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MAX = 10000007;

int dive[10000007];

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i]; 

	sort(rall(v));

	ll ans = v[0];

	int p = 1;
	for(int i = 0; i < n-2; i++){
		ans += v[p];
		if(i%2) p++;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4004
#include<stdio.h>
#define INF 100000000

int main(){
  int i,j,k,n,r[100],c[100];
  int dep[100][100];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d %d",&r[i],&c[i]);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
    dep[i][j] = INF;
    }
  }

  for(i=0;i<n;i++)
    dep[i][i] = 0;

  for(j=0;j<n;j++){
    for(i=0;i<n-j;i++){
      for(k=i+1;k<=i+j;k++){
        if(dep[i][i+j]<dep[i][k-1]+dep[k][i+j]+r[i]*c[k-1]*c[i+j]) dep[i][i+j]=dep[i][i+j];
        else dep[i][i+j]=dep[i][k-1]+dep[k][i+j]+r[i]*c[k-1]*c[i+j];
      }
    }
  }
  printf("%d\n",dep[0][n-1]);
  return 0;
}



Measured memory_bytes: 2112
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)
    alice = [A[i] for i in range(N) if not i & 1]
    bob = [A[i] for i in range(N) if i & 1]

    print(sum(alice) - sum(bob))

main()


Measured memory_bytes: 3060
s, t = input(), input()

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

possible = []
for i in range(len(s)-len(t)+1):
    temp = s[i:i+len(t)]
    flag = True
    for a, b in zip(t, temp):
        if not (a == b or b == "?"):
            flag = False
    if flag:

        possible.append((s[:i] + t + s[i+len(t):]).replace("?", "a"))

if len(possible) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(possible)[0])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
 
 
 
int main() {
 
//変数の宣言
 
    int i,j,temp;
    vector<int> hight;
 
 
/////メイン処理/////
 
    for(i=0;i<10;i++){
        cin >> temp;
        hight.push_back(temp);
    }
     
    for(j=0;j<hight.size()-1;j++){
        for(i=0;i<hight.size()-1-j;i++){
            if (hight[i] > hight[i+1]) {
                temp = hight[i];
                hight[i] = hight[i+1];
                hight[i+1] = temp;
            }
        }
    }
     
    for(i=0;i<3;i++){
        cout << hight[hight.size() -i -1] <<endl;
    }
     
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

#define pb push_back
#define fst first
#define snd second
#define FOR(i,S,E) for(int i=S; i<E; i++)
#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
const int MAXN = 55, INF = 1e8;
int N, a[MAXN], m=INF, M=-INF, mId, MId;

int main() {
    ri(N);
    FOR(i,0,N) {
        ri(a[i]);
        if (m > a[i]) {
            m = a[i];
            mId = i;
        }
        if (M < a[i]) {
            M = a[i];
            MId = i;
        }
    }
    vii ans;
    int mode, add, addId;
    if (abs(m) > abs(M)) {
        mode = 0;
        add = m;
        addId = mId;
    }
    else {
        mode = 1;
        add = M;
        addId = MId;
    }
    printf("%d\n", 2*N-1);
    FOR(i,0,N) {
        printf("%d %d\n", addId+1, i+1);
    }
    if (mode) {
        FOR(i,1,N) {
            printf("%d %d\n", i, i+1);
        }
    }
    else {
        for(int i=N-2; i>=0; i--) {
            printf("%d %d\n", i+2, i+1);
        }
    }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int a,b,k;

signed main() {
    cin >> a >> b >> k;
    rep(i,k) {
        if (!(i%2)) b+=a/2,a/=2;
        else a+=b/2,b/=2;
    }
    cout << a << " " << b << endl;
}












Measured memory_bytes: 768
while True:
    try:
        a, b, c, d, e, f = map(int, input().split())
    except:
        break
    y = (c * d - f * a) / (b * d - e * a)
    x = (c - (b * y)) / a
    print("{:.3f} {:.3f}".format(x, y))


Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int A,B,C;
    
    cin >> A >> B >> C;
    A -= B;
    if( A > C ){
        cout << "0" << endl;
    }else{
        cout << C - A << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main() {
	int i, j, k;
	int	n, m, h, g, c, d, l, r;
	long long int f = 0;
	int w = 0;
	int a[110000];
	int b[110000];

	scanf("%d", &n);

	for (i = 0;i < n+1;i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0;i < n;i++) {
		scanf("%d", &b[i]);
	}

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

		if (a[i] <w) {
			f = f + a[i];
			a[i] = 0;
		}
		else {
			f = f + w;
			a[i] = a[i] - w;
		}

		if (a[i] < b[i]) {
			f = f + a[i];
			w = b[i] - a[i];
			a[i] = 0;
		}
		else {
			f = f + b[i];
			w = 0;
			a[i] = a[i] - b[i];
		}
	}
	if (a[n] < w) {
		f = f + a[n];
		a[n] = 0;
	}
	else {
		f = f + w;
		a[n] = a[n] - w;
	}


	printf("%lld", f);

	return 0;
}

Measured memory_bytes: 1024
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    ret = 0
    while all(a % 2 == 0 for a in A):
        A = [a//2 for a in A]
        ret += 1
    print(ret)


if __name__ == '__main__':
    main()


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

const int N = 20;

typedef long long LL;

int a[N];

LL dfs(int l, int r, int tl, int tr) {
    if (l > r) return 0;
    LL res = 1e18; 
    for (int i = l; i <= r; i++) 
        res = min(res, dfs(l, i - 1, tl, tl + tr) + dfs(i + 1, r, tl + tr, tr) + (LL)a[i] * (tl + tr));
    return res;
}

int main() {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    printf("%lld\n", dfs(2, n - 1, 1, 1) + a[1] + a[n]);
    return 0;
}


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

char ans[1001][1001];
void put3s(int i, int j){
    ans[i][j] = ans[i+1][j] = ans[i+2][j+1] = ans[i+2][j+2] = 'a';
}
void put3d(int i, int j){
    ans[i][j] = ans[i][j+1] = ans[i+2][j+1] = ans[i+2][j+2] = 'b';
    ans[i+1][j] = ans[i+2][j] = ans[i][j+2] = ans[i+1][j+2] = 'c';
}
void put4(int i, int j){
    ans[i][j] = ans[i+1][j] = ans[i+2][j+2] = ans[i+3][j+2] = 'a';
    ans[i][j+1] = ans[i+1][j+1] = ans[i+2][j+3] = ans[i+3][j+3] = 'b';
    ans[i][j+2] = ans[i][j+3] = ans[i+2][j] = ans[i+2][j+1] = 'c';
    ans[i+1][j+2] = ans[i+1][j+3] = ans[i+3][j] = ans[i+3][j+1] = 'd';
}
void put5(int i, int j){
    ans[i+2][j] = ans[i+2][j+1] = ans[i][j+2] = ans[i+1][j+2] = 'd';
    ans[i+3][j] = ans[i+3][j+1] = ans[i][j+3] = ans[i+1][j+3] = 'e';
    ans[i+4][j] = ans[i+4][j+1] = ans[i][j+4] = ans[i+1][j+4] = 'f';
    put3d(i+2, j+2);
}
void put6(int i, int j){
    put3s(i, j);
    put3d(i, j+3);
    put3d(i+3, j);
    put3s(i+3, j+3);
}
void put7(int i, int j){
    put3s(i, j);
    put3s(i+3, j);
    put3s(i, j+3);
    put3s(i+3, j+3);
    ans[i][j+6] = ans[i+1][j+6] = ans[i+6][j] = ans[i+6][j+1] = 'b';
    ans[i+2][j+6] = ans[i+3][j+6] = ans[i+6][j+2] = ans[i+6][j+3] = 'c';
    ans[i+4][j+6] = ans[i+5][j+6] = ans[i+6][j+4] = ans[i+6][j+5] = 'd';
}
void output(int n){
    for(int i=0;i<n;++i) cout << ans[i] << endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, four, five;
    cin >> n;
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) ans[i][j] = '.';
    switch(n){
        case 2: cout << -1 << endl; break;
        case 3: put3d(0, 0); output(n); break;
        case 4: put4(0, 0); output(n); break;
        case 5: put5(0, 0); output(n); break;
        case 6: put6(0, 0); output(n); break;
        case 7: put7(0, 0); output(n); break;
        case 8: put4(0, 0); put4(4, 4); output(n); break;
        case 9: put3d(0, 0); put3d(3, 3); put3d(6, 6); output(n); break;
        case 10: put5(0, 0); put5(5, 5); output(n); break;
        case 11: put5(0, 0); put6(5, 5); output(n); break;
        default:
            four = n / 4 - n % 4;
            five = n % 4;
            for(int i=0;i<four;++i) put4(i*4, i*4);
            for(int i=0;i<five;++i) put5(four*4+i*5, four*4+i*5);
            output(n);
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  double ans = 0;
  for(int i=0;i<N;i++){
    double x;
    string u;
    cin>>x>>u;
    if(u=="JPY"){
      ans+=x;
    }
    else if(u=="BTC"){
      double jpyx = x*380000;
      ans+=jpyx;
    }
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}
            


Measured memory_bytes: 256
# "#"と"."だけで行き来できるエリアを"島"とする
# 島にある"#"から"."には必ず行けるので、
# "#"の数 * "."がその島の場合の数。これをすべて足し合わせる

# visitedになっていない点をすべて捜査する。
# 進めなかった（"#"もしくは"."が連続した）マスはvisitedにしない。

H,W = map(int,input().split())
grid = [None] * H
for i in range(H):
  grid[i] = input()
  
visited = [[False] * W for i in range(H)]

def get_next_unvisited(checked_y):
  for i in range(checked_y,H):
    for j in range(W):
      if not visited[i][j]:
        return i,j
  return -1,-1 # 候補なし
  
from collections import deque
ans = 0
cases = ((0,1),(0,-1),(1,0),(-1,0))
checked_y = 0
while True:
  y,x = get_next_unvisited(checked_y)
  if y == -1 and x == -1:
    print(ans)
    exit(0)
  checked_y = y
  # y,x,親,親マスの文字
  q = deque([[y,x,-1,-1,"N"]])
  black = 0
  white = 0
  
  while q:
    y,x,parent_y,parent_x,parent = q.pop()
    if visited[y][x]:
      continue
    point = grid[y][x]
    if point == parent:
      continue
    visited[y][x] = True
    if point == "#":
      black += 1
    if point == ".":
      white += 1
    for c in cases:
      if y + c[0] == parent_y and x + c[1] == parent_x:
        continue
      if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
        q.append([y + c[0],x + c[1],y,x, point])
  ans += black * white


Measured memory_bytes: 107484
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL n;
int c[200000];
vector<int> g[200000]; 
LL delta=0;//全局增量 
void dfs(int now,int father,vector<LL> & block_size,vector<LL> & dp){
	LL Ancient=block_size[c[now]]+delta;
	for(auto it:g[now]){
		if(it!=father) {
			LL ancient=block_size[c[now]]+delta;
			dfs(it,now,block_size,dp);
			LL New=block_size[c[now]]+delta-ancient;
			dp[c[now]]+=((New-1)*(New))/2+New;
		}
	}
	delta++;	
	block_size[c[now]]=Ancient-delta;
} 
int main(){
	fastio;
	cin>>n;
	rep(i,n) cin>>c[i],c[i]--;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		g[u].PB(v);
		g[v].PB(u);
	}
	vector<LL> bs,f;
	bs=vector<LL> (n,0);
	f=bs;
	dfs(0,-1,bs,f);
	rep(i,n){
		bs[i]+=delta; 
		f[i]+=bs[i]+(bs[i]*(bs[i]-1))/2;
		f[i]=(n*(n-1))/2+n-f[i];
		cout<<f[i]<<endl; 
	} 
	return 0;
}


Measured memory_bytes: 36704
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using bb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, n) for(ll i = 0; i < n; i++)

int main(){
  ll n; cin >> n;
  vll a(n);
  vll p(1000001,0);
  rep(i,n){cin >> a[i]; p[a[i]]++;}
  sort(a.begin(),a.end());
	
  ll sum = n;
  rep(i,n){
    if(p[a[i]] > 1){sum--; continue;}
    else if(a[i] <1000){
      rep(j,i){
        if(a[i] % a[j] == 0){sum--; break;}
      }     
    }
    else{
      for(ll j = 2; j <= 1000; j++){
        if(p[j]){
          if(a[i] % j == 0){sum--; break;}
        }
        else if(a[i] % j == 0 && p[a[i]/j]){
          sum--; break;
        }
      }
    }
  }
  if(p[1] == 1){sum = 1;}
  else if(p[1] > 1){sum = 0;}
  
  cout << sum << endl;
}
        
    
        

Measured memory_bytes: 12760
n = int(input())
mp = [[] for i in range(n)]
for i in range(n):
    m = mp[i]
    a = int(input())
    for j in range(a):
        m.append(list(map(int,input().split())))

ans = 0
maxc = 2**n
cnt = 0
while(cnt < maxc):
    isOK = True
    
    for i in range(n):
        if(1 & cnt>>i):
            #i番目の人の証言が正しいと仮定する
            for x,y in mp[i]:
                if(y == 1):
                    if(1 & cnt>>(x-1)):
                        continue
                else:
                    if(not (0 | (cnt>>(x-1) & 1) )):
                        continue
                #print(bin(cnt),x,y,' ',bin(cnt>>(x-1)))
                isOK = False
    
    if isOK:
        num = str(bin(cnt)).count('1')
        
        if ans < num:
            ans = num
    
    cnt += 1

print(ans)

Measured memory_bytes: 3064
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))


Measured memory_bytes: 16896
// Problem : D - Road to Millionaire
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n;
	ll ar[n];
	m=1000;
	ll s=0;
	for(i=0;i<n;i++)
	cin>>ar[i];
	ll b[n+1]={0};
	b[0]=0;
	for(i=1;i<n;i++)
	{
		if(ar[i]>=ar[i-1])
		b[i]=b[i-1]+1;
	}
	for(i=0;i<n;i++)
	{
		if(b[i]==0 and b[i+1]==1)
		{
			s=m/ar[i];
			m%=ar[i];
		}
		else if(b[i]>0 and b[i+1]==0)
		{
			m+=s*ar[i];
			s=0;
		}
	}
	cout<<m;
}

Measured memory_bytes: 3604