akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    int n;
    cin >> n;
    int a[101];
    REP(i, 101) a[i] = 0;
    REP(i, n){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    int ans = 0;
    REP(i, 101){
        if(a[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N = 1e5+20;

struct UF{
	int p[N], comp[N];
	UF(){ REP(i,0,N) p[i] = i, comp[i] = 1; }
	int find(int i){ return (p[i] == i) ? i : (p[i] = find(p[i])); }
	void join(int i, int j){
		int x = find(i), y = find(j);
		if(x != y){
			p[x] = y;
			comp[y] += comp[x];
		}
	}
};

UF uf;
int deg[N];
vector<int> block[N];

int main(){

	fastio;
	int n,m,k,a,b;
	cin >> n >> m >> k;
	for(int i = 0; i < m; ++i){
		cin >> a >> b;
		uf.join(a,b);
		deg[a]++;
		deg[b]++;
	}
	for(int i = 0; i < k; ++i){
		cin >> a >> b;
		block[a].pb(b);
		block[b].pb(a);
	}

	for(int i = 1; i <= n; ++i){
		int ans = uf.comp[uf.find(i)] - deg[i] - 1;
		for(int v : block[i]) if(uf.find(i) == uf.find(v)) ans--;
		cout << ans << " ";
	}
	cout << endl;
	
	return 0;
}


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

def solve(N: int, X: "List[int]"):
    min = None
    for p in range(1, 101):
        r = 0
        for x in X:
            r += (x - p)**2
        if min is None or min > r:
            min = r
    return min

# 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
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, X))

if __name__ == '__main__':
    main()


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

int main(){
    int n,a,b;
    cin>>n>>a>>b;

    int sum_total=0;
    int digit_sum=0;
    string i_str;

    for(int i=1; i<=n; i++){
        digit_sum=0;
        i_str=to_string(i);
        for(int j=0; j<i_str.size(); j++){
            digit_sum+=i_str[j]-'0';
        }
        if(a<=digit_sum && digit_sum<=b){
            sum_total+=i;
        }
    }

    cout<<sum_total<<endl;   
}

Measured memory_bytes: 256
n,c = map(int,input().split())
d = [list(map(int,input().split())) for i in range(c)]
s = [list(map(int,input().split())) for i in range(n)]
x = [0] * c
y = [0] * c
z = [0] * c
for i in range(n):
    for j in range(n):
        a = (i+j) % 3
        if a == 0:
            x[s[i][j]-1] += 1
        if a == 1:
            y[s[i][j]-1] += 1
        if a == 2:
            z[s[i][j]-1] += 1
ans = 10 ** 16
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i != j and i != k and j != k:
                o = 0
                for l in range(c):
                    o += d[l][i] * x[l]
                p = 0
                for l in range(c):
                    p += d[l][j] * y[l]
                q = 0
                for l in range(c):
                    q += d[l][k] * z[l]
                ans = min(ans,o+p+q)
print(ans)

Measured memory_bytes: 76400
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N, K, A[100050];

struct edge {
  int src, dst;
  edge(int s, int d) : src(s), dst(d) { }
};
typedef vector<edge> edges;
typedef vector<edges> graph;

int res;
int dfs(const graph& g, int u, int p = -1) {
  int h = 0;
  for (const edge& e : g[u]) {
    chmax(h, 1 + dfs(g, e.dst, e.src));
  }

  if (h == K - 1 && p > 0) {
    ++res;
    return -1;
  }
  return h;
}

int main() {
  N = in();
  K = in();
  graph G(N);
  res = 0;
  for (int i = 0; i < N; ++i) {
    A[i] = in() - 1;
    if (i == 0 && A[0] != 0) {
      A[0] = 0;
      ++res;
    }
    if (i != 0) {
      G[A[i]].emplace_back(A[i], i);
    }
  }

  dfs(G, 0);

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

  return 0;
}


Measured memory_bytes: 10752
n = int(input())
a = list(map(int, input().split()))
b = a.copy()
answer = 0
MOD = 10**9+7
for i in range(n-2, -1, -1):
	b[i] += b[i+1]

for i in range(n-1):
	answer = (answer+a[i]*b[i+1])%MOD
print(answer)

Measured memory_bytes: 31744
#include<iostream>
//#include <cmath>
//#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
  //  freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,x;cin>>n>>x;int arr[n+1];arr[0]=0;
    for(int i=1;i<n+1;i++){
        int t;cin>>t;
        arr[i]=arr[i-1]+t;
    }int cnt=0;
    for(int i=0;i<n+1;i++){
        if(arr[i]<=x) {
            cnt++;
        }
        else{
            break;
        }
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 3624
/*
	Name:
	Date:
	Description:
*/
#include<iostream>
#include<vector>
//#include<buque>?
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int main(){
	long long a,b,c,d=0;
	cin>>a>>b>>c;
	for(int i=a;d<=100;i+=a){
		if(i%b==c){
			cout<<"YES";
			return 0;
		}
		d++;
	}
	cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
list1 = []
goukei = 0
list1 = list(map(int, input().split()))
list1 = sorted(list1, reverse=True)
N_max = list1[0]
goukei = sum(list1[1:])
if N_max < goukei:
  print("Yes")
else:
  print("No")

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));
template <unsigned mod> struct RollingHash {
    vector<unsigned> hashed, power;

    inline unsigned mul(unsigned a, unsigned b) const {
        unsigned long long x = (unsigned long long)a * b;
        unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
        asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod));
        return m;
    }

    RollingHash(const string &s, unsigned base = 10007) {
        int sz = (int)s.size();
        hashed.assign(sz + 1, 0);
        power.assign(sz + 1, 0);
        power[0] = 1;
        for (int i = 0; i < sz; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if (hashed[i + 1] >= mod) hashed[i + 1] -= mod;
        }
    }

    unsigned get(int l, int r) const {
        unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if (ret >= mod) ret -= mod;
        return ret;
    }

    unsigned connect(unsigned h1, int h2, int h2len) const {
        unsigned ret = mul(h1, power[h2len]) + h2;
        if (ret >= mod) ret -= mod;
        return ret;
    }

    int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
                low = mid;
            else
                high = mid;
        }
        return (low);
    }
};

