akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    SORT(a);

    int sum = 0;
    FOR(i, 1, N) {
        sum += a[i]-a[i-1];
    }

    cout << sum << endl;
    
    return 0;
}

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

typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main(){
	speed;
	str s;
	cin >> s;
	int sum = 0;
	for(char i : s){
		sum = sum + (i - '0');
	}
	if(sum % 9){
		cout << "No";
	}
	else{
		cout << "Yes";
	}
}

Measured memory_bytes: 3740
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
vector<pii> G[MAXN];
int D[MAXN], color[MAXN];
int ans[2 * MAXN];

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    vector<pii> V;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &D[i]);
        V.push_back(make_pair(D[i], i));
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(make_pair(i, b));
        G[b].push_back(make_pair(i, a));
    }
    sort(V.begin(), V.end());
    for (int i = 0; i < N; i++) {
        int cur = V[i].second;
        bool OK = false;
        for (auto j : G[cur]) {
            int to = j.second;
            if (D[to] <= D[cur]) OK = true;
        }
        if (!OK) return !printf("-1\n");
    }
    for (int i = 0; i < N; i++) {
        int cur = V[i].second;
        if (color[cur]) continue;
        for (auto j : G[cur]) {
            int to = j.second, idx = j.first;
            if (D[to] > D[cur]) continue;
            if (!color[to]) {
                color[to] = 1;
                color[cur] = 2;
            } else if (color[to] == 1) {
                color[cur] = 2;
            } else {
                color[cur] = 1;
            }
            ans[idx] = D[cur];
            break;
        }
    }
    for (int i = 1; i <= N; i++) {
        if (!color[i]) assert(false);
        if (color[i] == 1) printf("B");
        else printf("W");
    }
    puts("");
    for (int i = 0; i < M; i++) {
        if (!ans[i]) ans[i] = (int)1e9;
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 13300
n, m, x, y = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i).sort
ys = gets.split.map(&:to_i).sort
(x+1..y).each do |i|
  if xs[-1] < i && ys[0] >= i
    puts "No War"
    break
  end
  if i == y
    puts "War"
  end
end

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

template<class M, class N>
constexpr std::common_type_t<M, N> gcd(M m, N n) {
    return n == 0 ? abs(m) : gcd(n, abs(m) % abs(n));
}

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

        ll A, B, C, D;
        std::cin >> A >> B >> C >> D;

        auto solve = [&](ll N) { return N - (N / C + N / D - N / ((C * D) / gcd(C, D))); };
        std::cout << solve(B) - solve(A - 1) << std::endl;
    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {

	int a, b, c;
	cin >> a>> b>> c;

	if ((a + b + c) == 17) {
		if ((a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7)) {
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;

		}
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a+b<c+d){
        printf("Right\n");
    }
    else if(a+b==c+d){
        printf("Balanced\n");
    }
    else printf("Left\n");
    
return 0;
}

Measured memory_bytes: 128
N = int(input())
nums = list(map(int, input().split()))
cnt = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            tmp_list = [nums[i], nums[j], nums[k]]
            if i >= j or j >= k:
                continue
            if len(tmp_list) != len(set(tmp_list)):
                continue
            else:
                tmp_list.sort()
                if tmp_list[-1] >= sum(tmp_list[:-1]):
                    continue
                else:
                    cnt += 1
print(cnt)


Measured memory_bytes: 9192
result = 0

def gcdAB(A, B):
    if(B == 0):
        return A
    return gcdAB(B, A%B)

def gcdABC(A, B, C):
    ABgcd = gcdAB(A, B)
    return gcdAB(ABgcd, C)


K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            result += gcdABC(a,b,c)
            
print(result)

Measured memory_bytes: 77532
S = input()

if S[0] != 'A' or not 'C' in S[2:-1] or not S[1].islower() or not S[-1].islower():
    print('WA')
    exit()
n = 1
for i in S[2:-1]:
    if i.islower():
        pass
    elif i == 'C' and n==1:
        n-=1
    else:
        print('WA')
        exit()
print('AC')

