akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(n: int, a: "List[int]"):
    r = [str(rr) for rr in list(reversed(a[::2]))]
    l = [str(rr) for rr in a[1::2]]
    if n % 2 == 1:
        print(' '.join(r + l))
    else:
        print(' '.join(list(reversed(r+l))))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49920
#include<stdio.h>

int main(){
	int n,m;
	int i,a,b,c,d;
	scanf("%d %d",&n,&m);
	if(n+m<=2){
      printf("0\n");
	}else{
		b=n*(n-1)/2;
		c=m*(m-1)/2;
		d=b+c;
		printf("%d\n",d);
	}
	return 0;
}


Measured memory_bytes: 1716
# -*- coding: utf-8 -*-

n,m = map(int,input().split())

ans = 0

if n == 1 and m == 1:
    ans = 1
elif n == 1:
    ans = m-2
elif m == 1:
    ans = n-2
else:
    ans = (n-2) * (m-2)

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    bool che=true;
    unordered_map<int,int> cnt;
    rep(i,n)cnt[a[i]]++;
    if(cnt.size()>3)che=false;
    else if(cnt.size()==3){
        if(n%3)che=false;
        int v[cnt.size()];
        int k[cnt.size()];
        int i=0;
        for(auto it=cnt.begin();it!=cnt.end();it++){
            v[i]=it->second;
            k[i]=it->first;
            i++;
        }
        if((v[0]!=v[1]||v[1]!=v[2])){
           che=false;
        }
        int tmp=0;
        rep(i,cnt.size())tmp^=k[i];
        if(tmp!=0)che=false;
    }
    else if(cnt.size()==2){
        if(n%3)che=false;
        int v[2];
        int i=0;
        bool zero=false;
        for(auto it=cnt.begin();it!=cnt.end();it++){
            if(it->first==0)zero=true;
            v[i++]=it->second;
        }
        if(!zero){che=false;}
        if(che&&!((2*v[1]==v[0])||(2*v[0]==v[1]))){che=false;}
    }
    else if(cnt.size()==1){
        if(cnt.begin()->first!=0)che=false;
    }

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




Measured memory_bytes: 4004
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N, X; cin >> N >> X;
    int minM = INT_MAX;
    rep(i, 0, N) {
      int m;
      cin >> m;
      X -= m;
      minM = min(minM, m);
    }
  
    cout << N + X/minM << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else
    {
        int x = n%1000;
        int y=1000-x;
        cout<<y<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(void)
{
	int i,j,k,n,b,f,r,v;
	int A[4][3][10]={0};
	scanf("%d",&n);
	while(n){
		scanf("%d%d%d%d",&b,&f,&r,&v);
			A[b-1][f-1][r-1] = A[b-1][f-1][r-1] + v;
		n--;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",A[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3) printf("####################\n");
	}

	return 0;
}

Measured memory_bytes: 612
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		while (true) {
		    int dist = sc.nextInt();
		    int buget = sc.nextInt();
		    if (dist == 0) {
		        break;
		    }
		    double min = Double.MAX_VALUE;
		    for (int i = 0; i <= dist / 2; i++) {
		        min = Math.min(min, Math.abs(buget - Math.sqrt(Math.pow(i, 2) + Math.pow(dist - i, 2))));
		    }
		    sb.append(min).append("\n");
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 26352
S = gets.chomp

l = S.length - 1
sum = 0
(2**l).times do |i|
	pos = 0
	b = i
	l.times do |j|
		if (b >> j) & 1 == 1
			a = S[pos, j+1-pos].to_i
			sum += a
			pos = j + 1
		end
	end
	a = S[pos,l-pos+1].to_i
	sum += a
end

print sum, "\n"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


vector<int> v[100000];
vector<bool> u(100000,false);

int main(){
  int a,b;
  cin >> a >> b;
  if(a > 12) cout << b << endl;
  else if(a > 5) cout << b/2 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 2560
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] s = Console.ReadLine().Split(' ');
			double[] x = new double[n];
			for (int i = 0; i < n; i++)
			{
				x[i] = double.Parse(s[i]);
			}
			s = Console.ReadLine().Split(' ');
			double[] y = new double[n];
			for (int i = 0; i < n; i++)
			{
				y[i] = double.Parse(s[i]);
			}
			double p1 = 0, p2 = 0, p3 = 0, pinf=0;
			for (int i = 0; i < n; i++)
			{
				p1 += Math.Abs(x[i] - y[i]);
				p2 += Math.Pow(x[i] - y[i], 2);
				p3 += Math.Pow(Math.Abs(x[i] - y[i]), 3);
				if (pinf < Math.Abs(x[i] - y[i])) pinf = Math.Abs(x[i] - y[i]);
			}
			p2 = Math.Pow(p2, (double)1 / (double)2);
			p3 = Math.Pow(p3, (double)1 / (double)3);
			Console.WriteLine("{0} {1} {2} {3}", p1, p2, p3, pinf);
		}
	}
}