using RH = RollingHash<1000000007>;

void solve(long long N, std::string S) {
    RH rh(S);

    auto check = [&](int d) {
        map<ll, ll> m;
        rep(j, N + 1 - d) {
            ll hash = rh.get(j, j + d);
            if (m.count(hash) == 0) {
                m[hash] = j;
            } else {
                if (m[hash] + d <= j) return true;
            }
        }
        return false;
    };

    // 二分探索
    int left = 0, right = N / 2 + 1;
    while (right - left > 1) {
        int mid = (left + right) >> 1;
        if (check(mid))
            left = mid;
        else
            right = mid;
    }
    cout << left << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long a[(int)2e5];
int main()
{
    long long k;
    cin >> k;
    for(int i = 1;i<=k;i++)
        cin >> a[i];
    long long cur1 = 2;
    long long cur2 = 2;
    for(int i = k;i>0;i--)
    {
        if (cur1%a[i]!=0)
        {
            cur1 = (cur1 + (a[i] - cur1 % a[i]));
        }
        if (cur2%a[i]!=0)
        {
            cur2 = cur2 - cur2%a[i];
        }
       // cout << cur1 << ' '<<cur2<<'!'<<endl;
        if (cur2<cur1)
        {
            cout<<-1;
            return 0;
        }
        cur2 = cur2 + a[i]-1;
       // cout << cur1 << ' '<<cur2<<endl;
    }
    cout << cur1 << ' '<<cur2<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int n, h[21],ans,max;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&h[i]);
	max=h[0];
	ans=1;
	for(int i=1;i<n;i++) {
		if(h[i]>=max)ans++;
		if(h[i]>max)max=h[i];
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  string input;
  cin >> input;
  int N;
  N = input.length();

  int a[N];
  for(int i=0;i<N;++i){
    a[i] = (int)(input[i] - '0');
  }

  bool flug1 = false;
  bool flug2 = false;

  if(a[0]*10+a[1]<13 && a[0]*10+a[1]>0) flug1 = true;
  if(a[2]*10+a[3]<13 && a[2]*10+a[3]>0) flug2 = true;

  if(flug1){
    if(flug2) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }

  else if(flug2) cout << "YYMM" << endl;

  else cout << "NA" << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())

sum = 0
m = 0
for i in range(1, 10**5 + 1):
    sum += i
    if sum >= N:
        m = i
        break

sum = N
for i in range(1, m + 1)[::-1]:
    if sum - i >= 0:
        sum -= i
        print(i)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define snd second
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int calc_combination(map<P, int>& memo, int n, int r) {
    P p = make_pair(n, r);

    if (memo.count(p)) {
        return memo.at(p);
    }

    if (r == 0) {
        return 1;
    }

    if (r == 1) {
        return n;
    }

    if (2 * r > n) {
        return calc_combination(memo, n, (n-r));
    }

    int a = calc_combination(memo, n-1, r);
    int b = calc_combination(memo, n-1, r-1);
    int ans = a + b;

    memo[p] = ans;
    return ans;
}

signed main() {
    int N, R;

    cin >> N >> R;

    int odd_pack_count = 0;
    int even_pack_count = 0;
    vector<int> As(N);
    REP(i, N) {
        int A;
        cin >> A;

        As.at(i) = A;
        if (A % 2 == 0) {
            even_pack_count += 1;
        } else {
            odd_pack_count += 1;
        }
    }

    debug(even_pack_count);
    debug(odd_pack_count);

    map<P, int> memo;

    if (R == 0) {
        cerr << "hit" << endl;
        // 偶数になるように選ぶ
        // → 偶数個のクッキーから好きな数だけ、奇数個のクッキーの中から2n個選ぶ
        // (oddC0 + oddC2 + oddC4 + ... oddC2n) * 2^even

        int ans = 0;
        for(int r = 0; r <= (odd_pack_count / 2) * 2; r += 2) {
            int c = calc_combination(memo, odd_pack_count, r);
            debug(c);
            ans += c;
        }

        ans *= pow(2, even_pack_count);
        cout << ans << endl;
    } else {
        // 奇数になるように選ぶ
        // → 偶数個のクッキーから好きな数だけ、奇数個のクッキーの中から2n+1個選ぶ
        // (oddC1 + oddC3 + oddC5 + ... oddC(2n+1)) * 2^even

        int ans = 0;
        int max;
        if (odd_pack_count % 2 == 1) {
            max = odd_pack_count;
        } else {
            max = odd_pack_count - 1;
        }
        debug(max);

        for(int r = 1; r <= max; r += 2) {
            ans += calc_combination(memo, odd_pack_count, r);
        }

        ans *= pow(2, even_pack_count);
        cout << ans << endl;

    }
}


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

int main(){
    int A,B,C,X,Y,AB,k,a,b;
    int l;
    int price,ans=0;
    int tmp=1000000;
    int tmp2=1000000;
    cin>>A>>B>>C>>X>>Y;  

    if (X<=Y){
        ans+=min(A+B,C*2)*X;
        Y-=X;
        ans+=min(B,C*2)*Y;
    }else{
        ans+=min(A+B,C*2)*Y;
        X-=Y;
        ans+=min(A, C*2)*X;        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// 21:15
//
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
  int N;
  int C[505];
  int S[505];
  int F[505];

  cin >> N;
  for(int i = 1; i < N; i++){
    cin >> C[i] >> S[i] >> F[i];
  }

  for(int i = 1; i < N; i++){
    int ans = 0;
    for(int k = i; k < N; k++){
      //cout << "k:" << k << endl;
      if(ans <= S[k]) ans = (S[k] + C[k]); // 開通式後初電車に乗る
      else{
        if(!((S[k] <= ans) && (ans % F[k] == 0))) ans += (F[k] - ans%F[k]) + C[k]; //電車を待ってから乗る
        else ans += C[k]; // 待たずに乗る
      }
      //cout << "ans:" << ans << endl;
    }
    cout << ans << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#![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::<usize>();
    let (n, k) = (v[0], v[1]);
    if k == 1 {
        println!("{:?}", 0);
        return;
    } else {
        println!("{:?}", n - k);
    }
}

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
# -*- coding: utf-8 -*-
from math import sqrt
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
A, B = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            P.append(i)
            for j in range(2*i, N+1, i):
                sieve[j] = 0
    return P

P = primes(10**6)

ans = 1

ext = []

ais = True
bis = True

S = min(A, B)
for p in P:
    if p > min(A, B):
        break
    ans += int(A%p == B%p == 0)
    while A%p == 0:
        A //= p
    while B%p == 0:
        B //= p
else:
    if A > 1:
        ans += int(B%A == 0)
    elif B > 1:
        ans += int(A%B == 0)

print(ans)

Measured memory_bytes: 50928
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define REP1(i,n) FOR(i,1,n+1)
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define endl '\n'
using namespace std;
signed main (){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	vector<int> vc(n*2);
	REP(i,n*2) cin>>vc[i];
	sort(ALL(vc));
	int sum=0;
	for (int i=0;i<n*2;i+=2){
		sum+=vc[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK: 2000000")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 998244353;
string s;
int q, rev;
deque<char> d;

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>s>>q;
	for(int i=0; i<s.size(); i++) d.push_back(s[i]);
	while(q--){
		int t;
		cin>>t;
		if(t==1) rev++, rev%=2;
		else{
			int f; char c;
			cin>>f>>c;
			if((rev+f)%2==1) d.push_front(c);
			else d.push_back(c);
		}
	}
	if(rev) reverse(d.begin(), d.end());
	for(char c : d) cout<<c;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

lli n,w;

lli maxx = 0;

lli memo[110][100010];

lli calc(lli ind,lli p_wei,lli wei[],lli val[])
{
    if(ind >= n)
        return 0;
    if(memo[ind][p_wei] != -1)
        return memo[ind][p_wei];
    lli a1 = 0;
    lli a2 = 0;
    if(p_wei + wei[ind] <= w)
    {
        a1  = calc(ind+1,p_wei+wei[ind],wei,val) + val[ind];
    }
    a2 = calc(ind+1,p_wei,wei,val);
    a1 = max(a1,a2);
    memo[ind][p_wei] = a1;
    return a1;
    }

int main()
{
    cin>>n>>w;
    lli wei[n],val[n];
    for(lli i=0;i<110;i++)
    {
        for(lli j=0;j<100010;j++)
            memo[i][j] = -1;
    }
    for(lli i=0;i<n;i++)
    {
        cin>>wei[i]>>val[i];
    }
    cout<<calc(0,0,wei,val);
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef queue<pi> qpi;
typedef queue<pl> qpl;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef priority_queue<pi> pqpi;
typedef priority_queue<pl> pqpl;

#define read freopen("in.c", "r", stdin)
#define write freopen("out.c", "w", stdout)
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define ff first
#define ss second
#define left(x) ((x) + (x) + 1)
#define right(x) ((x) + (x) + 2)
#define pb push_back
#define pp pop_back
#define eps 1e-9

ll in()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

int main()
{
    int n;
    cin >> n;
    int ara[n + 5];
    for(int i = 0; i < n; i++)
        cin >> ara[i];
    sort(ara, ara + n);
    int ans = 0, prev = 0;
    for(int i = 0; i < n; )
    {
        int k = upper_bound(ara, ara + n, ara[i]) - ara;
        //cout << "k = " << k << endl;
        int s = k;
        k -= prev;
        prev = s;


        if(k >= ara[i])
            ans += k - ara[i];
        else
            ans += k;
        i = prev;
        //cout << "i = " << i << endl;
        //getchar();
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

static const int INF = 1 << 28;

#define D(x) cout << x << endl;
#define d(x) cout << x;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;

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

  ll ans = 0;

  if (m >= 2 * n) {
    m -= 2 * n;
    ans += n;
    ans += m / 4;
  } else {
    ans += m / 2;
  }
  
  D(ans);
  
  return 0;
}


Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const p = args.slice(1, N + 1).map(arg => parseInt(arg[0], 10)).sort((a, b) => b - a)
	let sum = p[0] / 2

	for (let i = 1; i < N; i++) {
		sum += p[i]
	}

	console.log(sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();
        System.out.println(n1*n2 + " " + 2*(n1+n2));
    }
}


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

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 main(){
  ll X;
  //ll A,B;
  cin>>X;
  for(ll A=0; ;A++){
    for(ll B=0; ;B++){
      ll l = pow(A,5);
      ll r = pow(B,5);
      if(l-r==X){
        cout<<A<<' '<<B;
        return 0;
      }else if(l+r == X){
        cout<<A<<' '<<B*-1;
        return 0;
      }else if(l+r > X && l-r < X){
        break;
      }
    }
  }


}


Measured memory_bytes: 4100
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-10;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[60];
int q[60];
int t[60][60];
int can[60][60][60];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++)scanf("%d",q+i);
	long long ret=0;
	for(int i=0;i<60;i++)can[0][i][i]=1;
	for(int i=1;i<60;i++)for(int j=0;j<60;j++)for(int k=0;k<60;k++){
		can[i][j][k]=can[i-1][j][k]|can[i-1][j%i][k];
	}

	for(int i=0;i<a;i++)t[i][p[i]]=1;
	for(int i=51;i>=1;i--){
		bool nd=false;
		for(int j=0;j<a;j++){
			bool ok=false;
			for(int k=0;k<60;k++){
				if(t[j][k]&&can[i-1][k][q[j]]){
					ok=true;
		//			printf("%d %d %d\n",i,j,k);
				}
			}
			if(!ok)nd=true;
		}
		if(nd){
			if(i==51){
				printf("-1\n");return 0;
			}
			ret+=(1LL<<i);
			for(int j=0;j<a;j++){
				for(int k=0;k<60;k++){
					t[j][k%i]|=t[j][k];
				}
			}
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long a,b[200005],c,ans;
int main()
{
	cin>>a;
	for(int i=0;i<a;i++)
	cin>>b[i];
	for(int i=a-2;i>=0;i--)
	{
		c=(c+b[i+1])%1000000007;
		ans=(ans+c*b[i])%1000000007;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int x;
  cin >> x;
  
  if(400 <= x && 599 >= x) cout << 8 << endl;
  if(600 <= x && 799 >= x) cout << 7 << endl;
  if(800 <= x && 999 >= x) cout << 6 << endl;
  if(1000 <= x && 1199 >= x) cout << 5 << endl;
  if(1200 <= x && 1399 >= x) cout << 4 << endl;
  if(1400 <= x && 1599 >= x) cout << 3 << endl;
  if(1600 <= x && 1799 >= x) cout << 2 << endl;
  if(1800 <= x && 1999 >= x) cout << 1 << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    ll s; cin >> s;
    ll x = (INF - s % INF) % INF;
    ll y = (s + x) / INF;
    cout << "0 0 1000000000 1 " << x << " " << y << "\n";
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

n = int(input())
mod = 10**9 + 7

# 再帰だとなんか通らん
# dp = {}
# def rec(i, zero, nine):
#     if (i, zero, nine) in dp:
#         return dp[(i, zero, nine)]
#     if i == n:
#         return 1 if (zero and nine) else 0
#     ret = 0
#     for j in range(10):
#         if j == 0:
#             ret += rec(i + 1, True, nine)
#         elif j == 9:
#             ret += rec(i + 1, zero, True)
#         else:
#             ret += rec(i + 1, zero, nine)
#         ret %= mod
#     dp[(i, zero, nine)] = ret
#     return ret

# print(rec(0, False, False))

dp = [[[0 for _ in range(2)] for _ in range(2)] for _ in range(10**6 + 10101)]
dp[0][0][0] = 1  # どういう意味なのかは不明
for i in range(n):
    for j in range(2):
        for k in range(2):
            for m in range(10):
                if m == 0:
                    dp[i + 1][1][k] += dp[i][j][k]
                    dp[i + 1][1][k] %= mod
                elif m == 9:
                    dp[i + 1][j][1] += dp[i][j][k]
                    dp[i + 1][j][1] %= mod
                else:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j][k] %= mod
print(dp[n][1][1])
# 869121

# 2511445


Measured memory_bytes: 392556
#include <iostream>
#include <algorithm>
#include "math.h"
#include "stdio.h"

using namespace std;

#define UP_SURFACE 1
#define SURFACE 2
#define RIGHT_SURFACE 3

#define IN_ROLL 7
#define IN_PITCH 8

class Dice{
public:
    int surface[6];
    
    void roleEast();
    void roleWest();
    void roleNorth();
    void roleSouth();
    void swap(int surface2[]);
    int getSurface(int num);
    bool isPitchSide(int num);
};

void Dice::swap(int* surface2){
    for(int i = 0;i < 6;++i){
        surface[i] = surface2[i];
    }
}

void Dice::roleEast(){
    int tmp[6];
    tmp[0] = surface[3];
    tmp[3] = surface[5];
    tmp[5] = surface[2];
    tmp[2] = surface[0];
    tmp[1] = surface[1];
    tmp[4] = surface[4];
    swap(tmp);
}

void Dice::roleWest(){
    int tmp[6];
    tmp[3] = surface[0];
    tmp[5] = surface[3];
    tmp[2] = surface[5];
    tmp[0] = surface[2];
    tmp[1] = surface[1];
    tmp[4] = surface[4];
    swap(tmp);
}

void Dice::roleNorth(){
    int tmp[6];
    tmp[0] = surface[1];
    tmp[1] = surface[5];
    tmp[5] = surface[4];
    tmp[4] = surface[0];
    tmp[2] = surface[2];
    tmp[3] = surface[3];
    swap(tmp);
}

void Dice::roleSouth(){
    int tmp[6];
    tmp[0] = surface[4];
    tmp[4] = surface[5];
    tmp[5] = surface[1];
    tmp[1] = surface[0];
    tmp[2] = surface[2];
    tmp[3] = surface[3];
    swap(tmp);
}

int Dice::getSurface(int num){
    for(int i = 0;i < 6;++i){
        if(surface[i] == num){
            return i + 1;
        }
    }
    return 0;
}

bool Dice::isPitchSide(int num){
    int surface = getSurface(num);
    if(surface == 3 || surface == 4){
        return true;
    }
    return false;
}


int main(){
    int num;
    Dice dice;
    int upSurface,frontSurface;
    for(int i = 0;i < 6;++i){
        cin >> dice.surface[i];
    }
    cin >> num;
    
    for(int i = 0;i < num;++i){
        cin >> upSurface >> frontSurface;
        // frontSurfaceを合わせる
        while(frontSurface != dice.surface[SURFACE - 1]){
            if(dice.isPitchSide(frontSurface)){
                dice.roleEast();
            }
            else {
                dice.roleSouth();
            }
        }
        // upSurfaceを合わせる
        while(upSurface != dice.surface[UP_SURFACE - 1]){
            dice.roleEast();
        }

        cout << dice.surface[RIGHT_SURFACE - 1] << endl;
    }
}



Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main(){
    int i,n,j;
    int taro_p = 0, hanako_p = 0;
    string taro, hanako;
    
    cin >> n;
    
    for(i = 0; i < n; i++ ){
            cin >>  taro >>  hanako;
            
            if((taro > hanako) == 1){
                taro_p = taro_p + 3;
                }
            
            if((taro < hanako) == 1){
                hanako_p = hanako_p + 3;
                }
            
            if((taro == hanako) == 1){
                hanako_p++; taro_p++;
                }
        }
        
    cout << taro_p << " " << hanako_p << endl;
    return 0;
}

Measured memory_bytes: 1208
n, k = map(int, raw_input().split(" "))
v = map(int, raw_input().split(" "))

ans = 0
for k1 in range(0, min(n, k) + 1):
    for k2 in range(0, max(min(k - k1 + 1, n - k1 + 1), 0)):
        k3 = max(0, k - k1 - k2)

        gets = v[0:k1] + v[len(v)-k2:len(v)]
        sort = sorted(gets)

        sum = 0
        for i in range(0, len(sort)):
            if sort[i] < 0 and i <= k3 - 1:
                pass
            else:
                sum += sort[i]

        # if ans < sum:
            # print("%d %d %d" % (k1, k2, sum))
            # print(gets)
        ans = max(sum, ans)

print(ans)


Measured memory_bytes: 2696
x=int(input())
y=list(map(int, input().split()))

ans=99
ansb=0
t=0
for i in range(x):
	ansb=0
	t=y[i]
	while t%2==0:
		ansb=ansb+1
		t=t/2
	if ans>ansb:
		ans=ansb
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int stu[31] = {0};
	int i = 28, n;
	
	while(i-- > 0){
		scanf("%d", &n);
		stu[n] = 1;
	}
	
	for(i = 1; i < 31; i++){
		if(stu[i] == 0){
			printf("%d\n", i);
		}
	}
	
	return(0);
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//↑templete
signed main(){

	int N;
	cin>>N;
	vector<int> V;
	for(int i=0;i<N;i++){
		int v;
		cin>>v;
		V.emplace_back(v);
	}

	vector<pair<int, int>> cnt[2];	//(aの数, a)
	for(int i=0;i<2;i++){
		for(int j=0;j<100050;j++){
			cnt[i].emplace_back(0, j);
		}
	}

	for(int i=0;i<N;i++){
		cnt[i%2][V[i]].first++;
	}

	for(int i=0;i<2;i++){
		sort(cnt[i].begin(), cnt[i].end(), greater<pair<int, int>>());
	}

	if(cnt[0][0].second==cnt[1][0].second){
		cout<<N-max(cnt[0][0].first+cnt[1][1].first, cnt[0][1].first+cnt[1][0].first)<<endl;
	}
	else{
		cout<<N-cnt[0][0].first-cnt[1][0].first<<endl;
	}

    return 0;
}

Measured memory_bytes: 2932
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val all = IntArray(n) { readLine()!!.toInt() }
    var index = 0
    for (i in 1..n) {
        val a = all[index]
        if (a == 2) {
            return println(i)
        }
        index = a-1
    }
    println(-1)
}

Measured memory_bytes: 39524
require 'set'
require 'pp'
N = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)


# bits = Array.new(N) { Array.new(21, 0) }
# N.times do |i|
#   x = a[i]
#   21.times do |j|
#     bits[i][j] = x % 2
#     x /= 2
#   end
#   # pp [i, bits[i]]
# end


ans = 0

l = r = 0
# cur = Array.new(21, 0)
cur = 0
while l < N do
  # puts "l:#{l} r:#{r} ans:#{ans} cur:#{cur}"
  while r < N do
    flag = (cur ^ a[r]) != (cur + a[r])
    break if flag

    cur = cur ^ a[r]
    r += 1
    # puts "l:#{l} r:#{r} ans:#{ans} cur:#{cur}"
  end

  ans += r - l

  cur = cur ^ a[l]

  l += 1
end


puts ans


Measured memory_bytes: 16580
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while (scanf ("%d",&n)!=EOF)
    {
    int prime[n+1],i,j;
    for (i=0;i<=n;i++)
        prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for (i=2;i<=sqrt(n);i++)
    {
        if (prime[i]==1)
        {
            for(j=2;i*j<=n;j++)
                prime[i*j]=0;
        }
    }
    int cnt=0;
    for (i=0;i<=n;i++)
    {
        if (prime[i]!=0)
            cnt++;
    }
    cout<<cnt<<endl;
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b;
  	cin >> a >> b;
	cout << max(0,a-b) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
from networkx import *
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
g = Graph(a)
ans = 0
for i in range(2, n + 1):
  for p in all_simple_paths(g, 1, i):
    if len(p) == n:
      ans += 1
print(ans)

Measured memory_bytes: 53328
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;


signed main(){
  int N,a;cin>>N;
  map<int,int> mp;
  REP(i,0,N){
    cin>>a;
    if(a%4==0){
      mp[4]++;
    }
    else if(a%2==0){
      mp[2]++;
    }
    else{
      mp[1]++;
    }
  }
  string ans;
  if(mp[4]>=mp[1])ans="Yes";
  else if(mp[4]+1==mp[1]){
    if(mp[2]>0)ans="No";
    else ans="Yes";
  }
  else ans="No";

  print(ans)

}


Measured memory_bytes: 256
S=input()
K = int(input())

ans = 0

for i in range(len(S)):
	if int(S[i])==1:
		ans = 1
	else:
		if K-1<=i:
			ans = int(S[K-1])
		else:
			ans = int(S[i])
		break
print(ans)

Measured memory_bytes: 3060
fun main(args: Array<String>) = println(run {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val students = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val checkpoint = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    students.map { ab ->
        val (a,b) = ab
        checkpoint.withIndex().minBy { cd ->
            val (c,d) = cd.value
            Math.abs(a-c) + Math.abs(b-d)
        }!!.index + 1
    }.joinToString("\n")

})


Measured memory_bytes: 37924
import numpy as np

num = int(input())
inputs = np.array(input().split(), dtype=np.int32)

left = 0
right = len(inputs)-1
diff = 0

while left <= right:
    if diff == 0:
        diff += inputs[left] - inputs[right]
        left += 1
        right -= 1
    elif diff < 0:
        diff += inputs[left]
        left += 1
    elif diff > 0:
        diff -= inputs[right]
        right -= 1

print(np.abs(diff))

Measured memory_bytes: 21536
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}

int main() {
  int cnt = 0;
  long long money = 100, x; cin >> x;
  while (money < x) {
    money = floor(money * 1.01);
    //cout << money << endl;
    cnt++;
  }
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep(i,k) cin >> l[i] >> r[i];
    vector<mint> dp(n+1);
    vector<mint> dpsum(n+1);
    dp[1] = 1;
    dpsum[1] = 1;
    for (int i = 2; i <= n; i++) {
        rep(j,k) {
            int li = i-r[j];
            int ri = i-l[j];
            if (ri < 0) continue;
            li = max(li, 1);
            dp[i] += dpsum[ri] - dpsum[li-1];
        }
        dpsum[i] = dpsum[i-1] + dp[i];
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 6428
#include<iostream>
#include<algorithm>
using namespace std;
int n,h[1<<17],dp[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=!!i*2e9;
	}
	for(int i=0;i<n;i++)
	{
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	a = Tuple{Int,Int}[(0,0) for i in 1:n]
	for i in 1:n
		t,d = readline() |> split |> parseMap
		a[i] = (t,d)
	end
	a = sort(a,by=x->x[2],rev=true)
	uni = Int[]
	inu = Int[]
	chk = zeros(Int,n)
	for i in 1:n
		if chk[a[i][1]] == 0
			push!(uni,a[i][2])
			chk[a[i][1]] = 1
		else
			push!(inu,a[i][2])
		end
	end
	lu = length(uni)
	li = length(inu)
	for i in 2:lu
		uni[i] += uni[i-1]
	end
	for i in 2:li
		inu[i] += inu[i-1]
	end
	maxim = 0
	for i in 1:min(lu,k)
		if i+li>=k
			if i==k
				maxim = max(maxim,uni[i]+k*k)
			else
				maxim = max(maxim,uni[i]+inu[k-i]+i*i)
			end
		end
	end
	println(maxim)
end

main()

Measured memory_bytes: 161508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int A, B;
    cin >> A >> B;
    int i;
    for (i = 1; i <= 1250; i++) {
        if (int(i*0.08) == A && int(i*0.1) == B) {
            cout << i;
            break;
        }
    }
    if (i == 1251)
        cout << -1;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int A, B, p, m, x, max;
  scanf("%d%d", &A, &B);
  p = A + B;
  m = A - B;
  x = A * B;
  max = p;
  if (max < m)
  {
    max = m;
  }
  if (max < x)
  {
    max = x;
  }
  printf("%d\n", max);
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        int d = scn.nextInt();
        System.out.println(Math.min(a,b)+Math.min(c,d));
    }
}

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


int main(){
 int n;cin >> n;
 string frag = "Yes";
 vector <pair<int,int>> p(n);
 rep{
   int ai,bi;cin >> ai>>bi;
   p[i] = make_pair(bi,ai);
 }
 sort(p.begin(), p.end());
 ll s = 0;
 rep{
   s+= p[i].second;
   if(s>p[i].first) frag = "No";
 }
 cout << frag << endl;
} 

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int MAX = 1000000;
constexpr int inf = 1<<30;

int h,w,k;
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    char s;
    cin>>s;
    char st = tolower(s);
    if(st == s) cout << "a" << endl;
    else cout << "A" << endl;
    return 0;
}

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

using namespace std;

namespace jumpmelon
{
	const int MAXN = 20;
	char X[(1 << MAXN) + 3];
	int *Ans[MAXN + 1], *F[MAXN + 1][MAXN + 1];
	int *P[MAXN + 1][2];
	
	void work()
	{
		int n, lim;
		scanf("%d%d", &n, &lim);
		for (int i = 0; i <= n; i++)
		{
			Ans[i] = new int[1 << i | 3];
			memset(Ans[i], 0, sizeof(int[1 << i]));
			for (int j = 0; i + j <= n; j++)
			{
				F[i][j] = new int[1 << (i + j) | 3];
				memset(F[i][j], 0, sizeof(int[1 << (i + j)]));
			}
			for (int k = 0; k < 2; k++)
			{
				P[i][k] = new int[1 << i | 3];
				for (int S = 0; S < (1 << i); S++)
				{
					if (i == 0)
						P[i][k][S] = -1;
					else if ((S >> (i - 1) & 1) == k)
						P[i][k][S] = i - 1;
					else
						P[i][k][S] = P[i - 1][k][S & ((1 << (i - 1)) - 1)];
				}
			}
		} 
		for (int j = 0; j <= n; j++)
		{
			scanf("%s", X);
			for (int T = 0; T < (1 << j); T++)
				F[0][j][T] = X[T] - '0';
		}
		for (int i = 0; i <= n; i++)
			for (int j = 0; i + j <= n; j++)
				for (int S = 0; S < (1 << i); S++)
					for (int T = 0; T < (1 << j); T++)
					{
						int v = F[i][j][S << j | T];
						Ans[i][S] += v;
						for (int k = 0; k < 2; k++)
						{
							int m = P[j][k][T], TT = T & ((1 << m) - 1);
							if (m >= 0)
								F[i + 1][m][(S << 1 | k) << m | TT] += v;
						}
					}
		for (int l = n; l >= 0; l--)
			for (int S = 0; S < (1 << l); S++)
				if (Ans[l][S] >= lim)
				{
					for (int i = (l - 1); i >= 0; i--)
						putchar((S >> i & 1) + '0');
					putchar('\n');
					return;
				}
	}
}

int main()
{
	jumpmelon::work();
	return 0;
}

Measured memory_bytes: 192256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 

int main() {
	ll n;
	cin>>n;
	ll A[n];
	for(ll i=0;i<n;i++){cin>>A[i];}
	
	ll i=0,j=n-1;ll ans=0,check=0;
	ll left=0,right=0,l=0,r=0;
	while(i<n && j>0 && i<j )
	{
	   if(l==0){left+=A[i];l=1;}
	   if(r==0){right+=A[j];r=1;}
	   
	   if(right>left)
	   {
	      i++;l=0; 
	   }
	  else if(left>right)
	  {
	      j--;r=0;
	  }
	  else if(left==right)
	  {
	      i++;j--;l=0;r=0;
	  }
	}
	ans=abs(left-right);
	if(i==j && ans==0){ans+=A[i];}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792