akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstring>

const int MaxN = 5000;
const int Mod = 1000000007;

int N, A, B;
int F[MaxN + 5][2], G[MaxN + 5][2];

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }
inline void inc(int &x, int y = 1) { (x += y) >= Mod ? x -= Mod : 0; }
inline int pw(int x, int y) { int z = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) z = mul(z, x); return z; }

void init() {
  scanf("%d %d %d", &N, &A, &B);
  if (A > B) std::swap(A, B);
}

void solve() {
  G[0][0] = 1;
  for (int i = 1; i < B; ++i) {
    for (int j = A; j <= i; ++j)
      G[i][0] = add(G[i][0], G[i - j][1]);
    for (int j = 1; j <= i; ++j)
      G[i][1] = add(G[i][1], G[i - j][0]);
  }
  for (int i = 1; i <= N; ++i) {
    F[i][0] = i < A;
    for (int j = 1; j < A && j < i; ++j)
      F[i][0] = add(F[i][0], F[i - j][1]);
    F[i][1] = add(G[i][0], G[i][1]);
    for (int j = 1; j < B && j < i; ++j)
      F[i][1] = add(F[i][1], mul(F[i - j][0], G[j][1]));
  }
  int ans = add(F[N][0], F[N][1]);
  for (int j = 1; j < B; ++j)
    ans = add(ans, mul(F[N - j][0], G[j][0]));
  printf("%d\n", sub(pw(2, N), ans));
}

int main() {
  init();
  solve();
  return 0;
}

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

int n;
vector<int> T(100005),P(100005),X(100005);
int m;

int main(){
    cin >> n;
    T.resize(n);
    
    for(int i=0;i<n;i++)
        cin >> T[i];
    
    cin >> m;
    
    P.resize(m);
    X.resize(m);

    for(int i=0;i<m;i++){
        cin >> P[i] >> X[i];
        vector<int> tmp(T);

        tmp[P[i]-1]=X[i];
        int sum=accumulate(tmp.begin(),tmp.end(),0);

        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 1408
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val x = nextInt()
    println(when (x) {
        3 -> "YES"
        5 -> "YES"
        7 -> "YES"
        else -> "NO"
    })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33780
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

void resolve() {
    string s;
    cin >> s;
    string t;
    REP(i,0,s.size()) if (s[i] != 'x') t += s[i];
    int l = 0, r = s.size()-1;
    int cnt = 0;
    while (l < r) {
        if (s[l] == s[r]) {
            ++l; --r;
        } else if (s[l] == 'x') {
            ++cnt;
            ++l;
        } else if (s[r] == 'x') {
            ++cnt;
            --r;
        } else {
            cout << -1 << endl;
            return;
        }
    }
    cout << cnt << endl;
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())

from collections import Counter
d = Counter(a+b)
if max(d.values()) > n:
    print("No")
    exit()

same = set(i for i in range(n) if a[i]==b[i])
from random import randrange
while same:
    i = same.pop()
    while True:
        j = randrange(0,n)
        if a[j] != b[i] and a[i] != b[j]:
            b[i],b[j] = b[j],b[i]
            same.discard(j)
            break

print("Yes")
print(*b)


Measured memory_bytes: 150732
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}




int main(void) {
	ll n; cin >> n;
	vector<ll> v(n);
	rep(i, n)cin >> v[i];
	ll cnt = 1;
	ll bre = 0;
	rep(i, n) {
		if (v[i] != cnt) {
			bre++;
		}
		else {
			cnt++;
		}
	}
	if (cnt == 1)cout << -1 << endl;
	else cout << bre << endl;	
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int A = a * 10 + b + c;
		int B = a + b * 10 + c;
		int C = a + b + c * 10;

		if (A >= B && A >= C) {

			System.out.println(A);

		} else if (B >= A && B >= C) {

			System.out.println(B);

		} else {

			System.out.println(C);

		}

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    
    int n;
    string s;
    int cac = 0, cwa = 0, ctle = 0, cre = 0;
    cin >> n;
    while(n--){
        cin >> s;
        if(s == "AC"){
            cac++;
        }
        else if(s == "WA"){
            cwa++;
        }
        else if(s == "TLE"){
            ctle++;
        }
        else{
            cre++;
        }
    }
    cout << "AC x" << " " << cac << endl;
    cout << "WA x" << " " << cwa << endl;
    cout << "TLE x" << " " << ctle << endl;
    cout << "RE x" << " " << cre << endl;

    return 0;
}

Measured memory_bytes: 3664
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int d[100];
	long long sum = 0;
	//int c[100];

	for(int i=0; i<n;i++)
	{
		cin >> d[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j) continue;
			sum += d[i] * d[j];
		}
	}
	sum /= 2;
	cout << sum;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

