akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 200005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n;
	cin>>n>>k;
	ll pr[n+1],cr[n+1];
	for(i=1;i<=n;i++){
		cin>>pr[i];
	}
	for(i=1;i<=n;i++){
		cin>>cr[i];
	}

	ll ans=-1e18;
	for(i=1;i<=n;i++){
		ll fl[n+1]={0},tmp=i,sc=0,c=0,an=0;
		while(fl[tmp]==0){
			fl[tmp]=1;
			tmp=pr[tmp];
			sc+=cr[tmp]; c++;
		}
		// if(i==4)
		// 	cout<<sc<<endl;
		ll q=k/c,r=k%c;
		if(k%c==0) q--,r=c;
		if(sc<0){
			memset(fl,0,sizeof(fl));
			tmp=i; sc=0; an=-1e18; ll vv=k;
			while(vv>0&&fl[tmp]==0){
				fl[tmp]=1;
				tmp=pr[tmp]; vv--;
				sc+=cr[tmp]; an=max(an,sc);
			}
		}
		else{
			an+=q*sc;
			// if(i==4)
			// cout<<an<<endl;
			tmp=i; sc=0; ll vv=-1e18;
			while(r>0){
				tmp=pr[tmp];
				sc+=cr[tmp]; r--;
				vv=max(vv,sc);
			}
			an+=vv;
		}
		// cout<<i<<" "<<an<<endl;
		ans=max(ans,an);
	}
	cout<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll,ll> P;
ll n,a[10005];
ll LCM=1;
ll ans;
ll P[1000001];
ll p[10000];
ll pp=0;
const ll MOD=1000000007;
map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i=2;i*i<=n;i++){
        bool w=true;
        while(n%i==0){
            res[i]++;
            n=n/i;
            if(w){
                w=false;
                p[pp]=i;
                pp++;
            }
        }
    }
    if(n!=1){
        res[n]=1;
        p[pp]=n;
        pp++;
    }
    return res;
}
ll modinv(ll a,ll MOD) {
    ll b=MOD,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=MOD; 
    if(u<0) u+=MOD;
    return u;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        map<ll,ll> M;
        M=prime_factor(a[i]);
        for(int j=0;j<pp;j++){
            P[p[j]]=max(P[p[j]],M[p[j]]);
            p[j]=0;
        }
        pp=0;
    }
    for(int i=0;i<1000001;i++){
        for(int j=0;j<P[i];j++){
            LCM=(LCM*i)%MOD;
        }
    }
    for(int i=0;i<n;i++){
        ans=(ans+(LCM*modinv(a[i],MOD))%MOD)%MOD;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 7468
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# LRLRRL
#    ↑
# 反転させると
# LLLRLL
#  ↑↑  ↑
# また反転させると
# LLLLLL
#  ↑↑↑↑↑

# 反転させると最大2人まで幸福な人を増やせる
N, K = getNM()
s = input()
cnt = 0
for i in range(N - 1):
    if s[i] == s[i + 1]:
        cnt += 1
print(min(cnt + 2 * K, N - 1))

Measured memory_bytes: 39536
#include <iostream>
#include <cstdlib>
#include <vector>
#define llint long long

using namespace std;

struct WeightedUnionFind{
	int size;
	vector<int> parent;
	vector<llint> weight;
	
	WeightedUnionFind(){}
	WeightedUnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		weight.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i, weight[i] = 0;
	}
	int root(int i){
		if(parent[i] == i) return i;
		int r = root(parent[i]);
		weight[i] = weight[parent[i]] + weight[i];
		return parent[i] = r;
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	llint get(int i, int j){ //i->jの重みを返す（非連結なら0を返す）
		if(!same(i, j)) return 0;
		return weight[j]-weight[i];
	}
	bool unite(int i, int j, llint x){ //i->jの重みをxに設定する。矛盾があればfalseを返す。
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j){
			return get(i, j) == x;
		}
		parent[root_i] = root_j;
		weight[root_i] = weight[j]-weight[i]-x;
		return true;
	}
};

