akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100005;
const int mod = 1e9 + 7;
struct node {
    int x,i;
    bool operator <(const node &rhs)const {
        return x < rhs.x;
    }
}a[maxn];
int main() {
    int n,ans=0;
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>a[i].x;a[i].i = i;
    }
    sort(a, a+n);
    for (int i=0; i<n; i++) {
        if (!(i&1) && a[i].i&1) {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

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


		//H,Wが両方とも0になるまで繰り返す
		while(true) {


			//縦、横の高さ
			int H  = src.nextInt();
			int W  = src.nextInt();
			

	        //HW両方が0になった場合終了
		     if((W == 0) && (H == 0)) {
		    	 break;
		     }


			//縦の列の繰り返し
	        for (int i = 1; i <= H; i++) {

	        	
	        	//縦の交互
	        	if(i % 2 == 0) {
	        		
		        	//横の列の繰り返し、交互１
		            for (int j = 1; j <= W; j++) {
		            	if(j % 2 == 0) {
			                System.out.print("#");
		            	}else {
		            		System.out.print(".");
		            	}
		            }
		        }else {

		        	
		        	//横の列の繰り返し、交互2
		            for (int j = 1; j <= W; j++) {
		            	if(j % 2 == 0) {
			                System.out.print(".");
		            	}else {
		            		System.out.print("#");
		            	}
	
		            }
	        	}


	            //縦に１列進む
	            System.out.println();
			}

	        System.out.println();

		}
	}
}


Measured memory_bytes: 35360
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let K = read!(i64);
    let mut sum = 0_i64;

    for a in 1..K + 1 {
        for b in 1..K + 1 {
            for c in 1..K + 1 {
                sum += gcd(a, gcd(b, c));
            }
        }
    }

    println!("{}", sum)
}


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

struct num{
  	int a;
  	int b;
  	bool operator<(const num &alt) const {
      	return b < alt.b;
    };
};

int main(){
	int N;
	cin >> N;
	vector<num> n(N);
	for(int i = 0;i<N;i++){
    	cin >> n[i].a >> n[i].b;
    }
  	sort(n.begin(),n.end());
  	int time = 0;
  	bool dead = false;
  	for(auto itr : n){
      time += itr.a;
      if(time > itr.b){
        dead = true;
        break;
      }
    }
  	if(dead){
      	cout << "No" << endl;
    }else{
      	cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1792
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        String op = sc.next();
        int B = sc.nextInt();

        if(op.equals("+"))
        System.out.println(A+B);
        else
            System.out.println(A-B);             
    }
    
}    





Measured memory_bytes: 23124
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
ll A[100009], B[100009];
ll suma=0, sumb=0;

void pr(ll ans){
    cout1(ans)
    exit(0);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    
    rep(i,N) suma+=A[i];
    rep(i,N) sumb+=B[i];
    
    if(suma<sumb){
        pr(-1);
    }
    
    int ans=0;
    ll husoku=0;
    priority_queue<int> amari;
    rep(i,N){
        ll x = A[i]-B[i];
        if(x==0) continue;
        if(x>0){
            amari.push(x);
        }else{
            husoku += -x;
            ans++;
        }
    }
    
    while(husoku>0&&amari.size()){
        ans++;
        int x=amari.top(); amari.pop();
        husoku-=x;
    }
    
    if(husoku>0) pr(-1);
    else pr(ans);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1e18;

int N;
vector<ll> a;
vector<vector<P>> dp;  // first: コストの合計の最小値、second: 1つにまとめた時の値

P rec(int l = 0, int r = N) {  // メモ化再帰
    if (r - l == 1) return make_pair(0, a[l]);
    P &ret = dp[l][r];
    if (ret.first != INF) return ret;

    for (int i = l + 1; i < r; i++) {
        P L = rec(l, i);
        P R = rec(i, r);
        ll sum = L.second + R.second;
        ll cost = L.first + R.first + sum;
        chmin(ret, make_pair(cost, sum));
    }

    return ret;
}

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    dp.assign(N + 2, vector<P>(N + 2, make_pair(INF, 0)));  // 初期化

    cout << rec().first << endl;

    return 0;
}


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

