akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
全探索でいけるのかな
2点間のとりかたnC2
そのくみあわせ、nC2*nCk
すくなくとも1000^4むりじゃね
効率化･･･
基本的には数が大きいもの同士？
4 2
2 5 2 5

2,4,5,7,9,10,12,14
2=   10
4=  100
5=  101
7=  110
9= 1001
10=1010
12=1100
14=1110

12+14=1100=12

2,5
2= 10
5=101
7=111
和の時点で法則、あるっちゃあるか
1000個とかになると、コントロールきつい

一番外側のBITを満たすものがあるか調べる
すくなくともnC2通り全部は可能
成立しないなら次の桁
最大何桁になる、13桁くらいならnC2*10でいけるか
対象をしぼる必要あるかな
あるか
どうやって抜こう
queueのコピーってできるかな
  queue<ll> A,B;
  A.emplace(1);
  B=A;
  cout<<B.front()<<endl;
でるんかい
true=1
13桁じゃないわ
10^13=2^? 43
*/
int main(){
  ll N,K,ans=0; cin>>N>>K;
  queue<ll> A,B,W;//Aは対象、Bはバックアップ用、Wは作業
  vector<ll> C(N+1,0);
  for(ll i=1; i<=N; i++) cin>>C[i];
  for(ll i=1; i<=N; i++) C[i]=C[i-1]+C[i];
  for(ll i=1; i<=N; i++) for(ll j=0; j<i; j++) A.emplace(C[i]-C[j]);
  //外側のBITから全探索
  B=A;
  for(ll i=50; i>=0; i--){
    A=B;
    queue<ll> emp;
    W.swap(emp);
    while(!A.empty()){
      ll n=A.front(); A.pop();
      if(1&n>>i) W.emplace(n);
    }
    if(W.size()<K) continue;
    //必要量があるとき
    B=W;
  }
  //最後BかCに必要なくみあわせがはいってる
  if(!B.empty()){
    ans=B.front();
    B.pop();
  }
  while(!B.empty() && --K>0){
    ans=ans&B.front();
    B.pop();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8448
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N;
	cin >> N;
	VI a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}

	int j = 0;
	int count = 0;
	FOR(i, 0, 100002) {
		count++;
		if (a[j] == 2) {
			break;
		}
		j = a[j] - 1;
	}
	cout << (count == 100002 ? -1 : count) << endl;

	return 0;
}

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

int main(){
  int n; cin >> n;
  vector<tuple<string , int , int>> S;
  for(int i=0; i<n; i++){
    string s; int p;
     cin >> s >> p;
    S.push_back(make_tuple(s , 100-p , i+1));}
  sort(S.begin(),S.end());
  
  for(auto x:S)
  {cout << get<2>(x) << endl;}
    
}

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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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


int a[4];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i =0;i<3;++i)
        cin>>a[i];
    sort(a,a+3);
    bool f = a[0]==5&&a[1]==5&&a[2]==7;
    cout<<(f?"YES\n":"NO\n");
}

Measured memory_bytes: 3512
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      for(int i=0;i<n;i++)a[i]=sc.nextInt();
      int k = 0;
      int cnt = 1;
      for(int i=0;i<n;i++){
        if(a[i]==cnt){
          cnt++;
        }
      }
      if(cnt==1)System.out.println(-1);
      else System.out.println(n-cnt+1);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 87096
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

double T,X;

int main(){
    cin>>T>>X;

    cout<<setprecision(10)<<T/X<<endl;
}

Measured memory_bytes: 256
fn main() {
	let mut s = [[[0; 10]; 3]; 4];

	let n = readLine::<usize>();
	for _ in 0..n {
		let xs = read_vec::<i32>();
		let(b, f, r, v) = (xs[0] as usize, xs[1] as usize, xs[2] as usize, xs[3]);
		s[b - 1][f - 1 ][r - 1] += v;
	}
	for i in 0..4 {
		for j in 0..3 {
			print_array(s[i][j]);
		}
		if i < 3 {
			println!("####################");
		}
	}
}

fn print_array(xs: [i32; 10]) {
	for i in 0..9 {
		print!(" {}", xs[i]);
	}
	println!(" {}", xs[9]);
}