Measured memory_bytes: 3064
//Code by Enderturtle
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define repe(i,a) for(register int i=head[a];i;i=e[i].nxt)
#define il inline
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
using namespace std;
il void filejudge(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
il int read(){
	int x=0;bool f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=0;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?x:-x;
}
/*----- head end -----*/
const int N=2010,mod=1e9+7;
ll fac[N*N],inv[N*N];

il ll ksm(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)
			res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
il void init(){
	const int ed=2000*2000;
	fac[0]=1;
	rep(i,1,ed) fac[i]=fac[i-1]*i%mod;
	inv[ed]=ksm(fac[ed],mod-2);
	for(register int i=ed-1;i>=1;--i) inv[i]=inv[i+1]*(i+1ll)%mod;
	inv[0]=1;
}
il ll c(int x,int y){ return fac[x]*inv[y]%mod*inv[x-y]%mod;}

ll dp[N][N];
int n,k;

il void add(ll &x,ll y){
	x+=y;
	if(x>=mod) x-=mod;
}

int main(){
	init();
	n=read();k=read();
	if(k==1){puts("1");return 0;}
	dp[0][0]=1;
//	rep(i,1,n*n) cerr<<fac[i]<<' '<<inv[i]<<endl;
	rep(i,0,n-1){
		rep(j,i,n){
			if(dp[i][j]){
				if(i<j) add(dp[i+1][j],dp[i][j]);
				if(j<n) add(dp[i][j+1],c(i+j*(k-1)+k-2,k-2)*dp[i][j]%mod);
			//	cerr<<i+j*(k-1)+k-1<<' '<<k-1<<endl;
			}
		}
	}
	printf("%lld\n",dp[n][n]*fac[n]%mod);
	return 0;
}

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

void solveC(){
  int n;
  cin >> n;
  int x[n],y[n],h[n];
  int xt,yt,ht;
  int flg=1;

  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]!=0 && flg) xt=x[i],yt=y[i],ht=h[i];
  }

  int cx,cy,ch;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      ch = ht + abs(xt-i) + abs(yt-j);
      for(int k=0;k<n;k++){
	if (max(ch-abs(x[k]-i)-abs(y[k]-j),0)==h[k]){
	  if (k==n-1){
	    cx = i;
	    cy = j;
	    i=100;
	    j=100;
	    break;
	  }
	}
	else break;
      }
    }
  }
  cout << cx << " " << cy << " " << ch << endl;  
}

int main(){
  solveC();
}


Measured memory_bytes: 256
n=int(input())
mention_list = {}

for i in range(n):
    a=int(input())
    xy_list = []
    for j in range(a):
        x, y =map(int,input().split())
        x=x-1
        xy_list.append([x,y])
    mention_list[i] = xy_list

max_count = 0
num = 2**n
flag = 0
for i in range(1,num):
    bina = bin(i)[2:].zfill(n)
    count = 0
    for x in range(n):
        j = int(bina[x])
        flag = 0
        if j == 1:
            for mention in mention_list[x]:
                if int(bina[mention[0]]) != int(mention[1]):
                    flag = -1
                    break
            if flag == -1:
                break
            count = count + 1
    if flag == -1:
        continue
    max_count = max(max_count, count )

