akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll p[25];
int main(void) {
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int first = 0;
    int second = 0;
    int third = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i] <= a) {
            first++;
        }
        if (p[i] >= a + 1 && p[i] <= b) {
            second++;
        }
        if (p[i] >= b + 1) {
            third++;
        }
    }
    cout << min({ first,second,third }) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#define int long long
using namespace std;

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

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

signed main(){
	int a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f,a){
		int x = 1,y = 1,z = 1,pos;
		pos = a % b;
		while(pos != 1){
			pos = pos * a % b;
			x++;
		}
		pos = c % d;
		while(pos != 1){
			pos = pos * c % d;
			y++;
		}
		pos = e % f;
		while(pos != 1){
			pos = pos * e % f;
			z++;
		}
		cout << lcm(x,lcm(y,z)) << endl;
	}
	return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>

int min(int* arr, int size)
{
    int vmin = INT_MAX;
    for (int i = 0; i < size; i++)
        if (arr[i] < vmin)
            vmin = arr[i];
    return vmin;
}

int max(int* arr, int size)
{
    int vmax = INT_MIN;
    for (int i = 0; i < size; i++)
        if (arr[i] > vmax)
            vmax = arr[i];
    return vmax;
}

long int sum(int* arr, int size)
{
    long int s = 0;
    for (int i = 0; i < size; i++)
        s += arr[i];
    return s;
}
int main()
{
    int n;
    std::cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
        std::cin >> arr[i];
    
    std::cout << min(arr, n) << ' ';
    std::cout << max(arr, n) << ' ';
    std::cout << sum(arr, n) << std::endl;
    return 0;
}



Measured memory_bytes: 3152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        int ans = 0;
        String[] arr = new String[2];
        
        if(N < 1 || N > 1000)
            System.exit(1);
        
        
        else{
            for(int i = 0; i < N; i++){
                arr = sc.nextLine().split(" ");
                if(Integer.parseInt(arr[0]) > Integer.parseInt(arr[1])){
                    System.exit(1);
                }
                else{
                    ans += Integer.parseInt(arr[1]) - Integer.parseInt(arr[0]) + 1;
                }
            }
        }
            
        System.out.println(ans);
    }
}

Measured memory_bytes: 25032
import java.util.*;

public class Main {
  public static void main(String[] args){
      
    Scanner sc = new Scanner(System.in);    

    int N = sc.nextInt();
                 
    long[] t = new long[N];
    long[] a = new long[N];
    
    for(int i = 0;i < N;i++){
        t[i] = sc.nextLong();
        a[i] = sc.nextLong();
    }

    long ct = t[0];
    long ca = a[0];
    
    for(int i = 1;i < N;i++){
        long kt = ct/t[i] + (ct%t[i] > 0 ?1 :0);
        long ka = ca/a[i] + (ca%a[i] > 0 ?1 :0);
        long k = Math.max(kt,ka);
        ct = k*t[i];
        ca = k*a[i];
    }
    
    System.out.println(ct + ca);    
      
  }  
}


Measured memory_bytes: 22996
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 200000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int w[6]={200,300,500,1000,1200,1500};
int price[6]={380,550,850,1520,1870,2244};
int main()
{
	int dp[6000];
	for(int i=0;i<6000;i++)
	{
		dp[i]=INF;
	}
	dp[0]=0;
	for(int k=0;k<6;k++)
	{
		for(int i=0;i+w[k]<=5000;i++)
		{
			dp[i+w[k]]=min(dp[i+w[k]],dp[i]+price[k]);
		}
	}
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))

Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    if(A==B) cout<<"Draw"<<endl;
    else if(A==1) cout<<"Alice"<<endl;
    else if(B==1) cout<<"Bob"<<endl;
    else cout<<(A>B?"Alice":"Bob")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