fn readLine<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5024
import sys
import numpy as np  # noqa
import numba  # noqa
from numba import njit, b1, i4, i8, f8  # noqa

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, ), cache=True)
def main(K):
    for i in range(K):
        if i == 0:
            a = 7 % K
        else:
            a = (a * 10 + 7) % K
        if a == 0:
            return i + 1

    return -1


K = int(readline())

print(main(K))


Measured memory_bytes: 106380
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

int main(){
  int n,m;
  double tmp=0;
  int sum=0,ava=0,cou=0;
  while(scanf("%d,%d",&n,&m) != EOF){
    sum += n * m;
    tmp += m;
    cou++;
  }
  ava = round(tmp/cou);
  cout << sum << endl << ava << endl;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>

using namespace std;
typedef long long ll;
const int maxN = 100010;
int a[maxN];
ll CA[2*maxN],CB[2*maxN]; 
int main()
{
	int n,m; 
	scanf("%d%d",&n,&m); 
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l,r;
	ll ans;
	for(int i=1;i<n;i++)
	{
		l = a[i];
		r = a[i+1];
		if(r<l)
			r = r+m;
		ans += r-l;
		if(l+2<=r)
		{
			CA[l+2]++;
			CB[l+2] -= (l+1);
			CA[r+1]--;
			CB[r+1] += (l+1);
		}
	}
	for(int i=1;i<=m*2;i++)
	{
		CA[i] += CA[i-1];
		CB[i] += CB[i-1];
	}
	ll tmp,cnt = 0;
	for(int i=1;i<=m;i++)
	{
		tmp = CA[i]*i + CA[i+m]*(i+m) + CB[i] + CB[i+m];
		if(tmp > cnt)
			cnt = tmp;
	}
	ans -= cnt;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3712
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)44e15;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	llint n;cin>>n;
	int a=1,b=n-1;
	string as,bs;
	cout<<1<<endl;cin>>as;
	if(as=="Vacant"){RE;}
	cout<<n-1<<endl;cin>>bs;
	if(bs=="Vacant"){RE;}
	if(as!=bs){cout<<0<<endl;cin>>as;RE;}
	while(-1){
		int ter;
		ter=(a+b)/2;cout<<ter<<endl;
		string ret;cin>>ret;
		if(ret=="Vacant"){RE;}
		if((ret==as)==(a%2==ter%2)){a=ter;as=ret;}
		else{b=ter;bs=ret;}
	}
	return 0;
}


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

		using namespace std;

		int main()
		{ios_base::sync_with_stdio(false);
		    cin.tie(NULL);
		    int n,m;
		    long long int ma=-1;
		    cin>>n>>m;
		    long long int a[n+1][3];
		    for(int i=1;i<=n;i++)
		    {
		    	for(int j=0;j<3;j++)
		    	{
		    		cin>>a[i][j];
		    	}	
		    }
		    for(int j=0;j<8;j++)
		    {
		    	vector<long long int > v;
		    for(int i=1;i<=n;i++)
		    {
		    	long long int s=0;
		    	for(int k=0;k<3;k++)
		    	{
		    		if(j/(1<<k)%2==0)
		    			s+=a[i][k];
		    		else
		    			s-=a[i][k];
		    	}
		    	v.push_back(s);
		    	
		    }
		    sort(v.rbegin(),v.rend());
		    long long int ans=0;
		    for(int i=0;i<m;i++)
		    {
		    	ans+=v[i];
		    }
		    ma=max(ma,ans);
			}
			cout<<ma<<endl;
			return 0;

		}

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