llint n, s;
llint x[100005], p[100005];
WeightedUnionFind wuf(100005);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;
	for(int i = 1; i <= n; i++) cin >> x[i] >> p[i];
	
	llint l = 1, r = n, m = lower_bound(x, x+n+1, s) - x;
	while(l < r){
		if(l >= m){
			l = r;
			break;
		}
		if(r < m){
			r = l;
			break;
		}
		if(p[l] >= p[r]){
			p[l] += p[r];
			wuf.unite(l, r, x[r]-x[l]);
			r--;
		}
		else{
			p[r] += p[l];
			wuf.unite(r, l, x[r]-x[l]);
			l++;
		}
		//cout << l << " " << r << endl;
	}
	
	/*for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout << wuf.get(i, j) << " ";
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, wuf.get(l, i));
	ans += abs(s - x[l]);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 35088
fun main(args: Array<String>) {
    fun max(x: Long, y:Long) = if (x > y) x else y
    val sc = java.util.Scanner(System.`in`)
    val N = sc.next().toLong()
    val M = sc.next().toLong()

    if (M == 1L && N == 1L){
        println(1)
    } else if (M == 1L || N == 1L) {
        println( max(N,M) - 2 )
    } else {
        println( (N-2)*(M-2) )
    }

}

Measured memory_bytes: 29596
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b;
  cin >> a >> b;

  map<int, int> mp;
  mp[1]=0;
  mp[3]=0;
  mp[5]=0;
  mp[7]=0;
  mp[8]=0;
  mp[10]=0;
  mp[12]=0;
  mp[2]=1;
  mp[4]=2;
  mp[6]=2;
  mp[9]=2;
  mp[11]=2;
  cout << (mp[a]==mp[b] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n, x, i;
    int d[101], l[101];
    scanf("%d %d", &n, &x);
    d[0] = 0;
    for (i=0; i<n; i++){
            if (i==n-1) scanf("%d\n", &l[n-1]);
            else scanf("%d", &l[i]);
    }
    for (i=0; i<n; i++){
        d[i+1] = d[i]+l[i];
        if (d[i+1]>x){
            printf("%d", i+1);
            break;
        }
        if (i==n-1){
            printf("%d", n+1);
        }
    }
    
    return 0;
}

Measured memory_bytes: 128
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();
    int z = scan.nextInt();
    
    System.out.println(z + " " + x + " " + y);
    
  }
  
}

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

using namespace std;

int X[101010];
int n, k, ans;

int main()
{
	int i;
	
	ans = 1e9;
	
	scanf("%d%d", &n, &k);
	
	for(i=0; i<n; i++){
		scanf("%d", X + i);
	}
	
	for(i=0; i<=n-k; i++){
		if(X[i + k - 1] <= 0) ans = min(ans, -X[i]);
		else if(X[i] >= 0) ans = min(ans, X[i + k - 1]);
		else ans = min(ans, X[i + k - 1] - X[i] + min(-X[i], X[i + k - 1]));
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, m, x, i;

    int a[102] = {0};

    int ku = 0;

    int ks = 0;
   
      
    scanf("%d %d %d", &n, &m, &x );
   

    for( i = 1 ; i <= m ; i = i + 1 ){

        scanf("%d", &a[i] );

        }

    
    for( i = 1 ; i <= m ; i = i + 1 ){

         if( a[i] > x ) ku += 1;

         }

    for( i = 1 ; i <= m ; i = i + 1 ){

         if( a[i] < x ) ks += 1;

         }


    if( ku < ks ){

        printf("%d\n", ku );

        return 0;

        }

    else{

          printf("%d\n", ks );

          return 0;

          }


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

const int MAXLEN = 3000;
short dp[MAXLEN][MAXLEN];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string s, t;
    cin >> s >> t;

    int slen = s.length();
    int tlen = t.length();

    // is = 0
    for (int it = 0; it < tlen; ++it) {
        if (s[0] == t[it]) {
            for (; it < tlen; ++it) {
                dp[0][it] = 1;
            }
        } else {
            dp[0][it] = 0;
        }
    }

    //! it = 0
    for (int is = 0; is < slen; ++is) {
        if (s[is] == t[0]) {
            for (; is < slen; ++is) {
                dp[is][0] = 1;
            }
        } else {
            dp[is][0] = 0;
        }
    }

    for (int is = 1; is < slen; ++is) {
        for (int it = 1; it < tlen; ++it) {
            if (s[is] == t[it]) {
                dp[is][it] = dp[is-1][it-1] + 1;
            } else {
                dp[is][it] = max(dp[is-1][it], dp[is][it-1]);
            }
        }
    }

    string ans;
    int it = tlen-1;
    int is = slen-1;
    while (0 <= is && 0 <= it && 0 < dp[is][it]) {
        while (0 < it && dp[is][it-1] == dp[is][it]) --it;
        while (0 < is && dp[is-1][it] == dp[is][it]) --is;
        ans = s[is] + ans;
        --is;
        --it;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
 
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ "; for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") "; return os<<"}"; }
    #define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " |"; __f(comma + 1, args...); }
#define rng(x) x.begin(), x.end()
#define pb push_back
#define F first
#define S second
#define el '\n'
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
 
/*-----------------------------Code begins----------------------------------*/

