akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  ll n,k;
  cin>>n>>k;
  int a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  ll count1 = 0;
  ll count2 = 0;
  int mod = 1000000007;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n-i-1; j++){
      if(a[j] > a[n-i-1]){
        count1+=k*(k+1)/2%mod;
      }
    }
    for(int j = 0; j < i; j++){
      if(a[n-j-1]>a[n-i-1]){
        count2+=k*(k-1)/2%mod;
      }
    }
  }
  ll ans = (count1+count2)%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    ptr = 0
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))
    
    bc = sorted(bc, key=lambda x: x[1], reverse=True)
    

    for i in range(m):
        num = bc[i][0]
        is_next = True
        for j in range(num):
            if ptr < n and a[ptr] < bc[i][1]:
                a[ptr] = bc[i][1]
                ptr += 1
            else:
                is_next = False
                break
        
        if not is_next:
            break
    print(sum(a))

Measured memory_bytes: 23272
n,m = map(int,input().split())
c = [int(i) for i in input().split()]
dp = [[float("INF")]*(n+1) for _ in range(m+1)]

dp[0][0] = 0
for i in range(m):
    for yen in range(n+1):
        if yen - c[i] < 0: dp[i+1][yen] = dp[i][yen]
        else: dp[i+1][yen] = min(dp[i][yen],dp[i+1][yen-c[i]]+1)
print(dp[m][n])


