akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
#include <complex>

using namespace std;

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)


// àÏ (dot product) : a&#8901;b = |a||b|cosÆ
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
// 2¼üÌ¼ð»è : aÛb <=> dot(a, b) = 0
int is_orthogonal (P a, P b) {
  return EQ( dot(a, b), 0.0 );
}

int main()
{
//	cut here before submit 
//	freopen("testcase.orthognal", "r", stdin);
	string str = "";
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		double xa, ya, xb, yb, xc, yc, xd, yd;
		stringstream ss(str);
		ss >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd;

		P A(xa, ya), B(xb, yb), C(xc, yc), D(xd, yd);
		P Vab = B - A, Vcd = D - C;
			
		if (is_orthogonal (Vab, Vcd ) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		} // end if	
	} // end loop

//	cout << res << endl;	
		
	return 0;
}

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

int main(){
    long long N,a,b;
    long long sum=0,minB=1000000001;
    bool same=true;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a >> b;
        sum+=a;
        if(a!=b)
        same=false;
        if(a>b && minB>b)
        minB=b;
    }
    if(same==true)
    cout << 0 << endl;
    else
    cout << sum-minB << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int N, A, index, ans = 0;
	scanf("%d", &N);
	for(index = 0;  index < N; index++)
	{
		scanf("%d", &A);
		if(A % 2 == 1)
			ans++;
		if(++index >= N)
			break;
		scanf("%d", &A);
	}
	printf("%d\n", ans);
	return 0;
}

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

template <typename Tp>
class fenwick{
    std::vector<Tp> tree;
    std::size_t n;

public:
    fenwick(size_t _n) : n(_n) {
        tree.resize(n);
    }

    void add(size_t pos, Tp val){
        while(pos < n) {
            tree[pos] += val;
            pos |= (pos + 1);
        }
    }

    Tp get(size_t pos) {
        Tp v{};
        do{
            v += tree[pos];
            pos &= pos + 1;
        }while(pos-- > 0);

        return v;
    }

    Tp get(size_t left, size_t right){
        if(left == right) return {};
        else if(left == 0) return get(right - 1);
        else return get(right - 1) - get(left - 1);
    }

    Tp operator[](size_t pos){
        if(pos == 0) return get(pos);
        else return get(pos) - get(pos-1);
    }

    void modify(size_t pos, Tp val){
        Tp diff = val - this->operator[](pos);
        this->add(pos, diff);
    }
};

int64_t inv(int* begin, size_t n){
    set<int> s;
    for(int i=0;i<n;++i) s.insert(*(begin+i));
    map<int,int> mp;
    int ord = 0;
    for(int v: s){
        mp[v] = ord;
        ++ord;
    }
    vector<int> x(n), tp(n);
    for(int i=0;i<n;++i) x[i] = mp[*(begin+i)];
    
    fenwick<int> fw(n);
    int64_t r = 0;
    for(int i=0;i<n;++i){
        tp[i] = fw.get(0, x[i]+1);
        fw.add(x[i], 1);
        r += i - tp[i];
    }
    return r;
}

int main(){
    int64_t n;
    int a[100000], v[100000], s[100001];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
        v[i] = a[i];
    }
    sort(v, v+n);
    int l=0, r=n;
    while(r-l > 1){
        int m = (l+r)/2;
        s[0] = 0;
        for(int i=0;i<n;++i){
            s[i+1] = s[i] + (a[i] < v[m] ? -1: 1);
        }
        int64_t iv = inv(s, n+1);
        if((n+1)*n/2 - iv >= (n+1)*n/4) l = m;
        else r = m;
    }
    cout << v[l] << endl;
    
    return 0;
}

Measured memory_bytes: 12016
def main():
    A, B, K = map(int, input().split())
    if B - A + 1 <= 2 * K:
        for i in range(A, B+1):
            print(i)
    else:
        for i in range(K):
            print(A+i)
        for i in range(K):
            print(B-K+1+i)