vvi moves;
vector <string> mat;
int n, m;
queue <pi> Q;

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

bool isValid(int x, int y){
    return x >= 0 and x < n and y >= 0 and y < m and mat[x][y] == '.' and moves[x][y] == -1;
}

void dfs(int x, int y){
    for (int i = 0; i < 4; ++i){
        int nx = x + dx[i], ny = y + dy[i];
        if(!isValid(nx, ny)) continue;
        moves[nx][ny] = moves[x][y];
        Q.push({nx, ny});
        dfs(nx, ny);
    }
}


void solve(){
    cin>>n>>m;
    int sx, sy; cin>>sx>>sy; sx--; sy--;
    int ex, ey; cin>>ex>>ey; ex--; ey--;
    moves = vvi(n, vi(m, -1));
    mat = vector <string> (n);
    for(string &str : mat) cin>>str;

    moves[sx][sy] = 0;
    Q.push({sx, sy});
    dfs(sx, sy);

    while(!Q.empty()){
        int x = Q.front().F, y = Q.front().S; Q.pop();
        if(x == ex and y == ey) break;

        for (int xf = -2; xf <= 2; ++xf){
            for (int yf = -2; yf <= 2; ++yf){
                int nx = x + xf, ny = y + yf;
                if(!isValid(nx, ny)) continue;
                moves[nx][ny] = moves[x][y] + 1;
                Q.push({nx, ny});
                dfs(nx, ny);
            }
        }
    }

    cout<<moves[ex][ey]<<el;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1;
    // cin>>T; 
    while(T--){
        solve();
    }
    return 0; 
}