template <unsigned T>
bool nextBitset(bitset<T> &bs, int digit)
{
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

int solve(int u, vector<int>& unit, vector<bitset<20> > condition)
{
    int n = unit.size();

    int a = 1;
    int b = n;
    while(a < b){
        int c = (a + b) / 2;
        bitset<20> bs((1<<c)-1);
        bool ok = false;
        do{
            int tmp = 0;
            bitset<20> bs1;
            for(int j=0; j<n; ++j){
                if(bs[j]){
                    tmp += unit[j];
                    bs1 |= condition[j];
                }
            }
            if(tmp < u || (~bs & bs1).any())
                continue;
            b = c;
            ok = true;
            break;
        }while(nextBitset(bs, n));

        if(!ok)
            a = c + 1;
    }

    return a;
}

int main()
{
    for(;;){
        int n, u;
        cin >> n >> u;
        if(n == 0)
            return 0;
        
        vector<int> unit(n);
        vector<bitset<20> > condition(n);
        for(int i=0; i<n; ++i){
            cin >> unit[i];
            int k;
            cin >> k;
            for(int j=0; j<k; ++j){
                int tmp;
                cin >> tmp;
                condition[i][tmp] = true;
            }
        }

        cout << solve(u, unit, condition) << endl;
    }
}

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

int main(){
    string s;
  	cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 10000005;

int d[10000005];

void sieve() {
    for (int i = 1; i < N; i++) {
        for (int j = i; j < N; j += i) {
            d[j]++;
        }
    }
}

signed main(){
    IOS;
    sieve();
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 10000000; i < 10000005; i++)
        dbg(d[i])
    for (int i = 1; i <= n; i++) {
        ans += i * d[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81740
n=int(input())
a=list(map(int,input().split()))
mina=min(a)
maxa=max(a)
if mina == maxa:
    if 2*maxa <= n or maxa == n-1:
        print('Yes')
    else:
        print('No')
elif maxa - mina == 1:
    cntmin = a.count(mina)
    if maxa - cntmin <= 0:
        print('No')
    elif n + cntmin >= 2 * maxa:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int rnum = 0;
  rep(i, n) if (s[i] == 'R') rnum++;
  int lrnum = 0;
  rep(i, rnum) if (s[i] == 'R') lrnum++;
  cout << rnum - lrnum << endl;
  return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#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(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	string S;
	int dp[128];

	Fill(dp, -100);

	cin >> S;
	rep(i,S.size()){
		if( i - dp[ S[i] ] <= 2 ){
			cout << (dp[ S[i] ] + 1) << " " << (i + 1) << endl;
			return 0;
		}
		dp[ S[i] ] = i;
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}


Measured memory_bytes: 512
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
import core.checkedint;
import core.bitop;

void main()
{
	int a, b;
	readln.chomp.split.tie(a, b);
	int ite = 0;
	for (int i = 1; i <= 999; ++i) {
		if (b - a == i && ite - a > 0) {
			debug verbose(i, ite);
			writeln = ite - a;
			break;
		}
		ite += i;
	}
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int A, B, C, K ;
    cin >> A >> B >> C >> K;

    int maximum = max ( max(A,B), C ) ;
    
    int power = 2 ;
    for(int x = 1; x < K; x++) { power *= 2 ; }
    
    int result = A + B + C - maximum + maximum * power ;
    cout << result << endl ;

    return 0;
}

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

using namespace std;

constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7;

int tc, n, m;
array<int, MAXN> a;

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	cout << (n ^ 1) << endl;
    return 0;
}

Measured memory_bytes: 3592
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let r = iter.next().unwrap().parse::<usize>().unwrap();
    let c = iter.next().unwrap().parse::<usize>().unwrap();
    println!("{} {}", r * c, r * 2 + c * 2);
}


Measured memory_bytes: 5036
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool c1 = true, c2 = true;
    if (n % 100 >= 13 || n % 100 == 0) {
        c2 = false;
    }
    if (n / 100 >= 13 || n / 100 == 0) {
        c1 = false;
    }
    if (c1 && c2) {
        cout << "AMBIGUOUS" << endl;
    } else if(!c1 && c2) {
        cout << "YYMM" << endl;
    } else if (c1 && !c2) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i;
        ArrayList <Integer> num = new ArrayList<Integer>();
        num.add(1);
        num.add(2);
        num.add(3);

        for (i=0;i<=num.size()-1;i++) {
            int x = sc.nextInt();
           num.removeIf(n -> (n == x));
            int y = sc.nextInt();
            num.removeIf(n -> (n == y));
            System.out.println(num.get(0));
        }
    }
}

