akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 998244353;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}

int n;
ll k, a[100100];
int r[100100][100];

signed main() {

	cin >> n >> k;
	
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j < 62; j++) {
			r[i+1][j] = r[i][j];
			r[i+1][j] += !!(a[i] &(1LL << j));
		}
	}

	ll ans = 0;
	ll x = 0;
	for(int i = 61; i >= 0; i--) {

		if(r[n][i] < n - r[n][i] && x + (1LL << i) <= k) {
			x += (1LL<<i);
			ans += (1LL<<i) * (n-r[n][i]);
		}
		else {
			ans += (1LL<<i) * r[n][i];
		}
	}

	cout << ans << endl;
	


    return 0;
}



Measured memory_bytes: 40064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B, N; 
  cin >> A >> B >> N;

  int x = min(N, B-1);

  int ans = (A*x)/B-A*(x/B);

  x = N;

  chmax(ans, (A*x)/B-A*(x/B));

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
LL n,a,b,c,d;
char s[10];
int main()
{
	n=read();
	while(n--){
		scanf("%s",s);
		if(s[0]=='A')
			++a;
		else if(s[0]=='W')
			++b;
		else if(s[0]=='T')
			++c;
		else if(s[0]=='R')
			++d;
	}
	printf("AC x %lld\n",a);
	printf("WA x %lld\n",b);
	printf("TLE x %lld\n",c);
	printf("RE x %lld\n",d);
	return 0;
}


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

int n;
int k[100010]; // 奇数
int g[100010]; // 偶数

int main()
{
	int kmx1, kmx2;
	int gmx1, gmx2;
	int tmp;

	kmx1 = kmx2 = gmx1 = gmx2 = 0;
	
	cin >> n;
	for( int i = 0; i < n/2; i++ ) {
		cin >> tmp;
		k[tmp]++;
		if( kmx1 != tmp ) {
			if( kmx1 == 0 || k[kmx1] < k[tmp] ) {
				kmx2 = kmx1;
				kmx1 = tmp;
			} else if( kmx2 == 0 || k[kmx2] < k[tmp] ) {
				kmx2 = tmp;
			}
		}
		cin >> tmp;
		g[tmp]++;
		if( gmx1 != tmp ) {
			if( gmx1 == 0 || g[gmx1] < g[tmp] ) {
				gmx2 = gmx1;
				gmx1 = tmp;
			} else if( gmx2 == 0 || g[gmx2] < g[tmp] ) {
				gmx2 = tmp;
			}
		}
	}
	//cout << "kmx:" << kmx1 << " " << kmx2 << endl;
	//cout << "gmx:" << gmx1 << " " << gmx2 << endl;
	if( kmx1 != gmx1 ) {
		cout << (n - (k[kmx1]+g[gmx1])) << endl;
	} else {
		int ans1 = n - (k[kmx1]+g[gmx2]);
		int ans2 = n - (k[kmx2]+g[gmx1]);
		if( ans1 < ans2 ) {
			cout << ans1 << endl;
		} else {
			cout << ans2 << endl;
		}
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b;
    a=read(), b=read();
    printf("%lld\n",(a+b-1)/2+1);
    return 0;
}

Measured memory_bytes: 3656
import java.util.*;
public class Main {

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String str = sc.next();
	int output = 0;
	if(str.equals("SUN")){
	    output = 7;
    }else if(str.equals("MON")){
	    output = 6;
    }else if(str.equals("TUE")){
        output = 5;
    }else if(str.equals("WED")){
        output = 4;
    }else if(str.equals("THU")){
        output = 3;
    }else if(str.equals("FRI")){
        output = 2;
    }else if(str.equals("SAT")){
        output = 1;
    }
	System.out.println(output);
    }
}


Measured memory_bytes: 24020
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    root = [[] for _ in range(N)]
    node = [0] * N
    color = [0] * (N-1)
    for i in range(N-1):
        a,b = LI()
        root[a-1].append((b-1,i))
        root[b-1].append((a-1,i))

    q = [(0,0)]
    ans = 0
    while q:
        i,c = q.pop()
        node[i] = 1
        next_c = 1
        for d,x in root[i]:
            if node[d]: continue
            if next_c == c: next_c += 1
            color[x] = next_c
            ans = max(ans,next_c)
            q.append((d,next_c))
            next_c += 1
    print(ans)
    print(*color,sep='\n')

if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5 + 69;

