akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut s: Vec<Option<i64>> = (0..1<<n).map(|_| Some(sc.cin())).collect();
    s.sort();
    s.reverse();
    let mut t = vec![];
    {
        t.push(s[0].unwrap());
        s[0] = None;
    }
    for _ in 0..n {
        t.sort(); t.reverse();
        let mut dt = vec![];
        let mut i = 0;
        for &x in t.iter() {
            while i < s.len() {
                if let Some(y) = s[i] {
                    if x > y {
                        dt.push(y);
                        s[i] = None;
                        break;
                    }
                }
                i += 1;
            }
        }
        if dt.len() != t.len() {
            put!("No");
            return;
        }
        for &y in dt.iter() {
            t.push(y);
        }
        // trace!(&t, &s);
    }
    put!("Yes");
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 24768
import qualified Data.Set as Set
import Control.Monad

main = do
    [n, k] <- map readInt .words <$> getLine
    susukesHoldingSweet <- concat <$> (forM [1..k] $  \_ -> do
        getLine
        map readInt . words <$> getLine)
    let susukeSetHoldingSweet = Set.fromList susukesHoldingSweet
    print $ n - Set.size susukeSetHoldingSweet

readInt :: String -> Int
readInt = read

Measured memory_bytes: 6552
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010;
struct node
{
	int a,b;
	bool operator<(const node &c)const
		{
			return a<c.a;
		}
}a[N];
int n,m;
int main()
{
#ifndef ONLINE_JUDGE
//	freopen("C.in","r",stdin);
#endif
	n=gi();m=gi();
	for(int i=1;i<=n;i++)
		a[i].a=gi(),a[i].b=gi();
	sort(a+1,a+n+1);
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=1ll*min(m,a[i].b)*a[i].a;
		m-=min(m,a[i].b);
		if(m<=0)break;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }


  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
     if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  bool operator == (Mint &a) const {
    return x==a.x;
  }

  bool operator != (Mint &a) const {
    return x!=a.x;
  }
};