if __name__ == "__main__":
    main()


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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 */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((c > b) || (a > d))
    {
        cout << 0 << endl;
    }
    else
    {
        cout << min(b, d) - max(a, c) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) 
  {
    cin >> s.at(i);
  }
  
  cin >> M;
  vector<string> t(M);
  for (int l = 0; l < M; l++) 
  {
    cin >> t.at(l);
  }
  vector<int> answer(N);
  
  for (int i = 0; i < N; i++) 
  {
    for (int j = 0; j < N; j++) {
      if (s.at(i)==s.at(j))
      {
        answer.at(i)++;
      }
    }
    for (int k = 0; k < M; k++) {
      if (s.at(i)==t.at(k))
      {
        answer.at(i)--;
      }
    }
  }  
  
  int Max = 0;
  
  for (int i = 0; i < N; i++) 
  {
    for (int j = i+1; j < N; j++) 
    {
      if(answer.at(j)>Max){
        Max=answer.at(j);
      }
    }
    
  }
  if(Max<0)
  {
    Max=0;
    cout << Max << endl;
  }
  else
  {
  cout << Max << endl;
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
#include <functional>


using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to, cost;
	edge (int _from, int _to, int _cost){
		from = _from; to = _to; cost = _cost;
	}
};
 
int V,E;
vector<edge> es;


int d[105][105];
int n,m;

int main(){
	cin >> n >> m;
	int a, b, c;
	rep(i, n) {
		rep(j, n) {
			d[i][j] = INF;
		}
	}
	rep(i, n) {
		d[i][i] = 0;
	}
	rep(i, m) {
		cin >> a >> b >> c;
		a--; b--;
		es.push_back(edge(a, b, c));
		d[a][b] = d[b][a] = c;
	}
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				d[i][j] = min(d[i][j],(d[i][k] + d[k][j]));
			}
		}
	}
	int ans = 0;
	rep(i, m) {
		a = es[i].from;
		b = es[i].to;
		if (es[i].cost > d[a][b])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[50],b[50],c[50],d[50];
    int s;
    int x;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    for(int i=0;i<m;i++)cin>>c[i]>>d[i];
    for(int i=0;i<n;i++){
        s=1000000000;
        for(int j=0;j<m;j++){
            if(s>abs(a[i]-c[j])+abs(b[i]-d[j])){
                s=abs(a[i]-c[j])+abs(b[i]-d[j]);
                x=j+1;
            }
        }
        cout<<x<<endl;
    }
    return 0;
}

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

int main( void )
{
    int a,b,x;
    cin >> a >> b >> x;
    
    if ( a + b >= x && a <= x )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	double a,b,c,d,e,f;
	double x,y;

	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) !=EOF)
	{
		y=(d*c-a*f)/(d*b-a*e);
		x=(c-b*y)/a;

		printf("%.3lf %.3lf\n",x,y);
	}

	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
  cin>>a>>b;
	if(a==b)
	{
		for(int i=1;i<=a;i++)
		{
			cout<<a;
		}
	}
	else if(a>b)
	{
		for(int i=1;i<=a;i++)
		{
			cout<<b;
		}
	}
	else
	{
		for(int i=1;i<=b;i++)
		{
			cout<<a;
		}
	}
	return 0;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define em emplace
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1<<30;
constexpr ll LINF = 1LL<<58;
constexpr int mod = 1000000007;

vector<ll> dp(101010);