ll n;
// vector<int> adj[N];

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

  cin >> n;
  ll kurang = 0;
  for(int i = 1; i < n; i++) {
    ll u, v;
    cin >> u >> v;
    if(u > v)
      swap(u, v);
    // adj[u].push_back(v);
    // adj[v].push_back(u);
    kurang += u * (n - v + 1LL);
    // cerr << kurang << '\n';
  }

  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    ans = (ans + 1LL * i * (i + 1) / 2);
  }
  // cout << ans << " " << kurang << " :D";
  ans -= kurang;
  cout << ans << '\n';





  return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> g[50];

int m;
ll dp[50][1<<20];
bool visited[50];

bool dfs(int s, int t, int q){
	int i;
	visited[s] = true;
	if(s==t){
		return true;
	}
	for(i=(g[s].l_ength()-1); i>=0; --i){
		if(visited[g[s][i].first]){
			continue;
		}
		if(dfs(g[s][i].first,t,q)){
			g[s][i].second |= (1<<q);
			return true;
		}
	}
	return false;
}

int main(void){
	int n,i,j,a,b,k,mask,r;
	cin >> n; 
	for(i=1; i<n; ++i){
		cin >> a >> b; --a; --b;
		g[a].push_back(P(b,0));
		g[b].push_back(P(a,0));
	}
	cin >> m; r = (1<<m);
	for(i=0; i<m; ++i){
		cin >> a >> b; --a; --b;
		fill(visited,visited+n,false);
		dfs(a,b,i);
		fill(visited,visited+n,false);
		dfs(b,a,i);
	}
	dp[0][0] = 1ll; k = 0;
	fill(visited,visited+n,false);
	for(a=0; a<n; ++a){
		visited[a] = true;
		for(j=(g[a].l_ength()-1); j>=0; --j){
			b = g[a][j].first;
			mask = g[a][j].second;
			if(visited[b]){
				continue;
			}
			for(i=0; i<r; ++i){
				dp[k+1][i] += dp[k][i];
				dp[k+1][i|mask] += dp[k][i];
			}
			++k;
		}
	}
	cout << dp[k][r-1] << endl;
	return 0;
}


Measured memory_bytes: 401664
import sys

W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
ans = 0
x_s, y_s, x_e, y_e = 0, 0, W, H

for x, y, a in xya:
    if a == 1:
        if (x_s < x) and (x_e > x):
            x_s = x
        elif x_e <= x:
            print(0)
            sys.exit()
        elif x_s >= x:
            pass
    elif a == 2:
        if (x_s < x) and (x_e > x):
            x_e = x
        elif x_e <= x:
            pass
        elif x_s >= x:
            print(0)
            sys.exit()
    elif a == 3:
        if (y_s < y) and (y_e > y):
            y_s = y
        elif y_e <= y:
            print(0)
            sys.exit()
        elif y_s >= y:
            pass
    elif a == 4:
        if (y_s < y) and (y_e > y):
            y_e = y
        elif y_e <= y:
            pass
        elif y_s >= y:
            print(0)
            sys.exit()
print((x_e - x_s) * (y_e - y_s))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define BAT 1
#define SOU 2
using namespace std;

int main(){
  int n, sum;
  char s,t,b;
  int mem[20][9];

  while( cin>>n && n ){
    cin >> s>>t>>b;
    int souko = b-'A';
    int goal= t-'A';
    
    for( int i=0;i<=n;i++ )
      for( int j=0;j<9;j++ )
	mem[i][j] = 0;

    mem[0][ s-'A' ]=1;
    for( int i=0;i<n;i++ ){
      for( int j=0;j<9;j++ ){	
	if( mem[i][j]==0 ) continue;
	int k=i+1;
	// up
	if( j<3 || j-3==souko )  mem[k][j]  +=mem[i][j];
	else                     mem[k][j-3]+=mem[i][j];
	// right
	if( j%3==2 || j+1==souko )  mem[k][j] +=mem[i][j];
	else                        mem[k][j+1]+=mem[i][j];
	// down
	if( j>5 || j+3==souko )  mem[k][j] += mem[i][j];
	else                     mem[k][j+3] +=mem[i][j];
	// left
	if( j%3==0 || j-1==souko )  mem[k][j] += mem[i][j];
	else                        mem[k][j-1]+=mem[i][j];
      }
    }
    /*
    for( int i=0;i<=n;i++ ){
      cout << "n="<<i << "|"<<endl ;
      for( int j=0;j<9;j++ ){
	cout << " "<<mem[i][j];
	if( j%3==2 ) cout << endl;
      }
      cout << endl;
    }
    */
    sum=0;
    for( int i=0;i<9;i++ )
      sum += mem[n][i];
    /*
    cout << "souko==" << souko << " goal="<<goal<<endl;
    cout << "dev " << mem[n][goal] << "/"<<sum <<endl;
    */
    printf("%lf\n",(double)mem[n][goal]/sum );
  }
  return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split()) 