int main(){
	string s,t;
	cin >> s >> t;
	map<char, char> mp1;
	map<char, char> mp2;
	for (char c = 'a'; c <= 'z'; ++c) {
		mp1[c] = 'A';
		mp2[c] = 'A';
	}
	bool ok = true;
	rep(i,s.size()){
		if(mp1[s[i]] != 'A' && mp1[s[i]] != t[i]) ok = false;
		if(mp2[t[i]] != 'A' && mp2[t[i]] != s[i]) ok = false;
		mp1[s[i]] = t[i];
		mp2[t[i]] = s[i];
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 776
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
		int memo[32][1 << 16];
int main() {
	bitset<16>bs;
	while (1) {
		int N, C; cin >> N >> C;
		if (!N)break;
		vector<bitset<16>>ls;
		for (int a = 0; a < N; ++a) {
			bitset<16>bs;
			for (int i = 0; i < 16; ++i) {
				int aa; cin >> aa;
				bs[i] = aa;
			}
			ls.push_back(bs);
		}
		vector<bitset<16>>ps;
		for (int a = 0; a < C; ++a) {
			bitset<16>bs;
			for (int i = 0; i < 16; ++i) {
				int aa; cin >> aa;
				bs[i] = aa;
			}
			ps.push_back(bs);
		}
		memset(memo, 0, sizeof(memo));
		for (int j = 0; j < N; ++j) {
			for (int i = 0; i < (1 << 16); ++i) {
				memo[j][i] = -1000000;
			}
		}
		
		memo[0][0] = 0;
		for (int t = 0; t < N; ++t) {
			for (int b = 0; b < (1 << 16); ++b) {
				bitset<16>bs(b);
				const int nowscore = memo[t][bs.to_ulong()];
				bs |= ls[t];
				for (auto p : ps) {
					int plus = (p&bs).count();
					int nexthash = (bs&(~p)).to_ulong();
					memo[t + 1][nexthash] = max(memo[t + 1][nexthash], nowscore + plus);
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < (1 << 16); ++i) {
			ans = max(ans, memo[N][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 11256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  const long double PI = 3.141592653589793238462643383279;
  long double r;
  cin >> r;
  cout << fixed << setprecision(6) << (long double)PI * r * r << " " << (long double)2 * PI * r << endl;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;

#define ll long long

int main(void) {

    ll H, W;
    cin >> H >> W;

    ll ans = ((H*W)+1)/2;
    if(H == 1 || W == 1) ans = 1;
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

  int N;

  cin >> N;

  if((N-7)%10==0 || (N/10-7)%10==0 || (N/100-7)%10==0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()



int R, C, K;
int v[3000][3000];

long long dp[3001][3001][4];



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

	cin >> R >> C >> K;
	rep(_, K) {
		int r, c, _v;
		cin >> r >> c >> _v;
		v[r - 1][c - 1] = _v;
	}

	long long ans = 0;
	dp[0][0][1] = v[0][0];
	rep(r, R)rep(c, C) rep(i, 4) {
		if (c + 1 < C) {
			dp[r][c + 1][i] = max(dp[r][c + 1][i], dp[r][c][i]);

			if (i < 3) dp[r][c + 1][i + 1] = max(dp[r][c + 1][i + 1], dp[r][c][i] + v[r][c + 1]);
		}
		if (r + 1 < R) {
			dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][i]);

			dp[r + 1][c][1] = max(dp[r + 1][c][1], dp[r][c][i] + v[r + 1][c]);
		}
		ans = max(ans, dp[r][c][i]);
	}

	cout << ans << endl;

	return 0;
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



signed main()
{
	//cin
	int n,m;cin>>n>>m;
	//dp table & inisialize
    vector<int> dp(n+1, 0);

	vector<bool> issafe(n+1, true);
	for(int i = 0; i < m; ++i){
		int a; cin >> a;
		issafe[a] = false;
	}

	//inisial condition
	dp[0] = 1;
	if(issafe[1])
	dp[1] = 1;

	//loop
	for(int i = 2; i <= n; ++i){

		if(issafe[i-1]) dp[i] += dp[i-1];

		if(issafe[i-2]) dp[i] += dp[i-2];

		dp[i]%=MOD;
	}
	//cout
	cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
def main():
    k = int(input())
    init = 7%k
    an = [init]
    for _ in range(k):
        a = an[-1]
        an.append((10*a+7) % k)

    for ind, a in enumerate(an):
        if a==0:
            print(ind+1)
            return
    print(-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 48544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<ll>a(n+1);
    vector<ll>b(n);
    rep(i,n+1){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    ll ans = 0;
    rep(i,n){
        if(a[i]<b[i]){
            ans+=a[i];
            b[i]-=a[i];
            if(b[i]>a[i+1]){
                ans+=a[i+1];
                a[i+1]=0;
            }
            else{
                ans+=b[i];
                a[i+1]-=b[i];
            }
        }
        else{
            ans+=b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(){
  char s;
  cin>>s;
  if(s=='A') cout<<'T'<<endl;
  else if(s=='T') cout<<'A'<<endl;
  else if(s=='C') cout<<'G'<<endl;
  else if(s=='G') cout<<'C'<<endl;
  return 0;
}


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

int W,H,ans;
char grid[105][105];
bool flag[105][105];

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

void dfs(int x,int y,char c){
    grid[x][y]='.';
    for(int i=0;i<4;i++){
        int tx=x+dx[i],ty=y+dy[i];
        if(tx>=0&&tx<H&&ty>=0&&ty<W&&grid[tx][ty]==c){
            dfs(tx,ty,c);
        }
    }
}

int main(){
    while(true){
        cin>>H>>W;
        if(W==0&&H==0) break;

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                scanf(" %c",&grid[i][j]);
            }
        }
        ans=0;

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(grid[i][j]!='.'){
                    ans++;
                    dfs(i,j,grid[i][j]);
                }
            }
        }

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





Measured memory_bytes: 3628
import java.util.*;
import java.util.regex.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    int n = scanner.nextInt();
    scanner.nextLine();
    for (int ii = 0; ii < n; ii++) {
      String line = scanner.nextLine();
      Pattern pattern3 = Pattern.compile("Hoshino");
      Matcher matcher3 = pattern3.matcher(line);
      out += matcher3.replaceAll("Hoshina") + "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 17368
h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.bytes.map{|c| (c == "#".ord) ? 1 : 0}}
cnt = 0
[0, 1].repeated_permutation(h) do |x|
  m = []
  x.each_with_index do |y, i|
    if y == 0
      m << rows[i]
    else
      m << [0] * w
    end
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = []
    u.each_with_index do |v, l|
      if v == 0
        mc << m.transpose[l]
      end
    end
    cnt += 1 if mc.flatten.inject(:+) == k
  end
end
puts cnt

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	string s; cin >> s;
	if(s=="AAA" || s=="BBB"){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

D getExpectation(D x) {
   return perform(x)/x;
}

int main()
{
    Int ans=0;
        cin>>N;
        A.resize(N);
        for(auto &x:A) cin>>x;
        ans+=A.front();
        
        for(int i=0;i+1<N;++i){
            ans+=(A[i+1]>A[i] ? A[i+1]-A[i]:0);
        }
        cout<<ans<<"\n";
}

Measured memory_bytes: 26964
import itertools

n=int(input())
L=list(map(int,input().split()))
M=[]
N=[]

for v in itertools.combinations(L,3):
    M.append(list(map(int,v)))

if n==1 or n==2:
       print(0)
else :
    for i in range(len(M)):
        if M[i][0]==M[i][1] or M[i][0]==M[i][2] or M[i][1]==M[i][2]:
            continue
        if M[i][0]+M[i][1]>M[i][2] and M[i][0]+M[i][2]>M[i][1] and M[i][1]+M[i][2]>M[i][0]:
            N.append(M[i])
    print(len(N))

Measured memory_bytes: 29536
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int mod = 998244353;
// const int mod = 1e9 + 7;
struct mod_t {
  static int norm(int x) {
    return x + (x >> 31 & mod);
  }
  int x;
  mod_t() {  }
  mod_t(int v) : x(v) {  }
  mod_t(ll v) : x(v) {  }
  mod_t(char v) : x(v) {  }
  mod_t operator +(const mod_t &rhs) const {
    return norm(x + rhs.x - mod);
  }
  mod_t operator -(const mod_t &rhs) const {
    return norm(x - rhs.x);
  }
  mod_t operator *(const mod_t &rhs) const {
    return (ll) x * rhs.x % mod;
  }
};
const int MAXN = 1e5 + 10;
int n, m, k, ans[MAXN], cnt1[MAXN], cnt2[MAXN], cnts[MAXN], f[MAXN];
int find(int x) {
  return f[x] == x ? x : f[x] = find(f[x]);
}
inline void work() {
  n = rdint();
  m = rdint();
  k = rdint();
  For(i, n) {
    f[i] = i;
  }
  ms(cnt1);
  ms(cnt2);
  ms(cnts);
  For(i, m) {
    int a = rdint(), b = rdint();
    ++cnt1[a];
    ++cnt1[b];
    if(find(a) != find(b)) {
      f[find(b)] = find(a);
    }
  }
  For(i, n) {
    ++cnts[find(i)];
  }
  For(i, k) {
    int c = rdint(), d = rdint();
    if(find(c) == find(d)) {
      ++cnt2[c];
      ++cnt2[d];
    }
  }
  For(i, n) {
    ans[i] = cnts[find(i)] - cnt1[i] - cnt2[i] - 1;
  }
  For(i, n) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b ) {
	if(a>b)
		return a;
	else return b;
}
//vector<pair<int,int>> v(ma.begin(),ma.end());

ll mod = 1e9 + 7;
int main() {
	/*ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans = 1;
	for(ll i=0; i<n; i++) {
		//cout<<a[i]<<" ";
		if(ans<=1000000000000000000)
			ans = ans*a[i];
		else {
			ans = -1;
			break;
		}
	}
	if(ans > 1000000000000000000)
		ans = -1;
	cout<<ans;*/
	ll a;
	long double b;
	cin>>a>>b;
	ll c = a*b;
	cout<<c;
return 0;
}/*
8 -2 5 2 5 3 -30 6 9
0 -2 5 2 5 3 

a - b>0 and other max(nos)>a
*/

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,i,t=0;
	bool q=true;
	string a;
	cin>>a;
	if (a[0]!='A'){
		q=false;
	}
	for (i=2;i<a.size()-1;i++){
		if (a[i]=='C'){
			t++;
		}
	}
	if (t!=1){
		q=false;
	}
	for (i=1;i<a.size()-1;i++){
		t=a[i]-'0';
		if (t<43&&t!=19){
			q=false;
		}
	}
	t=a[a.size()-1]-'0';
	if (t<43){
		q=false;
	}
	if (q==false){
		cout<<"WA";
	}
	else {
		cout<<"AC";
	}
	return 0;
}

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

int main() {
  int H = 0, W = 0, k = 0, l = 0;
  cin >> H >> W;
  
  int tate = H, yoko = W;
  
  vector<vector<char>> a(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
   for (int j = 0; j < W; j++) {
     cin >> a.at(i).at(j);
   }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++){
      if (a.at(i).at(j) == '#') {
        break;
      }
      if (j == a.at(i).size() - 1) {
        tate--;
      }
    }
  }
  
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (a.at(j).at(i) == '#') {
        break;
      }
      if (j == a.size() - 1) {
        yoko--;
      }
    }
  }
  
  vector<vector<char>> b(tate, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') {
        for (int m = 0; m < W; m++) {
          b.at(k).at(m) = a.at(i).at(m);
        }
        k++;
        break;
      }
      if (j == a.at(i).size() - 1) {
        break;
      }
    }
  }
  
  vector<vector<char>> c(tate, vector<char>(yoko));
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < tate; j++) {
      if (b.at(j).at(i) == '#') {
        for (int m = 0; m < tate; m++) {
          c.at(m).at(l) = b.at(m).at(i);
        }
        l++;
        break;
      }
      if (j == b.size() - 1) {
        break;
      }
    }
  }
  
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < l; j++){
      cout << c.at(i).at(j);
    }
    cout << endl;
  }
}


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

w = [0]
w_total = 0
b = [0]
b_total = 0
for i in range(N):
    if S[i] == '#':
        w_total += 1
    w.append(w_total)
    if S[N - 1 - i] == '.':
        b_total += 1
    b.append(b_total)

ans = N + 1
for i in range(N + 1):
    ans = min(ans, w[i] + b[N - i])
print(ans)


Measured memory_bytes: 12808
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n,k;
  cin>>n>>k;
  vector<in> a(n);
  rep(i,n)
    cin>>a.at(i);
  for(int i=k+1;i<=n;i++){
    if(a.at(i-k-1)<a.at(i-1))
      Yes;
    else
      No;
  }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#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 repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, T;
    cin >> N >> T;
    vector<pair<ll, ll>> AB(N);
    rep(i, N) cin >> AB[i].first >> AB[i].second;
    sort(all(AB));

    vvl dp(N, vl(T, 0));
    rep(i, N - 1) {
        ll a, b;
        tie(a, b) = AB[i];
        rep(j, T) {
            if (j >= a)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    ll ans = 0;
    rep(i, N)
        ans = max(ans, dp[i][T - 1] + AB[i].second);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;
 
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define fr(i, st, n) for(int i = (int )st; i < (int )n; i++)
#define rfr(i, en, st) for(int i = (int )en; i >= (int )st; i--)
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
 
typedef long long int LL;
typedef pair< int, int> ii;
typedef vector< int> vi;
typedef vector< ii> vii;
typedef vector< vi> vvi;
 
const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
 // START FROM HERE




int main(int argc, char const *argv[])
{
	fastio;


	int n; cin >> n;
	vi h(n); fr(i,0,n) cin >> h[i];

// APPROACH 1
	// vi dp(n);

	// fr(i,1,n) {
	// 	dp[i] = dp[i-1] + abs(h[i-1]-h[i]);
	// 	if(i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i-2]-h[i]));
	// }
	// cout<<dp[n-1]<<endl;

// APPROACH 2

	vi dp(n);

	rfr(i,n-2,0) {
		dp[i] = dp[i+1] + abs(h[i]-h[i+1]);
		if(i+2<n) dp[i] = min(dp[i], dp[i+2] + abs(h[i]-h[i+2]));
	}
	cout << dp[0] << endl;



	return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b,c;
	cin>>a>>b>>c;
	c=c-(a-b);
	if(c<0)
		c=0;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int>P;
const int TIMES = 5;
int main(){
  int day;
  int cost[30];
  int satisfied[370][30];
  int i,j;
  priority_queue<P>pq_s[370];
  
  long long score=1000000;
  long long cost_sum=0;
  long long sub=0;
  int last[370]={0};
  
  //scanf("%d",&day);
  cin>>day;
  
  for(i=1;i<=26;i++){
    //scanf("%d ",&cost[i]);
    cin>>cost[i];
    cost_sum+=cost[i];
  }
  
  for(i=1;i<=day;i++){
    for(j=1;j<=26;j++){
      //scanf("%d ",&satisfied[i][j]);
      cin>>satisfied[i][j];
      pq_s[i].push(P(satisfied[i][j],j));
    }
  }
  
  //  int array[]={0,1,17,13,14,13};
  for(i=0;i<TIMES;i++){
    
  }
  for(i=1;i<=day;i++){
    //    int contest=(i+25)%26+1;
    int contest=(pq_s[i].top().first + 25)%26+1;
    printf("%d\n",contest);
    score+=satisfied[i][contest];
    sub+=cost_sum-(i-last[contest])*cost[contest];
    score-=sub;
    last[contest]=i;
  }
  //printf("%lld\n",score);
  return(0);
}

Measured memory_bytes: 3872
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <time.h>
#include <limits>
#include <math.h>
#include <climits>
#include <numeric>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <functional>
#include<unordered_map>
#include<unordered_set>

using namespace std;
const double pi=acos(-1.0);
//memset ( a , 0 , n * sizeof(ll) ) ;

#define 	boost  		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // don't use if small inpts
#define 	endl 		'\n'
#define 	sl(n) 		scanf("%lld",&n)
#define		mp 			make_pair
#define 	pb 			push_back
#define 	ppb 		pop_back
#define 	fi 			first
#define 	se 			second
#define 	ll 			long long
#define 	ull 		unsigned long long
#define 	pii 		pair<int, int>
#define 	f(i,a,b) 	for(ll i = (ll)(a); i < (ll)(b); i++)
#define 	rf(i,a,b) 	for(ll i = (ll)(a); i > (ll)(b); i--)
#define 	ms(a,b) 	memset((a),(b),sizeof(a))
#define 	max(a,b) 	((a>b)?(a):(b))
#define 	min(a,b) 	((a<b)?(a):(b))
#define 	vec(g1) 	int temp;cin>>temp;g1,push_back(temp);
#define 	abs(x) 		((x<0)?(-(x)):(x))
#define 	MAX 		1000005
#define 	inf 		LLONG_MAX
#define 	MIN 		INT_MIN

//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}
////****************************************************************************************************************************************************************************************************************////

int main(){
    int k,s;
    cin>>k>>s;
    ll ans=0;
    for(int i=0;i<=k;i++){
    	for(int j=0;j<=k;j++){
    		 int res= s-(i+j);
    		 if(res<=k && res>=0)ans++;
    	}
    }
    cout<<ans<<endl;

    return 0;
            }

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<pll> node;
};

Vertex V0[100005], V1[100005];
ll C0[100005], C1[100005];
ll C[100005];

int main() {
    ll N, M, S, T;
    cin >> N >> M >> S >> T;
    S--;
    T--;
    REP(i, M) {
        ll a, b, x, y;
        cin >> x >> y >> a >> b;
        x--;
        y--;
        V0[x].node.push_back(pll(y, a));
        V0[y].node.push_back(pll(x, a));
        V1[x].node.push_back(pll(y, b));
        V1[y].node.push_back(pll(x, b));
    }

    REP(i, N) {
        C0[i] = C1[i] = INF;
    }
    C0[S] = C1[T] = 0;

    {
        priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
        q.push(pll(S, 0));
        while (!q.empty()) {
            pll t = q.top();
            q.pop();
            if (C0[t.first] < t.second)
                continue;
            REP(i, V0[t.first].node.size()) {
                pll n = V0[t.first].node[i];
                ll cost = n.second + t.second;
                if (C0[n.first] <= cost)
                    continue;
                C0[n.first] = cost;
                q.push(pll(n.first, cost));
            }
        }
    }
    {
        priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
        q.push(pll(T, 0));
        while (!q.empty()) {
            pll t = q.top();
            q.pop();
            if (C1[t.first] < t.second)
                continue;
            REP(i, V1[t.first].node.size()) {
                pll n = V1[t.first].node[i];
                ll cost = n.second + t.second;
                if (C1[n.first] <= cost)
                    continue;
                C1[n.first] = cost;
                q.push(pll(n.first, cost));
            }
        }
    }

    REP(i, N) {
        C[i] = C0[i] + C1[i];
    }

    for (ll i = N - 2; i >= 0; --i) {
        C[i] = std::min(C[i], C[i + 1]);
    }

    REP(i, N) {
        cout << INF - C[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 19140
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
typedef long long ll;
 
ll N,M,K,L,A,B,C,T;
ll esta[3010];//急行駅の番号
 
 
vector<ll> vec;
 
inline ll updiv(ll a,ll b){
	return a%b ? a/b+1 : a/b;
}
 
int main(){
	cin>>N>>M>>K>>A>>B>>C>>T;
 
	for(int i=1;i<=M;i++) cin>>esta[i];
 
	L=K-M;
	ll res=0;
	for(int i=2;i<=M;i++){
		if(B*(esta[i]-1)>T) break;
		res++;
	}
 
	for(int i=1;i<M;i++){
		ll now_t=(esta[i]-1)*B;
		ll now_n=esta[i];
		if(now_t>T) break;
		ll cango=(T-now_t)/A;
		if(now_n+cango>=esta[i+1]-1){
			res+=(esta[i+1]-esta[i]-1);
			continue;
		}
		res+=cango;
 
		for(int j=1;j<=3010;j++){
			if(cango==0&&(T-now_t)<C) break;
			now_t+=C*(cango+1);
			now_n+=cango+1;
			if(now_t>T) break;
			cango=(T-now_t)/A;
			if(now_n+cango>=esta[i+1]-1){
				vec.push_back(esta[i+1]-now_n);
				break;
			}
			vec.push_back(cango+1);
		}
	}
	sort(vec.begin(),vec.end(),greater<ll>());
 
	L=min(L,(ll)vec.size());
	for(int i=0;i<L;i++){
		res+=vec[i];
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 68576
s,c = map(int,input().split())

if s >= c:
    #print("s>=c")
    scc = int(c/2)
    print(scc)
    exit()

if s < c:
    #print("s<c")
    scc = s
    cc = c-s*2
    scc += int(cc/4)
    print(scc)
    exit()


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

int N;
void next(string base, int num, int cs) {
  if (num == N) {
    cout << base << endl;
    return;
  }

  for (int i = 0; i < cs+1; i++) {
    char c = 'a' + i;
    int ncs = cs > i ? cs : i+1;
    next(base + c, num+1, ncs);
  }
}

int main() {
  cin >> N;
  next("", 0, 0);
}

Measured memory_bytes: 1536
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]
heru = [0 for _ in range(26)]
for i in s:
	targ = i
	for j in range(26):
		targ[j] -= heru[j]
	r = targ.index(max(targ))
	heru[r] -= c[r]
	print(r+1)


Measured memory_bytes: 74968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;cin>>n;
  int h[n];
  for(int i=0;i<n;i++)cin>>h[i];
  int ma=0;
  int ans=0;
  for(int i=0;i<n;i++){
    if(h[i]>=ma){
      ans++;
      ma=h[i];
    }
  }
  cout<<ans<<endl;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

ll mod=1e9+7;
ll dp[2001][2001] ;
ll C(int n, int i){
	if(dp[n][i]!=-1) return dp[n][i];
	if(n < i) return (dp[n][i]=0);
	if(n==i || i==0) return (dp[n][i]=1LL);
	else return (dp[n][i] = (C(n-1,i-1) + C(n-1,i))%mod);
	
}



int main(){
	startTime=clock();
	ll n,k;
	cin >> n >> k;
	FOR(i,2001)
		FOR(j,2001) dp[i][j]=-1;
	//cout << C(n,k);
	for(int i=1;i <=k;i++){
		cout << (C(k-1,i-1) * C(n-k+1,i))% mod <<"\n";
	}

	return 0;
}

Measured memory_bytes: 34920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;



int main() {

    

  int n,k;

  cn n>>k;

  ll mod=1000000000+7;
  ll sum=0;
  for (int i = k; i <=n ; ++i)
  {
  	   ll tm=i-1;

  	   ll sm=((tm+1)*tm)/2;
       sm%=mod;

       ll tu=n-i;
       tm=n;

       ll su=-(tu*(tu+1))/2+(tm*(tm+1))/2;

       su%=mod;

     //  _(k);
      // _(su-sm+1);

       sum+=(mod+(su-sm+1)%mod)%mod;
       sum%=mod;	
  }
  sum++;
  sum%=mod;

  ct sum,nl;
    return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=1e6+7;
const int mod=1e9+7;

int n,cnt[200],sum[200];
char ss[K];
int main(void)
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin>>n;
    for(int i='a';i<='z';i++)
        cnt[i]=100;
    while(n--)
    {
        cin>>ss;
        memset(sum,0,sizeof sum);
        for(int i=0,sz=strlen(ss);i<sz;i++)
            sum[ss[i]]++;
        for(int i='a';i<='z';i++)
            cnt[i]=min(cnt[i],sum[i]);
    }
    for(int i='a';i<='z';i++)
        while(cnt[i]--)cout<<(char)i;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n,k; cin >> n >> k;
    
    if(n%k==0) cout << 0 << ln;
    else cout << 1 << ln;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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(void){
    int N,X;
    cin>>N>>X;
    int L[N];
    for(int i=0;i<N;i++) cin>>L[i];
    int ans=1;
    int sum=0;
    int j=0;
    while(sum+L[j]<=X && j<N){
        ans++;
        sum+=L[j];
        j++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

    using ll = long long;

    vector<ll> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<ll> s(n + 1);

    for (int i = 0; i < n; i++) {
        s[i + 1] = s[i] + a[i];
    }

    map<ll, ll> m;

    m[0]++;
    
    ll ans = 0;
    
    for (int i = 1; i <= n; i++) {
        ans += m[s[i]];

        m[s[i]]++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 15872