akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep (i, n) cin >> h[i];

  vector<int> dp(n, INF);
  dp[0] = 0;

  rep (i, n) {
    if (i - 1 >= 0) dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <functional>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

const int maxn = 110;

int main()
{
	int k, t, a[maxn], ans = 0;
	scanf("%d %d", &k, &t);
	for (int i = 0; i < t; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + t);
	for (int i = 0; i < t - 1; i++) {
		ans += a[i];
	}
	ans = a[t - 1] - ans - 1;
	if (ans < 0) {
		ans = 0;
	}
	if (t == 1) {
		ans = a[0] - 1;
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    
    int sum = 0;
    int max = 0;
    int b = 0;
    for(int i=0;i<a;i++){
      b=sc.nextInt();
      sum+=b;
      if(max<=b){
        max=b;
      }
    }
    sum-=max;
    if(max<sum)System.out.println("Yes");
	else System.out.println("No");
  }
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  string s;
  cin>>N>>s;

  VEC2(v,3,N);
  FOR(i,0,N){
    if(s[i]=='J')v[0][i]=1;
    if(s[i]=='O')v[1][i]=1;
    if(s[i]=='I')v[2][i]=1;
  }
  FOR(i,1,N){
    v[0][i]+=v[0][i-1];
    v[2][N-i-1]+=v[2][N-i];
  }
  ll res=0,inst=0;

  FOR(i,0,N){
    inst=max(inst,v[0][i]*v[2][i]);
    if(v[1][i]==1)res+=v[0][i]*v[2][i];
  }
  res+=inst;
  inst=0;
  FOR(i,0,N){
    if(v[1][i]==1){
      inst+=(v[0][i]+1)*v[2][i];
    }
  }
  res=max(res,inst);
  inst=0;
  FOR(i,0,N){
    if(v[1][i]==1){
      inst+=(v[2][i]+1)*v[0][i];
    }
  }
  res=max(res,inst);
  cout<<res<<endl;
  //coutv(v[0],0,N);
  //coutv(v[1],0,N);
  //coutv(v[2],0,N);
}



Measured memory_bytes: 6144
N, M = [int(x) for x in input().strip().split(" ")]
H = [int(x) for x in input().strip().split(" ")]

no_good = []
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    if H[a] == H[b]:
        no_good += [a, b]
    elif H[a] < H[b]:
        no_good.append(a)
    elif H[a] > H[b]:
        no_good.append(b)
print(N - len(set(no_good)))

Measured memory_bytes: 20128
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[666666];
signed main()
{
	int n;cin>>n;
	int minx=9999999999999;
	int maxn=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		minx=min(minx,a[i]);
		maxn=max(maxn,a[i]);
	}
	int ans=999999999999999;
	for(int i=minx;i<=maxn;i++){
		int sum=0;
		for(int j=1;j<=n;j++){
			sum+=(i-a[j])*(i-a[j]);
		}ans=min(sum,ans);
	}cout<<ans;
    
}


Measured memory_bytes: 256
N = int(input())
L = input()

l = 0
r = N-1
count = 0

while l < r:
    if L[l] == 'W' and L[r] == 'R':
        count += 1
        l += 1
        r -= 1
        continue

    if L[l] != 'W':
        l += 1
    
    if L[r] != 'R':
        r -= 1

print(count)

Measured memory_bytes: 9412
<?php
  fscanf(STDIN, "%d %d", $k, $x);
  for ($i = $x - $k + 1; $i < $x + $k; $i++) {
    if ($i != $x + $k - 1) {
      print $i . " ";
    } else {
      print $i . "\n";
    }
  }

Measured memory_bytes: 4728
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
namespace MCF {
	// required <string.h> <vector> <queue> <algorithm>
	#define MAXN 3100
	#define MAXM 21000
	#define wint int
	#define cint long long
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = 1001001001001001LL;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));
		//*
		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		//*/
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; f=min(f,capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}
int z[2100];
int b[1100];
int c[1100];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",b+i,c+i);
		z[i*2]=b[i];
		z[i*2+1]=c[i];
	}
	MCF::init(a*3+2);
	std::sort(z,z+a*2);
	int s=a*3;
	int t=a*3+1;
	for(int i=0;i<a;i++){
		MCF::ae(s,i,1,0);
		MCF::ae(i,t,1,1000000);
		int L=lower_bound(z,z+a*2,b[i])-z;
		int R=lower_bound(z,z+a*2,c[i])-z;
		MCF::ae(i,a+L,1,1000000-c[i]);
		MCF::ae(i,a+R,1,1000000-b[i]);
	}
	for(int i=0;i<a*2;i++)MCF::ae(a+i,t,1,0);
	MCF::solve(s,t,a);
	printf("%lld\n",-MCF::toc+1000000*a);
}

Measured memory_bytes: 1472
#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 <set>
#include <iomanip>
using namespace std;

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

