akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a>=k)cout << k;
  else if(a<k&&k<=(a+b))cout << a;
  else if((a+b)<k&&k<=(a+b+c))cout << a-(k-a-b);
  else cout << a-c;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if (a!=b && b==c){
		cout<<"Yes";
	}
	else if (a==b && b!=c){
		cout<<"Yes";
	}
	else if (a!=b && a==c){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3596
program sample
  implicit none

  integer(8) :: x1,y1,x2,y2,x3,y3,x4,y4

  

  ! 整数を読み込む
  read(*,*) x1,y1,x2,y2
  x3=x2-y2+y1
  y3=y2+x2-x1
  x4=x3-y3+y2
  y4=y3+x3-x2

    write(*,*)x3,y3,x4,y4

  
  stop
end program sample


Measured memory_bytes: 2860
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a -  b;
    if (s < 0) s += mod;
    return s;
}
const int maxN = 405;
int pw[maxN][maxN];
int n;
int a[maxN], b[maxN];
int c;
int pref[maxN][maxN];
int dp[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    for (int i = 0; i < maxN; i++) {
        pw[i][0] = 1;
        for (int j = 1; j < maxN; j++) {
            pw[i][j] = mult(pw[i][j - 1], i);
        }
    }
    for (int what = 0; what < maxN; what++) {
        for (int i = 0; i < maxN; i++) {
            pref[what][i] = pw[i][what];
            if (i) pref[what][i] = sum(pref[what][i], pref[what][i - 1]);
        }
    }
    cin >> n >> c;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            for (int cnt = 0; cnt + j <= c; cnt++) {
                dp[i + 1][j + cnt] = sum(dp[i + 1][j + cnt], mult(dp[i][j], sub(pref[cnt][b[i + 1]], pref[cnt][a[i + 1] - 1])));
            }
        }
    }
    cout << dp[n][c];
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A, B;
  cin >> A >> B;
  string C = A + A;
  int co = 0;
  rep(i, A.size()) {
    rep(j, A.size()) {
      if(C.at(i+j) == B.at(j)) {
        co++;
      }
    }
    if(co == A.size()) {
      break;
    }
    co = 0;
  }
  if(co == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << ((a + b)*h) / 2 << endl;

	return 0;
}

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

int main() {
  int n, k, s;
  cin >> n >> k >> s;

  int mx = 1000000000;

  if (s < mx) {
    for (int i = 0; i < k; i++) {
      cout << s << endl;
    }
    for (int i = 0; i < n - k; i++) {
      cout << mx << endl;
    }
  } else {
    for (int i = 0; i < k; i++) {
      cout << s << endl;
    }
    for (int i = 0; i < n - k; i++) {
      cout << 1 << endl;
    }
  }

  return 0;
}


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

int main(){
    int K, N;
    cin >> K;
    cin >> N;
    vector<int> dist(N);
    for(int i=0; i<N; i++){
        cin >> dist[i];
    }  
    int d_max = dist[0] + (K-dist[N-1]);
    for(int i=0; i<N-1; i++){
        if(dist[i+1]-dist[i] > d_max){
            d_max = dist[i+1]-dist[i];
        }
    }
    cout << K - d_max << endl;
    return(0);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
char judge_class(int, int, int);

int main(void)
{
    int pm, pe, pj, n;
    while (true) {
        cin >> n;
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            cin >> pm >> pe >> pj;
            cout << judge_class(pm, pe, pj) << endl;
        }
    }
    return 0;
}