Measured memory_bytes: 9376
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int sum=0;
    int sum2=0;
    for(int i=1;i<=s.size();i+=2){
        if(s[i-1]=='1') sum++;
        if(i>=s.size()) break;
        if(s[i]=='0') sum++;
    }
    for(int i=1;i<=s.size();i+=2){
        if(s[i-1]=='0') sum2++;
        if(i>=s.size()) break;
        if(s[i]=='1') sum2++;
    }
    cout<<min(sum,sum2)<<endl;
    return 0;
}




Measured memory_bytes: 512
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=100005;
///Code begin..................................................................

char a[3], b[3];

int main ()
{
    scanf("%s%s",a,b);
    if (a[0]==b[0]) puts("=");
    else {
        puts(a[0]<b[0]?"<":">");
    }
}


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

#define inf 10000000

int n;
vector<vector<int> > g; //graph
vector<int> dist; //from s
vector<int> reach;

void solve() {
    int mi=inf;
    int ming;
    reach.push_back(0);
    dist[0] = 0;

    while(reach.size() < n) {
        mi = inf;
        ming = 0;
        for(int i : reach) {
            for(int j = 0; j < n ; j ++){
                if(i == j || dist[j] < inf) continue;
                if(g[i][j] < 0 )continue;
//                cout << "reached " << i << endl;
                if(g[i][j] + dist[i] < mi) {
//                    cout << "minimum " << j << endl;
                    mi =g[i][j] + dist[i];
                    ming = j;
                }
            }
        }
        reach.push_back(ming);
        dist[ming] = mi;
    }

}

