akhauriyash/Code-Regression huggingface dataset:
#coding: utf-8
q,h,s,d = map(int, input().split())
n = int(input()) * 4
h = min(h,2*q)
s = min(s,2*h)
d = min(d,2*s)

price = [d,s,h,q]
#print (price)
ans = 0
for i,p in enumerate(price):
    b = int(2**(3-i))
    #print (n,b)
    ans += (n // b) * p
    n = n % b
print (ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Result{
  set<int> value;
  int p;
  Result(set<int> v, int p) : value(v), p(p) {}
};

bool is_operator(char c){
  string opes = "uidsc";
  REP(i, opes.size()) if(c == opes[i]) return true;
  return false;
}
void operation(const set<int>& s1, const set<int>& s2, char ope, set<int>& res){
  if(ope == 'u'){
    FORIT(it, s1) res.insert(*it);
    FORIT(it, s2) res.insert(*it);
  }else if(ope == 'i'){
    FORIT(it, s1) if(s2.count(*it)) res.insert(*it);
  }else if(ope == 'd'){
    FORIT(it, s1) if(!s2.count(*it)) res.insert(*it);
  }else if(ope == 's'){
    FORIT(it, s1) if(!s2.count(*it)) res.insert(*it);
    FORIT(it, s2) if(!s1.count(*it)) res.insert(*it);
  }else{
    assert(false);
  }
}
Result expr(const string& s, int p, map<char, set<int> >& vars);
Result factor(const string& s, int p, map<char, set<int> >& vars);
Result expr(const string& s, int p, map<char, set<int> >& vars){
  Result r = factor(s, p, vars);
  while(is_operator(s[r.p])){
    Result r_ = factor(s, r.p + 1, vars);
    set<int> newset;
    operation(r.value, r_.value, s[r.p], newset);
    r.value = newset;
    r.p = r_.p;
  }
  return r;
}
Result factor(const string& s, int p, map<char, set<int> >& vars){
  if(s[p] == '('){
    Result r = expr(s, p + 1, vars);
    assert(s[r.p] == ')');
    r.p++;
    return r;
  }else if(s[p] == 'c'){
    Result r = factor(s, p + 1, vars);
    set<int> v;
    FORIT(it, vars['U'])if(!r.value.count(*it)){
      v.insert(*it);
    }
    r.value = v;
    return r;
  }else{
    assert(vars.count(s[p]));
    set<int> v = vars[s[p++]];
    return Result(v, p);
  }
}

int main(){
  while(true){
    char v; int l;
    map<char, set<int> > vars;
    while(cin >> v >> l){
      if(v == 'R'){
        break;
      }
      set<int> s;
      REP(i, l) {
        int t; cin>>t;
        s.insert(t);
        vars['U'].insert(t);
      }
      vars[v] = s;
    }
    if(cin.eof()) return 0;
    string s;
    cin >> s;
    set<int> res = expr(s, 0, vars).value;
    assert(expr(s, 0, vars).p == s.size());
    FORIT(it, res){
      if(it != res.begin()) cout << " ";
      cout << *it;
    }
    if(res.empty()) cout << "NULL";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<typename T = int, class F = std::plus<T>, class F_INV = std::minus<T>, const T E = 0>
struct BinaryIndexedTree {
    const F op = F(); const F_INV op_inv = F_INV();
    int n; vector<T> dat;
    template<class U = vector<T>> void build(U&& v) {
        n = v.size(); dat.assign(n, E); for (int i = 0; i < n; ++i) add(i, v[i]);
    }
    void add(int k, T v) { for (int i = k; i < n; i |= i + 1) dat[i] = op(dat[i], v); }
    T query(int a, int b) {
        if (a == b) return E;
        T ret = E; for (int i = b - 1; i >= 0; i = (i & (i + 1)) - 1) ret = op(ret, dat[i]);
        return op_inv(ret, query(0, a));
    }
};

int main() {
    int N;
    cin >> N;
    vector<bool> black(2 * N);
    vector<int> a(2 * N);
    rep(i, 2 * N) {
        char c;
        cin >> c >> a[i];
        a[i]--;
        black[i] = c == 'B';
    }

    vector<int> bi(N), wi(N);
    rep(i, 2 * N) {
        if (black[i]) bi[a[i]] = i;
        else wi[a[i]] = i;
    }

    vv<int> dp = vvec(N + 1, N + 1, INF);
    dp[0][0] = 0;
    
    BinaryIndexedTree<int> bbit, wbit;
    bbit.build(vector<int>(2 * N));
    wbit.build(vector<int>(2 * N));
    rep(i, N) {
        int lbtb = bbit.query(0, bi[i]);

        wbit.dat.assign(wbit.dat.size(), 0);
        rep(j, N) {
            int lbtw = bbit.query(0, wi[j]);
            int lwtb = wbit.query(0, bi[i]);
            int lwtw = wbit.query(0, wi[j]);
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + wi[j] - lbtw - lwtw);
            dp[i + 1][j] = dp[i][j] + bi[i] - lbtb - lwtb;
            wbit.add(wi[j], 1);
        }

        dp[i + 1][N] = dp[i][N] + bi[i] - lbtb - wbit.query(0, bi[i]);
        bbit.add(bi[i], 1);
    }

    wbit.dat.assign(wbit.dat.size(), 0);
    rep(j, N) {
        dp[N][j + 1] = min(dp[N][j + 1], dp[N][j] + wi[j] - bbit.query(0, wi[j]) - wbit.query(0, wi[j]));
        wbit.add(wi[j], 1);
    }

    write(dp[N][N]);
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=505;
int n,P,ans,f[N][N];
struct st{int i,l,r;}a[N];
inline bool cmp(st a,st b)
{
	int a1=a.i<n?a.l-1:a.r;
	int a2=a.i<n?a.r:a.l-1;
	int b1=b.i<n?b.l-1:b.r;
	int b2=b.i<n?b.r:b.l-1;
	return a1!=b1?a1<b1:(a2!=b2?a2<b2:a.i>b.i);
}
inline int calc(int k)
{
	memset(f,0,sizeof(f));f[0][0]=1;int s=0;
	rep(i,1,2*n)
	{
		rep(j,0,k)if(f[i-1][j])
		{
			int w=f[i-1][j];
			if(a[i].i>=n)
			{
				int c=a[i].r+1-(i-1-(s-j));
				if(c>0)f[i][j]=(f[i][j]+1ll*w*c)%P;
			}
			else
			{
				int c=a[i].r+1-(2*n-a[i].i-1+k-j);
				if(c>0)f[i][j]=(f[i][j]+1ll*w*c)%P;
				c=a[i].l-(i-1-(s-j));
				if(c>0)f[i][j+1]=(f[i][j+1]+1ll*w*c)%P;
			}
		}
		s+=a[i].i<n;
	}
	return f[2*n][k];
}
int main()
{
	n=rd();P=rd();
	rep0(i,0,2*n)
	{
		a[i+1].i=i;if(i<n)a[i+1].l=ceil(sqrt(n*n-i*i));
		a[i+1].r=floor(sqrt(4*n*n-i*i));a[i+1].r=min(a[i+1].r,2*n-1);
	}
	sort(a+1,a+2*n+1,cmp);
	rep(i,0,n)ans=(ans+1ll*(i&1?P-1:1)*calc(i))%P;
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, ans;
    string s;

    cin >> s;

    n = s.size();

    ans = n;
    for (i = 0; i < n - 1; i++) {
        if (s[i] != s[i + 1]) {
            ans = min(ans, max(i + 1, n - i - 1));
        }
    }

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

    return 0;
}

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

using namespace std;

int main()
{
  string s; cin >> s; reverse(s.begin(), s.end());
  
  int dp[1000005][2]; dp[0][0] = 0; dp[0][1] = 1;
  for (int i = 0; i < s.length(); ++i) {
    dp[i+1][0] = min(dp[i][0], dp[i][1]+1)+s[i]-'0';
    dp[i+1][1] = min(dp[i][0], dp[i][1]-1)+10-(s[i]-'0');
  }
 
  cout << min(dp[s.length()][0], dp[s.length()][1]+1) << endl;
  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, k;
    cin >> n >> k;
    ll m = n % k;
    ll ans = min(m, abs(k - m));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n = gets
until n.nil?
    classmember = Array.new(39,0)
    kyan = n.to_i
    i = 0
    kyan.times do
        classmember[i] += 1
        i += 1
        if i == 39
            i = 0
        end
    end
    howkyan = classmember.max
    num = classmember.rindex(howkyan)
    ansnum = num + 1
    if ansnum < 10
        ansnumm = ansnum.to_s
        ansnum = "0"+ansnumm
    end
    
    puts "3C#{ansnum}"

    n = gets
end


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

using namespace std;

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

    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int res = 2000000000;
    for (int i = 0; i + k - 1 < n; i++) {
        res = min(res, x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i])));
    }

    cout << res << endl;
}


Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    let x = [ a + a-1,
              a + b,
              b + b-1,
            ];
    println!("{}", x.iter().max().unwrap());
}


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

