akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define EPS (1e-5)
typedef complex<double> P;
inline double sq(double a) { return a*a; }

const char names[4][8] = {"Red", "Green", "Blue", "White"};
int N, A, B, xs[50], ys[50];
P ps[50];

inline double cross(const P& a, const P& b) { return imag(conj(a)*b); }
inline P unit(const P& p) { return 1/abs(p)*p; }

inline bool intersectSP(const P& s0, const P& s1, const P& p) {
    return abs(s0-p)+abs(s1-p)-abs(s1-s0) < EPS;
}

P crosspoint(const P& l0, const P& l1, const P& m0, const P& m1) {
    const double A = cross(l1-l0, m1-m0);
    const double B = cross(l1-l0, l1-m0);
    if(abs(A)<EPS && abs(B)<EPS) return m0;
    return m0+B/A*(m1-m0);
}

vector<P> crosspointsCL(const P& p, double r, const P& l0, const P& l1) {
    vector<P> v;
    const P cp(crosspoint(p, p+(l1-l0)*P(0, 1), l0, l1));
    if(abs(cp-p)<EPS) {
        const P dir(r*unit(l1-l0));
        v.push_back(p+dir); v.push_back(p-dir);
    }
    else if(abs(cp-p)<r+EPS) {
        const double a = sqrt(sq(r)-norm(p-cp));
        const P dir(a*unit(cp-p)*P(0, 1));
        v.push_back(cp+dir); v.push_back(cp-dir);
    }
    return v;
}

double angle(P p, double L) {
    double a = -1e100;
    rep(i, N-1) {
        vector<P> v(crosspointsCL(p, L, ps[i], ps[i+1]));
        rep(j, v.size()) {
            if(real(p)<real(v[j]) && intersectSP(ps[i], ps[i+1], v[j])) {
                a = max(a, arg(v[j]-p));
            }
        }
    }
    return a;
}

int main() {
    const double sqrt2 = sqrt(2);
    const double arg45 = arg(P(1, 1));
    const double pi = atan2(0.0, -1.0);
    scanf("%d%d%d", &N, &A, &B);
    rep(i, N) scanf("%d%d", xs+i, ys+i);
    rep(i, N) ps[i] = P(xs[i], ys[i]);
    int rp = 0;
    P cur(A, ys[0]+(double)(A-xs[0])*(ys[1]-ys[0])/(xs[1]-xs[0]));
    cur += unit(ps[1]-ps[0]);
    while(cur.real()<B-EPS) {
        const double a = angle(cur, 1), b = angle(cur, sqrt2);
        if(a>b-arg45-EPS) cur += P(cos(a), sin(a)), rp += 1;
        else cur += P(cos(b), sin(b))*sqrt2, rp += 2;
    }
    puts(names[rp%4]);
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w, ch,cw, dh, dw;
	cin >>h >>w >>ch >>cw >>dh >>dw;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];
	ch--;cw--;dh--;dw--;
	
	vector<vector<pii>> r(h*w);
	
	rep(i, h) rep(j, w) if(ba[i][j]=='.'){
		rep2(yy, -2, 3) rep2(xx,-2, 3){
			if(yy+i<0 || yy+i>=h || xx+j<0 ||xx+j>=w) continue;
			if(ba[yy+i][xx+j] != '.' || (yy==0 && xx==0)) continue;
			if(abs(yy) + abs(xx) ==1) r[i*w+j].emplace_back((yy+i)*w +xx+j, 0);
			else r[i*w+j].emplace_back((yy+i)*w +xx+j, 1);
		
		}
	}
	
	
	
	const int dr[]={0,1,0,-1,0};

	typedef pair<ll, int> pli;
	const ll INF = 1e18;
	priority_queue< pli, vector<pli>, greater<pli> > que;
	vector<ll> d(h*w, INF);
	d[ch*w+cw] = 0;
	que.emplace(0, ch*w+cw);
	while(!que.empty()){
		ll cost; int v; tie(cost, v) = que.top(); que.pop();
		if(d[v] < cost) continue;
		for(const auto& rp : r[v]){ 
			int rto = rp.first;
			ll ncst = d[v] + rp.second;
			if(d[rto] > ncst){
				d[rto] = ncst; que.emplace(ncst, rto);
			}
		}
	}
	ll ans = d[dh*w + dw];
	cout << (ans!=INF? ans: -1) <<"\n";
	return 0;
}



Measured memory_bytes: 105460
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    L = LI()
    m = max(L)
    other = sum(L) - m
    if m < other:
        print("Yes")
    else:
        print("No")

main()



