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

int main(){
    int N, i;
    int a[10];
    int a_min = 1200;
    int a_max = 0;

    for (i=0; i<3; i++){
        cin >> a[i];
    }

    sort (a, a+3);

    cout << a[2]-a[0] << endl;

    }




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


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int same(int s_pos, string &s, string &t) {
	int size = t.size();
	if (s.size() - s_pos < size) {
		return false;
	}

	rep(i, size) {
		if (s[i + s_pos] != t[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	string s;
	cin >> s;

	string dream =  "dream";
	string er = "er";
	string a = "a";
	string erase = "erase";
	string r = "r";

	int cur = 0;
	while(cur < s.size()) {

		if (same(cur, s, dream)) {
			if (same(cur + 5, s, er)) {
				if (same(cur + 7, s, a)) {
					cur +=  5;
				} else {
					cur +=7;
				}
			} else {
				cur += 5;
			}

		} else if (same(cur, s, erase)){
			if (same(cur + 5, s, r)) {
				cur += 6;
			} else {
				cur += 5;
			}


		} else {
			cout << "NO" << endl;
			return 0;
		}
		//cout << "cur:" << cur << endl;
	}

	if (cur == s.size()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()

        val SP = (1..N).map { i -> Triple(i, sc.next(), sc.next().toInt()) }
        SP.sortedBy { "%s%3d".format(it.second, 100 - it.third) }
            .forEach { println(it.first) }
    }
}


Measured memory_bytes: 36236
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N, M, Ans = 0;
	string S;
	cin >> S;
	bool flag = true;
	rep(i, S.size()) {
		if (i % 2 == 0) {
			if (S[i] == 'L')
				flag = false;
		}
		else {
			if (S[i] == 'R')
				flag = false;
		}
	}

	if (flag == true)
		cout << "Yes" << END;
	else
		cout << "No" << END;

	return 0;
}


Measured memory_bytes: 256
import sys
from math import sqrt

def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


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


def main():
    n = int(input())
    r = 0
    for i in range(2, int(sqrt(n)+1)):
        if n % i == 0:
            e = 0
            while n % i == 0:
                e += 1
                n //= i
            k = 1
            while e - k >= 0:
                r += 1
                e -= k
                k += 1
        if i > n:
            break
    
    if n > 1:
        r += 1
    
    print(r)

main()


Measured memory_bytes: 9096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = (int)Math.pow(10, 5) - 10000;
        int b = (int)Math.pow(10, 3) - 100;
        int c = (int)Math.pow(10, 1) - 1;
        int length = String.valueOf(n).length();
        if (length == 6) {
            System.out.println(a + b + c);
        } else if (length == 5) {
            System.out.println((n - (int)Math.pow(10, 4) + 1) + b + c);
        } else if (length == 4) {
            System.out.println(b + c);
        } else if (length == 3) {
            System.out.println((n - (int)Math.pow(10, 2) + 1) + c);
        } else if (length == 2) {
            System.out.println(c);
        } else {
            System.out.println(n);
        }
    }
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
  
string s;
  cin >> s;
  
  for(ll i=0; i<sz(s); i++)
  {
    if(s[i]=='1')
    {
      cout << "9";
    }
    
    else
    {
      cout << "1";
    }
  }
  cout << endl;
    return 0;
}

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

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

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

	long long min=a[0], max=a[0], sum=a[0];
	for(int i=1; i<n; i++){
		if(a[i] < min)
			min = a[i];
		else if(a[i] > max)
			max = a[i];
		sum += a[i];
	}

	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3160
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <functional>

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

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


int main(){

  int n,sum;
  int x,y,z;
  x = -1;
  y = -1;
  z = -1;

  cin >> n >> sum;

  sum /= 1000;

  for( int i = 0; i <= n; ++i){
    for( int j = 0; j <= n-i; ++j){
      if( sum == i + 5*j + 10*(n-i-j)){
        x = n-i-j;
        y = j;
        z = i;
        break;
      }
    }
  }

  cout << x <<" " << y << " " << z << endl;



}


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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define pi 3.14159265358979323846

