akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

string calc(Vec2 a, Vec2 b, Vec2 c) {
    auto ab = b - a;
    auto ac = c - a;

    auto d = ab.cross(ac);
    if (d > 0)
        return "COUNTER_CLOCKWISE";
    if (d < 0)
        return "CLOCKWISE";

    // |ab||ac|cos(pi) で cos(pi) = -1 なので負なら逆向き
    if (ab.dot(ac) < 0)
        return "ONLINE_BACK";

    if (ab.magSq() >= ac.magSq())
        return "ON_SEGMENT";
    return "ONLINE_FRONT";
}

void main() {
    auto xs = readints();
    auto a = Vec2(xs[0], xs[1]);
    auto b = Vec2(xs[2], xs[3]);

    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        auto c = Vec2(xy[0], xy[1]);
        auto ans = calc(a, b, c);
        writeln(ans);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opNeg() { return Vec2(-this.x, -this.y); }
    Vec2 opAdd(Vec2 other) { return Vec2(this.x + other.x, this.y + other.y); }
    Vec2 opSub(Vec2 other) { return Vec2(this.x - other.x, this.y - other.y); }
    Vec2 opMul(double d) { return Vec2(this.x * d, this.y * d); }

    double dot(Vec2 other) { return this.x * other.x + this.y * other.y; }
    double cross(Vec2 other) { return this.x * other.y - other.x * this.y; }
    double mag() { return sqrt(magSq()); }
    double magSq() { return this.x * this.x + this.y * this.y; }

    Vec2 normalized() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}



Measured memory_bytes: 2476
#!/usr/bin/env python3
import sys

def solve(N: int, Z: int, W: int, a: "List[int]"):
    print(max(abs(a[N-1]-a[N-2]),abs(a[N-1]-W)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, Z, W, a)

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2] && s[0] == 'R') cout << 3 << '\n';
    else if ((s[0] == s[1] || s[1] == s[2]) && (s[1] == 'R')) cout << 2 << '\n';
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << '\n';
    else cout << 0 << '\n';
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int m = sc.nextInt();
  Set<Integer> s1 = new HashSet<>();
  Set<Integer> sn = new HashSet<>();
  for (int i=0; i<m; i++) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a == 1)s1.add(b);
    if (b == n)sn.add(a);        
  }
  s1.retainAll(sn);
  System.out.println(s1.isEmpty() ? "IMPOSSIBLE":"POSSIBLE");
}}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl
inline int ceil10(int n) { n+=(10-n%10)%10; return n; }

