akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, ans = 0, a, b, c;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &l[i]);
    }
    sort(l.begin(), l.end());

    for(int i = 0; i < n; i++){
        a = l[i];
        for(int j = i+1; j < n; j++){
            b = l[j];
            int lft = j+1, rgt = n-1, m;
            if(lft == rgt){
                if(l[lft] < a+b) ans++;
            }
            else if(l[rgt] < a+b) ans += rgt - j;
            else if(a+b <= l[lft]) ans += 0;
            else{
                m = (lft+rgt+1)/2;
                while(!(l[m-1] < a+b && a+b <= l[m])){
                    if(a+b <= l[m]){
                        rgt = m-1;
                    }
                    else{
                        lft = m;
                    }
                    m = (lft+rgt+1)/2;
                }
                ans += m-1 - j;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while 1:
    try:
        n=[0]*10
        n[0]=float(input())
        for i in range(1,10):
            if i%2==1:
                n[i]=n[i-1]*2
            elif i%2==0:
                n[i]=n[i-1]/3
        print(f'{sum(n):.8f}')
    except:break


Measured memory_bytes: 5592
if __name__ == '__main__':
    n = int(input())
    a = []
    b = list(map(int, input().split()))
    a.append(b[0])
    for i in range(n-1):
        a.append(b[i])
    for j in range(n-1):
        if b[j] != max(a[j], a[j+1]):
            a[j] = min(a[j], a[j+1])
            a[j+1] = min(a[j], a[j+1])
    print(sum(a))

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

int main(void) {
  int N, sum=0;
  cin >> N;
  int d[N];
  
  for(int i=0; i<N; i++) cin >> d[i];
  
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      sum += d[i]*d[j];
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A - 2 * B, 0) << endl;
    return 0;
}


Measured memory_bytes: 764
# coding: utf-8
# Your code here!
def main():
    tmp = input()
    a = int(tmp[0])
    b = int(tmp[1])
    c = int(tmp[2])
    d = int(tmp[3])
    
    for i in range(2 ** 3):
        opt = []
        for j in range(3):
            if (i >> j) & 1:
                opt.append("+")
            else:
                opt.append("-")
        ans = int(tmp[0])
        for j, x in enumerate(tmp[1:]):
            if opt[j] == "+":
                ans += int(x)
            else:
                ans -= int(x)
        if ans == 7:
            print(tmp[0] + opt[0] + tmp[1] + opt[1] + tmp[2] + opt[2] + tmp[3] + "=7")
            break
    
main()

Measured memory_bytes: 9208
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N+1];
		for( int i=1; i<=N; i++ ){
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		int count = 1;
		long[] a = new long[2];
		int[] b = new int[2];
		int c = 0;
		for( int i=N; i>=2; i-- ){
			if( A[i]==A[i-1] ){
				count++;
			}
			if( A[i]==A[i-1] && A[i]!=A[i-2] ){
				a[c] = A[i];
				b[c] = count;
				count = 1;
				c++;
			}
			if( c==2 ){
				break;
			}
		}
		long ans = 0;      
		if( b[0]>=4 ){
			ans = a[0]*a[0];
		}else if( c==2 ){
			ans = a[0]*a[1];
		}else{
			ans = 0;
		}     
		System.out.println(ans);
	}
}


Measured memory_bytes: 57268
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e18;