int main() {
    cin >> n;
    g.resize(n);
    dist.resize(n);

    //init
    for(int i=0;i<n;i++){
        g[i].resize(n);
        dist[i]=inf;
        for(int j=0;j<n;j++) {
            g[i][j]=-1;
        }
    }

    int u,k,v,c;
    for(int i=0;i<n;i++) {
        cin >> u >> k;
        for(int j=0;j<k;j++) {
            cin >> v >> c;
            g[u][v] = c;
        }
    }

    solve();
    for(int i=0;i<n;i++) {
        cout << i << " " << dist[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3192
import sys
input = sys.stdin.readline

import numpy as np

def main():
  n, W = map(int, input().split())
  dp = np.zeros(W+1, dtype=np.int64)
  for _ in range(n):
    w, v = map(int, input().split())
    dp[w:W+1] = np.array((dp[:W-w+1]+v, dp[w:W+1])).max(axis=0)
  print(dp[W])
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 17000
// 2次元累積和を使って、ある区間のイチゴの数を瞬時に調べるようにした
#include<bits/stdc++.h>
using namespace std;

const int MAX_HW = 330;
char cake[MAX_HW][MAX_HW]; //元の文字列(0-indexed)
int acm[MAX_HW][MAX_HW]; //2次元累積和(1-indexed)
int res[MAX_HW][MAX_HW]; //出力(1-indexed)
int H, W, K, ID = 1;

void init(){
    //acmは1-indexed
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            if(cake[i][j] == '#') acm[i+1][j+1] = 1;
    
    for(int i = 0; i <= H+1; ++i) 
        for(int j = 1; j <= W+1; ++j) acm[i][j] += acm[i][j-1];

    for(int j = 0; j <= W+1; ++j)
        for(int i = 1; i <= H+1; ++i) acm[i][j] += acm[i-1][j];
}

int berry(int x1, int y1, int x2, int y2) {
    // 1 <= x1 <= x2 <= H, 1 <= y1 <= y2 <= W
    return acm[x2][y2] - acm[x1-1][y2] - acm[x2][y1-1] + acm[x1-1][y1-1];
}

void print_res(int x1, int y1, int x2, int y2){
    for(int i = x1; i <= x2; ++i) for(int j = y1; j <= y2; ++j) res[i][j] = ID;
    ++ID;
}

void section_cut(int x1, int y1, int x2, int y2) {
    int num = berry(x1, y1, x2, y2);
    if(num == 1) { print_res(x1,y1,x2,y2); return ; }
    if(x1 > x2 || y1 > y2) { return ; }

    for(int i = x1; i < x2; ++i) {
        int p = berry(x1,y1,i,y2);
        if(p > 0 && p < num) {
            section_cut(x1,y1,i,y2);
            section_cut(i+1,y1,x2,y2);
            return ;
        }
    }

    for(int j = y1; j < y2; ++j) {
        int p = berry(x1,y1,x2,j);
        if(p > 0 && p < num) {
            section_cut(x1,y1,x2,j);
            section_cut(x1,j+1,x2,y2);
            return ;
        }
    }
}

int main()
{
    scanf("%d %d %d", &H, &W, &K);
    for(int i = 0; i < H; ++i) scanf("%s", cake[i]);

    init();

    section_cut(1,1,H,W);
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) printf("%d ", res[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1664
a,b,k = map(int,input().split())
if a < k:
  k -= a
  a = 0
else :
  a -= k
  k = 0

if b < k:
  b = 0
  k = 0
else :
  b -= k
  k = 0

print(str(a)+ " " + str(b))


Measured memory_bytes: 9112
#coding: utf-8

while True:
    n = int(raw_input())
    if n == 0:
        break
    l = range(0, 2*n + 1)
    l[0] = 0
    l[1] = 0
    for i in range(0, 2*n + 1):
        if l[i] != 0:
            for k in range(i + i, 2*n + 1, i):
                l[k] = 0
            continue
    l = l[n + 1:]
    l = [x for x in l if x]
    print len(l)

Measured memory_bytes: 25808
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
const int inf = (int) 1e9+7;
const long long INF = -1000000000000;
int main(){
	fastIO;
	int n,m;
	long long p;
	cin>>n>>m>>p;
	vector< vector< pair<int,long long> > > v1(5003);
	vector< vector<int> > v2(5003);
	for(int i=0;i<m;i++){
		int a,b;
		long long c;
		cin>>a>>b>>c;
		--a;--b;c-=p;
		v1[a].push_back(make_pair(b,c));
		v2[b].push_back(a); 	
	}        
	queue<int> q;
	bool alg[2600];
  	for(int i=0;i<n;i++)alg[i]=false;
	q.push(n-1);
	alg[n-1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<(int)v2[x].size();i++){
			int nxt=v2[x][i];
			if(!alg[nxt]){
				alg[nxt]=1;
				q.push(nxt);
			}
		}
	}
	
	long long d[2600];
	for(int i=0;i<2600;i++)d[i]=-1000000000000;
	d[0]=0ll;              
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(d[j] != -1000000000000){
				for(int k=0;k<(int)v1[j].size();k++){
					int nxt = v1[j][k].first;
					if(d[j] + v1[j][k].second > d[nxt]){
		      	d[nxt] = d[j] + v1[j][k].second;
					}               
				}                 			
			}		
		}
	}
 
	/*for(int i=0;i<n;i++){
		cout<<d[i]<<" ";
	}
	cout<<'\n';*/
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)v1[i].size();j++){
			int nxt=v1[i][j].first;	
			if(d[i] == -1000000000000 || d[nxt] == -1000000000000)continue;
			if(d[i] + v1[i][j].second > d[nxt] && alg[nxt]){
				cout<<-1<<'\n';
				return 0;
			}
		}
	}	
	cout<<max(0ll,d[n-1])<<'\n';
	return 0;
}

Measured memory_bytes: 768
def bfs_longest(x,y):
    queuex = [x]
    queuey = [y]
    queuedis = [0]
    ans = [0]
    dis = [[-1 for _ in range(w+2)]for k in range(h+2)]
    dis[x][y] = 0
    while(len(queuex)):
        nowx = queuex.pop(0)
        nowy = queuey.pop(0)
        nowdis = queuedis.pop(0)
        search = [[nowx+1,nowy],[nowx-1,nowy],[nowx,nowy+1],[nowx,nowy-1]]
        for i in range(len(search)):
            if dis[search[i][0]][search[i][1]] == -1:
                if maze[search[i][0]][search[i][1]] == ".":
                    queuex.append(search[i][0])
                    queuey.append(search[i][1])
                    queuedis.append(nowdis+1)
                    ans.append(nowdis+1)
                    dis[search[i][0]][search[i][1]] = nowdis+1
    return ans[-1]

h,w = map(int,input().split())
maze = [["#" for _ in range(w+2)]for p in range(h+2)]
anchor = []
for i in range(h):
    data = str(input())
    for j in range(w):
        maze[i+1][j+1] = data[j]
        if data[j] == ".":
            anchor.append([i+1,j+1])

answer = 0
for i in range(len(anchor)):
    answer = max(bfs_longest(anchor[i][0],anchor[i][1]),answer)
print(answer)

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

const int N = 205;
const int INF = (int) 1e9;

int a, b, c;
int n, m, r;
int vis[N];
int dist[N][N];

