akhauriyash/Code-Regression huggingface dataset:
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn f(i: usize) -> usize {
    if i == 0 {
        return 1;
    }
    i * f(i - 1) % 1_000_000_007
}

fn main() {
    let i: usize;
    input!(i);
    println!("{}",f(i));
}

Measured memory_bytes: 5884
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main() {
	ll n, m, ans = 0, A[10101];
	cin >> n;
	if (n > 999)
		cout << "ABD" << endl;
	else
		cout << "ABC" << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define sz(v) (ll)v.size()
#define inf 100000000000000
#define vll vector<ll>
#define pll pair<ll,ll>nnnn
using namespace std;
const int N=200004;

ll deg[5];
map<ll,ll>mp;
void solve()
{
	ll a,b,i;
	cin>>a>>b;
	deg[a]++;
	deg[b]++;
	cin>>a>>b;
	deg[a]++;
	deg[b]++;
	cin>>a>>b;
	deg[a]++;
	deg[b]++;
	for (i=1;i<=4;i++)
		mp[deg[i]]++;
	if(mp[1]==2 && mp[2]==2)
		cout<<"YES";
	else
		cout<<"NO";

}
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

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

long long comb(int n, int m){
    long long c=1;
    for(int i=1; i<=m; i++){
        c *= n-i+1;
        c /= i;
    }
    return c;
}

int main(void)
{
  int n;
  cin >> n;
  
  map<int, int> factor;
  for(int i=2; i<=n; i++){
    //printf("i %d\n", i);
    
    int tmp=i;
    int rt=sqrt(i);
    for(int j=2; j<=rt; j++){
        while(tmp % j  == 0){
          factor[j]++;
          //printf("%d ", j);
          tmp /= j;
        }
    }
    if(rt < tmp){
        factor[tmp]++;
        //printf("%d ", tmp);
    }
    //printf("\n");
  }
  
  long long count = 1;
  long long div = 1000000007;
  
  for(auto i = factor.begin(); i != factor.end(); i++){
      count *= ((long long)i->second+1);
      count %= div;
      //printf("%d %d %lld %lld\n",i->first, i->second+1, count, count%div);
  }

  cout << count % div << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()


ans = 0
i = 0
running_A_count = 0
while i + 1 < len(S):
    if S[i] == "A":
        running_A_count += 1
    elif S[i] == "B" and S[i+1] == "C":
        ans += running_A_count
        i += 1
    else:
        running_A_count = 0
    
    i += 1






print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s[0] + s[1] + s[2] - '0' * 3;
}


Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))

answer = 1
zero_exist = False
up_to_threshold = False
for i in range(n):
    if answer>int(1e+18):
        up_to_threshold = True
    else:
        answer*=a[i]
    if a[i] == 0:
        zero_exist = True
    
if zero_exist == True:
    print(0)
elif up_to_threshold == True or answer > int(1e+18):
    print(-1)
else:
    print(answer)