int main()
{
    int D,G;
	cin >> D >> G;
	vector<int> pbs(D+1, 0), bonus(D+1, 0);
	for(int i=1; i<=D; i++){
		cin >> pbs[i] >> bonus[i];
	}
	vector< vector <int> > dp(D+1, vector<int>(1010, 0));//total[d][i]:d番目の問題まででi問以下を使って実現することができる最高点
	for(int d=1; d<=D; d++){
		for(int i=1; i<=1000; i++){
			for(int j=0; j<pbs[d]; j++){
				if(i-j<0) continue;
				dp[d][i]=max(dp[d][i], dp[d-1][i-j]+j*d*100);
			}
			if(i-pbs[d]>=0) dp[d][i]=max(dp[d][i], dp[d-1][i-pbs[d]]+d*100*pbs[d]+bonus[d]);
		}
	}
	for(int i=0; i<=1000; i++){
		if(dp[D][i]>=G){
			cout << i << endl;
			break;
		}
	}
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    vector<ll> A(3);
    REP(i,3)cin >> A[i];
    sort(ALL(A));
    int sum = A[0]+A[1]+A[2];
    if(A[0] == A[1] && A[1] == A[2]){
        cout << (A[0]%2?0:-1) << "\n";
    }else{
        for(int i = 0;;i++){
            if(A[0]%2 == 0&&A[1]%2 == 0&&A[2]%2 == 0){
                REP(l,3)A[l] = (sum - A[l])/2;
            }else{
                cout << i << "\n";
                break;
            }
        }
    }
}

Measured memory_bytes: 256
#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;
    cin >> N;
    vector<int> A(N);
    rep(i,N){
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());
    cout << A.at(N-1) - A.at(0) << endl;
}

Measured memory_bytes: 384
#include<iostream>

#include<string>

using namespace std;

int main(){

  int a,b,c,d,e,f,g,h;
  cin>>a>>b>>c>>d>>e>>f>>g>>h;



  if(a+b+c+d>=e+f+g+h){cout<<a+b+c+d<<endl;}
  else{cout<<e+f+g+h<<endl;}


  return 0;
}

Measured memory_bytes: 3104
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  rep(i,1000){
    if(i%2==0){
      c-=b;
      if(c<=0){
        cout<<"Yes"; return;
      }
    }
    else{
      a-=d;
      if(a<=0){
        cout<<"No";
        return;
      }
    }
  }
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long int ll;

int main() {

    ll curpos = 0;
    ll X;

    cin >> X;

    int ans = 0;
    ll delta = 1;
    while (curpos < X) {
        curpos += delta;
        ++delta;
        ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_N 100
#define MAX_M (MAX_N * MAX_N)

typedef struct EDGE {
	int to;
	struct EDGE *next;
} edge;

int size;
edge buff[MAX_M];
edge *adj[MAX_N];

void add_edge(int u, int v) {
	edge *e = buff + size++;
	e->to = v;
	e->next = adj[u];
	adj[u] = e;
}

typedef int data_t;
data_t queue[MAX_N];
int head, tail;

void enqueue(data_t data) {
	queue[tail++] = data;
}

data_t dequeue() {
	return queue[head++];
}

bool empty() {
	return head == tail;
}

int dist[MAX_N];

void bfs(int s) {
	edge *e;

	memset(dist, -1, sizeof(dist));
	dist[s] = 0;
	enqueue(s);

	while(!empty()) {
		const int u = dequeue();
		for(e = adj[u]; e != NULL; e = e->next) {
			if(dist[e->to] == -1) {
				dist[e->to] = dist[u] + 1;
				enqueue(e->to);
			}
		}
	}
}

int main() {
	int n;
	int u, k;
	int i, j;
	int v;

	scanf("%d", &n);
	for(i = 0; i < n; ++i) {
		scanf("%d %d", &u, &k);
		for(j = 0; j < k; ++j) {
			scanf("%d", &v);
			add_edge(u - 1, v - 1);
		}
	}

	bfs(0);
	for(u = 0; u < n; ++u) {
		printf("%d %d\n", u + 1, dist[u]);
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 604
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//Dijkstra法
struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;

void Dijkstra(int s, vector<vector<edge>>& g, vector<ll>& d) {
	priority_queue<P, vector<P>, greater<P>> q;
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	q.push(P{ 0,s });

	while (!q.empty()) {
		P p = q.top(); q.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P{ d[e.to] , e.to });
			}
		}
	}
}

//#.###
//#.#.#
//#.#.#
//#.#.#
//###..
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> m(H);
	for (int i = 0; i < H; i++) {
		cin >> m[i];
	}
	vector<vector<edge>> g(H * W + 1);
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		if (i != H - 1) {
			if (m[i][j] == '.' && m[i + 1][j] == '#')g[i * W + j].push_back({ (i + 1) * W + j,1 });
			else g[i * W + j].push_back({ (i + 1) * W + j,0 });
		}
		if (j != W - 1) {
			if (m[i][j] == '.' && m[i][j + 1] == '#')g[i * W + j].push_back({ i * W + j + 1,1 });
			else g[i * W + j].push_back({ i * W + j + 1,0 });
		}
	}
	if (m[0][0] == '#')g[H * W].push_back({ 0, 1 });
	else g[H * W].push_back({ 0, 0 });
	vector<ll> d;
	Dijkstra(H * W, g, d);
	cout << d[H * W - 1] << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * @author Bhavya Karia
 * created on 31/05/20
 */
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();
        int b = s.nextInt();

        System.out.println(a*b);
    }
}