Measured memory_bytes: 8796
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		A_ColorfulSubsequence solver = new A_ColorfulSubsequence();
		solver.solve(1, in, out);
		out.close();
	}

	static class A_ColorfulSubsequence {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			final int MOD = (int) (1e9 + 7);
			in.nextInt();
			char[] s = in.next().toCharArray();
			int[] a = new int[26];
			for (char c : s) {
				++a[c - 'a'];
			}
			long ans = 1;
			for (int x : a) {
				ans = ans * (x + 1) % MOD;
			}
			ans = (ans + MOD - 1) % MOD;
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		int n = in.nextInt();
		int k = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		int x = Kstone(arr, k);
		if (x == 1) {
			System.out.println("First");
		} else {
			System.out.println("Second");
		}
	}

	public static int Kstone(int a[], int k) {
		int dp[] = new int[k + 1];
		int n = a.length;
		for (int i = 1; i < k + 1; i++) {
			for (int j = 0; j < n; j++) {
				if (i - a[j] >= 0) {
					if (dp[i - a[j]] == 0) {
						dp[i] = 1;
					}
				}
			}
		}
		return dp[k];
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

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

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
bool dp[110000];
int main()
{
	int N, K;
	cin >> N >> K;
	vec(A);
	fx(N) {
		vecp(A);
	}

	fx(K) {
		bool flag = false;
		fy(N) {
			if (x+1-A[y]>=0) {
				flag |= !dp[x + 1 - A[y]];
			}
		}
		dp[x + 1] = flag;
	}
	if (dp[K]) {
		ce("First")
	}
	else {
		ce("Second")
	}
    return 0;
}



Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextLong();
        var M = sc.nextLong();

        var ans = 0L;
        if (N * 2 <= M) {
            ans += N;
            M -= N * 2;
            ans += M / 4;
        } else {
            ans += M / 2;
        }
        WriteLine(ans);
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {

        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

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

        vi a(n),b(n);
        rep(i,n)cin>>a[i];
        reverse(all(a));

        int left=0,right=n-1;

        rep(i,n)
        {
                if(i%2==0)
                {
                        b[left++]=a[i];
                }else
                {
                        b[right--]=a[i];
                }
        }

        each(it,b)cout<<it<<" ";
        cout<<endl;
}

Measured memory_bytes: 3712
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int r,g,b,n;
    R(r,g,b,n);
    int ans=0;
    REP1(i,0,n/r) REP1(j,0,n/g) {
        int k=n-i*r-j*g;
        if ( k>=0 && k%b==0 ) ans++;
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3740
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,a,b;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n >> a >> b;
	rc(min(n * a,b));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define llint long long

using namespace std;

int n;
int a, b, c, d;
string s;
vector<string> vec;

int main(void)
{
	cin >> s;
	s += "D";
	
	int id = 0; string t;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A') t += 'A';
		else if(s[i] == 'B'){
			if(i+1 < s.size() && s[i+1] == 'C'){
				t += 'B';
				i++;
			}
			else{
				vec.push_back(t);
				t = "";
			}
		}
		else{
			vec.push_back(t);
			t = "";
		}
	}
	
	//for(int i = 0; i < vec.size(); i++) cout << vec[i] << endl;
	
	llint ans = 0;
	for(int i = 0; i < vec.size(); i++){
		llint cnt = 0;
		for(int j = 0; j < vec[i].size(); j++){
			if(vec[i][j] == 'A') cnt++;
			else ans += cnt;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5368
#include <stdio.h>
int main()
{
    int a,b,c=0;
    scanf("%d",&a);
    int num[a];
    for(int i=0; i<a; i++)
        scanf("%d",&num[i]);
    for(int i=0; i<a; i++)
    {
        for(int j=i+1; j<a; j++)
            if(num[i]<num[j])
                continue;
            else
            {
                b=num[i];
                num[i]=num[j];
                num[j]=b;
            }
    }
    for(int i=0; i<a; i++)
    {
        for(int j=i+1; j<a; j++)
        {
            for(int k=j+1; k<a; k++)
            {
                if(num[i]+num[j]>num[k])
                    c++;
            }
        }
    }
    printf("%d",c);
    return 0;
}


Measured memory_bytes: 128
n = input()
l = len(n)

per0 = str('0')
for i in range(l-1):
    if (i+1)%2 == 0:
        per0 = per0 + str('0')
    else:
        per0 = per0 + str('1')

per1 = str('1')
for i in range(l-1):
    if (i+1)%2 == 0:
        per1 = per1 + str('1')
    else:
        per1 = per1 + str('0')

count0 = 0
count1 = 0
for i in range(l):
    if n[i] == per0[i]:
        count0 = count0 + 1
    elif n[i] == per1[i]:
        count1 = count1 + 1
    else:
        count0 = count0
        count1 = count1

print(min(count0,count1))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <boost/algorithm/string/replace.hpp>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  string a;
  cin >> a;
  boost::algorithm::replace_all(a, ",", " ");
  cout << a << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
ll n;
const int sz=1e5;
vector<ll> g[sz];
vector<ll> path,mem;
vector<ll> col;
void dfs(int v,int p)
{
    path.push_back(v);
    if(v==n-1)mem=path;
    for(int to:g[v])if(to!=p)dfs(to,v);
    path.pop_back();
}
void dfs2(int v,int c)
{
    for(int to:g[v])if(col[to]==-1)col[to]=c,dfs2(to,c);
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    rep(i,n-1)
    {
        int u,v;cin>>u>>v;--u,--v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0,-1);
    col.assign(n,-1);
    int sz=mem.size();
    for(int i=0;i<(sz+1)/2;i++)col[mem[i]]=0;
    for(int i=(sz+1)/2;i<sz;i++)col[mem[i]]=1;
    for(int i=0;i<sz;i++)dfs2(mem[i],col[mem[i]]);
    int dif=0;
    for(int i=-0;i<n;i++)dif+=(col[i]==0?1:-1);
    cout<<(dif>0?"Fennec":"Snuke");
    return 0;
}

Measured memory_bytes: 17524
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

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

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl;
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n,q;
	R(n);
	vi a(n);
	rv(a);
	map<int,int>frq;
	for(auto x : a)
	{
		frq[x]++;
		sum += x;
	}
	R(q);
	while(q--)
	{
		int b,c;
		R(b,c);
		sum += (c-b)*frq[b];
		frq[c]+=frq[b];
		frq[b] = 0;
		W(sum);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 7988
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

char ma[2000 + 5][2000 + 5];
int l[2000 + 5][2000 + 5];
int r[2000 + 5][2000 + 5];
int u[2000 + 5][2000 + 5];
int d[2000 + 5][2000 + 5];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> ma[i][j];

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (ma[i][j] == '#')l[i][j] = 0;
			else l[i][j] = l[i][j - 1] + 1;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = m; j >= 1; j--)
		{
			if (ma[i][j] == '#')r[i][j] = 0;
			else r[i][j] = r[i][j + 1] + 1;
		}
	}
	for (int j = 1; j <= m; j++)
	{
		for (int i = 1; i <= n; i++)
		{
			if (ma[i][j] == '#')u[i][j] = 0;
			else u[i][j] = u[i-1][j] + 1;
		}
	}
	for (int j = 1; j <= m; j++)
	{
		for (int i = n; i >= 1; i--)
		{
			if (ma[i][j] == '#')d[i][j] = 0;
			else d[i][j] = d[i + 1][j] + 1;
		}
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			long long res = 0;
			int flag = 0;
			if (l[i][j])flag++, res += l[i][j];
			if (r[i][j])flag++, res += r[i][j];
			if (u[i][j])flag++, res += u[i][j];
			if (d[i][j])flag++, res += d[i][j];
			if (flag >= 2)res = res - flag + 1;
			ans = max(ans, res);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<10;++i){
        for(int j=1;j<10;++j){
            if(i*j==n){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

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

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

ll lcm(ll a,ll b){
  ll g=gcm(a,b);
  return a/g*b;
}

int main(void){
  int N;
  cin >> N;
  ll ans=1LL;
  for(int i=0;i<N;i++){
    ll X;
    cin >> X;
    ans=lcm(ans,X);
  }
  cout << ans << endl;
  return 0;
}
  


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
vector<int> v;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void dfs(ll s, ll n) {
  if (s > n) return;
  string t = to_string(s);
  if (t.find("3") != string::npos && t.find("5") != string::npos && t.find("7") != string::npos) {
    v.push_back(s);
  }
  dfs(10 * s + 3, n);
  dfs(10 * s + 5, n);
  dfs(10 * s + 7, n);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;  cin >> n;
    dfs(0, n);
    cout << v.size() << '\n';

    return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var n, x int64
	fmt.Fscanf(in, "%d%d", &n, &x)

	xs := make([]int64, n)
	for i := range xs {
		fmt.Fscanf(in, "%d", &xs[i])
	}
	ans := abs(xs[0] - x)
	for i := range xs {
		ans = abs(gcd(ans, xs[i]-x))
		x = xs[i]
	}
	fmt.Fprintln(out, ans)
}

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 7296
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <functional>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int

using namespace std;

int main(void) {
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    vector<int> d(n);
    REP(i,n) cin >> d[i];
    sort(d.begin(),d.end(),greater<int>());
    int ans = c/a;
    REP(i,n){
        c += d[i];
        a += b;
        ans = max(ans,c/a);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <map>
#include <cmath>
#include <cctype>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
vector<vector<pair<int,int>>> z(100010);


int main()
{
    int N,K,i;
    cin >> N >>K;
    double ans=0; 
    srep(i,1,N+1){
        int cnt=0;
        while(i*pow(2,cnt)<K){
            cnt++;
        }
        ans+=(double)1*pow(0.5,cnt)/N;
    }
        cout <<fixed << setprecision(13)<< ans <<endl;

    return 0;
}

Measured memory_bytes: 2560
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a = LIST()

a = [x//2 for x in a]
if a[0] % 2 == 0:  # 偶数の時
	for x in a:
		if x % 2 == 1:
			print(0)
			sys.exit(0)
	for x in a:
		if a[0] != x and abs(a[0]-x)%gcd(2*a[0], 2*x) != 0:
			print(0)
			sys.exit()

	tmp = 1
	for x in a:
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)


else:
	for x in a:
		if x % 2 == 0:
			print(0)
			sys.exit(0)
	tmp = 1
	for x in a:  # 奇数の時
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)


Measured memory_bytes: 85100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    cin >> n;
    bool ans = false;
    if (n == 3 || n == 5 || n == 7) ans = true;

    if (ans) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i]; 
		b[i]=a[i];	
	} 
	sort(b,b+n);
	for(int i=0;i<n;i++)
	{
		if(a[i] == b[n-1])
			cout << b[n-2] << endl;
		else
			cout << b[n-1] << endl;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
using namespace std;
signed main()
{
    int t,a=0,b=0,c=0,d=0;
      string s;
   // string s1="x";
    cin>>t;
  for(int i=0;i<t;i++)
    {
      
        cin>>s;
        if(s=="AC")
        a++;
         if(s=="TLE")
        b++;
         if(s=="WA")
        c++;
         if(s=="RE")
        d++;
    }
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<c<<"\n";
    cout<<"TLE x "<<b<<"\n";
    cout<<"RE x "<<d;

}
                 


Measured memory_bytes: 3620
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ab_sum , answer, b_i = sum(B), 0, M
for a_i in range(N+1):
  while b_i>0 and ab_sum >K:
    b_i -= 1
    ab_sum -= B[b_i]
  if ab_sum >K:
    break
  answer = max(answer, a_i+b_i)
  if a_i==N:
    break
  ab_sum += A[a_i]

print(answer)


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

using namespace std;
using ll = long long;

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

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
    }
    for(int i = 0; i < m; ++i) {
        cin >> b.at(i);
    }

    int ai = 0;
    while(ai < n && k >= 0) {
        k -= a.at(ai);
        ai++;
    }
    if(k < 0) {
        ai--;
        k += a.at(ai);
    }

    int bi = 0, ans = ai;
    while(true) {
        while(k >= 0 && bi < m) {
            k -= b.at(bi);
            bi++;
        }
        if(k < 0) {
            bi--;
            k += b.at(bi);
        }
        ans = max(ans, ai + bi);
        if(ai == 0) break;
        k += a.at(ai - 1);
        ai--;
    }

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

    return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

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

typedef vector<ll> vecll;
typedef vector<ld> vecld;
typedef vector<bool> vecbl;
typedef vector<vector<ll> > matll;
typedef vector<vector<ld> > matld;
typedef vector<vector<bool> > matbl;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

// nのk乗(mod p = prime)
ll power(ll n, ll k) {
	ll p = prime;
	if (k == 1) {
		return n;
	}
	ll m = n * n;
	m %= p;
	if (k % 2 == 0) {
		return power(m, k / 2);
	}
	m = power(m, k / 2);
	m *= n;
	m %= p;
	return m;
}

// nCk(mod p = prime)
ll com(ll n, ll k) {
	// nCk
	ll p = prime;

	ll ans = 1;
	for (ll i = 1; i <= n; i++)
	{
		ans *= i;
		ans %= p;
	}

	for (ll i = 2; i <= k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	for (ll i = 2; i <= n-k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	return ans;
}

int main() {

	ll n, k;
	cin >> n >> k;
	n = n % k;
	cout << min(abs(n - k), n) << endl;

	return 0;
}


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

const int MAX = 200005;
int A[MAX];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);

    for (int i = n - 1; i >= 0; i -= 2) printf("%d\n", A[i]);
    int x;
    if (n % 2 == 0) x = 0;
    else x = 1;
    for (int i = x; i < n; i += 2) printf("%d\n", A[i]);
    
    return 0;
}

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



int main() {
  int H, W;
  cin >> H >> W;
  char s[H+2][W+2];
  for(int j=0; j<W+2; ++j) {s[0][j] = '.';}
  for(int j=0; j<W+2; ++j) {s[H+1][j] = '.';}
  for(int i=1; i<H+1; ++i){
    for(int j=0; j<W+2; ++j){
      if(j == 0 || j == W+1) s[i][j] = '.';
      else cin >> s[i][j];
    }
  }

  bool check = true;
  for(int i=1; i<H+1; ++i){
    for(int j=1; j<W+1; ++j){
      if (s[i][j] == '#'){
        if(s[i][j-1] == '.' && s[i][j+1] == '.'
        && s[i-1][j] == '.' &&s[i+1][j] == '.')
        check = false;
      }
    }
  }

  cout << (check ? "Yes" : "No");



  return 0;
}


Measured memory_bytes: 256
n = gets().to_i;
count = Array.new(26,0);
a = 'a';
base = a.ord; 
for i in 0..n-1
	count_s = Array.new(26,0);
	s = gets().chomp;
	s = s.split("");
	for j in 0..s.length-1
		count_s[s[j].ord-base] = count_s[s[j].ord-base] + 1;
	end
	for k in 0..25
		if count[k] > count_s[k] || i ==0
			count[k] = count_s[k];
		end
	end
end
for i in 0..25
	while(count[i]>0)
		print((i+base).chr);
		count[i] = count[i] - 1;
	end
end

Measured memory_bytes: 2044
L,R = list(map(int, input().split()))
 
if R-L > 673:
    print(0)
else:
    min_mod = 2019
    for i in range(L,R):
        i_mod = i%2019
        for j in range(i+1,R+1):
            j_mod = j%2019
            mod = (i_mod*j_mod)%2019
            if mod < min_mod:
                min_mod = mod
        
    print(min_mod)

Measured memory_bytes: 3060
N, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 1
mod = 10 ** 9 + 7

if 0 <= A[0]:
    # All the values are positive -> Use the highest values
    for i in range(N - 1, N - K - 1, -1):
        ans = (ans * A[i]) % mod
elif A[-1] <= 0:
    # All the values are negative -> Check if the result becomes positive or negative
    if K % 2:
        # The result becomes negative -> Use the highest values
        for i in range(N - 1, N - K - 1, -1):
            ans = (ans * A[i]) % mod
    else:
        # The result becomes negative -> Use the highest values
        for i in range(K):
            ans = (ans * A[i]) % mod
else:
    # There exist both positive and negative values
    # If K is an odd number, make K even by extracting A[-1] in advance
    l, r = 0, N - 1
    if K % 2:
        ans = A[-1]
        r -= 1
        K -= 1
    # Compare A[l] * A[l + 1] and A[r -1] * A[r] -> use the bigger one
    # Why: a single negative value makes the result negative
    while K:
        if A[l] * A[l + 1] < A[r] * A[r - 1]:
            ans = (ans * A[r] * A[r - 1]) % mod
            r -= 2
        else:
            ans = (ans * A[l] * A[l + 1]) % mod
            l += 2
        K -= 2

print(ans)


Measured memory_bytes: 104628
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
nodes = [-1]*N
diff_weight = [0]*N

def root(x):
    if nodes[x] < 0:
        return x
    root_x = root(nodes[x])
    diff_weight[x] += diff_weight[nodes[x]]
    nodes[x] = root_x
    return root_x

def weight(x):
    root(x)
    return diff_weight[x]

def unite(x,y,w):
    w += weight(x); w -= weight(y)
    x = root(x); y = root(y)
    if x == y:
        return
    rank_x = -nodes[x]; rank_y = -nodes[y]
    if rank_x >= rank_y:
        nodes[y] = x
        diff_weight[y] = w
        if rank_x == rank_y:
            nodes[x] -= 1
    else:
        nodes[x] = y
        diff_weight[x] = -w

def same(x,y):
    return root(x) == root(y)

def diff(x,y):
    return weight(y) - weight(x)

ans = "Yes"

for L,R,D in info:
    L -= 1; R -= 1
    unite(L,R,D)
    if diff(L,R) != D:
        ans = "No"
        break
print(ans)

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

int a[200005];

int cmp(int a,int b){
    return a>b;
}

int main(){
	int n,k,num,count=0;
	cin >> n >> k;
	
	for(int i=0;i<n;i++){
		cin >> num;
		a[num]++;
	}
	sort(a,a+200004,cmp);
	
	for(int i=k;i<200003;i++){
		count += a[i];
		if(a[i]==0) break;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int x,y,z;
	
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x>y){
			z=x;
			x=y;
			y=z;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    if(a>c){
        cout<<"NO"<<endl;
    }
    else if(a+b>=c){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


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

int freq[505][505];
int main() {
	int n,m,q;
	cin>>n>>m>>q;
	
	for(int i=0;i<m;i++)
	{
		int l,r;
		cin>>l>>r;
		freq[l][r]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=n;j++)
		{
			//cout<<freq[i][j-1]<<" "<<i<<" "<<j<<" "<<freq[i][j]<<endl;
			freq[i][j]+=freq[i][j-1];
			
		}
	}
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		int ans=0;
		for(int i=l;i<=r;i++)
		{
			ans+=freq[i][r];
		}
		cout<<ans<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 1920
S = input()
ans = len(S)
for tgt in set(S):
    T = S
    while len(T) != T.count(tgt):
        U = ''
        for ab in zip(T, T[1:]):
            U += tgt if tgt in ab else ab[0]
        T = U
    ans = min(ans, len(S) - len(T))
print(ans)

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
abs = []

m.times do
  abs << gets.split.map(&:to_i)
end

abs.sort_by! { |a, b| b }
last_cut = 0
cnt = 0
abs.each do |a, b|
  if a > last_cut 
    cnt += 1
    last_cut = b - 1
  end
end

p cnt


Measured memory_bytes: 12664