int main(){
    int n, w;
    cin >> n >> w;
    ll W[110], V[110];
    for (int i = 0; i < n; i++) cin >> W[i] >> V[i];
    for (int i = 0; i < n; i++) {
        for (int j = w; j >= 0 ; j--) {
            if(j - W[i] >= 0) chmax(dp[j], dp[j - W[i]] + V[i]);
        }
    }
    cout << *max_element(all(dp)) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
ll X, Y;
ll dpx[1234566], dpy[1234567];

// Combination
const ll COMB_MAX = 1e6;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < COMB_MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> X >> Y;
    if ((X + Y) % 3 == 0) {
        ll n = (2 * Y - X) / 3;
        ll m = (2 * X - Y) / 3;
        if (n < 0 || m < 0) {
            cout << 0 << endl;
            return 0;
        } else {
            COMinit();
            cout << COM(n + m, n) << endl;
        }
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 24832
from collections import deque
from itertools import chain

INF = 10**18

H, W = map(int, input().split())
S = [input() for _ in range(H)]

def check_max_route(sx, sy):
    r = [[INF for _ in range(W)] for _ in range(H)]
    r[sy][sx] = 0
    q = deque([(sx, sy)])
    while q:
        tx, ty = q.popleft()
        tr = r[ty][tx]

        for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
            x, y = tx+dx, ty+dy
            if not (0 <= x < W and 0 <= y < H):
                continue
            if S[y][x] == "#":
                continue
            if r[y][x] <= tr+1:
                continue
            r[y][x] = tr+1
            q.append((x, y))
    
    m = max([x for x in chain(*r) if x != INF])
    return m

max_num = 0
for sy in range(H):
    for sx in range(W):
        if S[sy][sx] == "#":
            continue
        m = check_max_route(sx, sy)
        max_num = max(max_num, m)

print(max_num)

Measured memory_bytes: 3316
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        sc.close();
        if(a < c){
            c -= a;
            a = 0;
            if(b < c){
                b = 0;
            }else{
                b -= c;
            }
        }else{
            a -= c;
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 38876
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,0,N) cin >> A[i];

    vector<bool> buy(N, false), sell(N, false);
    bool first = true;
    bool rise = false;
    rep(i,1,N) {
        if (A[i] > A[i-1]) {
            if (first) {
                first = false;
                buy[i-1] = true;
            } else {
                if (!rise) {
                    buy[i-1] = true;
                }
            }
            rise = true;
        } else if (A[i] < A[i-1]) {
            if (first) {
                first = false;
                sell[i-1] = true;
            } else {
                if (rise) {
                    sell[i-1] = true;
                }
            }
            rise = false;
        }
    }
/*
    for (auto v : buy) cout << (int)v << " ";
    cout << endl;
    for (auto v : sell) cout << (int)v << " ";
    cout << endl;
*/
    ll money = 1000;
    ll stock = 0;
    int buy_A = 0;
    rep(i,0,N) {
        if (buy[i]) {
            buy_A = A[i];
            stock = money / A[i];
            money %= A[i];
        } else if (sell[i]) {
            money += stock * A[i];
            stock = 0;
        }
    }
    money += stock * max(buy_A,A[N-1]);

    cout << money << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int length, n;
vector<int> a;
map<pair<int,int>, double> memo;

double dist(int i, int j) {
    return sqrt(4 * a[i] * a[j]);
}

double f(int p, int prev) {
    if (__builtin_popcount(p) == 0) {
        return a[prev];
    }
    if (memo.count(make_pair(p, prev))) return memo[make_pair(p, prev)];
    double ret = 1e+300;
    for (int i = 0; i < n; ++ i) if ((p>>i)&1) {
        if (prev == -1) {
            ret = min(ret, f(p&~(1<<i), i) + a[i]);
        } else {
            ret = min(ret, f(p&~(1<<i), i) + dist(prev, i));
        }
    }
    return memo[make_pair(p, prev)] = ret;
}

bool solve() {
    n = a.size();
    if (n == 0) return true;
    if (n == 1) return 2 * a[0] <= length;
    double len = f((1<<n)-1, -1);
    return len <= length + 1e-9;
}

int main() {
    string buf;
    while (getline(cin, buf)) {
        istringstream in(buf);
        in >> length;
        a.clear();
        memo.clear();
        for (int x; in >> x; ) a.push_back(x);
        cout << (solve() ? "OK" : "NA") << endl;
    }
}


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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    ll f = a - k;
    if(f == 0){
        cout << "0" << " " << b << endl;
        return 0;
    }
    else if(f < 0){
        ll g = b + f;
        if(g>=0){
            cout << "0" << " " << g << endl;
            return 0;
        }
        else{
            cout << "0" << " " <<"0" << endl;
            return 0;
        }
        
    }
    else if(f > 0){
        cout << f << " " << b << endl;
        return 0;
    }

  
    
    return 0;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool num[1000010] = {};

int main()
{
    int s;
    ci >> s;
    
    int i = 1;
    int bef = s;
    num[bef] = true;
    while(1) {

	i++;
	
	if(bef % 2 == 0) bef /= 2;
	else bef = bef * 3 + 1;

	if(num[bef]) {
	    co << i << en;
	    return 0;
	}
	num[bef] = true;
	
    }
  
    return 0;
}




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

n = inp()
a = [inp() for _ in range(n)]
res = 0
for i,x in enumerate(a):
    res += x//2
    if x%2:
        if i == n-1 or a[i+1] == 0: continue
        a[i+1] -= 1
        res += 1
print(res)

Measured memory_bytes: 82744
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>
#include <random>

using namespace std;

int main() {
    string ball1, ball2, check;
    int b1 = 0;
    int b2 = 0;
    cin >> ball1 >> ball2;
    cin >> b1 >> b2 >> check;

    if (check == ball1) {
        b1--;
    }
    else {
        b2--;
    }

    cout << b1 << " " << b2;
}   


Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int a, b, c, d;
    scan(a, b, c, d);

    auto on = new int[](200);

    foreach (i ; a .. b) {
        on[i]++;
    }

    foreach (i ; c .. d) {
        on[i]++;
    }

    writeln(on.count!"a == 2");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main() {
  long long ans=0,w=0;
  //cin>>N;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='W'){
      w++;
      ans+=i;
      //cout<<
    }
  }
  cout<<ans-(w-1)*w/2;
  
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
//string b="12345";
//a = int(b[4]-48);
using namespace std;
int main()
{
	long long N, K, T = 0;
	vector<long long> H;

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		long long t;
		cin >> t;
		H.push_back(t);
	}
	sort(H.begin(), H.end());
	for (int i = 0; i < N-K; i++) {
		T = T + H[i];
	}
	cout << T << endl;
}

Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		long A = long.Parse(str[1]);
		long B = long.Parse(str[2]);
		long[]P = new long[N];
		long[]P1 = new long[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			P[i] = long.Parse(str2[i]);
			P1[P[i]-1] = i;
		}
		long[,]D = new long[N+1,N*2+1];
		for(var i=1;i<=N;i++){
			long min = D[i-1,0];
			D[i,0] = D[i-1,0]+B;
			for(var j=1;j<N*2+1;j++){
				min = Math.Min(min,D[i-1,j]);
				if(j==P1[i-1]*2+1){
					D[i,j] = min;
				} else if(j%2==1){
					D[i,j] = 99999999999999999;
				} else if(j<P1[i-1]*2+1){
					D[i,j] = min+B;
				} else {
					D[i,j] = min+A;
				}
			}
		}
		long ans = 99999999999999999;
		for(var j=0;j<N*2+1;j++){
			ans = Math.Min(ans,D[N,j]);
		}
		Console.WriteLine(ans);
	}
}

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