map<string, int> mp;

int main() {
  	string s, t, u;
  	int a, b;
  	cin >> s >> t;
  	cin >> a >> b;
  	mp[s] = a;
  	mp[t] = b;
  	cin >> u;
  	mp[u]--;
  	cout << mp[s] << " " << mp[t] << "\n";
}

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

int main() {
  int n, k, a = 1;
  cin >> n >> k;
  rep(i, n) a = min(a*2, a+k);
  cout << a << endl;
  return 0;
}

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

int main() {
   string S_A, S_B, S_C;
   cin >> S_A >> S_B >> S_C;
   int A_count = 0, B_count = 0, C_count = 0;

   char turn = 'a';
   for(;;) {
         if(turn == 'a') {
         if(A_count == S_A.size()) {
            cout << 'A' << endl;
            return 0;
         }
         turn = S_A[A_count];
         A_count++;
         }

      if(turn == 'b') {
         if(B_count == S_B.size()) {
            cout << 'B' << endl;
            return 0;
         }
         turn = S_B[B_count];
         B_count++;
      }

      if(turn == 'c') {
         if(C_count == S_C.size()) {
            cout << 'C' << endl;
            return 0;
         }
         turn = S_C[C_count];
         C_count++;
      }
   }
}

Measured memory_bytes: 3600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<n; i++)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
}

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

