akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 4e5 + 10;

LL a[N];
LL b[N];

int main()
{
	LL n, m, k;
	cin >> n >> m >> k;

	for (int i = 1;i <= n;i++)
		cin >> a[i], a[i] += a[i - 1];

	for (int i = 1;i <= m;i++)
		cin >> b[i], b[i] += b[i - 1];

	int ans = 0;
	for (int i = 0;i <= n;i++)
		if (a[i] > k)break;
		else {
			int idx = upper_bound(b, b + m + 1, k - a[i]) - b - 1;
			ans = max(ans, i + idx);
		}

	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 6324
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    intl d[n];
    cin(i,d);
    intl cnt = 0;
    rep(i,n){
        repi(j,i + 1,n){
            cnt += d[i] * d[j];
        }
    }
    cout << cnt << endl;
    return 0;
}

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

// 各桁の和を計算する関数
int SumDigi(int x) {
  int sum = 0;
  while (x > 0) { // n が 0 になるまで
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int ans = 1000000;
  rep(i, n-1){
    int sumAB = SumDigi(i+1) + SumDigi(n-i-1);
    ans = min(ans,sumAB);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
char s[2000][2001];
int main(void)
{
	int n,m,i,j,sum;
	char buf[2001];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)	scanf("%s",s[i]);
	sum=0;
	for(i=0;i<n;i++)	{
		scanf("%s",buf);
		for(j=0;j<m;j++)	{
			if(s[i][j]!=buf[j])	sum++;
		}
	}
	printf("%d\n",sum);
	return 0;
}


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

const int64_t MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int64_t> A(N);
  map<int64_t,int64_t> M;
  for(int i=0;i<N;++i){
    cin>>A.at(i);
    ++M[A.at(i)];
  }

  int frag=true;
  if(N%2==0){
    for(int i=0;i<N/2;++i){
      if(M[2*i+1]!=2){
        frag=false;
        break;
      }
    }
  }
  else{
    for(int i=1;i<N/2;++i){
      if(M[2*i]!=2){
        frag=false;
        break;
      }
    }
    if(M[0]!=1){
      frag=false;
    }
  }

  if(!frag){
    cout<<0<<endl;
  }
  else{
    int64_t ans=1;
    for(int i=0;i<N/2;++i){
      ans = (ans*2)%MOD;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int n; cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b; cin>>a>>b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

int gcd(int a, int b) {
    if (b > a) swap(&a, &b);
    while (a % b != 0) {
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return b;
}

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", gcd(a, b));
}



Measured memory_bytes: 2104
import collections

N = int(input())

a = list(map(int, input().split()))

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        for key, count in zip(a_key,a_value):
            if key == 0:
                if count != int(N/3):
                    print("No")
                    exit()
            else:
                if count != int(2*N/3):
                    print("No")
                    exit()
        print("Yes")
        exit()
        
if len(a_key) == 3:
    for count in a_value:
        if count != int(N / 3):
            print("No")
            exit()
        
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 14468
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);

using namespace std;

signed main(){
    int n;
    cin >> n;
    vector<int> v;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        sum += x;
        v.push_back(x);
    }
    vector<int> ans;
    int a = 0;
    for(int i = 0; i <= n - 2; i++){
        a += v[i];
        int x = abs(sum  -  a * 2);
        ans.push_back(x);
    }
    sort(ans.begin(), ans.end());
    cout << ans[0];
}


Measured memory_bytes: 4848
N, *A = map(int, open(0).read().split())
M = N // 2
A.sort()
ans = 0
if N % 2:
    for i in range(1, M):
        ans += A[i + M + 1] - A[i - 1]
        ans += A[i + M + 1] - A[i]
    ans += A[M + 1] - A[0]
    ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])
else:
    ans += A[M] - A[0]
    for i in range(1, M):
        ans += A[i + M] - A[i - 1]
        ans += A[i + M] - A[i]