a,b,c = I()
if a-b <= c:
    print(c-(a-b))
else:
    print(0)


Measured memory_bytes: 10452
using System;

namespace Duplex_Printing
{
    class Program
    {
        static void Main(string[] args)
        {
            var numberPages = int.Parse(Console.ReadLine());

            double rawPages = (numberPages / 2);

            if(numberPages % 2 != 0)
            {
                rawPages = rawPages + 1;
            }

            int numberSheets = int.Parse(rawPages.ToString());            
            Console.WriteLine(numberSheets);
        }
    }
}


Measured memory_bytes: 11092
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)
#define cio ios::sync_with_stdio(false);

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    printf("%d %d %d\n",z,x,y);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
    cin >> N;
    if(N%1111 == 0){
    	cout << "Yes" << endl;
    }
    else if((N/10)%111==0){
    	cout << "Yes" << endl;
    }
    else if((N%1000)%111==0){
    	cout << "Yes" << endl;
    }
    else{
    	cout << "No" << endl;
    }
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define MOD 1000000007

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

    int n,m,x;
    cin>>n>>m>>x;
    
    int a[n][m];
    int c[n];
    for(int i = 0; i<n; i++){
        cin>>c[i];
        for(int j = 0; j<m; j++){
            cin>>a[i][j];
        }
    }
    int ans = INT_MAX;
    
    for(int mask = 1; mask<(1<<n); mask++){
        int sum = 0;
        vector<int> l(m,0);
        for(int i = 0; i<n; i++){
            if(mask & (1 << i)){
                sum+=c[i];
                for(int j = 0; j<m; j++){
                    l[j] += a[i][j];
                }
            }
        }
        bool f =1;
        for(int i = 0; i<m; i++){
            if(l[i] < x){
                f=0;
                break;
            }
        }
        if(f){
            ans = min(ans,sum);
        }
    }
    if(ans == INT_MAX){
        cout<<"-1\n";
    }else{
        cout<<ans<<"\n";
    }
    
    
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdlib>
#define llint long long

using namespace std;

llint n;
llint a[200005], sum[200005];;