dl = list(map(str, input().split())) 

curr_num = N
while True:
    n_str = str(curr_num)
    for d in dl:
        if d in n_str:
            curr_num += 1
            break
    else:
        print(curr_num)
        break

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

using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};
string S;

int main() {
	cin >> S;

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

	bool can = true;
	for (int a = 0; a < (int)S.size();) {
		bool can2 = false;
		for (int b = 0; b < 4; ++b) {
			string s_a = divide[b];
			if (S.substr(a, s_a.size()) == s_a) {
				can2 = true;
				a += s_a.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int d[10][10];

int main() {
    Int n;
    cin >> n;
    for (Int i = 1; i <= n; i++) {
        string s = to_string(i);
        d[s[0] - '0'][i % 10]++;
    }
    Int res = 0;
    for (Int i = 1; i <= 9; i++) {
        for (Int j = 1; j <= 9; j++) {
            res += d[i][j] * d[j][i];
        }
    }
    dump(res);
    return 0;
}

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

int main(){
  int n;
  string str="No";
  cin>>n;
  for(int i=2;i<10;i++){
    if(n%i==0){
      if(n/i<10){
        str="Yes";
      }
    }
  }
  if(n==1){str="Yes";}
  cout<<str;
  return 0;
}


Measured memory_bytes: 3572
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int N = stdIn.nextInt();
	String result = "No";
	for(int i=1;i<10;i++){
	    for(int j=1;j<10;j++){
		if(i*j==N){
		    result="Yes";
		    break;
		}
	    }
	}
	System.out.println(result);
    }
}


Measured memory_bytes: 23764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
    int tmp = 0;
    int count = 0;
    boolean allzero = true;
    for(int i=0;i<N;i++){
      int nextNum = sc.nextInt();
      tmp = tmp^nextNum;
      count = (count+1)%3;
      if(nextNum!=0)allzero = false;
    }
    if((count==0&&tmp==0) || allzero){
        System.out.println("Yes");
    }else{
      System.out.println("No");
    }
	}
}

Measured memory_bytes: 48184
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 8
#define M 31
using namespace std;
typedef pair<int,int> P0;
typedef pair<double,P0> P;
typedef pair<int,int> P1;
double dijkstra();
int n,m,p,a,b,ti[N];
double d[(1<<N)][M],ans;
vector<P1> edge[M];

int main(){
  int x,y,z;
  while(1){
    cin>>n>>m>>p>>a>>b;
    if(!n&&!m&&!p&&!a&&!b) break;
    for(int i=0;i<n;i++) cin>>ti[i];
    a--,b--;
    while(p--){
      cin>>x>>y>>z;
      x--,y--;
      edge[x].push_back(P1(y,z));
      edge[y].push_back(P1(x,z));
    }
    ans=INF;
    ans=dijkstra();
    if(ans==INF) cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
    for(int i=0;i<m;i++) edge[i].clear();
  }
  return 0;
}

double dijkstra(){
  priority_queue<P,vector<P>,greater<P> > q;
  for(int i=0;i<(1<<n);i++)
    for(int j=0;j<m;j++) d[i][j]=INF;
  d[0][a]=0;
  q.push(P(0,P0(0,a)));
  while(!q.empty()){
    P t=q.top(); q.pop();
    double cost=t.first;
    int uy=t.second.first,ux=t.second.second;
    if(d[uy][ux]<cost) continue;
    for(int i=0;i<edge[ux].size();i++){
      int nx=edge[ux][i].first;
      for(int j=0;j<n;j++){
	double c=cost+1.0*edge[ux][i].second/ti[j];
	if((uy&(1<<j))==0){
	  int ny=uy|(1<<j);
	  if(d[ny][nx]>c){
	    d[ny][nx]=c;
	    q.push(P(c,P0(ny,nx)));
	  }
	}
      }
    }
  }
  double res=INF;
  for(int i=0;i<(1<<n);i++) res=min(res,d[i][b]);
  return res;
}

Measured memory_bytes: 2704
import itertools

N = int(input())
data = range(1,N+1)
p_list = list(itertools.permutations(data, N))

P = list(map(int,input().split()))
Q = list(map(int,input().split()))

P_num = 0
Q_num = 0

for index,data in enumerate(p_list):
  if list(data) == P:
    P_num = index
  if list(data) == Q:
    Q_num = index
    
print(abs(P_num - Q_num))

Measured memory_bytes: 8052
#include<stdio.h>
int R=1,C=1,H[2000010];
double N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(double a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,i;
  double a,b;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&a);
    hin(a);
  }
  for(i=1;i<n;i++){
    a=N[hout()];
    b=N[hout()];
    hin((a+b)/2.0);
  }
  printf("%.10lf\n",N[hout()]);
  return 0;
}