Measured memory_bytes: 83692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static Scanner sc = new Scanner(new InputStreamReader(System.in));

	public static void main (String[] args) throws Exception {
		int[] list = sumList(prime());
		while(true) {
			String str = br.readLine();
			int n = Integer.parseInt(str);
			if(n == 0) break;
			System.out.println(list[n-1]);
		}
	}
	
	public static int[] prime() {
		int[] list = new int[10000];
		list[0] = 2;
		list[1] = 3;
		list[2] = 5;
		list[3] = 7;
		list[4] = 11;
		list[5] = 13;
		int pit = 6;
		for(int i=17; pit<10000; i = i+2) {
			for(int j=1; list[j]*list[j] < i; j++) {
				if(i%list[j] == 0) break;
				if(list[j+1]*list[j+1] > i) {
					list[pit] = i;
					pit++;
				}
			}
		}
		return list;
	}
	
	public static int[] sumList(int[] list) {
		int[] sums = new int[10000];
		sums[0] = 2;
		for(int i=1; i<10000; i++) {
			sums[i] = sums[i-1] + list[i];
		}
		return sums;
	}
}

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

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;class Main{public static void main(String[]g)throws Exception{BufferedReader B=new BufferedReader(new InputStreamReader(System.in));Integer i=0,o,m,l=1+i.valueOf(B.readLine()),w[]=new Integer[l],n=i.valueOf(B.readLine());while(i<l)w[i]=i++;for(;n-->0;w[m]=i){g=B.readLine().split(",");i=w[o=i.valueOf(g[0])];w[o]=w[m=i.valueOf(g[1])];}for(i=0;++i<l;)System.out.println(w[i]);}}