ll cmb(ll a, ll b){
    ll ret = 1;
    if(b > a){
        switch(a, b);
    }
    if(b > a/2){
        b = a-b;
//        cout << "!" << endl;
    }
//    cout << a << "C" << b;
    for(int i = 0; i < b; i++){
        ret *= a--;
        ret /= (i+1);
    }
//    for(int i = 1; i <= b; i++){
//        ret /= i;
//    }
//    cout << "=" << ret << endl;
    
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    map<ll, int> mp;
    vector<TP> d;

    REP(i, N){
        cin >> v[i];
        mp[v[i]]++;
    }
    sort(v.begin(), v.end(), greater<>());
    
    for(int z = A; z <= B; z++){
        ll max = 0;
        ll subans = 1;
        map<ll, int> cnt;
        REP(i, z){
            cnt[v[i]]++;
            max += v[i];
        }
        for(auto x: cnt){
//            cout << key << ":" << mp[key] << "->" << val << endl;
            subans *= cmb(mp[x.first], x.second);
        }
        d.push_back(make_tuple(subans, z, max));
    }
    
    long double m = 0;
    ll mnum = 0;
    for(int i = 0; i < d.size(); i++){
        ll sum, nums, cnt;
        tie(sum, nums, cnt) = d[i];
        long double ave = (long double)cnt/(long double)nums;
        if(ave > m){
            m = ave;
            mnum = sum;
//            cout << sum << ","<<endl;
        }else if(ave == m){
            mnum += sum;
//            cout << sum << ","<<endl;
        }
        //   cout << sum << ","  << ave << endl;
    }
    printf("%0.10Lf\n", m);
    printf("%lld\n", mnum);
    
    
    return 0;
}


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

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

    if(a+b==c || b+c==a || c+a==b)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

#define repi(i, s, n) for (long long i {s}, i##_len{n}; i < i##_len; ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) std::begin(x), std::end(x)

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
namespace xmaho
{
inline namespace integer
{
template<typename C>
constexpr auto ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type;
template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept;
}
}
using namespace xmaho;

int main()
{
  const auto a {get_value<int>()};
  const auto b {get_value<int>()};
  const auto small {min(a, b)};
  rep(i, max(a, b))
    cout << small;
  cout << '\n';
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}

template<typename C>
constexpr auto xmaho::integer::ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
{ return c.size(); }

template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t xmaho::integer::ssize(const T (&)[N]) noexcept
{ return N; }


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(i64, N, K);

    vector<i64> cnt(K);
    for (i64 a = 1; a <= N; ++a) {
        cnt[a % K] += 1;
    }

    dump(cnt);

    i64 ans = 0;
    rep(a, 0, K) {
        const i64 b = (K - a) % K;
        const i64 c = (K - a) % K;
        dump(a, b, c);
        if ((b + c) % K == 0) {
            ans += cnt[a] * cnt[b] * cnt[c];
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int d , n;
	while(1){
		cin >> d;
		if (cin.eof())
			break;
		n=600/d;
		int s=0;
		for (int i=1; i<=n; i++){
			s += d*(i-1)*d*(i-1)*d;
		}
		cout << s << endl;
	}


	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var rank = new(int num, int rank) [n];
            var ranks = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            for (var i = 0; i < n; i++)
            {
                rank[i] = (i + 1, ranks[i]);
            }
            Console.WriteLine(string.Join(" ", rank.OrderBy(tpl => tpl.rank).Select(tpl => tpl.num)));
        }
    }
}