int main() {
  int n, mini = 0, ans = 0;
  cin >> n;
  vector<int> moti(n);
  for (int i = 0; i < n; i++) cin >> moti.at(i);
  sort(moti.begin(), moti.end());
  for(int x : moti) {
    if(mini != x) {
      ans++;
      mini = x;
    }else {
      continue;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(void)
{
  int n;
  vector<int> d;
  int inp;
  int count=0;

  cin>>n;

  for(int i = 0; i < n; i++)
  {
    cin>>inp;
    d.push_back(inp);
  }

  sort(d.begin(),d.end());

  for(int i=1;i<=n;i++)
  {
    if(d[i] != d[i-1])
    {
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int ans = 1 << 20;
        for (int i = 0; i + 1 < n; i++) {
            ans = min(ans, a[i + 1] - a[i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3136
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        char a;
        cin >> a;
        if (a<= 'z' && a>= 'a') cout << 'a';
        else cout << 'A';
return 0;
}


Measured memory_bytes: 3652
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nums = inputs.head.split(" ").map(_.toInt)
  val x = nums(0)
  val y = nums(1)

  println(solve(x, y))

  private def solve(x: Int, y: Int): String = {
    val ga = Seq(1, 3, 5, 7, 8, 10, 12)
    val gb = Seq(4, 6, 9, 11)
    val yes = (ga.contains(x) && ga.contains(y)) || (gb.contains(x) && gb.contains(y))

    if (x == 2 || y == 2) {
      "No"
    } else if (yes) {
      "Yes"
    } else {
      "No"
    }
  }
}

Measured memory_bytes: 54836
#python3
from collections import deque

class Edge:
    def __init__(self, to, d):
        self.to = to
        self.d = d

def main():
    n = int(input())
    g = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        g[a].append(Edge(b, i))
        g[b].append(Edge(a, i))

    dq = deque() 
    dq.append(0) 
    done = [0 for _ in range(n)]
    done[0] = 1
    ans = [0 for _ in range(n-1)]


    while len(dq):
        v = dq.pop()
        c = -1
        for i in range(len(g[v])):
            u = g[v][i].to
            ei = g[v][i].d
            if done[u]:
                c = ans[ei]
        k = 1
        for i in range(len(g[v])): 
            u = g[v][i].to
            ei = g[v][i].d
            if done[u]:
                continue 
            if k == c:
                k += 1
            ans[ei] = k
            k += 1
            dq.append(u)
            done[u] =  1
            

    mx = 0
    for i in range(len(g)):
        mx = max(mx, len(g[i]))

    print(mx)
    for i in ans:
        print(i)
main()

Measured memory_bytes: 60420
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    reverse(v.begin(), v.end());
    int idx = 0;
    int bnum = n - b;
    while(idx < n && bnum){
        int end = min(n, idx + a);
        while(bnum < end - idx - 1){
            end--;
        }
        sort(v.begin() + idx, v.begin() + end);
        bnum -= end - idx - 1;
        idx += a;
    }
    printd(bnum);
    if(bnum){
        cout << -1 << '\n';
        return 0;
    }
    vector<int> dp(n + 1, M);
    for(auto& e : v){
        *lower_bound(dp.begin(), dp.end(), e) = e;
    }
    if(find(dp.begin(), dp.end(), M) - dp.begin() != a){
        cout << -1 << '\n';
        return 0;
    }
    cout << v << '\n';
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> s(H);
	for (int i = 0; i < H; ++i) { cin >> s[i]; }

	vector<vector<int>> wc(H + 1, vector<int>(W + 1, 0));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			wc[i + 1][j + 1] = (s[i][j] == '1');
		}
	}
	for (int i = 0; i <= H; ++i) {
		for (int j = 0; j < W; ++j) { wc[i][j + 1] += wc[i][j]; }
	}
	for (int j = 0; j <= W; ++j) {
		for (int i = 0; i < H; ++i) { wc[i + 1][j] += wc[i][j]; }
	}

	int ans = 1e8;
	for (int b = 0; b < (1<<(H - 1)); ++b) {
		vector<int> h;
		h.push_back(0);
		int tmp = 0;
		for (int i = 0; i < H - 1; ++i) {
			if ((b>>i) & 1) {
				h.push_back(i + 1);
				++tmp;
			}
		}
		h.push_back(H);

		int l = 0;
		bool ok = true;
		for (int j = 1; j <= W; ++j) {
			if (!ok) { continue; }
			for (int i = 1; i < h.size(); ++i) {
				int h1 = h[i - 1], h2 = h[i];
				int k = wc[h2][j] - wc[h2][l] - wc[h1][j] + wc[h1][l];
				if (k > K) { ok = false; }
			}
			if (!ok) {
				ok = true;
				for (int i = 1; i < h.size(); ++i) {
					int h1 = h[i - 1], h2 = h[i];
					int k = wc[h2][j] - wc[h2][j - 1] - wc[h1][j] + wc[h1][j - 1];
					if (k > K) { ok = false; }
				}
				if (!ok) { break; }
				l = j - 1;
				++tmp;
			}
		}
		if (ok) { ans = min(ans, tmp); }
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int sum;
    int m;

    while(1){
    scanf("%d",&sum);
    if(sum == 0)
        break;
    REP(i,9){
        scanf("%d",&m);
        sum -= m;
    }
    printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 3208
def main():
    n, m = map(int, input().split())
    keys = [[None for j in range(2)] for i in range(m)]
    for i in range(m):
        a, b = map(int, input().split())
        keys[i][0] = a
        keys[i][1] = 0
        c = list(map(int, input().split()))
        for j in c:
            keys[i][1] += int(pow(2, j-1))
    dp = [10**9 for i in range(int(pow(2, n)))]
    dp[0] = 0
    for i in range(int(pow(2, n))):
        for j in range(m):
            if dp[i | keys[j][1]] > dp[i] + keys[j][0]:
                dp[i | keys[j][1]] = dp[i] + keys[j][0]
    if dp[int(pow(2, n)) - 1] == 10**9:
        print("-1")
    else:
        print(dp[int(pow(2, n)) - 1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX MAX000
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................

ull dfs(string& s, int& i) {
	int j;
	vector<int> v;
	if (s[i] != '[') {
		int v = stoi(&s[0] + i);
		//dump(i);
		//dump(v);
		while (s[i] != ']') i++;
		return v / 2 + v % 2;
	}
	while(s[i] == '[') {
		//dump(s.substr(i));
		i += 1;
		v.push_back(dfs(s, i));
		i += 1;
	}
	//cout << stoi(&s[0] + i) << endl;
	sort(ALL(v));
	int cnt = 0;
	rep(j, v.size() / 2 + 1) {
		cnt += v[j];
	}
	return cnt;
}
signed main(void)
{
	int i, j, k;
	int t;
	int loop;
	cin >> t;
	rep(loop, t) {
		string s;
		i = 0;
		cin >> s;
		cout << dfs(s, i) << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  long long int result=0;
  for(int i=0;i<s.size();i++){
  	if(s[i]!=t[i]){
		result++;    
    }
  }
    cout<<result;
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007

string str;
int d;
long long dp[10005][2][101];

long long solution(int n , int tight , int mo){

if(n==str.size()){
    return (mo==0) ? 1 : 0;
}
if(dp[n][tight][mo] != -1){
    return dp[n][tight][mo];
}

int en = tight ? (str[n]-'0') : 9;

long long ret = 0;

for(int i=0 ; i<=en ; i++){
    ret = (ret + solution(n+1 , tight&(en==i) , (mo+i)%d)%mod);
}

return dp[n][tight][mo] = ret;


}


int main(){

    cin>>str>>d;
    memset(dp , -1 , sizeof(dp));
    cout<<(solution(0 , 1 , 0)-1+mod)%mod<<endl;
    
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MAX_N = 2e5+7;

ll N;
vvl G(MAX_N);
vl cs(MAX_N), tree_size(MAX_N), color_cnts(MAX_N,0);
vl ans(MAX_N);

ll nc2(ll x) { return x*(x-1)/2; }

void calc_size(int v, int par = -1) {
    tree_size[v] = 1;
    for (auto to : G[v]) {
        if (to == par) continue;
        calc_size(to, v);
        tree_size[v] += tree_size[to];
    }
}
void dfs(int v, int par = -1) {
    ll prev_cnt = color_cnts[cs[v]];
    for (auto to : G[v]) {
        if (to == par) continue;
        ll prev = color_cnts[cs[v]];
        dfs(to, v);
        ll diff = color_cnts[cs[v]] - prev;
        ll cnt = tree_size[to] - diff;
        // cerr << v << "->" << to << ": " << cnt << endl;
        ans[cs[v]] -= nc2(cnt);
    }
    color_cnts[cs[v]] = prev_cnt + tree_size[v];
}

int main() {
    cin >> N;
    ans.assign(MAX_N, nc2(N));
    rep(i,N) cin >> cs[i+1], ans[cs[i+1]]++;
    rep(i,N-1) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    calc_size(1);
    dfs(1);
    rep(c,N) ans[c+1] -= nc2(N-color_cnts[c+1]);
    rep(i,N) cerr << ans[i+1] << endl;
    rep(i,N) cout << ans[i+1] << endl;
    return 0;
}


Measured memory_bytes: 39480
import numpy as np
n, k, q = map(int, input().split())

l=[]
for i in range(q):
    x = int(input())
    l.append(x)

p = np.array([k - q] * n)
pp = np.array([0] * n)

for i in range(q):
    index = l[i] - 1
    pp[index] += 1

xx = p + pp

for i in range(len(xx)):
    if xx[i] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 19172
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func modInv(a, mod int) int {
	b := mod
	u, v := 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		u -= t * v
		a, b = b, a
		u, v = v, u
	}
	u %= mod
	if u < 0 {
		u += mod
	}
	return u
}

// 二項係数のmodを求める
func modCom(n, k, mod int) int {
	ret := 1
	for i := n - k + 1; i <= n; i++ {
		ret = (ret * i) % mod
	}
	for i := 2; i <= k; i++ {
		ret = (ret * modInv(i, mod)) % mod
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	n, k := nextInt2()

	for i := 1; i <= k; i++ {
		// k個の青いボールをi個のグループに分ける
		blue := modCom(k-1, i-1, mod)
		// n-k個の赤いボールをi+1グループに分ける
		if n-k < i-1 {
			puts(0)
			continue
		}
		red := modCom(n-k+1, i, mod)

		puts((blue * red) % mod)
	}
}


Measured memory_bytes: 640
n,m,c = map(int,raw_input().split())
b = map(int,raw_input().split())
 
res = 0
for i in range(n):
    ai = map(int,raw_input().split())
    ab = [ai[j] * b[j] for j in range(m)]
    if sum(ab) +c > 0:
        res +=1
print res



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong a, b, c;
	cin >> a >> b >> c;

	cout << max(0ll, c - (a-b)) << endl;

	return 0;
}

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

int main(){
  int D;
  cin >> D;
  if(D == 25){
    cout << "Christmas" << endl;
  }
  else if(D == 24){
    cout << "Christmas Eve " << endl;
  }
  else if (D == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if (D == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c || b+c==a || c+a==b){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=1505;
int n,a[N][N];
int L[N][N],R[N][N],f[N][N];
ll ans;
char s[N];
int main(){
	scanf("%d",&n);
	For(i,1,n){
		scanf("%s",s+1);
		For(j,1,n) a[i][j]=(s[j]=='#'?0:s[j]-'0');
	}
	Rep(i,n,1)
		if (a[n][i]){
			L[i][n]=i;
			R[i][n]=(a[n][i+1]?R[i+1][n]:i);
			f[n][i]=f[n][i+1]+a[n][i];
			ans+=a[n][i]*f[n][i+1];
		}
	Rep(i,n-1,1) Rep(j,n,1) if (a[i][j]){
		if (!a[i+1][j]&&!a[i][j+1]){
			L[j][i]=R[j][i]=j;
			For(k,i+1,n) L[j][k]=n+1,R[j][k]=0;
		}
		else if (!a[i+1][j]){
			memcpy(L[j],L[j+1],4*(n+1));
			memcpy(R[j],R[j+1],4*(n+1));
			L[j][i]=j; R[j][i]=R[j+1][i];
			f[i][j]=f[i][j+1];
		}
		else if (!a[i][j+1]){
			L[j][i]=R[j][i]=j;
			f[i][j]=f[i+1][j];
		}
		else{
			f[i][j]=f[i+1][j]+f[i][j+1];
			L[j][i]=j; R[j][i]=R[j+1][i];
			int las=0;
			For(k,i+1,n){
				if (L[j+1][k]<=R[j][k]&&las<L[j+1][k])
					f[i][j]-=f[k][L[j+1][k]];
				las=R[j][k];
				R[j][k]=max(R[j][k],R[j+1][k]);
				L[j][k]=min(L[j][k],L[j+1][k]);
			}
		}
		ans+=a[i][j]*f[i][j];
		f[i][j]+=a[i][j];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

struct ITEM {
    int v, w;
    double x;

    bool operator>(const ITEM& right) const {
        return x > right.x;
    }
} item[1000];

int N, W;
int v[1000], w[1000];
int ans;
int ans2;

void dfs (int pos, int val, int sum, bool flag) {
    if (ans < val) {
        ans = val;
        ans2 = sum;
    }
    if (ans == val) {
        ans2 = min(ans2, sum);
    }
    if (pos == N) return;
    if (flag) {
        int _W = W-sum;
        double lim = val;
        for (int i = pos; i < N; i++) {
            if (_W >= item[i].w) {
                lim += item[i].v;
                _W -= item[i].w;
            } else {
                lim += _W * item[i].x;
                break;
            }
        }
        if (lim+EPS < ans) {
            return;
        }
    }
    if (sum+item[pos].w <= W) {
        dfs(pos+1, val+item[pos].v, sum+item[pos].w, false);
    }
    dfs(pos+1, val, sum, true);
}

int main() {
    int testcase = 1;
    while (cin >> W) {
        if (W == 0) break;
        ans = 0;
        cin >> N;
        rep(i,N) {
            char tmp;
            cin >> item[i].v >> tmp >> item[i].w;
            item[i].x = item[i].v / (double)item[i].w;
        }
        sort(item, item+N, greater<ITEM>());
        dfs(0, 0, 0, false);
        cout << "Case " << testcase << ":" << endl;
        cout << ans << endl;
        cout << ans2 << endl;
        testcase++;
    }
}




Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

bool solve(string s, int a, int b)
{
    if (s.length()!=a+b+1)
    {
        return false;
    }

    if (s[a]!='-')
    {
        return false;
    }
    for (int i=0;i<s.length();i++)
    {
        if (i==a)
        {
            continue;
        }
        if (s[i]-'0'<0||s[i]-'0'>9)
        {
            return false;
        }
    }

    return true;
}
int main()
{
    start();
    int a, b;
    cin>>a>>b;
    string s;
    cin>>s;
    if (solve(s, a, b))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (a == 0 && b == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << a * (n / (a + b)) + min(a, n % (a + b)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    ll N,K;
    string s;
    char L = 'L';
    char R = 'R';
    cin >> N >> K >> s;
   ll ans  = N;
    if(s[0] == L) ans += -1;
    if(s[s.size() -1] == R) ans += -1;
    REP(i, N-1){
        if(s[i] == R && s[i+1] == L) ans -= 2;
    }
    ans += 2*K;
    cout << min(N-1, ans);
 }




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>vec(n);
  rep(i,n)cin>>vec[i];
  sort(vec.begin(),vec.end(),greater<ll>());
  ll sum=0;
  rep(i,k)sum+=vec[i];
  cout<<sum<<endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int k,n,a[200007],maxl;
int main(){
	ios::sync_with_stdio(false);
	cin>>k>>n;
	for (int i=1; i<=n; i++){
		 cin>>a[i];
	}
	for (int i=1; i<n; i++) maxl=max(maxl,a[i+1]-a[i]);
	maxl=max(maxl,k+a[1]-a[n]);
	//cout<<maxl<<endl;
	cout<<k-maxl<<endl;
	return 0;
}

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

int main()
{
  int N;
  string S;
  
  cin >> N;
  cin >> S;
  
  for(int i=1;i<=S.size()-1;){
    if(S.at(i-1)==S.at(i)){
      S.erase(i, 1);
    }
    else{
      i++;
    }
    //cout << i << endl;
  }
  //cout << S << endl;
  cout << S.size() << endl;
  
  return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,b,a) for(i=b-1;i>=(ll)a;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
// const ll mod=1000000007;
const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
inline ll s(ll A,ll B,ll C,ll D){
  return (A/2+C/2+D/2)*2+B+(A&C&D&1)*3;
}
int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll A,B,C,D,ans;
  cin>>A>>B>>C>>C>>D;
  ans=s(A,B,C,D);
  if(A&&C&&D)chmax(ans,s(A-1,B,C-1,D-1)+3);
  print(ans);
}

Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		//Map<Integer,Integer> map = new TreeMap<Integer,Integer>()
		long ans = 0;
		for(int i=1;i<N+1;i++) {
			if(i%3==0||i%5==0) {
				continue;
			}
			ans = ans + i;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35776
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int a,b; 
int main()
{
    cin>>a>>b;
    int m,n,k;
    m=a+b;
    n=a-b;
    k=a*b;
    int z=-10001;
    z=max(z,m);
    z=max(z,n);
    z=max(z,k);
    cout<<z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

bool is_square(int n){
  int m=sqrt(n);
  return (n==m*m);
}
  
int main(){
  string s,t;cin>>s>>t;
  int n=stoi(s+t);
  if(is_square(n))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
from collections import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while-1<t[x]:x=t[x]
 return x
def u(L):
 x,y=map(r,L)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for l in q:u(l)
i=c=0;b=[];k=(n+~m)*2
for v in a:d[r(i)]+=v,;i+=1
print(k<1and'0'or(k>n)*'Impossible'or exec("for r,p in d.items():p.sort();c+=p.pop(0);b+=p;k-=1")or c+sum(sorted(b)[:k]))

Measured memory_bytes: 107000
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    int A[1010][1010];
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            int a; cin >> a;
            a--;
            A[i][j] = a;
        }
    }
    
    vector<int> cur(N);

    
    int cnt = 0;
    while(1){
        
        
        bool nopair = true;

        bool used[1010];
        for(int i=0; i<1010; i++)used[i] = false;

        for(int i=0; i<N; i++){
            if(cur[i]==N-1) continue;
            int aite = A[i][cur[i]];
            
            if(used[i] || used[aite]) continue;
            if(i==A[aite][cur[aite]]){
                cur[i]++;
                cur[aite]++;
                used[i] = true;
                used[aite] = true;
                nopair = false;
            }
        }
        
        
        if(nopair){
            cout << -1 << endl;
            return 0;
        }
        
        cnt++;
        
        bool allend = true;
        for(int i=0; i<N; i++){
            if(cur[i]!=N-1) allend = false;
        }
        
        
        if(allend){
            cout << cnt << endl;
            return 0;
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 4224
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

D.sort()
T.sort()
if N<M:
    print("NO")
    exit()

flag=True
cnt=0
count=0
for i in range(M):
    if cnt>=N:
        flag=False
        break
    chk=0
    while(D[cnt]!=T[i]):
        cnt+=1
        chk=1
        if cnt==N:
            flag=False
            break
    if cnt>=N:
        break
    if D[cnt]==T[i]:
        count+=1
    cnt+=1

if count==M:
    pass
else:
    flag=False

if flag:
    print("YES")
else:
    print("NO")

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

typedef long long ll;

struct state
{
    ll w,s,v;
    state(ll w, ll s, ll v) : w(w), s(s), v(v) {}
    state(){}
    bool operator < (const state &x ) const
    {
        return x.w + x.s > w + s;
    }
};

state v[10005];

const int maxm = 3e4 + 400;

ll dp[maxm];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n ; i++)
    {
        scanf("%lld %lld %lld",&v[i].w, &v[i].s, &v[i].v);
    }
    sort(v,v+n);

    for(int i = 0; i < n ; i++)
    {
        for(int j = v[i].s; j >= 0; j--)
        {
            int pos = j+v[i].w;
            if(pos < maxm)
                dp[pos] = max(dp[pos], dp[j] + v[i].v); 
        }
    }
    printf("%lld\n",*max_element(dp, dp + maxm));
    return 0; 
}

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

#define MAXN 105
#define MAXK 100010

using namespace std;

const int mod = 1e9 + 7;

int dp[MAXN][MAXK], sum[MAXN][MAXK];

int main() {

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

    int n, k;
    cin >> n >> k;

    int arr[n];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    
    for(int i = 0; i <= k; i++)
        if(i <= arr[0])
            dp[0][i] = 1;
        else
            dp[0][i] = 0;
    
    for(int i = 1; i < n; i++) {
        sum[i - 1][0] = dp[i - 1][0];
        for(int j = 1; j <= k; j++)
            sum[i - 1][j] = (sum[i - 1][j - 1] + dp[i - 1][j]) % mod;
        for(int j = 0; j <= k; j++) {
            dp[i][j] = sum[i - 1][j];
            if(j - arr[i] - 1 >= 0) {
                dp[i][j] -= sum[i - 1][j - arr[i] - 1];
                if(dp[i][j] < 0)
                    dp[i][j] += mod;
            }
        }
    }

    cout << dp[n - 1][k] << endl;
    return 0;
}


Measured memory_bytes: 80128
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A
// Graph II - Single Source Shortest Path II
// TODO: REVIEW

#define SUBMIT
//#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>
#include <queue>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

enum class color_type {
    white,
    gray,
    black
};

const int INF = INT_MAX >> 1;
const ui64 MAX_N = 100000;
vector<pair<int, int>> adj[MAX_N];
int n;

int dijkstra() {
    // (cost, node) pair
    priority_queue<pair<int, int>> pq;
    color_type color[MAX_N];
    int d[MAX_N];

    for (int i = 0; i < n; ++i) {
        d[i] = INF;
        color[i] = color_type::white;
    }

    d[0] = 0;
    color[0] = color_type::gray;
    pq.push(make_pair(0, 0));

    while (!pq.empty()) {
        auto f = pq.top();
        pq.pop();
        int u = f.second;
        color[u] = color_type::black;

        // 最小値を取り出してそれが最短でなければ無視
        if (d[u] < -f.first) continue;

        for (int j = 0; j < adj[u].size(); ++j) {
            int v = adj[u][j].first;
            if (color[v] == color_type::black) continue;

            if (adj[u][j].second + d[u] < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                pq.push(make_pair(-d[v], v));
                color[v] = color_type::gray;
            }
        }
    }

    for (int i = 0; i < n; ++i) cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
)";
    stringstream stream(program_input_str);
#endif
    stream >> n;
    int u, v, c, degree;
    for (int i = 0; i < n; ++i) {
        stream >> u >> degree;
        for (int d = 0; d < degree; ++d) {
            stream >> v >> c;
            adj[u].emplace_back(make_pair(v, c));
        }
    }

#ifdef DEBUG
    for (int y = 0; y < n; ++y) {
        for (int x = 0; x < n; ++x) {
            cout << weight[y][x] << " ";
        }
        cout << endl;
    }
#endif

    dijkstra();
    return 0;
}


Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,h,w,a,b,ans=0;
	cin>>n>>h>>w;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a>=h&&b>=w)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256