Measured memory_bytes: 28364
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] X = new int[N];
    double t = 0;
    for (int i = 0; i < N; i++) {
      X[i] = sc.nextInt();
      t += X[i]; 
    }
    int ave = (int)Math.round(t/N);
    int n = 0;    
    for (int i = 0; i < N; i++) {
      n += Math.pow(ave-X[i],2); 
    }
    System.out.println(n);
  }
}

Measured memory_bytes: 21844
# 二通りのやり方で解いてみよう。
# Aそれぞれに対してBを二分探索→M(累積和構成) + NlogM
# Aを昇順、Bを降順に動かす→O(N+M) このコードはこっち★

n, m, k = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

time_sum = sum(bb)

a_idx = 0
b_idx = m-1
ans = 0

# 最初はA無し、B全部からスタート
book_num = m
while True:
    if time_sum > k:

        if b_idx < 0:
            break
        time_sum -= bb[b_idx]
        b_idx -= 1
        book_num -= 1
    else:
        # 実行可能な読み方
        ans = max(ans, book_num)
        
        if a_idx > n-1:
            break
        time_sum += aa[a_idx]
        a_idx += 1
        book_num += 1

print(ans)


Measured memory_bytes: 41128
import bisect

N = int(input())
P = sorted(enumerate(map(int, input().split())), key=lambda x: x[1])[::-1]
used = [-1, P[0][0], N]
ans = 0
for i, p in P[1:]:
    idx = bisect.bisect_left(used, i)
    d = 0
    if idx != 1:
        d += (used[idx] - i) * (used[idx - 1] - used[idx - 2])
    if idx != len(used) - 1:
        d += (i-used[idx - 1]) * (used[idx + 1] - used[idx])
    ans += p * d
    used.insert(idx, i)
print(ans)


Measured memory_bytes: 91268
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%2!=b%2)
    {
        cout<<"IMPOSSIBLE\n";
    }

    else
    {
        cout<<(a+b)/2<<endl;
    }
    exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef array<ll,2> pll;
const ll NMAX=1005,MOD=1e9+7;
ll dp[NMAX][NMAX];
char b[NMAX][NMAX];