int main() {
  int A,B,N;
  cin >> N >> A >> B;
  if(N*A < B){
  	cout << N*A << endl;
  }else if(A*N > B){
  	cout << B << endl;
  }else{
  	cout << B << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;cin>>K;
	cout<<A[K-1];
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, GA,SA,BA,GB,SB,BB;

int dp0[4][5001];
int dp1[4][25000001];

signed main()
{
	cin >> N;
	cin >> GA >> SA >> BA;
	cin >> GB >> SB >> BB;

	int m0[4] = { 0, GA, SA, BA };
	int v0[4] = { 0, GB, SB, BB };

	for (int i = 0; i <= N; i++)
	{
		dp0[0][i] = i;
	}
	for (int j = 1; j <= 3; j++)
	{
		for (int i = 0; i <= N; i++)
		{
			int a = (i >= m0[j]) ? dp0[j][i - m0[j]] + v0[j] : 0;
			int b = dp0[j - 1][i];
			dp0[j][i] = MAX(a, b);
		}
	}

	int M = dp0[3][N];

	int m1[4] = { 0, GB, SB, BB };
	int v1[4] = { 0, GA, SA, BA };

	for (int i = 0; i <= M; i++)
	{
		dp1[0][i] = i;
	}
	for (int j = 1; j <= 3; j++)
	{
		for (int i = 0; i <= M; i++)
		{
			int a = (i >= m1[j]) ? dp1[j][i - m1[j]] + v1[j] : 0;
			int b = dp1[j - 1][i];
			dp1[j][i] = MAX(a, b);
		}
	}

	cout << dp1[3][M] << endl;
}











Measured memory_bytes: 781696
// AB BAHUT HO GAYA . NEXT LEVEL PAR JAO 
// HAVE FAITH AND BEILEVE IN YOURSELF 
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
int main()
{fast();
lli n;
cin>>n;
if(n%1000==0)
{cout<<0<<"\n";
}
else
{cout<<1000-(n%1000)<<"\n";
}
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}

int main() {
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    ll minxy = min(x,y);
    bool flag = false;
    if (a+b >2*c) {
        flag = true;
    }
    ll vv = minxy;
//    ll vv = 2*cc;
    if(flag==true)
    cout<<min(a*(x-vv) + b*(y-vv) + 2*c*vv,2*c*max(x,y))<<endl;
    else     cout<<a*(x) + b*(y)<<endl;
}



Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
const int MaxN = 300;

using namespace std;
int n , m , vis[MaxN + 5] , cnt[MaxN + 5];
int a[MaxN + 5][MaxN + 5];
int used[MaxN + 5];
void Init(){
	memset(vis , 0 , sizeof(vis));
	memset(used , 0 , sizeof(used));
	for(int i = 1;i <= n;i++) {
		for(int j = 1;j <= m;j++){
			scanf("%d" , &a[i][j]);
		}
	}
	for(int i = 1;i <= n;i++) cnt[i] = 1;
}
void Solve(){
	int Min = 1 << 30;
	while(1){
		int Max = 0 , pos = 0;
		for(int i = 1;i <= m;i++) vis[i] = 0;
		for(int i = 1;i <= n;i++){
			while(used[a[i][cnt[i]]]){
				cnt[i]++;
				if(cnt[i] > m){
					printf("%d\n" , Min);
					return ;
				}
			}
			if(++vis[a[i][cnt[i]]] > Max){
				Max = vis[a[i][cnt[i]]];
				pos = a[i][cnt[i]];
			}
		}
		Min = min(Min , Max);
		for(int i = 1;i <= n;i++){
			if(vis[a[i][cnt[i]]] == Max){
				used[a[i][cnt[i]]] = 1;
				 cnt[i]++;
				 if(cnt[i] > m) {
				 	 printf("%d\n" , Min);
				 	 return;
				 }
			}
		}
	}
}
int main()
{
	while(~scanf("%d%d" , &n , &m)){
		Init();
		Solve();
	}
}

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

int main(void) {
    int i, j, N;
    long long a[100010], P1, P2, Tc, Tp;
    scanf("%d", &N);
    for (i=0;i<N;i++) scanf("%lld", &a[i]);
//    memmove(b, a, N*sizeof(long long));

    P1 = 0LL;
    if (a[0]<=0LL) {
        P1 += -a[0] + 1LL;
        Tc = 1LL;
    } else Tc = a[0];
    for (i=1;i<N;i++) {
        Tp = Tc;
        Tc += a[i];
        if (Tc == 0LL) {
            if (Tp > 0LL) { Tc--; }
            else { Tc++; }
            P1++;
        } else if (Tc > 0LL && Tp > 0LL) {
            P1 += Tc + 1LL;
            Tc = -1LL;
        } else if (Tc < 0LL && Tp < 0LL) {
            P1 += -Tc + 1LL;            
            Tc = 1LL;
        }
    }
    P2 = 0LL;
    if (a[0]>=0LL) {
        P2 += a[0] + 1LL;
        Tc = -1LL;
    } else Tc = a[0];
    Tp = 0LL;
    for (i=1;i<N;i++) {
        Tp = Tc;
        Tc += a[i];
        if (Tc == 0LL) {
            if (Tp > 0LL) { Tc--; }
            else { Tc++; }
            P2++;
        } else if (Tc > 0LL && Tp > 0LL) {
            P2 += Tc + 1LL;
            Tc = -1LL;
        } else if (Tc < 0LL && Tp < 0LL) {
            P2 += -Tc + 1LL;            
            Tc = 1LL;
        }
    }
    if (P1<P2) printf("%lld\n", P1);
    else printf("%lld\n", P2);
//    for (i=0;i<N;i++) printf("%lld\t", b[i]);  printf("\n");
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
int ans;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        ans += (r - l + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
#define endl "\n"
using namespace std;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
void Run() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("mex.in", "r", stdin);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin); freopen("outt.txt", "w", stdout);
#endif
}
const int N = 1e5 + 10;
int f[N];
int e[N];
int main()
{
    Run();
    ll a, b, c, k;
    ll ans = 0;
    cin >> a >> b >> c >> k;
    if (a >= k) {
        ans += k;
        k = 0;
    }
    else
    {
        ans += a;
        k -= a;
    }
    if (b >= k)
        k = 0;
    else
    {
        k -= b;
    }
    ans += (k * -1);
    cout << ans;


}


Measured memory_bytes: 3648
#include<cstdio>
#include<map>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<vector>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;
void inp();
int main(){
#ifdef XS
//	freopen("d.in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
const int NN = 100 + 5;
typedef pair<ll,ll> P;// weight, value
typedef vector<P> VP;
typedef map<ll,ll> MLL;//weight, value
MLL dp;
#define WEI first
#define VAL second
VP vp;
ll W[NN], V[NN];
#define sca(I) scanf("%lld%lld", &W[(I)], &V[(I)])
#define ALL(v) (v).begin(), (v).end()
void pm(){
	for(auto p:dp){
		printf("%lld %lld \n", p.WEI, p.VAL);
	}
}
void inp(){
	ll n,w; scanf("%lld%lld", &n, &w);
	for(int i = 1;i<=n;i++){ sca(i); }
	ll ans = 0;
	dp[0] = 0;
	for(int i = 1;i<=n;i++){
		vp.clear();
		for(auto p: dp){
			ll nw = p.WEI + W[i];
			ll nv = p.VAL + V[i];
			if( nw <= w )
					vp.push_back(P(nw, nv));
		}
		for(auto p: vp){
			if(dp.count(p.WEI) ){
				ans = max(
						dp[p.WEI] = max(dp[p.WEI], p.VAL)
							,ans
						);
			}
			else {
				ans = max(
						dp[p.WEI] = ( p.VAL),
						ans);
			}
		}
		//pm();
	}
	printf("%lld", ans);
}
//d.cc by xsthunder at Sun Aug 12 13:52:37 2018


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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> H(N);
  for (long i = 0; i < N; i++) cin >> H.at(i);
  sort(H.rbegin(), H.rend());
  for (long i = 0; i < min(N, K); i++) H.at(i) = 0;
  cout << accumulate(H.begin(), H.end(), 0L) << "\n";
}

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

typedef long long ll;

int main() {
    int N, a, ans = 0;
    cin >> N;
    vector<int> v(100002, 0);
    rep(i, N) {
        cin >> a;
        v[a]++;
        v[a + 1]++;
        v[a + 2]++;
    }
    rep(i, 100002) {
        ans = max(ans, v[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt() - scan.nextInt();
        n %= scan.nextInt();
        System.out.println(n);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

struct aho_corasick
{
	static const int alpha = 26;

	vector<array<int, alpha>> go;
	vector<int> fail;
	vector<int> endpos;

	aho_corasick() { add_node(); }

	int add_string(const string &str)
	{
		int e = 0;
		for (char c : str)
		{
			if (!go[e][c-'A'])
			{
				int nn = add_node();
				go[e][c-'A'] = nn;
			}
			e = go[e][c-'A'];
		}
		++endpos[e];
		return e;
	}

	void build()
	{
		queue<int> que;
		for (int c = 0; c < alpha; ++c)
			if (go[0][c]) que.push(go[0][c]);
		for (; !que.empty(); que.pop())
		{
			int e = que.front();
			int f = fail[e];
			for (int c = 0; c < alpha; ++c)
				if (!go[e][c]) go[e][c] = go[f][c];
				else
				{
					fail[go[e][c]] = go[f][c];
					endpos[go[e][c]] += endpos[go[f][c]];
					que.push(go[e][c]);
				}
		}
	}

private:
	int add_node()
	{
		int pos = go.size();
		go.emplace_back(array<int, alpha>());
		fail.emplace_back(0);
		endpos.emplace_back(0);
		return pos;
	}
};

const ll mod = 1e9+7;

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;

	aho_corasick ac;
	ac.add_string("AGC");
	ac.add_string("ACG");
	ac.add_string("GAC");

	ac.add_string("ATGC");
	ac.add_string("AGTC");

	ac.add_string("AAGC");
	ac.add_string("AGAC");

	ac.add_string("AGGC");
	ac.add_string("AGGC");

	ac.add_string("ACGC");
	ac.add_string("AGCC");



	ac.build();

	vector<vector<ll>> dp(n+1, vector<ll>(ac.endpos.size()));
	dp[0][0] = 1;

	int sz = ac.endpos.size();
	vector<char> t = {'A', 'C', 'G', 'T'};
	for (int i = 0; i < n; ++i)
		for (int u = 0; u < sz; ++u)
			for (char j : t)
			{
				int v = ac.go[u][j-'A'];
				if (ac.endpos[v] == 0)
					dp[i+1][v] = (dp[i+1][v] + dp[i][u]) % mod;
			}

	ll ans = 0;
	for (int u = 0; u < sz; ++u)
		ans = (ans + dp[n][u]) % mod;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner; 
class Main 
{ 
    public static void main(String[] args) 
    { 
        Scanner s = new Scanner(System.in); 
        int a,b,c;
        a = s.nextInt();
        b = s.nextInt();
        c = s.nextInt();
        if (a+b+c>=22) System.out.println("bust");
        else System.out.println("win");
    } 
} 

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;

//Kaeru Jump
public class Main{

	int h, w, n;
	char[][] m;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
	char[] str = {'U','R','D','L'};
	char[] res;

	int[][] near(int i, int j){
		int[][] r = new int[4][2];
		for(int[]a:r)Arrays.fill(a, -1);
		for(int k=0;k<4;k++){
			int pi = i+d[k][0], pj = j+d[k][1];
			while(0<=pi&&pi<h&&0<=pj&&pj<w){
				if(m[pi][pj]=='o'){
					r[k][0] = pi; r[k][1] = pj; break;
				}
				pi += d[k][0]; pj += d[k][1];
			}
		}
		return r;
	}

	boolean dfs(int i, int j, int D, int c){
		if(c==n-1)return true;
		int[][] e = near(i, j);
		for(int k=0;k<4;k++){
			if(e[k][0]==-1||D==(k+2)%4)continue;
			res[c] = str[k];
			m[i][j] = '.';
//			boolean ok = true;
//			if(c<n-2){
//				for(int dir=0;dir<4;dir++){
//					if(e[dir][0]==-1)continue;
//					int[][] adj = near(e[dir][0], e[dir][1]);
//					boolean exist = false;
//					for(int x=0;x<4;x++)if(adj[x][0]!=-1)exist = true;
//					if(!exist)ok = false;
//				}
//			}
//			if(ok){
				if(dfs(e[k][0], e[k][1], k, c+1))return true;
//			}
			m[i][j] = 'o';
		}
		return false;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt(); w = sc.nextInt();
		n = 0;
		m = new char[h][];
		int si = -1, sj = -1, sd = -1;
		for(int i=0;i<h;i++){
			m[i] = sc.next().toCharArray();
			for(int j=0;j<w;j++){
				if(m[i][j]=='.')continue;
				n++;
				if(m[i][j]=='o')continue;
				si = i; sj = j;
				sd = m[i][j]=='U'?0:m[i][j]=='R'?1:m[i][j]=='D'?2:3;
				m[i][j] = 'o';
			}
		}
		res = new char[n-1];
		dfs(si, sj, sd, 0);
		System.out.println(new String(res));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    S, T = input().split()

    out= ""
    for i in range(N):
        out += S[i]
        out += T[i]

    print(out)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()
A = LI()

s = sum(A)
if N >= s:
    print(N-s)
else:
    print(-1)

Measured memory_bytes: 68288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX1=30,MAX2=3000;
int sgr[MAX2+5],wtr[MAX1+5],A,B,C,D,E,F,s1=1,s2=0;
int main(){
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    wtr[0]=1,sgr[0]=1;
    for(int i=1;i<=MAX1;i++){
        int t1=i-A,t2=i-B;
        if(t1>=0) if(wtr[t1]) wtr[i]=1;
        if(t2>=0) if(wtr[t2]) wtr[i]=1;
    }
    for(int i=1;i<=MAX2;i++){
        int t1=i-C,t2=i-D;
        if(t1>=0) if(sgr[t1]) sgr[i]=1;
        if(t2>=0) if(sgr[t2]) sgr[i]=1;
    }
    for(int i=0;i<=MAX1;i++) for(int j=0;j<=MAX2;j++) if(wtr[i]&&sgr[j]&&100*i+j<=F&&i*E>=j){
        if(s2*(100*i+j)<=s1*j) s1=100*i+j,s2=j;
    }
    printf("%d %d\n",s1,s2);
}


Measured memory_bytes: 256
program example
	implicit none
    
    character(100) S,A,B
    integer :: N,i,countA=0,countB=0,countS=0
    
    read(*,*) S
    
    S=adjustl(S)
    
    N=len_trim(S)
    
	do i=1,N
    
    	if(S(i:i)==S(N+1-i:N+1-i)) then
        	countS=countS+1
        end if
    
    end do
    
    if(countS/=N) then
    	write(*,*) "No"
        goto 1
    end if
    
    A=S(1:(N-1)/2)
    
    B=S((N+3)/2:N)

	do i=1,(N-1)/2
    
    	if(A(i:i)==A(((N-1)/2)+1-i:((N-1)/2)+1-i)) then
        	countA=countA+1
        end if
    
    end do
    
    do i=(N+3)/2,N
    
    	if(B(i:i)==B(N+((N+3)/2)-i:N+((N+3)/2)-i)) then
        	countB=countB+1
        end if
    
    end do
    
    if(countA==((N-1)/2) .and. countB==((N-1)/2)) then
    	write(*,*) "Yes"
    else
    	write(*,*) "No"
        
    end if
    
1 end program

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, H: "List[int]"):
    H.sort()
    if K>=len(H):
        print(0)
    else:
        for i in range(K):
            del H[-1]
        print(sum(H))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28048
# Here your code !
def ans(n, base = 0)
    a = base + n.to_i
    if n.size > 1
        b = (1 ... n.size).inject(0) do |s, len|
            b = n[0, len].to_i
            s + ans(n[len, n.size - len], base + b)
        end
        a + b
    else
        a
    end
end


n = gets.chomp
puts ans(n)


Measured memory_bytes: 1788
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    string ret("Good");
    for(int i = 0 ; i < 3 ; i++){
        if(s[i] == s[i+1]){
            ret = "Bad";
            break;
        }

    }
    cout << ret << endl;

    return 0;
}



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

using ll = long long;

ll f(ll b, ll n) {
	if (n < b) return n;
	return f(b, n / b) + n % b;
}

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

	for (ll b = 2; b * b <= n; b++) {
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}

	ll ans = n == s ? (s + 1) : -1;
	for (ll x = 1; x * x <= n - s; x++) {
		if ((n - s) % x != 0) continue;

		ll b = (n - s) / x + 1,
		   y = s - x;

		if (b * x + y == n and 1 <= x and x < b and 0 <= y and y < b) {
			ans = ans < 0 ? b : min(ans, b);
		}
	}

	cout << ans << endl;

	return 0;
}


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

long long A[100005],B[100005];

long long find(long long a,long long b)
{
	
	
	 if(a%b==0)
	return a;
	
    long long int x=a/b;
	return (x+1)*b;
	
}

int main()
{
	int N;
	cin>>N;
	
	int i;
	for (i=1;i<=N;i++)
	{
		cin>>A[i]>>B[i];
	}
	
	long long sum=0;
	
	for (i=N;i>0;i--)
	{
		long long x=find(A[i]+sum,B[i]);
		sum+=(x-A[i]-sum);
	}
	
	cout<<sum<<endl;
	
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
n = int(input())
MOD = 10**9 + 7

# agc, acg, gac, agxc, axgc
def ok(last4):
    if last4.count("AGC")>0:
        return False
    if last4.count("ACG")>0:
        return False
    if last4.count("GAC")>0:
        return False
    if last4[:2]=="AG" and last4[3]=="C":
        return False
    if last4[0]=="A" and last4[2:]=="GC":
        return False
    return True

memo = [{} for _ in range(n+1)]
def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1

    res = 0
    for c in "AGCT":
        if ok(last3+c):
            res = (res + dfs(cur+1, last3[1:]+c))%MOD
    memo[cur][last3] = res
    return res

print(dfs(0, "TTT"))


Measured memory_bytes: 3884
#include <iostream>

using namespace std;

int caseCnt, numbers[10], curNum;
bool used[10], result;

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = true;

        for(int i=0; i<10; ++i){
            cin >> numbers[i];
            used[i] = false;
        }
        curNum = numbers[0];
        used[0] = true;
        for(int i=1; i<10; ++i){
            if(numbers[i] > curNum){
                curNum = numbers[i];
                used[i] = true;
                //cout << "fk\n";
            }
        }

        bool first_not_used = true;
        for(int i=1; i<10; ++i){
            if(used[i] == false){
                if(first_not_used){
                    first_not_used = false;
                    curNum = numbers[i];
                    //cout << "curNum : " << curNum << endl;
                }else{
                    if(numbers[i] > curNum){
                        curNum = numbers[i];
                    }else{
                        result = false;
                        break;
                    }
                }
            }
        }
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}



Measured memory_bytes: 2976
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[i] - (m // s[- i - 1])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()

Measured memory_bytes: 114688
S = input()
n = len(S) + 1

A = [0 for _ in range(n)]
for i in range(n - 1):
    prev = A[i]
    if S[i] == "<":
        A[i + 1] = max(A[i + 1], prev + 1)

for i in range(n - 1):
    j = n - i - 2
    prev = A[j + 1]
    if S[j] == ">":
        A[j] = max(A[j], prev + 1)

print(sum(A))

Measured memory_bytes: 24092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define f first
#define s second
#define pb push_back
#define mp make_pair 
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vii;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pi;
const ll INF = 1LL << 60;
const unsigned int MOD = 1000000007;
const int dx4[4] = { 1, 0, -1, 0 };
const int dy4[4] = { 0, 1, 0, -1 };
const int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
const int dy8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; 

bool is_prime(int n) { for (int i = 2; i*i <= n; ++i) { if (n % i == 0) return false; } return true; }
long long mod(long long val, long long m) { long long res = val % m; if (res < 0) res += m; return res; }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }

void dfs() {
}

ll dp[110][11000] = {};
ll value[110];
ll weight[110];
int N, W;

int main() {
    cin >> N >> W;
    rep(i, N) cin >> value[i] >> weight[i];
    
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= W; ++j) {
            if(j - weight[i] >= 0) {
                chmax(dp[i + 1][j], dp[i][j - weight[i]] + value[i]);
            }
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 11244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define MP make_pair
#define VI vector<int>
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(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>>;

const ll MAXn=1e5+5;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

ll dp[MAXn];

bool sol(ll x){
  string s="";
  while(x){
    s+=x%10+'0';
    x/=10;
  }
  REP(i,SZ(s)/2){
    if(s[i]!=s[SZ(s)-i-1]) return false;
  }
  return true;
}

int main(){
  IOS();
  for(ll i=10000;i<MAXn;i++){
    dp[i]=dp[i-1];
    if(sol(i)) dp[i]++;
  }
  ll a,b;
  cin>>a>>b;
  cout<<dp[b]-dp[a-1]<<endl;
}


Measured memory_bytes: 1024
#if 0
2020.03.15

钦定根节点，然后把剩下的点和集合做一个匹配，
也就是在在每个集合选一个代表点，然后要求代表点两两不同。
构造方案时只需要从根开始 bfs 加边，每次从当前节点中选一个未考虑过的集合，
并对该集合的关键点连边。
#endif
#include <cstdio>
#include <queue>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 100005;
int head[maxn << 1], nxt[maxn << 3], to[maxn << 3], cap[maxn << 3], hp = 1;
int cur[maxn << 1], level[maxn << 1];

inline void add(int u, int v, int c) {
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
	cap[hp] = c;
	if(!(hp & 1)) add(v, u, 0);
}

bool bfs(int s, int t) {
	std::queue<int> q;
	q.push(s);
	std::fill(level, level + t + 1, 0);
	level[s] = 1;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = head[u]; i; i = nxt[i])
			if(cap[i] and !level[to[i]]) {
				level[to[i]] = level[u] + 1;
				q.push(to[i]);
			}
	}
	return level[t];
}

int dinic(int u, int t) {
	if(u == t) return 1;
	for(int &i = cur[u]; i; i = nxt[i])
		if(cap[i] and level[to[i]] == level[u] + 1) {
			int f = dinic(to[i], t);
			if(f) {
				cap[i] -= f;
				cap[i ^ 1] += f;
				return f;
			}
		}
	return 0;
}

bool vis[maxn];
int match[maxn];
int ansx[maxn], ansy[maxn], ap;

int main() {
	int n = read;

	int s = n * 2, t = n * 2 + 1;
	for(int i = 1; i < n; i ++)
		add(s, i, 1);
	for(int i = 1; i < n; i ++)
		add(n + i, t, 1);

	for(int i = 1; i < n; i ++) {
		int k = read;
		while(k --)
			add(read, n + i, 1);
	}

	int flow = 0;
	while(bfs(s, t)) {
		std::copy(head, head + t + 1, cur);
		int f;
		while((f = dinic(s, t)))
			flow += f;
	}

	if(flow != n - 1) return puts("-1"), 0;

	for(int u = n + 1; u < n * 2; u ++)
		for(int i = head[u]; i; i = nxt[i])
			if(cap[i])
				match[u - n] = to[i];

	std::queue<int> q;
	q.push(n);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = head[u]; i; i = nxt[i])
			if(to[i] != s and !vis[to[i] - n]) {
				vis[to[i] - n] = 1;
				q.push(match[to[i] - n]);
				++ ap;
				ansx[to[i] - n] = u;
				ansy[to[i] - n] = match[to[i] - n];
			}
	}

	if(ap != n - 1) return puts("-1"), 0;

	for(int i = 1; i <= ap; i ++)
		printf("%d %d\n", ansx[i], ansy[i]);
}


Measured memory_bytes: 14644
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    long long L, R, D; cin >> L >> R >> D;
    cout << R/D-(L-1)/D << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
	int i,j,n,k;
	string s;
	cin >> n >> k >> s;
	vector<int> v;
	if(s[0]=='0') v.push_back(0);
	for(i=1;i<n;i++){
		if(s[i]=='0' && s[i-1]=='1') v.push_back(i);
	}
	if(v.size()<=k){
		cout << n << endl;
		return 0;
	}
	int ans = 0;
	for(i=0;i + k - 1<v.size();i++){
		int l = v[i],r = v[i + k - 1],cnt = 0;
		for(j=l - 1;j>=0;j--){
			if(s[j]=='0') break;
			cnt++;
		}
		while(r<n - 1 && s[r + 1]=='0') r++;
		for(j=r+1;j<n;j++){
			if(s[j]=='0') break;
			cnt++;
		}
		ans = max(ans,r - l + cnt + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

long long int dp[101][9][1001];
int main() {
	int n[51],s[51],cn=0,i,j,k,c;
	for (i=0;i<=100;i++) {dp[i][0][i]=1; dp[100][0][i]=1; c=(i+1)/2;
		for (j=i-c+1;j<101 ;j++) if (j<=i) dp[j][1][i]=dp[100-i+j][1][200-i]=j-(i-c+1)+1; else dp[j][1][i]=c;}
	for (i=2;i<9;i++) 
	for (j=0; j<1000; j++) {for (k=2;k<101;k++) if (k<j) dp[k][i][j]=dp[k-1][i][j]+dp[k-1][i-1][j-k]; else dp[k][i][j]=dp[k-1][i][j];}
   while( cin >> n[cn] >> s[cn]) { cn++; if (n[cn-1]+s[cn-1]==0) break;}
   for (i=0;i<cn-1;i++) cout << dp[100][n[i]-1][s[i]] << endl;
   return 0;
}

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

int solve(int x, int y, int z) 
{
    return (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
}


int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
    cin >> n;
    vector<int> ans(1e5);
    for (int i = 1; i < 100; i++)
    {
        for (int j = 1; j < 100; j++)
        {
            for (int k = 1; k < 100; k++)
                ans[solve(i, j, k)]++;
        }
    }
    for (int i = 1; i < n + 1; i++) 
        cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3704
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,popcnt,sse4.1,sse4.2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<17, mod = 119<<23|1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct ctx {
	ll l = 0, sm = 0, sz = 0;
	vector<ctx> c;
	void add(ctx a) { c.pb(a); }
	void process(int f, int rt) {
		sz = 0;
		ll msm = 0, ml = 0;
		for(auto &i : c) {
			sz += i.sz;
			sm += i.sm;
			l += i.l;
			msm = max(msm, i.sm);
			ml = max(ml, i.l);
		}
		if(2*msm <= sm) l = sm&1;
		else l = min(l, 2*msm - sm);
		ll cs = 0;
		for(auto &i : c) {
			cs += min(i.sm, ml - ((i.l&1)!=(ml&1)));
		}
		if(ml != -1) {
			if(2*ml <= cs) l = sm&1;
			else l = min(l, 2*ml-cs);
		}
		sz += f;
		//cout << l << " " << sm << " " << sz << "\n";
		if(!rt) {
			sm += sz;
			l += sz;
		}
		//cout << l << " " << sm << " " << sz << "\n";
		c.clear();
	}
};
int n;
string s;
vi g[maxn];
ll ans = 1ll<<60;
ctx check(int v, int p = -1) {
	ctx t;
	for(auto &i : g[v]) if(i != p) t.add(check(i, v));
	//cout << v << ":\n";
	t.process(s[v]-'0', p == -1);
	return t;
}
ll cost(ll v, ll p = -1, ll h = 0) {
	ll res = (s[v]-'0')*h;
	for(auto &i : g[v]) if(i != p) res += cost(i, v, h+1);
	return res;
}
void go(int i) {
	ll t = check(i).l == 0 ? cost(i) : 1ll<<60;
	ans = min(t, ans);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> s;
	s = "0" + s;
	for(int f, t, i = 1; i < n; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
	}
	for(int i = 1; i <= n; i++) go(i);
	//go(6);
	if(ans == 1ll<<60) ans = -2;
	//assert(ans < 0 || ans%2 == 0);
	cout << ans/2;
}


Measured memory_bytes: 3712
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*

(B - A) < 2 の場合は、換金しないでひたすら叩くだけ
ans = 1 + K

そうでないの場合は、換金できるなら換金した方がいい

最初にA枚まで貯める
それに(A-1)ターンかかる

Aターン目から換金できる。残りは K - A + 1 ターン
換金→購入で2ターン使うので
((K - A + 1) / 2)(B-A) 個になる。

K - A + 1 が奇数の場合は最初に1ターン余るのでそこで1枚

*/


void main(){
	long k = read.to!long;
	long a = read.to!long;
	long b = read.to!long;
	
	long ans;
	if(b - a < 2){
		ans = 1 + k;
	}
	else{
		ans = a + ((k - a + 1) / 2 ) * (b - a);
		if((k - a + 1) % 2 == 1) ans += 1;
	}
	
	ans.writeln;
}



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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  int n, s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i <= min(n, s); i++) {
    for (int j = max(s - i - n, 0LL); j <= min(n, s - i); j++) {
      ans++;
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define pri_max 60000
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
bool isOperator(string c)
{
	if (c == "+" || c == "-" || c == "/" || c == "*" || c == "%" || c == "(" || c == ")" || c == "=")return true;
	return false;
}
int op_pri(string c)
{
	if (c == "+" || c == "-")return 2;
	if (c == "(")return -1;
	return 3;
}
long long calc(long long a, long long b, string op)
{
	if (op == "+")return a + b;
	if (op == "-")return a - b;
	if (op == "*")return a * b;
	if (op == "/")return a / b;
}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		string f; cin >> f;
		vector<string> v;
		string temp;
		for (int i = 0; i < f.size(); i++)
		{
			string now;
			now = f[i];
			if (isOperator(now))
			{
				if (temp != "")v.push_back(temp);
				v.push_back(now);
				temp = "";
			}
			else
			{
				temp += now;
			}
		}

		stack<string> st;
		vector<string> p;

		for (int i = 0; i < v.size() - 1; i++)
		{
			string now = v[i];
			if (isOperator(now))
			{
				if (now == "(")
				{
					st.push(now);
				}
				else if (now == ")")
				{
					while (st.top() != "(")
					{
						p.push_back(st.top());
						st.pop();
					}
					st.pop();
				}
				else
				{
					while (!st.empty())
					{
						if (op_pri(st.top()) >= op_pri(now))
						{
							p.push_back(st.top());
							st.pop();
						}
						else break;
					}
					st.push(now);
				}
			}
			else
			{
				p.push_back(now);
			}
		}
		while (!st.empty()) { p.push_back(st.top()); st.pop(); }

		stack<long long> a;

		for (int i = 0; i < p.size(); i++)
		{
			string now = p[i];
			if (isOperator(now))
			{
				long long v1, v2;
				v2 = a.top(); a.pop();
				v1 = a.top(); a.pop();
				a.push(calc(v1, v2, now));
			}
			else
			{
				a.push(atol(now.c_str()));
			}
		}
		cout << a.top() << endl;

	}
}

Measured memory_bytes: 1232
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

task = [0]*Q
for i in range(Q):
    b, c = list(map(int, input().split()))
    task[i] = (b, c)

count = [0]*(10**5+1)
for i in range(N):
    count[A[i]] += 1

ans = sum(A)

for pair in task:
    B, C = pair
    if count[B]:
        ans -= B * count[B]
        increment = count[B]
        count[C] += count[B]
        count[B] = 0
        ans += C * increment
    print(ans)


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

int main() {
	int n, k;
	cin >> n >> k;
	int d[k];
	int num;
	int cnt[n] = {};
	for (int i = 0; i < k; i++) {
		cin >> d[i];
		for (int j = 0; j < d[i]; j++) {
			cin >> num;
			cnt[num-1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (cnt[i] == 0) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624