Measured memory_bytes: 2176
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let (x,y) = (it.next().unwrap(), it.next().unwrap());

    if 4*x < y {
        println!("No"); 
    } else if y%2 == 0 && 2*x <= y{
        println!("Yes");
    } else {
        println!("No"); 
    }
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,k,ans,maxn;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	maxn=max(n,m);
	ans=k/maxn;
	if (k%maxn) ans++;
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, m;
pair<int,int> a[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> a[i].st >> a[i].nd;
	}
	sort(a, a+n);
	int j = 0;
	priority_queue<int> pq;
	int ans = 0;
	for(int i=1; i<=m; i++){ //day left
		for(; j<n && a[j].st == i; j++) pq.push(a[j].nd); 
		if (!pq.empty()) {
			ans += pq.top(); pq.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
struct Info{int nu,ne;}a[N*2];
int n,x,y,f[N],b[N],num,l=1,r=1,li[N],g[N],ma[N],dp[N][2];
void dfs(int x,int fa){f[x]=fa;for (int y=b[x];y;y=a[y].ne)if (a[y].nu!=fa)dfs(a[y].nu,x);}
void jb(int x,int y){a[++num].nu=y;a[num].ne=b[x];b[x]=num;}
void add(int x,int z){ma[x]=z;if(x<z)for(int y=b[x];y;y=a[y].ne){if (a[y].nu!=f[x])add(a[y].nu,z);}else li[++r]=x;}
void fu(int x,int z,int p){if(x<z){g[x]=p;for(int y=b[x];y;y=a[y].ne)if(a[y].nu!=f[x])fu(a[y].nu,z,p);}}
void get(int x,int z,int p){dp[x][p]=1;for (int y=b[x];y;y=a[y].ne)if (a[y].nu!=f[x]&&a[y].nu<z){get(a[y].nu,z,p);dp[x][p]+=dp[a[y].nu][p];}}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){scanf("%d %d",&x,&y);jb(x,y);jb(y,x);}
	dfs(1,0);
	li[l]=1;ma[1]=0;
	while(l<=r){
		get(li[l],li[l],1);get(li[l],ma[li[l]],0);
		g[li[l]]=dp[li[l]][0]+g[f[li[l]]];
		for (int y=b[li[l]];y;y=a[y].ne)if (a[y].nu!=f[li[l]]){fu(a[y].nu,li[l],g[li[l]]-dp[a[y].nu][0]+dp[a[y].nu][1]);}
		for (int y=b[li[l]];y;y=a[y].ne)if (a[y].nu!=f[li[l]])add(a[y].nu,li[l]);
		l++;
	}
	for(int i=2;i<=n;i++)printf("%d ",g[i]-1);	
	return 0;
}

Measured memory_bytes: 22656
#include <stdio.h>

int main(void)
{
  long max, first, tmp, num, i;

  scanf("%ld", &num);
  scanf("%ld", &first);
  scanf("%ld", &tmp);
  max = tmp - first;
  if(tmp < first){
    first = tmp;
  }

  for(i = 2; i < num; i++){
    scanf("%ld", &tmp);
    if(max < tmp - first){
      max = tmp - first;
    }
    if(tmp < first){
      first = tmp;
    }
  }

  printf("%ld\n", max);

  return 0;
}

Measured memory_bytes: 596
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var md1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var md2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.WriteLine(md1[0] == md2[0] ? 0 : 1);
        }
    }
}


Measured memory_bytes: 13140
//  RAKSHIT KADAM
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
            
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}} // if a and m are relativelyprime

void solve()
{
    ll n;cin>>n;ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            for(ll k=1;k<=n;k++)
            {
                sum+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  solve();
    return 0;
    
}
 


Measured memory_bytes: 3648
x=input()
s=list(x)
y=0
for i in range(len(s)):
  if (i+1)%2 == 0 and s[i]=='R':
    y+=1
  elif (i+1)%2 == 1 and s[i]=='L':
    y+=1
  else:
    y+=0
print('Yes' if y==0 else 'No')


Measured memory_bytes: 2940
N = int(input())

def ask(i):
  print(i,flush=True)
  s = input()
  if s == 'Vacant':
    exit()
  return s == 'Female'

a = 0
b = N
ga = ask(a)
gb = ga

while a < b:
  m = (a+b)//2
  gm = ask(m)

  parity_am = (m-a)%2 == 0
  parity_mb = (b-m)%2 == 0

  ram = (ga==gm) == parity_am
  rmb = (gm==gb) == parity_mb
  if ram:
    a = m
    ga = gm
  else:
    b = m
    gb = gm

ask(a)

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
  int mn=INT_MAX,mx=-INT_MAX;
  long long sum=0;
  int t;
  for(int i=0;i<n;i++)
  {
      cin>>t;
      mn=min(mn,t);
      mx=max(mx,t);
      sum+=t;
  }
  cout<<mn<<" "<<mx<<" "<<sum<<"\n";
  return 0;
  }




Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    int S, W;
    cin >> S >> W;
    if(S > W) Cout("safe");
    else Cout("unsafe");
}


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

