akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
int n,cnt[15],x[15][15],y[15][15],ans=0;
void check(int w)
{
	int num=0;
	for(int i=0;i<n;++i)
		if(w>>i&1)
		{
			++num;
			for(int j=0;j<cnt[i];++j)
				if((w>>x[i][j]&1)!=y[i][j])return;
		}
	ans=max(ans,num);
}
int main()
{
	cin>>n;
	REP(i,n)
	{
		cin>>cnt[i];
		REP(j,cnt[i])cin>>x[i][j]>>y[i][j],--x[i][j];
	}
	for(int i=1;i<1<<n;++i)check(i);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL INF = 1e14;
LL dp[405][405] = {0};
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];
    VL sum(n+1, 0);
    REP(i,n)sum[i+1] = sum[i] + a[i];

    FOR(len,2,n+1){
        REP(i,n-len+1){
            LL r = i + len;
            LL min_dp = INF;
            FOR(j,i+1,r){
                min_dp = min(min_dp, dp[i][j] + dp[j][r]);
            }
            dp[i][r] = sum[r] - sum[i] + min_dp;
        }
    }

    PUTS(dp[0][n]);
}

Measured memory_bytes: 1536
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let _N: usize = read();
    let S: String = read();
    use std::collections::{HashMap, HashSet};
    let mut m: HashMap<char, HashSet<i32>> = HashMap::new();
    m.insert('R', HashSet::new());
    m.insert('G', HashSet::new());
    m.insert('B', HashSet::new());
    for (i, c) in S.chars().enumerate() {
        m.get_mut(&c).unwrap().insert(i as i32);
    }
    let mut ans = 0;
    for r in m.get(&'R').unwrap() {
        for g in m.get(&'G').unwrap() {
            let mut checkBs = vec![];
            if (r + g) % 2 == 0 {
                checkBs.push((r + g) / 2);
            }
            let max = std::cmp::max(r, g);
            let min = std::cmp::min(r, g);
            let low = min - (max - min);
            let high = max + (max - min);
            checkBs.push(low);
            checkBs.push(high);
            let bs = m.get(&'B').unwrap();
            let mut tmp = bs.len();
            for v in checkBs {
                if bs.get(&v).is_some() {
                    tmp -= 1;
                }
            }
            ans += tmp;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2212
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
class Solver{
public:
    int cnt[2010];
    void solve(){ 
        int N,X,Y;
        cin>>N>>X>>Y;
        for(int u=1;u<=N;u++){
            for(int v=1;v<u;v++){
                int l=min(u-v,abs(u-Y)+abs(v-X)+1);
                cnt[l]++;
            }
        }
        for(int u=1;u<N;u++)cout<<cnt[u]<<"\n";
    }
};
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    (new Solver())->solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << min(a+b, min(b+c, c+a)) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        double[] p1 = {0, 0};
        double[] p2 = {100, 0};

        print(p1);
        koch(n, p1, p2);
        print(p2);

        sc.close();
    }

    private static void koch(int n, double[] p1, double[] p2) {
        if(n == 0) return;

        double[] s = new double[2];
        double[] u = new double[2];
        double[] t = new double[2];

        s[0] = (p1[0] * 2 + p2[0]) / 3;
        s[1] = (p1[1] * 2 + p2[1]) / 3;
        t[0] = (p1[0] + p2[0] * 2) / 3;
        t[1] = (p1[1] + p2[1] * 2) / 3;

        u[0] = (t[0] - s[0]) * Math.cos(Math.PI / 3) - (t[1] - s[1]) * Math.sin(Math.PI / 3) + s[0];
        u[1] = (t[0] - s[0]) * Math.sin(Math.PI / 3) + (t[1] - s[1]) * Math.cos(Math.PI / 3) + s[1];

        koch(n - 1, p1, s);
        print(s);
        koch(n - 1, s, u);
        print(u);
        koch(n - 1, u, t);
        print(t);
        koch(n - 1, t, p2);
    }

    private static void print(double[] p) {
        System.out.printf("%.8f %.8f\n", p[0], p[1]);
    }
}


Measured memory_bytes: 41504
def dfs(i, cost, skills):
    if i == N:
        if min(skills) < X:
            return INF
        else:
            return cost
    new_skills = [a + s for a, s in zip(contents[i], skills)]
    return min(dfs(i + 1, cost, skills), dfs(i + 1, cost + prices[i], new_skills))