char judge_class(int pm, int pe, int pj)
{
    if (pm == 100 || pe == 100 || pj == 100) {
        return 'A';
    } else if (pm + pe >= 90 * 2) {
        return 'A';
    } else if (pm + pe + pj >= 80 * 3) {
        return 'A';
    } else if (pm + pe + pj >= 70 * 3) {
        return 'B';
    } else if ((pm + pe + pj >= 50 * 3) && ((pm >= 80) || (pe >= 80))) {
        return 'B';
    } else {
        return 'C';
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define NL endl
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1e9+7
#define FOR(i,j,n)    for(ull i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

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

    ll n;
    cin>>n;
    ll arr[n];
    ll ans = 0;
    FOR(i,0,n) cin>>arr[i];
    priority_queue <int, vector<int>, greater<int> > pq;
    FOR(i,0,n){
        pq.push(arr[i]);
        ll tp = pq.top();
        if(arr[i] <= tp) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2936
#include<stdio.h>
int main(){
  char s[5];
  scanf("%s",s);
  
  int i,m;
  m=0;
  for(i=0;i<4;i++){
    if(s[i]=='+')
      m=m+1;
    else m=m-1;
    }
    
    printf("%d",m);
  }

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
 
const ll inf = 1e9;
const int mxN = 2e6+1;
const int mod = 1e9+7; 

 
void solve(){
    int n;
    cin >> n;
    string s = "ACL";
    while(n--) cout << s;
    cout << "\n";
}


 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  
  multiset<ll> d;
  rep(i,n){
    ll c;
    cin >> c;
    d.insert(c);
  }

  int m;
  cin >> m;
  vector<ll> t(m);
  rep(i,m) cin >> t.at(i);

  string ans = "YES";
  rep(i,m){
    ll now = t.at(i);
    if(d.find(now)==d.end()){ans="NO"; break;}
    else d.erase(d.find(now));
  }

  cout << ans;
}

Measured memory_bytes: 14040
N, H = [int(i) for i in input().split()]
A = []
B = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
amax = max(A)
B.sort(reverse=True)
i = 0
cnt = 0
while H > 0:
    if i < N and B[i] > amax:
        H -= B[i]
        i += 1
        cnt += 1
    else:
        cnt += H // amax
        if H//amax != H/amax:
            cnt += 1
        break
print(cnt)

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

void print(char *str, const int a, const int b)
{
    int i;

    for( i = a; i < b+1; ++i )
        printf("%c", str[i]);
    printf("\n");
}

void reverse(char *dst, const int a, const int b)
{
    int i, j;
    char src[1001];

    strcpy(src, dst);

    for( i = a, j = b; i < b+1; ++i, --j )
        dst[i] = src[j];
}

void replace(char *dst, const int a, const int b)
{
    int i, j;

    char p[1001];
    scanf("%s", p);

    for( i = a, j = 0; i < b+1; ++i, ++j )
        dst[i] = p[j];
}

int main()
{
    int i;

    char str[1001], op[256];
    int q, a, b;
    scanf("%s%d", str, &q);
    for( i = 0; i < q; ++i ){
        scanf("%s%d%d", op, &a, &b);
        if( strcmp("print", op) == 0 ) print(str, a, b);
        else if( strcmp("reverse", op) == 0 ) reverse(str, a, b);
        else if( strcmp("replace", op) == 0 ) replace(str, a, b);
    }

    return 0;
}

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

typedef long long ll;

int main(void) {
	const ll MOD = (ll)1e+9 + 7;
	int N, M;
	ll ans;

	cin >> N >> M;

	int K = min(N, M);
	if (N - K > 1 || M - K > 1) {
		cout << "0\n";
		return 0;
	}

	ans = (ll)K;
	for (int p = K - 1; p > 1; --p) {
		ans *= (ll)p;
		ans %= MOD;
	}

	ans *= ans;
	ans %= MOD;
	if (N == M) {
		ans += ans;
		ans %= MOD;
	}
	else {
		ans *= (ll)(K + 1);
		ans %= MOD;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int bubbleSort(int a[],int n);

int main() {
  
  int n,a[N],k,i;

  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    
    scanf("%d",a+i);

  }

  k = bubbleSort(a, n);
  
  for(i = 0; i < n; i++){

    if(i>0){
      printf(" ");
    }
    
    printf("%d", a[i]);

  }
  
  printf("\n");
  
  printf("%d\n",k);

  return 0;
}

int bubbleSort(int a[], int n) {
  int j,b,k=0,flag=1;

  while(flag) {
    flag = 0;
    for(j = n-1; j > 0;j--) {
      if(a[j] < a[j-1]) {
        b = a[j];
        a[j] = a[j-1];
        a[j-1] = b;
        flag = 1;
        k++;
      }
    }
  }
  return k;
}




Measured memory_bytes: 2108
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int> l(q),r(q);
    rep(i,q){
        cin>>l[i]>>r[i];
        --l[i];
        --r[i];
    }
    vector<int> ac(n,0);
    rep(i,n-1){
        if(s[i]=='A'&&s[i+1]=='C')ac[i]=1;
    }
    vector<int> csum(n,0);
    rep(i,n-1){
        csum[i+1]=csum[i]+ac[i];
    }
    rep(i,q){
        cout<<csum[r[i]]-csum[l[i]]<<endl;
    }

}

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

int a[12][12];
ll MX=111111111;

int main(){
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    ll ans=MX;
    rep(s,1<<n){
        ll cost =0;
        vector<int> d(m);
        rep(i,n){
            if(s>>i&1){
                cost += c[i];
                rep(j,m) d[j] +=a[i][j];
            }
        }
        bool ok = true;
        rep(j,m){
            if(d[j]<x) ok=false;
        }
        if(ok) ans=min(ans,cost);
    }
    if(ans!=MX) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3564
import java.util.*;
import java.io.*;

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		//int t = f.nextInt();
		//while(t-- > 0)
			solve();
		out.close();
	}

	static void solve() {
		int n = f.nextInt(), k = f.nextInt();
		SegmentTree seg = new SegmentTree(300_002);
		for(int i=0;i<n;i++) {
			int now = f.nextInt();
			long max = seg.get(now-k, now+k+1);
			seg.update(now, (int)(max + 1));
		}

		long ans = 0;
		for(int i=0;i<300_002;i++) {
			ans = Math.max(ans, seg.arr[i]);
		}

		out.println(ans);
	}

    static class SegmentTree {
        int n;
        long[] arr;
 
        SegmentTree(int l) {
            this.n = calc(l);
            arr = new long[n << 1];
        }
 
        private static int calc(int size) {
            int ans = 1;
            while (ans < size) {
                ans <<= 1;
            }
            return ans;
        }

        void update(int i, int x) {
            int ind = n - 1 + i;
            arr[ind] = x;
            while (ind > 0) {
                ind = (ind-1)/2;
                arr[ind] = Math.max(arr[2*ind+1], arr[2*ind+2]);
            }
        }
 
        long get(int left, int right) {
            return search(left, right, 0, 0, n);
        }
 
        long search(int l, int r, int x, int lx, int rx) {
 
            if(rx <= l || r <= lx) {
                return 0;
            }
            if(l <= lx && rx <= r) {
                return arr[x];
            }
 
            return Math.max(search(l, r, 2*x+1, lx, (rx+lx)/2),
                    search(l, r, 2*x+2, (rx+lx)/2, rx));
        }
 
    }


	static class FastReader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(IOException ioe) {
					ioe.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch(IOException ioe) {
				ioe.printStackTrace();
			}

			return s;
		}

		int  nextInt() {
			return Integer.parseInt(next());
		}

		long  nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 61884
n = int(input())

n1 = 2
n2 = 1
if n == 0:
  print(n1)
elif n == 1:
  print(n2)
else:  
  for i in range(2, n+1):
    n1, n2 = n2, n1+n2
    if i == n:
      print(n2)
      


Measured memory_bytes: 2940
import java.util.*;
import java.awt.Point;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if(w == 0 && h == 0) break;

			Point start = null;
			map = new int[h][w];
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					map[i][j] = sc.nextInt();
					if(map[i][j] == 2) start = new Point(j,i);
				}
			}

			PriorityQueue<State> open = new PriorityQueue<State>();
			HashSet<State> closed = new HashSet<State>();
			State ans = null;
			open.add(new State(start,6,0));

			while(!open.isEmpty()){
				State st = open.poll();
				if(closed.contains(st)) continue;
				closed.add(st);

				if(map[st.p.y][st.p.x] == 3){
					ans = st;
					break;
				}

				open.addAll(st.nexts());
			}

			System.out.println(ans==null ? -1 : ans.cost);
		}
	}

	private static int w;
	private static int h;
	private static int[][] map;
	private static int dx[] = {0,1,0,-1};
	private static int dy[] = {-1,0,1,0};

	private static class State implements Comparable<State>{
		Point p;
		int hp,cost;

		State(Point p,int hp,int cost){
			this.p = new Point(p.x,p.y);
			this.hp = hp;
			this.cost = cost;
		}

		List<State> nexts(){
			List<State> sts = new ArrayList<State>();

			for(int i=0;i<4;i++){
				int nx = p.x + dx[i];
				int ny = p.y + dy[i];

				if(nx>=0 && nx<w && ny>=0 && ny<h && map[ny][nx]!=0 && hp-1>0){
					int nhp = (map[ny][nx]==4 ? 6 : hp-1);
					sts.add(new State(new Point(nx,ny),nhp,cost+1));
				}
			}

			return sts;
		}

		public int compareTo(State st){
			return this.cost - st.cost;
		}

		public boolean equals(Object o){
			State st = (State)o;
			return st.p.equals(p) && st.hp == hp;
		}

		public int hashCode(){
			return p.x + p.y * 10 + hp * 100;
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  int point = 1;
  
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    if ((point * 2) < (point + K)) point *= 2;
    else point += K;
  }
  
  cout << point << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=4005;
ll a[maxn];
ll b[maxn][maxn];
int main(){
	ll n,x,minn=1e17;
	cin>>n>>x;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[n+i]);
		a[i]=a[n+i];
	}
	for(int i=n+1;i<=n+n;i++){
		b[i-n][0]=a[i];
		for(int j=1;j<n;j++){
			b[i-n][j]=min(b[i-n][j-1],a[i-j]);
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=0;j<n;j++)
//			cout<<b[i][j]<<" ";
//		cout<<endl;
//	}
	for(int k=0;k<=n-1;k++){
		ll sum=k*x;
		for(int i=1;i<=n;i++)
			sum+=b[i][k];
		minn=min(minn,sum);
//		printf("sum=%d\n",sum);
	}
	cout<<minn<<endl;
}