Measured memory_bytes: 35740
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  n = int(input())
  if n%1000 == 0:
    print(0)
  else:
    print(1000 - n%1000)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 9164
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a=n0()
print(a+a**2+a**3)

Measured memory_bytes: 9228
import numpy as np
from numba import jit


@jit
def gcd(K):
    ans = 0

    for x in range(1, K + 1):
        for y in range(1, K + 1):
            for z in range(1, K + 1):
                ans += np.gcd(np.gcd(x, y), z)

    return ans


def main():
    K = int(input())

    print(gcd(K))


if __name__ == "__main__":
    main()


Measured memory_bytes: 110248
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  ll ans = 0;
  ans += n;
  ans += n * n;
  ans += n * n * n;
  cout << ans << endl;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define rof_(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N;
set< pii > tops[1 << 20];

void topInsert(int f, int t) {
	for (pii p : tops[f]) tops[t].insert(p);
	while (tops[t].size() > 2) tops[t].erase(tops[t].begin());
}

int main() {
	cin >> N;
	for_(i,0,(1<<N)) {
		int a;
		cin >> a;
		tops[i] = set< pii >();
		tops[i].insert(pii(a, i));
	}
	
	for_(S,0,(1<<N)) for_(i,0,N) {
		if ((S >> i) & 1) continue;
		topInsert(S, S | (1 << i));
	}
	
	lint ans = 0;
	for_(k,1,(1<<N)) {
		lint sum_k = 0;
		for (pii p : tops[k]) sum_k += p.first;
		maxUpdate(ans, sum_k);
		cout << ans << endl;
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//


Measured memory_bytes: 76928
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    int l = 0;
    int r = 0;
    for (int i = 0; i < m; i++) {
        if (a[i] < x) {
            l++;
        }
        else {
            r++;
        }
    }
    cout << min(l, r) << endl;
    return 0;
}

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

int main() {
  int n, a, b, ans = 0;
  cin >> n >> a >> b;
  
  for (int i = 1; i <= n; i++) {
    int x = 0, y = i;
    for (int j = 0; j < 5; j++) x += y % 10, y /= 10;

    if (a <= x && x <= b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int max_index = max_element(v.begin(), v.end()) - v.begin();
    int min_index = min_element(v.begin(), v.end()) - v.begin();
    int index = 0;
    if (abs(v[max_index]) >= abs(v[min_index])) {
        index = max_index;
    } else {
        index = min_index;
    }
    vector<pair<int, int>> res;
    for (int i = 0; i < n; i++) {
        if (i != index) {
            res.push_back(make_pair(index, i));
            v[i] += v[index];
        }
    }
    if (v[index] >= 0) {
        for (int i = 0; i < n - 1; i++) {
            res.push_back(make_pair(i, i + 1));
            v[i + 1] += v[i];
        }
    } else {
        for (int i = n - 2; i >= 0; i--) {
            res.push_back(make_pair(i + 1, i));
            v[i] += v[i + 1];
        }
    }
    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }
}


Measured memory_bytes: 3640
#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;
  cin >> N;

  vector<pair<int,int>> A(N);
  rep(i, N) {
    int input; 
    cin >> input;
    A[i] = make_pair(input,i+1);
  }
  sort(A.begin(),A.end());
  rep(i, N) {
    int ans = A.at(i).second;
    cout << ans << ' ';
  }
  return 0;
}

Measured memory_bytes: 1536
def judge_bingo(m,a):
    sum_d1 = 0
    sum_d2 = 0
    for i in range(m):
        sum_h = 0
        sum_v = 0
        for j in range(m):
            sum_h += a[i][j]
            sum_v += a[j][i]
        
        if sum_h==3 or sum_v==3:
            return True
        sum_d1 += a[i][i]
        sum_d2 += a[i][-i-1]
        
    if sum_d1==3 or sum_d2==3:
        return True
    else:
        return False
    

if __name__ == "__main__":
    m = 3
    card = [[0]]*m
    bingo = [[0]*m for i in range(m)]
    for i in range(m):
        card[i] = list(map(int,input().split()))
    n = int(input())
    nums = []
    for i in range(n):
        nums.append(int(input()))
        
    sum_h = [0]*m
    for num in nums:
        for i in range(m):
            for j in range(m):
                if card[i][j]==num:
                    bingo[i][j] = 1
    if judge_bingo(m,bingo):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int s2i(string s){
  stringstream ss(s);
  int x;ss>>x;
  return x;
}
signed main(){
  string s,b,b1,b2,b3="";cin>>s;
  int i,j,k,l;
  bool u[10]={},u2[10]={};
  b=(((s[0]-'0'+5)%10)+'0');
  u[(s[0]-'0'+5)%10]=1;
  for(i=1;i<s.size();i++){
    for(j=0;j<10;j++) u2[j]=u[j];
    for(l=0;l<10;l++){
      if(u[(s[i]-'0'+10+l)%10]) continue;
      b2=b;
      b2+=(((s[i]-'0'+10+l)%10)+'0');
      u[((s[i]-'0'+10+l)%10)]=1;
      for(j=i+1;j<s.size();j++){
	k=9;while(u[k]) k--;u[k]=1;
	b2+=(k+'0');
      }
      k=pow(10,s.size());
      if(b3!=""){
	if(((min(abs(s2i(s)-s2i(b2)),abs(k-abs(s2i(s)-s2i(b2)))) ==
	     min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3)))))&&s2i(b2)<s2i(b3))
	   ||(min(abs(s2i(s)-s2i(b2)),abs(k-abs(s2i(s)-s2i(b2)))) >
	      min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3))))) ) b3=b2;
      }else b3=b2;
      for(j=0;j<10;j++) u[j]=u2[j];
      b2=b;
      b2+=(((s[i]-'0'+10+l)%10)+'0');
      u[((s[i]-'0'+10+l)%10)]=1;
      for(j=i+1;j<s.size();j++){
	k=0;while(u[k]) k++;u[k]=1;
	b2+=(k+'0');
      }
      k=pow(10,s.size());
      if(b3!=""){
	if(((min(abs(s2i(s)-s2i(b2)),abs(k-abs(s2i(s)-s2i(b2)))) ==
	     min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3)))))&&s2i(b2)<s2i(b3))
	   ||(min(abs(s2i(s)-s2i(b2)),abs(k-abs(s2i(s)-s2i(b2)))) >
	      min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3))))) ) b3=b2;
      }else b3=b2;
      for(j=0;j<10;j++) u[j]=u2[j];
    }
    //cout << b3 << endl;
    if(!u[s[i]-'0']){
      b+=s[i];u[s[i]-'0']=1;
    }else{
      b=b3;
      break;
    }
  }
  if(b3!=""){
    if(((min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3)))) ==
	 min(abs(s2i(s)-s2i(b)),abs(k-abs(s2i(s)-s2i(b)))))&&s2i(b3)<s2i(b))
       ||(min(abs(s2i(s)-s2i(b3)),abs(k-abs(s2i(s)-s2i(b3)))) >
	  min(abs(s2i(s)-s2i(b)),abs(k-abs(s2i(s)-s2i(b))))) ) b=b3;
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,k,i;
  cin>>n>>m;
  vector<int> vec(n+1); 
  for( i=0; i<n+1; i++){
    vec.at(i)=1;
  }
  for ( i = 0; i < m; i++) {
    cin>>k;
    vec.at(k)=0;
    
  }
  for(i=2; i<n+1; i++){
    if(vec.at(i)==0){
    }
    else{
      vec.at(i)=(vec.at(i-1)+vec.at(i-2))%1000000007;
    }
  }
  cout<<vec.at(n);
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