Measured memory_bytes: 43732
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 998244353;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    ll kizyun = w[0] - 1;
    rep(i,N) w[i] -= kizyun;
    vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(N+1,vector<ll>(405)));
    rep(i,N){
        rep(j,N){
            rep(k,405){
                if(k-w[i] < 0) dp[i+1][j+1][k] = dp[i][j+1][k];
                else dp[i+1][j+1][k] = max(dp[i][j+1][k], dp[i][j][k-w[i]] + v[i]);
            }
        }
    }
    ll ans = 0;
    rep(j,N){
        rep(k,405){
            if((j+1)*kizyun + k <= W){
                ans = max(ans, dp[N][j+1][k]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 36224
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long test;cin>>test;while(test--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

vector<ll> v[100005];
ll vis[100005]={0};

void dfs(ll p){
    if(vis[p]) return;
    vis[p]=1;

    for(ll x:v[p]){
        if(vis[x]==0){
            dfs(x);
        }
    }
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_cin;


    ll n,m;

    cin>>n>>m;

    f(i,0,m){
        ll p,q;
        cin>>p>>q;
        p--;q--;
        v[q].pb(p);
        v[p].pb(q);
    }

    ll ans=0;
    dfs(0);
    f(i,0,n){
        if(vis[i]==0){
            ans++;
            dfs(i);
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 11080
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))

tmp = sum(np.abs(a))
if np.count_nonzero(a < 0)%2 == 0:
    print(tmp)
else:
    ind = np.argmin(np.abs(a))
    print(tmp-abs(a[ind])*2)


Measured memory_bytes: 23308
#include <iostream>
using namespace std;
long long N, Q, S, T, a[200009], p[200009], ret;
int main() {
	cin >> N >> Q >> S >> T;
	for (int i = 0; i <= N; i++) {
		cin >> a[i]; if (i == 0)continue;
		p[i] = a[i] - a[i - 1];
		if (p[i] >= 1)ret += -S*p[i]; else ret += -T*p[i];
	}
	for (int i = 1; i <= Q; i++) {
		long long L, R, X; cin >> L >> R >> X;
		long long A1 = 0; if (p[L] >= 1)A1 = -S*p[L]; else A1 = -T*p[L]; p[L] += X;
		long long A2 = 0; if (p[L] >= 1)A2 = -S*p[L]; else A2 = -T*p[L];
		ret += (A2 - A1);
		if (R != N) {
			long long B1 = 0; if (p[R + 1] >= 1)B1 = -S*p[R + 1]; else B1 = -T*p[R + 1]; p[R + 1] -= X;
			long long B2 = 0; if (p[R + 1] >= 1)B2 = -S*p[R + 1]; else B2 = -T*p[R + 1];
			ret += (B2 - B1);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 6240
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<LL>::iterator sit;
const int N = 4e3 + 10;
int st[N], top = 0;

bool qry(int a, int b) {
	cout <<'?'<<' '<<a - 1<<' '<<b - 1<<endl, cout.flush();
	static char s[2]; scanf("%s",s);
	return s[0] == 'Y';
}

char honest[N];

int main() {
	int a, b; scanf("%d%d",&a,&b);
	if (a <= b) cout <<"Impossible"<<endl, cout.flush();
	else {
		rep(i,1,a + b) {
			if (top && !qry(i, st[top - 1])) { top--; continue; }
			st[top++] = i;
		}
		rep(i,1,a + b) honest[i] = '0' + qry(st[0], i);
		cout <<'!'<<' '<<honest + 1<<endl;
	}
	return 0;
}


Measured memory_bytes: 848
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main(void){
	int N,M,A1=0,A2=0;
	char S[3];
	scanf("%d %d",&N,&M);
	vector<bool> P(N+1);
	vector<int> P2(N+1);
	for(int i=0;i<M;i++){
		int p;
		scanf("%d %s",&p,S);
		string s=S;
		if(P[p]) continue;
		if(s=="AC") P[p]=true,A1++,A2+=P2[p];
		else P2[p]++;
	}
	printf("%d %d\n",A1,A2);
	return 0;
}

Measured memory_bytes: 3472
import math

n,m = map(int, input().split())
s = input()
t = input()

if n == m:
    if s == t:
        print(n)
    else:
        print(-1)
    exit()

if m == 1:
    n,m = m,n
    s,t = t,s

if n == 1:
    if s[0] == t[0]:
        print(m)
    else:
        print(-1)
    exit()

lcm = n * m // math.gcd(n, m)

n1 = lcm//n
m1 = lcm//m

lcm2 = n1 * m1 // math.gcd(n1, m1)
stepn = lcm2//n1
stepm = lcm2//m1

for i in range(0,10**5):
    if stepn*i > n-1 or stepm*i > m-1:
        print(lcm)
        break
    if s[stepn*i] != t[stepm*i]:
        print(-1)
        exit()

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

int main() {

  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> correct(Q);
  for (int i = 0; i < Q; i++) cin >> correct.at(i);

  vector<int> vec(N, K);

  for (int i = 0; i < vec.size(); i++) {
    vec.at(i) -= Q;
  }

  for (int i = 0; i < correct.size(); i++) {
    vec.at(correct.at(i) - 1) += 1;
  }

  for (int i = 0; i < vec.size(); i++) {
    if (vec.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

}

Measured memory_bytes: 1408
N = int(input())

MAXA = 55555
P = []
X = [True]*(MAXA+1)
X[0] = X[1] = False
for i in range(MAXA+1):
    if X[i]:
        P.append(i)
        X[i::i] = [False]*(MAXA//i)
X = []
for p in P:
    if p%5==1:
        X.append(p)
print(*X[:N])

Measured memory_bytes: 3900
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let (n, k) = (io.read::<usize>(), io.read::<usize>());

    let mut n = n;
    let mut ans = 0;
    while n > 0 {
        n /= k;
        ans += 1;
    }
    io.writeln(ans);
}

static MOD: i64 = 1000000007;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
l=[]
while True:
  e = list(map(int,input().split()))
  if e==[0, 0]:
    break
  l.append(e)

i = 0
while i < len(l):
  j = 0
  while j < l[i][0]:
    ans = ""
    if j % 2 == 1:
      for k in range(l[i][1]):
        if k % 2 ==1:
          ans += "#"
        else:
          ans += "."
        k += 1
    else:
      for k in range(l[i][1]):
        if k % 2 ==1:
          ans += "."
        else:
          ans += "#"
        k += 1
    print(ans)
    j += 1
  i += 1
  print("")


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifndef _LOCAL          
    #endif // _LOCAL

    long long n;
    cin >> n;
    string s = "";
    while (n > 0) {
        --n;
        s += ((n % 26) + 'a');
        n /= 26;
    }

    reverse(s.begin(), s.end());
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    int N;
    cin >> N;
    vec<ll> A(N),S(N+1,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
        S[i+1] = S[i]+A[i];
    }   
    ll ans = 1e18;
    for(int i=0;i<N-1;i++){
        ll l = S[i+1],r = S[N]-S[i+1];
        ans = min(ans,abs(l-r));
    }
    cout << ans << endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

string solve(string a, string b){
    if(a.size() < b.size()) return "LESS";
    if(a.size() > b.size()) return "GREATER";
    int n = a.size();
    for(int i=0;i<n;i++){
        if(a[i] == b[i]) continue;
        if(a[i] < b[i]) return "LESS";
        if(a[i] > b[i]) return "GREATER";
    }
    return "EQUAL";
}

int main() {
    std::ios::sync_with_stdio(false);
    string a, b;cin >> a >> b;
    cout << solve(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long long int num;
    int ex;
    
    while(scanf("%lld", &num) != EOF) {
        ex = num % 39;
        if(ex == 0)
            printf("3C%d\n", 39);
        else if(ex > 9 && ex <= 38)
            printf("3C%d\n", ex);
        else if(ex >= 0 && ex < 10)
            printf("3C%02d\n", ex);
    }
    
    return(0);
}

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

bool include3(int);

bool include3(int x){
    for(x; x > 0; x /= 10){
        if(x % 10 == 3) return true;
    }
    
    return false;
}

int main(void){
    int n;
    cin >> n;
    
    int i;
    
    for(i = 1; i <=n; i++){
        if(!(i % 3) || include3(i)) cout << " " << i;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3036
a, b, c = map(int, input().split())

cnt = 0

while True:
    if a % 2 == 1:
        print(cnt)
        exit()
    if b % 2 == 1:
        print(cnt)
        exit()
    if c % 2 == 1:
        print(cnt)
        exit()
    if a == b and a == c:
        print(-1)
        exit()
    lis = []
    lis.append((b+c)/2)
    lis.append((a+c)/2)
    lis.append((a+b)/2)
    a, b, c = lis

    cnt += 1

Measured memory_bytes: 3064
/*
in the name of ALLAH
author: Sepehr_Noori
*/
#include <bits/stdc++.h>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef map<int,int> mpii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef double db;
typedef long double ld;
const int mod = 1e9+7;
////////////////////////



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    db h,a;
    cin>>h>>a;
    cout<<ceil(h/a)<<endl;;

    return 0;
}

Measured memory_bytes: 256
s = list(str(input()))
q = int(input())
w = [list(map(str,input().split())) for i in range(q)]

reverse = False
front_list = []
end_list = []

for data in w:
    if int(data[0]) == 1:
        reverse = not reverse
    else:
        if (int(data[1]) == 1 and not reverse) or (int(data[1]) == 2 and reverse):
            front_list.append(data[2])
        else:
            end_list.append(data[2])
if not reverse:
    front_list.reverse()
    print("".join(front_list + s + end_list))
else:
    end_list.reverse()
    s.reverse()
    print("".join(end_list + s + front_list))

Measured memory_bytes: 45976
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int X,a,money=0;
    cin>>X;
    a = X/500;
    money += 1000*a;
    a = X%500;
    a = a/5;
    money += a*5;
    cout<<money;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100010];
int main() {
    cin.tie(0); cin.sync_with_stdio(0);
    cin >> n;
    bool zero = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) zero = true;
    }
    if (zero) {
        long long ans = 0;
        for (int i = 0; i < n; i++) ans += abs(a[i]);
        cout << ans;
        return 0;
    }
    for (int i = 0; i + 1 < n; i++) {
        if (a[i] < 0) {
            a[i] *= -1;
            a[i + 1] *= -1;
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i];
    }
    long long cur = ans;
    for (int i = n - 1; i >= 1; i--) {
        a[i] *= -1;
        a[i - 1] *= -1;
        cur += 2ll * (a[i] + a[i - 1]);
        ans = max(ans, cur);
    }
    cout << ans;
}

Measured memory_bytes: 640
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a =[]
    for i in range(6):
        s = int(input())
        a.append(s)

    flag =0

    for i in range(0,5):
        for j in range(i,5):
            if a[j] -a[i] >a[5]:
                flag +=1

    if flag >0:
        print(":(")
    else:
        print("Yay!")



Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int A[3];
  for (int i=0; i<3; i++) cin >> A[i];
  sort(A,A+3);
  int ans = 0;
  for (int i=0; i<2; i++) {
    ans += A[i+1]-A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

char C[] = {'I', 'O', 'T', 'J', 'L', 'S', 'Z'};

LL func1(map<char, LL> mp) {
    LL ans = mp['O'];


    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;
    mp['I'] %= 2;
    mp['L'] %= 2;
    mp['J'] %= 2;



    return ans;
}
LL func2(map<char, LL> mp) {
    LL ans = mp['O'];

    if (mp['I'] > 0 && mp['L'] > 0 && mp['J'] > 0) {
        mp['I'] --;
        mp['J'] --;
        mp['L'] --;
        ans += 3;
    }
    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;
    mp['I'] %= 2;
    mp['L'] %= 2;
    mp['J'] %= 2;



    return ans;
}

int main(void) {
    map<char, LL> mp;
    REP(i, 7) {
        LL buf;
        scanf("%lld", &buf);
        mp[C[i]] = buf;
    }

    cout << max(func1(mp), func2(mp))<< endl;
}


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

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  int c = A % K;
  if(c == 0)cout << "OK" << endl;
  else{
    if(K-c+A > B)cout << "NG" << endl;
    else cout << "OK" << endl;
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)
    printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <string.h>

int N;

void f(char S[], int n) {
    int M, i;
    char s[15];
    if (n==N) printf("%s\n", S);
    else {
        for (i=0; i<n; i++) s[i]=S[i];
        s[i]=0;
        M=0;
        for (i=0; i<n; i++) {
            if (s[i]>M) M=s[i];
        }
        for (i='a'; i<=M+1; i++) {
            s[n]=i; s[n+1]=0;
            f(s, n+1);
        }
    }
}

int main(void) {
    scanf("%d", &N);
    f("a", 1);
    return 0;
}

Measured memory_bytes: 1408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class ARemainingTime {
public:
  static void solve(istream &cin, ostream &cout) {
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  ARemainingTime solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a.at(i);
    sum += a.at(i);
  }
  //cout << "sum:" << sum << endl;
  
  vector<ll> s(n-1);
  vector<ll> rest(n-1);
  ll mndif = 9009009009;
  rep(i,n-1){
    if( i == 0 ) s.at(i) = a.at(i);
    else s.at(i) = s.at(i-1) + a.at(i);
    
    rest.at(i) = sum - s.at(i);
    //cout << s.at(i) << " " << rest.at(i) << endl;
    mndif = min(mndif,abs(rest.at(i)-s.at(i)));
  }
 
  cout << mndif << endl;
  return 0;
}

Measured memory_bytes: 4992
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 400 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll dp[MAXN][MAXN];
ll a[MAXN];
ll sum[MAXN];
ll n;

ll memoize(int l, int r){
    if (l == r){
        return dp[l][r] = a[l];
    }
    if(dp[l][r] != INF){
        return dp[l][r];
    }
    for (int k = l;k < r;k++){
        dp[l][r] = min(dp[l][r], memoize(l, k) + memoize(k + 1, r) + sum[r] - sum[l - 1]);
    }
    return dp[l][r];
}

int main()
{
    fast_io;
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for (int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            dp[i][j] = INF;
        }
    }
    cout << memoize(1,n)-sum[n] << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int X,Y;
  cin>>X>>Y;
  cout<<max(0,400000-X*100000)+max(0,400000-Y*100000)-400000*min(X+Y-3,0);
return 0;}


Measured memory_bytes: 3608
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //StringBuilder bd = new StringBuilder();
        ArrayList<String> A = new ArrayList<String>();
        //int[] A = new int[26];
        //Arrays.fill(A, 0);
        //String str;

        String str = sc.nextLine();
        String newStr = new String();
        newStr = str.substring(0);
        int q = sc.nextInt();
        String dummy = sc.nextLine();
        for (int i=0; i<q; i++) {
            String command = sc.nextLine();
            String[] S = command.split(" ");
            switch (S[0]) {
                case "print": {
                    System.out.println(newStr.substring(Integer.valueOf(S[1]), Integer.valueOf(S[2])+1));
                    break;
                }
                case "reverse": {
                   newStr = reverse(newStr, Integer.valueOf(S[1]), Integer.valueOf(S[2]));
                   break;
                }
                case "replace": {
                    newStr = replace(newStr, S[3], Integer.valueOf(S[1]), Integer.valueOf(S[2]));
                    break;
                }
            }
        }

    }
    public static String reverse(String str1, int a, int b) {
        String newstr = new String();
        if (a > 0) newstr += str1.substring(0, a);
        for (int i=b; i>=a; i--) {
            newstr += str1.substring(i, i+1);
        }
        if (b < str1.length()-1) newstr += str1.substring(b+1);
        return newstr;
    }

    public static String replace(String str1, String str2, int a, int b) {
        String newstr = new String();
        if (a > 0) newstr += str1.substring(0, a);
        newstr += str2;
        if (b < str1.length()-1) newstr += str1.substring(b+1);
        return newstr;
    }
}


Measured memory_bytes: 59316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int last(int d,int i,vector<int> answer){
   
      int t=0;
    for(int k=1;k<=d;k++){
       
       if(i==answer[d-k]) break;
       t++;
    }
   return t;
}

int main(){
   int D;cin>>D;
   vector<int> dism;
   rep(i,26){
      int a;cin>>a;
      dism.push_back(a);
   }
   vector<vector<int>> point(D,vector<int>(26,0));
   rep(i,D){
      rep(j,26){
         int s;cin>>s;
         point[i][j]=s;
      }
   }
//    vector<int> answer;
//    rep(i,D){
//       int a;cin>>a;
//       answer.push_back(a-1);
//    }
   vector<int> answer(D,0);
   
   
   rep(i,D){
      int ma=0;
      int ch=0;
      rep(k,26){
         
         int ans=0;
         answer[i]=k;
      
      ans=ans+point[i][k];
      rep(j,26){
       ans=ans-(dism[j]*(last(i+1,j,answer)));
      }
      if(ans>ma)ch=k;
      ma=max(ma,ans);
      
      }
      answer[i]=ch;
   }
   rep(i,answer.size()){
      answer[i]++;
   }
   for(auto e:answer)cout<<e<<endl;
 //  rep(i,26){  cout<<last(1,i,answer);}
}

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

using namespace std;

int mp[1005000],dist[1005000];
int h,w,k;
int fk1,fk2,ffk1,ffk2;

int get(int x,int y)
{
	return (x - 1) * w + y;
}

int getx(int id)
{
	return (id - 1) / w + 1;
}

int gety(int id)
{
	return id % w == 0 ? w : id % w;
}

char str[1005000];

int main()
{
	scanf("%d%d%d",&h,&w,&k);
	scanf("%d%d%d%d",&fk1,&ffk1,&fk2,&ffk2);
	for(int i = 1;i <= h; ++ i)
	{
		scanf("%s",str + 1);
		for(int j = 1;j <= w; ++ j)
			mp[get(i,j)] = str[j] == '@' ? 0 : 1;
	}
	if(!mp[get(fk1,ffk1)] || !mp[get(fk2,ffk2)])
	{
		puts("-1\n");
		return 0;
	}
	memset(dist,-1,sizeof(dist));
	dist[get(fk1,ffk1)] = 0;
	queue<int> que; que.push(get(fk1,ffk1));
	while(!que.empty())
	{
		int u = que.front();
		int xx = getx(u),yy = gety(u);
		que.pop();
		bool fg1 = 1,fg2 = 1,fg3 = 1,fg4 = 1;
		int td = dist[get(xx,yy)] + 1;
		for(int i = 1;i <= k; ++ i)
		{
			if(xx + i <= h && fg1)
			{
				if(mp[get(xx + i,yy)] && (dist[get(xx + i,yy)] == -1 || dist[get(xx + i,yy)] >= td))
				{
					if(dist[get(xx + i,yy)] == -1)
						que.push(get(xx + i,yy));
					dist[get(xx + i,yy)] = td;
				}
				else fg1 = 0;
			}
			else fg1 = 0;
			if(xx - i > 0 && fg2)
			{
				if(mp[get(xx - i,yy)] && (dist[get(xx - i,yy)] == -1 || dist[get(xx - i,yy)] >= td))
				{
					if(dist[get(xx - i,yy)] == -1)
						que.push(get(xx - i,yy));
					dist[get(xx - i,yy)] = td;
				}
				else fg2 = 0;
			}
			else fg2 = 0;
			if(yy + i <= w && fg3)
			{
				if(mp[get(xx,yy + i)] && (dist[get(xx,yy + i)] == -1 || dist[get(xx,yy + i)] >= td))
				{
					if(dist[get(xx,yy + i)] == -1)
						que.push(get(xx,yy + i));
					dist[get(xx,yy + i)] = td;
				}
				else fg3 = 0;
			}
			else fg3 = 0;
			if(yy - i > 0 && fg4)
			{
				if(mp[get(xx,yy - i)] && (dist[get(xx,yy - i)] == -1 || dist[get(xx,yy - i)] >= td))
				{
					if(dist[get(xx,yy - i)] == -1)
						que.push(get(xx,yy - i));
					dist[get(xx,yy - i)] = dist[get(xx,yy)] + 1;
				}
				else fg4 = 0;
			}
			else fg4 = 0;
			if(!fg1 && !fg2 && !fg3 && !fg4) break;
		}
	}
	printf("%d\n",dist[get(fk2,ffk2)]);
}

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

int main() {
  string s;
  string S = "";
  cin >> s ;
  
  for(int i=0;i<s.size();i++){
    if(s.at(i) == '0'){
      S = S + '0';
    }
    
    else if(s.at(i) == '1'){
      S = S + '1';
    }
    
    else{
      
      if(S.size() != 0){
     	 S.pop_back();
      }
    }
  }
  
  cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,45){
        if(_%3!=2){
            rep(i,0,D){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
        else{
            per(i,D-1,0){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,a[200010],x,y,n2=1,ans[200010];
multiset <int> dat[800010];
vector <int> g[200010],v;

void upd(int k,int val)
{
	if(val>0) dat[k].insert(val);
	else dat[k].erase(dat[k].lower_bound(-val));
	while(k>0)
	{
		k=(k-1)/2;
		dat[k].clear();
		dat[k].insert(max((dat[k*2+1].empty() ? 0:(*dat[k*2+1].rbegin())),
		(dat[k*2+2].empty() ? 0:(*dat[k*2+2].rbegin()))));
	}
}

int query(int k,int lb,int ub,int tlb,int tub)
{
	if(ub<tlb||tub<lb) return 0;
	if(tlb<=lb&&ub<=tub) return dat[k].size()==0 ? 0:(*dat[k].rbegin());
	return max(query(k*2+1,lb,(lb+ub)/2,tlb,tub),query(k*2+2,(lb+ub)/2+1,ub,tlb,tub));
}

void dfs(int pos,int par,int mx)
{
	//cout<<pos<<' '<<a[pos]<<'p'<<endl;
	int val=query(0,0,n2-1,0,a[pos]-1)+1;
	//cout<<val<<'k'<<endl;
	ans[pos]=max(mx,val);
	upd(a[pos]+n2-1,val);
	rep(i,g[pos].size()) if(g[pos][i]!=par) dfs(g[pos][i],pos,ans[pos]);
	upd(a[pos]+n2-1,-val);
}

int main()
{
	cin>>n;
	repn(i,n)
	{
		scanf("%d",&a[i]);
		v.pb(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	while(n2<v.size()) n2*=2;
	repn(i,n) a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
	rep(i,n-1)
	{
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0,0);
	repn(i,n) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 78644
#ifdef ONLINE_JUDGE

#include "bits/stdc++.h"
using namespace std;

#define ui unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double

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

#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ld PI = 3.1415926535897932384626;
ll MOD = 1000000007;
const ld EPS = 1e-9;
const int N = 3e5 + 7;

inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ui setBits(ui v) { ui c; for(c = 0 ; v; ++c) v &= (v - 1); return c; }
inline bool isPowerOfTwo(ui v) { return (v && !(v & (v - 1))); }
ll power(ll base, ull exp, ll mod = MOD) { 
	ll res = 1; base %= mod; 
	while(exp) { 
		if(exp & 1) res = (res * base)%mod; 
		exp >>= 1; base = (base * base)%mod; 
	} 
	return res; 
}
ll modInv(ll a, ll mod = MOD) { 
	if(mod == 1) return 0; 
	ll x = 1, y = 0, m = mod; 
	while(a > 1) { 
		ll q = a/m, t = m; m = a%m; a = t; t = y; y = x - q * y; x = t; 
	} 
	if(x < 0) x += mod; 
	return x; 
}
inline ui iabs(int x) { ui y = x; return (y > 0) ? y : -y; }
inline ll add(ll a, ll b, ll mod = MOD) { ll res = (a%mod + b%mod)%mod; return res; }
inline ll sub(ll a, ll b, ll mod = MOD) { ll res = (a%mod - b%mod + mod)%mod; return res; }
inline ll mult(ll a, ll b, ll mod = MOD) { ll res = (a%mod * b%mod)%mod; return res; }
inline ll div(ll a, ll b, ll mod = MOD) { ll res = (a%mod * modInv(b, mod))%mod; return res; }

#else

#include "custom.h"
using namespace std;

#endif

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

bool solveUtil(vector<string> grid, int r, int c, int k, int nr, int nc) {
	int pos = 1;
	while(r) {
		if(r&1) {
			for(int i = 0 ; i < nc ; ++i) {
				grid[pos - 1][i] = 'R';
			}
		}
		++pos;
		r >>= 1;
	}
	pos = 1;
	while(c) {
		if(c&1) {
			for(int i = 0 ; i < nr ; ++i) {
				grid[i][pos - 1] = 'R';
			}
		}
		++pos;
		c >>= 1;
	}
	int cnt = 0;
	for(int i = 0 ; i < grid.size() ; ++i) {
		for(int j = 0 ;j < grid[i].size() ; ++j) {
			if(grid[i][j] == '#') {
				++cnt;
			}
		}
	}
	return (cnt == k);
}

void solve(vector<string>& grid, int& ans, int k, int nrows, int ncols) {
	int rlim = (1 << nrows), clim = (1 << ncols);
	for(int r = 0 ; r < rlim ; ++r) {
		for(int c = 0 ; c < clim ; ++c) {
			if(solveUtil(grid, r, c, k, nrows, ncols)) {
				++ans;
			}
		}
	}
}

int main() {
	speed;
	openf();
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> grid(H);
	for(int i = 0 ; i < H ; ++i) {
		cin >> grid[i];
	}	
	int ans = 0;
	solve(grid, ans, K, H, W);
	cout << ans << endl;
	return 0;
}  
  

Measured memory_bytes: 3636
def calc( s , k , n):

	bruh = {}
	for i  in range(1, k + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = input()

k = int(input())

n = len(s)
 
calc( s , k , n)

Measured memory_bytes: 10632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N;
    vector<int>A(N);
    vector<int>C(N,0);
    vector<int>B(0);
    for(int i=0;i<N;i++)cin >> A[i];
    for(int j=N-1;j>-1;j--){
        int l=j+1;
        int X=N/l;
        int Y=0;
        for(int i=X;i>1;i--)Y+=C[i*l-1];
        if(Y%2!=A[j]){
            B.push_back(j+1);
            C[j]=1;
            }
            }
    int Z=B.size();
    cout << Z << endl;
    for(int i=0;i<Z;i++){
        cout << B[i] << endl;
    }
}
    


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

using namespace std;


void solve() {
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    int sum = 0, cnt = 0;
    int len = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i-1]) {
            len++;
        } else {
            sum += len-1;
            len = 1;
            cnt++;
        }
    }
    sum += len-1;
    int res = sum + min(k*2, cnt);
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
    int x,y;
    cin >> x;
    cin >> y;
    int r[y];
    int i,j;
    for(i=0;i<y;i++){
        cin >> r[i];
    }
    if(y > 0) {
        int k = x;
        if(x < 50){
            k = 100 - x;
        }
        int return_flag;
        for(j=0;j<=k;j++){
            return_flag = 1;
            for(i=0;i<y;i++){
                if(r[i] == (x - j)){
                    return_flag = 0;
                }
            }
            if(return_flag == 1){
                cout << x - j << '\n';
                return 0;
            }
            return_flag = 1;
            for(i=0;i<y;i++){
                if(r[i] == (x + j)){
                    return_flag = 0;
                }
            }
            if(return_flag == 1){
                cout << x + j << '\n';
                return 0;
            }
        }
    }
    cout << x << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<((a+d-1)/d>=(c+b-1)/b ? "Yes" : "No")<<endl;
    
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	for(int i=1; i<=5; i++)
	{
		int _x;
		cin>>_x;
		if(_x==0)
		{
			cout<<i<<endl;
		}
	}
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};

int main(){
  ll a, b, c; cin >> a >> b >> c;
  ll ans = b + min(c, a+b+1);
  cout << ans << endl;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


void solve(){
	llint a,b,n;
	cin >> a >> b >> n;
	llint ans=0;
	if(b>n){
		double t=a*n;
		t/=b;
		ans=floor(t);
	}
	else{
		double t=a*(b-1);
		t/=b;
		ans=floor(t);
	}
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 3744
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (n, k) = get!(usize, usize);
    let mut xx = Vec::new();
    let mut yy = Vec::new();
    for _ in 0..n {
        let (x, y) = get!(i64, i64);
        xx.push(x);
        yy.push(y);
    }

    let mut a = i64::max_value();
    for t in 0..n {
        for b in 0..n {
            if yy[t] - yy[b] <= 0 { continue; }
            for l in 0..n {
                for r in 0..n {
                    if xx[r] - xx[l] <= 0 { continue; }
                    let mut kk = 0;
                    for i in 0..n {
                        if yy[b] <= yy[i] && yy[i] <= yy[t] && xx[l] <= xx[i] && xx[i] <= xx[r] {
                            kk += 1;
                        }
                    }
                    if kk == k {
                        a = cmp::min(a, (yy[t] - yy[b]) * (xx[r] - xx[l]));
                    }
                }
            }
        }
    }
    println!("{}", a);
}

Measured memory_bytes: 2148