int main()
{
    ll n,m;
    cin>>n>>m;
    dp[0][1]=1;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cin>>b[i][j];
            if(b[i][j]=='.')
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 12384
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//#define int long long
const int MAX_H = 35;
const int MAX_W = 35;
const int INF = 1e9 + 10;

int W, H;
bool v[MAX_H][MAX_W][4];
int my[] = {-1, 0, 1, 0};
int mx[] = {0, 1, 0, -1};

class C{
  public:
    int y, x, c;
    C(int _y, int _x, int _c){ y = _y; x = _x; c = _c; };
    C(){}
};

int main() {
  while(cin >>W >>H && H){
    REP(i, MAX_H) REP(j, MAX_W) REP(k, 4) v[i][j][k] = true;
    REP(i, H) v[i][0][3] = v[i][W - 1][1] = false;
    REP(i, W) v[0][i][0] = v[H - 1][i][2] = false;
    string s;
    getline(cin, s);
    REP(z, 2 * H - 1){
      getline(cin, s);
      if(z % 2){
        for(int i = 0; i < (int)(s.length()); i += 2){
          if(s[i] == '1'){
            v[z / 2][i / 2][2] = false;
            v[(z + 1) / 2][i / 2][0] = false;
          }
        }
      } else{
        for(int i = 1; i < (int)(s.length()); i += 2){
          if(s[i] == '1'){
            v[z / 2][i / 2][1] = false;
            v[z / 2][(i + 1) / 2][3] = false;
          }
        }
      }
    }
    //debug
    //cout <<"-------" <<endl;
    //REP(i, H){
    //  REP(j, W){
    //    cout <<i <<", " <<j <<" | ";
    //    REP(k, 4) cout <<v[i][j][k] <<" ";
    //    cout <<endl;
    //  }
    //}

    queue<C> open;
    open.push(C(0, 0, 1));
    int closed[MAX_H][MAX_W];
    REP(i, MAX_H) REP(j, MAX_W) closed[i][j] = INF;
    while(!open.empty()){
      C now = open.front(); open.pop();
      int y = now.y, x = now.x, c = now.c;
      if(closed[y][x] <= c) continue;
      closed[y][x] = c;
      REP(i, 4) if(v[y][x][i]) open.push(C(y + my[i], x + mx[i], c + 1));
    }
    cout <<(closed[H - 1][W - 1] == INF ? 0 : closed[H - 1][W - 1]) <<endl;
  }
  return 0;
}

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

const int maxn = 3003;
int a[maxn];
#define left LEFT
#define right RIGHT
ll left[maxn];
ll right[maxn];

int main()
{
    ll n,k;
    while(cin>>n>>k){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        memset(left, 0, sizeof(left));
        memset(right, 0, sizeof(right));
        ll ans = 0;
        ll mod = 1e9+7;
        for(int i=0;i<n;i++){
            for(int j=0;j<i;j++){
                if(a[j] > a[i]){
                    right[j]++;
                }
            }
            for(int j=i+1;j<n;j++){
                if(a[j] > a[i]){
                    left[j]++;
                }
            }
        }
        for(int i=0;i<n;i++){
            ll temp = (k*(k-1LL)/2LL % mod) * (left[i] % mod) % mod;
            temp = (temp + ((k+1LL)*k/2LL%mod)*right[i]%mod + mod) % mod;
            ans = (ans + temp + mod) % mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#define pb push_back
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = 1; i <= n; ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define rng(x) x.begin(),x.end()
#define sz(x) int((x).size())
using namespace std;
typedef vector<int> vi;

const int MX = 305;
const int INF = 1001001001;

int n, s, sx;
int a[MX], b[MX], c[MX], d[MX];
int dp[MX][MX];

int main() {
  scanf("%d%d%d",&n,&s,&sx);
  rep(i,n) {
    scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
  }
  int m = MX-2;
  rep(i,m)rep(j,m) dp[i][j] = INF;
  rep(i,m) dp[i][0] = 0;
  rep(i,n)drep(j,s+1)drep(k,m) {
    if (j+a[i] <= s) mins(dp[j+a[i]][k], dp[j][k]-b[i]);
    if (k+d[i] <= m) mins(dp[j][k+d[i]], dp[j][k]+c[i]);
  }
  int ans = 0;
  rep(j,m) {
    if (dp[s][j] <= sx) ans = j;
  }
  cout<<ans<<endl;
  return 0;
}

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

const ll MAX = 50;

ll comb[MAX + 1][MAX + 1];

ll calc_comb(ll n, ll r){
  if(comb[n][r] != 0) return comb[n][r];
  ll ret = -1;
  if(n == r) ret = 1;
  else if(r == 0) ret = 1;
  else if(r == 1) ret = n;
  if(ret != -1) {
    comb[n][r] = ret; return ret;
  }
  
  ret = calc_comb(n-1, r-1) + calc_comb(n-1, r);
  comb[n][r] = ret; return ret;
}

int main(){
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> val(N);
  for(ll i = 0; i < N; i++){
    cin >> val[i];
  }
  sort(val.begin(), val.end(), greater<ll>());
  
  double ans = 0.0;
  ll pat = 0LL;
  if(*val.begin() == *(val.begin()+A-1)){
    cout << fixed << setprecision(10) << (double)val[0] << endl;
    ll fin = A-1;
    while(val[fin] == val[0] && fin < N){
      fin++;
    }
    ll lim = min(fin, B);
    for(ll i = A; i <= lim; i++){
      pat += calc_comb(fin, i);
    }
    cout << pat << endl;
  }else{
    ll tmp = 0;
    for(ll i = 0; i < A; i++){
      tmp += val[i];
    }
    ans = (double)tmp / (double)A;
    cout << fixed << setprecision(10) << ans << endl;
    
    ll fst = A-1, scd = A-1, vmin = val[A-1];
    while(val[fst-1] == vmin){
      fst--;
    }
    while(val[scd] == vmin && scd < N){
      scd++;
    }
    pat = calc_comb(scd - fst, A - fst);
    cout << pat << endl;
  }
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
        System.out.println(distance);
    }
}


Measured memory_bytes: 28160
S = input()
for i in range(1, len(S)):
    if (len(S) - i) % 2 == 0:
        tmp = S[:len(S)-i]
        left = tmp[:len(tmp)//2]
        right = tmp[len(tmp)//2:]
        if left == right:
            print(len(S) - i)
            exit()
print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

    if (a+b-1 >= c) cout << b+c << endl;
    else cout << b+min(a+b+1, c) << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,A,B;
int main(){
  cin>>N>>A>>B;
  prin(min(N*A,B));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll A, B, Q;
    cin>>A>>B>>Q;
    vector<ll> S(A), T(B);
    rep(i, A){
        cin>>S[i];
    }
    rep(i, B){
        cin>>T[i];
    }
    rep(i, Q){
        ll X;
        cin>>X;
        auto itrS=lower_bound(ALL(S), X);
        auto itrT=lower_bound(ALL(T), X);
        ll D, DD, C, CC;
        if(*itrS==X){
            D=X;
            DD=X;
        }
        else if(itrS==S.begin()){
            D=-1*INF;
            DD=S[0];
        }
        else if(itrS==S.end()){
            D=S[A-1];
            DD=INF;
        }
        else{
            DD=*itrS;
            itrS--;
            D=*itrS;
        }
        if(*itrT==X){
            C=X;
            CC=X;
        }
        else if(itrT==T.begin()){
            C=-1*INF;
            CC=T[0];
        }
        else if(itrT==T.end()){
            C=T[B-1];
            CC=INF;
        }
        else{
            CC=*itrT;
            itrT--;
            C=*itrT;
        }
      	//cout<<D<<" "<<C<<" "<<" "<<CC<<" "<<DD<<endl;
        vector<ll> W(6);
        W[0]=(CC+X-2*D);
      	W[1]=(2*CC-X-D);
        W[2]=(DD+X-2*C);
      	W[3]=(2*DD-X-C);
        W[4]=X-min(C, D);
        W[5]=max(CC, DD)-X;
        sort(ALL(W));
        cout<<W[0]<<endl;
        
        
    }

}
     

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

int main()
{
  int s;

  cin >> s;
  
  int h = s / 3600;
  s %= 3600;
  
  int m = s / 60;
  s %= 60;

  cout << h << ":" << m << ":" << s << endl;

  return 0;

}

Measured memory_bytes: 3088
#include <stdio.h>

int main()
{
    int n,q,l[100000],r[100000],i,j,ac_count,ac[100000] = {0};
    char s[100001];

    scanf("%d %d %s",&n,&q,s);
    for (i = 0; i < q; i++)scanf("%d %d",&l[i],&r[i]);

    ac_count = 0;
    ac[0] = 0;
    for (i = 0; i < n - 1; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'C')
        {
            ac[i + 1] = ac[i] + 1;
        }
        else
        {
            ac[i + 1] = ac[i];
        }
    }

    for (i = 0; i < q; i++)
    {
        printf("%d\n",ac[r[i] - 1] - ac[l[i] - 1]);
    }
    
}

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

 
int main() {
  int K, S, ans=0;
  cin >> K >> S;
  REP(i,K+1) {
    REP(j,K+1) {
      int x = i, y = j;
      int z = S - x - y;
      if(z >= 0 && z <= K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val N = nextInt()
    val X = listOfInt()
    var ans = Int.MAX_VALUE
    for (av in -100 .. 100) {
        var s = 0
        for (x in X) s += (av - x) * (av - x)
        if (ans > s) ans = s
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



Measured memory_bytes: 37904
using namespace std;
#include<bits/stdc++.h>
#define debug(x) clog<<#x<<" = "<<x<<'\n'
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define sz(c) ((int)c.size())
#define all(c) (c).begin(),(c).end()
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define fn "C"  /// ___FILE_NAME_HERE___
#define rep(c,it) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define __rep(c,it) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();it++)

template <class T,class U>
void maximize(T &x,U y)
{
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y)
{
    if(x > y)x=y;
}
template <class T>
T Abs(T x)
{
    return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x)
{
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD)
{
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD)
{
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD)
{
    return (ll)x*y%MOD;
}
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

const ll inf=1e18;
const int N=1e5+5;
int a[N];
ll s[N];
int n;
ll ans=inf;

ll calc(int val)
{
    fill(s+1,s+1+n,0);
    s[1]=val;
    s[0]=(a[1] < 0 ? 1 : -1);
    ll ret=0;
    for(int i=2;i<=n;++i)
    {
        s[i]=s[i-1] + 1ll*a[i];
        if(s[i] * s[i-1] >= 0)
        {
            if(s[i] < 0)ret+=Abs(s[i])+1,s[i]=1;
            else if(s[i] > 0)ret+=s[i] + 1,s[i]=-1;
            else
            {
                ret++;
                if(s[i-1] < 0)s[i]=1;
                else s[i]=-1;
            }
        }
    }
    return ret;
}

void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    if(!a[1])minimize(ans,min(calc(-1) + 1,calc(1)+1));
    else
    {
//        clog<<calc(a[1]);
        minimize(ans,min(calc(a[1]),min(calc(1) + Abs(1-a[1]),calc(-1) + Abs(-1-a[1]))));
    }
    printf("%lld\n",ans);
}}

int main(void)
{
    task::solve();
}


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

char s[330000];
int n;
int res = 1000000000;

int main(){
  cin >> n >> s;
  int e2 = 0, w2 = 0; //現在のリーダーより東側にいる人で、東と西を向いている人数
  rep(i, n){
    if(s[i] == 'E') e2++;
    else w2++;
  }
  //cout << e2 <<" "<< w2 <<endl;
  
  int e1 = 0, w1 = 0;//---西側にいる人で---
  rep(i, n){
    if(s[i] == 'E'){
      e2--; 
      int change = e2 + w1;
      res = min(res, change);
      e1++;
    }else{
      w2--;
      int change = e2 + w1;
      res = min(res, change);
      w1++;
    }
  }
  cout << res << endl;
}

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

int main(){

    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;

    map<char, int> rank;
    int pass = 0;

    for (int i=0; i<n; i++){
        char temp;
        temp = s.at(i);
        rank[temp]++;

        if ((temp == 'a') && (pass < a+b)){
            cout << "Yes" << endl;
            pass++;
        }
        else if ((temp == 'b') && (pass < a+b) && (rank[temp] <= b)){
            cout << "Yes" << endl;
            pass++;
        }
        else cout << "No" << endl;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 896
n = gets.to_i
a = gets.split.map(&:to_i)

breaks = 0
target = 1

a.each.with_index do |num, i|
  if i - breaks + 1 == num && num == target
    target += 1
  else
    breaks += 1
  end
end

puts target != 1 ? breaks : -1

Measured memory_bytes: 15388
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
ans = 0
if n % 2 == 1: 
    print(0)
    exit
else: 
    while n != 0:
        ans += n//10
        n //= 5
    print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
    int H,A;
    cin>>H>>A;
    int a[100002];
    for(int i=0;i<A;i++){
        cin>>a[i];
    }
    int i=0;
    while(i<A){
        H-=a[i++];
    }
    if(H<=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 888
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let (a, b) = (read::<usize>() - 1, read::<usize>() - 1);
        graph[a].push(b);
        graph[b].push(a);
    }

    let q: usize = read();
    let vdc: Vec<(usize, usize, i32)> = (0..q)
        .map(|_| (read::<usize>() - 1, read::<usize>(), read::<i32>()))
        .collect();

    let mut dp: Vec<Vec<usize>> = vec![vec![q; 11]; n];
    for i0 in 0..q {
        let i = q - i0 - 1;
        let (v, d, _) = vdc[i];
        let mut que: VecDeque<(usize, usize)> = VecDeque::new();
        if dp[v][d] == q {
            dp[v][d] = i;
        }
        if graph[v].is_empty() {
            for j in 0..d {
                if dp[v][j] == q {
                    dp[v][j] = i;
                }
            }
            continue;
        }
        que.push_back((v, d));
        while !que.is_empty() {
            let (p, dist) = que.pop_front().unwrap();
            if dist <= 0 {
                continue;
            }
            if dp[p][dist - 1] == q {
                dp[p][dist - 1] = i;
            }
            for j in &graph[p] {
                if dp[*j][dist - 1] == q {
                    dp[*j][dist - 1] = i;
                    que.push_back((*j, dist - 1));
                }
            }
        }
    }
    for i in 0..n {
        if dp[i][0] == q {
            println!("{}", 0);
        } else {
            println!("{}", vdc[dp[i][0]].2);
        }
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 33020
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int a;
	cin >> a;
	printf("%d\n", a + a * a + a * a * a);
	return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int k, q; cin >> k >> q; ll d[k];
  rep(i, k){
    cin >> d[i];
  }
  rep(i, q){
    ll n, x, m; cin >> n >> x >> m; n--;
    ll plus = 0, zero = 0;
    rep(j, k){
      plus+=(d[j]%m);
      if(d[j]%m==0) zero++;
    }
    ll kai = n/k, amari = n%k;
    //cout << kai << " " << amari << endl;
    plus*=kai; zero*=kai;
    //cout << plus << endl;
    rep(j, amari){
      plus+=(d[j]%m);
      if(d[j]%m==0) zero++;
    }
    plus+=(x%m);
    //cout << plus << endl;
    plus/=m;
    cout << n - plus - zero << endl;
  }
}

Measured memory_bytes: 384
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    ans = 0

    for i in range(n):
        if a_list[i] >= b_list[i]:
            ans += b_list[i]
        else:
            d = b_list[i] - a_list[i]
            ans += a_list[i]
            if a_list[i + 1] >= d:
                ans += d
                a_list[i + 1] = a_list[i + 1] - d
            else:
                ans += a_list[i + 1]
                a_list[i + 1] = 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 97460
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
string S;
/* function */
bool isPalimdrome(int R, int L) {
    int r = R, l = L;
    while (r <= l) {
        if (S[r] != S[l]) return false;
        r++;
        l--;
    }
    return true;
}
/* main */
int main(){
    cin >> S;
    int len = S.size();
    if (isPalimdrome(0, (len - 1) / 2 - 1)
        && isPalimdrome(0, len - 1)
        && isPalimdrome((len + 3) / 2 - 1, len - 1))
        cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int h, w, s, a[32][32], sum[33][33];
pi dp[32][32][32][32];

pi rec(int y, int x, int Y, int X){
	pi &res = dp[y][x][Y][X];
	if(res.first != -1) return res;
	
	res = mp(-inf, 0);
	if(sum[Y + 1][X + 1] - sum[Y + 1][x] - sum[y][X + 1] + sum[y][x] >= s){
		res = mp(1, sum[Y + 1][X + 1] - sum[Y + 1][x] - sum[y][X + 1] + sum[y][x] - s);
	}
	if(y < Y) for(int i = y; i < Y; i++){
		pi a = rec(y, x, i, X), b = rec(i + 1, x, Y, X);
		a.first += b.first;
		a.second = min(a.second, b.second);
		res = max(a, res);
	}
	if(x < X) for(int i = x; i < X; i++){
		pi a = rec(y, x, Y, i), b = rec(y, i + 1, Y, X);
		a.first += b.first;
		a.second = min(a.second, b.second);
		res = max(a, res);
	}
	return res;
}

int main(){
	while(cin >> h >> w >> s, h){
		s *= -1;
		rep(i, h) rep(j, w){
			cin >> a[i][j];
			s += a[i][j];
			sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
			rep(k, h) rep(l, w) dp[i][j][k][l] = mp(-1, 0);
		}
		pi ans = rec(0, 0, h - 1, w - 1);
		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 9368
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let a = nextInt()
    let b = nextInt()
    let c = nextInt()
    let d = nextInt()
    let e = nextInt()

    let min = Math.min(a,b,c,d,e)
    let ans = Math.ceil(n/min)
    console.log(ans + 4)

}
Main()



Measured memory_bytes: 30528
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  map<string, int> cnt;
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    cnt[s]++;
  }
  vector<string> a;
  int best = 0;
  for (auto& it : cnt) {
    best = max(best, it.second);
  }
  for (auto& it : cnt) {
    if (best == it.second) a.push_back(it.first);
  }
  sort(a.begin(), a.end());
  for (auto& s : a) cout << s << endl;
  return 0;
}


Measured memory_bytes: 25584
n = int(input())
s = input()

e = []
tmp = 0
for i in range(n):
    e.append(tmp)
    if s[i] == 'E':
        tmp += 1

w = []
tmp = 0
for i in range(1, n+1):
    w.append(tmp)
    if s[-i] == 'W':
        tmp += 1

wr = w[::-1]

res = 999999
for i in range(n):
    tmp = (i-e[i]) + (n-i-1-wr[i])
    res = min(res, tmp)

print(res)

Measured memory_bytes: 20176
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int P=1e9+7;
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	long long n,a,b,ans;
	cin>>n>>a>>b;
	if(a>b)swap(a,b);
	if((a-b)%2==0)ans=(b-a)/2; 
	else ans=min(b-a+n-b+n-b+1,b-a+a-1+a-1+1)/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int M = 51;

void dfs(int x, llint ks, vector<bool>& visited) {
  if (visited[x]) return;
  visited[x] = true;
  for (int i = 1; i < M; ++i) {
    if (ks & (1LL<<i)) {
      dfs(x % i, ks, visited);
    }
  }
}

bool can(int a, int b, llint ks) {
  vector<bool> visited(a+1, false);
  dfs(a, ks, visited);
  return visited[b];
}

bool canAll(vector<int>& a, vector<int>& b, llint ks) {
  REP(i, (int)a.size()) {
    if (!can(a[i], b[i], ks)) return false;
  }
  return true;
}

int main(void) {
  int N;
  scanf("%d", &N);
  vector<int> a(N), b(N);
  REP(i, N) scanf("%d", &a[i]);
  REP(i, N) scanf("%d", &b[i]);

  llint mask = (1LL<<M) - 1 - (1LL<<0);

  if (!canAll(a, b, mask)) {
    puts("-1");
    return 0;
  }

  for (int k = M-1; k >= 1; --k) {
    if (canAll(a, b, mask ^ (1LL<<k))) {
      mask ^= 1LL<<k;
    }
  }

  printf("%lld\n", mask);
  return 0;
}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n, k;
	cin >> n >> k;

	cout << n-k+1 << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;





int main() {
	int x;
	cin >> x;
	cout << (1 ^ x) << endl;


}

Measured memory_bytes: 3624