int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	
	llint ans = 1e18;
	for(int i = 1; i < n; i++){
		llint l = sum[i];
		llint r = sum[n]-sum[i];
		ans = min(ans, abs(l-r));
	}
	cout << ans << endl;
	
	return 0;
}

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

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

    int tmp = b;
    while (tmp) {
        tmp /= 10;
        a *= 10;
    }

    int sum = a + b;
    bool r = false;
    for (int i = 1; i <= sqrt(100100); i++) {
        if (i * i == sum) r = true;
    }

    if (r) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+10;
int a[N],b[N],c[N],d[N],f[N],n;
map<int,int> t;
int get(int x)
{
	if (f[x]==x) return x;
	return f[x]=get(f[x]);
}
int main()
{
	scanf("%d",&n);
	int x=0;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=1;i<=n;i++)x=x^a[i];
	a[n+1]=x;
	int y=0;
	for (int i=1;i<=n;i++) y=y^b[i];
	b[n+1]=y;
	for (int i=1;i<=n+1;i++)
	{
		c[i]=a[i];
		d[i]=b[i];
	}
	n++;
	sort(c+1,c+n+1);
	sort(d+1,d+n+1);
	for (int i=1;i<=n+1;i++)
	{
		if (c[i]!=d[i]) 
		{
			if (i<=n) 
			{
				puts("-1");
				return 0;
			}
			break;
		}
	}
	int ans=0,num=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]!=b[i]||i==n)
		{
			if (i<n) ans++;
			if (!t[a[i]]) num++,t[a[i]]=num;
			if (!t[b[i]]) num++,t[b[i]]=num;
		}
	}
	if (ans==0)
	{
		puts("0");
		return 0;
	}
	for (int i=1;i<=num;i++) f[i]=i;
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) f[get(t[a[i]])]=get(t[b[i]]);
	for (int i=1;i<=num;i++) if (f[i]==i) ans++;
	printf("%d\n",ans-1); 
} 

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

int BS(int a[],int n){
    int ans = 0;
    bool flag = 1;
    for(int i =0;flag;i++){
        flag = 0;
        for(int j =n-1;j>= i+1;j--){
            if(a[j]<a[j-1]){
                int k = a[j];
                a[j] = a[j-1];
                a[j-1] = k;
                flag=1;
                ans++;
            }
        }
    }
    return ans;
}