INF = float('inf')
N, M, X = map(int, input().split())
prices = []
contents = []
for _ in range(N):
    C, *A = map(int, input().split())
    prices.append(C)
    contents.append(A)
if (ans := dfs(0, 0, [0] * M)) == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9200
#なぜこれが通らないのか分からない
from collections import Counter
N = int(input())
v = list(map(int, input().split()))

odd = v[0::2]
even = v[1::2]

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

o.append((0,0))
e.append((0,0))


ans = N+1
for d1 in o:
    for d2 in e:
        if d1[0]!=d2[0]:
            ans = min(ans, N-d1[1]-d2[1])
print(ans)

Measured memory_bytes: 15972
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int K = scn.nextInt();

    ArrayList<Integer> D = new ArrayList<>();
    for (int i = 0; i < K; i++) {
      D.add(scn.nextInt());
    }

    ArrayList<Integer> useableNum = new ArrayList<>();
    for (int i = 0; i <= 9; i++) {
      if (!D.contains(i)) {
        useableNum.add(i);
      }
    }

    ArrayList<Integer> combi = new ArrayList<>();

    calcCombi("", combi, useableNum, String.valueOf(N).length());
    calcCombi("", combi, useableNum, String.valueOf(N).length() + 1);

    int ans = Integer.MAX_VALUE;
    for (int n : combi) {
      if (n >= N) {
        ans = Math.min(n, ans);
      }

    }
    System.out.println(ans);
  }

  public static void calcCombi(String num, ArrayList<Integer> combi, ArrayList<Integer> useableNum, int rest) {
    if (rest == 0) {
      combi.add(Integer.parseInt(num));
      return;
    }
    for (int n : useableNum) {
      calcCombi(num + String.valueOf(n), combi, useableNum, rest - 1);
    }
  }
}

Measured memory_bytes: 45172
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b,d,r;
    double f;
    
    cin >>a >>b;
    
    d = a/b;
    r = a%b;
    f = (double)a/b;
    
    printf("%d %d %6.6f\n",d,r,f);
    
    return 0;

}



Measured memory_bytes: 3196
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    res=1
    for i in 1:parseInt(sqrt(n))+1
        if n%i==0
            res=i
        end
    end
    println((res-1)+(div(n,res)-1))
end
main()

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

int main() {
  int h, a; cin >> h >> a;
  cout << h/a + (h%a!=0) << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');

        double a = double.Parse(str[0]);
        double b = double.Parse(str[1]);
        double d = double.Parse(str[2]);

        double S = (a * (b * Math.Sin(rad(d)))) / 2;
        double L = a + b + ( Math.Sqrt((a * a) + (b * b) - (2 * a * b * Math.Cos(rad(d)))));
        double H = b * (Math.Sin(rad(d)));

        Console.WriteLine(S);
        Console.WriteLine(L);
        Console.WriteLine(H);


    }

    static double rad(double x)
    {
        return (x * (Math.PI / 180));
    }
}

Measured memory_bytes: 9324
n=int(input())
if n>=105:
    if n>=135:
        if n>=165:
            if n>=189:
                if n>=195:
                    print(5)
                else:
                    print(4)
            else:
                print(3)
        else:
            print(2)
    else:
        print(1)
else:
    print(0)

Measured memory_bytes: 2940
H, W = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

h = 0
w = 0

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(n):
    for j in range(a[i]):
        ans[h][w] = i + 1
        if h % 2 == 0:
            if w == W - 1:
                h += 1
            else:
                w += 1
        else:
            if w == 0:
                h += 1
            else:
                w -= 1

for p in ans: print(' '.join(map(str, p)))



Measured memory_bytes: 3568
li = list(map(int,input().split()))
xy1,xy2 = (li[0],li[1]),(li[2],li[3])
div=(xy2[0]-xy1[0],xy2[1]-xy1[1])
print(xy2[0]-div[1],xy2[1]+div[0],xy1[0]-div[1],xy1[1]+div[0],sep=" ")

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

int main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a <= (c+d) && (a+b) >= c
     && c <= (a+b) && (c+d) >= a)
  {
    cout << abs(max(a, c) - min(b, d)) << endl;
  }
  else
  {
    cout << "0" << endl;
  }
  
  return 0;
}

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