struct Card {
	char name;
	int n;
};

Card newC(char name, int n){
	Card *dc = new Card;
	dc->name = name; dc->n = n;
	return *dc;
}

int Partition(Card *A, int p, int r){
	int x = A[r].n;
	int i = p-1;
	for(int j=p; j<r; j++){
		if(A[j].n<=x){
			i = i+1;
			Card k = A[j];
            A[j] = A[i]; A[i] = k;
		}
	}
	Card k = A[r];
	A[r] = A[i+1]; A[i+1] = k;
	return i+1;
}

void Quicksort(Card *A, int p, int r){
	if(p<r){
		int q = Partition(A, p, r);
		Quicksort(A, p, q-1);
		Quicksort(A, q+1, r);
	}
}

bool comp(Card& a, Card& b){
	if(a.n <= b.n){
		return true;
	}
	return false;
}
bool eq(Card& a, Card& b){
	return (a.n==b.n)&&(a.name==b.name);
}
int binst(Card& key, Card* A, int s, int e){
    if(e - s <= 1){
		if(s < e){
			if(eq(A[s],key)) return s;
			if((e >= 0) && eq(A[e],key)) return e;
        } else {
			if((e >= 0) && eq(A[e],key)) return e;
			if(eq(A[s],key)) return s;
		}
		return -1;
    }
    int mid = (s+e)/2;
    if(A[mid].n==key.n){
		int c = mid, k=mid;
		if(eq(A[mid], key)) return mid;
		while(1){
			c--;
			if(c<0 || A[c].n!=key.n) break;
			if(eq(A[c], key)) return c;
		}
		while(1){
			k++;
			if(k>e || A[k].n!=key.n) break;
			if(eq(A[k],key)) return k;
		}
		return -1;
	}
    if(comp(A[mid], key)){
        return binst(key, A, mid+1, e);
    } else {
        return binst(key, A, s, mid-1);
    }
}


