akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

double solve() {
    ll N, a;
    cin >> N;
    vector<ll> na(4);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        na[a]++;
    }
    double e[N+1][N+1][N+1] = {0};
    for ( int i3 = 0; i3 <= N; i3++ ) {
        for ( int i2 = 0; i2 <= N; i2++ ) {
            for ( int i1 = 0; i1 <= N; i1++ ) {
                if ( i1 == 0 && i2 == 0 && i3 == 0 ) continue;
                if ( i1 + i2 + i3 > N ) continue;
                double nx = 1;
                if ( i1 > 0 ) nx += e[i1-1][i2][i3] * i1/(double)N;
                if ( i2 > 0 ) nx += e[i1+1][i2-1][i3] * i2/(double)N;
                if ( i3 > 0 ) nx += e[i1][i2+1][i3-1] * i3/(double)N;
                nx *= N/(double)( i1 + i2 + i3 );
                e[i1][i2][i3] = nx;
            }
        }
    }
    double ans = e[na[1]][na[2]][na[3]];
    return ans;
}

int main() {
    cout.setf(ios::fixed);
    cout.precision(16);
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 213248
#include<bits/stdc++.h>
using namespace std;
int main() {
   int n,m;
   int l[100005],r[100005];
   cin>>n>>m;
   for(int i=0;i<m;i++){
      cin>>l[i]>>r[i];
   }
   sort(l,l+m);
   sort(r,r+m);
   if(r[0]>=l[m-1]){
     cout<<r[0]-l[m-1]+1<<"\n";
   }
   else{
     cout<<0<<"\n";
   }
   return 0;
}

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

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

	int ans = 1, num = a;

	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	while (num < b) {
		num += a - 1;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    int arr[n];
    int cnt = 0;
    int mysum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        mysum += a;
        arr[i] = a;
    }
    
    double border = (double)mysum / (4 * m);
    
    for (int j = 0; j < n; j++) {
        if(border<=arr[j]){
            cnt++;
        }
        if(cnt>=m){
            printf("Yes");
            return 0;
        }
    }

    printf("No");

    return 0;

}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include "iostream"

using namespace std;
int main()
{  //freopen("D:\\input.txt","r",stdin);
    int n,c=0,o=0;
    cin>>n;
    int p[1000],pp[1000];
    for(int i=0;i<n;i++)
        {cin>>p[i];
        pp[i]=p[i];
        }
    sort(p,p+n);

    for(int i=0;i<n;i++)
    {
        if(p[i]==pp[i])
           {
           o++;
           continue;
           }
         for(int j=0;j<n;j++)
        {
           // cout<<p[i]<<pp[i]<<c<<o<<endl;
         if(p[i]==pp[j] && p[j]==pp[i])
            {c++;

        }
      }
    }

            if(c<=2 && o>=n-2)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;

}


Measured memory_bytes: 3596
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	bool red[n];
	int boll[n];
	rep(i,n){
		red[i]=i?false:true;
		boll[i]=1;
	}
	int x,y;
	rep(i,m){
		cin>>x>>y;
		x--;y--;
		boll[x]--;boll[y]++;
		if(red[x]>0)red[y]=true;
		if(boll[x]==0)red[x]=false;
	}
	int ans=0;
	rep(i,n)ans+=red[i]?1:0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
w, h, n = list(map(int, input().split()))
data1 = [0]
data2 = [w]
data3 = [0]
data4 = [h]
for i in range(n):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    data1.append(x)
  elif a == 2:
    data2.append(x)
  elif a == 3:
    data3.append(y)
  else:
    data4.append(y)
data1.sort()
data2.sort()
data3.sort()
data4.sort()
x = (data2[0] - data1[-1])
y = (data4[0] - data3[-1])
if x < 0 or y < 0:
  print(0)
  exit()
print(x*y)

Measured memory_bytes: 3064
N, C = map(int, input().split())
X = []
V = []

for _ in range(N):
    x, v = map(int, input().split())
    X += [x]
    V += [v]

A = V[:]
B = V[::-1]

for i in range(N-1):
    A[i+1] += A[i]
    B[i+1] += B[i]

P = [0]
Q = [0]