const int MAX = 100010;

int cats[MAX];

void solve(void){
    int N, mn, mx; cin >> N;
    rep(N, i) scanf("%d ", &cats[i]);
    sort(cats, cats+N);
    mn = cats[0], mx = cats[N-1];
    if (mx-mn >= 2) {
        cout << "No" << endl;
        return;
    }
    if (mx == mn) {
        cout << ((N-1==mx || 2*mx <= N)?"Yes":"No") << endl;
        return;
    }
    int x = count(cats, cats+N, mn);
    cout << ((x+1<=mx && (N-x)/2==(mx-x))?"Yes":"No") << endl;
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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

long long com(long long n,long long k){
	
}
long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}
class G{
	long long node;
	long long w;
	
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N,M;
	cin>>N;
	long long ans=0;
	for(int i=0;i<N;i++){
		long long a;
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;
}

	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll 			long long
#define vl 			vector<ll>
#define vi 			vector<int>
#define pi 			pair<int,int>
#define pl 			pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define trace(x) 	cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;
int s(int a,int b){
	string aa,bb;
	aa=to_string(a);
	bb=to_string(b);
	int ret=0;
	for(int i=0;i<aa.length();i++){
		ret+=(aa[i]-'0');
	}
	for(int i=0;i<bb.length();i++){
		ret+=(bb[i]-'0');
	}
	return ret;
}

int main()
{
	fast_io;
	int n;
	cin>>n;
	int ans=1e9+7;
	for(int i=1;i<n;i++){
		int a=i;
		int b=n-i;
		ans=min(s(a,b),ans);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

#[derive(Debug, Clone)]
struct FlowEdge {
    to: usize,
    cap: u64,
    rev: usize,
}

fn main() {
    input!(n: usize, a: [i64; n]);
    let mut g = vec![vec![]; n + 2];
    fn insert(u: usize, v: usize, cap: u64, g: &mut [Vec<FlowEdge>]) {
        let lu = g[u].len();
        let lv = g[v].len();
        g[u].push(FlowEdge {
            to: v,
            cap,
            rev: lv,
        });
        g[v].push(FlowEdge {
            to: u,
            cap: 0,
            rev: lu,
        });
    }
    let s = 0;
    let t = n + 1;
    for i in 1..=n {
        for j in std::iter::successors(Some(2 * i), |x| Some(x + i)).take_while(|&x| x <= n) {
            insert(j, i, std::u64::MAX, &mut g);
        }
        let x = a[i - 1];
        if 0 < x {
            insert(s, i, x as u64, &mut g);
        }
        if x < 0 {
            insert(i, t, (-x) as u64, &mut g);
        }
    }

    let mut flow = 0;
    loop {
        let mut dist = vec![std::usize::MAX; n + 2];
        dist[s] = 0;
        let mut queue = std::collections::VecDeque::from(vec![s]);
        while let Some(from) = queue.pop_front() {
            for &FlowEdge { to, cap: _, rev: _ } in g[from].iter().filter(|&e| e.cap != 0) {
                if dist[to] != std::usize::MAX {
                    continue;
                }
                dist[to] = dist[from] + 1;
                queue.push_back(to);
            }
        }

        fn dfs(
            from: usize,
            d: u64,
            g: &[Vec<FlowEdge>],
            dist: &[usize],
            path: &mut Vec<FlowEdge>,
        ) -> u64 {
            if from == g.len() - 1 {
                return d;
            }
            for &FlowEdge { to, cap, rev } in g[from]
                .iter()
                .filter(|&&FlowEdge { to, cap, rev: _ }| dist[from] + 1 == dist[to] && cap != 0)
            {
                let e = dfs(to, d.min(cap), g, dist, path);
                if e != 0 {
                    path.push(FlowEdge { to, cap, rev });
                    return e;
                }
            }
            0
        }
        let mut path = Vec::new();
        let e = dfs(
            s,
            std::u64::MAX,
            g.as_mut_slice(),
            dist.as_slice(),
            &mut path,
        );

        for FlowEdge { to, cap: _, rev } in path {
            g[to][rev].cap += e;
            let FlowEdge {
                to: from,
                cap: _,
                rev: i,
            } = g[to][rev];
            g[from][i].cap -= e;
        }
        flow += e;

        if e == 0 {
            break;
        }
    }

    println!("{}", a.iter().map(|&x| x.max(0)).sum::<i64>() - flow as i64);
}


Measured memory_bytes: 2220
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    bool is=false;
    int si;
    if(S.size()>=T.size()){
        for(int i=0;i<=S.size()-T.size();i++){
            string tmp="";
            string splitS=S.substr(i,T.size());
            REP(k,splitS.size()){
                if(splitS[k]!=T[k]&&splitS[k]!='?')break;
                if(k==splitS.size()-1){
                    is=true;
                    si=i;
                }
            }
        }
    }
    if(is){
        int a=0;
        REP(i,S.size()){
            if(i>=si&&i<si+T.size()){
                cout<<T[a];
                a++;
            }
            else cout<<(S[i]=='?'?'a':S[i]);
        }
        cout<<endl;
    } else {
        cout<<"UNRESTORABLE"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    int max = 0;
    int ans = 0;

    rep(i, n)
    {
        if (h[i] >= max)
        {
            ans++;
            max = h[i];
        }
    }

    cout << ans << endl;
    
}

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

int n;
int a[100010];
int main(){
    cin >> n;

    int mi = INT_MAX;
    int mii;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(mi > a[i]){
            mi = a[i];
            mii = i;
        }
    }

    while(1){
        int mi2 = INT_MAX;
        for(int i = 0;i < n;i++){
            if(a[i] % mi != 0){
                if(mi2 > a[i] % mi){
                    mi2 = a[i] % mi;
                    mii = i;
                }
            }
        }

        if(mi2 == INT_MAX){
            cout << mi << endl;
            return 0;
        }else{
            mi = mi2;
            //a[mii] = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> a(n,0);
    for(ll i=0;i<q;i++){
	ll tmp;
	cin>>tmp;
	a[tmp-1]++;
    }
    for(ll i=0;i<n;i++){
	if(a[i]+k>q ){
	    cout<<"Yes"<<endl;
	}else{
	    cout<<"No"<<endl;
	}
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	string s;
	cin>>s;
	
	int ans=0;
	for(char c:s){
		if(c=='1') ans++;
	}
	
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int n;
    cin >> n;
    VI a(n,0);
    rep(i,n) {
        cin >> a[i];
    }
    VI b(n+1,0);
    for(int i = 1;i<=n;i++) {
        b[a[i-1]] = i;
    }

    for(int i = 1;i <= n;i++) {
        cout << b[i] << " ";
    }
    cout << endl;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    deque<int> q;
    bool fore = true;
    rep(i, n) {
        int a; cin >> a;
        if(fore) q.push_back(a);
        else q.push_front(a);
        fore = !fore;
    }
    while(!q.empty()) {
        int x;
        if(fore) {
            x = q.front();
            q.pop_front();
        } else {
            x = q.back();
            q.pop_back();
        }
        cout << x << endl;
    }
}


Measured memory_bytes: 2944
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

i64 a,b;
cin>>a>>b;
if(b==1)
cout<<0;
else
cout<<a-b<<endl;


    return 0;
  }


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

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

int main(){
    int n,k;
    cin>>n>>k;
    int p[1000];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    sort(p,p+n);
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=p[i];
    }
    cout<<sum<<endl;

    return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
string s;

int main()
{
    _FastIO;
    cin >> n;
    cin >> s;
    if(n >= 3200 && s != "red"){
        cout << s << endl;
    }
    else
        cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}


fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

	let n = read::<i64>(s);
	let mut m = 1i64;
	for _ in 0..n {
		m = (m * 10) %  (1000000000+7);
	}
	m += 5*(1000000000+7);
	let mut m8 = 1i64;
	for _ in 0..n {
		m8 = (m8 * 8) % (1000000000+7);
	}
	let mut m9 = 1i64;
	for _ in 0..n {
		m9 = (m9 * 9) % (1000000000+7);
	}
	m9 +=  1000000000+7 ;	
	

	let x = (m - ( m9*2 - m8)  ) %  (1000000000+7);

//	println!("m={} m8={} m9={}", m, m8, m9);
	println!("{} ", x);


}



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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
 
 int d,t,s;
 cin>>d>>t>>s;
 if(d<=s*t){
     cout<<"Yes"<<endl;
 }
 else{
     cout<<"No"<<endl;
 }


}

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

int main() {
	int a;
	int max=0;
	int data[101]={0};


	while(cin>>a){
		data[a]++;
	}
	for (int i = 1; i <= 100; ++i) {
		if(max<data[i])max=data[i];
	}
	for (int i = 1; i <= 100; ++i) {
			if(data[i]==max)cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }

const int nax = 2005;
vector<int> edges[nax];
int parent[nax];
int h[nax];
vector<pair<int,int>> up[nax];
pair<int,int> query[nax];
set<int> dirs[nax];

void dfs(int a) {
	for(int b : edges[a]) {
		if(b != parent[a]) {
			parent[b] = a;
			h[b] = h[a] + 1;
			dfs(b);
		}
	}
}

int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1);
	for(int id = 0; id < q; ++id) {
		int a, b;
		scanf("%d%d", &a, &b);
		query[id] = {a, b};
		while(a != b) {
			if(h[a] > h[b]) {
				up[a].emplace_back(id, 0);
				a = parent[a];
			}
			else {
				up[b].emplace_back(id, 1);
				b = parent[b];
			}
		}
	}
	for(int a = 1; a <= n; ++a) {
		debug() << imie(a) imie(up[a]);
	}
	int answer = 0;
	for(int a = 2; a <= n; ++a) {
		answer += min(2, (int) up[a].size());
	}
	printf("%d\n", answer);
	while(true) {
		bool done = false;
		for(int rep = 0; rep < 2 && !done; ++rep) {
			for(int a = 2; a <= n; ++a) {
				if((rep == 1 && (int) up[a].size() >= 1)
				|| (rep == 0 && (int) up[a].size() == 1 && (int) dirs[a].size() == 1)) {
					done = true;
					int must_be = 0;
					if((int) dirs[a].size() == 1) {
						must_be = *dirs[a].begin() ^ 1;
					}
					int path_id = up[a][0].first;
					int path_dir = up[a][0].second;
					if(path_dir != must_be) {
						swap(query[path_id].first, query[path_id].second);
					}
					debug() << imie(rep) imie(path_id) imie(query[path_id]);
					for(int b = 2; b <= n; ++b) {
						for(int i = 0; i < (int) up[b].size(); ++i) {
							if(up[b][i].first == path_id) {
								dirs[b].insert(up[b][i].second ^ (path_dir ^ must_be));
								swap(up[b][i], up[b].back());
								up[b].pop_back();
							}
						}
					}
					break;
				}
			}
		}
		if(!done) {
			break;
		}
	}
	for(int id = 0; id < q; ++id) {
		printf("%d %d\n", query[id].first, query[id].second);
	}
}


Measured memory_bytes: 16912
main = getContents >>= mapM_ print . map (calc . words) . takeWhile (not . elem '?') . lines
calc [a,op,b] = let
	a' = read a
	b' = read b
	in case op of
		"+" -> a' + b'
		"-" -> a' - b'
		"*" -> a' * b'
		"/" -> a' `div` b'

Measured memory_bytes: 4084
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

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