Measured memory_bytes: 24388
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
//#define int long long
vector<int> sieve(int n) {
	vector<int> prime;
	vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return prime;
}
map<ll, int> prime_factrorize(ll n, vector<int> const & primes) {
	map<ll, int> result;
	for (int p : primes) {
		if (n < p) break;
		while (n % p == 0) {
			result[p] += 1;
			n /= p;
		}
	}
	if (n != 1) result[n] += 1;
	return result;
}
const ll mod = 1e9 + 7;
signed main() {
	ll n;
	cin >> n;
	vector<int>primes = sieve(n);
	map<ll, int> factors;
	for (int i = 1; i <= n; i++) {
		for (auto e : prime_factrorize(i, primes)) {
			int p, cnt; tie(p, cnt) = e;
			factors[p] += cnt;
		}
	}
	ll ans = 1;
	for (auto e : factors) {
		int cnt = e.second;
		ans = ans * (1 + cnt) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int D = C - (A - B);
  if (D < 0)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << D << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main() {
  ll R,C,N;
  cin >> R >> C >> N;
  vector<pair<ll,int> > v;
  repeat(i,N){
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if((x1%R!=0 && y1%C!=0) || (x2%R!=0 && y2%C!=0)) continue;
    ll p1=0;
    if(y1==0) p1=x1;
    else if(y1==C) p1=2*R+C-x1;
    else if(x1==R) p1=R+y1;
    else p1=(2*R+2*C-y1)%(2*R+2*C);
    ll p2=0;
    if(y2==0) p2=x2;
    else if(y2==C) p2=2*R+C-x2;
    else if(x2==R) p2=R+y2;
    else p2=(2*R+2*C-y2)%(2*R+2*C);
    if(p1>p2)swap(p1,p2);
    v.push_back({p1,i+1});
    v.push_back({p2,-i-1});
    cerr << i+1 << endl;
  }
  sort(v.begin(),v.end());
  stack<int> st;
  bool isok=true;
  for(auto u:v){
    if(u.second<0){
      isok &= (st.top()+u.second)==0;
      st.pop();
    }else{
      st.push(u.second);
    }
  }
  cout <<(isok? "YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"

ll n,m,a,b,s,t;
vector<ll> adj[MAXN];
ll vis[MAXN],dist[MAXN];
queue<ll> q;

void bfs(ll s,ll t,ll n)
{
    vis[s]=1;
    q.push(s);
    dist[s]=0;
    while(!q.empty())
    {
        ll p=q.front();
        q.pop();
        for(ll i=0;i<adj[p].size();i++)
        {
            if(!vis[adj[p][i]])
            {
                dist[adj[p][i]]=dist[p]+1;
                vis[adj[p][i]]=1;
                q.push(adj[p][i]);
                if(adj[p][i]==t)
                {
                    cout<<dist[adj[p][i]]/3<<endl;
                    return;
                }
            }
        }
    }
    cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    while(m--)
    {
        cin>>a>>b;
        adj[a].pb(b+n);
        adj[a+n].pb(b+2*n);
        adj[a+2*n].pb(b);
    }
    cin>>s>>t;
    bfs(s,t,n);
}

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

using namespace std;

#define _int64 long long
#define mo 1000000007

int a[110000];
int ans[110000];
int fac[110000];
int inv[110000];
vector<int> q;

int pow1(int x,int y)
{
  _int64 ret;
  int i;
  ret=1;
  for (i=30;i>=0;i--)
  {
    ret=ret*ret%mo;
    if (((1<<i)&y)!=0)
    {
      ret=ret*x%mo;
    }
  }
  return ret;
}

int inv1(int x)
{
  return pow1(x,mo-2);
}

int c(int x,int y)
{
  _int64 ret;
  ret=1;
  ret*=fac[x];
  ret%=mo;
  ret*=inv[y];
  ret%=mo;
  ret*=inv[x-y];
  ret%=mo;
  return ret;
}

int main()
{
  int i,j,n,ex;
  _int64 tot;
  fac[0]=1;
  for (i=1;i<110000;i++)
    fac[i]=(_int64)fac[i-1]*i%mo;
  for (i=0;i<110000;i++)
  {
    inv[i]=inv1(fac[i]);
  }
  scanf("%d",&n);
  tot=0;
  for (i=0;i<n+1;i++)
  {
    scanf("%d",&a[i]);
    tot+=a[i];
  }
  tot-=(_int64)n*(n+1)/2;
  ex=tot;
  q.clear();
  for (i=0;i<n+1;i++)
    if (a[i]==ex) q.push_back(i);
  for (i=1;i<=n+1;i++)
  {
    ans[i]=c(n+1,i);
    if (q[0]+n-q[1]+1>=i)
    {
      ans[i]-=c(q[0]+n-q[1],i-1);
      if (ans[i]<0) ans[i]+=mo;
    }
  }
  for (i=1;i<=n+1;i++)
    printf("%d\n",ans[i]);
  return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,d,x,ans=0;
    cin>>n;
    cin>>d>>x;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=(d-1)/a[i]+1;
    }
    cout<<ans+x<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int q;
    cin>>q;
    rep(i,q){
        string n;
        cin>>n;
        int ans=0;
        while(n.length()>1){
            int maxans=0;
            for(int j=0;j<n.length()-1;j++){
                string s,t;
                s=n.substr(0,j+1);
                t=n.substr(j+1);
                maxans=max(maxans,STI(s)*STI(t));
            }
            n="";
            while(maxans>0){
                n+=maxans%10+'0';
                maxans/=10;
            }
            ans++;
            reverse(n.begin(),n.end());
        }
        cout<<ans<<endl;
    }
//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define N 100005

using namespace std;

int n;
vector<int> g[N];

int dfs(int u, int fa) {
    int sg = 0;
    for(auto v : g[u]) {
        if(v == fa) continue;
        sg ^= dfs(v, u) + 1;
    }
    return sg;
}

int main() {
    scanf("%d", &n);
    for(int i = 1, u, v; i < n; ++i) {
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    puts(dfs(1, 0) ? "Alice" : "Bob");
    return 0;
}

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

int main()
{
    string S;
    int money = 700;

    cin >> S;

    for (int i = 0; i < 3; i++)
    {
        if (S[i] == 'o')
            money += 100;
    }

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]

for i in range(n-1):
    a.append(b[i])
for j in range(n-1):
    if a[j+1] < a[j]:
        a[j] = a[j+1]
print(sum(a))


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

int main() {
  int N, K;
  cin >> N >> K;
  int d;
  vector<int> A(N);
  int x;
  rep(i, K){
   cin >> d;
   rep(j, d){
    cin >> x; 
    A.at(x-1)++;
   }
  }
  int ans = 0;
  rep(i, N){
   if(A.at(i) == 0) ans++; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;


int main(void){
  ll l,r;
  ll mi=1000000000000000000;
  int num[2019]={-1};
  cin>>l>>r;
  if(r-l+1>=2019)cout<<0<<endl;
  else{
    for(ll i=l;i<=r;i++){
          for(ll j=l;j <=r;j++){
           if(i !=j)mi=min(mi,i*j%2019);
      }
    }
    cout<<mi<<endl;
  }
}


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


using namespace std;


typedef long long LL;
typedef pair<LL,LL> pp;

int visited[101][101][2];
int N;

int f(int A, int B, int p) {
	visited[A][B][p] = 1;
	if (p == 0) {
		if (A != N && A+1 != B) {
			if (!visited[A+1][B][1-p] && !f(A+1, B, 1-p)) {
				return 1;
			}
		}
		if (A != 1 && A-1 != B) {
			if (!visited[A-1][B][1-p] && !f(A-1, B, 1-p)) {
				return 1;
			}
		}
	}
	else {
		if (B != N && B+1 != A) {
			if (!visited[A][B+1][1-p] && !f(A, B+1, 1-p)) {
				return 1;
			}
		}
		if (B != 1 && B-1 != A) {
			if (!visited[A][B-1][1-p] && !f(A, B-1, 1-p)) {
				return 1;
			}
		}
	}
	return 0;
}

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

	memset(visited, 0, sizeof(visited));
	cout << (f(A, B, 0) ? "Alice" : "Borys") << endl;
	exit(0);
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);



int main() {
    ios_base::sync_with_stdio(false);

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<vector<ll>> dp0(c+2,vector<ll>(d+2)),dp1(c+2,vector<ll>(d+2)); 
    dp0[a][b]=0;
    dp1[a][b]=1;
    repr(i,a,c+1) {
        repr(j,b,d+1) {
            dp0[i][j]=(dp0[i][j]+dp0[i-1][j]*j)%MOD;
            if (j>b) dp0[i][j]=(dp0[i][j]+dp1[i-1][j])%MOD;
            dp1[i][j]=(dp1[i][j]+(dp0[i][j-1]+dp1[i][j-1])*i)%MOD;
            if (j==b) dp1[i][j]=(dp1[i][j]+dp1[i-1][j]*j)%MOD;
        }
    }
    cout << (dp0[c][d]+dp1[c][d])%MOD << endl;
     

    return 0;
}


Measured memory_bytes: 144196
#素数判定
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
    
x=int(input())
for i in range(x, 2*x):
    if is_prime(i):
        print(i)
        break

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(s) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

void calc() {
	int N; cin >> N;
	priority_queue<int, vector<int>, greater<int>> a;
	priority_queue<int> b;
	vector<int> v(N);
	V ans(N + 1);
	V bns(N + 1);
	int asum = 0;
	rep(i, N) {
		int x; cin >> x;
		a.push(x);
		asum += x;
	}
	input(v);
	int bsum = 0;
	rep(i, N) {
		int x; cin >> x;
		b.push(x);
		bsum += x;
	}

	ans[0] = asum;
	rep(i, N) {
		int x = v[i];
		if (x > a.top()) {
			asum -= a.top();
			a.pop();
			asum += x;
			a.push(x);
		}
		ans[i + 1] = asum;
	}

	bns[N] = bsum;
	rep(i, N) {
		int x = v[N - i - 1];
		if (x < b.top()) {
			bsum -= b.top();
			b.pop();
			bsum += x;
			b.push(x);
		}
		bns[N - i - 1] = bsum;
	}

	int ret = -(1ll << 60);
	rep(i, N + 1) {
		maxup(ret, ans[i] - bns[i]);
	}
	cout << ret << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

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

typedef long long LL;
const int N = 200006;

LL pre[N];
int a[N];
int n;

LL get_ans(int i,int j,int k)
{
    if (i >= j || j >= k) return (1LL<<60);
    if (i < 1 || k >= n) return (1LL<<60);
    set<LL> st;
    st.insert(pre[i]);
    st.insert(pre[j] - pre[i]);
    st.insert(pre[k] - pre[j]);
    st.insert(pre[n] - pre[k]);
    return (*(--st.end()) - *(st.begin()));
}

inline LL cal(int L,int R)
{
    return (pre[R] - pre[L-1]);
}

int main ()
{
    scanf("%d",&n);
    for (int i=1;n>=i;i++)
    {
        scanf("%d",&a[i]);
        pre[i] = pre[i-1] + a[i];
    }
    LL ans = (1LL<<60);
    for (int j=2;n-1>=j;j++)
    {
        int Li=1,Ri=j-1;
        while (Ri - Li > 1)
        {
            int mid=(Li + Ri)>>1;
            if (pre[mid] >= cal(mid+1,j)) Ri = mid;
            else Li = mid;
        }
        int Lk=j+1,Rk=n-1;
        while (Rk - Lk > 1)
        {
            int mid=(Lk+Rk)>>1;
            if (cal(j+1,mid) >= cal(mid+1,n)) Rk = mid;
            else Lk = mid;
        }
        //cout << "j = " << j << " , Li = " << Li << " , Lk = " << Lk << endl;
        ans = min(ans,get_ans(Li,j,Lk));
        ans = min(ans,get_ans(Ri,j,Lk));
        ans = min(ans,get_ans(Li,j,Rk));
        ans = min(ans,get_ans(Ri,j,Rk));
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int A,B,w = 100,h = 0;
char a[105][105];
void Calc(int R,char W,char B)  {
    ++h;
    for(int i = 1 ; i <= w ; ++i) a[h][i] = B;
    if(!R) return;
    while(R >= 50) {
	R -= 50;
	for(int i = 1 ; i <= w ; ++i) {
	    if(i & 1) a[h + 1][i] = W;
	    else a[h + 1][i] = B;
	}
	for(int i = 1 ; i <= w ; ++i) a[h + 2][i] = B;
	h += 2;
    }
    if(R) {
	int t = 1;
	while(R--) {
	    a[h + 1][t] = W;
	    a[h + 1][t + 1] = B;
	    t += 2;
	}
	for(int i = t ; i <= w ; ++i) a[h + 1][i] = B;
	for(int i = 1 ; i <= w ; ++i) a[h + 2][i] = B;
	h += 2;
    }
}
void Solve() {
    read(A);read(B);
    --A;--B;
    Calc(A,'.','#');Calc(B,'#','.');
    out(h);space;out(w);enter;
    for(int i = 1 ; i <= h ; ++i) {
	for(int j = 1 ; j <= w ; ++j) {
	    putchar(a[i][j]);
	}
	enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 256
import bisect
a,b,q=map(int,input().split())
s=[int(input())for _ in range(a)]
s.append(12345678901234)
s.insert(0,-12345678901234)
t=[int(input())for _ in range(b)]
t.append(12345678901234)
t.insert(0,-12345678901234)
for query in range(q):
    ans = 123456789012345
    x=int(input())
    idxs = bisect.bisect_left(s,x)
    idxt = bisect.bisect_left(t,x)
    ls = s[idxs-1]
    rs=s[idxs]
    lt=t[idxt-1]
    rt=t[idxt]
    # 左
    ans = min(ans,max(abs(x-ls),abs(x-lt)))

    # 右
    ans = min(ans,max(abs(x-rs),abs(x-rt)))    

    # 行って帰って
    ans = min(ans,2*abs(x-ls)+abs(x-rt))
    ans = min(ans,2*abs(x-lt)+abs(x-rs))
    ans = min(ans,2*abs(x-rs)+abs(x-lt))
    ans = min(ans,2*abs(x-rt)+abs(x-ls))
    
    print(ans)


Measured memory_bytes: 12092
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

struct pt
{
	int x, y, i;
	pt() { }
	pt(int x, int y, int i) : x(x), y(y), i(i) { }
};

struct edge
{
	int v, u, w;
	edge() { }
	edge(int v, int u, int w) : v(v), u(u), w(w) { }
};

struct dsu
{
	int n;
	vector<int> p, w;

	dsu(int n) : n(n)
	{
		p.resize(n);
		w.resize(n);

		forn (i, n)
			p[i] = i, w[i] = 1;
	}

	int getp(int v) { return p[v] == v ? v : p[v] = getp(p[v]); }

	bool join(int u, int v)
	{
		u = getp(u);
		v = getp(v);
		if (u == v) return false;
		if (w[u] < w[v]) swap(u, v);
		p[v] = u;
		w[u] += w[u] == w[v];
		return true;
	}
};

int n;
pt p[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y), p[i].i = i;

	return true;
}

bool cmpx(pt a, pt b) { return a.x < b.x || (a.x == b.x && a.i < b.i); }
bool cmpy(pt a, pt b) { return a.y < b.y || (a.y == b.y && a.i < b.i); }
bool cmpe(edge a, edge b) { return a.w < b.w; }

void solve()
{
	vector<edge> e;
	sort(p, p + n, cmpx);

	forn (i, n - 1)
		e.push_back(edge(p[i].i, p[i + 1].i, p[i + 1].x - p[i].x));

	sort(p, p + n, cmpy);

	forn (i, n - 1)
		e.push_back(edge(p[i].i, p[i + 1].i, p[i + 1].y - p[i].y));

	sort(e.begin(), e.end(), cmpe);
	dsu d(n);
	llong ans = 0;

	forn (i, size(e))
		if (d.join(e[i].v, e[i].u))
			ans += e[i].w;

	printf("%lld\n", ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 6004
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[1001], tmp[1001], in[10];
	int q, a, b;
	int i;

	scanf("%s", str);
	scanf("%d", &q);

	while (q--) {
		scanf("%s %d %d", in, &a, &b);
		if (strcmp(in, "print") == 0) {
			for (i = a; i <= b; i++) putchar(str[i]);
			puts("");
		}
		else if (strcmp(in, "replace") == 0) {
			scanf("%s", tmp);
			strncpy(&str[a], tmp, b - a + 1);
		}
		else {
			strcpy(tmp, str);
			for (i = 0; i <= b - a; i++) tmp[a + i] = str[b - i];
			strcpy(str, tmp);
		}
	}

	return 0;
}


Measured memory_bytes: 2140
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC145_b solver = new ABC145_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC145_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            String S = in.next();

            if ((N % 2) != 0) {
                out.println("No");
                return;

            }
            String subs = S.substring((N / 2), N);
            if (S.indexOf(subs) == 0) {
                out.println("Yes");

            } else {
                out.println("No");
            }

        }

    }
}



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

int main () {
  int a ,b ;
  cin >> a >> b ;
  
  if ( a == b ) {
    cout << "Draw" << endl ;
  } else if ( a == 1 ){
    cout << "Alice" << endl ;
  } else if ( b == 1 ) {
    cout << "Bob" << endl ;
  } else if ( a >= b ) {
    cout << "Alice" << endl ;
  } else {
    cout << "Bob" << endl ;
  }
}

Measured memory_bytes: 256
s = input()
li = [0]*len(s)
n = 0
m = 0
num = 0

for i in range(len(s)):
    if s[i] == "R":
        if num%2 == 0:
            n += 1
        else:
            m += 1
        num += 1
    else:
        if num>0:
            if num % 2 == 0:
                li[i] += n
                li[i - 1] += m
            else:
                li[i] += m
                li[i - 1] += n
        n = 0
        m = 0
        num = 0

sle = s[::-1]
n = 0
m = 0
num = 0

for i in range(len(s)):
    if sle[i] == "L":
        if num%2 == 0:
            n += 1
        else:
            m += 1
        num += 1
    else:
        if num%2 == 0:
            li[-(i+1)] += n
            li[-i] += m
        else:
            li[-(i+1)] += m
            li[-i] += n
        n = 0
        m = 0
        num = 0

for i in li:
    print(i, end=" ")

Measured memory_bytes: 4992
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;
int64_t gcd(int64_t a,int64_t b){
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a>b){
		return gcd(a%b,b);
	}else{
		return gcd(b%a,a);
	}
}
int main(){
	int32_t n;
	cin>>n;
	for(int32_t loop=0;loop<n;loop++){
		int64_t a,b,c,d;
		cin>>a>>b>>c>>d;
		if(a<b){
			cout<<"No"<<endl;
			continue;
		}
		if(b>d){
			cout<<"No"<<endl;
		}else if(b==d){
			if(a%b<=c){
				cout<<"Yes"<<endl;
			}else{
				cout<<"No"<<endl;
			}
		}else if(c>=b){
			cout<<"Yes"<<endl;
		}else{
			int64_t step=gcd(b,d);
			if(a%b>c){
				cout<<"No"<<endl;
			}else if(c>=b-1){
				cout<<"Yes"<<endl;
			}else if(b-1-c>=step){
				cout<<"No"<<endl;
			}else if((c-(a%b))%step<(b-1-(a%b))%step){
				cout<<"Yes"<<endl;
			}else{
				cout<<"No"<<endl;
			}
		}
	}



}

Measured memory_bytes: 256
N = int(input())
s = input()
s += s[0]
L = ["SS","SW","WS","WW"]

for e in L:
    for k in range(1,N+1):
        if s[k] == "o" and e[-1] == "S":
            e += e[-2]
        elif (s[k] == "x" and e[-1] == "S") or (s[k] == "o" and e[-1] == "W"):
            if e[-2] == "S":
                e += "W"
            else:
                e += "S"
        elif s[k] == "o" and e[-1] == "W":
            if e[-2] == "W":
                e += "S"
            else:
                e += "W"
        else:
            e += e[-2]
    if e[:2] == e[-2:]:
        print(e[:-2])
        exit(0)
print(-1)


Measured memory_bytes: 3572
fun main(args: Array<String>){
    var (q, h, s, d) = readLine()!!.split(" ").map(String::toLong)
    val n = readLine()!!.toLong()
    h = Math.min(q * 2, h)
    s = Math.min(h * 2, s)
    d = Math.min(s * 2, d)
    println((d * (n / 2)) + (s * (n % 2)))
}


Measured memory_bytes: 37864
# import sys

def main():
    # input = sys.stdin.readline
    s = input()
    t = input()

    res = len(t)
    # 部分文字列の探索
    for i in range(len(s)-len(t)+1):
        diff = 0
        for j in range(len(t)):
            if s[i + j] != t[j]:
                diff += 1
        res = min(res, diff)
    print(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9020
n,m = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
a=[]
if n>=m:
    print(0)
else:
    for i in range(len(x)-1):
        a.append(x[i+1]-x[i])
    a = sorted(a)
    ans = 0
    for i in range(m-n):
        ans+=a[i]
    print(ans)

Measured memory_bytes: 13968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        char c[] = str.toCharArray();
        
        int count = 0;
        for (int i = 0; i < n -2; i++) {
            if (c[i] == 'A' && c[i+1] == 'B' && c[i+2] == 'C') {
                count++;
            }
        }
        System.out.println(count);
    }
}


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

int main(){
  vector<int> A(5);
  cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
  vector<int> P = {0,1,2,3,4};
  int final_answer = 10e8;
  do {
    int ans = 0;
    for (int i = 0; i < 5; i++){
      while (ans % 10 != 0) ans += 1;
      ans += A[P[i]];
    }
    final_answer = min(final_answer, ans);
  } while (next_permutation(P.begin(),P.end()));
  cout << final_answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
	int k,n;
	cin>>k>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	b[0]=a[n-1]-a[0];
	for(int i=1;i<n;i++){
		b[i]=k+a[i-1]-a[i];
	}
	for(int i=0;i<n;i++){
		if(b[i]<k)k=b[i];
	}
	cout<<k;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>


using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    int count,num;
    long double sum;
    sum = 0;
    for(int i=1;i<N+1;i++){
        num=i;
        count =0;
        while(1){
            if(num>=K){
                break;
            }
            num = num*2;
            count++;
        }
        sum += 1.0 /  pow(2.0,count);
    }
    cout << setprecision(20) << sum/N << endl;
}

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

using namespace std;


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

    size_t cnt = 0;

    for (size_t i = 0; i < 1000; ++i) {
        char l, m, n; // 3keta, 2keta, 1keta
        l = i / 100 + '0';
        m = (i / 10) % 10 + '0';
        n = i % 10 + '0';
        auto first = find(s.begin(), s.end(), l);
        auto rlast = find(s.rbegin(), s.rend(), n);
        if (first == s.end() || rlast == s.rend()) continue;
        auto distfrombegin = std::distance(rlast, s.rend()) - 1;
        auto last = s.begin() + distfrombegin;
       // if (i == 224) cout << distance(s.begin(), first) << " : " << distfromfirst << endl;
        if (distance(s.begin(), first) >= distfrombegin) continue;
        
        auto middle = find(first + 1, last, m);
        //if (i == 224) cout << distance(first, middle) << endl;
        if (middle != first && middle != last) {
            ++cnt;
        }
    }

    std::cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
w,h,n = [int(x) for x in input().split()]
l = 0
r = w
b = 0
t = h
for _ in range(n):
    x,y,a = [int(x) for x in input().split()]
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(r,x)
    elif a == 3:
        b = max(b,y)
    elif a == 4:
        t = min(t,y)

if r<l or t<b:
    print(0)
else:
    print((r-l) * (t-b))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

void pos (void) { cout << "Possible\n"; }
void imp (void) { cout << "Impossible\n"; }

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    sort(all(a));
    map<ll, int> m;
    rep (i, n) m[a[i]]++;
    if (m[a.front()] > 2) {
        imp(); return 0;       
    }
    if (a.size() == 2 && a[0] == 1 && a[1] == 1) {
        pos(); return 0;
    }
    if (m[a.front()] == 1) {
        bool ok = a.back() == a.front() * 2;
        int prev = a.front() - 1;
        for (auto [l, c] : m) {
            ok = ok && (l == a.front() || c >= 2) && (prev == l - 1);
            prev = l;
        }
        ok ? pos() : imp();
    } else {
        bool ok = a.front() > 1 && a.back() == a.front() * 2 - 1;
        ll prev = a.front() - 1;
        for (auto [l, c] : m) {
            ok = ok && (l == a.front() || c >= 2) && (prev == l - 1);
            prev = l;
        }
        ok ? pos() : imp();
    }
    return 0;
}

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

#define rep(i, N) for(int i = 0; i < N; i++)
#define all(v) v.begin(), v.end()

int main(){
	long long N, K;
	cin >> N >> K;
	
	const long long MOD = 1e9 + 7;

	long long ans = 1;
	rep(i, N){
		ans = (ans * K) % MOD;
	} 
	cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> room(n+1);
  vector<int> dist(n+1, -1);
  queue<int> que;
  for(int i=1 ; i<=m; i++) {
    int a, b;
    cin >> a >> b;
    room[a].push_back(b);
    room[b].push_back(a);
  }
  dist[1]=0;
  que.push(1);
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(int nv:room[v]) {
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }
  cout << "Yes" << endl;
  for(int i=2; i<=n; i++) {
    int minDist = 10000000;
    int minRoom;
    for(int j=0; j<(int)room[i].size(); j++) {
      if(dist[room[i][j]]<minDist) {
          minDist = dist[room[i][j]];
          minRoom = room[i][j];
      }
    }
    cout << minRoom << endl;
  }
}


Measured memory_bytes: 10344
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	var n []int
	for i := 1; i <= 100; i++ {
		if a%i == 0 && b%i == 0 {
			n = append(n, i)
		}
	}
	fmt.Println(n[len(n)-k])
}


Measured memory_bytes: 512
main :: IO ()
main = do
  [s, t] <- words <$> getLine
  [a, b] <- map read . words <$> getLine
  u <- getLine
  putStrLn . unwords . map show $ solve s t a b u

solve :: String -> String -> Int -> Int -> String -> [Int]
solve s _ a b u
  | s == u    = [a - 1, b]
  | otherwise = [a, b - 1]


Measured memory_bytes: 508
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

h,w=map(int,input().split())
ans=h*w
if h*w%3==0:
    print(0)
else:
    for x,y in ((h,w),(w,h)):
        x1=x//3
        x2=(x+2)//3
        y1=y//2
        y2=(y+1)//2
        ans=min(ans,abs(y*x2-y*x1))
        t=(y*x1,y2*(x-x1),(y-y2)*(x-x1))
        ans=min(ans,max(t)-min(t))
        t=(y*x2,y2*(x-x2),(y-y2)*(x-x2))
        ans=min(ans,max(t)-min(t))
    print(ans)


Measured memory_bytes: 3064
<>=~$";$G=$';map{$i+=100;for$k(reverse@a=//..$<){$p[$k]+=$-=$_>$k?0:$p[$k-$_]+$i*$_+($_==$`&&$')-$p[$k]for 1..$`}}<>;printf grep$p[$_]>=$G,@a

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

using namespace std;
int maxi,n,i,a[100005];
int dps[100005],dpd[100005];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    dps[2]=a[1];
    dpd[n-1]=a[n];

    for(i=3;i<=n;i++)
        dps[i]=__gcd(dps[i-1], a[i-1]);

    for(i=n-2;i>=1;i--)
        dpd[i]=__gcd(dpd[i+1], a[i+1]);

    maxi=max(dpd[1], dps[n]);

    for(i=2;i<=n-1;i++)
        maxi=max(maxi, __gcd(dps[i], dpd[i]));

    cout<<maxi;
    return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

c = [0] * (n + 1)
d = [0] * (n + 1)
for i in range(n):
    c[a[i]] += 1
    d[b[i]] += 1
# 鳩の巣原理
# どんなに頑張っても1個以上重なる
for i in range(n + 1):
    if c[i] + d[i] > n:
        print('No')
        sys.exit(0)

import itertools
c = list(itertools.accumulate(c))
d = list(itertools.accumulate(d))

max_gap = 0
for i in range(1, n + 1):
    max_gap = max(max_gap, c[i] - d[i-1])

ans = [0] * n
for i in range(n):
    ans[(i + max_gap) % n] = str(b[i])

print('Yes')
print(' '.join(ans))


Measured memory_bytes: 132756
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int N,K;
 string S;

 cin>>N>>K;
 cin>>S;

 vector<int> Nums;
 int now=1;
 int cnt=0;
 for(int i=0; i<N; i++){
   if(S[i]==(char)('0' + now))cnt++;
   else {
    Nums.push_back(cnt);
    now = 1-now; 
    cnt =1;
   }
 }

 if(cnt != 0) Nums.push_back(cnt);

 //1-0-1-0-1-0-1って感じの配列が欲しい
 //1-0-1-0みたいに0で終わってたら、適当に1つタス
 if(Nums.size() % 2==0)Nums.push_back(0);

 int Add= 2* K+1;
 int ans=0;

 int left=0;
 int right=0;
 int tmp=0; //[left right)のsum

 for(int i=0; i<Nums.size(); i+=2)
 {

  int Nextleft=i;
  int Nextright=min(i+Add,(int)Nums.size());
  //左端を移動する
  while(Nextleft> left){
   tmp -=Nums[left];
   left++;
  }
  //右端を移動する
  while(Nextright> right){
   tmp +=Nums[right];
   right++;
  }
  ans= max(tmp,ans);
 }

 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 1020
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int coin[2][55555],cost[2][55555];

void update(int i, int j, int c, int v){
	if(coin[i][j] < c){
		coin[i][j] = c;
		cost[i][j] = v;
	}else if(coin[i][j] == c){
		cost[i][j] = min(cost[i][j], v);
	}
}

int main(void){
	int n,p[111],i,j,r,c,a,b;
	bool flag;
	while(true){
		cin >> n;
		if(!n){
			break;
		}
		fill(coin[0],coin[2],0);
		fill(cost[0],cost[2],INF);
		cost[0][0] = 0;
		for(i=0; i<n; ++i){
			a = i%2;
			b = (i+1)%2;
			cin >> p[i];
			for(j=0; j<50000; ++j){
				update(b,j,coin[a][j],cost[a][j]);
				if(cost[a][j]>=INF){
					continue;
				}
				r = (p[i]+500)%1000;
				if(j>=r){
					update(b,j-r,coin[a][j]+1,cost[a][j]+p[i]);
				}
				r = (5000-p[i])%1000;
				if(r<500){
					update(b,j+r,coin[a][j],cost[a][j]+p[i]);
				}else{
					update(b,j+r-500,coin[a][j]+1,cost[a][j]+p[i]);
				}
			}
		}
		a = n%2; b = (n+1)%2;
		coin[b][0] = 0; cost[b][0] = INF;
		for(j=0; j<50000; ++j){
			if(cost[a][j]<INF){
				update(b,0,coin[a][j],cost[a][j]);
			}
		}
		cout << coin[b][0] << " " << cost[b][0] << endl;
	}
	return 0;
}



Measured memory_bytes: 3872
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                           //     #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };

           signed main(){
        
           	int m,n;
           	cin>>n>>m;
           	if(n%3==0 || m%3==0 || (n+m)%3==0)cout<<"Possible"<<endl;
           	else cout<<"Impossible"<<endl;
           	
           	
           //	cout<<-1<<endl;
           	
           	return 0;
           	
           	
           }
             

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  int m = -1;
  int soeji;
  int sum = 0;

  for(int i = 0; i < n; ++i){
    cin >> l.at(i);
  }
  for(int i = 0; i < n; ++i){
    if(l.at(i) > m){
      soeji = i;
      m = l.at(i);
    }
  }

  for(int i = 0; i < n; ++i){
    if(i == soeji) continue;
    sum += l.at(i);
  }

  if(sum > m){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
let () =
  let print str a b = print_endline (String.sub str a (b-a+1)) in
  let replace str a b p =
    String.mapi (fun i c -> if i >= a && i <= b then p.[i-a] else c) str in
  let reverse str a b =
    String.mapi (fun i c -> if i >= a && i <= b then str.[a-i+b] else c) str in
  let rec loop acc = function
      0 -> ()
    | i ->
      let code = read_line () |>Str.split (Str.regexp " ") |> Array.of_list in
      let op,a,b = code.(0),
                   code.(1) |> int_of_string,
                   code.(2) |> int_of_string in
      match op with
      | "print" -> print acc a b; loop acc (i-1)
      | "reverse" -> loop (reverse acc a b) (i-1)
      | _ -> loop (replace acc a b code.(3)) (i-1)
  in 
  let str = read_line () in
  loop str (read_int ())

Measured memory_bytes: 2412