Measured memory_bytes: 62976
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { 1, 0, -1, 0 };
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> X(N * N), Y(N * N);
	vector<vector<int> > dist(N, vector<int>(N));
	for (int i = 0; i < N * N; ++i) {
		int p;
		cin >> p; --p;
		X[i] = p / N;
		Y[i] = p % N;
	}
	for (int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			dist[i][j] = min({ i + 1, N - i, j + 1, N - j });
		}
	}
	vector<vector<bool> > flee(N, vector<bool>(N, false));
	long long ans = 0;
	for (int i = 0; i < N * N; ++i) {
		--dist[X[i]][Y[i]];
		ans += dist[X[i]][Y[i]];
		flee[X[i]][Y[i]] = true;
		queue<pair<int, int> > que;
		que.push(make_pair(X[i], Y[i]));
		while (!que.empty()) {
			pair<int, int> u = que.front(); que.pop();
			for (int j = 0; j < 4; ++j) {
				int tx = u.first + dx[j], ty = u.second + dy[j];
				if (0 <= tx && tx < N && 0 <= ty && ty < N && dist[tx][ty] > dist[u.first][u.second] + !flee[tx][ty]) {
					dist[tx][ty] = dist[u.first][u.second] + !flee[tx][ty];
					que.push(make_pair(tx, ty));
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6280
#include<iostream>
int N,a,b,v[1<<17],z,s;main(){std::cin>>N;while(N--)std::cin>>a>>b,v[a]++,v[b+1]--;while(++N<1<<17)z+=v[N],s=N<z+2?N-1:s;std::cout<<s<<'\n';}

Measured memory_bytes: 1556
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
//#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
//using namespace atcoder;
stack<int> st;
queue<int> qu;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define mod 1000000007
//#define mint=modint1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll D=0;
    ll S=0;
    int m;
    cin >> m;
    rep(i,m){
        ll d,c;
        cin >> d>> c;
        D+=c;
        S+=d*c;
    }
    ll ans=D-1+(S-1)/9;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3548
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    auto a = aryread();
    a.sort();
    // writeln(a);
    long ans = 0;
    long i = n;
    foreach (_; 0 .. n)
    {
        ans += a[n];
        n += 2;

    }
    writeln(ans);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 15400
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    p=min(a[i],b[i])
    a[i]-=p
    ans+=p
    q=min(b[i]-p,a[i+1])
    a[i+1]-=q
    ans+=q
print(ans)


Measured memory_bytes: 19156
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	ff 				first
#define 	ss				second
#define 	pb 				push_back
#define 	mp				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define     print(a)        cout << a << '\n'
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 
// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
 
// vll pwx(22);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 22)pwx[i] = x*(pwx[i-1]); }
 
/* ################################################################ */

#define space 200005

ll cnt;

void dfs(ll u, vvll &adj, vll &vis) {
    vis[u] = 1;
    cnt++;
    for(auto v : adj[u]) {
        if(!vis[v]) dfs(v, adj, vis);
    }
}

void solve() { 
    ll n, m, u, v;
    cin >> n >> m;

    map<pll, ll> mp;

    vvll adj(n+1);

    rep(i, 0, m) {
        cin >> u >> v;
        if(mp.find({u, v}) == mp.end()) {
            adj[u].pb(v);
            adj[v].pb(u);
        }
    }
    ll ans = 0;

    vll vis(n+1, 0);

    rep(i, 1, n+1) {
        if(!vis[i]) {
            cnt = 0;
            dfs(i, adj, vis);
            ans = max(ans, cnt);
        }
    }
    cout << ans << nl;

}

int main(){
    // boost;
    // cal(2);

    // For getting input from input.txt file 
    // freopen("running_on_fumes_chapter_1_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 25016
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N = I()
    print(int(N/2) if N%2==0 else int(N/2)+1)

main()



Measured memory_bytes: 12248
def dfs(now):
    if vis[now]:
        return 0
    vis[now]=1
    for i in range(n):
        if graph[now][i]:
            dfs(i)
n,m=map(int,input().split())
edge=[[int(i) for i in input().split()]for i in range(m)]
graph=[[0 for i in range(n)]for i in range(n)]
for i in range(m):
    graph[edge[i][0]-1][edge[i][1]-1]=1
    graph[edge[i][1]-1][edge[i][0]-1]=1
vis=[0]*n
ans=0
for i in range(m):
    graph[edge[i][0]-1][edge[i][1]-1]=0
    graph[edge[i][1]-1][edge[i][0]-1]=0
    vis=[0]*n
    dfs(0)
    connect=False
    for j in range(n):
        if vis[j]==0:
            connect=True
    if connect:
        ans+=1
    graph[edge[i][0]-1][edge[i][1]-1]=1
    graph[edge[i][1]-1][edge[i][0]-1]=1
print(ans)



Measured memory_bytes: 3064
#include<iostream>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <bits/stdc++.h> 
using namespace std;
 
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) 
\
 
int main()
{
	int n,d,i=0;
	cin>>n>>d;
  	if(n<10)
      i=d+(100*(10-n));
	else
      i=d;
	cout<<i;
  return 0;
}
    

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

int main(){
	int n;
	cin >> n;
	int fib[50];
	fib[0] = 1;
	fib[1] = 1;
	
	rep(i,n-1){
		fib[i+2] = fib[i+1] + fib[i];
	}
	
	cout << fib[n] << endl;
	
    return 0;
}




Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    int bcnt[s.size()];
    fill(bcnt, bcnt + s.size(), 0);
    rep(s.size(), i) {
        if (s[i] == 'B') bcnt[i]++;
    }
    rep2(1, s.size(), i) {
        bcnt[i] += bcnt[i - 1];
    }
    int ans = 0;
    rep(s.size(), i) {
        if (s[i] == 'W') ans += bcnt[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

vll fac(2,1),inv(2,1),finv(2,1) ;

void nCr_set(ll n){
	for(int i=2;i<=n;i++){
		fac.emplace_back(fac.at(fac.size()-1)*i%mod) ;
		inv.emplace_back(mod-inv.at(mod%i)*(mod/i)%mod) ;
		finv.emplace_back(finv.at(finv.size()-1)*inv.at(i)%mod) ;
	}
}

ll nCr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll nHr(ll n,ll r) {
	return nCr(n+r-1,n-1) ;
}

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}

int main(){
	ll n,m,k ;
	cin >> n >> m >> k ;
	nCr_set(n) ;
	ll ans = 0 ;
	for(int i=0;i<=k;i++){
		ans += nCr(n-1,i)*m%mod*modpow(m-1,n-i-1)%mod ;
		ans %= mod ;
	}
	cout << ans << endl ;
}


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

using namespace std;

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

int main() {
    int W, H, x, y;
    scanf("%d %d %d %d", &W, &H, &x, &y);
    double area = 1.0 * W * H / 2;
    int multi = 0;
    if (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2) {
        multi = 1;
    }
    printf("%lf %d\n", area, multi);
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        if(Math.abs(N-M) > 1){
            System.out.println(0);
            return;
        }
        long r = 1000000007;
        long ans = 1;
        while(N > 0 && M > 0){
            ans *= N;
            ans %= r;
            ans *= M;
            ans %= r;
            N--;
            M--;
        }
        if(N == M)  ans *= 2;
        ans %= r;
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
 
void swap(int* a,int* b){
    int po=*a;
    *a=*b;
    *b=po;
}
 
int seiretu(int* p,int N){
    for(int i=0;i<N;i++)if(p[i]!=i)return 0;
    return 1;
}
 
int main(void){
    int N;
    int count=0;
    int po[114514];
    scanf("%d",&N);
    int p[N];
    for(int i=0;i<N;i++)scanf("%d",&p[i]);
    while(seiretu(p,N)==0){
        if(p[0]<p[N-1]&&!(p[0]==0&&p[N-1]==N-1)){po[count]=N-1;count++;swap(&p[0],&p[N-1]);}
        for(int i=0;i<N-1;i++)swap(&p[i],&p[i+1]);po[count]=1;count++;
    }
    printf("%d\n",count);
    for(int i=0;i<count;i++)printf("%d\n",po[i]);
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		
		//２つの自然数入力
		int x = scan.nextInt();
		int y = scan.nextInt();
		scan.close();
		
		int gcd;
		
		
		if ( x == y) {
			gcd = x;
		} else {
			if (x > y) {
				int n = x % y;
				gcd = Gcd(y,n);
			}else {
				int n = y % x;
				 gcd = Gcd(x,n);
			}
		}
		
		System.out.println(gcd);
		
	}
	
	//最大公約数を求める
	public static int Gcd(int x, int y) {
		
		int n = Math.min(x, y);
		
		for (int i = n; i >= 1; i--) {
			if (x % i == 0 && y % i == 0) {
				return i;
			}
		}
		
		return 1;
	}
}



Measured memory_bytes: 26368
# エラトステネスの篩
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        c = 0
        while n % p == 0:
            n //= p
            c += 1
        result.append((p, c))
    return result


N = int(input())

prime_table = make_prime_table(N)
d = {}
for i in range(2, N + 1):
    for p, c in prime_factorize(i):
        d.setdefault(p, 0)
        d[p] += c

# 75 = 5 * 5 * 3
#    = 15 * 5
#    = 25 * 3
#    = 75
n74 = 0
n24 = 0
n14 = 0
n4 = 0
n2 = 0
for k in d:
    if d[k] >= 74:
        n74 += 1
    if d[k] >= 24:
        n24 += 1
    if d[k] >= 14:
        n14 += 1
    if d[k] >= 4:
        n4 += 1
    if d[k] >= 2:
        n2 += 1

result = 0
# x ^ 4 * y ^ 4 * z ^ 2 の約数の個数は75個
result += n4 * (n4 - 1) // 2 * (n2 - 2)
# x ^ 14 * y ^ 4 の約数の個数は75個
result += n14 * (n4 - 1)
# x ^ 24 * y ^ 2 の約数の個数は75個
result += n24 * (n2 - 1)
# x ^ 74 の約数の個数は75個
result += n74
print(result)


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

int main(){
    int n, ans;
    vector<int> v;
    cin >> n;
    ans = n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        v.emplace_back(a);
    }
    bool flag = false;
    int j = 1;
    for (int i = 0; i < n; i++)
    {
        if (v[i] == j)
        {
            ans--;
            j++;
            flag = true;
        }
    }
    if (flag)
    {
       cout << ans << endl;
       return 0;
    }    
    cout << -1 << endl;
}

Measured memory_bytes: 1400
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

#include<unistd.h>
struct Buffer{
    int idx;
    enum { chunk = 1 << 12 };
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    Buffer buf;
    int lim = 1e5;
    vector<char> prime(lim + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= lim; i++){
        if(prime[i]){
            for(int j = i + i; j <= lim; j += i){
                prime[j] = false;
            }
        }
    }
    vector<int> accs(lim + 1);
    for(int i = 1; i <= lim; i++){
        accs[i] = accs[i - 1] + (i & 1 && prime[i] && prime[(i + 1) / 2]);
    }
    // int q; cin >> q;
    int q = buf.next();
    for(int i = 0; i < q; i++){
        // int l, r;
        // cin >> l >> r;
        int l = buf.next(), r = buf.next();
        cout << accs[r] - accs[l - 1] << '\n';
    }
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
int a,b,p=0,r,v;
char s[6];
cin>>a>>b;
sprintf(s,"%d",b);
while(s[p]!='\0')p++;
r=1;
while(p--)
{
r*=10;
}
v=a*r+b;
if(sqrt(double(v))==floor(sqrt(double(v))))
{puts("Yes");}
else
{puts("No");}
return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

ll fexp(ll b, ll e, ll p = PRIME) {
  ll res = 1;
  while (e) {
    if (e & 1) res = (res * b) % p;
    b = (b * b) % p;
    e >>= 1;
  }
  return res;
}

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();

struct no_hack_hash {
  int operator()(int x) const { return x ^ RANDOM; }
};

struct iihash {
  int operator()(ii x) const { return x.first * 31 + x.second; }
};

// To use most bits rather than just the lowest ones:
struct ghash {  // large odd number for C
  const uint64_t C = ll(4e18 * acos(0)) | 71;
  ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};

/*-----------------END TEMPLATE-----------------*/

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  ll n, m;
  cin >> n >> m;
  ll left = 1, right = n;
  while (m--) {
    ll a, b;
    cin >> a >> b;
    left = max(left, a);
    right = min(right, b);
  }

  cout << max(right - left + 1, 0ll) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib> 
using namespace std;
int t;
long long a,b,c,d;
long long mygcd(long long x,long long y)
{
	return !y?x:mygcd(y,x%y);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(d<b || a<b)
		{
			puts("No");
			continue;
		}
		if(c>=b)
		{
			puts("Yes");
			continue;
		}
		long long g=mygcd(b,d%b);
		if(b-g+a%g>c)puts("No");
		else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

char ans[15];

int Solve(ll num, int turn){
  for (int i = turn - 1; i >= 0; i--){
    ans[i] = 'a' + num % 26;
    num /= 26;
  }

  printf("%s\n", ans);

  return 0;
}

int main(){
  ll N, num = 26, turn = 1; cin >> N;
  while (N - num > 0){
    N -= num; num *= 26; turn++;
  }
  Solve(N - 1, turn);

  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<bitset>
#include<cctype>

int read(){
	char ch;
	while (isspace(ch=getchar()));
	int ret=ch&15;
	while (isdigit(ch=getchar())) ret=(ret<<1)+(ret<<3)+(ch&15);
	return ret;
}

int n,sum,ans;
std::bitset<2000001> B;

int main(){
	n=read();B[0]=1;
	while (n--){
		int x=read();
		sum+=x;
		B|=B<<x;
	}
	ans=sum>>1;
	while (!B[ans]) ans--;
	printf("%d\n",sum-ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


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

    ll n,W;cin >> n >> W;
    vector<ll> w(n),v(n);
    rep(i,n)cin >> w[i] >> v[i];
    //dp[i][j]:=i番目までで価値j以上を手に入れる時の最小の重さ
    vector<vector<ll>> dp(n+1,vector<ll>(110000,W+1000000));
    dp[0][0]=0;
    //dp[i][j]から次へ配る
    rep(i,n)rep(j,100001){
        dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
        if(j+v[i]<110000)dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
    }
    int ans=0;
    rep(i,100001){
        if(dp[n][i]>W)continue;
        else ans=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 90808
N=int(input())
A=list(map(int,input().split()))
odd,even=0,0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
if even+odd//2==0:
    if odd%2==1:
        print("YES")
    else:
        print("NO")
else:
    if odd%2==1:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 14108
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  COUT(n/3);

  return 0;
}

Measured memory_bytes: 256
cou = 0

N = int(input())
l = list(map(int, input().split()))

for i in range(N):
  minj = i
  for j in range(i,N):
    if l[j] < l[minj]:
      minj = j
  if not l[i] == l[minj]:
    a = l[i]
    b = l[minj]
    l[i] = b
    l[minj] = a
    cou += 1

print(" ".join(map(str,l)))
print(cou)



Measured memory_bytes: 5596
// https://atcoder.jp/contests/abc126/tasks/abc126_e

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <class T>
inline bool chmax(T& a, T b);
template <class T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);

struct UnionFind {
  vector<ll> parents;

  UnionFind(ll n) : parents(vector<ll>(n, -1)) {}

  ll root(ll a) {
    if (parents[a] < 0) {
      return a;
    }

    auto r = root(parents[a]);
    parents[a] = r;
    return r;
  }

  bool same(ll a, ll b) { return root(a) == root(b); }

  void merge(ll a, ll b) {
    ll ar = root(a);
    ll br = root(b);

    if (ar == br) {
      return;
    }

    // make less index one as a root
    if (ar > br) {
      swap(ar, br);
    }

    parents[ar] += parents[br];
    parents[br] = ar;
  }

  ll size(ll a) { return -parents[a]; }

  ll group_count() {
    ll res = 0;

    for (auto s : parents) {
      if (s < 0) {
        res++;
      }
    }

    return res;
  }
};

void solve() {
  ll N, M;
  cin >> N >> M;

  UnionFind uf(N);
  rep(i, 0, M) {
    ll x, y, z;
    cin >> x >> y >> z;

    uf.merge(x - 1, y - 1);
  }

  ll res = uf.group_count();
  cout << res << endl;
}

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#endif

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;
}

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}


Measured memory_bytes: 1024
N=int(input())
S=input()
l=[0,0,0]
a=0
for i in S:
    if i=="R":
        l[0]+=1
        a+=l[1]*l[2]
    elif i=="G":
        l[1]+=1
        a+=l[0]*l[2]
    else:
        l[2]+=1
        a+=l[0]*l[1]
for i in range(1,2000):
    for j in range(N-2*i):
        if S[j]!=S[i+j] and S[j+i]!=S[j+i+i] and S[j]!=S[j+i+i]:
            a-=1
print(a)

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

int main() {
  int x,y;
  cin >> x >> y;
  if(y%2 == 1){
    cout << "No";
  }
  else if(y >= 2*x && y <= 4*x){
    cout << "Yes";
  }
  else
    cout << "No";
}
  
  

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    int n,k,q,a;
    cin >> n >> k >> q;
    vector<int>score(n,k-q);
    rep(i,q){
        cin >> a;
        score[a-1]++;
    }
    
    rep(i,n)cout << (score[i]>0?"Yes":"No") << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 2e5 + 10;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
int main() {
	ll a, b; cin >> a >> b;
	int cnt = 1;
	for (ll i = 2; i*i <= a && i*i <= b; ++i) {
		if (a%i == 0 && b%i == 0) {
			cnt++;
			while (a%i == 0) a /= i;
			while (b%i == 0) b /= i;
			//cout << i << " " << a << " " << b << endl;
		}
	}
	if (gcd(a, b) != 1) cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>



int main(void)
{
	ll a, b, c, d, ans;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  int a[H][W];
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }
  vector< vector<int> > op;
  vector<int> tmp(4);
  int cnt = 0;
  for(int i = 0; i < H; i++){
    if(i % 2 == 0){
      for(int j = 0; j < W-1; j++){
	if(a[i][j] % 2 != 0){
	  tmp[0] = i+1;
	  tmp[1] = j+1;
	  tmp[2] = i+1;
	  tmp[3] = j+2;
	  cnt++;
	  op.push_back(tmp);
	  a[i][j+1]++;
	}
      }
      if(a[i][W-1] % 2 != 0 && i < H-1){
	tmp[0] = i+1;
	tmp[1] = W;
	tmp[2] = i+2;
	tmp[3] = W;
	cnt++;
	op.push_back(tmp);
	a[i+1][W-1]++;
      }
    }else{
      for(int j = W-1; j > 0; j--){
	if(a[i][j] % 2 != 0){
	  tmp[0] = i+1;
	  tmp[1] = j+1;
	  tmp[2] = i+1;
	  tmp[3] = j;
	  cnt++;
	  op.push_back(tmp);
	  a[i][j-1]++;
	}
      }
      if(a[i][0] % 2 != 0 && i < H-1){
	tmp[0] = i+1;
	tmp[1] = 1;
	tmp[2] = i+2;
	tmp[3] = 1;
	cnt++;
	op.push_back(tmp);
	a[i+1][0]++;
      }
    }
  }
  
  cout << cnt << endl;
  for(int i = 0 ; i < cnt; i++){
    cout << op[i][0] << " " << op[i][1] << " " << op[i][2] << " " << op[i][3] << endl;
  }
}


Measured memory_bytes: 9904
#include<bits/stdc++.h>
using namespace std ;
using ll = long long ;
const ll INF = 1e18L + 7 ;
int main(){
	int n,k ;
	cin >> n ;
	vector<ll>a(n) ;
	for(auto& x : a)
		cin >>  x ;
	ll dp[405][405] ;
	
	auto sum = [&](int x,int y){
		ll sm = 0 ;
		for(int i=x;i<=y;i++)
			sm += a[i] ;
		return sm ;	
	} ;
	for(int i= n-1 ; i>=0 ; --i){
		for(int j=i; j < n ; j++){
			if(i==j)
				dp[i][j] = 0 ;
			else{
				dp[i][j] = INF ;
				ll sm = sum(i,j) ;
				for(int k=i; k < j; k++)
					dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+ sm ) ; // like mcm 
			}	
		
		}
	}	
	cout << dp[0][n-1] << endl ;	
}




Measured memory_bytes: 1536
S = input().split()
a = int(S[0])
b = int(S[1])
x = int(S[2])
def func(n, x): 
    ans=0
    if n>=0:
        ans+=(n//x)+1
    else:
        ans=0
    return int(ans)

answer = func(b, x) - func(a-1, x)
print(answer)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    int max1 = INT_MIN;
    for(int i=0 ;i < n ;i ++ )
        cin>> a[i],max1 = max( max1 , a[i]) ;
    int dp [max1+1];
    memset(dp,0,sizeof(dp));
    sort(a,a+n);
    for(int i=0 ;i < n;i++ ) dp[a[i]] ++ ;
    for(int i = 0 ;i < n ;i++ ) {
        int val = a[i];
        for(int j = 2*val ; j <= max1; j +=val){
            dp[j] +=1;
        }
    }
    int ans =0 ;
    for(int i = 0 ; i< n;i++ ) {
        if( dp[a[i]] == 1) {
            ans ++ ;
        }
    }
    cout<< ans ;
}


Measured memory_bytes: 8228