Measured memory_bytes: 84556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s[101];
int main(){
    int a,b;
    cin>>a>>b;
    --a;--b;
    rep(i,50)rep(j,100){
        if(i%2==0&&j%2==0&&a>0) s[i]+='.',--a;
        else s[i]+='#';
    }
    FOR(i,50,100)rep(j,100){
        if(i%2==0&&j%2==0&&i!=50&&b>0) s[i]+='#',--b;
        else s[i]+='.';
    }
    cout<<100<<" "<<100<<endl;
    rep(i,100) cout<<s[i]<<endl;
    return 0;
}

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

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

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int sum = 0;
        for(int j = 1; j <= i; j *= 10) {
            int d = i % (j * 10) / j;
            sum += d;
        }

        if(sum >= a && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

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

    int p = std::count(S.begin(), S.end(), '+');
    int n = std::count(S.begin(), S.end(), '-');

    std::cout<<p - n<<std::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 = float("inf")
    A = 0
    B = 0
    C = 0

    # W方向から切る場合

    ## 1/3より少し小さく切る

    A = (W//3) * H

    B = (W - (W//3)) * (H // 2)
    C = W*H - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )

    B = ((W - (W//3)) // 2 ) * H
    C = W*H - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )

    A = (W//3 + 1) * H
    B = (W - (W//3 + 1)) * (H//2)
    C = (W*H) - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )

    newH = W
    newW = H

    H = newH
    W = newW

    A = (W//3) * H

    B = (W - (W//3)) * (H // 2)
    C = W*H - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )

    B = ((W - (W//3)) // 2 ) * H
    C = W*H - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )

    A = (W//3 + 1) * H
    B = (W - (W//3 + 1)) * (H//2)
    C = (W*H) - (A+B)

    ans = min( ans , max(A,B,C)-min(A,B,C) )


    print (ans)


Measured memory_bytes: 3188
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

  	string s;
  	cin >> s;
  	bool good = 1;
  	for(int i = 0; i < s.size() - 1; ++ i){
  		good &= (s[i] != s[i + 1]);
  	}

  	if(good)
  		cout << "Good";
  	else
  		cout << "Bad";

    return 0;
}

/*

*/

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

ll arr[N];
ll pre[N],suf[N];
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  REP(i,n) scanf("%lld",&arr[i]);
  ll ans = 0;
  ll cur = 0;
  REP(i,n){
    cur+=max(arr[i],0ll);
    pre[i]=cur;
  }
  cur = 0;
  for(int i = n-1;i>=0;i--) {
    cur+=max(arr[i],0ll);
    suf[i]=cur;
  }
  cur=0;
  suf[n]=0;
  ll p = 0;
  REP(i,k) cur+=arr[i];
  REP(i,n){
    if(i+k>n) break;
    ans = max(ans,p+suf[i+k]+max(cur,0ll));
    cur-=arr[i]-arr[i+k];
    p=pre[i];
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main{
public static void main(String[] args){
  
  Scanner scanner = new Scanner(System.in);
  
  int x = scanner.nextInt();
  
  if(x==0){
    System.out.print("1");
  }else{
    System.out.print("0");
  }
  
}
}

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

int main (){
string s ,t;
cin >>s >>t;
int x = stoi (s+ t );
for ( int i =1; i <=1000; i ++){
if ( i*i == x ){
puts (" Yes ");
return 0;
}
}
puts (" No ");
}


Measured memory_bytes: 256
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)
 
func run() {

	var S string;
    S = next();
	solve(S);

}

func solve(S string){

	if len(strings.Replace(S, S[0:1], "", -1)) == 0 {
		Println("No")
		return
	}

	if len(strings.Replace(strings.Replace(S, S[0:1], "", 2), strings.Replace(S, S[0:1], "", 2)[0:1], "", 2)) == 0 {
		Println("Yes")
	}else {
		Println("No")
	}
}


// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}


type IntHeap []int
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

/////数字と文字
// 基本クラス
type NS struct {
    Num int
    Str string
}

//////　数字と数字
// 基本クラス
type NN struct {
    Num1 int
    Num2 int
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}



Measured memory_bytes: 2816
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
unordered_map<string, ll> memo;
vector<int> d[101];
string AND(string s, string t){
	string ret;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='1' && t[i]=='1') ret+='1';
		else ret+='0';
	}
	return ret;
}
ll solve(string s){
	int n=s.size();
	if(n==1){
		if(s[0]=='0') return 1;
		else return 2;
	}
	auto itr=memo.find(s);
	if(itr!=memo.end()) return itr->second;
	ll ans=solve(s.substr(1, n-1));
	if(s[0]=='1') ans=ans*2%MOD;
	string t=s;
	for(int i=2; i<=n; i++){
		ll c;
		if(i==n) c=1;
		else c=solve(s.substr(i, n-i));
		for(auto x:d[i]){
			string t=s.substr(0, x);
			for(int j=1; j<i/x; j++){
				t=AND(t, s.substr(j*x, x));
			}
			ans=(ans+c*solve(t));
			ans%=MOD;
		}
	}
	return memo[s]=ans;
}

int main()
{
	string s;
	cin>>s;
	for(int i=2; i<=s.size(); i++){
		for(int j=1; j<i; j++){
			if(i%j==0) d[i].push_back(j);
		}
	}
	cout<<solve(s)<<endl;
	return 0;
}

Measured memory_bytes: 5388
#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;


int main() {
	double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	printf("%f\n", sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));

	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
	int n;
  	cin>>n;
  
  	vector<double> v(n);
  	rep(i,n){
      cin>>v[i];
    }
  
	sort(ALL(v));
  
  double ans=v[0];
  
  for(int i=1;i<n;i++){
  	ans=(v[i]+ans)/2;
  }
  
  cout<<ans<<endl;
  

}

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

int main() {
    long a, b, k, i;

    cin >> a >> b >> k;

    while (1) {
        // 高橋のターン
        if (a % 2 == 1) a--;
        a /= 2;
        b += a;
        i++;
        if (i >= k) break;

        // 青木のターン
        if (b % 2 == 1) b--;
        b /= 2;
        a += b;
        i++;
        if (i >= k) break;
    }

    cout << a << ' '<< b << endl;
}


Measured memory_bytes: 256
N = int(input())
A = input().split()

pear = 0

i_result = {}
j_result = {}

for i in range(N):
  result = str(i + int(A[i]))
  if result in i_result:
    i_result[result] += 1
  else:
    i_result[result] = 1

for j in range(N):
  result = str(j - int(A[j]))
  if result in j_result:
    j_result[result] += 1
  else:
    j_result[result] = 1

for k in i_result.keys():
  if k in j_result:
    pear += (i_result[k] * j_result[k])
      
      
print(pear)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, a, b;
ll A, B;

int main() {
    cin >> n;
    A = B = 1;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        A = (A % a == 0 ? A : A + a - A % a);
        B = (B % b == 0 ? B : B + b - B % b);
        if (A / a * b > B) {
            B = A / a * b;
        }
        if (B / b * a > A) {
            A = B / b * a;
        }
    }
    cout << A + B << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int year, month, day;
	int Y[1000] = {0};
	int M[15][2] = {0};
	for (int i = 2; i < 15; i++) {
		M[i][1] = M[i-1][1] + 20;
		M[i][0] = M[i-1][0] + 20;
		if (i % 2 == 1) {
			M[i][0] -= 1;
		}
	}
	//cout << M[11][0] << " " << M[11][1] << endl;
	for (int i = 2; i < 1000; i++) {
		Y[i] = Y[i-1] + M[11][(i-1)%3 == 0];
	}
	for (int i = 0; i < n; i++) {
		cin >> year >> month >> day;
		cout << 196470-Y[year]-M[month][year%3==0]-day+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
// includes {{{
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 2000;
ll n, k;
const int mod = 924844033;

// WARN : use H with larger N
/// --- Modulo Factorial {{{ ///
template < int N, int mod = (int) 1e9 + 7 >
struct Factorial {
  constexpr ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = 0;
    return b == 0 ? (x = 1, y = 0, a) : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
  }
  constexpr ll modinv(ll a) {
    ll x = 0, y = 0;
    extgcd(a, mod, x, y);
    return (x + mod) % mod;
  }
  int arr[N + 1], inv[N + 1];
  ll operator[](int i) const { return arr[i]; }
#if !defined(DEBUG)
  constexpr
#endif
      Factorial()
      : arr(), inv() {
    arr[0] = 1;
    for(int i = 1; i <= N; i++) {
      arr[i] = (ll) i * arr[i - 1] % mod;
    }
    inv[N] = modinv(arr[N]);
    for(int i = N - 1; i >= 0; i--) {
      inv[i] = (ll)(i + 1) * inv[i + 1] % mod;
    }
  }
  ll C(int n, int r) const {
    if(n < 0 || r < 0 || n < r) return 0;
    return (ll) arr[n] * inv[r] % mod * inv[n - r] % mod;
  }
  ll H(int n, int r) const { return C(n + r - 1, r); }
};
/// }}}--- ///

Factorial< N, mod > fact;

ll dp[N + 1][N + 1][2]; // [i-thまでで][j個選んだ][i-thは前向きに選んだ?]

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  ll ans = 0;
  vector< int > num(n + 1);
  for(int i = 0, now = 0; i < n;
      i++, now += 2 * k, now = now >= n ? now % (2 * k) + 1 : now)
    num[i + 1] = now + 1;
  dp[0][0][0] = 1;
  for(int i = 1; i <= n; i++) for(int j = 0; j <= n; j++) {
    // 何も選ばない
    for(int t = 0; t < 2; t++) dp[i][j][0] += dp[i - 1][j][t];
    if(j >= 1) {
      if(num[i] - 2 * k >= 1) { // 前回が存在する
        // 後ろ向きに選ぶ
        if(num[i] - k >= 1) {
          dp[i][j][0] += dp[i - 1][j - 1][0];
        }
      } else {
        // 後ろ向きに選ぶ
        if(num[i] - k >= 1) {
          for(int t = 0; t < 2; t++) dp[i][j][0] += dp[i - 1][j - 1][t];
        }
      }
      // 前向きに選ぶ
      if(num[i] + k <= n) {
        for(int t = 0; t < 2; t++) dp[i][j][1] += dp[i - 1][j - 1][t];
      }
    }
    dp[i][j][0] %= mod, dp[i][j][1] %= mod;
  }
  for(int i = 0; i <= n; i++) {
    ans += (dp[n][i][0] + dp[n][i][1]) * fact[n - i] % mod * (i % 2 ? -1 : 1);
  }
  ans %= mod;
  if(ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define ll long long
#define pi pair<int,int>
#define sz size()
#define er erase
#define fr first
#define sc second
using namespace std;

int n;
double t,a,h[1005];
pair <double,int> p[1005];

int main()
{
    cin >> n >> t >> a;
    fort(i,n)
    {
        cin >> h[i];
        p[i].fr=t-h[i]*6/1000, p[i].sc=i;
    }
    sort (p+1,p+n+1);
    fort(i,n+1)
    {
        if (a>=p[i-1].fr&&a<=p[i].fr&&i<=n)
        {
            if (a-p[i-1].fr<p[i].fr-a)
            {
                cout << p[i-1].sc;
                return 0;
            }
            else
            {
                cout << p[i].sc;
                return 0;
            }
        }
        else if (i==n+1)
        {
            cout << p[i-1].sc;
            return 0;
        }
    }
}


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


int main() {
    string s;
    cin >>s;
    s[5] = ' ';
    s[13] =' ';
    cout << s<< endl;
  }

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	int GetHead(int n) {
		while (n / 10 != 0) {
			//std::cout << n << std::endl;
			n /= 10;
		}

		return n;
	}
	int GetMaxNum(int head, int tail, int digit) {
		int res = 1;
		for (int i = 0; i < digit - 1; ++i) res *= 10;
		res *= (head + 1);
		res -= 10;
		res += tail;
		return res;
	}

	int GetMinNum(int head, int tail, int digit) {
		int res = 1;
		for (int i = 0; i < digit - 1; ++i) res *= 10;
		res *= head;
		res += tail;
		return res;
	}
}


int main() {

	int n;
	std::cin >> n;

	ll ans = 0;

	for (int a = 1; a <= n; ++a) {
		//std::cout << a << " ";
		// aを決め撃ち
		// この時に当てはまるb
		int head = a % 10;
		int tail = GetHead(a);

		if (head == 0) continue;

		// よって 先頭がtailで末尾がheadのbでn以下
		// bの桁数
		int sum = 0;
		for (int digit = 1; digit <= 6; ++digit) {
			int max_num = GetMaxNum(head, tail, digit);
			int min_num = GetMinNum(head, tail, digit);

			if (digit == 1) {
				if (tail == head) ++sum;
				continue;
			}
			if (digit == 2) {
				int num = head * 10 + tail;
				if (num <= n) ++sum;
				continue;
			}
			if (max_num <= n) {
				// 間に何が入ってもよい
				int num = 1;
				for (int j = 1; j <= digit - 2; ++j) {
					num *= 10;
				}
				sum += num;
			}
			else {
				int num = n - min_num;
				if (num >= 0) sum += num / 10 + 1;
			}
		}
		ans += sum;
		//std::cout << sum << std::endl;
	}

	std::cout << ans << std::endl;


	return 0;
}

Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let n = scan "%d" id
let ls = scan_lines n "%d %d" Tuple2.make

let rec gcd a b =
  if b = 0 then a
  else gcd b (a mod b)

let () =
  let open ModOp in
  let (ks, ms) = ListL.partition ls ~f:(fun (a,b) -> a = 0 && b = 0) in
  let ms = ListL.map ms ~f:(fun (a, b) ->
      if a = 0 then (0,-1)
      else if b = 0 then (1,0)
      else
        let m = gcd (abs a) (abs b) in
        if a < 0 then (-a/m, -b/m)
        else (a/m, b/m)) in
  let h0 = Hashtbl.create n in
  let h1 = Hashtbl.create n in
  ListL.iter ms ~f:(fun (a,b) ->
      Hashtbl.modify_def 0 (a,b) succ h0;
      if b >= 0 then Hashtbl.modify_def 0 (a,b) succ h1
      else Hashtbl.modify_def 0 (-b,a) id h1);
  Hashtbl.map (fun (a,b) n ->
      let x = Hashtbl.find_default h0 (b,-a) 0 in
      pow 2 n + pow 2 x - 1) h1;
  |> Hashtbl.to_list |> List.map Tuple2.second
  |> ListL.fold_left ~init:1 ~f:( * )
  |> ((+) (List.length ks - 1))
  |> Printf.printf "%d\n"


Measured memory_bytes: 74048
#include <iostream>
#include <cstring>

using namespace std;

const int INF = -1;

int N, W;
int v[101], w[101];
int dp[101][10001];

// i???????????§???????????§???j??\????????????
int main() {
    memset(dp, 0, sizeof(dp));
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> v[i] >> w[i];
    for (int i = N-1; i >= 0; --i) {
        for (int j = 0; j <= W; ++j) {
            if (j < w[i]) dp[i][j] = dp[i+1][j];
            else dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    cout << dp[0][W] << endl;
    return 0;
}

Measured memory_bytes: 7020
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
geta = lambda fn: map(fn, readline().split())
gete = lambda fn: fn(input())

# sys.setrecursionlimit(10**5)


def main():
    S = gete(str)[::-1]
    m, mod = 13, 10**9 + 7
    prev, curr = [0] * m, [0] * m
    base = []

    s0, b = 0, 1
    for i, c in enumerate(S):
        if c == "?":
            base.append(b)
        else:
            s0 = (s0 + b * int(c)) % m
        b = (b * 10) % m
    curr[s0] = 1

    for b in base:
        prev, curr = curr, [0] * m

        for d in range(10):
            ad = d * b
            for r, p in enumerate(prev):
                curr[(r + ad) % m] += p

            for r, c in enumerate(curr):
                curr[r] = c % mod

    print(curr[5])


if __name__ == "__main__":
    main()


Measured memory_bytes: 45552
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	while(scanf("%d%d", &a, &b) != EOF){
		int c = a+b;
		int cnt = 0;
		do{
			c /= 10;
			++cnt;
		}while(c>0);
		printf("%d\n", cnt);
	}
	return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//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)
#define LOOP(n) REP(ATC_LIB_COUNTER, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


//source
//------------------------------------------

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    REP (i, n) cin >> a[i];
    REP (i, n) cin >> b[i];
    REP (i, n - 1) cin >> c[i];
    int ans {0};
    ans += accumulate(b.begin(), b.end(), 0);
    REP (i, n - 1) {
        if (a[i + 1] - a[i] == 1) ans += c[a[i] - 1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
sys.setrecursionlimit(10**9)
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
N, A, B, C = map(int, input().split())
L = []
for i in range(N):
    L.append(int(input()))
# L.sort()
def dfs(cnt, a, b, c):
    if cnt == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a,b,c) > 0 else 10**9
    r0 = dfs(cnt+1, a, b, c)
    r1 = dfs(cnt+1, a+L[cnt], b, c) + 10
    r2 = dfs(cnt+1, a, b+L[cnt], c) + 10
    r3 = dfs(cnt+1, a, b, c+L[cnt]) + 10
    return min(r0, r1, r2, r3)
    
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
/**
 * Created by Sakib on 06/04/2018.
 */
#include <bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(args...) { dbg,args; cerr<<"\n"; }
struct debugger{
template<typename T>debugger& operator,(const T& v){cerr<<v<<" ";return *this;}}dbg;

#define Fix( x ) setprecision( x ) << fixed
#define mem( a , x ) memset( a , x , sizeof( a ) )
#define bug( a , b ) cerr<< #a <<" = "<<a<<" , "<< #b <<" = "<<b<<"\n";
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define FOR( i , a , b ) for( int i = a; i <= b; i++ )
#define ROF( i , a , b ) for( int i = a; i >= b; i-- )
#define sz( V ) (int)V.size( )
#define all( V ) V.begin( ),V.end( )
#define Found( S , val ) S.find( val ) != S.end( )
#define Unique( V ) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
typedef pair < int , int > ii;
typedef pair < int , ii > iii;
typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );

int n , l;
vector <string> V;

bool cmp( string a , string b ) {
    return ( a+b < b+a );
}
int main( int argc, char const *argv[] ) {
    fast_io;
    cin >> n >> l;
    string s;
    FOR( i , 1 , n ) cin >> s , V.pb( s );
    sort( all(V) , cmp );
    for( auto x : V ) cout << x;
    return 0;
}











Measured memory_bytes: 256
#include <iostream>
#include <vector>


#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() {
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	vector<vector<int>> a(n, vector<int>(m));
	int count = 0;

	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			sum += a[i][j] * b[j];
		}
		if (sum + c > 0)count++;
	}

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int l;
int main(){
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=a+b) cout<<"No"<<endl;
	else{
		if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

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



namespace Test1 {

    class ClassMain {

        static bool[] primes = Enumerable.Repeat<bool>(true,10000001).ToArray();

        public static void makePrimes() {
            primes[0] = false; primes[1] = false;
            for (int i = 2; i < 10000000 / 2; i++) {
                if (primes[i] == false) { continue; }
                for (int j = 2; i * j <= 10000000; j++) {
                    primes[i*j] = false;
                }
            }
        }

        public static void Main(String[] args) {
            makePrimes();
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                if(n%2==0){n--;}
                for(int i = n; i>=13;i-=2){
                    if (primes[i] && primes[i - 2] && primes[i - 6] && primes[i - 8]) {
                        Console.WriteLine(i);
                        break;
                    }
                }

            }
        }


    }

}

Measured memory_bytes: 40184
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

int main () {
  int N, A, B;
  cin >> N >> A >> B;
  int t[1010];
  for (auto i = 0; i < N; i++) {
    cin >> t[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; i++) {
    if (A <= t[i] && t[i] < B) {
    } else {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();
        
        long price1 = a * x + b * y;
        long price2 = a * Long.max(0, x - y) + 2 * c * y;
        long price3 = 2 * c * x + b * Long.max(0, y - x);
        long price4 = c * 2 * Long.max(x, y);
        
        long ans = Long.min(Long.min(Long.min(price4, price3), price2), price1);
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    char a;cin>>a;
    if(a>='a' and a<='z'){
        cout<<"a";
    }
    else{
        cout<<"A";
    }
}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3796
import java.util.*;

class Main{
  public static void main(String[] args)
  {
    Scanner scanner = new Scanner(System.in);
    int[] a = new int[3];
    int[] b = new int[3];

    int iti = 0,ni=0,san=0,si =0;

    int odd=0, even=0;

    for(int i=0; i<3; i++){
      a[i] = scanner.nextInt();
      b[i] = scanner.nextInt();
    }

    for(int i=0; i<3; i++){
      if(a[i] == 1){
        iti++;
      }
      else if(a[i]==2)
      {
        ni++;
      }else if(a[i] == 3)
      {
        san++;
      }else if(a[i] == 4){
        si++;
      }

      if(b[i] == 1){
        iti++;
      }
      else if(b[i]==2)
      {
        ni++;
      }else if(b[i] == 3)
      {
        san++;
      }else if(b[i] == 4){
        si++;
      }
    }

    if(checkEven(iti)){
      even++;
    }else{
      odd++;
    }
    if(checkEven(ni)){
      even++;
    }else{
      odd++;
    }
    if(checkEven(san)){
      even++;
    }else{
      odd++;
    }

    if(checkEven(si)){
      even++;
    }else{
      odd++;
    }

      if(odd == 2 && even == 2)
      {
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }

  }

  public static boolean checkEven(int num){
    if(num %2 == 0){
      return true;
    }
    return false;
  }

}

Measured memory_bytes: 21716
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;
int main(){
    int N;
    cin>>N;
    
    for(int i=0;i<N;i++){
        stack<int> a,b;
        a.push(0);
        b.push(0);
        bool flag=true;
        for(int j=0;j<10;j++){
            int tm;
            cin>>tm;
            if(tm>a.top()) a.push(tm);
            else if(tm>b.top()) b.push(tm);
            else {flag=false;}
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

    return 0;
};

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

	public static long div = (long) (Math.pow(10, 9) + 7);

	public static long[] f = new long[1000000];
	public static long[] finv = new long[1000000];
	public static long[] inv = new long[1000000];

	public static void Init() {
		f[0] = 1;
		f[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for(int i = 2; i < 1000000; i++) {
			f[i] = f[i - 1] * i % div;
			inv[i] = div - inv[(int) div % i] * (div / i) % div;
			finv[i] = finv[i - 1] * inv[i] % div;
		}
	}

	public static long Com(int n, int k) {
		if(n < k)
			return 0;
		if(n < 0 || k < 0)
			return 0;
		return f[n] * (finv[k] * finv[n - k] % div) % div;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		if(x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		int xcnt = x - y;
		y -= xcnt;
		if(y % 3 != 0) {
			System.out.println(0);
		} else {
			xcnt += y / 3;
			int ycnt = y / 3;
			Init();
			long ans = Com(xcnt + ycnt, ycnt);
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 46676
import sys
readline = sys.stdin.readline

X,N = map(int,readline().split())
P = set(list(map(int,readline().split())))
lo = X
hi = X
while True:
  if lo not in P:
    print(lo)
    break
  lo -= 1
  if hi not in P:
    print(hi)
    break
  hi += 1

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n, 0);
  for (int i = 0; i < q; ++i) {
    int cur;
    cin >> cur;
    --cur;
    a[cur]++;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] + k > q) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	int kkt = 89;
	while (kkt) {
		vector<ll> a(30);
		ll L;
		cin >> a[0] >> L;
		if (a[0] == 0 && L == 0) break;
		for (int i = 1; i < 30; i++) {
			string s;
			ll z = L - to_string(a[i - 1]).size();
			for (int j = 0; j < z; j++) s += '0';
			s += to_string(a[i - 1]);
			sort(s.begin(), s.end());
			ll mn = stoll(s);
			reverse(s.begin(), s.end());
			ll mx = stoll(s);
			a[i] = mx - mn;
			bool flag = false;
			for (int j = 0; j < i; j++) if (a[j] == a[i]) {
				cout << j << " " << a[i] << " " << i - j << "\n";
				flag = true;
				break;
			}
			if (flag) break;
		}
	}
	return 0;

}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(S == U)  --A;
        else    --B;
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#define ll long long
#define dd long double
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>   
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>
dd pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll fact[100] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
// ll seed;
//mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits

void solve()
{
    ll n ;
    cin >> n ;
    ll ans = 0 ;
    ll arr[n] ;
    fo(i , n)
    {
        cin >> arr[i] ;
    }
    for(ll i = 1 ; i < n ; i++)
    {
        ans += max(0 , arr[i-1] - arr[i]) ;
        arr[i] = max(arr[i] , arr[i-1]) ;
    }
    cout << ans << endl ;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   /* #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif*/
    
    ll t ;
    //cin >> t ;
    t = 1 ;
   
    while(t--)
    {
        solve() ;
    }
   // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}

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

int main() {
    string s; cin>>s;
    ll bc=0, ans=0;
    rep(i,s.size()) {
        if (s[i] == 'B') bc++;
        else ans+=bc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3776