int main(){
	int n;
	map<int,int> mp;
	cin >> n;
	
	Card *A,*B;
	int *a,*b;
	A = new Card[n];
	B = new Card[n];
	for(int i=0;i<n;i++){
		char cd; int num;
		scanf(" %c %d",&cd,&num);
		A[i] = newC(cd, num);
		B[i] = newC(cd, num);
	}
	Quicksort(A,0,n-1);
	bool f = true;
	for(int i=0;i<n;i++){
		int id = binst(B[i],A,0,n-1);
		int p = A[id].n;
		if( mp[p]==0 || mp[p]<id) mp[p] = id;
		else f = false;
	}
	if(f) printf("Stable\n");
	else printf("Not stable\n");
	for(int i=0;i<n;i++){
		printf("%c %d\n",A[i].name,A[i].n);
	}
	return 0;
}

Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int n;cin >> n;
    vector<int> v(n);rep(i,n)cin >> v[i];

    map<int,int> m1;    // even
    map<int,int> m2;    // odd

    rep(i,n){
        if(i % 2 == 0)m1[v[i]]++;
        else m2[v[i]]++;
    }

    int a = 0;
    int b = 0;
    int a2 = 0;
    int b2 = 0;
    int a3 = 0;
    int b3 = 0;

    vector<int> ali;
    vector<int> bli;

    bool ok = false;

    for(auto t : m1){
        ali.push_back(t.S);
        if(a < t.S){
            a = t.S;
            a3 = t.F;
        }
    }

    
    
    for(auto t : m2){
        bli.push_back(t.S);
        if(b <= t.S){
            b = t.S;
            b3 = t.F;
        }
    }

    sort(rall(ali));
    sort(rall(bli));

    a2 = ali[1];
    b2 = bli[1];
    
    int ans = 0;
    if(a3 == b3){
        int ans1 = n - b - a2;
        int ans2 = n - a - b2;
        ans = min(ans1,ans2);
    }
    else{
        ans = n - a - b;
    }

    cout << ans << endl;


}


Measured memory_bytes: 5888
import java.util.Scanner;

//クラス名は必ずMainにする必要があります。



public class Main {
    public static void main(String args[] ) throws Exception {
		Scanner sc = new Scanner(System.in);
        int l = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int num = 0;

        for(int i = l; i <= r; i++){
            if(i % d == 0){
                num++;
            }
        }
        System.out.println(num);
 	}
}

Measured memory_bytes: 35532
import math
import sys
a,b=map(int,input().split())
a2=math.ceil(a/0.08)
a3=math.floor((a+1)/0.08)
if a2>a3:
    print("-1")
    sys.exit()
b2=math.ceil(b/0.1)
b3=math.floor((b+1)/0.1)
if b2>b3:
    print("-1")
    sys.exit()
if b2<a2:
    if a2<(b+1)/0.1:
        print(a2)
    else:
        print("-1")
if a2<b2:
    if b2<(a+1)/0.08:
        print(b2)
    else:
        print("-1")
if a2==b2:
    print(a2)


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll INF = 1LL << 60;

int N, E;
ll T;
ll x[100010];
ll dp[100010];

using Data = pair<ll, ll>;

priority_queue<Data, vector<Data>, greater<Data>> que, que2;
int piv;

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

	for (int i = 1; i <= N; ++i) {
		cin >> x[i];
		dp[i] = INF;
	}

	que.push(mp(T, x[1]));

	for (int i = 1; i <= N; ++i) {

		while (!que.empty()) {
			Data p = que.top();

			if (p.se * 2 + T < x[i] * 2) {
				que.pop();
				continue;
			}

			dp[i] = min(dp[i], p.fi);
			break;
		}

		while (piv < i && 2 * x[piv+1] + T <= 2 * x[i]) {
			que2.push(mp(dp[piv] - 2 * x[piv + 1] - x[piv], x[piv+1]));
			++piv;
		}

		if (que2.size()) {
			dp[i] = min(dp[i], que2.top().fi + x[i] * 2);
		}

		dp[i] += x[i];
		que.push(mp(dp[i]-x[i]+T, x[i+1]));
	}

	cout << dp[N] + E - x[N] << endl;

	return 0;
}

Measured memory_bytes: 4468
from math import log

N, K = map(int, input().split(" "))

sum_num = 0
for i in range(1, N+1):
    count = 0
    while i < K:
        i *= 2
        count += 1
    sum_num += 1 / 2**count
    # print(count, sum_num)