    vector<ll> cp;
    cp.push_back(0);
    cp.push_back(a[1]);
    for(int i = 2; i <= n; i++){
        if(a[i] != a[i-1]){
            cp.push_back(a[i]);
        }
    }

    n = cp.size() - 1;
    a = cp;

    vector<ll> x(2*100000 + 1,0);

    vector<ll> dp(n+1,0);
    dp[0] = 1;

    for(int i = 1; i < n+1; i++){
        dp[i] = dp[i-1];
        if(x[a[i]] > 0){
            dp[i] += dp[x[a[i]]];
            dp[i] %= MOD;
        }
        x[a[i]] = i;
    }

    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  if(n==1){
    cout<<"Hello World"<<endl;
  }else{
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n;
	int b, f, r, v;
	int i, j, k;

	int tenants[4][3][10] = { { {} } };

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		tenants[b - 1][f - 1][r - 1] += v;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; ++k) {
				printf(" %d", tenants[i][j][k]);
			}
			printf("\n");
		}
		if (i != 3) printf("####################\n");
	}

	return 0;
}


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

int main(){
	
	string s;
	while(getline(cin,s)){
		for(int i=0;i<s.size();i++)if('a'<=s[i]&&s[i]<='z')s[i]-=32;
		cout<<s<<endl;
	}
	return 0;
}