int main(){
    int n;
    int aa[100];
    cin >> n;
    for(int i = 0;i<n;i++){
        int v;
        cin >> v;
        aa[i] = v;
    }
    int ans = BS(aa,n);
    for(int h =0;h<n;h++){
        if(h != n-1){
            cout << aa[h] << ' ';
        }else{
            cout << aa[h] << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3120
#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;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	
	vector<bool> dp(k+1,false);
	
	for(int i = a[0]; i < dp.size(); i++){
		rep(j,a.size()){
			if(i - a[j] >= 0 && dp[ i - a[j] ] == false){
				dp[i] = true;
				break;
			}
		}
	}
	
	printf("%s", dp[k]==true? "First":"Second");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		String s;
		
		int left = 0;
		int right;
		int min = (int) (3 * Math.pow(10, 5));
		
		n = sc.nextInt();
		s = sc.next();
		
		right = s.replaceAll("W", "").length();
		
		char [] sarray = s.toCharArray();
		
		for(int i = 0; i < n ; i++){
			
			if(sarray[i] == 'E')
				right--;
			
			min = Math.min(min, left + right);
			
			if(sarray[i] == 'W')
				left++;
			
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 45280
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
#define MV 100000
#define INF 1e15
struct edge{long long to,cost; };
vector <edge> G[MV];
 
long long V,E;
long long d[MV+1];//最短径路を格納
int R;
bool bellmanford(int s){
  fill(d,d+MV,INF);
  d[s] = 0;
  long long c = 0;
  bool upd = false;
  while(true){
    R = d[V-1];
    upd = false;
    for(int i = 0;i < V;i++){
      for(int j = 0;j < G[i].size();j++){
	edge e = G[i][j];
	if(d[i] !=INF && d[e.to] > d[i] + e.cost){
	  d[e.to] = d[i] + e.cost;
	  upd = true;
	}
      }
    }
    //cout << upd << endl;
    if(!upd)
      break;
    
    if(c == V-1 && R != d[V-1]){
      return true;//負の閉路の判定
    }
    else if(c == V-1 && R == d[V-1]){
      return false;
    }
    c++;
  }
  return false;
}
 
int main(){
  d[MV] = INF;
  int first;
  bool flag;
  cin >> V >> E;
  
  for(int i = 0;i < E;i++){
    long long f,t;
    edge e;
    cin >> f >> e.to >> e.cost;
    e.to--;
    f--;
    e.cost *= -1;
    G[f].push_back(e);
    /*
      G[f]にはfからでてる辺が格納されている。
     */
    t = e.to;
    
    //e.to = f;
    //G[t].push_back(e);
  }
 
  edge t;
  
  flag = bellmanford(0);
  if(flag == true)
    cout << "inf" << endl;
  else{
    
      
      
      cout << -1*d[V-1] << endl;
      
    
  }
  
}


Measured memory_bytes: 3456
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;ll h;
	cin>>h;
	ll num = 1;
	ll ans = 0;
	while(h > 0){
		ans += num;
		num*=2;
		h /= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,cnt,num1,num2,num3;
  scanf("%d",&cnt);
  for(i=0; i<cnt; i++){
    scanf("%d %d %d",&num1,&num2,&num3);
    if(((num1*num1)==((num2*num2)+(num3*num3))) || ((num2*num2)==((num1*num1)+(num3*num3))) || ((num3*num3)==((num1*num1)+(num2*num2)))){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    N = int(input())
    #Xs = list(map(int, input().split()))

    if N % 2 == 1:
        N += 1
    print(N // 2)


if __name__ == '__main__':
    main()


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

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

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

  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" <<  endl;
  }
  return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;

int main() {
	string a;
	cin >> a;
	map<string, string> b;
	b["A"] = 'T';
	b["T"] = 'A';
	b["C"] = 'G';
	b["G"] = 'C';
	cout << b[a] << endl;
}

Measured memory_bytes: 256
i,a[1<<17],b[1<<17];c;
main(s){
	for(;~(c=getchar_unlocked());)if(c>10)a[i]=a[i]*10+c-48;else ++i;
	for(b[i=s]=1;!b[s=a[s]]++&&s-2;i++);
	printf("%d",s-2?-1:i);
}

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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(A);
    scanInt(B);
    scanInt(C);
    scanInt(K);
    cout << (A + B + C - max({A, B, C}) + max({A, B, C}) * static_cast<int>(pow(2, K))) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <math.h>
#define inf 99999.0

using namespace std;

bool check(int *label, int n)
{
	for(int i = 1; i <= n; i++){
		if(label[i] == 0){
			return true;
		}
	}
	
	return false;
}

void dij(float **a, int n, int s, int t)
{
	int *label, current=s, num=1, next, *ne;
	float *cost, min;
	
	cost = (float *)calloc(n+1, sizeof(float));
	label = (int *)calloc(n+1, sizeof(int));
	ne = (int *)calloc(n+1, sizeof(int));
	
	for(int i = 1; i <= n; i++){
		cost[i] = a[current][i];
		if(a[current][i] != inf){
			ne[i] = s;
		}
	}
	label[current] = num++;
	
	while(check(label, n)){
		min = inf;
		for(int i = 1; i <= n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = num++;
		for(int i = 1; i <= n; i++){
			if(label[i] == 0 && cost[i] > (a[next][i]+cost[next])){
				cost[i] = a[next][i] + cost[next];
				ne[i] = next;
			}
		}
		current = next;
	}

	if(ne[t] == 0){
		cout << "NA" << endl;
	} else {
		free(label);
		label = (int *)calloc(n+1, sizeof(int));
		label[0] = t;
		next = ne[t];
		current = 1;
		while(ne[next] != next){
			label[current++] = next;
			next = ne[next];
		}
		label[current] = next;
		for(int i = current; i > 0; i--){
			cout << label[i] << " ";
		}
		cout << t << endl;
	}
	
	free(ne);
	free(cost);
	free(label);
	
	return ;
}

int main(int argc, char **argv)
{
	float **a, *x, *y;
	int n, m, s, t, bn;
		
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (float **)calloc(n+1, sizeof(float));
		x = (float *)calloc(n+1, sizeof(float));
		y = (float *)calloc(n+1, sizeof(float));
		
		for(int i = 1; i <= n; i++){
			a[i] = (float *)calloc(n+1, sizeof(float));
			cin >> bn;
			cin >> x[bn] >> y[bn];
		}
		cin >> m;
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				a[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
				if(a[i][j] > 50.0){
					a[i][j] = inf;
				}
			}
		}
		for(int i = 0; i < m; i++){
			cin >> s >> t;
			dij(a, n, s, t);
		}
		
		for(int i = 0; i <= n; i++){
			free(a[i]);
		}
		free(a);
		free(x);
		free(y);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;

  int ans = 0;
  rep(i, 0, n) {
    int x;
    cin >> x;
    ans += min(x, k - x) * 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val n = nextInt()
    val r = if (n % 2 == 0) n else n * 2
    println(r)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    if(b-a+1 < 2*k)
    {
        
        for(int i = a; i <= b; i++)
        {
            cout << i<<endl;
        }
        
    }
    else
    {
        
        for(int i = 0; i < k; i++)
        {
            cout << a+i << endl;
        }
        
        for(int i = k - 1; i >= 0; i--)
        {
            cout << b-i << endl;
        }
        
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, e, t;
int x[100005];
ll f[100005];
int main()
{
	scanf("%d%d%d", &n, &e, &t);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &x[i]);
	}
	ll tmp = 0x3f3f3f3f3f3f3f3f;
	for(int i = 1, j = 1; i <= n; i++)
	{
		while(j <= n && (x[i] - x[j]) * 2 > t)
		{
			tmp = min(tmp, f[j - 1] - x[j] * 2);
			j++;
		}
		f[i] = min(f[j - 1] + t, tmp + x[i] * 2);
	}
	printf("%lld\n", f[n] + e);
	
	
	
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
using namespace std;
#define LL long long
const LL N = 105;
const LL mod = 1e9+7;


int main()
{
	LL n,k;
	scanf("%lld %lld",&n,&k);
	if(k%2==1){
		printf("%lld\n",(n/k)*(n/k)*(n/k));
	}else{
		LL to=k/2;
		LL x=n/k+((n%k)>=to);
		LL y=n/k;
		printf("%lld\n",x*x*x+y*y*y);
	}

}


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

int main(){
  int N,D;cin>>N>>D;
  long long A[2][300000];
  for(int i=0;i<N;i++){
    cin>>A[0][i]>>A[1][i];
  }
  
  long long cnt=0;
  for(int i=0;i<N;i++){
    if(sqrt(A[0][i]*A[0][i]+A[1][i]*A[1][i])<=D) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 6836
#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>;

ll x = 1e9 + 7; 

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n+1; i++) {
    ll a = 0;
    a += -1 * i * i;
    a += i * (n+1) + 1;
    ans += a;
    ans %= x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}
int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	int n, k;
	cin >> n >> k;
	k *= pow(k - 1, n - 1);
	cout << k << endl;
}

Measured memory_bytes: 384
import datetime

M1, D1 = input().split(' ')
M2, D2 = input().split(' ')

M1 = int(M1)
M2 = int(M2)
D1 = int(D1)
D2 = int(D2)

date1 = datetime.datetime(2019, M1, D1)
date2 = datetime.datetime(2019, M2, D2)

if date1.month == date2.month - 1:
    print(1)
else:
    print(0)

Measured memory_bytes: 3440
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main (){
	int n,m; cin >> n >> m;
	vector<int> a(m);
	cinv(m,a);
	vector<int> b(n+1);
	rep(i,m){
		b[a[i]] = 1;
	}
	vector<int> dp(n+1);
	dp[0]=1;
	for(int i = 1; i < n+1; i++){
		if (i==1){
			if (b[i]){
				dp[i]=0;
			}else{
				dp[i]=1;
			}
			continue;
		}
		if (b[i]){
			dp[i]=0;
			continue;
		}
		dp[i] = (dp[i-1] + dp[i-2])%MOD;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c,x,y=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(i*500+j*100+k*50==x)y++;
			}
		}
	}
	cout<<y<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define MOD 1000000007ll
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll A,B;
int X[100100];
ll dp[100100];
int main(){
	scanf("%d %lld %lld",&N,&A,&B);
	for(int i=0;i<N;i++){
		scanf("%d",&X[i]);
	}
	dp[0]=0;
	for(int i=1;i<N;i++)dp[i]=LLINF;
	for(int i=1;i<N;i++){
		dp[i]=min(dp[i-1]+A*(ll)(X[i]-X[i-1]),dp[i-1]+B);
	}
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define REP(i, n) FOR(i, 1, ll(n) + 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

struct MAX {
    ll mx1, mx2;
    void f(const ll a) {
        if(mx1 < a) {
            mx2 = mx1;
            mx1 = a;
        } else
            chmax(mx2, a);
    }
    void f(const MAX m) {
        f(m.mx1);
        f(m.mx2);
    }
    ll sum() { return mx1 + mx2; }
};

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

    int n;
    cin >> n;

    vector<MAX> mx(1 << n);
    rep(i, 1 << n) {
        ll a;
        cin >> a;
        mx[i] = {a, -inf};
    }
    rep(j, n) {
        int x = 1 << j;
        rep(i, 1 << n) {
            if(!(i & x)) i |= x;
            mx[i].f(mx[i ^ x]);
        }
    }

    ll ret = 0;
    FOR(i, 1, 1 << n) {
        chmax(ret, mx[i].sum());
        cout << ret << endl;
    }
}

Measured memory_bytes: 7168
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

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

int main() {

	string s; cin >> s;
	int ans = s.length()/2;
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == 'p') ans--; 
	}
	cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC116();
}

void ABC116(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
b={}
for i in range(N):
    if a[i] in b:
        b[a[i]]+=1
    else:
        b[a[i]]=1
cnt=0
for i in b:
    if b[i]>i:
        cnt+=b[i]-i
    elif b[i]<i:
        cnt+=b[i]
print(cnt)

Measured memory_bytes: 17780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] cards1 = new String[n];
        String[] cards2 = new String[n];
        for(int i = 0; i < n; i++) {
        	String s = sc.next();
        	cards1[i] = s;
        	cards2[i] = s;
        }

        bubbleSort(cards1);
        System.out.println("Stable");

        selectionSort(cards2);
        isStable(cards1, cards2);
	}

	static void bubbleSort(String[] cards) {

		for(int i = 0; i < cards.length; i++) {
			for(int j = cards.length - 1; j > i; j--) {
				if(getNumber(cards[j-1]) > getNumber(cards[j])) {
					String temp = cards[j-1];
					cards[j-1] = cards[j];
					cards[j] = temp;
				}
			}
		}
		printArray(cards);
	}

	static void selectionSort(String[] cards) {

		for(int i = 0; i < cards.length; i++) {
			int minj = i;
			for(int j = i; j < cards.length; j++) {
				if(getNumber(cards[j]) < getNumber(cards[minj])) {
					minj = j;
				}
			}
			String temp = cards[i];
			cards[i] = cards[minj];
			cards[minj] = temp;
		}
		printArray(cards);
	}

	static int getNumber(String str) {
		return Integer.parseInt(str.substring(1));
	}

	static boolean isStable(String[] bs, String[] ss) {

		for(int i = 0; i < bs.length; i++) {
			if(!bs[i].equals(ss[i])) {
				System.out.println("Not stable");
				return false;
			}
		}
		System.out.println("Stable");
		return true;
	}

	static void printArray(String[] strArray) {
		for(int i = 0; i < strArray.length - 1; i++) {
			System.out.print(strArray[i] + " ");
		}
		System.out.println(strArray[strArray.length - 1]);
	}
}



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

int main(){
        int A,B,C,X,Y;
        cin >> A>>B>>C>>X>>Y;
        int ans;
        if((A+B) > (C*2))
        {
                int p,q;
                int cbuy1 = min(X, Y);
                p = C*2*cbuy1;
                p+=A * (X - cbuy1) + B * (Y - cbuy1);

                int cbuy2 = max(X, Y);
                q= C*2*cbuy2;

                ans = min(p,q);
        }
        else
        {
                ans = A*X + B*Y;
        }

        cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M; cin >> N >> M;

  int from = -1, to = N+1;
  for (int i = 0; i < M; i++) {
    int L, R; cin >> L >> R;
    from = max(from, L);
    to = min(to, R);
  }

  cout << ((to < from) ? 0 : (to - from + 1)) << endl;
  return 0;
}


Measured memory_bytes: 256