akhauriyash/Code-Regression huggingface dataset:
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let b: Vec<usize> = sc.vec(n);
    let c: Vec<usize> = sc.vec(n - 1);
    let mut result = b.iter().fold(0, |sum, b| sum + b);
    let mut pre = a[0];
    for i in 1..n {
        if pre + 1 == a[i] {
            //let idx = a[i] - pre - 1;
            result += c[pre - 1];
            //println!("{} {} {} {}", pre, a[i], i - 1, c[i - 1]);
        }
        pre = a[i];
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int edit_distance(const std::string& a, const std::string& b) {
	std::vector<std::vector<int>> memo(2, std::vector<int>(a.size() + 1, 0));
	for (auto i = 0; i <= a.size(); ++i) memo[1][i] = i;
	for (auto i = 0; i < b.size(); ++i) {
		memo[i % 2][0] = memo[(i + 1) % 2][0] + 1;
		for (auto j = 0; j < a.size(); ++j) {
			if (a[j] == b[i]) {
				memo[i % 2][j + 1] = memo[(i + 1) % 2][j];
			}
			else {
				memo[i % 2][j + 1] = std::min({ memo[(i + 1) % 2][j] + 1, memo[i % 2][j] + 1, memo[(i + 1) % 2][j + 1] + 1 });
			}
		}
	}
	return memo[(b.size() + 1) % 2].back();
}

int main() {
	std::string from, to; std::cin >> from >> to;
	std::cout << edit_distance(from, to) << std::endl;
}



Measured memory_bytes: 3204
def make_list(a, n):
    res = [1]
    i = 1
    while pow(a, i) <= n:
        res.append(pow(a, i))
        i += 1
    return res[::-1]


def find_withdraw_times(n, w):
    res = 0
    for ww in w:
        res += n // ww
        n %= ww
    return res


def main():
    n = int(input())
    answer = float("inf")
    way_6 = make_list(6, n)
    way_9 = make_list(9, n)
    for i in range(n + 1):
        answer = min(answer, find_withdraw_times(i, way_6) + find_withdraw_times(n - i, way_9))
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for(auto& s: S) cin >> s;

    ll ans = 1e9;
    for(int i=0; i<(1<<(H-1)); i++){
        bitset<10> b(i);
        ll sum = b.count();
        vector<ll> c(b.count()+1);
        bool ok = true;
        for(int j=0; j<W; j++){
            bool update = false;
            vector<ll> tmp(b.count()+1);
            for(int k=0, l=0; k<H; k++){
                if(S[k][j]=='1') tmp[l]++;
                if(b[k]) l++;
            }
            for(int k=0; k<=b.count(); k++){
                if(tmp[k] > K) ok = false;
                if(c[k]+tmp[k] > K) update = true;
            }

            if(update){
                for(int k=0; k<=b.count(); k++) c[k] = tmp[k];
                sum++;
            }
            else{
                for(int k=0; k<=b.count(); k++) c[k] += tmp[k];
            }
            // cout << "\t" << sum << " ";
            // debug(c);
        }
        // cout << b << " " << sum << endl;
        if(ok) ans = min(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
int a[100010], b[100010];
ll c[100010];
int q, k;
int x[100010], y[100010];

ll dp[100010];
vector<pair<int, ll>> G[100010];

void dfs(int u, int p, ll dist) {
	for(auto tmp : G[u]) {
		int v = tmp.fi;
		ll nd = tmp.se;
		if(v == p) continue;
		dp[v] = dist + nd;
		dfs(v, u, dist + nd);
	}
}

int main(void) {
	cin >> n;
	rep(i, n - 1) cin >> a[i] >> b[i] >> c[i];
	cin >> q >> k;
	rep(i, q) cin >> x[i] >> y[i];

	rep(i, n) G[a[i]].pb(mp(b[i], c[i])), G[b[i]].pb(mp(a[i], c[i]));
	dp[k] = 0;
	// printf("k\n");
	dfs(k, -1, 0);

	rep(i, q) {
		printf("%lld\n", dp[x[i]] + dp[y[i]]);
	}
	return 0;
}

Measured memory_bytes: 16640
import copy
H,W = list(map(int,input().split()))
F = [] #map
for i in range(H):
    a = input()
    b = []
    for j in range(W):
        if a[j] == ".":
            b.append(0)
        else:
            b.append("w")
    F.append(b)
    
#print(F)

#マップからの経路を算出する関数

s = [0,0]

def n_route(s):
    """
    F:マップ配列
    s:スタート座標
    """
    C = copy.deepcopy(F)
    P = []#点の座標配列
    nP = []
    P.append(s)
    C[s[0]][s[1]] = -1
    
    c = 1
    while P:
        #print(c)
        
        for p in P:
            #print("p=",p)
            for v in [[1,0],[0,1],[-1,0],[0,-1]]:
                np = [p[0]+v[0],p[1]+v[1]]
                #print(np)
                #行ける点があったら
                if 0<=np[0]<H and 0<=np[1]<W and C[np[0]][np[1]] == 0:
                    C[np[0]][np[1]] = c
                    #記録
                    if [np[0],np[1]] not in nP:
                        nP.append([np[0],np[1]])
        #print(nP)        
        P = []
        while nP:
            P.append(nP.pop(0))
            
        #print(C)
        #print("P:",P)
        
        c += 1
        
    return C
    
#print(n_route(s))    

Mn = [[0]*W for i in range(H)]
#print(Mn)

#Fのうち、すべての0の点でn_routeを回す。
for i in range(H):
    for j in range(W):
        if F[i][j] == 0:
            #print(i,j)
            nr = n_route([i,j])
            #print(nr)
            
            for k in range(H):
                for l in range(W):
                    if nr[k][l] != "w" and Mn[k][l] < nr[k][l]:
                        Mn[k][l] = nr[k][l]
                        
#print(Mn)

m=[]
for i in Mn:
    #print(i)
    m.append(max(i))
print(max(m))
        




    
    


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

int MOD;

struct modnum {
private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum;

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

const int MAXN = 3100;
int n;
num ncr[MAXN][MAXN];
num pp2[MAXN];
num stir[MAXN][MAXN];

void precomp() {
	const int N = 3010;
	pp2[0] = 2;
	for (int i = 1; i <= N; i++) {
		pp2[i] = pp2[i-1] * pp2[i-1];
	}
	for (int i = 0; i <= N; i++) {
		ncr[i][0] = ncr[i][i] = 1;
		for (int j = 1; j < i; j++) {
			ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
		}
	}
	stir[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		stir[i][1] = stir[i][i] = 1;
		for (int j = 2; j < i; j++) {
			stir[i][j] = stir[i-1][j-1] + num(j) * stir[i-1][j];
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	cin >> MOD;
	precomp();
	num ans = 0;
	for (int c = 0; c <= n; c++) {
		num tot = 0;
		for (int i = 0; i <= c; i++) {
			tot += stir[c+1][i+1] * pow(num(2), (n-c) * i);
		}
		tot *= pp2[n-c];
		tot *= ncr[n][c];
		if (c % 2 == 0) ans += tot;
		else ans -= tot;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 75520
import math
a,b,n,m=map(int,input().split())

n%=12
n*=30
m*=6
n+=m/60*5
ans=abs(n-m)
if ans>180:
    ans=360-ans

print(math.sqrt(a*a+b*b-2*a*b*math.cos(ans*math.pi/180)))

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    int a,b;
    cin >> a>>b;
    if (a<=8 && b<=8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vector<ll> p(100000 + 10);

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

    ll N;
    string S;
    cin >> N;

    vector<ll> A(N);
    REP(i,N){
        cin >> A.at(i);
    }
    ll Q;
    cin >> Q;
    vector<ll> B(Q),C(Q);
    REP(i,Q){
        cin >> B.at(i) >> C.at(i);
    }

    

    REP(i,N){
        p.at(A.at(i))++;
    }

    ll ans = 0;

    REP(i,N){
        ans += A.at(i);
    }

    REP(i,Q){
        ll tmp = p.at(B.at(i));
        p.at(C.at(i)) += tmp;

        ll tmp1 = (C.at(i) - B.at(i)) * tmp;

        ans += tmp1;

        cout << ans << endl;

        p.at(B.at(i)) = 0;
    }
}


Measured memory_bytes: 6348
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x[]= new int[5];
		int ret=0;
		for(int i=0;i<5;i++) {
			x[i] = sc.nextInt();
			if(x[i]==0) {
				ret = (i+1);
			}
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 35684
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (fabs(c-a)<=d) cout << "Yes" << endl;
    else if (fabs(c-b)<=d && fabs(b-a)<=d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if((A+B)%2) cout << "IMPOSSIBLE" << endl;
  else cout << (A+B)/2 << endl;
  return 0;
}

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

// 二分探索を行う関数
bool binarySearch(int key, int n, const vector<int>& A) {
    // 探索範囲の左端
    int left = 0;
    // 探索範囲の右端
    int right = n;

    while (left < right) {
        int center = (left + right) / 2;
        if (A[center] == key) {
            return true;
        }
        if (A[center] < key) {
            left = center + 1;
            continue;
        }
        right = center - 1;
    }

    if (A[left] == key || A[right] == key) {
        return true;
    }

    return false;
}

int main() {
    // 数列Sの要素数n
    int n;
    cin >> n;

    // 数列Sを格納するための配列（nの最大値+α）
    vector<int> A(100100);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    // 数列Tの要素数q
    int q;
    cin >> q;

    // 数列T内の要素を格納する変数
    int key;
    // 答えを格納する変数
    int sum = 0;

    for (int i = 0; i < q; ++i) {
        cin >> key;
        if (binarySearch(key, n, A)) ++sum;
    }

    cout << sum << endl;

    return 0;
}


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

#累積和で受け取る
A = [0] * N
S = 0
for i, a in enumerate(input().split()):
    S += int(a)
    A[i] = S

answer = S

#indexは最後に回収する番号
B = 0
D = 0

for C in range(1, N - 2):
    D = max(D, C + 1)
    SB = A[B]
    SC = A[C] - A[B]
    SD = A[D] - A[C]
    SE = S - A[D]
    left_score = abs(SB - SC)
    #BCの境界の調整
    while True:
        B_ = B + 1
        SB_ = A[B_]
        SC_ = A[C] - SB_
        x = abs(SB_  - SC_)
        if left_score > x:
            B, SB, SC, left_score = B_, SB_, SC_, x
            continue
        break

    right_score = abs(SE - SD)
    while True:
        D_ = D + 1
        SD_ = A[D_] - A[C]
        SE_ = S - A[D_]
        x = abs(SD_ - SE_)
        if right_score > x:
            D, SD, SE, right_score = D_, SD_, SE_, x
            continue
        break

    score = max(SB, SC, SD, SE) - min(SB, SC, SD, SE)
    answer = min(score, answer)
print (answer)


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

int main()
{	
	int n;
	
	cin >> n;
	
	while (n > 0) {
		string s;
		int m = 1, u = 1, f = 2, r = 3, t;

		for (int i = 0; i < n; i++) {
			cin >> s;

			if (s == "North") {
				t = u;
				u = f;
				f = 7 - t;
			}
			else if (s == "East") {
				t = u;
				u = 7 - r;
				r = t;
			}
			else if (s == "West") {
				t = u;
				u = r;
				r = 7 - t;
			}
			else if (s == "South") {
				t = u;
				u = 7 - f;
				f = t;
			}
			else if (s == "Right") {
				t = f;
				f = r;
				r = 7 - t;
			}
			else if (s == "Left") {
				t = f;
				f = 7 - r;
				r = t;
			}

			m += u;
		}

		cout << m << endl;
		
		cin >> n;
	}
	
	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int a, b;
	cin >> a >> b;

	int ans = 0;
	for(int i = a; i <= b; i++){
		string s = to_string(i);
		string srev = s;
		reverse(srev.begin(), srev.end());
		bool chk = true;
		rep(i, s.size()){
			if(s[i] != srev[i]) chk = false;
		}
		if(chk) ans++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b){
  if(b==0){
    return a;
  } else {
    return gcd(b,a%b);
  }
}

int main(){
  int a,b,tmp;
  scanf("%d %d",&a,&b);
  if(a<b){
    tmp=b;
    b=a;
    a=tmp;
  }
  tmp=gcd(a,b);
  printf("%ld",(long)a*b/tmp);
}


Measured memory_bytes: 128
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        private static long mod = 1000000007;
        private static long[] fac;
        private static long[] inv;
        private static long[] facInv;
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();

            long duplicate = -1;
            var hashSet = new HashSet<long>();
            foreach(var a in line)
            {
                if(hashSet.Contains(a))
                {
                    duplicate = a;
                    break;
                }
                hashSet.Add(a);
            }
            
            var first = -1;
            var second = -1;
            for(var i = 0; i < line.Length; i++)
            {
                if (line[i] != duplicate)
                {
                    continue;
                }
                if(first == -1)
                {
                    first = i;
                }
                else
                {
                    second = i;
                    break;
                }
            }

            var exclusionNum = second - first + 1;

            Init(n + 1);
            var answers = new List<long>();
            answers.Add(n);

            for(var i = 2; i <= n + 1; i++)
            {
                var num = Combination(n + 1, i);
                num -= Combination(n + 1 - exclusionNum, i - 1);
                if(num < 0)
                {
                    num += mod;
                }
                answers.Add(num);
            }

            answers.ForEach(value => WriteLine(value));
        }

        private static void Init(int n)
        {
            fac = new long[n + 1];
            inv = new long[n + 1];
            facInv = new long[n + 1];
            fac[0] = fac[1] = 1;
            facInv[0] = facInv[1] = 1;
            inv[1] = 1;
            for(var i = 2; i < n + 1; i++)
            {
                fac[i] = fac[i - 1] * i % mod;
                inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                facInv[i] = facInv[i - 1] * inv[i] % mod;
            }
        }

        private static long Combination(int n, int k)
        {
            if(n < 0 || k < 0)
            {
                return 0;
            }
            if(n < k)
            {
                return 0;
            }
            return fac[n] * (facInv[k] * facInv[n - k] % mod) % mod;
        }
    }
}


Measured memory_bytes: 43100
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;


using namespace std;

int main() {

	SINT32 A = 0;
	SINT32 B = 0;

	cin >> A;
	cin >> B;

	cout << 100 << " " << 100 <<endl;
	A--;
	B--;
	rep(i,0,50) {
		rep(j,0,100) {
			if (A != 0) {
				if (((i % 2) == 1) && ((j % 2) == 1)) {
					A--;
					cout << ".";
				} else {
					cout << "#";
				}
			} else {
				cout << "#";
			}
		}
		cout << endl;
	}

	rep(i,0,50) {
		rep(j,0,100) {
			if (B != 0) {
				if (((i % 2) == 1) && ((j % 2) == 1)) {
					B--;
					cout << "#";
				} else {
					cout << ".";
				}
			} else {
				cout << ".";
			}
		}
		cout << endl;
	}
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n;
  cin >> n;
  vi32 x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  function<f80(int, int)> dist = [&](int i, int j) {
    return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
  };
  f80 ans = 0;
  rep(i, n) rep(j, n) {
    if (i == j) continue;
    ans += dist(i, j);
  }
  ans /= n;
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(s[0] != 'B' || s[2 * n - 1] != 'B'){
		cout << 0 << endl;
		return 0;
	}
	string res = "";
	res += 'L';
	repn(i, 1, 2 * n){
		if(s[i] == s[i - 1]){
			if(res[res.size() - 1] == 'L') res += 'R';
			else res += 'L';
		}
		else{
			res += res[res.size() - 1];
		}
	}
	ll ans = 1LL;
	ll l1 = 0, r1 = 0;
	rep(i, 2 * n){
		if(res[i] == 'L') l1++;
		else (ans *= l1 - r1) %= MOD, l1--;
	}
	if(l1){
		cout << 0 << endl;
		return 0;
	}
	repn(i, 1, n + 1) (ans *= i) %= MOD;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 916
import sys
input=sys.stdin.readline
N,A,B=map(int,input().split())

hlist=[]
for i in range(N):
  hlist.append(int(input()))
mh=max(hlist)
#print(mh,hlist)

def isOK(m):
  if m==0:
    return False
  
  hlist2=list(hlist)
  for i in range(N):
    hlist2[i]-=m*B
  #print(m,hlist2)
  if max(hlist2)<=0:
    return True
  
  cnt=0
  for i in range(N):
    if hlist2[i]>0:
      cnt+=-(-hlist2[i]//(A-B))
  return cnt<=m

l,r=1,mh//B+1
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  if not isOK(mid-1) and isOK(mid):
    print(mid)
    break
  elif isOK(mid-1):
    r=mid-1
  else:
    l=mid+1

Measured memory_bytes: 60456
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll x;
	cin >> x;
	vector<ll> dp(100000+1,0);
	dp[100] = 1;
	dp[101] = 1;
	dp[102] = 1;
	dp[103] = 1;
	dp[104] = 1;
	dp[105] = 1;
	if(x > 105){
		for(int i = 106; i <= x; i++) {
			for(int j = 0; j <= 5; j++) {
				dp[i] = max(dp[i - j  -100],dp[i]);
			}
		}
	}
	cout << dp[x] << endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
A = list("abcdefghijklmnopqrstuvwxyz")
B = [50]*26
for i in range(n):
    C = [0]*26
    s = input()
    s = sorted(s)
    for j in range(len(s)):
        for k in range(26):
            if s[j] == A[k]:
                C[k] += 1
                break
    for m in range(26):
        B[m] = min(B[m],C[m])

D = [] 
for i in range(26):
    D.append(A[i]*B[i])
D.sort()
print(*D, sep = "")

Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using ullong = unsigned long long;

struct value {
    int index;
    int discount;
    value(int i, int d) : index(i), discount(d) { }
};

//discountに従って降順に処理したい
bool operator< (const value &a, const value &b) {
    return a.discount < b.discount;
}

inline int pow2(int n) {
    if (n == 0) return 1;
    int x = 1;
    int cnt = 0;
    while (cnt < n) {
        x *= 2;
        ++cnt;
    }
    return x;
}


int main() {

    int N, M;
    cin >> N >> M;

    ullong valueTotal = 0;
    vector<int> A(N);
    for (auto &a: A) {
        cin >> a;
        valueTotal += a;
    }

    priority_queue<value, vector<value>, less<value>> PQ;
    for (int i=0; i<N; i++) {
        // 0枚から1枚への変更で安くなる金額
        int Discount = A[i] - A[i]/2;
        PQ.push(value(i, Discount));
    }

    int numTotal = 0;
    ullong dTotal = 0;
    vector<int> numEach(N, 0);

    while (numTotal < M) {
//    while (PQ.size() > 0)  {

        value elm = PQ.top();
        PQ.pop();
        //cout << elm.index << ' ' << elm.discount << endl;
        dTotal += elm.discount;
        if (dTotal >= valueTotal) {
            cout << 0 << endl;
            return 0;
        }

        ++numEach[elm.index];
        int num = numEach[elm.index];
        // n枚からn+1枚への変更で安くなる金額
        elm.discount = A[elm.index] / pow2(num) - A[elm.index] / pow2(num+1);
        PQ.push(elm);
        ++numTotal;
    }

    ullong cost = 0;
    for (int i=0; i<N; i++) {
        cost += A[i] / pow2(numEach[i]);
    }
    cout << cost << endl;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,M,C;
  cin>>N>>M>>C;
  vector<ll> B(M);
  for(ll i=0;i<M;i++) {
cin>>B[i];
  }
  ll ans=0;
  for(ll i=0;i<N;i++) {
    ll sum=C;
for(ll j=0;j<M;j++) {
  ll A;
  cin>>A;
  sum+=A*B[j];
}
    
    if(sum>0) {
ans++;
    }
  }
  
  cout<<ans<<endl;
}
  
  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
int get (int n) {
	int ans = 0;
	while (n) {
		ans += n / 5;
		n /= 5;
	}
	return ans;
}
int n;
void solve() { 
	cin >> n;
	if (n % 2 == 1 or n == 0) {
		cout << 0;
		return;
	}	
	n /= 2;
	cout << get(n);
}


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

int main()
{
	string s;
	int w;
	cin >> s >> w;
	string ans;
	for (int i = 0; i * w < s.size(); i++)
	{
		ans += s[i * w];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#coding=UTF-8

mozir=input()
hyo=mozir.split(' ')
Height=int(hyo[0])
Width=int(hyo[1])

N=int(input())

mozir=input()
hyo=mozir.split(' ')
kosuu=[int(mono) for mono in hyo]

color_ptr=0
cnt=0
#牛耕式にすればいいのでは
muki='R'
for tate in range(0,Height,1):
    demoji=''
    for yoko in range(0,Width,1):
        if muki=='R':
            demoji=demoji+str(color_ptr+1)+' '
        else:
            demoji=str(color_ptr+1)+' '+demoji
        #incremention
        cnt+=1
        if cnt == kosuu[color_ptr]:
            color_ptr+=1
            cnt=0

    print(demoji[0:len(demoji)-1])
    muki='R' if muki=='L' else 'L'


Measured memory_bytes: 3316
N, K = map(int, input().split())
X = list(map(int, input().split()))

ub = 10 ** 9 + 7
lb = 0
while ub - lb > 1:
    mid = (ub + lb) // 2

    cnt = 0
    for v in X:
        cnt += -(-v // mid) - 1

    if cnt <= K:
        ub = mid
    else:
        lb = mid

print(ub)


Measured memory_bytes: 104172
n = int(input())
x_tmp = input().split()
x = [[0 for j in range(3)] for i in range(n)]
for i in range(n):
    x[i][0] = int(x_tmp[i])
    x[i][1] = i
x = sorted(x, key=lambda y: y[0])
mid = n//2
for i in range(n):
    if i <= mid-1:
        x[i][2] = x[mid][0]
    else:
        x[i][2] = x[mid-1][0]
x = sorted(x, key=lambda y: y[1])
for i in range(n):
    print(x[i][2])


Measured memory_bytes: 60564
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	ll x;
	cin>>x;
	ll i=0;
	ll sum=100;
	while(1)
	{
		if(floor(sum)>=x)
		{
			cout<<i;break;
		}
		sum+=sum/100;
		i++;
	}
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

using namespace std;

long int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<long int> a(n);

    long int all = 0;

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

        all += a[i];
        all %= MOD;
    }

    long int ans = 0;

    for(int i = 0; i < n; ++i){
        all -= a[i];

        if(all < 0) all += MOD;

        ans += (all * a[i]) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

#define ll long long
#define ld long double
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

struct edge
{
    int to;
    int id;
};

vector<vector<edge> > g;
vector<int> ans;

void dfs(int v,int c = -1,int p = -1)
{
    int k=1;
    rep(i,g[v].size())
    {
        int to = g[v][i].to, ei = g[v][i].id;
        if (to == p)
        {
            continue;
        }
        if (k==c)
        {   
            k++;
        }
        ans[ei] = k;
        k++;
        dfs(to,ans[ei],v);
    }    
}

int main()
{
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    rep(i,n-1)
    {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back((edge){b,i});
        g[b].push_back((edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n)
    {
        mx = max(mx,sz(g[i]));
    }
    cout << mx << endl;
    rep(i,n-1)
    {
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define int long long

int dp[55][55][2505];

signed main() {
	int n, a;
	cin >> n >> a;
	int x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= 2500; k++) {
				if (x[i] <= k && j >= 1) {
					dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]];
				} else {
					dp[i + 1][j][k] = dp[i][j][k];
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		ans += dp[n][i][i * a];
	}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 54400
#include<stdio.h>
#include<stdlib.h>
#define MAX 100

int main()
{
  int N,A[MAX],i,j,minj,count=0,temp,k;

  scanf("%d",&N);
  if( N < 1 || MAX < N ) exit(2);

  for( i = 0 ; i < N ; i++ )
    {
      scanf("%d",&A[i]);
      if( A[i] < 0 || MAX < A[i] ) exit(3);
    }

  for( i = 0 ; i < N ; i++ )
    {
      minj=i;
      for( j = i+1 ; j < N ; j++ )
	{
	  if( A[j] < A[minj] )
	    minj = j;
	}
      if( i != minj )
	{
      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;
      count++;
	}
 }


  for( i = 0 ; i < N-1 ; i++ )
    {
      printf("%d ",A[i]);
    }
  printf("%d\n%d\n",A[i],count); 


  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e5+7;
int T,n,m;
int a[N];
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    rep(i,0,len){
        if(s[i]=='1')
            putchar('9');
        else if(s[i]=='9')
            putchar('1');
        else
            printf("%c", s[i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 256
s = rstrip(readline())

if s[1] != 'A'
    println("WA")
    quit()
end

if s[2] < 'a' || 'z' < s[2]
    println("WA")
    quit()
end

C = false
for i = 3:endof(s)-1
    if s[i] =='C'
        if C
            println("WA")
            quit()
        else
            C = true
        end
    elseif s[i] < 'a' || 'z' < s[i]
        println("WA")
        quit()
    end
end

if !C || s[end] < 'a' || 'z' < s[end]
    println("WA")
    quit()
end

println("AC")

Measured memory_bytes: 108344
import java.util.*;

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

    int N = sc.nextInt();
    String str = sc.next();
    int min_count = N;
    int count;

    String str1 = str.substring(1);
    count = str1.length() - str1.replaceAll("E", "").length();
    min_count = Math.min(min_count, count);

    for (int i=1; i < N; i++) {
      if (str.substring(i-1, i).equals("W") && str.substring(i, i+1).equals("W")) {
        count++;
      }

      if (str.substring(i-1, i).equals("E") && str.substring(i, i+1).equals("E")) {
        count--;
      }

      min_count = Math.min(min_count, count);
    }

    System.out.println(min_count);
  }
}


Measured memory_bytes: 54592
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
int dp[1<<21];
int cnt[21][100010];
int ccnt[21];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string n;cin>>n;
    int ans=0;bool abc=1;
    for(int i=n.length()-1;i>=1;i--){
        if(n[i]!='9')abc=0;
        ans+=9;
    }
    if(abc==0)ans+=n[0]-'0'-1;
    else ans+=n[0]-'0';
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n, k; cin >> n >> k;
    pair<ll, ll> ab[n];
    for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
    sort(ab, ab + n);
    ll cnt  = 0, i = 0, ans;
    while (cnt < k) {
        cnt += ab[i].second;
        ans = ab[i].first;
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<String> W = new ArrayList<String>();
        String preWordEnd = new String();
        boolean ans = true;
        for(int i = 0; i < N; i++){
            String s = sc.next();
            if(i != 0){
                if(W.contains(s) || !s.startsWith(preWordEnd)) {
                    ans = false;
                    break;
                }
            }
            W.add(s);
            preWordEnd = s.substring(s.length()-1, s.length());
        }
        if(ans) System.out.println("Yes");
        else System.out.println("No");
        sc.close();

    }

}


Measured memory_bytes: 24916
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ll long long
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	const ll INF = 1e9;
	
	int N, K;
	cin >> N >> K;
	vector<ll> h(N);
	REP(i, N) cin >> h.at(i);
	vector<ll> dp(N+1, INF);
	dp[0] = 0;
	dp[1] = abs(h.at(0) - h.at(1));
	FOR(i, 2, N) {
		FOR(j, 1, min(K, i)+1) {
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
		}
	}
	//print_array(dp);
	cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
N = int(input())
a = [int(input()) for _ in range(N)]
ans = sum(a)
if ans % 10 == 0:
    if all([i % 10 == 0 for i in a]):
        print(0)
    else:
        ans -= min([i for i in a if i % 10 != 0])
        print(ans)
else:
    print(ans)

Measured memory_bytes: 3060
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: isize = iterator.next().unwrap().parse().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();
    let c: isize = iterator.next().unwrap().parse().unwrap();
    let mut k: isize = iterator.next().unwrap().parse().unwrap();

    if k < a {
        return k.to_string();
    }

    if a + b >= k {
        return a.to_string();
    }

    return (a - (k - a - b)).to_string();
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int maxn=1e5+10;
const int maxm=4e5+10;

int n,m,size,col[maxn],Point,BG,UBG;
int tote,FIR[maxn],TO[maxm],NEXT[maxm];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

bool search(int u)
{
	bool flag=1;
	size++;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (!col[v])
			col[v]=3-col[u],flag&=search(v);
		else
			flag&=col[u]+col[v]==3;
	}
	return flag;
}

int main()
{
#ifdef h10
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	for (i=1;i<=n;i++)
		if (!col[i])
		{
			size=0; col[i]=1;
			if (search(i))
				size==1?Point++:BG++;
			else
				size==1?Point++:UBG++;
		}
	printf("%lld\n",2ll*Point*n-(LL)Point*Point+((LL)BG+UBG)*(BG+UBG)+(LL)BG*BG);
}


Measured memory_bytes: 6912
a,b = map(int,input().split())
if b%1000 != 0:
  print('-1 -1 -1')
else:
  d = 0
  s = b//1000 - a
  for x in range(s//9+1):
    if d > 0:
      break
    for y in range(min((s-9*x)//4,a-x)+1):
      if 9*x + 4*y == s:
        print(x,y,a-x-y)
        d += 1
        break
  if d == 0:
    print('-1 -1 -1')

Measured memory_bytes: 3064