Measured memory_bytes: 1172
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

bool is_ok(const string& s)
{
    size_t l = s.length();

    if(l % 2) return false;

    return equal(s.begin()      , s.begin() + l/2,
                 s.begin() + l/2, s.end());
}

int main()
{
    char buf[1024];
    scanf("%s\n", buf);
    string s(buf);

    FOR(i, 1, s.length()) {
        string s_sub(s.begin(), s.end()-i);
        if(is_ok(s_sub)) {
            printf("%lu\n", s_sub.length());
            break;
        }
    }

    return 0;
}


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

int main(){
  int K;
  string S;
  cin >> K >> S;
  
  if (K >= S.size())
    cout << S << endl;
  else {
    for (int i; i < K; i++)
      cout << S.at(i);
    cout << "..." << endl;
  }   
}

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

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

	int a,b,c;

	cin >> a >> b >> c;

	int res = min(b/a,c);

	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int mod = 1000_000_007;
    static long[] frac;
    public static void main(String[] args) {
        frac = new long[200_001];
        frac[0] = 1;
        for (int i = 1; i < 200_001; i++) frac[i] = frac[i - 1] * i % mod;
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        long ans = 0;
        for (int i = 0; i < h - a; i++) {
            ans += comb(i + b - 1, i) * comb(h + w - b - i - 2, w - b - 1) % mod;
            ans %= mod;
        }
        System.out.println(ans);
    }
    public static long comb(int a, int b) {
        return (frac[a] * modInv(frac[b]) % mod) * modInv(frac[a - b]) % mod;
    }
    public static long modInv(long n) {
        long[] xy = new long[2];
        xGcd(n, mod, xy);
        return (xy[0] % mod + mod) % mod;
    }
    public static void xGcd(long a, long b, long[] xy) {
        if (b == 0) {
            xy[0] = 1;
            xy[1] = 0;
            return;
        }
        xGcd(b, a % b, xy);
        long temp = xy[0];
        xy[0] = xy[1];
        xy[1] = temp - a / b * xy[1];
    }
}