print(ans)


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

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int    N;    // input
  string S;
  int    P;

  int    res_num;
  // int in_a,  in_b;
  // int out_a, out_b;  // output

  int i;    // subscript


  /* Input, Array_Proclamation */
  cin >> N;
  vector< tuple<string, int, int> > intro(N);

  for(i=0; i<N; i++)
  {
    cin >> S >> P;
    intro.at(i) = make_tuple(S, 100-P, i+1);
  }


  /* Initialize */


  /* Calculation */
  sort( intro.begin(), intro.end() );


  /* Output */
  for(i=0; i<N; i++)
  {
    res_num = get<2>(intro.at(i));
    cout << res_num << endl;
  }


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N,D;
  cin >> N >> D;
  int A = D * 2 + 1;
  for ( int i = 0; i < N+1; i++ ) {
    if ( N <= A * i ){
      cout << i << endl;
      break;
    }
  }
}

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

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

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    X /= 50;

    int ans = 0;

    for(int i = 0; i <= A; i++) {
        for(int j = 0; j <= B; j++) {
            int x = X - 10 * i - 2 * j;
            if(x < 0) break;
            if(x <= C) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
const ll N = 200010;
ll mod=1e9+7;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

ll dp[N][5];

int main()
{
    FIO;
    ll i,a,b,c,n;
    cin>>n>>a>>b>>c;
    dp[1][1]=a, dp[1][2]=b, dp[1][3]=c;
    for(i=2;i<=n;i++)
    {
        cin>>a>>b>>c;
        dp[i][1]=a+max(dp[i-1][2], dp[i-1][3]);
        dp[i][2]=b+max(dp[i-1][1], dp[i-1][3]);
        dp[i][3]=c+max(dp[i-1][1], dp[i-1][2]);
    }
    cout<<max(dp[n][1], max(dp[n][2], dp[n][3]))<<endl;
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int arr[N],mark[N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    mark[1]=arr[1];
    for(int i=2;i<=n;i++){
        mark[i]=min(mark[i-1],arr[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(arr[i]<=mark[i]) {
              ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int h,w,n;
pair<int,int> a[1000000];
int c[100][100];

int main(){

  cin>>h>>w>>n;

  for(int i=0;i<n;i++){
    int b;
    cin>>b;
    a[i].first = b;
    a[i].second = i+1;
  }

  sort(a,a+n);


  int i=n,j=0,k=0;
  bool d = true;

  while(i>-1){
    while(a[i].first>0){
      c[k][j] = a[i].second;
      if(d)
        j++;
      else
        j--;
      if(j==w){
        j = w-1;
        d = false;
        k++;
      }
      if(j==-1){
        j = 0;
        d = true;
        k++;
      }
      a[i].first--;
    }
    i--;
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      printf("%d ",c[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 384
N = int(input())
d = {}
for i in range(N-1):
    u, v, w = map(int, input().split())
    if u in d:
        d[u].append([v, w])
    else:
        d[u] = [[v, w]]
    if v in d:
        d[v].append([u, w])
    else:
        d[v] = [[u, w]]

isChecked = [False for i in range(N)]
ans = [0 for i in range(N)]
for k in d:
    c = ans[k-1]
    q = [[0, k]]
    while q:
        l = q[-1][0]
        p = q[-1][1]
        q.pop()
        #print(l, p)
        if isChecked[p-1]:
            continue
        if l%2 == 0:
            ans[p-1] = c
        else:
            ans[p-1] = (c+1)%2
        isChecked[p-1] = True
        for e in d[p]:
            n = e[0]
            w = e[1]
            q.append([l+w, n])

for i in range(N):
    print(ans[i])


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

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

struct Block {
  int w, s, v;
};

const ll INF = LLONG_MAX >> 2;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<Block> a(n);
  REP(i, n) cin >> a[i].w >> a[i].s >> a[i].v;
  sort(ALL(a), [](const Block &a, const Block &b) {
    ll scoreA = b.s - a.w;
    ll scoreB = a.s - b.w;
    if (scoreA != scoreB) return scoreA > scoreB;
    return a.s < b.s;
  });
  const int M = 1e4 + 4;
  VV<ll> dp(n + 1, V<ll>(2 * M, -INF));
  dp[0][0] = 0;
  REP(i, n) REP(j, 2 * M) if (dp[i][j] >= 0) {
    MAX(dp[i + 1][j], dp[i][j]);
    if (j <= a[i].s && j + a[i].w < 2 * M)
      MAX(dp[i + 1][j + a[i].w], dp[i][j] + a[i].v);
  }
  ll ans = 0;
  REP(i, 2 * M) MAX(ans, dp[n][i]);
  cout << ans << endl;
}


Measured memory_bytes: 160640
#include <stdio.h>
#define max 150

int arr[max][max];
int d[max],f[max];
int t = 0,n;

void dfs(int i){

  int j;
  t++;
  d[i] = t;

  for(j = 0 ; j < n ; j++){
    if(arr[i][j] != 0 && d[j] == 0)dfs(j);
  }

  t++;
  f[i] = t;
}


int main(){
  int i,j;
  int u,k,v;

  scanf("%d",&n);

  for(i  = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      arr[u-1][v-1] =1;
    }
  }

  for(i = 0 ; i < n ; i++)if(d[i] == 0)dfs(i);

  for(i = 0 ; i < n ; i++)printf("%d %d %d\n",i+1 , d[i] , f[i]);
  return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    if((A+B) % 2 == 0){
        print((A+B)/2);
    }else{
        print("IMPOSSIBLE");
    }

    
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()

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 MOD = 1000000007;


int main()
{
    ll N, X;
    cin >> N >> X;
    vector<ll> p(N+1);
    vector<ll> b(N+1);
    p[0] = 1;
    b[0] = 1;
    REP(i, N) {
        b[i+1] = 2 * b[i] + 3;
        p[i+1] = 2 * p[i] + 1;
    }
    ll ans = 0;
    ll L = N;
    while(L >= 0) {
        if (X == 1) {
            if (L == 0) ans++;
            break;
        }
        if (X == b[L]) {
            ans += p[L];
            break;
        }
        ll mid = b[L]/2 + 1;
        L--;
        if (L < 0) {
            ans++;
            break;
        }
        if (mid < X) {
            ans += p[L] + 1;
            X = X - mid;
        } else if (mid > X) {
            X = X - 1;
        } else {
            ans += p[L] + 1;
            break;
        }
    }
    PRINT(ans);
    return 0;
}


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

typedef unsigned long long ull;

int main()
{
  string t, p;
  ull data = 0, hash = 0;
  ull b = 10007, mul = 1;

  cin >> t >> p;
  
  if(t.size() < p.size()) return (0);
  
  for(int i = p.size() - 1; i >= 0; i--) {
    data += mul * t[i];
    hash += mul * p[i];
    mul *= b;
  }
  
  if(data == hash) cout << 0 << endl;
  
  for(int i = 0; i < t.size() - p.size(); i++) {
    data = data * b - t[i] * mul + t[i + p.size()];
    if(data == hash) cout << i + 1 << endl;
  }
  
  return (0);
}
  

Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {

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

}

Measured memory_bytes: 22740
def isPrime(n):
    for i in range(2, n):
        if i * i > n:
            return 1
        if n % i == 0:
            return 0
    return 1

ans = 0
n = int(input())
for i in range(n):
    x = int(input())
    ans = ans + isPrime(x)

print(ans)



Measured memory_bytes: 5612
import sys
import itertools
import collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n = int(input())
a = lmi()
a.sort()
# print(a)
ans = sum([abs(i) for i in a[1:]]) - a[0]
for i in range(n):
    if a[i] >= 0:
        b = a[:i]
        c = a[i:]
        break
else:
    b = a[:]
    c = []

# print(b,c)

if b == []:
    l = c[0]
    c.pop(0)
else:
    l = b[0]
if c == []:
    # print('%')
    r = b[-1]
    b.pop(-1)
    ans = sum([abs(i) for i in a[:-1]]) + a[-1]
else:
    r = c[-1]

print(ans)
# print('#',l,r)

for i in range(len(c)-1):
    print(l,c[i])
    l -= c[i]
for i in range(len(b)-1):
    print(r,b[-i-1])
    r -= b[-i-1]
print(r, l)


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 H,W,h,w;
    cin >> H >> W >> h >> w;

    cout << H*W-h*W-w*H+w*h << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int x,y;
	cin >> x >> y;
	ll counta = x, countb = y, countc = 0;
	ll mini = a*counta + b*countb;
	while(1) {
		if(counta > 0) counta--;
		if(countb > 0) countb--;
		countc += 2;
		chmin(mini, a*counta + b*countb + c*countc);
		if(counta == 0 && countb == 0) break;
	}
	cout << mini << endl;
	

  return 0;
}


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

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DBG         cerr << __LINE__ << " Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX     30000
vector<int>two, three, twoThree, result;
int main()
{
//    freopen("maxon.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int sum = 0;
    int n;
    sf(n);
    if(n == 3)
    {
        puts("2 5 63");
        return 0;
    }
    result.pb(2);
    result.pb(4);
    result.pb(3);
    result.pb(9);
    for(int i = 8; i<=MAX; i+=2)
    {
        if(i%3 == 0)
            continue;
        two.pb(i);
    }
    for(int i = 15; i<=MAX; i+=6)
        three.pb(i);
    for(int i = 6; i<=MAX; i+=6)
        twoThree.pb(i);
    int need = n - result.size();
    for(int i = 0; i<two.size()-1 && need > 1; i += 2, need -= 2)
        result.pb(two[i]), result.pb(two[i+1]);
    for(int i = 0; i<three.size()-1 && need > 1; i += 2, need -= 2)
        result.pb(three[i]), result.pb(three[i+1]);
    for(int i = 0; i<need; i++)
        result.pb(twoThree[i]);

    for(int i = 0; i<n; i++)
        printf("%d ",result[i]);
    puts("");
//    D(even.size());
//    for(int i = 0; i<n; i++)
//        printf("%d ",even[i]);
//    puts("");
//    while(even.size() != n)
//        even.pop_back();
//    for(auto u: even)
//        cout << u << " ";
//    cout << endl;
//    sum = 0;
//    for(auto u: even)
//        sum += u;
//    D(sum);
//    for(auto u: even)
//    {
//        int tmp = sum - u;
//        if(__gcd(tmp, u) == 1)
//        {
//            D(tmp);D(u);
//        }
//        assert(__gcd(tmp, u) != 1);
//    }
    return 0;
}




Measured memory_bytes: 640
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
D=[1]*(A[-1]+1)
for i in A:
  if D[i]==1:
    for j in range(A[-1]//i):
      D[i*(j+1)]=0
    D[i]=1
dic={}
for i in A:
  if i not in dic:
    dic[i]=1
  else:
    D[i]=0
ans=0
for i in A:
  if D[i]==1:
    ans+=1
print(ans)

Measured memory_bytes: 43396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;
    Set<String> set = new HashSet<>();
    int K;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[][] ans = new String[h+2][w+2];

        for(int i=0; i<=h+1; i++){
            if(i == 0 || i == h+1){
                for(int j=0; j<=w+1; j++){
                    ans[i][j] = "#";
                }
            } else {
                char[] array = sc.next().toCharArray();
                for(int j=0; j<=w+1; j++){
                    if(j == 0 || j == w+1){
                        ans[i][j] = "#";
                    } else {
                        ans[i][j] = String.valueOf(array[j-1]);
                    }
                }
            }
        }

        for(int i=0; i<=h+1; i++){
            for(int j=0; j<=w+1; j++){
                if(j == w+1){
                    System.out.println(ans[i][j]);
                } else {
                    System.out.print(ans[i][j]);
                }
            }
        }
    }

    void substring(String s, int num){
        for(int i=1; i<=num; i++){
            if(i > K){
                break;
            }
            for(int j=0; j<num; j++){
                if(j + i-1 < num){
//                    System.out.println(s.substring(j, j+i));
                    set.add(s.substring(j, j+i));
                } else {
                    break;
                }
            }
        }
    }

    void permutation(String s, String ans){
        if(s.length() <= 1){
            System.out.println(ans + s);
        } else {
            for(int i=0; i<s.length(); i++){
                permutation(s.substring(0, i) + s.substring(i + 1), ans + s.charAt(i));
            }
        }
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define VV(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int H, W;
	while(true) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		string fl = "", ne = "#";
		rep(i, 0, W) fl += "#";
		rep(i, 0, W - 2) ne += ".";
		ne += "#";
		P(fl);
		rep(i, 0, H - 2) P(ne);
		P(fl);
		P("");
	}
	return 0;
}

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

using namespace std;
 
typedef pair<int, string> P;
 
bool compare(P a, P b)
{
    return a.first > b.first;
}
 
int main()
{
    int n, a, b, c, t = 0;
    string str;
     
    while (cin >> n, n) {
        if (t) puts("");
        t++;
        vector<P> v;
        for (int i = 0; i < n; i++) {
            cin >> str >> a >> b >> c;
            int p = a * 3 + c;
            v.push_back(P(p, str));
        }
        stable_sort(v.begin(), v.end(), compare);
        for (int i = 0; i < n; i++) {
            cout << v[i].second << "," << v[i].first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3152
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  string r, g, b;
  cin >> r >> g >> b;
  r += g;
  r += b;
  int n = stoi(r);
  if (n%4==0) cout << "YES";
  else cout << "NO";
  cout << endl;
}


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

int main() {
  int H, W; cin >> H >> W;
  vector<string> A(H);
  for (int i = 0; i < H; i++) cin >> A.at(i);
  map<char, int> M;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (M.count(A.at(i).at(j))) M[A.at(i).at(j)]++;
      else M[A.at(i).at(j)] = 1;
    }
  }
  int cnt_odd = 0, cnt2 = 0;
  for (auto p : M) {
    if (p.second % 2 == 1) cnt_odd++;
    if (p.second % 4 == 2) cnt2++;
  }
  bool can = false;
  if (H % 2 == 0 && W % 2 == 0) {
    if (cnt_odd == 0 && cnt2 == 0) can = true;
  }
  else if (H % 2 == 1 && W % 2 == 1) {
    if (cnt_odd == 1 && cnt2 <= H/2 + W/2) can = true;
  }
  else {
    if (H % 2 == 1) {
      if (cnt_odd == 0 && cnt2 <= W / 2) can = true;
    }
    else {
      if (cnt_odd == 0 && cnt2 <= H / 2) can = true;
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

typedef struct{
	double x;
	double y;
}point;

void Printp(point a){
	printf("%lf %lf\n", a.x, a.y);
}

void koch(int d, point p, point q){
	if(d==0) return;
	
	point s, u, t;
	//calculation
	s.x=(2*p.x+q.x)/3.0;
	s.y=(2*p.y+q.y)/3.0;
	t.x=(p.x+2*q.x)/3.0;
	t.y=(p.y+2*q.y)/3.0;
		
	double ang=M_PI*60/180.0;
	u.x=(t.x-s.x)*cos(ang) - (t.y-s.y)*sin(ang) +s.x;
	u.y=(t.x-s.x)*sin(ang) + (t.y-s.y)*cos(ang) +s.y;
	
	koch(d-1, p, s);
	Printp(s);
	koch(d-1, s, u);
	Printp(u);
	koch(d-1, u, t);
	Printp(t);
	koch(d-1, t, q);
}

int main(){
	int n;
	scanf(" %d", &n);
	
	point s1,s2;
	s1.x=0; s1.y=0;
	s2.x=100; s2.y=0;
	
	Printp(s1);
	koch(n, s1, s2);
	Printp(s2);
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define INF 0X3f3f3f3f
#define ll long long
#define eps 1e-8
using namespace std;
typedef pair<ll,ll> node;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
ll n,a,b,m,t,ans;
int main()
{
    cin >> n >> b;
    while(n)
    {
        ans ++;
        n /= b;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<int> v;
    for (int x: a) {
        if (v.empty()) {v.push_back(x); continue;}
        auto it = lower_bound(v.begin(), v.end(), x) - 1;
        if (it >= v.begin()) *it = x;
        else v.insert(v.begin(), x);
    }
    cout << v.size() << endl;
    return 0;
}

Measured memory_bytes: 1276
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/aising2020/tasks/aising2020_d
ll powmod(ll a, ll n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n % 2 == 1) { ret = ret * a % mod; }
    a = a * a % mod;
    n /= 2;
  }
  return ret;
}
 
ll calc(ll num, ll depth)
{
  if (num == 0LL) return depth;
 
  ll p_count = __builtin_popcount(num);
  return calc(ll(num % p_count), depth + 1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    string x;
    cin >> n >> x;

    ll bitCount = 0;
    for(int i = 0;i<n;i++){
        if(x[i] == '1')
            bitCount++;
    }
    ll rem_p1 = 0;
    ll rem_m1 = 0;
    for(int i = 1;i<=n;i++){
        if(x[n-i] == '1'){
            rem_p1 += powmod(2,i-1,bitCount+1);
            rem_p1 %= (bitCount+1);
            if(bitCount > 1){
                rem_m1 += powmod(2,i-1,bitCount-1);
                rem_m1 %= (bitCount-1);
            }
        }
    }
    for (int i = 0; i < n; i++){
        if (x[i] == '1'){
            if (bitCount == 1){
                cout << 0 << endl;
                continue;
            }
            ll rem = rem_m1 - powmod(2, n - i - 1, bitCount - 1);
            rem = (rem + (bitCount - 1)) % (bitCount - 1);
            cout << calc(rem, 1) << endl;
        }
        else if (x[i] == '0'){
            if (bitCount == 0){
                cout << 1 << endl;
            }
            else{
                ll rem = rem_p1 + powmod(2, n - i - 1, bitCount + 1);
                rem = rem % (bitCount + 1);
                cout << calc(rem, 1) << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define tracev(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define trace2v(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n'; cerr << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int n;
vector<ll> A, B, dp;

ll solve(ll h) {
    if (h <= 0) return 0;
    if (dp[h] != -1) return dp[h];
    ll temp = INF;
    forn(i, n) uin(temp, B[i] + solve(h - A[i]));
    return dp[h] = temp;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("errlog", "w", stderr);
#endif
    ll h; cin >> h >> n;
    A.resize(n);
    B.resize(n);
    dp.resize(h + 1, -1);
    forn(i, n) cin >> A[i] >> B[i];
    ll ans = solve(h);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

#include <bits/stdc++.h>
using namespace std;


int main()
{
	
	int n; cin >> n;
	int a[n+2];
	int b[n+10];
	int c[n+10];

	int res = 0;

	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++)  cin >> b[i];
	for (int i = 1; i <= n-1; i++)  cin >> c[i];

	int old_A = -1000;

	for (int i = 1; i <= n; i++) {

		int A = a[i];
		res += b[A];

		if (old_A + 1 == A) {
			res += c[old_A];
		}
		old_A = A;
	}

	cout << res;
	return 0;

}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#define Size 8

using namespace std; 

bool Find;
vector<int> queen;
vector< vector<int> > board;

void put_queen(int r, int c) {
	for (int i = 0; i < Size; ++i) {
		if (board[r][i] > 0) {
			board[r][i] = -r;
		}
	}
	for (int i = 0; i < Size; ++i) {
		if (board[i][c] > 0) {
			board[i][c] = -r;
		}
	}
	int base = min(r,c);
	for (int i = 0; i < base+min(Size-r,Size-c); ++i) {
		if (board[r-base+i][c-base+i] > 0) {
			board[r-base+i][c-base+i] = -r;
		}
	}
	base = min(Size-r-1,c);
	for (int i = 0; max(r+base-i,c-base+i) < Size && min(r+base-i,c-base+i) >= 0; ++i) {
		if (board[r+base-i][c-base+i] > 0) {
			board[r+base-i][c-base+i] = -r;
		}
	}
	queen[r] = c;
	return;
}

void unput_queen(int r, int c) {
	for (int i = 0; i < Size; ++i) {
		if (board[r][i] == -r) {
			board[r][i] = 1;
		}
	}
	for (int i = 0; i < Size; ++i) {
		if (board[i][c] == -r) {
			board[i][c] = 1;
		}
	}
	int base = min(r,c);
	for (int i = 0; i < base+min(Size-r,Size-c); ++i) {
		if (board[r-base+i][c-base+i] == -r) {
			board[r-base+i][c-base+i] = 1;
		}
	}
	base = min(Size-r-1,c);
	for (int i = 0; max(r+base-i,c-base+i) < Size && min(r+base-i,c-base+i) >= 0; ++i) {
		if (board[r+base-i][c-base+i] == -r) {
			board[r+base-i][c-base+i] = 1;
		}
	}
	queen[r] = -1;
	return;
}

void print() {
	for (int i = 0; i < Size; ++i) {
		for (int j = 0; j < Size; ++j) {
			if (queen[i] == j) {
				cout << "Q";
			}
			else {
				cout << ".";
			}
		}
		cout << endl;
	}
	return;
}

void search(int r) {
	if (r == Size) {
		Find = true;
		print();
		return;
	}
	if (queen[r] >= 0) {
		search(r+1);
	}
	for (int i = 0; !Find && i < Size; ++i) {
		if (board[r][i] > 0) {
			put_queen(r,i);
			search(r+1);
			unput_queen(r,i);
		}
	}
	return;
}

int main(void) {
	int k,r,c;
	cin >> k;
	queen = vector<int>(Size,-1);
	board = vector< vector<int> >(Size,vector<int>(Size,1));
	for (int i = 0; i < k; ++i) {
		cin >> r >> c;
		put_queen(r,c);
	}

	Find = false;
	search(0);

	return 0;
}



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

const int INF = 1e9;
int h, w;
vector<string> s;

int main(void){
  cin >> h >> w;
  s = vector<string>(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  vector<vector<int>> z(h+1, vector<int>(w+1, INF));
  if(s[0][0] == '#') z[0][0] = 1;
  else z[0][0] = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '.'){
        if(i+1 < h && s[i+1][j] == '#'){
            z[i+1][j] = min(z[i+1][j], z[i][j]+1);
        }else{
            z[i+1][j] = min(z[i+1][j], z[i][j]);
        }
        if(j+1 < w && s[i][j+1] == '#'){
            z[i][j+1] = min(z[i][j+1], z[i][j]+1);
        }else{
            z[i][j+1] = min(z[i][j+1], z[i][j]);
        }
      }else{
          if(i+1 < h) z[i+1][j] = min(z[i+1][j], z[i][j]);
          if(j+1 < w) z[i][j+1] = min(z[i][j+1], z[i][j]);
      }
    }
  }
  cout << z[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 3712
def a():
    N = raw_input().split(" ")
    A = int(N[0])
    B = int(N[1])
    T = int(N[2])

    print T / A * B

def b():
    sum = 0
    N = int(raw_input())
    V = raw_input().split()
    C = raw_input().split()
    for i in range(N):
        value = int(V[i]) - int(C[i])
        if value > 0:
            sum = sum + value
    print sum
    
def main():
    b()
	
if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
// AOJ 323 ruins
// 2018.2.25 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define LIM		50
#define MAX		1000002
#define EPS		1e-8
 
typedef struct { int x, r; double r2; } T;
T tbl[100002];
int n;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check(double d)
{
	int i;
	double xmin, xmax, xx, d2;

	d2 = d*d;
	xmin = -MAX, xmax = MAX;
	for (i = 0; i < n; i++) {
		if (tbl[i].r < d) return 0;
		xx = sqrt(tbl[i].r2 - d2);
		if (tbl[i].x - xx > xmin) xmin = tbl[i].x - xx;
		if (tbl[i].x + xx < xmax) xmax = tbl[i].x + xx;
		if (xmin > xmax) return 0;
	}
	return 1;
}

int cmp(T *a, T *b) { return a->r - b->r; }

int main()
{
	int i;
	double a, hi, lo, mi;

	n = in();
	for (i = 0; i < n; i++) {
		tbl[i].x = in(), a = tbl[i].r = in();
		tbl[i].r2 = a*a;
	}
	if (i == 1) { printf("%.12lf\n", (double)tbl[0].r); return 0; }

	qsort(tbl, n, sizeof(T), cmp);
	lo = 0, hi = MAX;
	for (i = 0; i < LIM; i++) {
		mi = 0.5*(lo + hi);
		if (check(mi)) lo = mi; else hi = mi;
	}
	printf("%.12lf\n", lo);
	return 0;
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back

int main() {

   // IOS;
    char c;
    cin>>c;
    if((int)c<=90)cout<<"A";else cout<<"a";
    return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> A){
    LL ans = 0;
    if(N == 0 && A[0] == 1) {
        cout << 1 << endl;
        return;
    }

    if(A[0] != 0) {
        cout << -1 << endl;
        return;
    }

    VLL max_node(N+1, 0);
    max_node[0] = 1LL;
    REP1(i, N+1) {
        max_node[i] = min(max_node[i-1] * 2LL - A[i], INFL);
    }

    LL prev_node = A[N];
    ans += A[N];

    RREP(i, N-1) {
        LL check_node = prev_node / 2 + prev_node % 2;
        //cout << i << " maxnode:" << max_node[i] << " check:" << check_node << " prev:" << prev_node << " A[i]" << A[i] <<  endl; 
        if(max_node[i] < check_node) {
            cout << -1 << endl;
            return;
        }

        prev_node = A[i] + min(max_node[i], prev_node);
        ans += prev_node;

        //cout << "add: " << prev_node << " ans:" << ans<< endl;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-0+1);
    for(int i = 0 ; i < N-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4868
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

table = [0] * 100001

c = 0
s = 0

for i in A:
    table[i] += 1
    s += i

for i in range(Q):
    B, C = map(int,input().split())
    c = table[B]
    s += (C - B) * c
    table[C] += table[B]
    table[B] = 0
    print(s)


Measured memory_bytes: 20816
from collections import deque

def bfs(maze, visited, sy, sx):
    queue=deque([[sy, sx]])
    visited[sy][sx]=0
    md=0
    l=[]
    while queue:
        y, x=queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x=y+j, x+k
            if 0<=new_y<R and 0<=new_x<C:
              if maze[new_y][new_x]=="." and visited[new_y][new_x]==-1:
                visited[new_y][new_x]=visited[y][x] + 1
                queue.append([new_y, new_x])
                md=max(visited[new_y][new_x],md)
    return md


R, C=map(int, input().split())

maze=[input() for i in range(R)]
ans=0
for i in range(R):
  for j in range(C):
    visited=[[-1]*C for j in range(R)]
    if maze[i][j]!='#':
      a=bfs(maze,visited,i,j)
      ans=max(a,ans)
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > a(n+1,vector<int>(m+1));
    vector<vector<int> > b(m+1,vector<int>(2));
    vector<vector<int> > c(n+1,vector<int>(2,0));
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=1; i<=m; i++){
        cin >> b[i][1];
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            c[i][1]+=a[i][j]*b[j][1];
        }
    }
    for(int i=1; i<=n; i++)
        cout << c[i][1] << endl;
    
    return 0;
    
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	set<int>tmp;
	for (auto p : prime_factor(a)) {
		while (p.second--){
			tmp.insert(p.first);
		}
	}
	set<int>ans;
	for (auto p : prime_factor(b)) {
		while (p.second--) {
			if (tmp.find(p.first) != tmp.end()) {
				ans.insert(p.first);
			}
		}
	}
	cout << ans.size() + 1 << endl;
	return 0;
}

Measured memory_bytes: 256