int main() {
  int n;
  cin >> n;
  int i = 0;
  while (n > 1000 * i) {
    i++;
  }
  cout << 1000 * i - n << endl;
}


Measured memory_bytes: 3580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	s := bufio.NewScanner(os.Stdin)
	min := 1001
	max := -1

	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	if n == 1 {
		//	fmt.Println("111111")
		fmt.Println(0)
		return
	}

	s.Scan()
	a := strings.Split(s.Text(), " ")
	for _, v := range a {
		i, _ := strconv.Atoi(v)
		if i < min {
			min = i
		}
		if i > max {
			max = i
		}
	}
	//	fmt.Printf("Max: %v Min: %v \n", max, min)
	fmt.Println(max - min)
}


Measured memory_bytes: 640
//It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9+7;
ll res;

void solve()
{
     string s;cin>>s;
     int n = s.size();
     if(s[n-1] == 's'){
         s += "es";
         cout<<s<<endl;
     }
     else{
         s += 's';
         cout<<s<<endl;
     }
}
 
int main()
{
    IOS;ll t = 1;
    // cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > hr,wc;
void perm(int index,int length,vector<int> temp,int flag)
{
	if(index == length)
	{
		if(flag == 0)
			hr.push_back(temp);
		else
			wc.push_back(temp);
		return ;
	}
	temp.push_back(index);
	perm(index+1,length,temp,flag);
	temp.pop_back();
	perm(index+1,length,temp,flag);
}
int main()
{
	//freopen("/home/dhruv/Desktop/tests/input.txt","r",stdin);
	int h,w,k;
	cin>>h>>w>>k;
	char grid[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cin>>grid[i][j];
	}
	vector<int> temp;
	perm(0,h,temp,0);
	temp.clear();
	perm(0,w,temp,1);
	int ans = 0;
	for(int i=0;i<hr.size();i++)
	{
		for(int j=0;j<wc.size();j++)
		{
			int row[h]={0},col[w]={0},black = 0;
			for(int k=0;k<hr[i].size();k++)
				row[hr[i][k]]=1;
			for(int k=0;k<wc[j].size();k++)
				col[wc[j][k]]=1;
			for(int l=0;l<h;l++)
			{
				for(int m=0;m<w;m++)
				{
					if(row[l]!=1 && col[m]!=1 && grid[l][m]=='#')
						black++;
				}
			}
			if(black == k)
				ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3608
def solve():
    n = int(input())

    # ord('B') == 66 (== 0 mod 3)
    # ord('R') == 82 (== 1 mod 3)
    # ord('G') == 71 (== 2 mod 3)
    s = [ord(c) % 3 for c in input()]
    ans = 1
    ans = s.count(0) * s.count(1) * s.count(2)
    for i in range(n):
        for j in range(i + 1, n):
            k = j + j - i
            if k < n:
                if s[i] == s[j] or s[i] == s[k] or s[j] == s[k]:
                    continue
                ans -= 1
    return ans


print(solve())


Measured memory_bytes: 9208
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		int flag = 1;
		for (int j = i; j < n; j++) {
			if (s[j] != t[j - i]) flag = 0;
		}
		if (flag) {
			cout << n + i << endl;
			break;
		}
		if (i == n - 1) cout << 2 * n << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  int m=n;
  int sum=0;
  while(m>0){
    sum+=m%10;
    m/=10;
  }
  if(n%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3576
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

dp = [0]*n
b = a[0]

dp[1] = max(a[0],a[1])

for i in range(2,n):
    if i%2 == 0:
        b += a[i]
        dp[i] = max(dp[i-1],dp[i-2]+a[i])
    else:
        dp[i] = max(b,dp[i-2]+a[i])

print(dp[-1])

Measured memory_bytes: 92132
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  string s;
  cin >> s;

  int ans = 0;
  int apos = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'A') {
      apos = i;
      break;
    }
  }
  int zpos = 0;
  for (int i = s.length() - 1; i > apos; --i) {
    if (s[i] == 'Z') {
      zpos = i;
      break;
    }
  }

  cout << (zpos - apos + 1) << endl;
  
  return 0;
}

Measured memory_bytes: 3744
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
    static long[] dp,fac,inv;
    static int n,m;
	public static void main(String[] args) {
		fac = new long[MAX+1];
		inv = new long[MAX+1];
		precompute(MAX);
	    int h = sc.nextInt();
	    int w = sc.nextInt();
	    int n = sc.nextInt();
	    Pair[] p = new Pair[n+1];
	    for(int i=0;i<n;++i) {
	    	p[i] = new Pair(sc.nextInt(),sc.nextInt());
	    }
	    p[n] = new Pair(h,w);
	    Arrays.sort(p);
	    dp = new long[n+1]; // paths that goes from top to x,y without blocking
	    for(int i=0;i<=n;++i) {
	    	int x = p[i].x;
	    	int y = p[i].y;
	    	dp[i] = ncr(x+y-2,x-1);
	    	
	    	for(int j=0;j<i;++j) {
	    		int a = p[j].x;
	    		int b = p[j].y;
	    		if(a <= x && b <= y)
	    		dp[i] = (dp[i] - mul(dp[j],ncr(x+y-a-b,x-a)) + mod)%mod;
	    	}
	    }
       out.print(dp[n]);
		out.close();
   }
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			return (this.x + this.y) - (o.x + o.y);
		}
		
	}
	static void precompute(int n){

		 fac = new long[n+1];
	     inv = new long[n+1];
		 fac[0]=fac[1]=1;
		for(int i=2;i<fac.length;i++)
		{
			fac[i]=fac[i-1]*i;
			fac[i]%=mod;
		}
		
		inv[n]=pow(fac[n],(int) (mod-2));
		for(int i=n-1;i>=0;i--)
		{
			inv[i]=inv[i+1]*(i+1);
			inv[i]%=mod;
		}
	}
	
	 private static long pow(long a, int b) {
			return BigInteger.valueOf(a).modPow(BigInteger.valueOf(b), BigInteger.valueOf(mod)).longValue();
		}
		 
		private static long ncr(int n , int r) {
			return mul(fac[n],inv[r],inv[n-r]);
		}
		
		 private static long mul(long ... a) {
				long ans = 1;
				for(long x : a) ans = ((ans%mod) * (x%mod))%mod;
				return ans;
			}
}