int main() {
	scanf("%d %d %d", &n, &m, &r);
	for(int i = 0; i < r; ++i) {
		scanf("%d", &vis[i]);
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) {
			if(i != j) dist[i][j] = INF;
		}
	}
	for(int i = 0; i < m; ++i) {
		scanf("%d %d %d", &a, &b, &c);
		dist[a][b] = min(dist[a][b], c);
		dist[b][a] = min(dist[b][a], c);
	}

	for(int k = 1; k <= n; ++k) {
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= n; ++j) {
				if(dist[i][k] + dist[k][j] < dist[i][j])
					dist[i][j] =  dist[i][k] + dist[k][j];
			}
		}
	}

	int ans = INT_MAX;
	sort(vis, vis + r);

	do {
		int cost = 0;
		for(int i = 0; i < r - 1; ++i) {
			cost += dist[vis[i]][vis[i + 1]];
		}
		// fprintf(stderr, "%d\n", cost);
		ans = min(ans, cost);
	} while(next_permutation(vis, vis + r));
	printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
   int w,h,x,y,r;
   scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
   if(w-r>=x&&r<=x&&h-r>=y&&r<=y){
   	printf("Yes\n");
   }else{
   	printf("No\n");
    }
}


Measured memory_bytes: 2696
# -*- coding:utf-8 -*-
import sys
N, K = map(int, input().split())
ans = []
for tmp in range(N):
    a, b = map(int, input().split())
    ans.append((a,b))
ans.sort()
s = 0
for tmp in range(len(ans)):
    s += (ans[tmp])[1]
    if s >= K:
        print((ans[tmp])[0])
        sys.exit()

Measured memory_bytes: 16940
#include <stdio.h>
#include <stdlib.h>
int min(int a,int b){
    if (a < b){
        return a;
    } else {
        return b;
    }
}
int main(void)
{
    int A, B, C, X, Y;
    scanf("%i %i %i %i %i", &A, &B, &C, &X, &Y);
    int ans;
    if (X > Y)
    {
        ans = min(A + B, 2 * C) * Y + min(A, 2 * C) * (X - Y);
    }
    else
    {
        ans = min(A + B, 2 * C) * X + min(B, 2 * C) * (Y - X);
    }
    printf("%i\n", ans);
}

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

int main()
{
    vector<int> sum_of_scores(2, 0);

    for (auto &s : sum_of_scores) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        s = a + b + c + d;
    }

    cout << max(sum_of_scores[0], sum_of_scores[1]) << endl;

    return 0;
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;


namespace hogeeeee
{
    class hogehoge
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int APlace = -1;
            int ZPlace = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A' && APlace == -1)
                {
                    APlace = i;
                }
                if (s[i] == 'Z')
                {
                    ZPlace = i;
                }
            }
            Console.WriteLine(ZPlace - APlace +1);
        }
    }
}


Measured memory_bytes: 13664
from collections import Counter

N = int(input())
a = [int(x) for x in input().split()]

c = Counter(a)
ans = 0
for i in range(min(a) - 1, max(a) + 1):
    res = c[i - 1] + c[i] + c[i + 1]
    ans = max(ans, res)
print(ans)

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

int gcd(int a, int b) {
    if (a == 0) return b;
    return gcd(b % a, a);
}

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

    vector<int> B(N);
    vector<int> C(N);
    B[0] = A[0];
    C[N-1] = A[N-1];
    for(int i=1; i<N; i++)
        B[i] = gcd(A[i], B[i-1]);
    for(int i=N-2; i>=0; i--)
        C[i] = gcd(A[i], C[i+1]);
    int ans = 0;
    ans = max(ans, C[1]);
    ans = max(ans, B[N-2]);
    for(int i=1; i<=N-2; i++)
        ans = max(ans, gcd(B[i-1], C[i+1]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<(a*3+b)/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, ll>;
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;}
const long long LLINF = 1LL << 60;
using namespace std;

const ll mod = 1e9 + 7;
ll dp[101][5][5][5];

string agct[] = { "A", "G", "C", "T" };

bool ng(int p3, int p2, int p1) {
    string tmp = "";
    tmp += agct[p3] + agct[p2] + agct[p1];
    return tmp == "AGC";
}


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

    dp[0][3][3][3] = 1LL;
    for (int i=0; i<N; ++i) {
        rep(p3, 4) rep(p2, 4) rep(p1, 4) rep(p, 4) {
            if (dp[i][p3][p2][p1] == 0) continue;

            if (ng(p2, p1, p) or ng(p2, p, p1) or ng(p1, p2, p)) continue;
            if (ng(p3, p1, p) or ng(p3, p2, p)) continue;

            dp[i+1][p2][p1][p] += dp[i][p3][p2][p1];
            dp[i+1][p2][p1][p] %= mod;
        }
    }

    ll ans = 0;
    rep(p3, 4) rep(p2, 4) rep(p1, 4) {
        ans += dp[N][p3][p2][p1];
        ans %= mod;
    }

    cout << ans << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
    int n, a[100];
    cin >> n;
    for(int i = 0;i < n;i++) cin >> a[i];
     
    int minus = 0;
    for(int i = 0;i < n;i++) if(a[i] % 2 == 0) minus++;
     
    cout << pow(3,n) - pow(2,minus) << endl;
    return 0;
    }

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int n; cin >> n;
    vector<int> a(n), b(n);
    collect(a,n); collect(b,n);
    
    priority_queue<int> excess;
    int lack = 0, changed = 0;
    rep(i,n){
        int c = a[i]-b[i];
        if(c > 0) excess.push(c);
        if(c < 0){
            changed++;
            lack += c;
        }
    }
    
    while(!excess.empty() && lack<0){
        lack += excess.top();
        changed++;
        excess.pop();
    }
    
    if(lack<0){
        changed = -1;
    }
    cout << changed << endl;
}