print(max_count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

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

    vpll task(n);
    for (ll i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        pll p = make_pair(b, a);
        task[i] = p;
    }

    sort(task.begin(), task.end());

    string ans = "Yes";
    ll time = 0;
    for (ll i = 0; i < n; i++)
    {
        time += task[i].second;
        if (time > task[i].first)
        {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main()
{
    while(cin>>s)
    {
        ll sum=0;
        sum+=15-int(s.size());
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='o') sum++;
        }
        if(sum>=8) cout<<"YES\n";
        else cout<<"NO\n";
    }



}



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

int main(){
    int N = 136;
    cin >> N;
    string N_s = to_string(N);
    int count = 0;

    for(int i=1; i<=N; i++){
        string N_s = to_string(N);
        // cout << N_s.size() << endl;

        if(to_string(i).size()%2 == 1){
            count ++;        
        }
        else{

        }
    }   

    // if(N%2==1){
    //     count = count -1;
    // }

    cout << count<<endl;
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	int n,d;
	cin >> n >> d;
	cout << n/(d*2+1) + (n%(d*2+1) > 0 ? 1 : 0) << endl;
	return 0;
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	ll k;
	cin >> k;
	vi aux(10, INF);
	int r = k % 10;
	for (int i = 1;i < 10;i++) {
		int x = r * i % 10;
		aux[x] = min(aux[x], i);
	}
	ll ans = 0, sum = 0;
	do {
		int x = 7 - sum % 10;
		if (x < 0) x += 10;
		if (aux[x] == INF) {
			ans = -1;
			break;
		}
		else {
			sum += k * aux[x];
		}
		while (sum % 10 == 7) sum /= 10, ans++;
	} while (sum);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3644
import copy
def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
n,m,r=map(int,input().split())
R=list(map(int,input().split()))
for i in range(r):
  R[i]=R[i]-1
d=[[10**10]*n for i in range(n)] 
for i in range(m):
  a,b,c=map(int,input().split())
  a=a-1
  b=b-1
  d[a][b]=c
  d[b][a]=c
for i in range(n):
  d[i][i]=0
D=warshall_floyd(d)
s=1
S=[]
for i in range(1,r+1):
  s=s*i
  S.append(s)
ans=10**10
for i in range(s):
  RR=copy.copy(R)
  E=[]
  for j in range(r-1):
    E.append(RR[i//S[r-j-2]])
    RR.pop(i//S[r-j-2])
    i=i-S[r-j-2]*(i//S[r-j-2])
  E.append(RR[0]) 
  di=0
  for i in range(r-1):
    di=di+D[E[i]][E[i+1]]
  if di<ans:
    ans=di
print(ans)

Measured memory_bytes: 47848
from copy import deepcopy
H, W, K = map(int, input().split())
board = [[0]*W for _ in range(H+1)]
for i in range(1,H+1):
    board[i] = list(map(int, list(input())))
def drop(board_copy):
    change = True
    score = 0
    p = 0
    while change:
        change = False
        for i in range(2,H+1):
            ser = 1
            for j in range(W):
                if j==W-1:
                    if ser>=K:
                        score += 2**p*board_copy[i][-1]*ser
                        change = True
                        for k in range(i,0,-1):
                            board_copy[k][j-ser+1:] = board_copy[k-1][j-ser+1:]
                    continue
                if board_copy[i][j]>0 and board_copy[i][j]==board_copy[i][j+1]:
                    ser += 1
                else:
                    if ser>=K:
                        score += 2**p*board_copy[i][j]*ser
                        change = True
                        for k in range(i,0,-1):
                            board_copy[k][j-ser+1:j+1] = board_copy[k-1][j-ser+1:j+1]
                    ser = 1
        p += 1
    return score
ans = 0
for h in range(1,H+1):
    for w in range(W):
        board_copy = deepcopy(board)
        for k in range(h,0,-1):
            board_copy[k][w] = board[k-1][w]
        ans = max(ans,drop(board_copy))
print(ans)

Measured memory_bytes: 54620
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    S = input()
    ans = 0

    for i in range(N-2):
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n , k ,q;
  cin >> n >> k >> q;
  int a;
  vector<int> p(n,0); //自分が何回答えたか
  rep(i,q){
    cin >> a;
    a--;
    p[a]++;
  }
  rep(i,n){
    if(p[i] > q-k) printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
    
   
    int n;
    cin >> n;
    bool f = 0;
    while (n--) {

        int t;
        cin >> t;
        if (t % 2)continue;
        if (t % 3 && t % 5)f = 1;

    }
    if (f)cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;

    return 0;

}

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


int main(){
	
    int n,m;
	cin>>n>>m;
	vector<int> arr(m);
	for(int i=0;i<m;i++){
		cin>>arr[i];
	}
	long long suma = 0;
	for(int i=0;i<m;i++){
		suma += arr[i];
	}
	if(suma > n)
		cout<<-1<<endl;
	else
		cout<<n - suma<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

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

    ll mx = pow(2LL, m);
    if (k == 0)
    {
        for (ll i = 0; i < mx - 1; i++)
        {
            cout << i << " " << i << " ";
        }
        cout << mx - 1 << " " << mx - 1 << endl;
    }
    else
    {
        if (m == 0 || m == 1 || mx <= k)
        {
            cout << "-1" << endl;
        }
        else
        {
            for (ll i = 0; i < mx; i++)
            {
                if (i != k)
                {
                    cout << i << " ";
                }
            }
            cout << k << " ";
            for (ll i = mx - 1; i >= 0; i--)
            {
                if (i != k)
                {
                    cout << i << " ";
                }
            }
            cout << k << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll a, b, c, k;

    cin >> a >> b >> c >> k;
    
    ll ans = min(a, k);

    ll minus = max((ll)0, k-(a+b));

    ans -= minus;

    cout << ans << endl;


}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		
		if(N%2==1) {
			System.out.println(0);
			return;
		}
		
		//nの二重階乗を２で割ると、階乗になる。
		long M = N/2; //このとき、２でn回わってることに注意。２の数に追加する必要がある。
		//2の数（求める必要はないが、勉強のため）
		long num2 = N;
		while(M>0) {
			M /= 2;
			num2 += M; 
		}
		//5の数
		M = N/2;
		long num5 = 0;
		while(M>0) {
			M /= 5; // 5の次は25を調べるが、これはMを５で割っても同じことが調べられる。
			num5 += M;
		}
		long ans = Math.min(num2, num5);
		System.out.println(ans);
	}
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int x;
  cin >> x;

  while (1) {
    int rx = sqrt(x);
    bool ok = true;
    for (int i = 2; i < rx; ++i) {
      if (x % i == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << x << '\n';
      break;
    }
    ++x;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int S;
    scanf("%d", &S);
    int h, m, s;
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    scanf("%d %d %d", &h, &m, &s);
    printf("%d:%d:%d\n", h,m,s);
    return 0;
}


Measured memory_bytes: 2760
import itertools
n,m,q=map(int,input().split())

data=[]

for i in range(q):
    data.append(list(map(int,input().split())))

l=range(1,m+1)

#h = itertools.combinations_with_replacement(l, 2)
koho = list(itertools.combinations_with_replacement(l, n))

#print(len(koho))

ans=0

for k in koho:
    score=0
    for d in data:
        if(k[d[1]-1]-k[d[0]-1]==d[2]):
            score+=d[3]
    if(score>ans):
        ans=score

print(ans)

Measured memory_bytes: 21620
/*************************************
 * @contest:      AGC041.
 * @user_name:    hkxadpall.
 * @time:         2019-12-28.
 * @language:     C++.
 * @upload_place: AtCoder.
*************************************/ 

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

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

long long n, a, b;

int main()
{
    n = read<long long>();
    a = read<long long>();
    b = read<long long>();
    if (abs(a - b) % 2 == 0) printf("%lld", abs(a - b) / 2);
    else {
        long long ans = n;
        ans = min(ans, (a + b - 1) / 2); 
        ans = min(ans, ((n - a) + (n - b) + 1) / 2); 
        write(ans);
    }
    return 0;
}

Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import math
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	A, B, H, M = getlist()
	x0 = A * math.cos(math.radians(30 * H + M * 0.5))
	y0 = A * math.sin(math.radians(30 * H + M * 0.5))
	x1 = B * math.cos(math.radians(6 * M))
	y1 = B * math.sin(math.radians(6 * M))
	ans = ((x1 - x0) ** 2 + (y1 - y0) ** 2) ** 0.5
	print(ans)

	
if __name__ == '__main__':
	main()

Measured memory_bytes: 65684
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-9;

int main(){
	int n;

	while(~scanf("%d",&n)){
		if(n==0) break;

		vector<int> input;
		for(int i=1;i<=n-1;i++){
			input.push_back((i*i)%n);
		}

		int* table = new int[(n-1)/2+1]();
		//set<int> table;

		sort(input.begin(),input.end());

		vector<int>::iterator end_it = unique(input.begin(),input.end());
		input.erase(end_it,input.end());

		for(int i=0;i<input.size();i++){
			for(int j=0;j<input.size();j++){
				if(i==j) continue;
				int calc = input[i]-input[j] ;
				if(calc < 0) calc+=n;
				if(calc > (n-1)/2) calc = n - calc;

				//table.insert(calc);
				table[calc]++;
			}
		}

		for(int i=1;i<(n-1)/2+1;i++){
			printf("%d\n",table[i]);
		}

		delete[] table;
	}
}

Measured memory_bytes: 0
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
lis1 = deque(lis[:N//2+1])
lis2 = deque(lis[N//2+1:])
if M % 2 == 0:
    
    for i in range(M//2):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a,b)
else:
    for i in range(M//2+1):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a, b)



Measured memory_bytes: 90524
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=998244353;
int main(){
  ll N,S,dp[3020][3020];
  cin>>N>>S;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){cin>>A.at(i);}
  dp[0][0]=1;
  for(ll i=1;i<=N;i++){
    for(ll j=0;j<=S;j++){
      dp[i][j]=dp[i-1][j]*2%MOD;
      if(j-A.at(i-1)>=0){
        dp[i][j]+=dp[i-1][j-A.at(i-1)]%MOD;
      }
    }
  }
  cout<<dp[N][S]%MOD<<endl;
}

Measured memory_bytes: 74380
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

template<typename T>
struct Dinic{
    //適当にフローを流す
    //流した辺のcapを減らし，逆辺のcapをその分増やす
    //これを繰り返す
    //O(EV^2)，通常こんなにかからない

    const T TINF;

    struct edge{
        int to;
        //容量
        T cap;
        int rev;
        bool isrev;
        int idx;
    };

    vector<vector<edge>> g;
    vector<int> min_cost, iter;

    Dinic(int V):TINF(numeric_limits<T>::max()),g(V){}

    void add_edge(int from, int to, T cap, int idx=-1){
        g[from].push_back((edge){to,   cap, (int)g[to].size(),     false, idx});
        g[to].  push_back((edge){from, 0,   (int)g[from].size()-1, true,  idx});
    }

    bool bfs(int s, int t){
        min_cost.assign(g.size(), -1);
        queue<int> q;
        min_cost[s]=0;
        q.push(s);
        while(!q.empty() and min_cost[t]==-1){
            int p=q.front();q.pop();
            for(auto &e:g[p]){
                if(e.cap>0 and min_cost[e.to]==-1){
                    min_cost[e.to]=min_cost[p]+1;
                    q.push(e.to);
                }
            }
        }
        return min_cost[t]!=-1;
    }

    //dfsでtまでフローを流せるだけ流すdfs
    T dfs(int idx, const int t, T flow){
        if(idx==t) return flow;
        for(int &i=iter[idx];i<g[idx].size();i++){
            edge &e=g[idx][i];
            if(e.cap and min_cost[idx]<min_cost[e.to]){
                //今のポイントに流れてきた分を次の点に流せるだけ流す
                T d=dfs(e.to, t, min(flow,e.cap));
                if(d>0){
                    //流せるならcapの量を減らし，逆辺のcapを増やす
                    e.cap-=d;
                    g[e.to][e.rev].cap+=d;
                    //どこか1つ見つければいいのでd>0で
                    //dが見つかれば即リターン
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(int s,int t){
        T flow=0;
        while(bfs(s,t)){
            iter.assign(g.size(),0);
            T f=0;
            while((f=dfs(s,t,INF))>0) flow+=f;
        }
        return flow;
    }

};


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

    int n,m;cin>>n>>m;
    Dinic<int> g(n);
    rep(i,m){
        int u,v,c;cin>>u>>v>>c;
        g.add_edge(u,v,c);
    }
    cout<<(g.max_flow(0,n-1))<<endl;
    return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = c-a;
  int y = d-b;
  rep(i,x){ cout << 'R'; }
  rep(i,y){ cout << 'U'; }
  rep(i,x){ cout << 'L'; }
  rep(i,y){ cout << 'D'; }
  cout << 'D';
  rep(i,x+1){ cout << 'R'; }
  rep(i,y+1){ cout << 'U'; }
  cout << 'L';
  cout << 'U';
  rep(i,x+1){ cout << 'L'; }
  rep(i,y+1){ cout << 'D'; }
  cout << 'R';
  cout << ln;
  return 0;
}

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

using namespace std;

int m, d;
int ans = 0;

int main () {
  scanf ("%d %d", &m, &d);
  for (int i = 2; i <= d; i++) {
    int x = i%10;
    int y = (i/10)%10;
    if (x < 2 || y < 2) continue;
    if (x*y <= m) ans++;
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
  ans = 0
  N = int(input())
  C = list(map(int, input().split()))
  C.sort()
  mod = 10**9+7
  for i in range(N):
    ans += C[i]*(N+1-i)
    ans %= mod
  ans = ans*pow(2,2*N-2,mod)%mod
  return ans
print(solve())

Measured memory_bytes: 31748
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] dw = input.Split(' ');

            int area = Int32.Parse(dw[0]) * Int32.Parse(dw[1]);
            int length = (Int32.Parse(dw[0]) + Int32.Parse(dw[1])) * 2;

            Console.WriteLine("{0} {1}", area, length);
        }
    }
}



Measured memory_bytes: 9120
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {

    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: u64,
    }
    let mut ans:u64 = 0;
    fn g(n:u64, x:u64)->u64{
        let y = n/x;
        return y*(y+1)*x/2;
    }
    for i in 1..n+1{
        ans += g(n ,i);
    }
    println!("{}", ans)
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;




int main(){
    
    string s;
    cin >> s;
    int count;
    if(s[0]!='C')
        count++;
    if(s[1]!='O')
        count++;
    if(s[2]!='D')
        count++;
    if(s[3]!='E')
        count++;
    if(s[4]!='F')
        count++;
    if(s[5]!='E')
        count++;
    if(s[6]!='S')
        count++;
    if(s[7]!='T')
        count++;
    if(s[8]!='I')
        count++;
    if(s[9]!='V')
        count++;
    if(s[10]!='A')
        count++;
    if(s[11]!='L')
        count++;
    if(s[12]!='2')
        count++;
    if(s[13]!='0')
        count++;
    if(s[14]!='1')
        count++;
    if(s[15]!='6')
        count++;
    cout<<count<<endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;

//コピペ用
//		int[] ab = Array.ConvertAll(Console.ReadLine().Split(' '),i=>int.Parse(i));
//      int a = int.Parse(Console.ReadLine());


class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
        int[] kx = Array.ConvertAll(Console.ReadLine().Split(' '),i=>int.Parse(i));
        int k=kx[0];
        int x=kx[1];

        int min,max;
        min = x-k+1;
        max = x+k-1;

        string s = "";
        for(int i=min;i<=max;i++){
            s += i + " ";
        }
        Console.WriteLine(s.Trim());
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG 

int main(){
    string S;
    cin>>S;
    int number[4];
    rep(i,4){
        number[i]=S[i]-'0';
    }
    char puramai[3];

    for(int bit=0; bit<(1<<3);bit++){
        int sum=number[0];
        rep(i,3){
            if(bit&(1<<i)){
                sum+=number[i+1];
            }
            else sum-=number[i+1];
        }
        if(sum==7){
            rep(i,3){
                if(bit&(1<<i)) puramai[i]='+';
                else puramai[i]='-';
            }
        }
    }

    cout<<number[0]<<puramai[0]<<number[1]<<puramai[1]<<number[2]<<puramai[2]<<number[3]<<"=7"<<endl;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i*i <= n; ++i) {
    if (n%i != 0) continue;
    ll j = n/i;
    ans = min(ans, i+j-2);
  }
  cout << ans << endl;
  return 0;
}



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

void zeta_transform(int N, vector<pair<int, int>> &f){
    for(int i=0; i<N; i++)
        for(int j=0; j<(1<<N); j++)
            if(j&(1<<i)){
                vector<int> hoge = {f[j].first, f[j].second, f[j^(1<<i)].first, f[j^(1<<i)].second};
                sort(hoge.begin(), hoge.end());
                f[j].first = hoge[3];
                f[j].second = hoge[2];
            }
}

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

    vector<pair<int, int>> B(M);
    for(int i=0; i<M; i++)
        B[i].first = A[i];

    zeta_transform(N, B);

    vector<int> C(M);
    for(int i=1; i<M; i++)
        C[i] = B[i].first + B[i].second;

    for(int i=1; i<M; i++)
        C[i] = max(C[i], C[i-1]);
    for(int i=1; i<M; i++)
        cout << C[i] << endl;

    return 0;
}


Measured memory_bytes: 7168
//
// ABC070B
// URL : https://atcoder.jp/contests/abc070/tasks/abc070_b
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoder
{
    class ABC070B
    {
        static void Main(string[] args)
        {
            preprocess();
            // 整数配列の入力
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long ans = Count(inputLongArray[0], inputLongArray[1], inputLongArray[2], inputLongArray[3]);
            Console.WriteLine(ans.ToString());
            Console.Out.Flush();
        }

        static long Count(long A_In, long A_Out, long B_In, long B_Out)
        {
            if (A_Out <= B_In) {
                return 0;
            }
            if(B_Out <= A_In)
            {
                return 0;
            }
            long countStart = (A_In < B_In) ? B_In : A_In;
            long countEnd = (A_Out < B_Out) ? A_Out : B_Out;
            return countEnd - countStart;            
        }

        //---------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        public static void preprocess()
        {
            //出力高速化
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        }


        /// <summary>
        /// 与えられた数が素数かどうかを計算する
        /// </summary>
        /// <param name="num">対象数</param>
        /// <returns>true:素数, false:素数ではない(合成数)</returns>
        public static bool isPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 順列mPnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Permutation(long m, long n)
        {
            long ret = 1;
            for(var i = 0; i < n; ++i)
            {
                ret *= m - i;
            }
            return ret;
        }
        /// <summary>
        /// 組み合わせmCnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Combination(long m, long n)
        {
            if(m == n || n == 0)
            {
                return 1;
            }
            long ans = 1;
            for(var i = 0; i <= n; ++i)
            {
                ans *= (m - i + 1) / i;
            }
            return ans;
        }
    }
}



Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
int INF=1000000007;
using ll=long long;

int main(){
	const int max_M=41,max_cM=401;
	int n,ma,mb;
	int a[max_M],b[max_M],c[max_M];
	cin>>n>>ma>>mb;
	rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
	//dp[i][j][k]: i番目を選んだ時ma=j,mb=k;
	int dp[max_M][max_cM][max_cM];
	rep(i,0,n+1)rep(j,0,max_cM)rep(k,0,max_cM)dp[i][j][k]=INF;
	dp[0][0][0]=0;
	rep(i,0,n){
		rep(j,0,max_cM){
			rep(k,0,max_cM){
				if(dp[i][j][k]==INF)continue;
				//i+1番目を選ばない.
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				//i+1番目を選ぶ.
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}
	int ans=INF;
	rep(j,1,max_cM){
		rep(k,1,max_cM){
			//Ma:Mb=j:kとなっているときans候補.
			if(ma*k==mb*j)
				ans=min(ans,dp[n][j][k]);
		}
	}
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}
	

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

const int N = 100005;

int x, y, a, b, c;
long long aa[N];
long long bb[N];
long long cc[N];

int solve() {
  scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);
  for (int i = 1; i <= a; ++i) scanf("%lld", &aa[i]);
  for (int i = 1; i <= b; ++i) scanf("%lld", &bb[i]);
  for (int i = 1; i <= c; ++i) scanf("%lld", &cc[i]);

  ++a, ++b, ++c;
  sort(aa + 1, aa + a, greater<long long>());
  sort(bb + 1, bb + b, greater<long long>());
  sort(cc + 1, cc + c, greater<long long>());

  for (int i = 1; i < a; ++i) aa[i] += aa[i-1];
  for (int i = 1; i < b; ++i) bb[i] += bb[i-1];
  for (int i = 1; i < c; ++i) cc[i] += cc[i-1];

  int ptrB = 0;
  int ptrC = x + y;
  long long ans = 0;
  for (int i = 0; i <= x; ++i) {
    if (x-i > c) {
      --ptrC;
      continue;
    }

    while (ptrC >= c || (ptrC > x-i && ptrB < b-1 && bb[ptrB+1] + cc[ptrC-1] > bb[ptrB] + cc[ptrC])) {
      ++ptrB;
      --ptrC;
    }

    while (ptrC < x-i || (ptrB > 0 && ptrC < c-1 && bb[ptrB-1] + cc[ptrC+1] > bb[ptrB] + cc[ptrC])) {
      --ptrB;
      ++ptrC;
    }

    // c./err << i << " " << ptrB << " " << ptrC << " " << aa[i] << " " << bb[ptrB] << " " << cc[ptrC] <<  endl;
    ans = max(ans, aa[i] + bb[ptrB] + cc[ptrC]);
    --ptrC;
  }
  printf("%lld\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 2560
n=int(input())
listb = [int(i) for i in input().split()]
ans=0
for i in range(n):
    if i==0:
        ans=ans+listb[0]
    if (i!=0) & (i!=n-1):
        ans=ans+min(listb[i-1],listb[i])
    if i==n-1:
        ans=ans+listb[i-1]
print(ans)

Measured memory_bytes: 38460
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,c=0,d=0,x,i;
  int *b;
  scanf("%d",&a);
  b=(int *)malloc(sizeof(int) * a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  while(c<a-1){
    for(i=a-1;i>0;i--){
      if(b[i]<b[i-1]){x=b[i];b[i]=b[i-1];b[i-1]=x;d++;}
    }
  c++;
  }
  for(i=0;i<a;i++){
  printf("%d",b[i]);
  if(i!=a-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",d);
  return 0;
}



Measured memory_bytes: 2760
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  x = int(input())
  prime = [True]*(x*2)
  prime[0] = False
  prime[1] = False
  for i in range(2, x):
    if prime[i]==True:
      baisu = i + i
      while baisu<2*x:
        prime[baisu]=False
        baisu += i
  for i in range(x,2*x):
    if prime[i]==True:
      print(i)
      break
  
  
if __name__ == '__main__':
  main()

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    ll stock = 0, money = 1000;
    vector<ll> s(n, 0);
    rep(i, n-1){
        if (s[i] == 0) {
            if (a[i] < a[i+1]) s[i+1]++;
        }
        else {
            if (a[i] <= a[i+1]) s[i+1]++;
        }
    }

    rep(i, n-1){
        if(s[i] == 0 && s[i+1] == 1){
            stock += money / a[i];
            money -= a[i] * stock;
        }
        else if (s[i] == 1 && s[i+1] == 0){
            money += a[i] * stock;
            stock = 0;
        }
    }
    money += stock * a[n-1];
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3624
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a, b = [0], [0]
a.extend(list(map(int, input().split())))
b.extend(list(map(int, input().split())))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

Measured memory_bytes: 40312
# coding=utf-8


get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


# N = 3
# A = [[1, 1], [5, 1], [5, 5]]

# N = 2
# A = [[10, 20], [20, 20]]

N = get()
A = getss(N)
UF = {}


def find(x):
    if x != UF[x]:
        UF[x] = find(UF[x])
    return UF[x]


def union(x, y):
    UF.setdefault(x, x)
    UF.setdefault(y, y)
    UF[find(x)] = find(y)


for i, j in A:
    union(i, -j)


count = {}
for x in UF:
    root = find(x)
    if root not in count:
        count[root] = [0, 0]
    if x > 0:
        count[root][0] += 1
    else:
        count[root][1] += 1

res = 0
for x in count:
    pos, neg = count[x]
    if pos > 1 and neg > 1:
        res += pos * neg
    else:
        res += max(pos, neg)
print res - N


Measured memory_bytes: 28604
N = gets.strip.to_i
s = gets.strip.split.map(&:to_i)

hs = Array.new(2) { Hash.new(0) }
hs[0][0] = 0
hs[1][0] = 0

s.each_with_index { |n, i| hs[i%2][n] += 1 }

e = hs[0].sort_by { |_, v| -v }
o = hs[1].sort_by { |_, v| -v }

if e[0][0] != o[0][0]
  n = e[0][1] + o[0][1]
else
  n = [e[0][1] + o[1][1], e[1][1] + o[0][1]].max
end
puts N - n


Measured memory_bytes: 21488
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int a[3];
  for(int i=0;i<3;++i) cin >> a[i];
  sort(a,a+3);
  cout << (a[2] - a[1]) + (a[1] - a[0]) << endl; 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b;
	char op[2];

	scanf("%d%s%d", &a, op, &b);
    
	if(op[0] == '+')
		printf("%d", a+b);
	else if(op[0] == '-')
		printf("%d", a-b);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>

int main()
{
  long long n, a, b, c, d;
  scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
  for (long long i = 0; i <= n - 1; ++i)
  {
    long long s = a + i * c;
    long long t = a + i * d;
    long long v = b + (n - 1 - i) * c;
    long long w = b + (n - 1 - i) * d;
    if (w < s || v > t) continue;
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 128