using namespace std;

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

	if( a < b )	swap( a, b );

	for( int i = 0; i < a; i++ ){
		cout << b;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 5;

char s[MAXN], t[MAXN];

int main(void)
{
	scanf("%s%s",s+1,t+1);
	int n = strlen(s+1);
	int m = strlen(t+1);
	
	int ans = m;
	for(int i=1; i+m-1 <= n; ++i)
	{
		int res = 0;
		for(int j=1; j<=m; ++j)
			if(s[i+j-1] != t[j])
				++res;
		ans = min(ans, res);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3756
Uses math;
var n,i,count:integer;
    p:array[1..30] of integer;
begin
read(n);count:=0;
for i := 1 to n do read(p[i]);
for i := 2 to n-1 do 
 if (p[i]>min(p[i-1],p[i+1]))and(p[i]<max(p[i-1],p[i+1])) then 
     inc(count);
write(count)
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

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

    if((a + W) < b)
        cout << b - a - W << endl;
    else if(b < a)
        cout << a - b - W << endl;
    else
    {
        cout << 0 << endl;
    }
    

}

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int K;
    cin >> K;
    int limit = K;
    int val = 0;
    int v = 1;
    rep(i, limit){
        if(i > 0){
            v *= 10;
            v = v % K;
        }

        val = (7 * v + val) % K;
        if(val == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int dp[15][25][200];

signed main(){
    while(1){
        int n, K, s;
        cin >> n >> K >> s;
        if(n + K + s == 0) break;
        rep(i, 0, 15) rep(j, 0, 25) rep(k, 0, 200) dp[i][j][k] = 0;
        dp[0][0][0] = 1;
        rep(i, 0, K){
            rep(j, 0, n){//pre
                rep(k, j + 1, n + 1){//new
                    rep(l, 0, s + 1){
                        // dp[i + 1][j][l] += dp[i][j][l];
                        // if(dp[i][j][l] == -1) continue;
                        if(l + k > s) continue;
                        // if(dp[i + 1][k][l + k] == -1) dp[i + 1][k][l + k] = 0;
                        dp[i + 1][k][l + k] += dp[i][j][l];
                    }
                }
            }
        }
        int ans = 0;
        // rep(i, 0, K + 1){
        //     rep(j, 0, n){
        //         rep(k, 0, 30){
        //             cout << dp[i][j][k] << " ";
        //         }
        //         cout << endl;
        //     }
        //     cout << endl << endl;
        // }
        rep(i, 0, n + 1){
            ans += dp[K][i][s];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3656
def _main():
  text = list(input())

  S1 = []
  S2 = []
  area = 0

  for i in range(len(text)):
    if text[i] == '\\':
      S1.append(i)
    elif text[i] == '/' and len(S1) > 0:
      j = S1.pop()
      section_area = i - j
      area += section_area
      while len(S2) > 0 and S2[-1][0] > j:
        section_area += S2[-1][1]
        S2.pop()
      S2.append([j, section_area])
  print(area)
  print(len(S2), *[n[1] for n in S2])




if __name__ == '__main__':
  _main()


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e5+5;
int p[N],dp[N];
int32_t main(){
    string s;
    cin>>s;
    int n=sz(s);
    s="#"+s;
    vector<int> v={0};
    forn(i,26)v.pb(1<<i);
    unordered_map<int,int> m;
    for(int i=1;i<=n;++i){
        int x=s[i]-'a';
        p[i]=p[i-1]^(1<<x);
    }
    for(int i=n;i>=1;--i){
        if(m.count(p[i]))upn(m[p[i]],dp[i+1]);
        else m[p[i]]=dp[i+1];
        dp[i]=N;
        for(int j:v){
            int tar=j^p[i-1];
            auto it=m.find(tar);
            if(it!=m.end())upn(dp[i],it->s+1);
        }
    }
    cout<<dp[1]<<'\n';
    return 0;
}

Measured memory_bytes: 14652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef double ld;
#define X first
#define Y second
#define mk make_pair
#define pb push_back
#define Rep(i, n) for(int i = 0; i < int(n); i ++)
#define Rep1(i, n) for(int i = 1; i <= int(n); i ++)
#define all(x) (x).begin(), (x).end()
const int MOD = (int) 1e9 + 7;
const ll base =  31;
void MAIN();
int main(){
    //freopen("input.txt", "r", stdin);
    ios:: sync_with_stdio(false); cin.tie(0);
    MAIN();
    return 0;
}
////////////////////////////////////////////////////////////////////////

const int N = 3004;

int n, t, s, f[N][N], g[N];
int a[N], b[N];

void MAIN(){
    cin >> n >> t >> s;
    Rep1(i, n) cin >> a[i] >> b[i];

    for(int i = 1; i <= n; i ++){
        for(int j = 0; j <= s; j ++){
            f[i][j] = f[i-1][j];
            if(j >= b[i]) f[i][j] = max(f[i][j], f[i-1][j-b[i]] + a[i]);
        }
    }
    for(int i = 0; i <= n; i ++) g[i] = f[i][s];
    memset(f, 0, sizeof f);
    for(int i = n; i >= 1; i --){
        for(int j = 0; j <= t-s; j ++){
            f[i][j] = f[i+1][j];
            if(j >= b[i]) f[i][j] = max(f[i][j], f[i+1][j-b[i]] + a[i]);
        }
    }
    int ans = 0;
    for(int i = 0; i <= n; i ++) ans = max(ans, g[i] + f[i+1][t-s]);
    cout << ans << endl;
}

Measured memory_bytes: 36488
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H * W - (h * W + w * H - w * h) << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, a[N], c[N], p[N], ans;

void add (int P) {
	p[P]++;
	int I = P-p[P]+1;
	if(I < 1 || ++c[I] > 1) ans++;
}

void del (int P) {
	int I = P-p[P]+1; p[P]--;
	if(I < 1 || c[I]-- > 1) ans--;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		add(a[i]);
	}
	for(int i=1;i<=m;i++) {
		int A, B;
		scanf("%d%d",&A,&B);
		del(a[A]); add(B);
		a[A] = B;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main() {
    double kyori;
    double zikan;
    double sokudo;

    cin >> kyori;
    cin >> zikan;
    cin >> sokudo;

    if (kyori / sokudo <= zikan) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    vi v,v2,v3;

    f(i,0,n-1)
    {
        li x,y;

        cin>>x>>y;

        v.PB(x+y);
        v2.PB(x-y);
        v3.PB(y-x);
    }

    sort(v.B,v.E);
    sort(v2.B,v2.E);
    sort(v3.B,v3.E);

    li ans=v[n-1]-v[0];

    ans=max(ans,v2[n-1]-v2[0]);
    ans=max(ans,v3[n-1]-v3[0]);

    cout<<ans;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

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

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}

Measured memory_bytes: 8164
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> b(26);
    REP(i,n) b[(s[i]-'a')]++;
    ll ans = 1ll;
    for (auto&& e: b) ans = (ans*(e+1))%MOD;
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N;
  cin >> N;
  vector<pair<int, int>> V(N);

  for (int i = 0; i < N; i++) {
    cin >> V.at(i).first;
    V.at(i).second = i+1;
  }
  
  sort(V.begin(), V.end());
  
 
  for (int i = 0; i < N; i++) {
          cout << V.at(i).second << " ";
  }
  cout << endl;
 
}

Measured memory_bytes: 3996
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  unordered_map<int, int> mp;
  while(cin >> n){
    mp[n]++;
  }
  int maxi = -1;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    maxi = max(maxi, itr->second);
  }
  vector<int> vec;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    if(maxi == itr->second)vec.pb(itr->first);
  }
  sort(vec.begin(), vec.end());
  rep(i, vec.size()){
    cout << vec[i] << endl;
  }
	return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,y; cin>>n>>x>>y; x--; y--;
    vi ans(n);
    rep(i,n)rep(j,n){
        if (i>=j) continue;
        int k = j-i;
        chmin(k,abs(x-i)+1+abs(y-j));
        chmin(k,abs(y-i)+1+abs(x-j));
        ans[k]++;
    }
    FOR(k,1,n-1){
        cout<<ans[k]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_129
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            var dict = new HashSet<int>();
            for(int i = 0; i < m; i++)
            {
                dict.Add(ReadInt());
            }

            var dp = new long[n + 10];
            long mask = 1000000000 + 7;
            dp[0] = 1;
            for (int i = 0; i < n; i++)
            {
                if (dict.Contains(i))
                {
                    dp[i] = 0;
                    continue;
                }
                dp[i + 1] += dp[i];
                dp[i + 1] %= mask;
                dp[i + 2] += dp[i];
                dp[i + 2] %= mask;
            }

            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            // Write output here
            WriteLine(dp[n]);
            Out.Flush();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 20192
#include<cstdio>
 
int main(){
    long long N,M;
    scanf("%lld%lld",&N,&M);
    long long Ans=0;
    if(N>1){
        if(M>1) Ans+=(N-2)*(M-2);
        else Ans+=N-2;
    }
    else{
        if(M>1) Ans+=M-2;
        else Ans=1ll;
    }
    printf("%lld",Ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int p[n];
  REP(i, n) {
    cin >> p[i];
    p[i]--;
  }
  int q[n];
  REP(i, n) q[p[i]] = i;
  int t = 1, sub = 1;
  REP(i, n - 1) {
    if (q[i] < q[i + 1])
      t++;
    else
      t = 1;
    sub = max(sub, t);
  }
  cout << n - sub << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define end getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt=1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n){
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i<= n; i++) {
		if(prime(i)){
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n <<":"<< endl;
	for (int i = 2; i<= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/
int n, tei, ang, ans = 1, t[100005], memo, hito;
signed main() {
	cin >> n >> tei >> ang;
	for (int i = 0; i < n; i++)cin >> t[i];
	sort(t, t + n);
	memo = t[0];
	for (int i = 0; i < n; i++) {
		if (t[i] > memo + ang || hito >= tei) {
			ans++;
			memo = t[i];
			hito = 1;
		}
		else hito++;
	}
	cout << ans << endl;
	end;
}

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

const int maxn = 410;

int n, c[maxn][4];
long long hash_val[maxn], ans;
std::map<long long, int> m;

inline void rot(int *a) {
	int t = a[0];
	a[0] = a[1];
	a[1] = a[2];
	a[2] = a[3];
	a[3] = t;
	return;
}

inline long long calc_hash_val(long long a, long long b, long long c, long long d) {
	return a * 1000000000ll + b * 1000000ll + c * 1000ll + d;
}

inline long long get_hash_val(long long a, long long b, long long c, long long d) {
	return std::min(std::min(calc_hash_val(a, b, c, d), calc_hash_val(b, c, d, a)), std::min(calc_hash_val(c, d, a, b), calc_hash_val(d, a, b, c)));
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d%d%d", c[i], c[i] + 1, c[i] + 2, c[i] + 3);
		for (int j = 0; j < i; ++j) {
			std::reverse(c[j] + 1, c[j] + 4);
			--m[hash_val[j]];
			for (int dj = 0; dj < 4; ++dj) {
				long long face[4];
				for (int k = 0; k < 4; ++k) {
					face[k] = get_hash_val(c[i][k], c[i][k + 3 & 3], c[j][k + 3 & 3], c[j][k]);
				}
				std::sort(face, face + 4);
				long long t = 1;
				for (int l = 0; l < 4; ++l) {
					if(!t) {
						break;
					}
					int r = l;
					while(r + 1 < 4 && face[r + 1] == face[l]) {
						++r;
					}
					int N = m.find(face[l]) == m.end() ? 0 : m[face[l]], M = r - l + 1;
					long long a = face[l] / 1000000000ll, b = face[l] / 1000000ll % 1000ll, c = face[l] / 1000ll % 1000ll, d = face[l] % 1000ll;
					int cnt = (calc_hash_val(a, b, c, d) == face[l]) + (calc_hash_val(b, c, d, a) == face[l]) + (calc_hash_val(c, d, a, b) == face[l]) + (calc_hash_val(d, a, b, c) == face[l]);
					#ifdef DEBUG
					printf("%d %d\t%lld %d\n", N, M, face[l], cnt);
					#endif
					while(M--) {
						t *= (long long) (N - M) * cnt;
					}
					l = r;
				}
				#ifdef DEBUG
				printf("%lld\n", t);
				#endif
				ans += t;
				rot(c[j]);
			}
			++m[hash_val[j]];
			std::reverse(c[j] + 1, c[j] + 4);
		}
		hash_val[i] = get_hash_val(c[i][0], c[i][1], c[i][2], c[i][3]);
		if(m.find(hash_val[i]) == m.end()) {
			m[hash_val[i]] = 0;
		}
		++m[hash_val[i]];
		#ifdef DEBUG
		printf("hash_val[%d] = %lld\n", i, hash_val[i]);
		#endif
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
using namespace std;

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i*(m - 2 * j) + j*n == k)ans = 1;
		}
	}
	if (ans == 1)cout << "Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Many Medians
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	X := make([]int, N)
	Y := make([]int, N)
	for i := 0; i < N; i++ {
		X[i] = nextInt()
		Y[i] = X[i]
	}

	sort.Sort(sort.IntSlice(Y))
	ans := make(map[int]int, N)
	for i := 0; i < N; i++ {
		if i < N/2 {
			ans[Y[i]] = Y[N/2]
		} else {
			ans[Y[i]] = Y[(N/2)-1]
		}
	}

	for i := 0; i < N; i++ {
		fmt.Println(ans[X[i]])
	}

}


Measured memory_bytes: 13740
import sys
x = int(input())

ans = 0
for i in reversed(range(1, x + 1)):
    for j in reversed(range(2, x+1)):
        if i % j != 0:
            continue
        w = i // j
        p = 1
        while w % j == 0:
            w //= j
            p += 1
        if w == 1 and p >= 2:
            print(i)
            sys.exit()
print(1)




Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int q = sc.nextInt();
        
        Map<Character, TreeSet<Integer>> charRangeMap = new HashMap<>();
        for(int i = 0; i < s.length(); i++) {
           char c = s.charAt(i);
           if(!charRangeMap.containsKey(c))
             charRangeMap.put(c, new TreeSet<>());
           charRangeMap.get(c).add(i);
        }
        char[] charArray = s.toCharArray();
        for(int i = 0; i < q; i++) {
            int oper = sc.nextInt();
            if(oper == 1) {
                int idx = sc.nextInt() - 1;
                char newChar = sc.next().charAt(0);
                char originalChar = charArray[idx];
                if(originalChar == newChar) continue;
                charArray[idx] = newChar;
                if(!charRangeMap.containsKey(newChar)) {
                    charRangeMap.put(newChar, new TreeSet<>());
                }
                charRangeMap.get(originalChar).remove(idx);
                charRangeMap.get(newChar).add(idx);
            } else {
                int left = sc.nextInt() - 1;
                int right = sc.nextInt() - 1;
                int cnt = 0;
                for(Map.Entry<Character, TreeSet<Integer>> entry : charRangeMap.entrySet()) {
                     TreeSet<Integer> range = entry.getValue();
                     if(range.subSet(left, right+1).isEmpty()) continue;
                     else cnt++;
                }
                System.out.println(cnt);
            }
        }
    }
}


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

int main () {
    int n, a, b; cin >> n >> a >> b;
    int sum = 0, tmp, ans = 0;

    for (int i = 1; i <= n; i++) {
        tmp = i; sum = 0;
        while (tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from heapq import heapify, heappop as pop, heappush as push
import math

N, M = map(int, input().split())
A = [-x for x in map(int, input().split())]

heapify(A)


for _ in range(M):
    m = pop(A)
    push(A, math.ceil(m / 2))

print(-sum(A))

Measured memory_bytes: 97560
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

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

int n,a[N];
ll ans;

void init() {}

int main() {

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

    cin >> n;

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

    sort(a,a+n);
    reverse(a, a+n);

    n -= 2;

    ans = a[0];

    for (int i = 1; i < 1 + n / 2; ++i) {
        ans += a[i];
    }

    for (int i = 1; i < 1 + n - n / 2; ++i) {
        ans += a[i];
    }

    cout << ans << '\n';

    return 0;
}

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

using namespace std;

int main(){
    vector<char>s(3);
    for (int i = 0; i < 3; i++) {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    if (s[0] == 'a' && s[1] == 'b' && s[2] == 'c') {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int N;

int main(){
	while(1){
		cin>>N;
		if(!N) break;
		int ans=0,a;
		bool flag=0;
		for(int i=0;i<N;i++){
			cin>>a;
			if(a){
				ans++;
				if(a>1){
					flag=1;
				}
			}
		}
		if(flag) cout<<ans+1<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define N 1000005
#define M 10005
using namespace std;
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(!isdigit(ch))f=(ch=='-')?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f*x;
}
int n,w[N],g[N]={2};
bool check(int mid){
	int flag=0;
	for(int i=1;i<n+n;++i){
		g[i]=(w[i]>=mid);
		if(g[i]==g[i-1]){
			if(abs(i-n)<abs(flag-n))flag=i;
			if(abs(i-1-n)<abs(flag-n))flag=i;
		}
	}
	if(flag<=0){
		if(g[1]==0)return 0;
		else return 1;
	}
	if(g[flag]==1)return 1;
	else return 0;
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	n=read();
	g[n+n]=2;
	for(int i=1;i<n+n;++i)w[i]=read();
	int l=0,r=n+n,ans;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))l=mid+1,ans=mid;
		else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <list>
#include <cmath>
#include<vector>
#include <utility>
using namespace std;

#define D

#ifdef D

int main(void)
{
	int n;
	cin >> n;
	int max = -1000000000;
		
	int dis,in;
	cin >> in;
	int min =  in;

	for (size_t i = 1; i < n; i++)
	{
		cin >> in;

		if (max < in - min)
			max = in - min;
		if (min > in)
			min = in;
	}


	cout << max << endl;

	return 0;
}
#endif // D

Measured memory_bytes: 3100
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 09:47:06 2019
//
package main

import "fmt"

func main() {
	var H, W, N int
	fmt.Scan(&H, &W, &N)
	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	board := make([][]int, H)
	for i := range board {
		board[i] = make([]int, W)
	}

	h, w := 0, 0
	for i := range arr {
		for arr[i] > 0 {
			board[h][w] = i + 1
			w++
			if w == W {
				h++
				w = 0
			}
			arr[i]--
		}
	}

	for i := range board {
		if i%2 == 0 {
			for j := range board[i] {
				if j != 0 {
					fmt.Print(" ")
				}
				fmt.Print(board[i][j])
			}
		} else {
			for j := len(board[i]) - 1; j >= 0; j-- {
				if j != len(board[i])-1 {
					fmt.Print(" ")
				}
				fmt.Print(board[i][j])
			}
		}
		fmt.Println()
	}
}


Measured memory_bytes: 1536
N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N)]
for i in range(N):
    for w in range(W+1):
        dp[i][w] = dp[i-1][w]
        if w-wv[i][0] >= 0:
            dp[i][w] = max(dp[i][w],dp[i-1][w-wv[i][0]]+wv[i][1])
print(dp[-1][-1])

Measured memory_bytes: 120044
H,W = map(int,input().split())


if H == 1 or W == 1:
    print(1)
elif H % 2 == 0: # 縦が偶数
    print((H // 2) * W)
else: # 縦が奇数
    # １行目
    if W % 2 == 0:
        s = (W // 2)
    else:
        s = (W // 2) + 1
    
    print( ((H-1) // 2)*W + s )

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

/*
DPで解きます
*/

int unover(int a, int b){
    int tmp = 1;
    while(a>=pow(b,tmp)){
        tmp++;
    }
    return tmp-1;
}

int m3(int a, int b, int c){
    return max(a,max(b,c));
}

int dp[100010];

int ans(int i){
    if(dp[i]!=-1) return dp[i];
    else{
        if(i==0) {
            dp[i]=0;
            return 0;
        }
        else{
        int m = INF;
        m = min(m,ans(i-1)+1);
        rep(j,unover(i,6)){
            m = min(ans(i-pow(6,j+1))+1,m);
        }
        rep(j,unover(i,9)){
            m = min(ans(i-pow(9,j+1))+1,m);
        }
        dp[i]=m;
        return m;
        }
    }

}


void solve(){
    int n;
    cin >> n;
    rep(i,n+1){
        dp[i] = -1;
    }    
    dp[0] = 0;

    cout << ans(n) << endl;
    /*
    rep(i,n+1){
        cout << "dp[" << i << "]:" << dp[i] << endl;
    }
    */
}

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


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 2e4+5, inf = 1e9+7;
int n, k, i, d, l;
int A[N], dp[N][101][2];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    string s;
    cin>>s>>d;
    dp[0][0][0]=1;
    n = sz(s);
    rep(i, 0, n) rep(j, 0, d) rep(k, 0, 2){
        dp[i][j][k]%=inf;
        rep(l, 0, 10) {
            if(l>s[i]-'0' && !k) break;
            dp[i+1][(j+l)%d][k|(l<s[i]-'0')] += dp[i][j][k];
        }
    }
    cout<<(dp[n][0][0]+dp[n][0][1]-1+inf)%inf;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
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;

map<ll, ll> lunlun;
void dfs(ll nm, int i, int digit);

int main()
{
    ll K;
    cin >> K;
    rep(1, i, 10)
    {
        if (i == 9)
        {
            dfs(i, 8, 1);
            dfs(i, 9, 1);
        }
        else
        {
            dfs(i, i - 1, 1);
            dfs(i, i, 1);
            dfs(i, i + 1, 1);
        }
    }
    int i = 1;
    for (auto p : lunlun)
    {
        if (i == K)
        {
            cout << p.first << endl;
        }
        i++;
    }
}

void dfs(ll nm, int i, int digit)
{
    if (digit > 10)
    {
        return;
    }
    lunlun[nm];
    if (i == 0)
    {
        dfs(nm * 10 + i, 0, digit + 1);
        dfs(nm * 10 + i, 1, digit + 1);
        return;
    }
    else if (i == 9)
    {
        dfs(nm * 10 + i, 8, digit + 1);
        dfs(nm * 10 + i, 9, digit + 1);
        return;
    }
    else
    {
        dfs(nm * 10 + i, i - 1, digit + 1);
        dfs(nm * 10 + i, i, digit + 1);
        dfs(nm * 10 + i, i + 1, digit + 1);
        return;
    }
}

Measured memory_bytes: 12672
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


int main()
{
	string s;
	int k;
	cin >> s >> k;
	set<string> ss;
	for(int i = 0; i < s.length(); i++){
		string tmp = "";
		for(int j = 0; j < k && i + j < s.length(); j++){
			tmp += s[i + j];
			ss.insert(tmp);
		}
	}
	auto itr = ss.begin();
	for(int i = 0; i < k - 1; i++){
		itr++;
	}
	cout << *itr << endl;
	return 0;
}

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


void solve(long long N, std::vector<long long> s){
    std::sort(s.begin(), s.end());
    int sum = 0;
    for ( auto it = s.begin(); it != s.end();  ) {
       auto f = *it;
       it++;
       auto s =  *it;
       it++;
       sum += std::min(f, s);
    }
    std::cout << sum << std::endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(2*N);
    for(int i = 0 ; i < 2*N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n,q;
    cin>>n>>q;
    ll a[100010];
    ll sum[100010]={},evensum[100010]={};
    rep(i,n){
        cin>>a[i];
    }
    reverse(a,a+n);
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
        evensum[i+1]=evensum[i];
        if(i%2==0) evensum[i+1]+=a[i];
    }
    vll ths,vals;
    rep(i,(n-1)/2){
        ll th=(a[i+1]+a[i*2+2])/2+1;
        ll val=(sum[i+1]-sum[0])+(evensum[n]-evensum[i*2+2]);
        ths.pb(th),vals.pb(val);
    }
    reverse(all(ths)),reverse(all(vals));
    /*
    rep(i,ths.size()){
        cout<<ths[i]<<" ";
    }
    cout<<endl;
    rep(i,vals.size()){
        cout<<vals[i]<<" ";
    }
    cout<<endl;
    */
    rep(_,q){
        ll x;
        cin>>x;
        ll it=UB(ths,x);
        if(it==0){
            cout<<sum[(n+1)/2]-sum[0]<<endl;
        }
        else cout<<vals[it-1]<<endl;
    }
    return 0;
}

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

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

    int n[4];
    for (int i = 0; i < 4; ++i) {
        cin >> n[i];
    }
    sort(n, n + 4);
    int result[4] = { 1, 4, 7, 9};
    for (int i = 0; i < 4; ++i) {
        if (n[i] != result[i]) {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;
using System.Collections;

class A {

    static void Main() {
        int[] Q = Console.ReadLine().Split(' ').Select(w => int.Parse(w)).ToArray();
        string[] s = new string[Q[0]];
        for(int i =0; i < Q[0]; i++) {
            s[i] = Console.ReadLine();
        }
        Array.Sort(s);
        for(int i = 0; i < Q[0]; i++) {
            Console.Write(s[i]);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 3288
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
    string t;cin >> t;
    rep(i,t.size()){
    if(t[i]=='?')t[i]='D';
    }
    cout << t << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if(a.second == b.second){
        return a.first < b.first;
    }
    return a.second < b.second;
}
int main()
{
    fio;
    string s;
    cin >> s;
    map <char, ll> m;
    for(int i = 0; i < s.size(); i ++){
        m[s[i]] ++;
    }
    if(m['A'] > 0 && m['B'] > 0){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
A = []
for _ in range(3):
    lst = [int(i) for i in input().split(" ")]
    A.append(lst)

N = int(input())
opened = set()
for _ in range(N):
    opened.add(int(input()))


def check():
    for i in range(3):
        if all(A[i][j] in opened for j in range(3)):
            print("Yes")
            return

    for j in range(3):
        if all(A[i][j] in opened for i in range(3)):
            print("Yes")
            return

    if all(A[i][i] in opened for i in range(3)):
        print("Yes")
        return

    if all(A[i][2-i] in opened for i in range(3)):
        print("Yes")
        return

    print("No")
    return


check()


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

int main(){
  int n;
  cin >> n;
  vector<long long> A(n);
  vector<long long> B(n);
  long long x = 0, mod = 1000000007, b=0, t=0;
  for(int i=0; i<n; i++){
    cin >> A[i];
    b += A[i];
    b %= mod;
    B[i] = b;
  }
  for(int i=0; i<n-1; i++){
    if(b>B[i]) t = b - B[i];
    else t = b - B[i] + mod;
    x += A[i]*t;
    x %= mod;
  }
  cout << x;
}


Measured memory_bytes: 6428
object Main extends App {
	import math._
	val Array(n, k) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var ans = 0.0
	val tp = test(k)

	if(n >= k){
		ans = (n - k + 1)/n.toDouble
		for(i<-1 to k-1){
			ans += pow(0.5,  ceil(tp - test(i)))/n.toDouble
		}
	}else{
		for(i<-1 to n){
			ans += pow(0.5, ceil(tp - test(i)) )/n.toDouble
		}
	}

	println(ans)

	def test(x: Int): Double = log(x)/log(2)

}

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


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

    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);


    for(int i=2;i<n;i++)
    {
        dp[i]= min (dp[i-2] + abs( arr[i-2]-arr[i]), dp[i-1]+abs(arr[i-1]-arr[i]));
    }

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


}





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

typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll x, y, ans = 0;
    cin >> x >> y;
    for (ll i = x;  i <= y; i*=2)
        ans++;
    cout << ans << endl;
        
    
    return 0;
}


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

int main(){

    int x, i;
    i = 0;
    
    while(1){
        cin >> x;
        if ( x == 0 ) break;
        i++;
        cout << "Case" << " " << i << ":" << " " << x <<endl;
    }

    return 0;
}


Measured memory_bytes: 3096