int compare(long long int* x, long long int* y) {
  return *y-*x;
}

int main() {
  int i;
  int N;
  long long int result;
  long long int* arr;
  scanf("%d\n", &N);
  arr = (long long int*)malloc(sizeof(long long int)*N);
  for ( i = 0; i < N; i++ ) {
    scanf("%lld", &(arr[i]));
  }
  qsort(arr,N,sizeof(long long int),compare);
  // for ( i = 0; i < N; i++ ) {
  //   printf("%lld\n", arr[i]);
  // }
  result = 0;
  for ( i = 0; i < N-1; i++ ) {
    result += arr[(i+1)/2];
  }
  printf("%lld\n", result);
  free(arr);
  return 0;
}




Measured memory_bytes: 5040
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            List<Position> gv = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                gv.add(new Position(in.nextInt(), in.nextInt(), in.nextInt()));
            }

            gv.sort(Comparator.comparingInt(u -> u.t));
            int u = 0;
            int v = 0;
            int T = 0;
            for (int i = 0; i < n; i++) {
                Position p = gv.get(i);
                int nt = Math.abs(p.x - u) + Math.abs(p.y - v);
                if (T + nt > p.t || (p.x + p.y) % 2 != (p.t) % 2) {
                    out.print("No");
                    return;
                } else {
                    u = p.x;
                    v = p.y;
                    T = p.t;
                }
            }
            out.print("Yes");
        }

        private class Position {
            int t;
            int x;
            int y;

            public Position(int t, int x, int y) {
                this.t = t;
                this.x = x;
                this.y = y;
            }

        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 46404
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] f = new int[n][10];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < 10; j++) {
				f[i][j] = Integer.parseInt(sa[j]);
			}
		}
		int[][] p = new int[n][11];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < 11; j++) {
				p[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		long ans = Long.MIN_VALUE;
		int end = 1 << 10;
		for (int i = 1; i < end; i++) {
			long val = 0;
			for (int k = 0; k < n; k++) {
				int cnt = 0;
				for (int j = 0; j < 10; j++) {
					if (f[k][j] == 1 && (i >> j & 1) == 1) {
						cnt++;
					}
				}
				val += p[k][cnt];
			}
			ans = Math.max(ans, val);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23520
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string S;
    cin >> S;
    int N = sz(S), K;
    cin >> K;
    //dp[i][j][k]:=S[i:j]をk文字まで変更したときの価値の最大値
    int dp[N][N][K+1];
    //操作回数
    rep(i, K+1){
        //幅j
        rep(j, N){
            //スタート地点
            rep(k, N-j){
                if(j <= 2*i) dp[k][k+j][i] = j+1;
                else{
                    if(S[k] == S[k+j]){
                        if(j == 0) dp[k][k+j][i] = 2;
                        else dp[k][k+j][i] = dp[k+1][k+j-1][i]+2;
                    }
                    else{
                        dp[k][k+j][i] = max(dp[k+1][k+j][i], dp[k][k+j-1][i]);
                        if(i > 0){
                            chmax(dp[k][k+j][i], dp[k+1][k+j-1][i-1]+2);
                        }
                    }
                }
            }
        }
    }
    cout << dp[0][N-1][K] << endl;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

ll a[102345];

int main(){
	ll n;
	ll k;
	
	cin >> n >> k;
	
	ll ma = 0;
	
	ll ans = 1;
	
	REP(i,n){
		cin >> a[i];
		
		ma = max(ma, a[i]);
	}
	
	if (n != 1) ans = gcd(a[0], a[1]);
	
	REP(i,n-2){
		ans = gcd(ans, a[i+2]);
	}
	
	if (k > ma) cout << "IMPOSSIBLE" << endl;
	else {
		if (k%ans == 0) cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
	}
	
	return 0;
}

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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9

typedef   pair<int,int> P;

int main() {

	int a;
	scanf("%d",&a);
	printf("%d\n",a/3);
}




Measured memory_bytes: 256
#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 <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "NO\n"; return;}
#define yes {cout << "YES\n"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int N = 60;

vector <pi> g[N];
int path[N];

bool dfs(int v, int p, int fin, int num) {
    if (v == fin)
        return true;
    for (pi pa : g[v])
        if (pa.F != p && dfs(pa.F, v, fin, num)) {
            path[num] = path[num] ^ (1ll << pa.S); return true;
        }
    return false;
}

void solve() {
    string s, t, u;
    int n, m;
    cin >> s >> t >> n >> m >> u;
    cout << n - (s == u) << " " << m - (t == u);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3588
package main

import (
	"fmt"
	"strings"
)

func acgt(s string) bool {
	if s == "A" || s == "C" || s == "G" || s == "T" {
		return true
	}
	return false
}

func main() {
	var s string
	fmt.Scan(&s)

	a := strings.Split(s, "")
	var res int

	for i := range a {
		tmp := 0
		for j := i; j < len(a); j++ {
			if acgt(a[j]) {
				tmp++
				if tmp > res {
					res = tmp
				}
			} else {
				tmp = 0
			}
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 640
import sys

def eat(i,candies,counter):
    s=candies[i]+candies[i-1]
    nc=max(0,s-x)
    counter+=nc
    candies[i]-=nc
    return counter

def main(n,x,candies):
    counter=0
    if candies[0]>x:
        counter=candies[0]-x
        candies[0]=x
    for i in range(1,n):
        counter=eat(i,candies,counter)
    return counter

n,x=map(int,sys.stdin.readline().strip().split())
candies=list(map(int,sys.stdin.readline().strip().split()))
print(main(n,x,candies))


Measured memory_bytes: 20016
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from functools import reduce
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

def gcd_list(numbers):
    return reduce(gcd, numbers)

K = i()

sigma = 0
nums = [i for i in range(1, K + 1)]
for abc in itertools.combinations_with_replacement(nums, 3):  # 重複組み合わせ，200H3
    tmp = gcd_list(abc)
    abc_set = set(abc)
    sigma += int(tmp * (6 / (math.factorial(-len(abc_set) + 4))))

print(sigma)

"""
[1, 2, 3]
(1, 1)
(1, 2)
(1, 3)
(2, 2)
(2, 3)
(3, 3)
"""

Measured memory_bytes: 88860
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)

  var currentBitSet = 0
  var r = 0
  var ans = 0L
  for (l in 0 until n) {
    if (l == 0) {
      currentBitSet = xs[0]
    }  else {
      currentBitSet = currentBitSet xor xs[l - 1]
    }

    if (r == l - 1) {
      currentBitSet = xs[l]
      r++
    }

    while (r + 1 < n && (currentBitSet and xs[r + 1]) == 0) {
      currentBitSet = currentBitSet xor xs[r + 1]
      r++
    }
    // println("$l $r $currentBitSet")
    ans += r - l + 1
  }
  println(ans)
}


Measured memory_bytes: 43428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <cmath> 
#include <algorithm>
using namespace std; 
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 1e5 + 5; 
const int Mod = 1e9 + 7; 
int N, M, n, x[MAX_N], y[MAX_N], f[MAX_N]; 
int o[MAX_N], m; 
pair<int, int> p[MAX_N]; 
int c[MAX_N]; 
inline int lb(int x) { return x & -x; } 
void add(int x, int v) { while (x <= m) c[x] = (c[x] + v) % Mod, x += lb(x); } 
int sum(int x) { int res = 0; while (x) res = (res + c[x]) % Mod, x -= lb(x); return res; } 
bool cmp(pair<int, int> l, pair<int, int> r) { 
	if (l.first == r.first) return l.second > r.second;
	else return l.first < r.first; 
} 
int main () { 
	N = gi(), M = gi(); 
	for (int i = 1; i <= N; i++) x[i] = gi(); 
	for (int i = 1; i <= M; i++) y[i] = gi(); 
	for (int i = 1; i <= N; i++) { 
		if (x[i] < y[1] || x[i] > y[M]) continue; 
		int pos = lower_bound(&y[1], &y[M + 1], x[i]) - y; 
		if (y[pos] == x[i]) continue; 
		p[++n] = make_pair(x[i] - y[pos - 1], y[pos] - x[i]); 
		o[++m] = y[pos] - x[i]; 
	} 
	sort(&o[1], &o[m + 1]); 
	m = unique(&o[1], &o[m + 1]) - o - 1; 
	sort(&p[1], &p[n + 1], cmp); 
	n = unique(&p[1], &p[n + 1]) - p - 1; 
	for (int i = 1; i <= n; i++) p[i].second = lower_bound(&o[1], &o[m + 1], p[i].second) - o;
	for (int i = 1; i <= n; i++) { 
		f[i] = (sum(p[i].second - 1) + 1) % Mod; 
		add(p[i].second, f[i]); 
	} 
	int ans = 1;
 	for (int i = 1; i <= n; i++) ans = (ans + f[i]) % Mod; 
	printf("%d\n", ans); 
    return 0; 
} 

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  i64 n,a,b;

  while(cin >> n >> a >> b){

    i64 ans = n / (a + b) * a + min(n % (a + b), a);

    puts_all(ans);
  }


  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

void chmax(int &a,int b) { a=max(a,b); }
void chmin(int &a,int b) { a=min(a,b); }

//-----------------------------------------------------------------------------

int a,b,c;

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

	cin>>a>>b>>c;
	set<int> st;
	st.insert(a),st.insert(b),st.insert(c);
	cout<<st.size()<<endl;

	return 0;
}


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

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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

int main() {
    init();
    ll ans = 0, s_num = 0;
    string s;
    cin >> s;
    ll N = s.size();
    ans = N;
    rep(i, N) {
        if (s[i] == 'S') {
            s_num += 1;
            continue;
        }
        if (s_num == 0) continue;
        s_num--;
        ans -= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <math.h>
#include <set>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<vi> s(m, vi(11, 0));
    vi p(m, 0);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    int ans = 0;

    if (n == 1) {
        cout << p[0] << endl;
        return 0;
    }

    for (int bit = 0; bit < (1 << n); ++bit) {
        bool is_cnt_up = true;
        for (int j = 0; j < m; ++j) {
            int on_num = 0;
            for (auto sk: s[j]) {
                if ((bit >> (sk - 1)) & 1) on_num++;
            }
            if (on_num % 2 != p[j])is_cnt_up = false;
        }
        if (is_cnt_up) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn main() {
    let z = read_parameters::<usize>().unwrap();
    let (n, m) = (z[0], z[1]);

    let mut a = Vec::with_capacity(m);
    for _ in 0..n {
        let mut raw = read_parameters::<u32>().unwrap();
        let sum = raw.iter().sum();
        raw.push(sum);
        a.push(raw);
    }

    let mut last = Vec::with_capacity(m + 1);

    for j in 0..m + 1 {
        let mut sum = 0;
        for i in 0..n {
            sum += a[i][j];
        }
        last.push(sum);
    }
    a.push(last);

    for i in 0..n + 1 {
        for j in 0..m {
            print!("{} ", a[i][j]);
        }
        println!("{}", a[i][m]);
    }
}



Measured memory_bytes: 5052
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static class Range implements Comparable<Range> {
		long x, l;
		
		public Range (long x, long l) {
			this.x = x;
			this.l = l;
		}

		@Override
		public int compareTo(Range o) {
			return Long.compare(this.x + this.l, o.x + o.l);
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			System.out.println(N == M ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ull N, K;
	cin >> N >> K;

	double winProb = 0.0;
	for (ull ii = 1; ii <= N; ++ii){
		ull score = ii;
		double prob = 1.0 / (double) N;
		while (score < K) {
			score *= 2;
			prob = prob / 2.0;
		}
		winProb += prob;
	}

	printf("%.12f\n", winProb);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int a[10005]={0};
int main(){   
	int T,flag=1,p;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&p);
		if(p%2==0){
			if(p%3!=0&&p%5!=0) flag=0;
			
			
		}
		
		
	}
	if(flag) printf("APPROVED");
	else printf("DENIED");
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = sc.nextInt();

        List<String> s = new ArrayList<>();
        int endsWithA = 0;
        int beginsWithB = 0;
        int both = 0;
        for (int i=0; i < n; i++) {
            String t = sc.next();
            s.add(t);
            if (t.startsWith("B") && !t.endsWith("A"))
                beginsWithB++;
            else if (t.endsWith("A") && !t.startsWith("B"))
                endsWithA++;
            else if (t.endsWith("A") && t.startsWith("B"))
                both++;
        }

        int ans = 0;
        for (String e : s) {
            ans += containsHowManyAB(e);
        }

        if (both > 1) {
            ans += both - 1;
        }
        if (both > 0) {
            if (endsWithA > 0) {
                endsWithA--;
                ans++;
            }
            if (beginsWithB > 0) {
                beginsWithB--;
                ans++;
            }
        }

        ans += endsWithA > beginsWithB ? beginsWithB : endsWithA;
        System.out.println(ans);
    }

    private static int containsHowManyAB(String s) {
        int ret = 0;
        for (int i=0; i < s.length()-1; i++) {
            if (s.substring(i, i+2).equals("AB"))
                ret++;
        }
        return ret;
    }

}


Measured memory_bytes: 33152
// a
fn main() {
    input! {
        s: chars
    }

    if s[s.len() - 1] == 's' {
        let a = s[0..s.len()]
            .iter()
            .fold(String::new(), |a, b| a + &b.to_string());
        println!("{}", a + "es");
    } else {
        let a = s.iter().fold(String::new(), |a, b| a + &b.to_string());
        println!("{}", a + "s");
    }
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	long sum = 0, max = -1000000, min = 1000000;
    	int n = scan.nextInt();
    	long a[] = new long[n]; 
    	for(int cnt = 0; cnt < n; cnt++){
    		a[cnt] = scan.nextLong();
    		if(a[cnt] < min)
    			min = a[cnt];
    		if(a[cnt] > max)
    			max = a[cnt];
    		sum += a[cnt];
    	}		
        System.out.println(min + " " + max + " " + sum);
        scan.close();
    }

}

Measured memory_bytes: 41884
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll A, B, C;
    cin >> A >> B >> C;
    if(C >= A and C <= B) print("Yes");
    else print("No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
 
  if ((a / d) + 1 < (c / b)) {
    cout << "No" << endl;
  }
  else if ((a / d) == (c / b) && (a % d) == 0 && (c % b) != 0) {
    cout << "No" << endl;
  }
  else if ((a / d) < (c / b) && (a / d) + 1 == (c / b) && (a % d) != 0 && (c % b) == 0) {
    cout << "Yes" << endl;
  }
  else if ((a / d) < (c / b) && (a / d) + 1 == (c / b) && (c % b) != 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define fi first
#define sc second
typedef pair<int,int> P;
typedef long long ll;
int dp[4005][4005];
int nxt0[2][4005];
int nxt1[2][4005];
vector<int>zero[2],one[2];
string s,t;
int n,m;
int rec(int a,int b){
	if(a == n+1 && b == m+1) return dp[a][b] = 0;
	if(dp[a][b] >= 0) return dp[a][b];
	dp[a][b] = 1000000;
	dp[a][b] = min(dp[a][b],rec(nxt0[0][a],nxt0[1][b])+1);
	dp[a][b] = min(dp[a][b],rec(nxt1[0][a],nxt1[1][b])+1);
	return dp[a][b];
}
void rec2(int a,int b,string &s){
	if(a == n+1 && b == m+1) return;
	/*cout << a << " " << b << endl;
	cout << dp[a][b] << endl;
	cout << dp[nxt0[0][a]][nxt0[1][b]]+1 << endl;
	cout << dp[nxt1[0][a]][nxt1[1][b]]+1 << endl;*/
	
	if(dp[a][b] == dp[nxt0[0][a]][nxt0[1][b]]+1){
		s.pb('0');
		rec2(nxt0[0][a],nxt0[1][b],s);
	}
	else{
		assert(dp[a][b] == dp[nxt1[0][a]][nxt1[1][b]]+1);
		s.pb('1');
		rec2(nxt1[0][a],nxt1[1][b],s);
	}
	return;
}
int main(){
	cin >> s >> t; n = s.size(), m = t.size();
	rep(i,n){
		if(s[i] == '0') zero[0].pb(i+1);
		else one[0].pb(i+1);
	}
	zero[0].pb(n+1); one[0].pb(n+1);
	rep(i,m){
		if(t[i] == '0') zero[1].pb(i+1);
		else one[1].pb(i+1);
	}
	zero[1].pb(m+1); one[1].pb(m+1);
	for(int i=0;i<=n;i++){
		int x = upper_bound(zero[0].begin(),zero[0].end(),i)-zero[0].begin();
		nxt0[0][i] = zero[0][x];
		x = upper_bound(one[0].begin(),one[0].end(),i)-one[0].begin();
		nxt1[0][i] = one[0][x];
	}
	nxt0[0][n+1] = nxt1[0][n+1] = n+1;
	for(int i=0;i<=m;i++){
		int x = upper_bound(zero[1].begin(),zero[1].end(),i)-zero[1].begin();
		nxt0[1][i] = zero[1][x];
		x = upper_bound(one[1].begin(),one[1].end(),i)-one[1].begin();
		nxt1[1][i] = one[1][x];
	}
	nxt0[1][m+1] = nxt1[1][m+1] = m+1;
	memset(dp,-1,sizeof(dp));
	int len = rec(0,0);
	string ret = "";
	rec2(0,0,ret);
	cout << ret << endl;
}
	



Measured memory_bytes: 65984
#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int num) {
  double sqrt_num = sqrt(num);

  for(int i = 2; i <= sqrt_num; i++) {
    if(num % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int number_num;

  cin >> number_num;

  int prime_count = 0;
  for(int i = 0; i < number_num; i++) {
    int target;
    cin >> target;
    if(is_prime(target)) {
      prime_count++;
    }
  }

  cout << prime_count << endl;
}


Measured memory_bytes: 3096
program main
    implicit none
    integer(8) k
    integer, dimension(19) :: a
    integer(8) i,j,l,m,c,d,n,u,flag
    read(*,*) k

    c = 1
    a = 10
    a(1) = 0

    do i = 1,k

        u = 0
        do j = 1, c
            u = u + a(j)
        end do

        if (u == 9*c) then
            c = c + 1
            a(c) = 1
            do j = c-1,1,-1
                if(a(j+1) == 0) then
                    a(j) = 0
                else
                    a(j) = a(j+1) - 1
                end if
            end do
        else

            d = 0
            do l = 1, c
                if(a(l+1) == a(l) - 1) then
                    d = l + 1
                else
                    exit
                end if
            end do
            
            if (d /= 0) then
                a(d) = a(d) + 1
                do l = d-1, 1, -1
                    a(l) = a(l+1) -1
                    if(a(l) == -1) then
                        a(l) = 0
                    end if
                end do
            else if ( a(1) == 9 .and. a(2) == 9) then
                flag = 0
                do l = 3, c
                    if(a(l) == 9) then
                    else if(a(l+1) == a(l) - 1) then
                        flag = l + 1
                    else
                        if (flag == 0) then
                        a(l) = a(l) + 1
                        do m = l-1,1,-1
                            a(m) = a(m+1) - 1
                            if(a(m) == -1) then
                                a(m) = 0
                            end if
                        end do
                        end if
                        exit
                    end if
                end do
                if (flag /= 0) then
                    a(flag) = a(flag) + 1
                    do l = flag-1,1,-1
                        a(l) = a(l+1) - 1
                        if(a(l) == -1) then
                            a(l) = 0
                        end if
                    end do
                end if
            else
                a(1) = a(1) + 1
            end if

        end if

    end do

    n = 0
    do j = 1, c
        n = n + 10**(j-1)*a(j)
    end do

    write(*,*) n

end program

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

//--global--//



//----------//

void print2dArray(vector<vector<ll> > vv, int a){
    rep(i, vv.size()){
        rep(j, a){
            if(i)cout << " ";
            cout << vv[i][j];
        }
        cout << endl;
    }
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//
    
    int n, w;
    cin >> n >> w;
    vector<vector<ll> > vv(n+1, vector<ll>(MAX+1));
    vector<ll> W(n);
    vector<ll> V(n);
    rep(i, n+1){
        fill(vv[i].begin(), vv[i].end(), pow(10, 12));
    }

    rep(i, n){
        cin >> W[i] >> V[i];
    }

    vv[0][0] = 0;
    rep2(i, 1, n+1){
        vv[i][V[i-1]] = min(vv[i][V[i-1]], W[i-1]);
        rep(j, pow(10, 5)+1){
            if(vv[i-1][j] != -1){
                vv[i][j] = min(vv[i-1][j], vv[i][j]);
                if(j + V[i-1] <= pow(10, 5)+1)
                    vv[i][j+V[i-1]] = min(vv[i][j+V[i-1]], vv[i-1][j]+W[i-1]);
            }
        }
    }

    //print2dArray(vv, 90);


    ll res = 0;
    rep(i, pow(10, 5)+1){
        if(vv[n][i] >= 0 && vv[n][i] <= w){
            res = max(ll(i), res);
        }
    }

    cout << res << endl;

    
    return 0;
}


Measured memory_bytes: 80256