bool is_repdigit(int n) {
    int d = n % 10;
    n /= 10;
    while (n!=0) {
        if (n%10!=d)
            return false;
        n/=10;
    }
    return true;
} 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N,D,X; cin>>N>>D>>X;
    vector<int> A(N); cin >> A;

    int ans = X;
    rep(i, N)
        ans += 1 + (D - 1) / A[i];
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main (){
    int n,i,tmp,j,k,l,q;
    int pos[101],dp[100][100];
    scanf("%d",&n);
    scanf("%d %d",&pos[0],&pos[1]);
    for(i=2;i<=n;i++){
        scanf("%d %d",&tmp,&pos[i]);
    }
    for(i=0;i<=n;i++){
        dp[i][i]=0;
    }
    for(l=2;l<=n;l++){
        for(i=1;i<=n-l+1;i++){
            j=i+l-1;
            dp[i][j]=1000000000;
            for(k=i;k<j;k++){
                q=dp[i][k]+dp[k+1][j]+pos[i-1]*pos[k]*pos[j];
                if(dp[i][j]>q){
                    dp[i][j]=q;
                }
            }
        }
    }
    printf("%d\n",dp[1][n]);
    return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

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


int main()
{
    
    ll N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;
    
    if(N < M){
        swap(N,M);
        swap(S,T);
    }
    ll a = gcd(N,M);
    ll ans = N*M/a;
    ll n = M/a;
    ll m = N/a;
    for (ll i = 0; i < M; i++) {
        if((i*m)%(n) == 0){
            if(T[i] != S[i*m/n]){
                cout << -1 << endl;
               
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
import bisect
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  if bind == N:
    continue
  ans += z[bind]
print(ans)

Measured memory_bytes: 23328
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<vector>
#include<queue>
#define N 500010
using namespace std;
typedef long long ll;
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<vector>
#include<queue>
#define N 15
using namespace std;
typedef long long ll;
char a[N];
int main()
{
    ios::sync_with_stdio(false);
    int n,left,right,mid,x,y;
    cin>>n;
    cout<<"0"<<endl;
    cin>>a;
    if(a[0]=='V')
        return 0;
    else if(a[0]=='M') x=1;
    else x=0;
    left=0,right=n;
    while(left!=right-1)
    {
        mid=(left+right)/2;
        cout<<mid<<endl;
        cin>>a;
        if(a[0]=='V')
           return 0;
        else if(a[0]=='M') y=1;
        else  y=0;

        int t =mid-left;
        if(t%2==0){
            if(y==x) left=mid,x=y;
            else right=mid;
            }
        else{
            if(x==y)right=mid;
            else left=mid,x=y;
            }
    }
    return 0;
}



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

int main() {
	int n, num, turn;
	vector< int > sq;
	
	while(cin >> n, n){
		sq.resize(n);
		for(int i = 0; i < n; ++i) cin >> sq[i];
		
		num = 32;
		turn = 1;
		
		while(num > 0){
			if(turn % 2){
				num -= (num - 1) % 5;
			}else{
				num -= (sq[(turn / 2 - 1) % n]);
				if(num < 0) num = 0;
			}
			++turn;
			
			cout << num << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define clv(V) (V).clear()
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define upmax(a,b) (a)=max((a),(b))
using namespace std;
const db pi = acos(-1.0);
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

typedef long long ll;
typedef pair<ll, ll> pll;
ll operator * (pll a, pll b) { return a.X * b.Y - b.X * a.Y; }
ll ccw(pll a, pll b, pll c) { return a * b + b * c + c * a; }
struct Node
{
	vector<pll> V;
	void init() { clv(V); }
	void push(ll a, ll b)
	{
		for(; 1 < sz(V) && ccw(befv(V), V.back(), {a, b}) <= 0; V.pop_back());
		V.pb({a, b});
	}
	ll f(ll x, int idx) { return V[idx].X * x + V[idx].Y; }
	ll f(ll x)
	{
		if(V.empty()) return -INFLL;
		int s = 0, e = sz(V) - 1;
		for(int m; s < e;)
		{
			m = (s + e) / 2;
			ll l = f(x, m), r = f(x, m + 1);
			if(l < r) s = m + 1; 
			else e = m;
		}
		return f(x, s);
	}
};
const int Mn = 300010;
Node a;
ll L[Mn], R[Mn], P[Mn], S[Mn], T[Mn];
int N, M;

void f(ll d[]) 
{
	rep(i, 1, N) S[i] = S[i - 1] + T[i];
	a.init(); a.push(0, 0);
	rep(i, 1, N)
	{
		d[i] = max(d[i - 1], a.f(i) + ((ll)i * i + i) / 2 - S[i]);
		a.push(-i, d[i] + S[i] + ((ll)i * i - i) / 2);
	}
}

void f(ll d[], int s, int e) 
{
	if(s > e) return;
	if(s == e) 
	{
		upmax(d[s], L[s - 1] + R[s + 1] + 1 - T[s]);
		return;
	}
	int m = (s + e) / 2; ll x = -INFLL;
	a.init();
	rep(j, m + 1, e)
		a.push(-j, R[j + 1] - S[j] + ((ll)j * j + j) / 2);
	rep(i, s - 1, m - 1) 
	{
		ll t = a.f(i) + L[i] + S[i] + ((ll)i * i - i) / 2;
		upmax(x, t); 
		upmax(d[i + 1], x);
	}
	a.init(); 
	x = -INFLL;
	rep(i, s - 1, m - 1)
		a.push(-i, L[i] + S[i] + ((ll)i * i - i) / 2);
	for(int j = e; m < j; j --) 
	{
		ll t = a.f(j) + R[j + 1] - S[j] + ((ll)j * j + j) / 2;
		upmax(x, t); 
		upmax(d[j], x);
	}
	f(d, s, m); 
	f(d, m + 1, e);
}

int main()
{
	scanf("%d", &N);
	rep(i, 1, N) scanf("%lld", &T[i]);
	f(L); reverse(T + 1, T + N + 1);
	f(R); reverse(R + 1, R + N + 1);
	reverse(T + 1, T + N + 1);
	rep(i, 1, N) S[i] = S[i  -1] + T[i];
	fill(P + 1, P + N + 1, -INFLL);
	f(P, 1, N);
	M = read();
	while(M --)
	{
		int p = read();
		ll x;
		scanf("%lld", &x);
		printf("%lld\n", max(0ll, max(L[p - 1] + R[p + 1], P[p] + T[p] - x)));
	}
	return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(a <= 0 and b >= 0){
cout<<"Zero"<<endl;
}else if(a > 0 or (b - a +1) % 2 == 0){
cout<<"Positive"<<endl;
}else{
cout<<"Negative"<<endl;
}

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n,q;
  ll sum = 0;
  map<ll, ll> mp;
  cin >> n;
  rep(i,n) {
    int a;
    cin >> a;
    sum += a;
    mp[a]++;
  }
  cin >> q;
  vector<ll> b(q),c(q);
  rep(i,q) cin >> b[i] >> c[i];
  rep(i,q){
    sum-=b[i]*mp[b[i]];
    sum += c[i] * mp[b[i]];
    mp[c[i]] += mp[b[i]];
    mp[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 10448
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    string t;
    cin >> t;
    int m = t.size();
    int minCost = 10000;
    for (int i = 0; i <= (n - m); i++)
    {
        int cost = 0;
        for (int j = 0; j < m; j++)
        {
            if (s[i + j] != t[j])
            {
                cost++;
            }
        }
        if (cost < minCost)
        {
            minCost = cost;
        }
    }
    cout << minCost << endl;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if (abs(a - c) <= d) cout << "Yes" << endl;
    else if (abs(a - b) <= d and abs(b - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
N,C=list(map(int,input().split()))
D = []
gridColor = []
for i in range(C):
    D.append(list(map(int, input().split())))
for i in range(N):
    gridColor.append(list(map(int, input().split())))

colorBucket=[[0]*C, [0]*C, [0]*C]
for i in range(1,N+1):
    for j in range(1,N+1):
        colorBucket[(i+j)%3][gridColor[i-1][j-1]-1] += 1

cost_change_color=[[0]*C, [0]*C, [0]*C]

for k in range(3):
#グループごとに、ある色への塗り替えコストの計算
    for m in range(C):
        total=0
        for l in range(C):
            total+=D[l][m]*colorBucket[k][l]
        cost_change_color[k][m] = total

cost = []
for s in range(C):
    for t in range(C):
        for r in range(C):
            if not(s==t or t==r or r==s):
                cost.append(cost_change_color[0][s]+cost_change_color[1][t]+cost_change_color[2][r])

print(min(cost))


Measured memory_bytes: 6636
n = int(input())
plist = list(map(int, input().split()))

cnt = 0
for num in range(2, n):
    p1 = plist[num-2]
    p2 = plist[num-1]
    p3 = plist[num]
    if p1 > p3:
        if p1 > p2 > p3:
            cnt = cnt + 1
    else:
        if p3 > p2 > p1:
            cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060
// https://beta.atcoder.jp/contests/abc083

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

int main() {
    ui64 X, Y;
#ifdef SUBMIT
    cin >> X >> Y;
#else
    X = 314159265, Y = 358979323846264338;
#endif
    ui64 ans = 0;
    ui64 d = Y / X;

    for (ui64 i = 0; i < 64; ++i) {
        if (d == 0) break;
        d /= 2;
        ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    string c;
    cin >> c;
    if (c == "a") cout << "b";
    if (c == "b") cout << "c";
    if (c == "c") cout << "d";
    if (c == "d") cout << "e";
    if (c == "e") cout << "f";
    if (c == "f") cout << "g";
    if (c == "g") cout << "h";
    if (c == "h") cout << "i";
    if (c == "i") cout << "j";
    if (c == "j") cout << "k";
    if (c == "k") cout << "l";
    if (c == "l") cout << "m";
    if (c == "m") cout << "n";
    if (c == "n") cout << "o";
    if (c == "o") cout << "p";
    if (c == "p") cout << "q";
    if (c == "q") cout << "r";
    if (c == "r") cout << "s";
    if (c == "s") cout << "t";
    if (c == "t") cout << "u";
    if (c == "u") cout << "v";
    if (c == "v") cout << "w";
    if (c == "w") cout << "x";
    if (c == "x") cout << "y";
    if (c == "y") cout << "z";
}

Measured memory_bytes: 3496
#include <stdio.h>
int main(void) 
{
	int H, R;
	scanf("%d %d", &H, &R);
	if (R + H > 0) {
		printf("1\n");
	}
	else if (R == -H) {
		printf("0\n");
	}
	else
		printf("-1\n");
	return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

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


int main()
{
    int H,W,K;
    cin >> H >> W >> K;
    char tile[H][W];
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            cin >> tile[h][w];
        }
    }
    int ans=0;
    for(int i=0; i<(1<<(H+W)); i++){
        int tmp=i;
        vector<bool> hflag(H,0),wflag(W,0);
        for(int j=0; j<H; j++){
            if(tmp%2==0) hflag[j]=true;
            tmp/=2;
        }
        for(int j=0; j<W; j++){
            if(tmp%2==0) wflag[j]=true;
            tmp/=2;
        }

        int cnt=0;
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                if(wflag[w]==false && hflag[h]==false && tile[h][w]=='#') cnt++;
            }
        }
        if(cnt==K) ans++;
    }

    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 

//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;
ll t=1;

void solve()
{
    cin>>n;
    string s;
    cin>>s;
    string ss=s;
    sort(ss.begin(),ss.end());
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]!=ss[i] and s[i]=='W')cnt++;
    }
    cout<<cnt;
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

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

int main(){
    int AC=0, WA=0;
    int N, M;
    cin >> N >> M;

    if(M == 0){
        cout << 0 << " " << 0 << endl;
        return 0;
    }

    vector<int> p(M);
    vector<string> S(M);
    vector<int> tmpWA(N);
    vector<bool> flag(N); //AC出したらtrueに。添字+1が問題番号

    for(int i=0;i<M;i++){
        cin >> p[i] >> S[i];
    }
    for(int i=0;i<N;i++){
        flag[i] = false;
        tmpWA[i] = 0;
    }

    for(int i=0;i<M;i++){
        
        if(flag[p[i]-1] == true){
            continue;
        }
        if(S[i] == "WA"){
            tmpWA[p[i]-1]++;
        } 
        else if(S[i] == "AC"){
            AC++;
            flag[p[i]-1] = true;
        }
    }

    for(int i=0;i<N;i++){
        if(flag[i] == true){
            WA += tmpWA[i];
        }
    }
    cout << AC << " "<< WA << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N=1000005;
int n,i,a[N];
long long s,ans,b[N];
int main()
{
	scanf("%d",&n);
	for(i=0;i<=n;++i)
		scanf("%d",&a[i]);
	b[0]=1-a[0];
	if(b[0]<0)
	{
		puts("-1");
		return 0;
	}
	for(i=1;i<=n;++i)
	{
		b[i]=b[i-1]*2-a[i];
		b[i]=min(b[i],10000000000000000ll);
		if(b[i]<0)
		{
			puts("-1");
			return 0;
		}
	}
	for(i=n;i>=0;--i)
	{
		ans+=min(1ll*b[i],s)+a[i];
		s+=a[i];
	}
	cout<<ans;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N, L;

    cin >> N >> L;

    int first = L;
    int end = L+N-1;
    int sum = N*L;

    for(int i = 0; i<N; i++){
        sum+=i;
    }

    if (first > 0){
        sum-=first;    
    }else if (end < 0){
        sum-=end;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;
const int STD=500000;

int main(){
  string s;
  char str[1000000];
  int q;
  cin >> s >> q;
  for(int i=0;i<s.length();i++){
    str[STD+i] = s[i];
  }
  int r=STD, l=STD+s.length()-1;
  bool direction=true;
  for(int i=0;i<q;i++){
    int tmp;
    cin >> tmp;
    if(tmp==1){
      direction ^= true;
    }
    else if(tmp==2){
      int f;
      char c;
      cin >> f >> c;
      if(direction ^ (f==1)){
        l++;
        str[l]=c;
      }
      else{
        r--;
        str[r]=c;
      }
    }
  }
  if(direction){
    for(int i=r;i<=l;i++){
      cout << str[i];
    }
  }
  else{
    for(int i=l;i>=r;i--){
      cout << str[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, sum = 0;
  int m;
  cin >> n >> m;
  vector<ll> A(m);
  rep(i,m) {
    cin >> A[i];
    sum += A[i];
  }
  ll ans = 0;
  if (sum <= n) ans = n - sum;
  else ans = -1;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  int sum = 0;
  for(int&e:v)sum+=e;
  cout << sum - n << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int A = keyboard.nextInt();
		int B = keyboard.nextInt();
		int C = keyboard.nextInt();
		
		String ans;
		
		if(A < C && C < B) {
			ans = "Yes";
		}else {
			if(B < C && C < A) {
				ans = "Yes";
			}else {
				ans = "No";
			}
		}
			System.out.println(ans);
			
		keyboard.close();	
	}
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  vector<vector<int>> dp(k+1,vector<int>(n+1,0));
  int p=1000000007;
  for(int j=0;j<=n;j++)
    dp[0][j]=1;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=n;j++){
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%p;
      if(i-a.at(j-1)-1>=0)
        dp[i][j]=(dp[i][j]-dp[i-a.at(j-1)-1][j-1]+p)%p;
    }
  }
  cout<<dp[k][n]<<endl;
}

Measured memory_bytes: 45056
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    int r, g;
    cin >> r;
    cin >> g;
    
    P(2 * g - r);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, a, b, s, ans;
	cin >> n >> k;
	vector<pair<long long, long long>> p(n);
	for (i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
	sort(p.begin(), p.end());
	s = k;
	for (i = 0; i < n; i++) {
		if (s <= p[i].second) {
			ans = p[i].first;
			break;
		}
		s -= p[i].second;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
N = gets.to_i

vs = [1]

[6, 9].each do |v|
  k = v
  while k <= N
    vs << k
    k *= v
  end
end

dp = Array.new(N + 1, 1.0 / 0)
dp[0] = 0
1.upto(N) do |i|
  vs.each do |v|
    next if i < v
    dp[i] = [dp[i], dp[i - v] + 1].min
  end
end

puts dp[N]


Measured memory_bytes: 2556
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

// Dynamic Programming - LCS

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

    int q;
    cin >> q;

    for (int _ = 0; _ < q; ++_) {
        string s1, s2;
        cin >> s1 >> s2;

        const int s1_size = s1.size();
        const int s2_size = s2.size();
        vector<vector<int>> dp(s1_size + 1);
        for (int i = 0; i < s1_size + 1; ++i) dp[i].resize(s2_size + 1, 0);

        for (int i = 0; i < s1_size; ++i) {
            for (int j = 0; j < s2_size; ++j) {
                if (s1[i] == s2[j]) dp[i+1][j+1] = dp[i][j] + 1;
                else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
        cout << dp[s1_size][s2_size] << "\n";
    }

    cout << flush;
    return 0;
}



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


void solve(long long N, long long M){
    ll ans = N * (N-1)/2;
    ans += M * (M-1)/2;
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  char s[4];
  scanf("%s", s);
  int price = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') {
      price += 100;
    }
  }
  printf("%d\n", price);

  return 0;
}

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



int main(){
    ll N, M; cin >> N >> M;
    ll SUM = 0;
    for(int i = 0; i < M; i++){
        ll a; cin >> a;
        SUM += a;
    }
    if(N < SUM) cout << -1 << endl;
    else cout << N - SUM << endl;
}

Measured memory_bytes: 3636
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            int n = ReadI();
            int a = ReadI();

            if (n % 500 <= a) WriteLine("Yes");
            else WriteLine("No");
        }

        //メインじゃない関数
        private static string Read() { return ReadLine(); }
        private static int ReadI() { return int.Parse(ReadLine()); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll M = 1000000007;

ll factorial(ll n) {
  if (n == 0) return 1;
  return ((n % M) * (factorial(n - 1) % M)) % M;
}

int main() {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll x = factorial(n);
  ll y = factorial(m);
  ll z = (x * y) % M;
  if (n == m) { z *= 2; }
  cout << z % M << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int arr[2019];
int main(){
	int l,r;
	cin>>l>>r;
	if(r-l>=2018||r%2019<l%2019){
		cout<<0<<endl;
		return 0;
	}
	l%=2019,r%=2019;
	int ans=3000;
	for(int i=l;i<=r-1;i++)
		for(int j=i+1;j<=r;j++)
			ans=min(ans,i*j%2019);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const ll inf = int(1e18);
const int mod = 256;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);
 
void solve()
{
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <= n; ++i){
		int x;
		cin >> x;
		cnt += (i != x);
	}
	if(cnt <= 2){
		cout << "YES";
	}
	else cout << "NO";
}
int main()
{
	Red;
	solve();
	return 0;
}

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

using namespace std;

/* エラトステネスの篩 */
vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n + 1, 0);

  for (int i = 2; i <= n; i++) primes[i] = i;

  for (int i = 2; i * i <= n; i++) {
    if (0 == primes[i]) continue;  //  0ならば素数ではない
    for (int j = i + i; j <= n; j += i) primes[j] = 0;  //  iの倍数を0にする
  }

  // primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());

  return primes;
}

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

  auto v = sieve_of_eratosthenes(1000000);
  for (auto w : v) {
    if (w != 0) {
      if (x <= w) {
        cout << w << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  rep(i,19)
    if(i==5 || i==13)
      cout<<" ";
    else
      cout<<s[i];
  cout<<endl;
}


Measured memory_bytes: 256
function Main(input) {

	input = input.split("\n");
	var N = parseInt(input[0]);
	var lists = [];
	
	function List(name,score,num){
	    this.name = name;
	    this.score = score;
	    this.num = num;
	}
	
	List.prototype.show = function(){
	    return this.num;
	}
	
	for(var i = 0;i < N;i++){
	     pass = input[i+1].split(" ");
	     lists[i] = new List(pass[0],parseInt(pass[1]),parseInt(i+1));
	}
	
	lists.sort((a,b) => { return (a.name > b.name) ? 1
    						   : (a.name < b.name) ? -1
      				           : (b.score >= a.score)? 1 : -1; });
    for(var j = 0;j < N;j++){
        console.log(lists[j].show());
    }
    //console.log(lists);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = INF;
  for (int i = 0; i <= 100000; i++){
    int tmp = i * 2 * C;
    if (i < X){
      tmp += (X - i) * A;
    }
    if (i < Y){
      tmp += (Y - i) * B;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

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

int main(void){
  	string str;
  	cin >> str;
  
	vector<char> S;
  	for(int i=0;i<str.size();i++)
		S.push_back(str[i]);
	
	int Q,T,F,count;
	char C;
	cin >> Q;
	for(int i=0;i<Q;i++){
	cin >> T;
	if(T==1){
      if(count==0) count=1;
      else count=0;
    }
	else{
		cin >> F >> C ;
		if((F==1)&&(count==0))	S.insert(S.begin(),C);
		else if((F==1)&&(count==1))	S.emplace_back(C);
      	else if((F==2)&&(count==0))	S.emplace_back(C);
      	else S.insert(S.begin(),C);
		}
	}
  
  	if(count==1) reverse(S.begin(), S.end());
  
	for (auto itr = S.begin(); itr != S.end(); ++itr)
   		 cout << *itr ;

    return 0;
}



Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    map<ll,ll> mp;
    rep(i,n) {
        ll a;
        cin >> a;
        if(mp[a]==0) mp[a] = 1;
        else mp[a] += 1;
    }
    ll v0 = 0;
    ll v1 = 0;
    for(auto iter = mp.begin(); iter != mp.end();iter++){
        if (iter->second >= 4){
            v0 = iter->first;
            v1 = iter->first;
        }else if(iter->second >= 2){
            v1 = v0;
            v0 = iter->first;
        }
    }
    cout << v0 * v1 << endl;
}

Measured memory_bytes: 6528
n = int(input())
v_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
res = []
for i in range(n):
    if v_list[i]-c_list[i] > 0:
        res.append(v_list[i]-c_list[i])
    else:
        continue
print(sum(res))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int H, W, b = 0;
    while(b == 0){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(i == 0 || j ==0 || j == W - 1 || i == H - 1)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
                if(j == W - 1)
                cout << endl;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3052
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
#define nofind string::npos

int main()
{
	string s;
	int pl;
	while(getline(cin ,s))
	{

		pl = 0;

		for(int i = 0;i < 30;i++)
		{
			for(int j = 0; j < s.size(); j++)
			{
				if(islower(s[j]))
				{
					s[j]++;
				}
				if(s[j] > 'z')
				{
					s[j] -= 'z' - 'a' + 1;
				}
			}
			if(s.find("the") != nofind)
			{
				break;
			}
			if(s.find("this") != nofind)
			{
				break;
			}
			if(s.find("that") != nofind)
			{
				break;
			}
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1180
import qualified Data.List as L
import Control.Monad
main = do
  n <- read <$>  getLine :: IO Int
  as <- fmap read . lines <$> getContents :: IO [Int]
  let as' = L.sort as
      m1 = as' !! (n - 1)
      m2 = as' !! (n - 2)
  forM_ as $ \a ->
    print $ if a < m1 then m1 else m2


Measured memory_bytes: 47740
/*
ID: jerrywcy
TASK: AtCoder ABC 104 Problem A
LINK: https://abc104.contest.atcoder.jp/tasks/abc104_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int d,g;
int p[15],c[15];

int main(){
	cin>>d>>g;
	int i,j;
    for(i=1;i<=d;i++)
        cin>>p[i]>>c[i];
        
    int Max=(1<<d)-1,ans=0x3f3f3f3f;
    
    for(i=0;i<=Max;i++){
        int cnt=0,rest=g;
        for(j=d;j>=1 && rest>0;j--)
            if(i&(1<<(j-1))){
                int tmp=p[j]*j*100;
                if(tmp>=rest){
                    cnt+=(rest+100*j-1)/(100*j);
                    rest=0;
                    break;
                }
                else{
                    rest-=tmp+c[j];
                    cnt+=p[j];
                }
            }
        if(rest<=0)ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var x = int.Parse(spl[1]);
        var ary = ToIntArray(input.ReadLine(), n);

        int c = 0;
        int y = 0;
        while (true) {
            c++;
            if (c > n) break;

            y += ary[c-1];
            if (y > x) break;
        }
        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13140
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my ($y, $m, $d) = split /\//, read_line;
say do {
  if ( $y < 2019 ) {
    'Heisei';
  }
  elsif ( $y == 2019 ) {
    $m <= 4 ? 'Heisei' : 'TBD';
  }
  else {
    'TBD';
  }
};


Measured memory_bytes: 640
import numpy as np

n = int(input())
t, a = map(int, input().split())
h = np.array(list(map(int, input().split())))

A = list(map(lambda x: abs(a-(t-x*0.006)), h))
[idx] = [i for i, x in enumerate(A) if x == min(A)]

print(idx+1)

Measured memory_bytes: 14408
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  int k;
  cin >> s >> k;

  int n = s.length();
  string mx[5];
  REP(i,k){
    mx[i] = "z" + s;  
  }

  REP(i,26){
    REP(j,n){
      if(s[j] == 'a' + i){
        string tmp = "";
        REP(l,k){
          if(j+l >= n) break;
          tmp = tmp + s[j+l];

          bool isin = false;
          REP(ll,k){
            if(mx[ll] == tmp){
              isin = true;
              break;
            }
          }
          if(isin) continue;
          REP(ll,k){
            if(mx[ll] > tmp){
              FOR(lll,ll+1,k){
                mx[lll] = mx[lll-1];
              }
              mx[ll] = tmp;
              break;
            }
          }
        }
      }
    }
    if(mx[k-1] != "z" + s) break; 
  }

  cout << mx[k-1] << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

void update(ll &mi, ll &ma, ll val, ll val2) {
	if (val > val2) swap(val, val2);
	chmax(mi, val); chmin(ma, val2);
}

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

	int n;
	cin >> n;
	int m = (1 << n);
	vector<int> a(m);
	rep(i, m) cin >> a[i];
	vector<P> dp(m), dp2(m);
	dp[0] = P(a[0], 0); dp2[0] = P(-inf, -1);
	int ans = 0;
	for (int i = 1; i < m; i++) {
		vector<P> ok;
		rep(j, n) {
			if ((i >> j) & 1) {
				int b = (1 << j);
				ok.pb(P(a[i], i)); ok.pb(dp[i - b]); ok.pb(dp2[i - b]);
				if (i != b) {
					ok.pb(dp[b]); ok.pb(dp2[b]);
				}
			}
		}
		sort(all(ok)); reverse(all(ok));
		int sum = 0; int idx = -1; int cnt = 0;
		for (P j : ok) {
			if (j.second != idx) {
				sum += j.first;
				idx = j.second;
				if (cnt == 0) dp[i] = j;
				if (cnt == 1) dp2[i] = j;
				cnt++;
				if (cnt == 2) break;
			}
		}
		chmax(ans, sum);
		cout << ans << '\n';
	}
}

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

using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, lst=0, a;
	ll s=0;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a;
		if(a>lst)
			lst = a;
		else
			s += lst - a;
	}
	cout << s;
	return 0;
} 
 


Measured memory_bytes: 3584
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

import math
a = 100
x = int(input())
cnt = 0
while True:
    a = math.floor(a*1.01)
    cnt += 1
    if a>=x:
        break
print(cnt)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char S;
  cin >> S;
  
  if (( S == 'a') || ( S == 'i') || ( S == 'u') ||
     ( S == 'e') || ( S == 'o'))
  {
    cout << "vowel" << endl;
  }
  else  
  {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	ll n, ans=0, a[200000], p[200000];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		p[a[i]-1]=i;
	}
	set<int> s;
	s.insert(-1);
	s.insert(n);
	for(int i=0; i<n; i++){
		set<int>::iterator it=s.lower_bound(p[i]);
		ll r=(*it)-p[i];
		it--;
		ll l=p[i]-(*it);
		ans+=(i+1)*r*l;
		s.insert(p[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main(){
	int x,y;
	for(;;){
		cin>>x>>y;
		if(x==0 && y==0)break;
		if(x>y){
			cout<<y<<" "<<x;
		}else{
			cout<<x<<" "<<y;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, L;
  cin >> N >> L;
  
  // L ~ L+N-1
  int eat;
  if (L > 0){
    eat = L;
  }
  else if (L+N-1 < 0){
    eat = L+N-1;
  }
  else{
    eat = 0;
  }
  int sum = N * (2*L+N-1) / 2;
  cout << sum - eat << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a = 0, b = 0, c = 0;
	for (int i=0; i<n; ++i){
		int a1,b1,c1;
		cin >> a1 >> b1 >> c1;
		a1 += max(b,c);
		b1 += max(a,c);
		c1 += max(a,b);
		a = a1;
		b = b1;
		c = c1;
	}
	cout << max({a,b,c});
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using pll = pair<long long, long long>;
int main() {
    int N; cin >> N;
    vector<pll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i].first, A[i].second = i;
    sort(A.begin(), A.end(), greater<pll>());

    vector<vector<long long>> dp(N+1, vector<long long>(N+1, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; i + j < N; ++j) {
            // left
            chmax(dp[i+1][j], dp[i][j] + A[i+j].first * (A[i+j].second - i));

            // right
            chmax(dp[i][j+1], dp[i][j] + A[i+j].first * ((N-1-j) - A[i+j].second));
        }
    }
    long long res = 0;
    for (int i = 0; i <= N; ++i) chmax(res, dp[i][N-i]);
    cout << res << endl;
}

Measured memory_bytes: 34664
import sys
input = sys.stdin.readline
import bisect

a, b, q = (int(i) for i in input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
x = [int(input()) for i in range(q)]

def get_near(e, x):
    xi = bisect.bisect_left(x,e)
    if xi == 0:
        return [x[0]]
    if xi == len(x):
        return [x[-1]]
    return [x[xi-1], x[xi]]

for e in x:
    s_ = get_near(e,s)
    t_ = get_near(e,t)
    min_dist = 10**11
    for si in s_:
        for ti in t_:
            dist = min(abs(e-si), abs(e-ti)) + abs(si-ti)
            min_dist = min(min_dist, dist)

    print(min_dist)


Measured memory_bytes: 16224
def examD():
    N = I()
    a = LI()
    a_b = list(map(lambda x: x*(-1), a))
    R = a[:N]; B = a_b[2*N:]
    heapq.heapify(R)
    heapq.heapify(B)
    ansC =[]
    curR = [sum(R)]; curB = [-sum(B)]
    for i in range(N):
        heapq.heappush(R, a[N+i])
        cur = curR[-1] - heapq.heappop(R) + a[N+i]
        curR.append(cur)
    for i in range(N):
        heapq.heappush(B, a_b[2*N-1-i])
        cur =curB[-1] - heapq.heappop(B)*(-1) - a_b[2*N-1-i]
        curB.append(cur)
    for i in range(N+1):
        ansC.append(curR[i]-curB[-1-i])
    ans = max(ansC)
    print(ans)
#    print(ansC)
#    print(curR,curB)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll n;cin>>n;
    double a[n];
    double b=1;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b=b*a[i];
    }
    double sum=0;
    for(ll i=0;i<n;i++){
        sum=sum+(b/a[i]);
    }
    cout<<b/sum<<endl;
    
    return 0;
}



Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e5+5;

void solve(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n){
		cin>>a[i];
	}
	int ans=0,cnt=0;
	rep(i,n-1){
		if(a[i]<a[i+1]){
			cnt=0;
		}
		else {
			cnt++;
			umax(ans,cnt);
		}
	}
	cout<<ans;
	
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)solve();
}


Measured memory_bytes: 3720