Measured memory_bytes: 135432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n;
  cin>>n;
  vector<string>w(n);
  bool ex=true;
  rep(i,n) cin>>w[i];
  rep(i,n)rep(j,i){
    if(w[i]==w[j])
      ex=false;
  }
  rep(i,n-1){
    if(w[i].back()!=w[i+1].front())
      ex=false;
  }
  if(ex)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int H, W;
int sx, sy;
vector<string> s;

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

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

vector<vector<int>> bfs() {
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    vector<vector<int>> d(H, vector<int>(W, inf));
    d[sx][sy] = 0;

    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front(); que.pop();
        rep(k, 4) {
            int nx = x + dx[k], ny = y + dy[k];
            if (inside(nx, ny) && s[nx][ny] != '#' && d[nx][ny] == inf) {
                d[nx][ny] = d[x][y] + 1;
                que.emplace(nx, ny);
            }
        }
    }

    return d;
}

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

    cin >> H >> W;
    s.resize(H);
    rep(i, H) cin >> s[i];
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == '%') {
                sx = i, sy = j;
            }
        }
    }

    auto d = bfs();
    int princess;
    int soldier = inf;
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == '@') {
                princess = d[i][j];
            }
            if (s[i][j] == '$') {
                soldier = min(soldier, d[i][j]);
            }
        }
    }

    cout << (princess < soldier ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3352
a="-.,!? -abc-def-ghi-jkl-mno-pqrs-tuv-wxyz".split("-")
gets
while s=gets
puts s.gsub("0"," ").split.map(&:to_i).map{|i|a[i%10][(i.to_s.size-1)%a[i%10].size]}.join
end

Measured memory_bytes: 6148
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n,k;
	cin>>n>>k;
	
	ll p[n+1],c[n+1],s[n+1]={0};
	for (int i=1;i<=n;i++){
		cin>>p[i];
	}
	for (int i=1;i<=n;i++){
		cin>>c[i];
	}
	ll ans=-inf;
	for (int st=1;st<=n;st++){
		ll cnt=0,cur=st,mx=-inf,sum=0;
		while (true){
			cnt++;
			cur=p[cur];
			sum+=c[cur];
			s[cnt]=sum;
			mx=max(mx,sum);
			if (cur==st) break;
		}
		for (ll x=1;x<=cnt && x<=k;x++){
			ans=max(ans,s[x]);
			if (sum>0){
				ans=max(ans,s[x]+sum*((k-x)/cnt));
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3768
import collections

x,y,z,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a15 = a[-15:]
b15 = b[-15:]
c15 = c[-15:]

oisi = []

for i, aa in enumerate(a[:k]):
    for j, bb in enumerate(b[:(k//(i+1))+2]):
        for l,cc in enumerate(c[:(k//((i+1)*(j+1)))+2]):
            oisi.append(aa+bb+cc)
#            print(i,j,l)

#for i, aa in enumerate(a[:k]):
#    for j, bb in enumerate(b[:k]):
#        for l,cc in enumerate(c[:k]):
#            print(i,j,l,aa+bb+cc)

#for aa in a15:
#    for bb in b15:
 #       for cc in c:
#            oisi.append(aa+bb+cc)

#print(len(oisi))
oisi.sort(reverse=True)
#print(oisi)

for j in oisi[:k]:
    print(j)



Measured memory_bytes: 48880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int answer[3000];

int main(){
    int n, x, y;
    cin>>n>>x>>y;
    for(int i =1; i<=n; i++){
        priority_queue<pair<int,int> > q;
        bool visited[3000];
        for(int j=0; j<3000; j++) visited[j] = false;
        q.push(make_pair(0, i));
        while(!q.empty()){
            int next = (q.top()).second;
            int dist = (q.top()).first;
            
            
            q.pop();
            if(next<=0 || next>n) continue;
            if(visited[next]) continue;
            else visited[next] = true;
            answer[abs(dist)]++;
            //cout<<i<<" "<<next<<endl;
            if(next == x){
                if(!visited[x-1]){
                    q.push(make_pair(dist-1, x-1));
                }
                if(!visited[x+1]){
                    q.push(make_pair(dist-1, x+1));
                }
                if(!visited[y]){
                    q.push(make_pair(dist-1, y));
                }
            }
            else if(next == y){
                if(!visited[y-1]){
                    q.push(make_pair(dist-1, y-1));
                }
                if(!visited[y+1]){
                    q.push(make_pair(dist-1, y+1));
                }
                if(!visited[x]){
                    q.push(make_pair(dist-1, x));
                }
            }
            else{
                if(!visited[next+1]) q.push(make_pair(dist-1, next+1));
                if(!visited[next-1]) q.push(make_pair(dist-1, next-1));
            }
        }
    }

    for(int i =1; i<n; i++){
        cout<<answer[i]/2<<endl;
    }
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  vi a(n+1), b(n);
  rep(i, n+1) std::cin >> a[i];
  rep(i, n) std::cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    if (a[i] < b[i]) {
      ans += a[i];
      ans += min(a[i+1], b[i]-a[i]);
      a[i+1] = max(0, a[i+1]-(b[i]-a[i]));
    } else ans += b[i];
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
typedef long long LL;
const int N=1e6;
const LL mod=998244353;
struct node{
	LL a,b,c,sum;
}a[N];
bool cmp(node x,node y){
	return x.sum<y.sum;
}
int main(){
	LL n,k;
	cin>>n>>k;
	if(n<2*k-1){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<=k;i++){
		a[i].a=i+k-1;
		a[i].b=2*n-1+i;
		a[i].sum=a[i].a+a[i].b;
	}
	for(int i=k+1;i<=k+n-1;i++){
		a[i].a=i+k-1;
		a[i].b=i+(n-k)+k-1;
		a[i].sum=a[i].a+a[i].b;
	}
	sort(a+1,a+n+1,cmp);
	LL c=k+2*n;
	for(int i=1;i<=n;i++){
		//if(a[i].a+a[i].b>c+i-1)cout<<"XXX"<<endl;
		printf("%lld %lld %lld\n",a[i].a,a[i].b,c+i-1);
	}
}


Measured memory_bytes: 8320
k,n = map(int,input().split())
a = input().split()
s = 0
t = 0
while t < n:
  x = int(a[t-1])
  y = int(a[t])
  if y-x > s:
    s = y-x
  t += 1
l = int(a[0])+k - int(a[-1])

print(k-max(s,l))

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

int main() {
  int a, b;
  char op;
  while (1) {
    cin >> a >> op >> b;

    if (op == '+') {
      cout << a + b << endl;
    } else if (op == '-') {
      cout << a - b << endl;
    } else if (op == '*') {
      cout << a * b << endl;
    } else if (op == '/') {
      cout << a / b << endl;
    } else if (op == '?') {
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int dp[20010];
int main(){
  	int h,n;
  	cin>>h>>n;
  	memset(dp,-1,sizeof(dp));
  	dp[0] = 0;
  	for (int i=1;i<=n;i++){
      	int a,b;
    	cin>>a>>b;
      	for (int j=a;j<=a+h;j++) if (dp[j-a]!=-1){
        	if (dp[j] == -1 || dp[j] > dp[j-a] + b) dp[j] = dp[j-a] + b;  
        }
    }
  	int sum =1e9+10;
  	for (int i=h;i<=20000;i++) if (dp[i] != -1) sum = min(sum, dp[i]);
  	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b), a|b) {
    assert(a % 100 == 0 && b % 100 == 0);
    assert(a <= b);
    assert(0 < a && a <= 100000000);
    assert(0 < b && b <= 100000000);
    int n = b - a;
    int ans3 = n / 1000;
    n %= 1000;
    int ans2 = n / 500;
    n %= 500;
    int ans1 = n / 100;
    n %= 100;
    assert(n == 0);
    printf("%d %d %d\n", ans1, ans2, ans3);
  }
  assert(scanf("%s", str) == EOF);
}

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

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

	sort(a, a+N);
	int cnt = 1;
	for(int i=1; i<N; i++){
		if( a [i-1] != a[i] ) cnt++;
		else continue;
	}
	cout << cnt << endl;
	return 0;
}


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

int main(int argc, char const *argv[]) {
  string s,t;
  std::cin >> s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if (s<t) {
    std::cout << "Yes" << '\n';/* code */
  }
  else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n + 2, 0);
    ll sum = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i + 1];
        sum += abs(a[i + 1] - a[i]);
    }
    sum += abs(a[n+1] - a[n]);
    for (ll i = 1; i <= n; i++)
    {
        ll temp = sum;
        cout << temp - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i + 1]) << endl;
    }
}

Measured memory_bytes: 2048
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

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

ll N,A,B,max_hp;
std::vector<ll> hp;
bool killable(ll times){
    ll spell_left = times;
    ll widespread_dmg = times*B;
    REP(i,N){
        if(hp[i] > widespread_dmg){
            spell_left-=(hp[i]-widespread_dmg)/(A-B)+bool((hp[i]-widespread_dmg)%(A-B));
        }

        if(spell_left<0){
            return false;
        }
    }
    return true;
}

int main(){
    cin>>N>>A>>B;
    REP(i,N){
        ll temp; cin >> temp;
        hp.push_back(temp);
        max_hp=max(max_hp,temp);
    }

    //binary seach on the answer
    ll left = 1LL, right = max_hp/B+1LL, mid, ans = right;

    while(left <= right){
        mid = (right+left)/2LL;
        if(killable(mid)){
            ans = min(mid, ans);
            right = mid-1LL;
        } else {
            left = mid+1LL;
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    int n, d[100];
    cin >> n;

    rep(i,n) cin >> d[i];

    int sum = 0;

    rep(i,n){
        for (int j = i+1; j < n; ++j){
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int ,int>P;

int main(void){
    int ans;
    int n;  cin >> n;
    vector<P>red(n),blue(n);
    for(int i=0;i<n;i++){
        int first,second; cin >> first >> second;
        red[i] = {second,first};
    }
    for(int i=0;i<n;i++){
        int first,second; cin >> first >> second;
        blue[i] = {first,second};
    }

    vector<bool>have_been(n);

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());

    for(int i=0;i<n;i++){
        int tmp = red[i].first;
        red[i].first = red[i].second;
        red[i].second = tmp;
    }
    int cnt=0;
    int idx = 0;
    for(int i=0;i<n;i++){
        for(int j=n-1;0<=j;j--){
            if(red[j].first < blue[i].first && red[j].second < blue[i].second && have_been[j] == false) {
                cnt++;
                have_been[j] = true;
                break;
                // cout << red[j].first <<',' << red[j].second  <<' ' << blue[i].first << ',' << blue[i].second << endl;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

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;
typedef pair<int,int> P;
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; }
ll MOD = 1000000007;

int main(){
  ll n; cin >> n;
  ll upper = 0;
  ll sum = 0;
  rep(i,n){
    ll a; cin >> a;
    upper = max(upper,a);
    if(upper != a){
      sum += upper - a;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1e9+7
#define INF 1e9
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;


int main(void){
    int N;
    cin>>N;
    VI h(N),dp(N+10,INF);
    REP(i,N)cin>>h[i];
    dp[0]=0;
    REP(i,N){
        dp[i+1]=min(dp[i]+abs(h[i+1]-h[i]),dp[i+1]);
        dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+2]);
    }
    cout<<dp[N-1]<<endl;
}




Measured memory_bytes: 1024