for i in range(N):
    P += [max(P[-1], A[i]-X[i]*2)]
    Q += [max(Q[-1], B[i]-(C-X[N-i-1])*2)]

ans = 0
for i in range(N):
    ans = max(ans, A[i] + Q[N-i-1] - X[i])
    ans = max(ans, B[i] + P[N-i-1] - (C - X[N-i-1]))

print(ans)


Measured memory_bytes: 78168
#include<bits/stdc++.h>
typedef long long ll;
const int N=1e5+5;
int x,y,a,b,c;
int p[N],q[N],r[N];
bool cmp(int & a,int & b){return a>b;}
int main()
{
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i=0;i<a;i++) scanf("%d",p+i);
	for(int i=0;i<b;i++) scanf("%d",q+i);
	for(int i=0;i<c;i++) scanf("%d",r+i);
	std::sort(p,p+a,cmp);
	std::sort(q,q+b,cmp);
	std::sort(r,r+c,cmp);
	ll ans=0;
	std::priority_queue<int> qu;
	for(int i=0;i<x;i++) qu.push(-p[i]),ans+=p[i];
	for(int i=0;i<y;i++) qu.push(-q[i]),ans+=q[i];
	for(int i=0;i<c;i++)
	{
		if(r[i]>-qu.top())
		{
			ans+=qu.top()+r[i];
			qu.pop();
			qu.push(-r[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2552
class UnionFind:

    def __init__(self, n):
        self.table = [-1] * (n + 1)
        self.size = [1] * (n + 1)

    def merge(self, r1, r2):
        self.table[r1] = r2
        self.size[r2] += self.size[r1]
        self.size[r1] = 0

    def find_root(self, k):
        path = []
        curr = k
        while self.table[curr] != -1:
            path.append(curr)
            curr = self.table[curr]
        self.defrag(curr, path)
        return curr

    def defrag(self, r, p):
        for i in p:
            self.table[i] = r


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = ab[::-1]
    ans = [n * (n - 1) // 2]
    uf = UnionFind(n)
    for _b, _a in zip(ab[::2], ab[1::2]):
        ra = uf.find_root(_a)
        rb = uf.find_root(_b)
        if ra == rb:
            ans.append(ans[-1])
            continue
        ans.append(ans[-1] - uf.size[ra] * uf.size[rb])
        uf.merge(ra, rb)
    return "\n".join([str(a) for a in ans[:-1][::-1]])


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 26264
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    string s;
    cin >> s;
    REP(i,s.length()) if (s[i] == '?') s[i] = 'D';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3748
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  tim[102][2];
int ct = 1;
int go[102];
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	go[t] = 1;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		tim[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {

	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		v[i][1] = 0;
	}
	search(1);
	for (int i = 2; i <= n; i++) {
		if (!go[i]) {
			st.push(i);
			for (int j = 1; j <= n; j++) {
				v[j][i] = 0;
			}
			search(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

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

int main()
{
  string s;
  cin>>s;
  int i=0;
  int j=s.length()-1;
  int c=0;
  while(i<=j)
  {
    if(s[i]!=s[j])
      c++;
    i++;
    j--;
  }
  cout<<c;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> dp(n), num(n);
    for (int &i : num)
    {
        cin >> i;
    }
    dp.at(0) = 0;
    dp.at(1) = abs(num.at(1) - num.at(0));
    for (int i = 2; i < n; ++i)
    {
        dp.at(i) = abs(num.at(i) - num.at(i - 1)) + dp.at(i - 1);
        for (int j = 2; j <= k && i - j >= 0; ++j)
        {
            dp.at(i) = min(abs(num.at(i) - num.at(i - j)) + dp.at(i - j), dp.at(i));
        }
    }
    cout << dp.back();
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

long long a, b, k;
int main()
{
	scanf("%lld%lld%lld", &a, &b, &k);
	if (a > k) {
		a = a - k;
		k = 0;
	}
	else {
		k = k - a;
		a = 0;
	}
	b = b > k ? b - k : 0;
	printf("%lld %lld", a, b);
	return 0;
}

Measured memory_bytes: 128
module ABC140

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_C

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_C

    ! variables for this <subroutine>
    integer(INT64) :: len_sequence_A
    integer(INT64) :: val_sum_sequence_A

    ! arrays for this <subroutine>
    integer(INT64), dimension(:), allocatable :: val_sequence_B

    ! support variables for this <subroutine>
    integer :: itr

    ! STEP.01
    ! read out the given data
    ! (the length of the sequence B)
    read(unit=INPUT_UNIT, fmt=*) len_sequence_A

    ! STEP.02
    ! allocate the arrays to store the given data
    allocate( val_sequence_B(1:len_sequence_A - 1) )

    ! STEP.03
    ! read out the given data
    ! (the values of the sequence B)
    read(unit=INPUT_UNIT, fmt=*) val_sequence_B(:)

    ! STEP.04
    ! calculate the answer of this task
    val_sum_sequence_A &!
    = val_sequence_B(len_sequence_A - 1) &!
    + val_sequence_B(1)

    do itr = len_sequence_A - 1, 2, -1
      val_sum_sequence_A = val_sum_sequence_A + min(val_sequence_B(itr), val_sequence_B(itr - 1))
    end do

    ! STEP.05
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') val_sum_sequence_A

    ! STEP.06
    ! deallocate the arrays to store the given data
    deallocate( val_sequence_B )

    ! STEP.END
    return

  end subroutine task_C

end module ABC140


program main

  ! <module>s to import
  use, non_intrinsic :: ABC140

  ! require all variables to be explicitly declared
  implicit none

  call task_C

end program main

Measured memory_bytes: 640
/*
 * atcoder/abc089/b.cpp
 */

// 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++)
void solve();
int main() { solve(); return 0; }

vector<string> Z { "No", "Yes" };

#include <set>
void solve() {
  int a, b; cin >> a >> b;
  int cnt = 0;
  loop(i,a,b+1) {
    string x = to_string(i);
    string y = x;
    reverse(y.begin(), y.end());
    cnt += x == y;;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3676
use std::io::*;
use std::str::FromStr;
use std::cmp::max;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let a: u32 = read();
    let b: u32 = read();
    println!("{}", max(max(2 * a - 1, a + b), 2 * b - 1));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
const int inf=1e9+7;
const ll INF=1e18;

int main() {
 int n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  ////////
  ll ans=0;
  string taka;
  rep(i,n){
   if(t[i]=='r'){
      if(i>=k && taka[i-k]=='p'){
        taka+='x';
      }
     else{
      ans+=p;
       taka+='p';
     }
   }
   else if(t[i]=='s'){
      if(i>=k && taka[i-k]=='r'){
        taka+='x';
      }
     else{
      ans+=r;
       taka+='r';
     }
   }
   else if(t[i]=='p'){
      if(i>=k && taka[i-k]=='s'){
        taka+='x';
      }
     else{
      ans+=s;
       taka+='s';
     }
   }
   
    
    
  }
  cout<<ans<<endl;
}



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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, x;
  cin >> a >> b >> x;
  cout << ((a <= x && a + b >= x) ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    cout << N * 800 - (N / 15) * 200 << endl;
}

Measured memory_bytes: 3608
from scipy.sparse import*
f=lambda*z:map(int,raw_input().split())
d=lambda s:csgraph.dijkstra(csr_matrix(([1]*len(a),(a,b)),[n+1]*2),0,s)
n,=f()
a,b=zip(*map(f,[0]*~-n))
g=d(1)
h=d(n)
print 'Snuke'if sum(g[i]>h[i] for i in range(n+1))*2>=n else'Fennec'

Measured memory_bytes: 37728
#include <iostream>
#include <vector>

int main()
{
	long long N, A, B;
	std::cin >> N >> A >> B;
	std::vector<long long> X(N);
	for(int i=0; i<N; i++) scanf(" %lld", &X[i]);

	long long ans = 0;
	for(int i=0; i<N-1; i++){
		ans += A*(X[i+1]-X[i]) < B ? A*(X[i+1]-X[i]) : B;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N,A,B,C=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(N) ]

L=[]    #i回目の選択で1を足す変数の名前を順番に格納

for i,s in enumerate(S): #0-indexed
    if s=="AB":
        if A<B:
            A+=1
            B-=1
            L.append("A")
        elif B<A:
            A-=1
            B+=1
            L.append("B")
        elif A==B==0:
            print "No"
            quit()
        elif A==B:
            try: #next_sが取れるときは
                next_s=S[i+1]
                if next_s=="AB":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                    A+=1
                    B-=1
                    L.append("A")
                elif next_s=="AC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    A+=1
                    B-=1
                    L.append("A")
                elif next_s=="BC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    A-=1
                    B+=1
                    L.append("B")
            except: #最終行のときはどっちを取っても良い
                A+=1
                B-=1
                L.append("A")
    elif s=="AC":
        if A<C:
            A+=1
            C-=1
            L.append("A")
        elif C<A:
            A-=1
            C+=1
            L.append("C")
        elif A==C==0:
            print "No"
            quit()
        elif A==C:
            try: #next_sが取れるときは
                next_s=S[i+1]
                if next_s=="AC":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                    A+=1
                    C-=1
                    L.append("A")
                elif next_s=="AB":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    A+=1
                    C-=1
                    L.append("A")
                elif next_s=="BC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    A-=1
                    C+=1
                    L.append("C")
            except: #最終行のときはどっちを取っても良い
                A+=1
                C-=1
                L.append("A")
    elif s=="BC":
        if B<C:
            C-=1
            B+=1
            L.append("B")
        elif C<B:
            B-=1
            C+=1
            L.append("C")
        elif B==C==0:
            print "No"
            quit()
        elif B==C:
            try: #next_sが取れるときは
                next_s=S[i+1]
                if next_s=="BC":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                    B+=1
                    C-=1
                    L.append("B")
                elif next_s=="AB":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    B+=1
                    C-=1
                    L.append("B")
                elif next_s=="AC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                    B-=1
                    C+=1
                    L.append("C")
            except: #最終行のときはどっちを取っても良い
                A+=1
                C-=1
                L.append("A")
print "Yes"
for x in L:
    print x

Measured memory_bytes: 86008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> ab(n);
    bool ans = true;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(b, a);
    }
    sort(ab.begin(), ab.end());
    int time = 0;
    for (int i = 0; i < n; i++)
    {
        time += ab[i].second;
        if (ab[i].first < time)
            ans = false;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		int fib = 1;
		int fibSub1 = 1;
		
		while(n > 1) {
			int temp = fib;
			fib = fib + fibSub1;
			fibSub1 = temp;
			n--;
		}
		
		System.out.println(fib);
	}

}



Measured memory_bytes: 26224
poly = input().split()

stack = []

for _ in poly:

    if _ == '+':
        right = stack.pop()
        left = stack.pop()
        stack.append(left + right)

    elif _ == '-':
        right = stack.pop()
        left = stack.pop()
        stack.append(left - right)

    elif _ == '*':
        right = stack.pop()
        left = stack.pop()
        stack.append(left * right)

    else:
        stack.append(int(_))

print(stack[0])



Measured memory_bytes: 5600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;

    cout << pow(n, 3) << endl;
}

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

int main()
{
  int n, q;
  cin >> n >> q;
  vector<vector<int>> child(n);
  vector<int> s(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    child.at(a - 1).push_back(b - 1);
  }
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    s.at(p - 1) += x;
  }
  for (int i = 0; i < n; i++) {
    for (auto t : child.at(i)) {
      s.at(t) += s.at(i);
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << s.at(i) << " ";
  }
  cout << s.at(n - 1) << endl;
}


Measured memory_bytes: 14080
"""
"""


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


def read(): input()


def solve(array, dist):
    total = 0
    biggest = 0
    for i, x in enumerate(array):
        if i == len(array) - 1:
            next_pos = dist + array[0]
        else:
            next_pos = array[i + 1]
        d = next_pos - array[i]
        if d > biggest:
            biggest = d
        total += d
    return total - biggest


K, N = read_array()
array = read_array()
print(solve(array, K))


Measured memory_bytes: 26444
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    LL n;
    cin >> n;
    LL a[n];
    REP(i, n)
    {
        cin >> a[i];
    }
    LL ans = 1e15;
    REP(i, 2)
    {
        LL sum = 0;
        LL tmp = 0;
        REP(j, n)
        {
            sum += a[j];
            bool plus = ((j % 2) == i);
            if (plus)
            {
                if (sum <= 0)
                {
                    tmp += abs(sum) + 1;
                    sum = 1;
                }
            }
            else
            {
                if (sum >= 0)
                {
                    tmp += abs(sum) + 1;
                    sum = -1;
                }
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    string s, t;
    cin >> s >> t;

    ll x = N;
    rep(i,N){
        bool isok = true;
        repe(j,i,N){
            if(s[j]!=t[j-i]){
                isok = false;
                break;
            }
        }
        
        if(isok){
            x = i;
            break;
        }
    }

    cout << N + x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int year[2],month[2],day[2];
    while(cin>>year[0]>>month[0]>>day[0]>>year[1]>>month[1]>>day[1]){
        bool en=0;
        for(int i=0;i<2;i++)if(year[i]<0||month[i]<0||day[i]<0)en=1;
        if(en)break;
        int ans=0;
        for(int i=year[0];i<=year[1];i++){
            ans+=365;
            if(i%4==0&&i%100!=0||i%400==0)ans+=1;
        }
        ans+=day[1]-day[0];
        for(int i=1;i<month[0];i++){
            if(i==2)ans-=28;
            else if(i==4||i==6||i==9||i==11)ans-=30;
            else ans-=31;
        }
        for(int i=month[1];i<13;i++){
            if(i==2)ans-=28;
            else if(i==4||i==6||i==9||i==11)ans-=30;
            else ans-=31;
        }
        if((year[0]%4==0&&year[0]%100!=0||year[0]%400==0)&&month[0]>=2)ans-=1;
        if((year[1]%4==0&&year[1]%100!=0||year[1]%400==0)&&month[1]<=2)ans+=1;
        cout<<ans<<endl;
    }
}

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

int main(){
    int N=0;
    cin >> N;
    if(N<105)cout << 0 << endl;
    else if(N>=105&&N<135)cout << 1 << endl;
    else if(N>=135&&N<165)cout << 2 << endl;
    else if(N>=165&&N<189)cout << 3 << endl;
    else if(N>=189&&N<195)cout << 4 << endl;
    else cout << 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)


int main()
{
  ll n,k;
  cin >> n >> k;
  vector<ll> h;
  for(ll i = 0;i < n;i++)
  {
    int H;
    cin >> H;
    h.push_back(H);
  }
  sort(h.begin(),h.end());
  vector<ll> min;
  for(ll i = 0;i < n-k+1;i++)
  {
    min.push_back(h[i+k-1]-h[i]);
  }
  sort(min.begin(),min.end());
  // cout << min.size() << endl;
  cout << min[0] << endl;
}


Measured memory_bytes: 2548
import numpy as np

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

babies = sorted([(activity, index) for index, activity in enumerate(A, 1)], reverse=True)

DP = np.zeros(n+1, dtype=np.int64)
position = np.arange(1, n+1, dtype=np.int64)

for filled, (activity, index) in enumerate(babies, 1):
    to_left = DP[:filled] + abs((position[:filled]-index)*activity)
    to_right = DP[:filled] + abs((position[-filled:]-index)*activity)
    DP[1:filled+1] = np.maximum(DP[1:filled+1], to_left)
    DP[:filled] = np.maximum(DP[:filled], to_right)

print(DP.max())


Measured memory_bytes: 27840
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = l()
q = k()
count = [0]*100001
ans = []
an=sum(a)
for i in range(n):
    x = a[i]
    count[x-1] += 1
for i in range(q):
    b,c=I()
    an += (c-b)*count[b-1]
    count[c-1]+=count[b-1]
    count[b-1]=0
    ans.append(an)

for i in ans:
    print(i)


Measured memory_bytes: 22444
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 350000
#include<map>
using namespace std;
struct node{
	long long x,id;
}a[N];
map<long long,long long>p;
long long n,siz[N],fa[N],ans;
int tot,Next[N],v[N],h[N];
int add(int x,int y){
	tot++;
	Next[tot]=h[x];
	v[tot]=y;
	h[x]=tot;
}
long long dfs(int x,int fa){
	siz[x]=1;
	for(int i=h[x];i;i=Next[i]){
		if(v[i]==fa)continue;
		dfs(v[i],x);
		ans+=siz[v[i]];
		siz[x]+=siz[v[i]];
	}
	return ans;
}
bool cmp(node x,node y){
	return x.x>y.x;
}
int main(){
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++){
		scanf("%lld",&a[i].x);
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(long long i=1;i<=n;i++){
		p[a[i].x]=a[i].id;
	}
	for(long long i=1;i<n;i++){
		long long x=a[i].id;
		p[a[i].x]=0;
		siz[x]++;
		long long o=a[i].x+siz[x]-(n-siz[x]);
	//	prlong longf("%d %d %d\n",a[i].x,o,siz[x]);
		long long l=p[o];
		if(l==0){
			printf("-1");
			return 0;
		}
		siz[l]+=siz[x];
		fa[x]=l;
		add(l,x);
		add(x,l);
	}
	fa[a[n].id]=0;
	memset(siz,0,sizeof(siz));
	if(dfs(a[1].id,0)!=a[1].x){
		printf("-1\n");
		return 0;
	}
	for(long long i=1;i<=n;i++){
		if(fa[i]!=0)printf("%lld %lld\n",i,fa[i]);
	}
} 

Measured memory_bytes: 23680
n = gets.to_i
points = gets.split(" ").map{|v| v.to_i}
points.unshift(0)
points.push(0)
abs_list = (0...points.length - 1).inject([]) {|list, i| list << (points[i] - points[i + 1]).abs}
total = abs_list.inject(:+)
(0...points.length - 2).each{|i|
  a = (points[i] - points[i + 1]).abs
  b = (points[i + 1] - points[i + 2]).abs
  c = (points[i] - points[i + 2]).abs
  puts "#{total - a - b + c}"
}


Measured memory_bytes: 12940
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  cin >> n;
  int p[n];
  for(int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for(int i = 0; i < n - 1; i++) {
    if(p[i] != i + 1) {
      swap(p[i], p[p[i] - 1]);
      break;
    }
  }
  for(int i = 0; i < n - 1; i++) {
    if(p[i] > p[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 3592
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(2) # 一番頻度が高いやつ
    b = Counter(V[1::2]).most_common(2)
    a.append([0,0])
    b.append([0,0])#なんでこれする？

    #print(a,b,sep='\n')
    # もし頻度が高いやつと数字がかぶっていたら、
    # 加えた[0,0]により、差が小さいほうに合わせる
    # a,bどっちが譲るかって感じ
    if a[0][0] != b[0][0]:
        print(n-(a[0][1] + b[0][1]))
    else:
        # ここでその処理をしてる
        # aが譲って～って感じのと
        # bが譲って～って感じのやつ
        print(min(n-(a[1][1] + b[0][1]), n-(a[0][1] + b[1][1])))

    """Fi = {}
    Se = {}

    for i in range(0,n,2): # 奇数個
        print(i,len(V))
        if V[i] in Fi.keys():
            Fi[V[i]] += 1
        else:
            Fi[V[i]] = 1


    for i in range(1,n,2): # 偶数個

        if V[i] in Se.keys():
            Se[V[i]] += 1
        else:
            Se[V[i]] = 1
    #print(Fi,Se,sep='\n')
    # ソート
    sortFi = sorted(Fi.items(), key=lambda x:x[1]) # valuesでソートしてる！
    sortSe = sorted(Se.items(), key = lambda x:x[1])
    # リスト化しちゃう
    #print(Fi,Se,sep='\n')
    #na = '' # 繰り返し防止
    k,v = sortFi[0]
    mostFi = k
    #もじ、mostFiと、mostSeが一緒だったら、mostSeの方をずらす? 数字が小さいほうをずらしたほうがいい気もする?
    k,v = sortSe[0]
    mostSe = k
    if mostFi == mostSe:
        if len(sortSe) != 1:
            k,v = sortSe[1]
            mostSe = k
        else:
            mostSe = mostFi+1
    #print(mostFi)
    # 一番多くある数字に合わせる感じ
    cnt = 0
    for k,v in Fi.items():
        if mostFi == k:
            pass
        else:
            cnt += v
    for k,v in Se.items():
        if mostSe == k:
            pass
        else:
            cnt += v
    print(cnt)
    """


if __name__ == '__main__':
  main()


Measured memory_bytes: 15460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


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

    int ans = 0;
    for(int i=0; i<5; i++){
        ans += 10*( (a[i]-1)/10 + 1 );
    }

    int minv = 10;
    for(int i=0; i<5; i++){
        if(a[i]%10 == 0) continue;
        minv = min(minv, a[i]%10);
    }

    cout << ans - 10 + minv << endl;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

string inttos(int num)
{
    return to_string(num);
}

int stoint(string sss)
{
    return stoi(sss);
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));	
	int T;
	T=1;
	while(T--)
	{
		double r;
		cin >> r;
		std::cout << std::fixed;
    	std::cout << std::setprecision(10);
		cout << (3.14159)*(r)*(2.0) << endl;
	}
}


Measured memory_bytes: 3844
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x[ohara], y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> x[i];
  //奇数に配置すると嬉しいよね 1,3,5.....ね
  // 1,2はコーナーケースですよねえ
  if (x[0] == 1 && x[1] == 2) {
    ll want = 3;
    cnt = 1;
    ans = 2;
    rrep(i, 2, n) {
      if (want <= x[i])
        cnt++, want += 2;
      else {
        ans *= (cnt + 1);
        ans %= MOD;
      }
    }
    rrep(i, 1, cnt + 1) {
      ans *= i;
      ans %= MOD;
    }
    Cout(ans);
  } else {
    ll want = 1;
    cnt = 0;
    ans = 1;
    rep(i, n) {
      if (want <= x[i])
        cnt++, want += 2;
      else {
        ans *= (cnt + 1);
        ans %= MOD;
      }
    }
    rrep(i, 1, cnt + 1) {
      ans *= i;
      ans %= MOD;
    }
    Cout(ans);
  }
  return 0;
}

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

#ifdef HELTHAZAR
#define dout if (true) cout
#else
#define dout if (false) cout
#endif

const int MAXN = 101;
int dp[MAXN][2], a[MAXN][2];

void solve() {
	int n;
	cin >> n;

	for (int k = 0; k < 2; k++)
		for (int i = 0; i < n; i++)
			cin >> a[i][k];

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

	cout << dp[n - 1][1] << endl;
}

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

	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll choose(ll n){
    return n*(n-1)/2;
}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> cnt(n);
    rep(i,n) cnt[a[i]]++;
    ll tot = 0;
    rep(i,n){
        tot += choose(cnt[i]);
    }
    rep(i,n){
        ll ans = tot;
        ans -= choose(cnt[a[i]]);
        cnt[a[i]]--;
        ans += choose(cnt[a[i]]);
        cout << ans <<endl;
        cnt[a[i]]++;
    }
    return 0 ;
}
    

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

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

int main()
{
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  set<long long> st;
  for (int i = 0; i < N; i++)
    st.insert(A[i]);
  if (st.size() == N)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 11136
n,m,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[i]+al[i])
for i in range(m):
    bb.append(bb[i]+bl[i])
ans=0
j=m
for i in range(n+1):
    if aa[i]>k:
        break
    while bb[j]>k-aa[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)


Measured memory_bytes: 47648
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

int N; cin >> N;
VI A(N); invec(A);
sort(ALL(A));

rep(i , 0, N-1)
    if (A[i] == A[i+1]) {
        cout << "NO\n";
        return 0;
    }

cout << "YES\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

    int n, r;
    cin >> n >> r;

    if (n >= 10)
        cout << r << "\n";
    else
        cout << r + 100 * (10 - n) << "\n";

    return 0;
}


Measured memory_bytes: 256
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    N, M = LI()
    A = LI()
    A.sort()
    ma = max(A)
    l = 0; r = ma*2+1
    while(r-l>1):
        now = (l+r)//2
        cnt = 0
        for a in A:
            need = now-a
            if need>ma:
                continue
            c = bisect.bisect_left(A,need)
            cnt += N-c
        if cnt>=M:
            l = now
        else:
            r = now
    base = l
    cnt = 0
    ans = 0
    S = [0]+A
    for i in range(N):
        S[i+1] += S[i]
    #print(S)
    for a in A:
        need = base - a
        c = bisect.bisect_left(A, need+1)
        ans += a*(N-c) + S[N]-S[c]
        cnt += (N-c)
    if cnt<M:
        ans += base*(M-cnt)
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 55152
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var input1 = Console.ReadLine();
        var input2 = Console.ReadLine();
        int count = 0;
        for(var i = 0; i<3; i++)
        {
            if(input1[i] == input2[i])
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }


    public string[] ReadInput()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] ConvertIntArray(string[] x)
    {
        var convertedArray = new int[x.Length];
        for (var i = 0; i < x.Length; i++)
        {
            convertedArray[i] = int.Parse(x[i]);
        }

        return convertedArray;
    }

}



Measured memory_bytes: 13140
//添字付mergeSort
'use strict'
function mergeSort(arr){
  var groups=[[]];
  var n=0;
  for(let i=0;i<arr.length;i++){
    groups[n].push([arr[i],i]);
    if(arr[i]>arr[i+1]){
      n++;
      groups[n]=[];
    }
    
  }
  while(groups.length>1){//大
    let newGroups=[];
    while(groups.length>=2){//中
      let g1=groups.pop();
      g1.push([Infinity]);
      let g2=groups.pop();
      g2.push([Infinity]);
      let merged=[];
      let j=0,k=0;
      while(j<g1.length-1||k<g2.length-1){//小
        if(g1[j][0]<g2[k][0]){
          merged[j+k]=g1[j];
          j++;
        }else{
          merged[j+k]=g2[k];
          k++;
        }
      }//小了
      newGroups.push(merged);
    }//中了
    if(groups.length)
      newGroups.push(groups[0]);
    groups=newGroups;
  }//大了
  var result=groups[0];
  return result;
}

function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var sorted=mergeSort(input);
  var L=sorted[N/2-1][0];
  var H=sorted[N/2][0];
  var ans=[];
  for(let i=0;i<N/2;i++){
    let ID=sorted[i][1];
    ans[ID]=H;
  }
  for(let i=N/2;i<N;i++){
    let ID=sorted[i][1];
    ans[ID]=L;
  }
  console.log(ans.join('\n'));
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s, t;
  cin >> s >> t;
  sort(all(s));
  sort(all(t)), reverse(all(t));
  if (s < t) {
    yes();
  } else {
    no();
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
h2 = [0]*n
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(m):
    if h[a[j]-1] < h[b[j]-1]:
        h2[a[j]-1] = 1
    elif h[a[j]-1] > h[b[j]-1]:
        h2[b[j]-1] = 1
    else:
        h2[a[j]-1] = 1
        h2[b[j]-1] = 1

print(h2.count(0))

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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll dp[1010][1010];

int  main() {
		
	int n;
	int l[220];
	int ans = 0;
	cin >> n;
	rep(i, 2 * n)cin >> l[i];
	sort(l, l + 2 * n);

	for (int i = 0; i < 2 * n; i+=2)ans += l[i];

	pr(ans);
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
#define LL long long
const long long MAX=1e6+10;
LL n,m,x,y;
LL a[MAX];
LL min1=1e18;
int main()
{
    cin>>n;
    LL sum1=0;
    for(int i=1; i<=n; i++)
    {
        cin>>x>>y;
        sum1+=x;
        if(x>y)
            min1=min(min1,y);
    }
    if(min1==1e18)
        cout<<"0"<<endl;
    else
        cout<<sum1-min1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define INF 1000000000000000000LL
using namespace std;
int main(){
    long long n,m,l,a,b,c,q,s,t;
    cin>>n>>m>>l;
    long long g[n][n]={},h[n][n]={};
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)g[i][j]=h[i][j]=(i==j?0LL:INF);
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        a--;b--;
        g[a][b]=g[b][a]=c;
    }
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(g[i][j]<=l)h[i][j]=1LL;
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)h[i][j]=min(h[i][j],h[i][k]+h[k][j]);
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>s>>t;s--;t--;
        cout<<(h[s][t]==INF?-1:h[s][t]-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1920