akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		string ans = "Good";
		REP(i, s.size()-1) {
			if(s[i]==s[i+1]) ans="Bad";
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

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

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl

int32_t main(void)
{
    //   cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N; vector<int> vec(N, 0); for(int i = 0; i < N; i++) cin >> vec[i];
    double result = 0;
    
    for(auto v : vec)
    {
        result += 1 / (double)v;
    }
    
    printf("%.20lf\n", 1 / result);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n,k ;
	cin >> n >> k ;
	string s,t ; cin >> s ;
	ll cnt = 0 ;
	for(int i=1;i<k;i++){
		bool ok = true ;
		for(int j=0;j<n;j++) ok &= (s.at(0)==s.at(j)) ;
		if(ok) break ;
		if(i==1){
			string tmp = "" ;
			tmp += (char)('z'+1) ;
			for(int j=0;j<=n;j++){
				t = "" ;
				for(int l=0;l<n;l++) t += s.at(min((ll)j+l,2*n-1-j-l)) ;
				reverse(all(t)) ;
				tmp = min(tmp,t) ;
			}
			s = tmp ;
			for(int j=0;j<n;j++){
				if(s.at(j)!=s.at(0)) break ;
				cnt++ ;
			}
			reverse(all(s)) ;
		}else{
			t = "" ;
			for(int j=0;j<n;j++) t += s.at(min(n-cnt+j,n-1+cnt-j)) ;
			reverse(all(t)) ;
			s = t ;
			cnt = min(cnt*2,n) ;
		}
	}
	string tmp = "" ;
	tmp += (char)('z'+1) ;
	for(int i=0;i<=n;i++){
		t = "" ;
		for(int j=0;j<n;j++) t += s.at(min((ll)i+j,2*n-1-i-j)) ;
		tmp = min(tmp,t) ;
	}
	s = tmp ;
	cout << s << endl ;
}


Measured memory_bytes: 3640
import java.lang.Long.max
import java.lang.Long.min
import java.util.ArrayDeque

//

fun main() {
    abc121d()
}

fun abc121d() {
    val (a, b) = readLine()!!.split(" ").map { it.toLong() }
    val from0toA = fromZeroToN(a - 1)
    val from0toB = fromZeroToN(b)
    println(from0toA.xor(from0toB))
}

private fun fromZeroToN(n: Long): Long {
    // n と n+1のxorは1になるので計算を省略できる
    if (n <= 0L) return 0L
    return if (n % 2 == 1L) {
        (n + 1) / 2 % 2
    } else {
        n.xor(n / 2 % 2)
    }
}


Measured memory_bytes: 36428
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<u64>();
    let (a, b) = (v[0], v[1]);
    let x = if b >= 100 {
        a * 1000 + b
    } else if b >= 10 {
        a * 100 + b
    } else {
        a * 10 + b
    };
    for i in 0..10000 {
        if i * i == x {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int A[S.length()];
    for(int i=0;i<S.length();i++){
        A[i]=S[i]-'A';
        A[i] = (A[i]+N)%26;
        S[i] = 'A'+A[i];
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k;
ll v[50];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> v[i];

    ll ans = 0;
    int ab = min(n, k);
    for (int a = 0; a <= ab; a++) {
        for (int b = 0; b <= ab - a; b++) {
            vector<ll> d;
            rep(i, a) d.emplace_back(v[i]);
            rep(i, b) d.emplace_back(v[n-i-1]);
            sort(d.begin(), d.end());

            ll sum = 0;
            rep(i, a+b) {
                if (i < k-a-b && d[i] < 0) continue;
                sum += d[i];
            }
            chmax(ans, sum);
        }
    }
    cout << ans << endl;
}


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

int main(void){
    int A,B,K,cnt=0;
    cin>>A>>B>>K;
    vector<int> a;

    for(int i=1;i<=((A>B)?A:B);i++){
        if(A%i==0&&B%i==0){
            a.push_back(i);
        }
    }

    cout<<a[a.size()-K]<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import copy
input = sys.stdin.readline

n = int(input())
q = [tuple(map(int,input().split())) for _ in range(n)]

px = [0,1,2,3,4,5,6,7]
py = [0,1,2,3,4,5,6,7]
for i in q:
    px.remove(i[0])
    py.remove(i[1])

for v in itertools.permutations(py):
    r_q = copy.deepcopy(q)
    for x,y in zip(px,v):
        for c_q in r_q:
            if c_q[0] == x or c_q[1] == y or abs(c_q[0] - x) == abs(c_q[1]-y):
                break
        else:
            r_q.append((x, y))
            continue
        break
    else:
        board = [['.' for _ in range(8)] for _ in range(8)]
        for i in range(8):
            board[r_q[i][0]][r_q[i][1]] = "Q"
        for i in range(8):
            for j in range(8):
                print (board[i][j],end='')
            print ('')
        exit (0)





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

bool compare_p(tuple<int, int, int> a, tuple<int, int, int> b) {
    if(get<1>(a) != get<1>(b)) return get<1>(a) < get<1>(b);
    else return get<2>(a) < get<2>(b);
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> PY(M);
    rep(i, M) {
        int p, y;
        cin >> p >> y;
        PY[i] = make_tuple(i+1, p, y);
    }
    sort(PY.begin(), PY.end(), compare_p);
    //rep(i, M) cout << get<0>(PY[i]) << " " << get<1>(PY[i]) << " " << get<2>(PY[i]) << endl;

    vector<string> res(M);
    int pre = get<1>(PY[0]);
    int cnt = 1;
    rep(i, M) {
        string sl = "000000", sr = "000000";
        int pn = get<1>(PY[i]);
        string ps = to_string(pn);
        for(int k=0; k<ps.size(); k++) {
            sl[5-k] = ps[ps.size()-k-1];
        }
        string ys;
        if(pn == pre) {
            ys = to_string(cnt);
            cnt++;
        } else {
            ys = "1";
            cnt = 2;
        }
        for(int k=0; k<ys.size(); k++) {
            sr[5-k] = ys[ys.size()-1-k];
        }
        res[get<0>(PY[i])-1] = sl+sr;
        pre = pn;
    }

    rep(i, M) cout << res[i] << endl;
    return 0; 
}

Measured memory_bytes: 9344
#include<iostream>

using namespace std;

int a, b, c, d;

int main() {

	cin >> a >> b >> c >> d;

	while (1) {
		c -= b;
		if (c <= 0)break;
		a -= d;
		if (a <= 0)break;
	}

	if (c <= 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 105;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll h, w;
char arr[N][N];
ll dp[N][N][2];

ll recur(ll r, ll c, ll invert) {

  if ((r == h && c == (w + 1)) or (r == (h + 1) && c == w)) {
    return 0;
  }
  if (c > w) {
    return inf;
  }
  if (r > h)
    return inf;

  ll &ans = dp[r][c][invert];
  if (ans != -1)
    return ans;

  if (invert == 0) {
    if (arr[r][c] == '.') {
      ans = min(recur(r + 1, c, 0), recur(r, c + 1, 0));
    } else {
      ans = 1 + min(recur(r + 1, c, 1), recur(r, c + 1, 1));
      ;
    }
  } else {

    if (arr[r][c] == '#') {
      ans = min(recur(r + 1, c, 1), recur(r, c + 1, 1));
    } else {
      ans = min(recur(r + 1, c, 0), recur(r, c + 1, 0));
    }
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> h >> w;

  for (ll i = 1; i <= h; i++)
    cin >> (arr[i] + 1);

  memset(dp, -1, sizeof(dp));
  cout << recur(1, 1, 0) << en;

  return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int length = s.size();
    int ans = 0;
    for (int i=0; i<length/2; i++) {
        if (s[i] != s[length-i-1])
            ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str[]=new String[10000];
		int i=0,c=0,j;
		while(sc.hasNext()){
			str[c]=sc.next();
			c++;
		}
		
		for(i=0;i<c;i++){
			char ch[]=str[i].toCharArray();
			int lng=str[i].length()-1;
			for(j=0;;j++){
				if(ch[j]=='@'){
					j++;
					int k=ch[j]-'0';
					j++;
					for(int l=0;l<k;l++){
						System.out.print(ch[j]);
					}
				}
				else{
					System.out.print(ch[j]);
				}
				if(j==lng) break;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
import Data.Array.IO
import Control.Monad

main = do
  n <- getLine
  ary <- newArray ((0,0,0),(3,2,9)) 0 :: IO (IOArray (Int,Int,Int) Int)
  forM_ [1..read n] $ \i -> do
    m <- getLine
    let [b,f,r,v] = map (read :: String->Int) . words $ m
    vOld <- readArray ary (b-1,f-1,r-1)
    writeArray ary (b-1,f-1,r-1) (vOld+v)

  forM_ [0..3] $ \i -> do
      forM_ [0..2] $ \j -> do
          forM_ [0..9] $ \k -> do
            vNew <-  readArray ary (i,j,k)
            putStr $ " " ++ show vNew
          putStrLn ""
      if i < 3 then putStrLn "####################" else return ()

Measured memory_bytes: 4132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

/*
//143 E
int main(void) {
	ll n, m, l;
	cin >> n >> m >> l;
	vector <vector<ll>>wf = vector<vector<ll>>(n,vector<ll>(n,1e10));
	rep(i, 0, n)wf[i][i] = 0;
	rep(i, 0, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		wf[a][b] = c;
		wf[b][a] = c;
	}
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				wf[i][j] = min(wf[i][j],wf[i][k] + wf[k][j]);
			}
		}
	}

	ll INF = 1e10;
	vector<vector<ll>>wf2 = vector<vector<ll>>(n, vector<ll>(n, 1e10));
	
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (wf[i][j] <= l) wf2[i][j] = 1;
		}
	}

	rep(i, 0, n)wf2[i][i] = 0;

	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				wf2[i][j] = min(wf2[i][j],wf2[i][k] + wf2[k][j]);
			}
		}
	}

	ll q;
	cin >> q;

	rep(i, 0, q) {
		ll s, t;
		cin >> s >> t;
		s--;
		t--;
		cout << (wf2[s][t] == INF ? -1 : wf2[s][t] - 1) << endl;
	}
}
*/

/*
//143 D
int main(void) {
	ll n;
	cin >> n;
	vector<ll> t = vector<ll>(n);
	rep(i, 0, n) cin >> t[i];
	sort(t.begin(), t.end());
	ll ans = 0;
	rep(i, 0, n-2) {
		rep(j, i + 1, n-1) {
			auto itr = lower_bound(t.begin() + j + 1, t.end(), t[i] + t[j]);
			ans += distance(t.begin() + j + 1, itr);
		}
	}
	cout << ans << endl;
}
*/

/*
//143 C
int main(void) {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	rep(i, 0, n) {
		if (i == n - 1 || s[i] != s[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}
*/

/*
//143 B
int main(void) {
	ll n;
	cin >> n;
	vector <ll> t = vector<ll>(n);
	rep(i, 0, n) cin >> t[i];
	ll ans = 0;
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			ans += t[i] * t[j];
		}
	}
	cout << ans << endl;
}
*/

/*
//143 A
int main(void) {
	ll a, b;
	cin >> a >> b;
	cout << max((ll)0, a - b * 2) << endl;
}
*/

int main(void) {
	ll n, m;
	cin >> n >> m;
	vector<ll> a = vector<ll>(m);
	vector<vector<ll>> box = vector<vector<ll>>(m, vector<ll>());
	rep(i, 0, m) {
		ll b;
		cin >> a[i] >> b;
		rep(j, 0, b) {
			ll c;
			cin >> c;
			box[i].push_back(c);
		}
	}
	const ll INF = 1e10;
	// dp[S | S'][i] = min(dp[S | S'][i-1],dp[S][i-1] + a[i]);
	vector<ll> dp = vector<ll>((1 << n), INF);
    dp[0] = 0;

	rep(i, 0, m) {
		ll now = 0;
		for (const auto& c : box[i]) {
			now |= 1 << (c - 1);
		}
		rep(bits, 0, 1 << n) {
			dp[now | bits] = min(dp[now | bits], dp[bits] + a[i]);
		}
	}
	ll ans = dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1];
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> l(m), r(m);
	int lm = 0, rm = 100000000;
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
		lm = max(lm, l[i]);
		rm = min(rm, r[i]);
	}
	int ans = rm - lm + 1;
	if (0 < ans) {
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1024
#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 ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();


void bubblesort(long long n,long long A[]){
    int flag = 1;
    long long i = 0;
    int count = 0;
    while(flag){
        flag = 0;
        REP3(j,n-1,i){
            if(A[j] < A[j-1]){
                swap(A[j-1],A[j]);
                flag = 1;
                count++;
            } 
        }
        i++;
    }
    REP(k,n-1){printf("%lld ",A[k]);}
    printf("%lld\n",A[n-1]);
    printf("%d\n",count);
}


int main(){
    long long n;
    scanf("%lld",&n);
    long long A[n];
    REP(i,n){scanf("%lld ",&A[i]);}
    bubblesort(n,A);

    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    string S;
    cin >> S;
    int l = S.length();
    int maxLen = 0;
    int current = 0;
    rep(i, l) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'T' || S[i] == 'G') {
            current++;
        } else {
            maxLen = max(maxLen, current);
            current = 0;
        }
    }
    maxLen = max(maxLen, current);
    cout << maxLen << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to k'th element (0-based), order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 1e5 + 10;

LL n, a, b;
int x[N];

int main() {
    cin >> n >> a >> b;
    REP(i, n) cin >> x[i];
    LL ans = 0;
    for (int i = 0; i+1 < n; i++) {
        ans += min(b, a * (x[i+1] - x[i]));
    }
    cout << ans << endl;
}





























Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef pair<long long, long long> P;
int main() {
	long long N, K, R, S, P; cin >> N >> K >> R >> S >> P;
	map<char, char>C;
	C['r'] = 'p';
	C['s'] = 'r';
	C['p'] = 's';
	string T; cin >> T;
	vector<char>Takahashi(N);
	for (long long i = 0; i < N; i++) {
		Takahashi.at(i) = C[T.at(i)];
	}
	for (long long i = K; i < N; i++) {
		if (Takahashi.at(i) == Takahashi.at(i - K)) {
			Takahashi.at(i) = '0';
		}
	}
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		if (Takahashi.at(i) == 'r') ans += R;
		else if (Takahashi.at(i) == 's') ans += S;
		else if (Takahashi.at(i) == 'p') ans += P;
	}
	cout << ans << endl;
}

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

int main(void)
{
	string S;
	cin >> S;
	int N = S.size();
	bool flag = true;
	int count = 0;
	for (int i = 0; i < N-1; i++) {
		if (S.at(i) == S.at(i + 1)) {
			count++;
			if (S.at(i + 1) == '0') {
				S.at(i + 1) = '1';
			}
			else {
				S.at(i + 1) = '0';
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll N;
    cin >> N;
    for (ll n = 1; n <= 3500; ++n)
    {
        for (ll h = 1; h <= 3500; ++h)
        {
            ll a = 4 * h * n - N * (n + h);
            ll b = N * h * n;
            if (a >= 1 && b >= 1 && b % a == 0)
            {
                cout << n << " " << h << " " << b / a;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a[100], b[100], N, i, min, sum;
    scanf("%d", &N);
    for (i = 1; i <= N - 1; i++)
    {
        scanf("%d", &b[i]);
    }
    sum = b[1] + b[N - 1];
    ;
    for (i = 2; i <= N - 1; i++)
    {
        if (b[i - 1] < b[i])
            min = b[i - 1];
        else
            min = b[i];
        sum = sum + min;
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 128
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  ll res = b / x + 1;
  if (a > 0) res -= (a - 1) / x + 1;
  cout << res << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, m, i, j, k, x, y, xx, yy, v, ct, ans, mm;
	cin >> n >> m >> k;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i];
	vector<vector<int>> sum(n + 1, vector<int>(m + 1, 0));
	vector<int> ss(m + 1, 0);

	//for (i = 0; i < n; i++) {
	//	ss.assign(m + 1, 0);
	//	for (j = 0; j < m; j++) {
	//		ss[j + 1] = ss[j] + (1 - (s[i][j] - '0'));
	//		sum[i + 1][j + 1] = sum[i][j + 1] + ss[j + 1];
	//	}
	//}

	ans = n * m * 100;
	for (x = 0; x < (1 << (n - 1)); x++) {
		vector<int> g;	// end of each X section
		g.push_back(0);

		xx = x;
		ct = 0;
		for (i = 0; i < n - 1; i++) {
			if (xx & (1 << i)) {
				g.push_back(i + 1);
				ct++;
			}
		}
		g.push_back(n);

		mm = g.size();
		vector<int> s1(mm, 0), s2(mm, 0);
		for (i = 1; i <= m; i++) {
			bool valid = true, v2 = true;
			int v;
			for (j = 0; j < mm - 1; j++) {
				v = 0;
				for (int kk = g[j]; kk < g[j + 1]; kk++) {
					v += (s[kk][i - 1] - '0');
					if (v > k) v2 = false;
				}
				s2[j] = s1[j] + v;
				if (s2[j] > k) valid = false;
			}
			if (!v2) break;		// entire scheme doesn't work
			if (!valid) {
				ct++;
				for (j = 0; j < mm - 1; j++) s1[j] = s2[j] - s1[j];
			}
			else s1 = s2;
		}

		if (i > m) 
			ans = min(ans, ct);
	}   


	cout << ans << "\n";


	return 0;
}


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

const int MAX_N = 200010;
long long mod = 1e9 + 7;

vector<int> G[MAX_N];
vector<int> sz(MAX_N);
vector<long long> ans(MAX_N);
long long res1 = 1;
int n;

long long inv(long long a, long long p){
    long long res = 1;
    while (p){
        if (p & 1LL)
            res = (res * a) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        p >>= 1;
    }

    return res;
}

void dfs(int u, int p){
    sz[u] = 1;
    for (auto v: G[u]){
        if (v != p){
            dfs(v, u);
            sz[u] += sz[v];
        }
    }

    res1 = ((res1 % mod) * (sz[u] % mod)) % mod;
}

void dfs1(int u, int p){
    if (p != -1){
        ans[u] = (((ans[p] % mod) * (sz[u] % mod) % mod) * (inv(n - sz[u], mod - 2) % mod)) % mod;
    }

    for (auto v: G[u]){
        if (v != p){
            dfs1(v, u);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    
    for (int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;

        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(0, -1);
    ans[0] = 1;
    for (long long i = 1; i <= n; i++)
        ans[0] = ((ans[0] % mod) * (i % mod)) % mod;
    ans[0] = (ans[0] * inv(res1, mod - 2)) % mod;

    dfs1(0, -1);

    for (int i = 0; i < n; i++)
        cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 16244
#include<iostream>
typedef long long ll;
using namespace std;

int main() {
	ll x;
	ll com = 0;
	cin >> x;
	for (int i = 1; i <= x; ++i) {
		com += i;
		if (com >= x) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

if (N == 1 and M == 1):
    print(1)
    exit()
elif N == 1:
    if M == 2:
        print(1)
    else:
        print(M-2)
elif M == 1:
    if N == 2:
        print(1)
    else:
        print(N-2)
else:
    print((N-2)*(M-2))

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), b(n);
	rep(i, n) cin >>a[i] >>b[i];
	sort(all(a)); sort(all(b));
	
	if(n%2){
		cout << (ll)b[n/2] - a[n/2] +1 <<"\n";
	}else{
		cout << ((ll)b[n/2] + b[n/2-1] - a[n/2] -a[n/2-1])  +1 <<"\n";
	}

	return 0;
}


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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

int w, h;
vector<vector<int>> c(50, vector<int>(50)), homon(50, vector<int>(50));
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

void dfs(int y, int x){
  homon[y][x] = 1;
  REP(i, 8){
    int nx = x + dx[i], ny = y+dy[i];
    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
    if(homon[ny][nx] || c[ny][nx] == 0) continue;
    dfs(ny, nx);
  }
}

int main(){
  vector<int> ans;
  while(true){
    cin >> w >> h;
    if(w==0 && h== 0) break;
    REP(i, h){
      REP(j, w){
        cin >> c[i][j];
      }
    }
    REP(i, h){
      REP(j, w){
        homon[i][j] = 0;
      }
    }
    int cnt = 0;
    REP(i, h){
      REP(j, w){
        if(homon[i][j]==1 || c[i][j]==0) continue;
        dfs(i, j);
        cnt++;
      }
    }
    ans.push_back(cnt);
  }
  REP(i, ans.size()){
    cout << ans[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3192
#include <stdio.h>

int main() {
  int n, m, k = 0;
  scanf("%d %d", &n, &m);
  int a[m], b[100010];
  for (size_t i = 0; i < m; i++) {
    scanf("%d", a+i);
  }
  b[0] = 0; b[1] = 1;
  for (size_t i = 2; i <= n+1; i++) {
    if (i == a[k]+1) {
      b[i] = 0;
      k++;
    } else {
      b[i] = (b[i-1] + b[i-2]) % 1000000007;
    }
  }
  printf("%d\n", b[n+1]);
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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(){
    ll n,q;
    cin>>n>>q;
    vector<pair<ll,ll>> kill(n);
    vector<ll> deadend(n);
    rep(i,n){
        ll s,t,x;
        cin>>s>>t>>x;
        deadend[i]=x;
        //killが殺すのは[A,B)
        kill[i]=make_pair(max(0ll,s-x),max(0ll,t-x));
    }
    vector<ll> d(q);
    rep(i,q){
        cin>>d[i];
    }
    set<tuple<ll,ll,ll>> event_idx;
    //以下dのindexに関してRMQ
    //kill_idx-> dのidxに関して[A,B]
    rep(i,n){
        ll l=lower_bound(ALL(d),kill[i].first)-d.begin();
        ll r=upper_bound(ALL(d),kill[i].second-1ll)-d.begin();
        event_idx.insert(make_tuple(l,r,deadend[i]));
    }
    set<ll> st;
    vector<vector<ll>> imos_data(q+1);
    for(auto x:event_idx){
        ll el=get<0>(x),er=get<1>(x),dd=get<2>(x);
        imos_data[el].push_back(dd);
        imos_data[er].push_back(-dd);
    }
    rep(i,q){
        for(auto x:imos_data[i]){
            if(x<0) st.erase(-x);
            if(x>0) st.insert(x);
        }
        if(st.empty()){
            cout<<-1<<endl;
        }
        else{
            cout<<(*st.begin())<<endl;
        }
    }
    return 0;
}

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

int main(){
	int N, answer = 0;
	vector<int> B;
	
	cin >> N;
	for(int i = 0; i < N-1; i++){
		int tmp;
		cin >> tmp;
		B.push_back(tmp);
	}
	
	answer += B[0];
	for(int i = 0; i < N-2; i++){
		if(B[i] < B[i+1]) answer += B[i];
		else answer += B[i+1];
	}
	answer += B[N-2];
	cout << answer << endl;
	return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;

    int end=S.size()-1,start=0;
    int ct=0;
    vector<int> answ(300100);
    vector<int> anse(300100);

    for(int i=0;i<S.size();i++){
        if(i==0 && S[0]=='W') answ[0]=1;
        else if(i==0 && S[0]=='E') anse[0]=1;
        else if(S[i]=='W') {
            answ[i]=answ[i-1]+1;
            anse[i]=anse[i-1];
        }
        else if(S[i]=='E') {
            anse[i]=anse[i-1]+1;
            answ[i]=answ[i-1];
        }
       //cout << answ[i] << anse[i] << endl;
    }

    int mini;
    for(int j=0;j<S.size();j++){
        if(j==0) mini=anse[S.size()-1]-anse[0];
        else if(j==S.size()-1) mini=min(mini,answ[S.size()-2]);
        else mini=min(mini,answ[j-1]+anse[S.size()-1]-anse[j]);
    }
    cout << mini << endl;
    
}

Measured memory_bytes: 3076
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    if (0 < a && a < 10 && 0 < b && b < 10) {
        std::cout << a * b << std::endl;
    } else {
        std::cout << -1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

void connect(vector<P>& dat){
    if(dat.size() <= 1){
        return;
    }

    if(dat[SZ(dat)-1].first == dat[SZ(dat)-2].first){
        dat[SZ(dat)-2].second += dat[SZ(dat)-1].second;
        dat.pop_back();
    }
}

void carry(vector<P>& dat, int k){
    if(dat.back().first < k){
        return;
    }
    dat.pop_back();

    if(dat.size() == 0){
        return;
    }

    if(dat.back().first != k - 1){
        if(dat.back().second == 1){
            dat.back().first++;
            dat.emplace_back(0, 1);
            return;
        }
        dat.back().second--;
        dat.emplace_back(dat.back().first + 1, 1);
        dat.emplace_back(0, 1);
        return;
    }

    P last = dat.back();
    dat.pop_back();

    if(dat.size() == 0){
        return;
    }
    if(dat.back().second == 1){
        dat.back().first++;
        dat.emplace_back(0, last.second + 1);
        return;
    }
    dat.back().second--;
    dat.emplace_back(dat.back().first + 1, 1);
    dat.emplace_back(0, last.second + 1);
}

void increment(vector<P>& dat){
    if(dat.back().second == 1){
        dat.back().first++;
        return;
    }
    dat.back().second--;
    dat.emplace_back(dat.back().first + 1, 1);
}

bool judge(const vector<int>& a, int k){
    vector<P> dat;
    int pos = 0;

    rep(i, SZ(a)){
        if(pos < a[i]){
            dat.emplace_back(0, a[i] - pos);
            pos = a[i];
            continue;
        }

        while(pos > a[i]){
            P last = dat.back();
            dat.pop_back();
            pos -= last.second;
            if(pos < a[i]){
                dat.emplace_back(last.first, a[i] - pos);
                pos = a[i];
            }
        }
        increment(dat);
        carry(dat, k);

        if(dat.size() == 0){
            return false;
        }
    }
    return true;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int lo = 0;
    int hi = n;
    while(hi - lo > 1){
        int mid = (lo + hi) / 2;
        if(judge(a, mid)){
            hi = mid;
        }else{
            lo = mid;
        }
    }

    cout << hi << endl;

    return 0;
}


Measured memory_bytes: 9852
def bisect_left(a, x)
    lo = 0
    hi = a.size
    while lo < hi do
        mid = (lo + hi) / 2
        if a[mid] < x then
            lo = mid + 1
        else
            hi = mid
        end
    end
    return lo
end


N = gets.to_i
L = gets.strip.split.map(&:to_i)

L.sort!
result = 0
(0..N - 3).each do |i|
    (i + 1..N - 2).each do |j|
        result += bisect_left(L, L[i] + L[j]) - j - 1
    end
end
puts result


Measured memory_bytes: 1788
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

int n, w, ai, bi;
vector<int> a; // weight
vector<int> b; // value

long long dp[100001];

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

    cin >> n >> w;
    for (int i = 0; i < n && cin >> ai >> bi; i++) {
    	a.push_back(ai);
    	b.push_back(bi);
    }

    fill(dp, dp + 100001, 0);

    for (int i = 0; i < n; i++) {
    	for (int j = w; j - a[i] >= 0; j--) {
    		dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
    	}
    }

    cout << dp[w];

    return 0;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, result = 0;
  cin >> n;
  char s[n];
  rep(i, n) cin >> s[i];
  ll w = 0;

  FOR(i, 1, n) {
    if(s[i] == 'E') w++;
  }
  result = w;
  FOR(i, 1, n) {
    if (s[i] == 'E') w--;
    if (s[i - 1] == 'W') w++;
    result = min(result, w);
  }
  cout << result << endl;
}

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

int main(){
	
	//準備部分
	char T[1001],W[11];
	int i,x=0;
	
	//入力部分
	scanf("%s",W);
	
	while(1){
		scanf("%s",T);
		if(strcmp(T,"END_OF_TEXT")==0)break;
		for(i=0;T[i]!='\0';i++)T[i]=tolower(T[i]);
		if(strcmp(T,W)==0)x++;
	}
	printf("%d\n",x);
	
	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

map<ll,ll> mcount;
ll a,b,c,d;
ll rec(ll n){
  if(n == 0) return 0;
  if(n == 1) return d;
  if(mcount.count(n)) return mcount[n];

  ll u2 = (n+1)/2*2;
  ll l2 = n/2*2;
  ll u3 = (n+2)/3*3;
  ll l3 = n/3*3;
  ll u5 = (n+4)/5*5;
  ll l5 = n/5*5;

  ll ret = 1e18;
  if(n < 1e18/d) ret = n*d;
  ret = min(ret, llabs(l2-n)*d + a + rec(l2/2));
  ret = min(ret, llabs(u2-n)*d + a + rec(u2/2));

  ret = min(ret, llabs(l3-n)*d + b + rec(l3/3));
  ret = min(ret, llabs(u3-n)*d + b + rec(u3/3));

  ret = min(ret, llabs(l5-n)*d + c + rec(l5/5));
  ret = min(ret, llabs(u5-n)*d + c + rec(u5/5));

  mcount[n] = ret;
  return ret;

}

int main(){
  int t;cin >> t;
  rep(i,t){
    ll n;cin >> n >> a >> b >> c >> d;
    mcount.clear();
    cout << rec(n) << endl;
  }
}

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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            boolean[] exists = new boolean[26];

            for (int i = 0; i < s.length(); i++) {
                exists[s.charAt(i) - 'a'] = true;
            }

            for (int i = 0; i < 26; i++) {
                if (!exists[i]) {
                    out.println((char) (i + 'a'));
                    return;
                }
            }

            out.println("None");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double deg_s = 30*(h+m/60);
  double deg_l = 6*m;  
  double unit_s = deg_s * 2.0*asin(1.0) / 180.0;
  double unit_l = deg_l * 2.0*asin(1.0) / 180.0;
  
  double tmp = a*a+b*b-2*a*b*cos(unit_l-unit_s);
  double ans = sqrt(tmp);
    
  printf("%.12f", ans);
  return 0;
}


Measured memory_bytes: 4216
import java.util.Scanner;

/**
 * TITLE : Tax Increase
 * URL : https://atcoder.jp/contests/abc158/tasks/abc158_c
 */
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        for (int i = 1; i <= 10000; i++) {
            double a = i * 0.08;
            double b = i * 0.1;
            if ((int)a == A && (int)b == B) {
                System.out.println(i);
                sc.close();
                return;
            }
        }
        System.out.println(-1);
        sc.close();
    }
}


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

int main()
{
	int n;
	cin >> n;
	vector<double> x(n),y(n);
	vector<int> od(n);
	for(int i = 0;i<n;i++)
	{
		cin >> x[i] >> y[i];
		od[i]=i;
	}

	double  cnt = 0;
	double sum = 0;
	do
	{
		for(int i = 0;i<n-1;i++)
		{
			sum += sqrt((x[od[i]]-x[od[i+1]])*(x[od[i]]-x[od[i+1]])+(y[od[i]]-y[od[i+1]])*(y[od[i]]-y[od[i+1]]));
		}
		cnt++;
	}
	while(next_permutation(od.begin(),od.end()));
	printf("%.10lf\n",sum/cnt);
}


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

using namespace std;
int n,res=1e9,e[300005],w[300005];
string s;
int main()
{
    cin>>n;
    cin>>s;
    s='0'+s;
    for (int i=1;i<s.size();i++){
        if (s[i]=='W') {
            e[i]=e[i-1]+1;
        } else e[i]=e[i-1];
    }
    for (int i=n;i>=1;i--){
        if (s[i]=='E'){
            w[i]=w[i+1]+1;
        } else w[i]=w[i+1];
    }
    for (int i=1;i<s.size();i++){
        int t1 = e[i-1];
        int t2 = w[i+1];
        if (t1+t2<res) res=t1+t2;
    } // WEWEWEEEWWWE
    cout<<res;
    return 0;
}


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

int main(){
    while(true){
        int m,f,r,sum;
        cin >> m >> f >> r;
        if(m == -1 and f == -1 and r == -1){
            break;
        };
        sum = m + f;
        if(m == -1 or f == -1){
            cout << "F" << endl;
        }else if(sum >= 80){
            cout << "A" << endl;
        }else if(sum >= 65){
            cout << "B" << endl;
        }else if(sum >= 50 or r >= 50){
            cout << "C" << endl;
        }else if(sum >= 30){
            if(r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            };
        }else{
            cout << "F" << endl;
        };
    };
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n; cin >> n;
	int a[123456];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n / 2] - a[n / 2 - 1] << endl;
	cin >> n;
}

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

int main(){
    char s[200], p[100], tmp[200]; //1 ≦ p ≦ s ≦ 100 
    cin >> s;
    cin >> p;
    strcpy(tmp, s);
    strcat(s, tmp);
    if ( strstr(s, p) == NULL ){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    } 
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;


int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	c-=min(a-b,c);
	cout<<c;
}
// check for any potential overflow before submitting


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main(){
    fast;
    int ans = 0;
    int h;
    cin>>h;
    int cnt = 1;
    while(h!=0){
    	ans+=cnt;
    	h = h/(int)2;
    	cnt*=(int)2;
    }
    cout<<ans;
}  

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef pair<ll, vll> plv;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i, a, b) for(ll i=ll(a);i<=ll(b);++i)
#define REPR(i, a, b) for(ll i=ll(a);i>=ll(b);--i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()

template<typename T>
T absolute(T a, T b) { return a >= 0 ? a : -a; }

template<typename T>
T sqr(T a) { return a * a; }

int main() {
    fastio
    ll k,n;double r,sum=0;
    cin>>n>>k;
    REP(i,1,n){
        r=i;
        if(i<k)sum+=pow(0.5,ceil(log2(k/r)));
        else sum+=1;
    }
    sum/=n;
    cout.setf(ios::fixed);
    cout<<setprecision(14)<<sum<<endl;
}

Measured memory_bytes: 256