Measured memory_bytes: 34468
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] =  new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1] - a[0]);
	}
}

Measured memory_bytes: 23380
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
typedef long long ll;
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll  l, r;
  cin >> l >> r;

  ll res = 2019;
  ll lim = min(l + 2018, r);
  bool zerof = true;

  for(ll i = l; i <= lim && zerof; ++i){
    for(ll j = l; j <= lim && zerof; ++j){
      if(i != j){
        ll ans = i * j % 2019;
        if(ans < res){
          res = ans;
          if(res == 0){
            zerof = false;
          }
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

vector<int> bfs(vector<vector<int>> &G, int N, int s) {
    vector<int> res(N, INF);
    res[s] = 0;
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (int v : G[u]) {
            if (res[v] != INF) continue;
            res[v] = res[u] + 1;
            que.push(v);
        }
    }
    return res;
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    u--; v--;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> distT = bfs(G, N, u);
    vector<int> distA = bfs(G, N, v);

    int res = 0;
    for (int i = 0; i < N; i++) {
        if (distT[i] < distA[i]) {
            res = max(res, distA[i]);
        }
    }

    cout << res - 1 << endl;
    return 0;
}

Measured memory_bytes: 6656
#include <cstdio>

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

using namespace std;

int N;
int p[10];
int sum = 0;
int max_temp = 99;
int main()
{
  scanf("%d", &N);
  rep(i,N) {
    scanf("%d", &p[i]);
    if(p[i] > max_temp)
      max_temp = p[i];
    sum += p[i];
  }
  sum -= max_temp/2;
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
s = [len(i) for i in input().split("T")]
x,y  = (int(i) for i in input().split())
xl,yl,flag = [],[],False
for i in range(len(s)):
	if i%2==0: xl.append(s[i])
	else: yl.append(s[i])
x,y,xl = abs(x-xl[0]),abs(y),xl[1:]
xs,ys,lenx,leny,xl2,yl2 = sum(xl),sum(yl),len(xl),len(yl),[0],[0]
a,b = [[0 for i in range(xs+1)] for i in range(lenx+1)],[[0 for i in range(ys+1)] for i in range(leny+1)]
a[0][0],b[0][0] = 1,1
if xs>=x and (xs-x)%2==0 and ys>=y and (ys-y)%2==0: x2,y2,flag = (xs-x)//2,(ys-y)//2,True
else: print("No")
if flag:
	for i in range(lenx):
		for j in range(x2+1):
			if xl[i]<=j: a[i+1][j] = a[i][j-xl[i]] | a[i][j]
			else: a[i+1][j] = a[i][j]
	for i in range(leny):
		for j in range(y2+1):
			if yl[i]<=j: b[i+1][j] = b[i][j-yl[i]] | b[i][j]
			else: b[i+1][j] = b[i][j]
	if a[-1][x2] and b[-1][y2]: print("Yes")
	else: print("No")

Measured memory_bytes: 71028
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()

for loop in range(n):
    y, m, d = map(int, raw_input().split())
    m_lst = [20, 19, 20, 19, 20, 19, 20, 19, 20, 19]
    cnt = 0
    for i in range(m - 1):
        cnt += m_lst[i]
    if y % 3 == 0:
        cnt += (m - 1) // 2
    y -= 1
    cnt += y * 195 + (y // 3) * 5
    cnt += d - 1

    print 196470 - cnt


Measured memory_bytes: 5036
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: u64 = input();
    if n <= 999 {
        println!("ABC");
    } else {
        println!("ABD")
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int N,X,Y,Z,a[111],b[111],c[111],G=0,A=0;
cin >> N;
cin >> X;
for(int i=0;i<X;i++){
cin >> a[i];
}
cin >> Y;
for(int i=0;i<Y;i++){
cin >> b[i];
}
cin >> Z;
for(int i=0;i<Z;i++){
cin >> c[i];
}
A=Y*Z;
G=Z;
for(int i=0;i<Z;i++){
for(int j=0;j<X;j++){
if(a[j]==c[i]){
for(int k=0;k<Y;k++){
if(b[k]==c[i]){
G++;
}
}
G--;
}
}
}
cout << G <<endl;
return(0);
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    vector<int> b;
    b = a;

    sort(a.begin(), a.end());
    int k = n / 2;
    int x = a[k - 1], y = a[k];

    for (int i = 0; i < n; i++) {
        cout << (b[i] <= x ? y : x) << '\n';
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep( i, n ) for ( int i = 0; i < n; ++i )
#define reps( i, m, n ) for ( int i = m; i <= n; ++i )
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  string s; cin >> s;

  reverse( all(s) );

  bool isOK = true;
  int i = 0;

  while ( i < s.size() ) {

    if( s.substr(i, 5) == "maerd" || s.substr(i, 5) == "esare" ) i += 5;

    else if( s.substr(i, 7) == "remaerd" ) i += 7;

    else if( s.substr(i, 6) == "resare" ) i += 6;

    else{
      isOK = false;
      break;
    }

  }

  if( isOK ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int a[100000];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int m = a[n - 1];
	int r;
	int d = 1 << 30;
	for (int i = 0; i + 1 < n; i++) {
		int j = a[i];
		if (j > m / 2) j = m - j;
		if (d > m / 2 - j) {
			d = m / 2 - j;
			r = a[i];
		}
	}
	cout << m << " " << r << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
  string N; cin>>N;
  int n = N.size();
  bool ans[26];
  REP(i,26) ans[i] = false;
  REP(i,n){
      ans[N[i]-'a'] =true;
  }
  REP(i,26){
      if(!ans[i]){
          cout<<(char)(i+'a')<<endl;
          return 0;
      }
  }
  Out("None");
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	string S;
	cin >> S;
	N = S.length();
	ll ans = 0;
	ll count = 0;
	rep(i, N) {
		if (S[i] == 'B')
			count++;
		else
			ans += count;
	}

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

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;

    vector<int> sr(N + 1, 0);
    vector<int> sg(N + 1, 0);
    vector<int> sb(N + 1, 0);
    for(int i = 0; i < N; i++) {
        sr[i + 1] = sr[i];
        sg[i + 1] = sg[i];
        sb[i + 1] = sb[i];
        if(s[i] == 'R') {
            sr[i + 1]++;
        }
        if(s[i] == 'G') {
            sg[i + 1]++;
        }
        if(s[i] == 'B') {
            sb[i + 1]++;
        }
    }

    ll ans = 0;
    for(int i = 0; i < N; i++) {
        if(s[i] == 'R') {
            ans += sg[i] * (sb[N] - sb[i + 1]);
            ans += sb[i] * (sg[N] - sg[i + 1]);
        }
        if(s[i] == 'G') {
            ans += sr[i] * (sb[N] - sb[i + 1]);
            ans += sb[i] * (sr[N] - sr[i + 1]);
        }
        if(s[i] == 'B') {
            ans += sr[i] * (sg[N] - sg[i + 1]);
            ans += sg[i] * (sr[N] - sr[i + 1]);
        }
    }

    for(int i = 0; i < N; i++) {
        for(int d = 1; d < N; d++) {
            if(i + d < N && i + 2 * d < N) {
                if(s[i] != s[i + d] && s[i] != s[i + 2 * d] && s[i + d] != s[i + 2 * d]) {
                    ans--;
                }
            }
        }
    }

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


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 N;
  string s;
  cin >> N >> s;
  if (N % 2 || (s.substr(0, N/2) != (s.substr(N/2, N-N/2)))) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int x,ans,i ;

int main(void){

    scanf ("%d",&x) ;
    ans = 1 ;
    
    for (i=2; i<x; i++){
        
        int j ;
        for (j=i*i; j<=x; j=j*i){
            
            if (ans < j){
            ans = j ;
            }
        }
    }
    
    printf ("%d",ans) ;
    
    return 0 ;
}

Measured memory_bytes: 128
from itertools import combinations

s = list(input())
ans = 0

for i in range(len(s)):
    for j in combinations(range(len(s)-1),i):
        temp = [i for i in s]
        for k in j[::-1]:
            temp.insert(k+1,'+')
        temp = ''.join(temp)
        temp = temp.split('+')
        temp = map(int, temp)
        ans += sum(temp)

print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] nums = new int[n];
    for (int i = 0; i < n; i++) {
      nums[i] = sc.nextInt() - (i + 1);

    }
    Arrays.sort(nums);
    int b = nums[n / 2];
    
    long total = 0;
    for (int i = 0; i < n; i++) {
      nums[i] -= b;
      total += Math.abs(nums[i]);
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 64780
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

inline ll c(ll n,ll m)
{
	if (n<m) return  0ll;
	if (n==m) return 1ll;
	if (m==1) return n;
	return c(n-1,m-1)+c(n-1,m);
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ll n,m;
    in(n);in(m);
    out(c(n,2ll)+c(m,2ll));EL;
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}




Measured memory_bytes: 256
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1505, mod = 1e9 + 7, i2 = (mod+1)/2;
bool prime(ll x) {
	for(ll a = 2; a < x; a++) if(x%a == 0) return false;
	return true;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll n, a, b;
	cin >> n >> a >> b;
	vector<int> x(n);
	for(auto &i : x) cin >> i;
	ll ans = 0, p = 0;
	for(int i = 0; i < n; i++) {
		if(i)
		ans += min((x[i]-p)*a, b);
		//cout << (x[i]-p)*a << '\n';
		p = x[i];
	}
	cout << ans;
	return 0;
}


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

using namespace std;
typedef long long Int;

#define MOD 1000000007

Int fact(Int n){
  if(n == 0)return 1;
  return n * fact(n-1) % MOD;
}

int main(){
  Int n, m;
  cin >> n >> m;
  if(n > m)swap(n, m);
 
  Int ans = fact(n) * fact(m) % MOD;
  if(n == m)ans = ans * 2 % MOD;
  else if(n + 1 == m);
  else ans = 0;
  cout << ans << endl;
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	for(int i=0,pt=0,px=0,py=0;i<n;++i){
		int t,x,y; cin>>t>>x>>y;
		int st=abs(t-pt),di=abs(x-px)+abs(y-py);
		if(di>st||(di+st)&1){
			cout<<"No\n"s;
			return 0;
		}
		pt=t,px=x,py=y;
	}
	cout<<"Yes\n"s;
}


Measured memory_bytes: 3652