int main(){
  int N, L;
  scanf("%d", &N);
  scanf("%d", &L);
  std::vector<int > a(N);
  for (int i=0; i<N; i++){
    scanf("%d", &a[i]);
  }
  int max = 0;
  int index = -1;
  for (int i=0; i<N-1; i++){
    if (max<a[i]+a[i+1]){
      max = a[i]+a[i+1];
      index = i;
    }
  }
  if (max<L) {
    printf("Impossible\n");
    return 0;
  }
  //while(true){
  //};
  printf("Possible\n");
  std::vector<int> ans;
  for (int i=0; i<index; i++){
    ans.push_back(i);
  }
  for (int i=N-2; i>index; i--){
    ans.push_back(i);
  }
  ans.push_back(index);
  for (int p : ans){
    printf("%d\n", p+1);
  }
  return 0;
}


Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    int a;
    cin >> a;
    cout << (a == 3 || a == 5 || a == 7 ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

char map[8][8];
int r, c, k;
int ans = 0;
bool rvis[8] = {0};
bool cvis[8] = {0};


void dfs(int n){
    if(n==r+c){
        int temp = 0;
        for(int i =0;i<r;i++){
            if(rvis[i])continue;
            for(int j = 0;j<c;j++){
                if(cvis[j])continue;
                temp+=(map[i][j]=='#');             
            }
        }
        ans+=(temp==k);
        return ;
    }
    if(n<r){
        rvis[n] = true;
        dfs(n+1);
        rvis[n] = false;
        dfs(n+1);
    }else{
        cvis[n-r] = true;
        dfs(n+1);
        cvis[n-r] = false;
        dfs(n+1);
    }
    return ;
}

int main()
{
    scanf("%d %d %d", &r, &c, &k);
    for (int i = 0; i < r; i++)
    {
        scanf("%s", map[i]);
    }
    dfs(0);
    printf("%d",ans);
}



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

template<typename T>
vector<T> trialDivision(T a) {
	vector<T> res;
	T i = 2;
	while (i * i <= a) {
		if (a % i == 0) {
			a /= i;
			res.push_back(i);
		}
		else ++i;
	}
	if (a != 1) res.push_back(a);
	return res;
}

int main() {
	long N, ans = 0;
	cin >> N;
	// vector<long> a = trialDivision(N);
	vector<long> a;
	// long Nt = N;
	// long i = 2;
	// while (i * i <= Nt) {
	// 	if (Nt % i == 0) {
	// 		a.push_back(Nt);
	// 		Nt /= i;
	// 	}
	// 	else ++i;
	// }
	for (long i = 1; i * i <= N; ++i) {
		if (N % i == 0) a.push_back(N / i);
	}
	for (long i = 1; i * i <= N; ++i) {
		if (N % i == 0) a.push_back(i);
	}
	// a.push_back(Nt);
	// for (long& i : a) cout << i << ' ';
	// cout << endl;
	// a.erase(unique(a.begin(), a.end()), a.end());
	for (long& i : a) {
		long m = (N / i) - 1;
		if (m == 0) continue;
		if (N / m == N % m) ans += m;
	}
	// for (long& i : a) ans += N / i - 1;
	// ans += N - 1;
	cout << ans;
}

Measured memory_bytes: 384
import string
print raw_input().translate(string.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'))

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

using namespace std;
#define ll long long 


//====== Data Structure =//

//=======================//

//====== Variables ======//
int a, b, c;
//=======================//

//====== Functions ======//

//=======================//

int main(int argc, char *argv[]) {
	
	//==========================//
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	//==========================//
	
	cin >> a >> b >> c;
	int comb = b * 10 + c;
	if (comb % 4 == 0)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int n;
vector<int> a;
void solve(){
    cin >> n;
    a = vector<int>(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    int x = a[0];
    for(int i = 1; i < n; i++){
        x ^= a[i];
    }

    for(int i = 0; i < n; i++){
        cout << (x ^ a[i]) << " ";
    }
    cout << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	string S, T, origin;
	cin >> S >> T;
	origin = S;
	string ans = S;
	bool can = false;
	int sN = S.size(), tN = T.size();
	rep( i, 0, sN - tN + 1 ){
		bool correct = true;
		rep( j, 0, tN ){
			if (S[ i + j ] == '?')
				continue;
			if (S[ i + j ] != T[ j ])
				correct = false;
		}
		if (correct){
			string temp = S;
			rep( j, 0, tN ){
				temp[ i + j ] = T[ j ];
			}
			if (!can){
				ans = temp;
				can = true;
			}
			else
				ans = min(ans, temp);
		}
	}
	if (!can){
		cout << "UNRESTORABLE\n" << endl;
		return 0;
	}
	rep( i, 0, sN ){
		if (ans[ i ] == '?')
			cout << "a";
		else
			cout << ans[ i ];
	}
	cout << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
fn main() {
    let n: usize = read();
    let mut xs: Vec<i64> = vec![0;n];
    let mut min = 0;
    let mut max = 0;
    for i in 0..n {
        let x = read();
        if i == 0 {
            min = x;
        }
        if min > x {
            min = x;
        }
        if max < x {
            max = x;
        }
        xs[i] = x;
    }

    let mut ans = 10001 * xs.len() as i64;
    for d in min..max+1 {
        let mut sum = 0;
        for x in xs.iter() {
            sum += (x - d) * (x - d);
        }
        if ans > sum {
            ans = sum;
        }
    }
    println!("{}", ans);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .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: 4352
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <cstdio>
using namespace std;
int main(void){
	string s;
	int i,j,c;
	cin>>s;
	c=s.size()-2;
	while(1){
		int f=1;
		if(c%2==0){
			for(i=0;i<c/2;i++){
				if(s[i]!=s[i+c/2]) f=0;
			}
			if(f) break;
		}
		c--;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    int card[4][13];
    cin>>n;
    char ch; 
    int x;
    for(int a=0;a<4;a++){
        for(int b=0;b<13;b++){
            card[a][b]=false;
        }
    }
    for(int i=0;i<n;i++){
        cin>>ch>>x;
        if(ch=='S')card[0][x-1]=true;
        if(ch=='H')card[1][x-1]=true;
        if(ch=='C')card[2][x-1]=true;
        if(ch=='D')card[3][x-1]=true;
    }
    for(int a=0;a<4;a++){
        for(int b=0;b<13;b++){
            if(a==0&&card[a][b]==false)cout<<"S"<<" "<<b+1<<endl;
            if(a==1&&card[a][b]==false)cout<<"H"<<" "<<b+1<<endl;
            if(a==2&&card[a][b]==false)cout<<"C"<<" "<<b+1<<endl;
            if(a==3&&card[a][b]==false)cout<<"D"<<" "<<b+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
def checker(s):
    l = len(s)
    for i in range(l // 2):
        if (s[i] != s[-1 - i]):
            return 0
    else:
        return 1

s = input()
n = len(s)
#print(s[int((n+3)/2):])
if(checker(s) == checker(s[:int((n-1)/2)]) == checker(s[int((n+3)/2-1):]) == 1):
    print("Yes")
else:
    print("No")



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

int a[200005];

int N;

int main()
{
    cin >> N;

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

    if(N % 2 == 0)
    {
        for(int i = N;i >= 2;i-=2)
        {
            cout << a[i] << " ";
        }

        for(int i = 1;i <= N;i+=2)
        {
            cout << a[i] << " ";
        }
    }
    else
    {
        for(int i = N;i >= 1;i-=2)
        {
            cout << a[i] << " ";
        }

        for(int i = 2;i <= N;i+=2)
        {
            cout << a[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 2944
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let mut c = vec![2; n + 1];
    for i in (1..=n).rev() {
        let k: usize = (i * 2..=n).step_by(i).fold(0, |acc, x| acc + c[x]) % 2;
        c[i] = a[i - 1] ^ k;
    }
    let ans = (1..=n).filter(|&x| c[x] == 1).collect::<Vec<usize>>();
    println!("{}", ans.len());
    for i in ans {
        print!("{} ", i);
    }
}



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

#define EPS 1e-8
#define MAX_N 55

long long int ncr[MAX_N];

void set_ncr(long long int n) {
    ncr[0] = 1;
    for (long long int i = 1; i <= n; i++) {
        ncr[i] = (n - i + 1) * ncr[i - 1];
        ncr[i] /= i;
    }
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long int> v;
    map<long long int, int> mp;
    for(int i=0;i<n;++i){
        long long int tmp;
        cin >> tmp;
        v.push_back(tmp);
        mp[tmp]++;
    }

    sort(v.rbegin(), v.rend());
    map<long long int, int> mp2;
    long double avg = v[0];
    mp2[v[0]]++;
    for(int i=1;i<a;++i){
        avg = avg * i / (long double)(i+1) + v[i] / (long double)(i+1);
        mp2[v[i]]++;
    }

    long long int ptn = 0;
    long long int tmp = v[a-1];
    set_ncr(mp[tmp]);
    if(abs(avg - round(avg)) < EPS && abs(tmp - avg) < EPS){
        for(int i=mp2[tmp];i<=min(mp[tmp], b-a+mp2[tmp]);++i)ptn += ncr[i];
    }else{
        ptn += ncr[mp2[tmp]];
    }

    printf("%.10Lf\n",avg);
    if(ptn == 0)cout << 1 << endl;
    else cout << ptn << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

def solve(n):
    if n == 0:
        return 1
    return n * solve(n - 1)

if n <= 1:
    n_ans = 0
else:
    n_ans = solve(n) // (solve(n - 2) * 2)
if m <= 1:
    m_ans = 0
else:
    m_ans = solve(m) // (solve(m - 2) * 2)
ans = n_ans + m_ans
print(ans)


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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int l = S.length();
	if (l == N && l/2==(double)l/2.0) {
		string s1;
		string s2;
		s1 = S.substr(0, l / 2);
		s2 = S.substr(l / 2, l / 2);
		if (s1 == s2) cout << "Yes\n"; else cout << "No\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<int> v(n);
  vector<P> k(n);
  rep(i,n){
    cin >> v[i];
    k[i] = make_pair(v[i],i);
  }
  sort(ALL(k));
  rep(i,n)v[k[i].second] = i;
  int even = 0,odd = 0;
  rep(i,n)if((i%2) != (v[i]%2)){
    if(v[i] & 1)odd++;
    else even++;
  }
  cout << abs(odd-even)+min(odd,even) << endl;

  



  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  int minutes = (60*H2+M2) - (60*H1+M1);
  
  cout << max(0, minutes - K) << endl;  
  
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL)return ;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL)return ;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL)return ;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;
  }

  for(i=0;i<n;i++)if(T[i].p==NIL)root=i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 620
import math
def fr(i):
    s = 1
    for j in range(i+1):
        s*=j
    return s

def f():
    n,p = list(map(int,input().split(" ")))
    a = list(map(int,input().split(" ")))
    a.sort()
    m0 = 0
    m1 = 0
    for i in a:
        if i%2==0:
            m0 += 1
        else:
            m1 += 1
    s = 0
    if p==0:
        
        
        for i in range(0,m1+1,2):
            s_ = (2**m0)
            
            for j in range(0,i):
                s_ *= m1-j
            for j in range(1,i+1):
                s_ /= j
            s += s_
    if p==1:
        if m1 == 0:
            print("0")
            return
        s = 0
        for i in range(1,m1+1,2):
            s_ = (2**m0)
            for j in range(0,i):
                s_ *= m1-j
            for j in range(1,i+1):
                s_ /= j
            s += s_
    print(int(s))

f()

Measured memory_bytes: 3064
from sys import stdin

'''
def answer(A, x, y):
    if A < y < x:
        print("Yes")
    else:
        print("No")
'''


def main():
    A, B, C = [int(x) for x in stdin.readline().split()]
    if A < B:
        if A < C < B:
            print("Yes")
        else:
            print("No")
    else:
        if B < C < A:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	s := Scan()
	ans := 0
	for i := 0; i < n-2; i++ {
		if s[i:i+3] == "ABC" {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include <iostream>
using namespace std;
typedef long long LL;
LL gcd(LL u, LL v) {
  LL r;
  while (0 != v) {
	  r = u % v; 
	  u = v; 
	  v = r; //
  }
  return u;
}
//最少公倍数
LL lcm(LL a, LL b)
{
	return  a*b/gcd(a, b);
}
int main(int argc, char* argv[])
{
	LL A,B;
	cin>>A>>B;
	cout<<lcm(A,B)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll c[20], n;
ll solve(int i, ll a, ll b) {
	if (i == n) {
		ll d = a - b;
		if (d < 0) d = 0 - d;
		return d;
	}
	ll sum = 900000000000000000;
	sum = min(sum, solve(i + 1, a + c[i], b));
	sum = min(sum, solve(i + 1, a, b + c[i]));
	return sum;
}
int main() {
	while (cin >> n&&n != 0) {
		for (int i = 0; i < n; i++)
			cin >> c[i];
		cout << solve(0, 0, 0) << endl;
	}
}

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	sort(A.begin(), A.end());
	int S=0;
	int SS=1;
	for (int i=1; i<N; i++) {
		if (A.at(i)==A.at(i-1))
			SS++;
		else {
			S +=SS%2;
			SS=1;
		}
	}
	S +=SS%2;
	cout <<S << endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,a,b;cin>>n>>a>>b;
    ll buf=a+b;
    ll buf1=n/buf,buf2=n%buf;
    ll res=buf1*a;
    if(buf2<a)res+=buf2;
    else res+=a;
    cout<<res<<endl;
}

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

int main() {//https://atcoder.jp/contests/abc169/submissions/13892334
  ll a;
  double b;
  cin >> a >> b;
  ll ib = b*100+0.5;
  a *= ib;
  a /= 100;
  printf("%lld\n", a);
  return 0;
}


Measured memory_bytes: 3772
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool compare_by_second(pair<int, int> a, pair<int, int> b){
  if(a.second!=b.second) return a.second<b.second;
  else return a.first<b.first;
}

int main(){
  int n;
  cin>>n;
  vector<pair<int, int>> work(n);
  for(int i=0;i<n;i++){
    cin>>work[i].first>>work[i].second;
  }
  sort(work.begin(),work.end(),compare_by_second);
  long long sum=0;
  int ans=1;
  //  cout<<endl;
  for(int i=0;i<n;i++){
    sum+=work[i].first;
    if(sum>work[i].second) ans=0;
    //    cout<<work[i].first<<" "<<work[i].second<<endl;
  }
  if(ans==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    
    int l[n], sum=0, count=1;
    for(int i=0; i<n; i++) {
        cin >> l[i];
        sum += l[i];
        if(sum<=x) count++;
    }
    
    cout << count << endl;

    return 0;
    
}

Measured memory_bytes: 256
H, W = map(int, input().split())

if (H%3==0) or (W%3==0):
  print(0)
else:
  ans = H * W
  H, W = min(H, W), max(H, W)
  for wi in range(1, W//2 + 1):
    S1 = H * wi
    if (H%2==0) or ((W-wi)%2==0):
      S2 = H * (W-wi) // 2
      S3 = S2
    else:
      S2 = min(H, W-wi) * (max(H, W-wi)//2)
      S3 = S2 + min(H, W-wi)
    ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
  for hi in range(1, H//2 + 1):
    S1 = W * hi
    if (W%2==0) or ((H-hi)%2==0):
      S2 = W * (H-hi) // 2
      S3 = S2
    else:
      S2 = min(W, H-hi) * (max(W, H-hi)//2)
      S3 = S2 + min(W, H-hi)
    ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
    
  print(ans)
  
  

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

char f(char sw1, char sw2, char tar) {
	if ((sw2 == 'S' && tar == 'o') || (sw2 == 'W' && tar == 'x'))return sw1;
	return sw1 == 'S' ? 'W' : 'S';
}

int main() {
	int n; string s; cin >> n >> s;
	
	string d[4] = { "SS","SW","WS","WW" };
	for (int i = 0; i < 4; i++) {
		string ans = d[i];
		for (int j = 0; j < n - 2; j++) {
			ans += f(ans[j], ans[j + 1], s[j + 1]);
		}
		if (f(ans[n - 2], ans[n - 1], s[n - 1]) != ans[0])continue;
		if (f(ans[n - 1], ans[0], s[0]) != ans[1])continue;
		cout << ans << endl;
		return 0;
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 776
var
 s,t:string;
 t1:char;
 i,j:longint;
begin
 readln(s);
 readln(t);
 for i:=1 to length(s)-1 do
  for j:=i+1 to length(s) do
   if s[i]>s[j] then
    begin
     t1:=s[i];
     s[i]:=s[j];
     s[j]:=t1;
    end;
 for i:=1 to length(t)-1 do
  for j:=i+1 to length(t) do
   if t[i]<t[j] then
    begin
     t1:=t[i];
     t[i]:=t[j];
     t[j]:=t1;
    end;
 if t>s then writeln('Yes')
        else writeln('No');
end.

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

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

  for(int i = 0; i < N; i++) {
    if(a[a[i]-1] == i+1) ans++;
  }
  cout << ans/2 << endl;

  return 0;
}


Measured memory_bytes: 768
n = int(input())

count = 0
c = 0

for i in range(1,n + 1):
  if i % 2 != 0:
    for j in range(1,i + 1):
      if i % j == 0:
        count += 1
    if count == 8:
      c += 1
    count = 0

print(c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
int ans;
if(a>b) {
  ans = a-1;
} else {
  ans = a;
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var hugCount = 0;
            var midrange = input.Length / 2;

            for (var i = 0; i < midrange; i++)
            {
                if (input[i] != input[input.Length - 1 - i])
                {
                    hugCount++;
                }
            }

            Debug.WriteLine(hugCount);
            Console.WriteLine(hugCount);
        }
    }
}


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

int N;
vector<vector<pair<int, int>>> G;
vector<int> seen;
void dfs(int v, int cur) {
    seen[v] = cur;
    for (auto next_v : G[v]) {
        if (seen[next_v.first] != -1) continue;
        if (next_v.second % 2 == 0) {
            dfs(next_v.first, cur);
        }
        else {
            dfs(next_v.first, 1-cur);
        }
    }
    return;
}

int main() {
    cin >> N;
    seen.assign(N, -1);
    G.resize(N);
    for (int i = 0; i < N-1; i++) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        G[a].push_back(make_pair(b, c));
        G[b].push_back(make_pair(a, c));
    }
    dfs(0, 0);
    for (int i = 0; i < N; i++) {
        cout << seen[i] << endl;
    }
}

Measured memory_bytes: 8192
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  var list = nextIntArray();
  var L = 0;
  var R = 1000000009;
  var output = 0;
  while(Math.abs(R - L) > 1){
    var C = Math.floor((R + L) / 2);
    var count = 0;
    for(var i = 0; i < N; i++){
      count += Math.ceil(list[i] / C) - 1;
    }
    if(count <= K){
      output = C;
      R = C;
    }else{
      
      L = C;
    }
  }
  myout(output);
}


Measured memory_bytes: 50424
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        fib solver = new fib();
        solver.solve(1, in, out);
        out.close();
    }

    static class fib {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] dp = new int[n + 1];
            for (int i = 0; i <= n; i++) dp[i] = (i <= 1) ? 1 : dp[i - 1] + dp[i - 2];
            out.println(dp[n]);
        }

    }
}




Measured memory_bytes: 26440
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define ff first
#define ss second
#define mkp make_pair    
#define mkt make_tuple
#define all(v ) sort(v.begin(), v.end());      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char> 
#define vll vector< pair<ll,ll> > 
#define pr pair<ll,ll>
#define mps map<string ,ll>
#define mpc map<char ,char>
#define mpl map<ll,ll>
#define tpl tuple<ll,ll,ll>
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
//	   cin>>t;
	      while(t--)
{

/*
3 3
dxx
axx
cxx*/
ll n,m,i,j;
cin>>n>>m;
string  s[n];
fo(i,n)
{
	cin>>s[i];
}
fo(i,n-1)
{
	for(j=i+1;j<n;j++)
	{
		if(s[i]>s[j])
		swap(s[i],s[j]);
	}
}/*
5 5
dxxaa
axxaa
cxxxx
a
x
*/
fo(i,n)
cout<<s[i];
ee;
}
return 0;
}



Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>Map;
int P[101000][3], n, w[101000], ck[101000], w2[5], ck2[5], chk;
void DFS(){
    int i;
    int S = 0;
    for(i=1;i<=n;i++){
        S = S * (2*n) + (w2[i]*2-2+ck2[i]);
    }
    if(Map[S])return;
    for(i=1;i<=n;i++){
        if(w[i]!=w2[i]||ck[i]!=ck2[i])break;
    }
    if(i==n+1)chk=1;
    Map[S]=1;
    for(i=1;i<=n-2;i++){
        swap(w2[i],w2[i+2]);
        swap(ck2[i],ck2[i+2]);
        ck2[i]=!ck2[i];
        ck2[i+1]=!ck2[i+1];
        ck2[i+2]=!ck2[i+2];
        DFS();
        ck2[i]=!ck2[i];
        ck2[i+1]=!ck2[i+1];
        ck2[i+2]=!ck2[i+2];
        swap(w2[i],w2[i+2]);
        swap(ck2[i],ck2[i+2]);
    }
}
int BIT[2][101000];
void Ins(int pv, int a){
    while(a<=n){
        BIT[pv][a]++;
        a+=(a&-a);
    }
}
int Sum(int pv, int a){
    int r = 0;
    while(a){
        r += BIT[pv][a];
        a-=(a&-a);
    }
    return r;
}
int main(){
    int i, j, cnt = 0;
    scanf("%d",&n);
    for(i=0;i<3;i++){
        for(j=1;j<=n;j++){
            scanf("%d",&P[j][i]);
            P[j][i] += 2;
        }
    }
    for(i=1;i<=n;i++){
        if(P[i][0]/3!=P[i][1]/3 || P[i][0]/3!=P[i][2]/3 || (P[i][0]/3)%2 != i%2 || P[i][1]*2!=P[i][0]+P[i][2]){
            printf("No\n");
            return 0;
        }
        w[i] = P[i][0]/3;
        if(P[i][0]>P[i][2])ck[i]=1;
    }
    if(n<=4){
        for(i=1;i<=4;i++)w2[i]=i;
        DFS();
        if(chk)printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    int S = 0;
    for(i=1;i<=n;i++){
        if(ck[i])S=(S+i)%2, cnt++;
    }
    int s = 0, S2 = 0;
    for(i=n;i>=1;i--){
        s = (s+Sum(i%2,w[i]))%2;
        if(i%2==0) S2 = (S2 +  Sum(i%2,w[i]))%2;
        Ins(i%2,w[i]);
    }
    if(s%2!=cnt%2 || S2%2 != S%2){
        printf("No\n");
    }
    else printf("Yes\n");
}

Measured memory_bytes: 3072
n, k, q = map(int, input().split())
a = []
for i in range(q):
  a.append(int(input()))
cnt = [0]*n
for i in range(q):
  cnt[a[i]-1] += 1
for i in range(n):
  point = k - (q - cnt[i])
  if point <= 0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 8592
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	std::string s; cin >> s;

	auto dp = make_v<int>(s.size() + 1, 2);
	for(int i = 0; i < dp.size(); i++) for(int j = 0; j < dp[i].size(); j++) dp[i][j] = 1 << 30;
	dp[0][0] = dp[0][1] = 0;

	reverse(begin(s), end(s));
	for(int i = 0; i < s.size(); i++) {
		int cost = s[i] - '0';
		dp[i + 1][0] = std::min(dp[i][0] + cost, dp[i][1] + cost + 2);
		dp[i + 1][1] = std::min(dp[i][0] + (9 - cost), dp[i][1] + (9 - cost));
	}
	printf("%d\n", std::min(dp.back()[0], dp.back()[1] + 2));
	return 0;
}


Measured memory_bytes: 55940
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;
map<int, int> m1, m2;
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	m1.insert(make_pair(1,1));
	m1.insert(make_pair(3,1));
	m1.insert(make_pair(5,1));
	m1.insert(make_pair(7,1));
	m1.insert(make_pair(8,1));
	m1.insert(make_pair(10,1));
	m1.insert(make_pair(12,1));

	m2.insert(make_pair(4,2));
	m2.insert(make_pair(6,2));
	m2.insert(make_pair(9,2));
	m2.insert(make_pair(11,2));
	
	
	
	int x, y; cin >> x >> y;
	
	if (x == 2 || y == 2)
		cout << "No\n";
	else {
		int a, b;
		if (m1.find(x) != m1.end())
			a = m1[x];
		if (m2.find(x) != m2.end())
			a = m2[x];
		
		if (m1.find(y) != m1.end())
			b = m1[y];
		if (m2.find(y) != m2.end())
			b = m2[y];
		if (a == b)
			cout << "Yes\n";
		else
			cout << "No\n";
			
	}
	return 0;   
}  


Measured memory_bytes: 256
package main
import . "fmt"
import . "strings"
func main() {
  var h,w int
  var s [][]string
  var t string
  Scan(&h,&w)
  s = make([][]string,h)
  for i:=0;i<h;i++ {
    Scan(&t)
    s[i] = Split(t,"")
  }
  OUTSIDE:
  for j:=0;j<w;j++ {
    for i:=0;i<h;i++ {
      if s[i][j] == "#" { continue OUTSIDE }
    }
    for i:=0;i<h;i++ { s[i][j] = "n" }
  }
  for i:=0;i<h;i++ {
    var ng = true
    for j:=0;j<w;j++ {
      if s[i][j] == "#" { ng = false }
    }
    if ng { continue }
    for j:=0;j<w;j++ {
      if s[i][j] == "n" { continue }
      Print(s[i][j])
    }
    Println()
  }
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int A[100100];

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

    int N, x;
    std::cin >> N >> x;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    ll res = 0ll;
    for(int i=0,j=0;i<N-1;){
        while(j+1 < N && A[j] + A[j+1] > x){
            ++j;
        }

        for(;i<j;++i){
            int rest = (A[i] + A[i+1]) - x;
            if(rest <= 0){continue;}
            res += rest;

            if(rest <= A[i+1]){
                A[i+1] -= rest;
            }else{
                A[i+1] = 0;
            }
        }

        // std::cout << i << ", " << j << ", " << res << std::endl;

        while(j+1 < N && A[j] + A[j+1] <= x){
            ++j;
        }

        i = j;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
  }
  vector<int> Q(N);
  for (int i = 0; i < N; i++){
    cin >> Q[i];
  }
  int Pans, Qans;
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    p[i] = i + 1;
  }
  int count = 1;
  while (1){
    bool pflg = true;
    for (int i = 0; i < N; i++){
      if (P[i] != p[i]){
        pflg = false;
      }
    }
    if (pflg){
      Pans = count;
    }
    bool qflg = true;
    for (int i = 0; i < N; i++){
      if (Q[i] != p[i]){
        qflg = false;
      }
    }
    if (qflg){
      Qans = count;
    }
    count++;
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  cout << abs(Pans - Qans) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder.ABC._124
{
    class d
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var N = int.Parse(spl[0]);
            var K = int.Parse(spl[1]);
            var S = Console.ReadLine().Trim();
            var firstReverse = S[0] == '1';
            var list = new List<int>();
            var is1 = firstReverse;
            var cnt = 0;
            foreach(var c in S)
            {
                if (is1)
                {
                    if (c == '1')
                    {
                        ++cnt;
                    }
                    else
                    {
                        list.Add(cnt);
                        cnt = 1;
                        is1 = false;
                    }
                }
                else
                {
                    if (c == '0')
                    {
                        ++cnt;
                    }
                    else
                    {
                        list.Add(cnt);
                        cnt = 1;
                        is1 = true;
                    }
                }
            }
            if(cnt > 0)
            {
                list.Add(cnt);
            }
            if (firstReverse && K * 2 >= list.Count || !firstReverse && K * 2 - 1 >= list.Count)
            {
                Console.WriteLine(S.Length);
            }
            else
            {
                var i = 0;
                cnt = 0;
                if (firstReverse)
                {
                    for (; i < K * 2 + 1; ++i)
                    {
                        cnt += list[i];
                    }
                }
                else
                {
                    for (; i < K * 2; ++i)
                    {
                        cnt += list[i];
                    }
                }
                var max = cnt;
                for(; i<list.Count; i += 2)
                {
                    if (i >= K * 2 + 1)
                    {
                        cnt -= list[i - K * 2 - 1];
                    }
                    if (i >= K * 2)
                    {
                        cnt -= list[i - K * 2];
                    }
                    cnt += list[i];
                    if(i < list.Count - 1)
                    {
                        cnt += list[i + 1];
                    }
                    if(cnt > max)
                    {
                        max = cnt;
                    }
                }
                Console.WriteLine(max);
            }
        }
    }
}


Measured memory_bytes: 12384
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int input = scanner.nextInt();
		
		String str = new Integer(n).toString(n, input);
		System.out.println(str.length());
	}	
	
}

Measured memory_bytes: 21332
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long ans = 1;
    if (N == M) {
      for (int i = N; i > 0; i--) {
        ans *= i;
        ans = ans % 1000000007;
      }
      ans *= ans;
      ans *= 2;
      ans = ans % 1000000007;
    } else if (Math.abs(N - M) == 1) {
      for (int i = N; i > 0; i--) {
        ans *= i;
        ans = ans % 1000000007;
      }
      for (int i = M; i > 0; i--) {
        ans *= i;
        ans = ans % 1000000007;
      }
    } else {
      ans = 0;
    }
    System.out.println(ans);
  }
}

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

bool used[10];
int d[9], cnt = 0;
int x1[]{ 0,2,5,8 }, x2[]{ 1,4,7 }, x3[]{ 3,6 };

void solve3(int p, int k) {
	if (p == 2) {
		if (d[3] + k == d[6])cnt++;
		return;
	}
	if (~d[x3[p]])solve3(p + 1, k);
	else {
		for (int i = 1; i <= 9; i++) {
			if (!used[i]) {
				used[i] = true; d[x3[p]] = i;
				solve3(p + 1, k);
				used[i] = false; d[x3[p]] = -1;
			}
		}
	}
}
void solve2(int p, int k) {
	if (p == 3) {
		if ((d[1] + d[4] + k) % 10 == d[7])
			solve3(0, (d[1] + d[4] + k) / 10);
		return;
	}
	if (~d[x2[p]])solve2(p + 1, k);
	else {
		for (int i = 1; i <= 9; i++) {
			if (!used[i]) {
				used[i] = true; d[x2[p]] = i;
				solve2(p + 1, k);
				used[i] = false; d[x2[p]] = -1;
			}
		}
	}
}
void solve1(int p) {
	if (p == 4) {
		if ((d[0] + d[2] + d[5]) % 10 == d[8])
			solve2(0, (d[0] + d[2] + d[5]) / 10);
		return;
	}
	if (~d[x1[p]])solve1(p + 1);
	else {
		for (int i = 1; i <= 9; i++) {
			if (!used[i]) {
				used[i] = true; d[x1[p]] = i;
				solve1(p + 1);
				used[i] = false; d[x1[p]] = -1;
			}
		}
	}
}
int main() {
	rep(i, 9) {
		cin >> d[i];
		if (~d[i])used[d[i]] = true;
	}
	solve1(0);
	cout << cnt << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* funciton */
/* main */
int main() {
    int N;
    cin >> N;
    vector<double> prob(N);
    for (int i = 0; i < N; i++) cin >> prob[i];

    // dp[i] : 表がi枚出る確率
    // 遷移)
    // dp[i] += dp[i] * (1 - prob[i])
    // dp[i+1] = dp[i] * (prob[i])
    vector<double> dp(N+1, 0);
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j >= 0; j--) {
            dp[j+1] += dp[j] * prob[i];
            dp[j] = dp[j] * (1 - prob[i]);
        }
    }
    double ans = 0.0;
    for (int i = (N+1)/2; i <= N; i++) ans += dp[i];
    cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  
  if (left > right) {cout << "Left" << endl;}
  else if (left < right) {cout << "Right" << endl;}
  else {cout << "Balanced" << endl;}
}

Measured memory_bytes: 3596
#include<stdio.h>
#include <stdlib.h>

int main()
{
	int N;
	int SN=0;
	scanf("%d", &N);
	for (int i = 1;N>=i;i*=10)
	{
		

		SN += N/i%10;
		
	}

	if (N%SN == 0) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 128