Measured memory_bytes: 2428
#include <iostream>

#define SIZE 100

using namespace std;

int main() {
	int value[SIZE] = {0}, n, max = 0;


	while (cin >> n) {
		value[n - 1]++;

		if (value[n - 1] > max) max = value[n - 1];
	}

	for (int i = 1; i <= SIZE; i++) {
		if (value[i - 1] == max) {
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3000
io = STDIN
n=io.gets.to_i
A=io.gets.split.map(&:to_i)
sum=A.inject(:+)
m=Array.new(n)
m[0]=sum-2*1.step(n-2,2).inject(0){|s,i|s+A[i]}
(1...n).each {|i|m[i]=2*A[i-1]-m[i-1]}
puts m.join(" ")


Measured memory_bytes: 14084
n = int(input())
ans = 0
music = []
for i in range(n):
    s, t = input().split()
    music.append([s,t])

x = input()
flag = 0
for i in range(n):
    if flag == 1:
        ans += int(music[i][1])
    if music[i][0] == x:
        flag = 1

print(ans)


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

using namespace std;

int main(){
	
  int n;
  cin >> n;
  int a =0 , b = 0 ,c =0 , d= 0;
  while( n--)
  {
    string s;
    cin >> s;
    if(s == "AC")
      a++;
    else if(s == "WA")
      b++;
    else if(s == "TLE")
      c++;
    else
      d++;
  }
  
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;

}
  

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//�I�[�o�[�t���[�ɋC���‚���您����������
//�m�F�Y���Ȃ您����������

int main() {
    int n; cin >> n;
    rep(i,n) {
        int k, p; cin >> k >> p;
        while(k>=p) {
            k -= p;
        }
        if(k==0) cout << p << endl;
        else cout << k << endl;
    }

    return 0;
}


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

int main(void){
  int A,B,K,i,n;
  cin >> A >> B >> K;
  n = 0;
  for( i = min(A,B);n!=K; i--){
    if (A % i == 0 && B % i == 0){
      n++;
    }
  }
  cout << ++i << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
  ll sum=0;
  ll mi=inf;
  rep(i,n){
    ll a,b;cin>>a>>b;
    if(a>b)mi=min(mi,b);
    sum+=a;
  }
  if(mi==inf)cout<<0<<endl;
  else cout<<sum-mi<<endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(input())
result = N
count = 0
result = N
white = [0]*(N+1)
for i in range(N):
	white[i+1] = white[i]
	if a[i] == ".":
		white[i+1] += 1
for i in range(N+1):
    count = i-white[i] + white[N] - white[i]
    if count < result:
        result = count
print(result)


Measured memory_bytes: 12580
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
const ll maxSum = 50*50+1;
int main() {
    ll N ,T ,sa ;
    cin >> N >> T ;
    ll t[N] ;
    ll ans = T * N  ;
    cin >> t[0] ;
    for(ll i = 0 ; i < N -1 ; i++){
        cin >> t[i+1] ;
        sa = t[i+1] - t[i] ;
        if(sa < T){
            ans -= T - sa ;
        }
        
        
    }
     cout << ans << endl;

    return 0;
}

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

int main(){// 上2つと下1つをセットにするのが最善
  int N;
  cin >> N;

  vector<int64_t> data(3*N);
  for(int i=0; i<data.size(); i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end(), greater<int64_t>());

  int64_t ans= 0;
  for(int i=0; i<N; i++){
    ans+= data.at(2*i+ 1);
  }

  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
long long int hcf(long long int n1,long long int n2);
int main()
{
   long long int n1, n2,lcm;

   while(scanf("%lld %lld", &n1, &n2)!=EOF){
   lcm = (n1*n2)/hcf(n1 ,n2);
   printf("%lld %lld\n", hcf(n1,n2),lcm);
   }
   return 0;
}
long long int hcf(long long int n1,long long int n2)
{
    if (n2!=0)
       return hcf(n2, n1%n2);
    else
       return n1;

}

Measured memory_bytes: 596
#include <stdio.h>
int main(){
    long i,n,d,x,y;
    int ans=0;
    scanf("%lld %lld",&n,&d);
    for(i=0; i<n; i++){
        scanf("%lld %lld",&x,&y);
        if(x*x+y*y<=d*d)ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1680
alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
alphabet={moji:alphabetlist.index(moji) for moji in alphabetlist}

N=int(input())
S=input()

def condition(num):
    if num==0:
        return True

    data=[]
    x=0
    for i in range(num):
        x+=alphabet[S[i]]*26**i

    data.append((x,0))

    for i in range(0,N-num+1):
        if i==0:
            continue
        else:
            x=x//26+alphabet[S[i+num-1]]*26**(num-1)
            data.append((x,i))

    data.sort()
    min=data[0][1]
    max=data[0][1]
    for i in range(0,len(data)-1):
        if data[i][0]==data[i+1][0]:
            max=data[i+1][1]
        else:
            if max-min>=num:
                return True
            min=data[i+1][1]
            max=data[i+1][1]

    if max-min>=num:
        return True

    return False

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test

if condition(end):
    print(end)
else:
    print(start)

Measured memory_bytes: 95504
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int n=a.size();
	for(int i=0;i<n;i++)
	{
		if(a[i]=='C') 
		{
			for(int j=i+1;j<n;j++)
			{
				if(a[j]=='F')
				{
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 -O2 -Wall -Wl,--stack=268435456

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

typedef long long          ll;
typedef vector<int>        vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

typedef vector<ll>         vl;
typedef vector< vector <ll> >   vvl;

#define LARGE_INT     1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)

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



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int  n;
    cin >> n;
    vi a(n);
    vvl dp(n, vl(n, 0));  // dp[i][j]  game outcome with j to j+i left, 
    
    REP(j, 0, n) { cin >> a[j]; }
    int sign = (n % 2) * 2 - 1;  // the n-th stone is odd -> 1, even -> -1
    REP (j, 0, n) {  
        dp[0][j] = sign * a[j];
    }
    REP(i, 1, n) REP(j, 0, n-i) {
        if ((n-i) % 2 == 1) { // next stone is odd, first player's turn
            dp[i][j] = max(a[j] + dp[i-1][j+1], a[j+i] + dp[i-1][j]);
        } else {
            dp[i][j] = min(-a[j] + dp[i-1][j+1], -a[j+i] + dp[i-1][j]);
        }
    }
    /*
    REP(i, 0, n) {
        REP(j, 0, n-i)   cout << dp[i][j] << " ";
        cout << endl;
    }*/
    cout << dp[n-1][0];
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int step = 1;
  for (int i = 0; i < N - 1; i++) {
    if (vec.at(i) < vec.at(i+1) ) {
      step++;
    }
  }
  cout << step << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(void) {
    li N, M;
    cin >> N >> M;

    string S, T;
    cin >> S >> T;

    // 最小公倍数を出す
    li lcmNum = N * M / gcd(N, M);

    // 1文字目は同じでなければならない
    if (S[0] != T[0]) {
        cout << -1 << endl;
        return 0;
    }

    // 片方がもう片方の約数の場合
    if (N % M == 0 || M % N == 0) {
        if ( N > M) {
            li step = N / M;
            bool isNone = false;
            FOR(i, 0, M) {
                if (T[i] != S[step * i]) {
                    isNone = true;
                }
            }
            cout << (isNone ? -1 : N);
            return 0;
        } else {
            li step = M / N;
            bool isNone = false;
            FOR(i, 0, N) {
                if (S[i] != T[step * i]) {
                    isNone = true;
                }
            }
            cout << (isNone ? -1 : M);
            return 0;
        }
    }

    // それ以外
    li stepS = lcmNum / M;
    li stepT = lcmNum / N;
    li lcmSecond = (stepS * stepT) / gcd(stepS, stepT);
    bool isNone = false;
    for(int i = 0; i < lcmNum / lcmSecond; i++) {
        if (S[i * (lcmNum / M)] != T[i * (lcmNum / N)]) {
            isNone = true;
            break;
        }
    }
    if (isNone) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << lcmNum << endl;
        return 0;
    }
}

Measured memory_bytes: 512
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions,time
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,a,b = inpl()
res = n//(a+b) * a
rrr = n%(a+b) 
print(res+min(rrr, a))

Measured memory_bytes: 5656
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a, b;
    a = sc.nextInt(); b = sc.nextInt();
    int d = a / b;
    int r = a % b;
    double f = (double) a / (double) b;
    System.out.printf("%d %d %.5f\n", d, r, f);
  }
}


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

using namespace std;

using std::vector;

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

    vector<int> numbers(n);

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

    int count = 0;
    for (int i = 0; i < n-2; i++)
    {
        if((numbers[i] < numbers[i+1] && numbers[i+1] < numbers[i+2]) || (numbers[i] > numbers[i+1] && numbers[i+1] > numbers[i+2]))
        {
            count++;
        }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll s,x=1e9;
int main(){
	s=read();
	printf("0 0 %lld %lld 1 1000000000",(s+x-1)/x,(s+x-1)/x*x-s);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> a(n),d(n,0);
    rep(i,n) cin>>a[i];
    ll dp[n][3];
    rep(i,n){
        dp[i][0]=a[i]-1;
        dp[i][1]=a[i];
        dp[i][2]=a[i]+1;
        rep(j,3){
            if(dp[i][j]%2!=0) d[i]++;
        }
    }
    vector<ll> e(n,0);
    e[0]=d[0];
    rrep(i,n-1) e[i]=d[i]*e[i-1];
    ll sum=0;
    rep(i,n){
        rep(j,3){
            if(dp[i][j]%2==0){
                if(i==0) sum+=pow(3,n-i-1);
                else sum+=pow(3,n-i-1)*e[i-1];
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll ans = 1;
  double dans = 1;
  vector<ll> vec(n);
  for(int i=0; i<n; ++i){
    cin >> vec[i];
    if(vec[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0; i<n; ++i){
    ans *= vec[i];
    dans *= vec[i];
    if(dans > 1e18 || ans > 1000000000000000000){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
import heapq
import math

N,M=map(int,input().split())
A=list(map(int,input().split()))

now=[]

for i in range(N):   #O(NlogN)
    heapq.heappush(now,-A[i])

for j in range(M):  #O(MlogN)
    MIN=heapq.heappop(now)
    MIN/=2
    heapq.heappush(now,MIN)

for k in range(N):  #O(N)
    now[k]=math.floor(-now[k])

print(sum(now))







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

int main()
{
	int q;
	string S, T;
	cin >> S >> T >> q;
	int n = S.size(), m = T.size();
	vector<int> Sc(n + 1), Tc(m + 1);
	for (int i = 0; i < n; i++) {
		Sc[i + 1] = Sc[i] + (S[i] == 'A');
	}
	for (int i = 0; i < m; i++) {
		Tc[i + 1] = Tc[i] + (T[i] == 'A');
	}
	int a, b, c, d;
	while (q--) {
		cin >> a >> b >> c >> d;
		int s = Sc[b] - Sc[a - 1];
		s = b - a + 1 + s; s %= 3;
		int t = Tc[d] - Tc[c - 1];
		t = d - c + 1 + t; t %= 3;
		cout << (s == t ? "YES" : "NO") << endl;
	}
	return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll 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(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(3*n);
  rep(i,3*n) cin >> a[i];
  vector<pair<ll,ll>> borderArray(n+1);

  priority_queue< ll, vector<ll>, greater<ll>> min_que;
  ll sumLeft = 0;
  rep(i,n){
    sumLeft += a[i];
    min_que.push(a[i]);
  }
  borderArray[0].first = sumLeft;
  int idx = 1;
  FOR(i,n,2*n){
    min_que.push(a[i]);
    sumLeft += a[i];
    sumLeft -= min_que.top();
    borderArray[idx].first = sumLeft;
    min_que.pop();
    idx++;
  }


  priority_queue<ll>  max_que;
  ll sumRight = 0;
  FOR(i,2*n,3*n){
    sumRight += a[i];
    max_que.push(a[i]);
  }
  borderArray[n].second = sumRight;
  idx = n-1;
  for(ll i = 2*n-1; i >= n; i --){
    max_que.push(a[i]);
    sumRight += a[i];
    sumRight -= max_que.top();
    borderArray[idx].second = sumRight;
    max_que.pop();
    idx--;
  }
  ll ans = -1e15;

  rep(i,n+1){
    ans = max(borderArray[i].first - borderArray[i].second, ans);
  }
  cout << ans << endl;
  return 0;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll gcd(ll a, ll b){
    ll tmp;
    if(a%b == 0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}

const ll SIZE = 1e5+10;

ll a,b;

int main(){
    cin >> a >> b;
    for(int i = 1; i <= 3; i++){
        if(a != i && b != i)    cout << i << endl;
    }
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#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>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

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

    abs(x-a)<abs(x-b)? cout<<"A"<<endl:cout<<"B"<<endl;






}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0;i<n;i++)
#define REP(i, n) for(ll i=1;i<=n;i++)


int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	map<ll, ll> mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	sort(a.begin(), a.end());
	ll mx = a[n - 1];
	ll ans = 0;
	rep(i, n) {
		for (ll j = 2; j * a[i] <= 1000000; ++j) {
			if(j*a[i] > mx) break;
			mp[j * a[i]]++;
		}
		if (mp[a[i]] >= 2) continue;
		ans++;
	}
	cout << ans << endl;
	return 0;
}



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

using ll = long long;
using ii = pair<int, int>;

const int maxn = 1e3 + 3;
const int mod = 1e9 + 7;

inline int mul_actual(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
	return (int) ((long long) a * b % mod);
#endif
	unsigned long long x = (long long) a * b;
	unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
	asm(
		"divl %4; \n\t"
		: "=a" (d), "=d" (m)
		: "d" (xh), "a" (xl), "r" (mod)
	);
	return m;
}
inline int mul() { return 1; }
template <typename T, typename... V>
inline T mul(T x, V... v) {
	return mul_actual(x, mul(v...));
}

int n, k;
int a[maxn];
int C[maxn][maxn];
int dp[21][maxn];

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	for(int i = 0; i < maxn; i++) {
		C[i][i] = C[i][0] = 1;
	}
	for(int i = 1; i < maxn; i++) {
		for(int j = 1; j < i; j++) {
			C[i][j] = C[i-1][j] + C[i-1][j-1];
			if(C[i][j] >= mod) C[i][j] -= mod;
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= k; i++) {
		dp[i][0] = mul(dp[i-1][0], C[n][a[i]]);
		for(int j = 1; j <= n; j++) {
			for(int tek = 0; tek <= j and tek <= a[i]; tek++) {
				dp[i][j] += mul(dp[i-1][j-tek], C[j][tek], C[n-tek][a[i]-tek]);
				if(dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	cout << dp[k][n] << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

bool Check(int x, int y)
{
	if (x + y == 1) return false;
	bool f1 = true;
	for (int i = 2; i <= max(x, y); i += 2) {
		if (x >= i) {
			bool now1 = Check(x - i, y + i / 2);
			f1 &= now1;
		}
		if (y >= i) {
			bool now2 = Check(x + i / 2, y - i);
			f1 &= now2;
		}
	}
	if (f1) return false; else return true;
}

int main()
{
	/*for (int x = 0; x <= 20; x++) {
		for (int y = x; y <= 20; y++)
			if (x + y > 0 && Check(x, y)) {
				printf("%d %d\n", x, y);
			}
	}*/
	LL a, b;
	scanf("%lld%lld", &a, &b);
	if (a == 0 && b == 0) printf("Brown\n");
	else {
		if (max(a, b) - min(a, b) <= 1) printf("Brown\n");
		else printf("Alice\n");
	}
	return 0;
}

Measured memory_bytes: 128
//package Contest066;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
            int n = sc.nextInt();
            int arr[] = new int[n];
            for(int i=0;i<n;i++)
                arr[i] = sc.nextInt();
            if(n%2==0)
            {
                for(int i=n-1;i>0;i-=2)
                    out.print(arr[i]+" ");
                for(int i=0;i<=n-1;i+=2)
                    out.print(arr[i]+" ");
                out.println();
            }
            else{
                for(int i=n-1;i>=0;i-=2)
                    out.print(arr[i]+" ");
                for(int i=1;i<=n-1;i+=2)
                    out.print(arr[i]+" ");
                out.println();
            }
        out.flush();
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

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

const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };

int matubi(int x)
{
    return x % 10;
}

int sentou(int x)
{
    int out;
    while (x > 0) {
        out = x;
        x /= 10;
    }
    return out;
}
int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int x = 1; x <= 9; x++) {
        for (int y = 1; y <= 9; y++) {
            if (x != y) {
                int A = 0;
                int B = 0;
                for (int n = 1; n <= N; n++) {
                    if (matubi(n) == x && sentou(n) == y) {
                        A++;
                    }
                    if (matubi(n) == y && sentou(n) == x) {
                        B++;
                    }
                }
                ans += A * B;
            } else {
                int A = 0;
                for (int n = 1; n <= N; n++) {
                    if (matubi(n) == x && sentou(n) == y) {
                        A++;
                    }
                }
                ans += A * A;
            }
        }
    }

    if (N == 1) {
        cout << 1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256