print(sum_num / N)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int ans = 0;
    REP(i, A, B) {
        string S = to_string(i);
        string T = S;
        reverse(T.begin(), T.end());
        if(S == T) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b,c;
    cin >> a >> b >> c;
    // スペース区切りの整数の入力
   
    // 文字列の入力
   
    // 出力
   if(a+b==c || a+c==b || b+c==a){
    
    cout <<  "Yes" << endl;
    
  }else{
    cout <<  "No" << endl;
  }
  
  return 0;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll mod = 1e9+7;

int main()
{
    ll N; cin >> N;
    vll A(N); rep(i, N) cin >> A[i];
    vll cnt(61, 0);

    rep(i, 61) {
        rep(j, N) {
            cnt[i] += ((A[j] & (1ll << i)) > 0);
        }
    }

    ll ans = 0;
    rep(i, 61) {
        ll a = cnt[i], b = N - cnt[i];
        //(ans += (((a * b) % mod) * ((1LL << i) % mod)) % mod) %= mod;
        ans = (ans + (((a * b % mod) * ((1LL << i) % mod)) % mod)) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>

using namespace std;

int main(){

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

    int ans =1;
    for(int i=0;i<n;i++){
        ans = min(ans+k,2*ans);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
h = list(map(int,input().split()))
inf = 10 ** 10 + 7
dp = [inf] * N
dp[0] = 0
for i in range(N):
  for j in range(1, K + 1):
    if i + j < N:
      dp[i + j] = min(dp[i + j], abs(h[i + j] - h[i]) + dp[i])
print(dp[N - 1])

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

constexpr int64_t MOD = 1e9 + 7;
constexpr int64_t SIZE = 2e5;

int64_t modpow(int64_t x, int64_t n, int64_t m = 1) {
    return n == 0 ? m : modpow(x * x % MOD, n >> 1, n & 1 ? m * x % MOD : m);
}

int64_t comb(int64_t n, int64_t k) {
    if (n - k < k) k = n - k;

    int64_t res0 = 1, res1 = 1;
    for (int i = n; i > n-k; i--) {
        res0 = res0 * i % MOD;
    }
    for (int i = k; i > 0; i--) {
        res1 = res1 * i % MOD;
    }

    return res0 * modpow(res1, MOD-2) % MOD;
}

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

    cout << ((modpow(2, n) - 1 - comb(n, a) + MOD) % MOD - comb(n, b) + MOD) % MOD << endl;;
}


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

int main(){
    string s;
    cin>>s;
    int n = s.size();
    string T = "ATCG";
    int ans = 0;
    int now = 0;
    for(int i = 0; i < s.size();i++){
        bool isATCG = false;
        for(int j = 0; j < T.size(); j++){
            if(s[i] == T[j])isATCG = true;
        }
        if(!isATCG){
            now = 0;
        }
        else{
            now++;
            ans = max(now, ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
R = [int(input()) for _ in range(n)]

min_R = R[0]
max_D = R[1] - R[0]
for i in range(1, n):
    max_D = max(max_D, R[i] - min_R)
    min_R = min(min_R, R[i])

print(max_D)


Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 155555
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)
    #define Tra(i,u) for(int i=G.Start(u),__v=G.To(i);~i;i=G.Next(i),__v=G.To(i))
    #define p_b push_back
    #define sz(a) ((int)a.size())
    #define iter(a,p) (a.begin()+p)
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Rd(int cnt,...)
    {
        va_list args;
        va_start(args,cnt);
        F(i,1,cnt) 
        {
            int* x=va_arg(args,int*);R1(*x);
        }
        va_end(args);
    }

    int n;
    void Input()
    {
        R1(n);
    }
    void Add(int u,int v){printf("%d %d\n",u,v);}
    void Soviet()
    {
        F(i,0,20) if ((1<<i)==n)
        {
            puts("No");return;
        }
        puts("Yes");
        Add(1,2);
        Add(2,3);
        Add(3,n+1);
        Add(n+1,n+2);
        Add(n+2,n+3);
        Fs(i,5,n,i+=2)
        {
            Add(1+n,i);
            Add(i,i-1);
            Add(1+n,i-1+n);
            Add(i-1+n,i+n);
        }
        if (n%2==0)
        {
            int p2;
            F(i,0,20) if ((1<<i)<n) p2=(1<<i);

            Add(n,p2+n);
            Add(2*n,n^p2^1);
        }


    }

    #define Flan void
    Flan IsMyWife()
    {
        Input();
        Soviet();
    }
}
int main()
{
    Flandre_Scarlet::IsMyWife();
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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 namespace std;

struct edge{int from,to,cost;};
class GraphD{
public:
    int V,E;
    vector<vector<edge>> G;
    vector<int> dist;
    GraphD(int v, int e){
        V=v; E=e;
        G.resize(V);
    }
    void dijkstra(int s){
        dist=vector<int>(V,INF);
        dist[s]=0;
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top(); que.pop();
            int v=p.S;
            if(dist[v]<p.F)continue;
            rep(i,G[v].size()){
                edge e=G[v].at(i);
                if(chmin(dist[e.to],dist[v]+e.cost))que.push(P(dist[e.to],e.to));
            }
        } 
    }
};

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

    int n,m,s,t; cin>>n>>m>>s>>t;
    s--; t--;
    GraphD S(n,m),G(n,m);
    rep(i,m){
        int u,v,a,b; cin>>u>>v>>a>>b;
        u--; v--;
        edge e; e.from=u; e.to=v; e.cost=a;
        S.G[e.from].push_back(e);
        swap(e.from,e.to);
        S.G[e.from].push_back(e);
        e.cost=b;
        G.G[e.from].push_back(e);
        swap(e.from,e.to);
        G.G[e.from].push_back(e);        
    }

    S.dijkstra(s);
    G.dijkstra(t);

    //n-1,n-2,...,1,0
    vector<int> vec(n);
    int ans=INF;
    for(int i=n-1; i>=0; i--){
        chmin(ans,S.dist[i]+G.dist[i]);
        vec.at(i)=ans;
    }
    rep(i,n)cout<<1000000000000000-vec.at(i)<<endl;

}

Measured memory_bytes: 21888
N, K = map(int, input().split())

mod = 1000000007


def sum(a, b):
    r = (a+b)*(b-a+1) / 2
    return int(r) if r < mod else int(r % mod)


res = 0
for i in range(K, N+2):
    num_l = sum(0, i-1)
    num_r = sum(N-i+1, N)
    res += (num_r - num_l + 1)

print(res % mod)


Measured memory_bytes: 9064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int g = sc.nextInt();
            if (g == 0) {
                break;
            }
            int n=sc.nextInt();
            while(n-->0) {
                g+=sc.nextInt()-sc.nextInt();
            }
            System.out.println(g<=0?"OK":g);
        }
    }
}


Measured memory_bytes: 31420
#include<bits/stdc++.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;
 
typedef long long LL;
typedef vector<int> VI;
 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
 
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
 
vector<int>Z_Algorithm(const string&s) {
    int n=s.size();
    vector<int>z(n);
    int l = 0, r = 0;
    for (int i=1; i<n; i++) {
		if (i > r) {
		    l = r = i;
		    while (r<n && s[r-l] == s[r]) r++;
		    z[i] = r-l; r--;
		} else {
		    int k = i-l;
		    if (z[k] < r-i+1) z[i] = z[k];
		    else {
				l = i;
				while (r<n && s[r-l] == s[r]) r++;
				z[i] = r-l; r--;
		    }
		}
    }
    return z;
}
char buf[500011];
string S, T;
 
int nxt[61][500011];
 
void MAIN() {
    scanf("%s", buf);
    S = buf;
    scanf("%s", buf);
    T = buf;
 
    string g = T + S + S;
    while (g.size() < 2*T.size() + S.size()) g += S;
 
    memset(nxt, -1, sizeof nxt);
    VI Z = Z_Algorithm(g);
    REP (i, S.size()) {
		if (Z[T.size()+i] >= (int)T.size()) {
		    nxt[0][i] = (i + T.size()) % S.size();
		}
    }

    REP (t, 60) REP (i, S.size()) {
		int a = nxt[t][i];
		if (a >= 0) {
		    nxt[t+1][i] = nxt[t][nxt[t][i]];
		}
    }

    REP (i, S.size()) if (nxt[60][i] >= 0) {
		puts("-1");
		return;
    }
    LL ans = 0;
    REP (i, S.size()) {
	LL tmp = 0;
	int pos = i;
	for (int t=61; t--;) if (nxt[t][pos] >= 0) {
	    pos = nxt[t][pos];
	    tmp += 1LL<<t;
	}
 
	amax(ans, tmp);
    }
 
    printf("%lld\n", ans);
}
 
int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

Measured memory_bytes: 130604
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    double x, y;
    int C;
    cin >> x >> y >> C;

    double th = C * M_PI / 180.0;
    double S = (x * y / 2) * sin(th);
    double L = x + y + sqrt( pow(x, 2) + pow(y, 2) - 2 * x * y * cos(th) );
    double h = y * sin(th);

    cout << fixed << setprecision(5)
         << S << endl
         << L << endl
         << h << endl;

    return 0;
}

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

void negative() {
	cout << "-1 -1 -1" << endl;
}

void positive(int a, int b, int c) {
	cout << a << " " << b << " " << c << endl;
}

int main() {
	int N, Y;
	cin >> N >> Y;
	int Yd = Y / 1000;
	if (Yd < N || Yd > 10 * N) {
		negative();
		return 0;
	}

	int E = Yd - N;
	int C = floor(-2 * E / 9.0);
	if ((double)C >= -1 * E / 4.0 && (double)C >= -1 * Yd / 5.0) {
		positive(4 * C + E, -9 * C - 2 * E, 5 * C + Yd);
	} else {
		negative();
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,ans=1e9;
int dig(int x){
	int res=0;
	while(x>0)
		res+=x%10,x/=10;
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	int a;
	cin>>n;
	for(a=1;a<n;a++)
		ans=min(ans,dig(a)+dig(n-a));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 a, b, c, d;
  std::cin >> a >> b >> c >> d;
  std::cout << (std::abs(a - c) <= d || (std::abs(a - b) <= d && std::abs(b - c) <= d) ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, d, a;
    cin >> n >> d >> a;
    vector<P> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
        v[i].second = v[i].second / a + (v[i].second % a > 0);
    }
    sort(all(v));
    ll sum = 0, res = 0;
    queue<P> q;
    for (int i = 0; i < n; i++) {
        while (!q.empty()) {
            if (q.front().first + 2LL * d < v[i].first) {
                sum -= q.front().second;
                q.pop();
            } else {
                break;
            }
        }
        ll t = max(0LL, v[i].second - sum);
        sum += t;
        res += t;
        q.push(P(v[i].first, t));
    }
    cout << res << '\n';
}


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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF (1<<30)
#define bt (5)

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

	if (B - A == 0) {
		cout << B << endl;
		return 0;
	}

	vector<ll> cntA, cntB;
	ll a = A, b = B+1;
	for (ll i = 2; i < pow(2,60); i*=2) {
		ll c;
		//cout << a <<" "<< i << endl;
		c = a/i * (i/2);
		if ((a % i) > i/2) {
			c += (a%i) - i/2;
		}
		cntA.push_back(c);
	}
	for (ll i = 2; i < pow(2, 60); i *= 2) {
		ll c;
		c = b / i * (i/2);
		//cout << b <<" "<< i << endl;
		if ((b % i) > i/2) {
			c += (b%i) - i/2;
		}
		cntB.push_back(c);
	}
	ll j=1;
	ll ans=0;
	for (ll i = 0; i < cntB.size(); i++) {
		if(cntA.size() < i) cntA.push_back(0);
		if ((cntB[i] - cntA[i]) % 2 == 0) {
			
		}
		else {
			ans += j;
		}
		j *= 2;
		//cout << cntA[i] <<" "<< cntB[i] << endl;
	}

	cout << ans << endl;
}


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

main(){
    vector<int> n(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(),n.end());
    cout << n[0] << " " << n[1] << " " << n[2] << endl;
}


Measured memory_bytes: 3152
/*

	メモ：10000番目の素数は104,729
	∴サイズは105,000あれば良い。

*/

#include <stdio.h>
#include <stdbool.h>

#define SIZE 105000

void makePrime();

bool prime[SIZE];
int prime2[SIZE];

int main(){
	
	int i=0;
	int sum;
	int n;
	
	makePrime();
	
	while(1){
		
		scanf("%d", &n);
		
		if(n==0){
			
			break;
			
		}
		
		sum = 0;
		
		for(i=1; i<=n; i++){
			
			sum += prime2[i];
			
		}
		
		printf("%d\n", sum);
		
	}
	
	return 0;
	
}


void makePrime(){
	
	int i, k;
	int idx = 2;
	
	prime[0] = 0;
	prime[1] = 0;
	
	for(i=2; i<SIZE; i++){
		
		if(i%2 == 1){
			prime[i] = 1;
		}
		
	}
	
	
	prime[2] = 1;
	
	prime2[1] = 2;
	
	
	for(i=3; i<SIZE; i+=2){
		
		if(prime[i]){
			
			prime2[idx] = i;
			idx++;
			
			for(k=i+i; k<SIZE; k+=i){
				
				prime[k] = 0;
				
			}
			
		}
		
	}
	
}

Measured memory_bytes: 740
#include<bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 15
#define MOD 1000000007
#define inp freopen("input.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int vet[3];
    for(int i=0;i<3;i++){
        cin>>vet[i];
    }
    sort(vet,vet+3);
    cout<<vet[1]+vet[0]<<endl;
    return 0;
}   


Measured memory_bytes: 256
n = int(input())
h_list = list(map(int, input().split() ) )

ans = True
for i in range(1, len(h_list) ):
    if h_list[-i] - h_list[-i-1] >= 0:
        continue
    elif h_list[-i] - h_list[-i-1] == -1:
        h_list[-i-1] -= 1
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63856
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
set_t ost[26];
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, q;
	string s;
	cin >> n >> s >> q;
	for(int i=0; i<n; i++) {
		s[i] -= 'a';
		ost[s[i]].insert(i);
	}
	for(int z=0; z<q; z++) {
		int t;
		cin >> t;
		if(t == 1) {
			int i;
			char c;
			cin >> i >> c;
			i--;
			c -= 'a';
			ost[s[i]].erase(i);
			s[i] = c;
			ost[s[i]].insert(i);
		} else {
			int l, r;
			cin >> l >> r;
			l--, r--;
			int cnt = 0;
			for(int i=0; i<26; i++) {
				cnt += (ost[i].order_of_key(l) != ost[i].order_of_key(r+1));
			}
			cout << cnt << '\n';
		}
	}
}

Measured memory_bytes: 32028