Measured memory_bytes: 42024
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll N, W, w[110], v[110], l[110], O, dp[510][510][510], ans = 0;
int main() {
	cin >> N >> W;
	REP(i, N) {
		cin >> w[i] >> v[i];
		if (i == 0) O = w[0];
		w[i] -= O;
	}
	l[0] = W;
	REP(i, 100)l[i + 1] = l[i] - O;
	REP(i, N) {
		REP(j, i + 1) {
			REP(k, 500) {
				if (k + w[i] <= l[j + 1]) {
					dp[i + 1][j + 1][k + w[i]] = max(dp[i + 1][j + 1][k + w[i]], dp[i][j][k] + v[i]);
				}
				dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}
	REP(i, 110) {
		REP(j, 500) {
			ans = max(ans, dp[N][i][j]);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 203008
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print (l[int(input())-1])


Measured memory_bytes: 2940
#include<stdio.h>
int main(void){

	int n,x,t;

	scanf("%d	%d	%d",&n,&x,&t);

	if(n%x!=0)
		printf("%d",(n/x+1)*t);
	else
		printf("%d",(n/x)*t);

	return 0;
}

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

int main(){
    double A, B;
    int ans;
    std::cin >> A >> B;

    if(A >= B){
        ans = 1;
    }else{
        ans = (int)round(ceil((B - A)/(A-1))) + 1;
    }

    if(B == 1){
        ans = 0;
    }

    std::cout << ans;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    stack <char> st;
    for(int i = 0; i < sz(s); ++i){
        char c = s[i];
        if(c == '0' || c == '1'){
            st.push(c);
        }else if(!st.empty()){
            st.pop();
        }
    }
    string ans = "";
    while(!st.empty()){
        ans = st.top() + ans;
        st.pop();        
    }
    cout << ans;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
a = []
index = []
for i in range(H):
    array = list(input())
    if list(set(array)) != ['.']:
        a.append(array)

h = len(a)
w = len(a[0])
for i in range(w):
    judge = False
    for j in range(h):
        if a[j][i] == '#':
            judge = True
    
    if not judge:
        index.append(i)

cnt = 0
for i in index:
    for j in range(h):
        del a[j][i-cnt]
    cnt += 1
for i in a:
    print(''.join(i))
    


Measured memory_bytes: 3188
#include<iostream> 
#include<cstdio> 
using namespace std;
int main(){
    int a,b;
    cin >>a>>b;
    int d = a / b;
    int r = a % b;
    double f = (double)a / b;
    printf("%d %d %.6lf",d,r,f);
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main(){
  int a,i,j,k;
  string s,t;
  map<char,char> u,v;
  bool b=false;
  cin >> s >> t;
  for(i=0;i<s.size();i++){
    if(u[t[i]]=='\0')u[t[i]]=s[i];//t->s 初登場
    else if(u[t[i]]!=s[i])b=true;//二回目以降で違うのが入ってる

    if(v[s[i]]=='\0')v[s[i]]=t[i];//s->t 初登場
    else if(v[s[i]]!=t[i])b = true;//二回目以降違うのがはいってる
  }
  if(b)cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	ll a, b;
	cin >> a >> b;
	if ((a + b) % 2) cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=105;
const ll INF=1LL<<55;

int main(){
  int X,A,B,C,D;cin>>X>>A>>B>>C>>D;
  cout<<min((X+A-1)/A*B,(X+C-1)/C*D)<<endl;
}



Measured memory_bytes: 3108
fn solve(aa: &[i64]) -> Vec<i64> {
    let s = aa.iter().fold(0, |sum, i| sum + i);

    let x1 = s - 2 * {
        let mut acc = 0;
        for (i, &a) in aa.iter().enumerate() {
            if i % 2 == 0 {
                continue;
            }
            acc += a;
        }
        acc
    };

    let mut ans = Vec::new();

    aa.iter().fold(x1, |x, a| {
        ans.push(x);
        (a - x / 2) * 2
    });

    ans
}

#[test]
fn solve_test() {
    assert_eq!(solve(&vec![2, 2, 4]), vec![4, 0, 4]);
    assert_eq!(solve(&vec![3, 8, 7, 5, 5]), vec![2, 4, 12, 2, 8]);
    assert_eq!(
        solve(&vec![1000000000, 1000000000, 0]),
        vec![0, 2000000000, 0]
    );
    assert_eq!(solve(&vec![150, 600, 550]), vec![100, 200, 1000]);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let _n = parse_line!(usize);
    let aa = parse_vec!(i64);

    println!(
        "{}",
        solve(&aa)
            .iter()
            .map(|i| i.to_string())
            .collect::<Vec<String>>()
            .join(" ")
    );
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

int counts[200005];

long sizes[55];
long meats[55];

long eat(long n, long x) {
  if (x <= 0) {
    return 0;
  }
  if (x >= sizes[n]) {
    return meats[n];
  }
  if (n == 0) {
    return 1;
  }
  x--;
  long e1 = eat(n-1, x);
  x -= sizes[n-1];
  if (x >= 1) {
    x--;
    long e2 = eat(n-1, x);
    return e1+e2+1;
  } else {
    return e1;
  }
}

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

  long n, x;
  cin >> n >> x;

  sizes[0] = 1;
  meats[0] = 1;

  rep(i, n) {
    sizes[i+1] = sizes[i]*2+3;
    meats[i+1] = meats[i]*2+1;
  }

  cout << eat(n, x) << endl;
}


Measured memory_bytes: 256
S = gets.strip

(0..S.size-2).each do |i|
    if S[i]==S[i+1]
        puts "#{i+1} #{i+2}"
        exit
    end
end

(0..S.size-3).each do |i|
    if S[i]==S[i+2]
        puts "#{i+1} #{i+3}"
        exit
    end
end

puts "-1 -1"


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

int main(){
  int a,b,c,i,kotae=0;
  cin>>a>>b;
  for(i=0;i<a;i++){
    cin>>c;
    if(c>=b){
      kotae++;
    }
  }
  cout<<kotae;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int main() {
    int N;
    while (cin >> N) {
        vector<int> a(N+1);
        for (int i = 1; i <= N; ++i) cin >> a[i];


        vector<long long> res(N+1);
        for (int i = N; i >= 1; --i) {
            long long p = 0;
            for (int k = i*2; k <= N; k += i) p += res[k];
            p %= 2;
            if (a[i] == p) res[i] = 0;
            else res[i] = 1;
        }

        vector<long long> ans;
        for (int i = 1; i <= N; ++i) {
            if (res[i] == 1) ans.push_back(i);
        }
        cout << ans.size() << endl;
        for (auto r : ans) cout << r << " ";
        cout << endl;
    }
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using namespace boost::multiprecision;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
signed main(){
    int cnt=0,ans=0;
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s[i]!='A'&&s[i]!='G'&&s[i]!='C'&&s[i]!='T'){
            ans=max(ans,cnt);
            cnt=0;
        }
        else cnt++;
    }
    ans=max(ans,cnt);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;

public class AtCoderA
{
    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        string s = Console.ReadLine();

        string answer = "";
        for (int i = 0; i < n; i++)
        {
            string str = s.Substring(i, 1);
            if (i + 1 == k)
            {
                if ("A".Equals(str))
                {
                    answer += "a";
                }
                else if ("B".Equals(str))
                {
                    answer += "b";
                }
                else if ("C".Equals(str))
                {
                    answer += "c";
                }
            }
            else
            {
                answer += str;
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cmath>

using namespace std;
typedef unsigned long long ll;
ll n,a;
ll solve(int m){
	long double x = pow(n,(double)(1/(double)m));
	ll b = x,res = 1,i;
	for(i=0;i<m;i++) res *= b;
	ll ret = b*m + a*(m-1);
	while(res<n){
		ret++;
		res /= b;
		res *= (b + 1);
	}
	return ret;
}

int main(){
	ll i,ans = 100000000000000,ans2 = 100000000000000000;
	cin >> n >> a;
	for(i=1;i<50;i++){
		ans = min(ans,solve(i));
		if(solve(i)>ans) break;
	}
	for(i=50;i>=1;i--){
		ans2 = min(ans2,solve(i));
		if(solve(i)>ans2) break;
	}
	cout << max(ans2,ans) << endl;
}

Measured memory_bytes: 256
<?php
$s = str_split(trim(fgets(STDIN)));
$n = count($s);
$res = [];
for ($i = 0; $i < $n; $i++) {
    $res[$i] = 0;
}
for ($i = 0; $i < $n; $i++) {
    if ($i < $n - 1 && $s[$i] === 'R' && $s[$i + 1] === 'L') {
        $x = $i;
    }
    if ($s[$i] === 'L') {
        if (($i - $x) % 2 === 0) {
            $res[$x]++;
        } else {
            $res[$x + 1]++;
        }
    }
}
for ($i =  $n - 1; $i >= 0; $i--) {
    if ($i > 0 && $s[$i] === 'L' && $s[$i - 1] === 'R') {
        $x = $i;
    }
    if ($s[$i] === 'R') {
        if (($x - $i) % 2 === 0) {
            $res[$x]++;
        } else {
            $res[$x - 1]++;
        }
    }
}
echo implode(' ', $res).PHP_EOL;

Measured memory_bytes: 15992
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
class team
{
public:
	int id,b,acc,pen;
	team(int i = 0,int b = 0,int a = 0, int p = 0):
	id(i),b(b),acc(a),pen(p){}
	bool operator < (const team &t)const {
		if(acc==t.acc){
			if(pen==t.pen){
				return id < t.id;
			}else return pen < t.pen;
		}else return acc > t.acc;
	}
};
int n;
team T[1010];
int main(){
	while(cin>>n,n){
		for(int i =0;i < n;i++){
			cin>>T[i].id>>T[i].b>>T[i].acc>>T[i].pen;
		}
		sort(T,T + n);
		int select = 0;
		int bel_sele[100] ={0};
		for(int i =0;i < n;i++){
			int id = T[i].id;
			int belong = T[i].b;
			if(select < 10){
				if(bel_sele[belong] < 3){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}else if(select < 20){
				if(bel_sele[belong] < 2){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}else if(select < 26){
				if(bel_sele[belong]==0){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1180
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, KS, P):

    ans = 0
    for s in product((0, 1), repeat=N):
        for j, ks in enumerate(KS):
            k = ks[0]
            c = 0
            for i in range(1, k+1):
                c += s[ks[i]-1]
            if c % 2 != P[j]:
                break
        else:
            ans += 1
    return ans


def main():
    N, M = read_int_n()
    KS = [read_int_n() for _ in range(M)]
    P = read_int_n()
    print(slv(N, M, KS, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6724
S = [c for c in input()]

atgc = ['A', 'T', 'G', 'C']

max_count = 0
for i in range(len(S)):
    count = 0
    for j in range(i, len(S)):
        if S[j] not in atgc:
            break
        count += 1
        
    if count > max_count:
        max_count = count
        
print(max_count)
        

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

vector<int> v[N];
void solve() {
    int n,m;
    cin>>n>>m;
    vector<int> h(n+1);
    REP(i,1,n) {
        cin>>h[i];
    }
    int x,y;
    REP(i,1,m) {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    int ans = 0;
    REP(i,1,n) {
        ans++;
        for(auto it:v[i]) {
            if(h[it]>=h[i]) {
                ans--;
                break;
            }
        }
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

typedef long long ll;
ll N,D,c = 0;
int X[100][100];
double sum = 0;

int main(){
  cin >> N >> D;
  rep(i,N) rep(j,D) cin >> X[i][j];
  rep(i,N-1){
    for(int j = i+1; j < N; ++j){
      sum = 0;
      rep(k,D) sum += pow(X[i][k]-X[j][k],2);
      sum = sqrt(sum);
      if(floor(sum) == ceil(sum)) c++;
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
using namespace std;
int divisorCnt(int);


int main()
{
	int n,cnt=0;
	cin >> n;
	for (int i = 1; i <= n; i+=2) {
		if(divisorCnt(i)==8)cnt++;
	}
	cout << cnt << endl;
}

int divisorCnt(int t) {
	vector<int>divisorNum;
	for (int i = 1; i <= t; i++) {
		if (t % i == 0) {
			if(count(divisorNum.begin(),divisorNum.end(),t/i) == 0)divisorNum.push_back(t/i);
		}
	}
	return divisorNum.size();
}


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

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	ll a,b; cin >> a >> b;
	if(a>b)
		swap(a,b);
	if((b-a)&1){
		ll cur1=a+(b-a-1)/2;
		ll curn=(n-b+1)+(b-a-1)/2;
		cout << min(cur1,curn) << endl;
	}
	else{
		cout << (b-a)/2 << endl;
	}
	return 0;
}

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

int main(){
  int c[3][3]={},a[3],b[3];
  for(int i=0;i<3;++i)
    for(int j=0;j<3;++j)
        cin>>c[i][j];

  for(int k=0;k<=100;++k){
    a[0]=k;
    b[0]=c[0][0]-k;
    b[1]=c[0][1]-k;
    b[2]=c[0][2]-k;
    a[1]=c[1][0]-b[0];
    a[2]=c[2][0]-b[0];
    bool ans=true;
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            if(a[i]+b[j]!=c[i][j])ans=false;
        }
    }
    if(ans){
        cout <<"Yes" << endl;
        return 0;
    }
  }
  cout <<"No" << endl;
  return 0;
}


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

int main(){
	int h,w;
	char point;

	cin >>h >>w;
	string array[h];
	for(int i=0;i<h;i++)cin >>array[i];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(array[i][j]!='#'){
				point='0';
				if(i>0)if(array[i-1][j]=='#')point++;
				if(i<h-1)if(array[i+1][j]=='#')point++;
				if(j>0)if(array[i][j-1]=='#')point++;
				if(j<w-1)if(array[i][j+1]=='#')point++;
				if(i>0&&j>0)if(array[i-1][j-1]=='#')point++;
				if(i>0&&j<w-1)if(array[i-1][j+1]=='#')point++;
				if(i<h-1&&j>0)if(array[i+1][j-1]=='#')point++;
				if(i<h-1&&j<w-1)if(array[i+1][j+1]=='#')point++;
				array[i][j]=point;
			}
		}
	}
	for(int i=0;i<h;i++)cout<<array[i]<<endl;
	return 0;

}

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

using namespace std;
typedef long long ll;

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main() {
    int N;
    cin >> N;
    double sum = 0;
    int X[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        sum = sum + X[i];
    }

    double ans = 0;
    double mean = round(sum / N);

    for (int i = 0; i < N; i++) {
        ans = ans + pow(X[i] - mean, 2.0);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int a[3];
	int tmp;
	int i,j;
	for (i = 0; i < 3; i++){
		std::cin >> a[i];
	}
	for (i = 0; i < 2; i++){
		for (j = i; j < 3; j++){
			if (a[i] > a[j]){
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	std::cout << a[0] << " " << a[1] << " " << a[2] << '\n';

}

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

using namespace std;

#define io freopen("test.txt", "r", stdin);
#define fast ios_base::sync_with_stdio(0);cin.tie(0);


#define ull unsigned long long int
#define lli long long int
#define li long int
#define ld long double

#define cout(x) cout<<x<<" "
#define coutn(x) cout<<x<<endl
#define newline cout<<endl

#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define ar array

#define pii pair<int,int>
#define pll pair<lli,lli>
#define pps pair<pair<int,int>, string>

const int MOD=1000000007;
const lli INF=1e18;
const int MX=100001;
const int N=1000000;


void solve(){

    string s,t;
    cin>>s>>t;

    int n=s.size(), m=t.size();

    vector<vector<int>>v(m+1,vector<int>(n+1,0));

    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(s[j-1]==t[i-1]){
                v[i][j]=1+v[i-1][j-1];
            }else{
                v[i][j]=max(v[i-1][j],v[i][j-1]);
            }
        }
    }

    int i=m,j=n;
    string a;
    while(i>0 && j>0){
        if(s[j-1]==t[i-1]){
            a=s[j-1]+a;
            i--;
            j--;
        }else{
            if(v[i-1][j]>v[i][j-1]){
                i--;
            }else{
                j--;
            }
        }
    }

    cout<<a<<"\n";
    // cout<<v[m][n]<<"\n";

}


int main(){
    fast
    // #ifndef godzqa
    //     io
    // #endif

    lli t;
    // cin>>t;
    t=1;

    while(t--){
        solve();
    }
    
    return 0;
}


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

const int M = 1e3;
int m, n, cost[M], boxes[M], memo[M][4096], big = 5e8;

int solve(int i, int mask) {
    if (i == m) {
        if ((mask ^ ((1 << n) - 1)) == 0)
            return 0;
        return big;
    }
    int &r = memo[i][mask];
    if (r == -1)
        r = min(solve(i + 1, mask), cost[i] + solve(i + 1, mask | boxes[i]));
    return r;
}

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

    memset(memo, -1, sizeof memo);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int b;
        cin >> cost[i] >> b;
        while (b--) {
            int bit;
            cin >> bit;
            bit--;
            boxes[i] |= (1 << bit);
        }
    }
    int ans = solve(0, 0);
    if (ans >= big)
        ans = -1;
    cout << ans << "\n";
}
/*

1, n
m keys
cost, boxes that it can unlock

costs 7,
unlock, 1, 4, 8

boxes
1, 2, 3, 4, 5, 6, 7, 8, 9, 10


*/

Measured memory_bytes: 19700
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll A, B, M;
ll a[100005];
ll b[100005];

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

  cin >> A >> B >> M;
  ll ma = INF, mb = INF;
  REP(i, A) cin >> a[i], ma = min(ma, a[i]);
  REP(i, B) cin >> b[i], mb = min(mb, b[i]);

  ll ans = ma + mb;

  REP(i, M) {
    ll x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    ans = min(ans, (a[x] + b[y] - c));
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{
	int h, w, k;
	cin >> h >> w >> k;
	V<string> m(h);
	RBF(mi, m) {
		cin >> mi;
	}

	int ans = INF;
	for (unsigned b = 0; b < (1u << (h-1)); b++) {
		bitset<10> bit(b);
		bool able = true;

		int yoko = 0;
		REP(i, h) {
			if (bit[i]) yoko++;
		}

		VV<int> m2(yoko + 1, V<int>(w, 0));

		REP(j, w) {
			auto m2i = m2.begin();
			int white = 0;
			REP(i, h) {
				white += m[i][j] - '0';
				if (white > k) {
					able = false;
					break;
				}
				if (bit[i]) {
					(*m2i)[j] = white;
					m2i++;
					white = 0;
				}
			}
			(*m2i)[j] = white;
			if (!able) break;
		}
		if (!able) continue;

		int tmp = yoko;
		V<int> whites(yoko + 1, 0);
		REP(j, w) {
			REP(i, yoko + 1) {
				if (whites[i] + m2[i][j] > k) {
					tmp++;
					whites = V<int>(yoko + 1, 0);
					REP(i2, yoko + 1) {
						whites[i2] += m2[i2][j];
					}
					break;
				}
				whites[i] += m2[i][j];
			}
		}

		ans = min(ans, tmp);
	}

	col(ans);
	return 0;
}


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

int main() { 
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> cnt(3);
  vector<set<int>> st(3);
  map<char, int> id;
  id['R'] = 0;
  id['G'] = 1;
  id['B'] = 2;
  for (int i = 0; i < n; i++) {
    cnt[id[s[i]]].emplace_back(i);
    st[id[s[i]]].insert(i);
  }
  ll res = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) continue;
      int k = id[s[i]] + id[s[j]];
      k = 3 ^ k;
      int itr = lower_bound(cnt[k].begin(), cnt[k].end(), j + 1) - cnt[k].begin();
      if (itr == cnt[k].size()) continue;
      int add = cnt[k].size() - itr;
      int x = j - i + j;
      if (st[k].count(x)) add--;
      res += add;
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3804
#include <cstdio>

void printFrame( int h, int w );

int main( void )
{
    while ( true )
    {
        int h, w;
        scanf( "%d %d", &h, &w );
        if ( ( h == 0 ) && ( w == 0 ) ) break;
        printFrame( h, w );
    }
    return 0;
}

void printFrame( int h, int w )
{
    for ( int j = 0; j < w; j++ )   {   printf("#");    }
    printf("\n");
    
    for ( int i = 1; i < ( h - 1 ); i++ )
    {
        printf("#");
        for ( int j = 1; j < ( w - 1 ); j++ )   {   printf(".");    }
        printf("#\n");
    }

    for ( int j = 0; j < w; j++ )   {   printf("#");    }
    printf("\n");

    printf("\n");
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>

using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>=(0);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<P>> city(N+1);
    vector<int> ans1(M),ans2(M);

    rep(i,M){
        int a,b;
        cin >> a >> b;
        city[a].push_back({b,i});
    }

    rep(i,N+1){
        if(city[i].size() < 1) continue;
        sort(all(city[i]));
    }

    rep(i,N+1){
        rep(j,city[i].size()){
            P c = city[i][j];
            ans1[c.second] = i;
            ans2[c.second] = j+1;
        }
    }

    rep(i,M){
        cout << setfill('0') << right << setw(6) << ans1[i];
        cout << setfill('0') << right << setw(6) << ans2[i] << endl;
    }

}

Measured memory_bytes: 7808
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#define N 2000
int solve(int, int,int, int []);

int main() {
	int n, q, A[N] = { 0 }, M[N] = { 0 }, i;
	char str[2][4] = { "no","yes" };
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++) scanf("%d", &M[i]);
	for (i = 0; i < q; i++) printf("%s\n", str[solve(0, M[i], n, A)]);
	return 0;
}

int solve(int i, int m,int n,int A[]){
	int res;
	if (m == 0) return 1;
	if (i >= n) return 0;
	res = solve(i + 1, m,n,A) || solve(i + 1, m - A[i],n,A);
	return res;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    int r=0,l=0;
    int[] a=new int[s.length()];
    for(int i=0;i<s.length();i++) {
    	if(s.substring(i, i+1).equals("R"))r++;
    	else {
    		a[i]=r;
    		r=0;
    	}
    }
    for(int i=s.length();i>=1;i--) {
    	if(s.substring(i-1, i).equals("L"))l++;
    	else {
    		a[i-1]=l;
    		l=0;
    	}
    }
    for(int i=0;i<s.length()-1;i++) {
    	if(s.substring(i, i+2).equals("RL")) {
    		int buff=a[i]+a[i+1];
    		if(buff%2==0) {
    			a[i]=buff/2;
    			a[i+1]=buff/2;
    		}else {
    			if((Math.max(a[i], a[i+1])-1)%2==0) {
    	   			if(a[i]>a[i+1]) {
        				a[i]=buff/2;
        				a[i+1]=buff/2+1;
        			}else {
        				a[i]=buff/2+1;
        				a[i+1]=buff/2;
        			}
    			}else {
      	   			if(a[i]>a[i+1]) {
        				a[i]=buff/2+1;
        				a[i+1]=buff/2;
        			}else {
        				a[i]=buff/2;
        				a[i+1]=buff/2+1;
        			}
    			}
    		}
    	}
    }
    for(int i=0;i<s.length();i++) {
    	System.out.print(a[i]+" ");
    }
  }
}


Measured memory_bytes: 50152
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int mo = 1000000007;

LL pwr(LL a, LL b){
	LL res = 1;
	for (; b; b >>= 1, (a *= a) %= mo)
		if (b & 1) (res *= a) %= mo;
	return res;
}

const int N = 100005;
int n, ai[N], cnt[N], A, B;
LL fac[N], ifac[N];

LL C(int a, int b){
	if (a < b) return 0;
	return fac[a] * ifac[b] % mo * ifac[a - b] % mo;
}

int main(){
	// freopen("d.in", "r", stdin);
	cin >> n;
	REP(i, 1, n + 1){
		cin >> ai[i];
		++cnt[ai[i]];
	}
	REP(i, 1, n + 1) if (cnt[ai[i]] == 2){
		// cerr << i << endl;
		if (A) B = i;
		else A = i;
	}
	fac[0] = ifac[0] = 1;
	REP(i, 1, n + 1) fac[i] = fac[i - 1] * i % mo;
	ifac[n + 1] = pwr(fac[n + 1], mo - 2);
	PER(i, n, 1) ifac[i] = ifac[i + 1] * (i + 1) % mo;
	// REP(i, 1, n) assert(fac[i] * ifac[i] % mo == 1);
	
	cout << n << endl;
	REP(i, 2, n + 1){
		LL ans = C(n + 1, i) - C((n + 1 - (B - A + 1)), i - 1);
		ans = (ans % mo + mo) % mo;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main ()
{
    int a[1010],i,min1,min2;
    for(i=0;i<4;i++)
        scanf("%d",&a[i]);
    min1=a[0]>a[1]?a[1]:a[0];
    min2=a[2]>a[3]?a[3]:a[2];
    printf("%d\n",min1+min2);
    return 0;
} 

Measured memory_bytes: 256