akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (i % 3 == 0) continue;
		if (i % 5 == 0) continue;
		if (i % 15 == 0) continue;
		ans += i;
	}
	cout << ans;
	return 0;
}










Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
using ldb = long double;
using pa = pair < int, int >;
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;
#define pb push_back
#define all(c) c.begin(),c.end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 5e5 + 10;
const double PI = acos(-1);
const int LINF = LLONG_MAX;
int vis[N];
// void make_set(int v) {
//     parent[v] = v;
//     siz[v] = 1;
// }
// int find_set(int v) {
//     if (v == parent[v])
//         return v;
//     return parent[v] = find_set(parent[v]);
// }
// void union_sets(int a, int b) {
//     a = find_set(a);
//     b = find_set(b);
//     if (a != b) {
//         if (siz[a] < siz[b])
//             swap(a, b);
//         parent[b] = a;
//         siz[a] += siz[b];
//     }
// }
int c;
set<int>adj[N];
void dfs(int a){
    vis[a] = 1;
    c++;
    // cout << a << " " << c << "\n";
    for(auto s : adj[a]){
        if(!vis[s]){
            dfs(s);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,ans = 0,a,b,d,e;
    int m;
    cin >> n >> m;
    f(i,0,m){
        cin >> a >> b;
        adj[b].insert(a);
        adj[a].insert(b);
    }
    f(i,1,n+1){
        if(!vis[i]){
            dfs(i);
            ans = max(ans,c);
        }
        c = 0;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 53592
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vector<vector<int>>g(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int num=0;
    for(int j=0;j<g[i].size();j++){
      int next=g[i][j];
      if(h[i]>h[next]) num++;
    }
    if(num==g[i].size()) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 8804
program ABC163_C
  integer,allocatable::A(:),B(:)
  read(*,*)N
  allocate(A(2:N),B(N))
  B=0
  read(*,*)A
  do i=2,N
     B(A(i))=B(A(i))+1
  end do
  do i=1,N
     write(*,*)B(i)
  end do
end program ABC163_C

Measured memory_bytes: 5108
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define rep(i, j, n) for (int i = j; i < n; i++)
#define rep_nested(i, s, n) for (int i = s; i <= n; i++)
#define ll long long
#define ull unsigned long long

const int N = 500;
const ll INF = 1e9 + 7;

using namespace std;

template <class T>
T limit(T n, T k) {
	return (n > k) ? k : n;
}

template <class T>
T has_order(T a, T b, T c) {
	return (b > a && b < c) || (b < a && b > c);
}

template <class T>
float points_distance(T a) {
	return sqrt(a);
}

template <class T>
T is_integer(T a) {
	return floor(a) == a;
}

int main() {
	int a;
	cin >> a;
	cout << (3 * a * a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    double c,d,e;
    c = a/b;
    d = a%b;
    e = 1.0*a/b;
    printf("%.4lf\n", c);
    printf("%.8lf\n", d);
    printf("%.5lf\n", e);
}


Measured memory_bytes: 3216
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	static int F => int.Parse(Str);
	static long FL => long.Parse(Str);
	static int[] G => Strs.Select(int.Parse).ToArray();
	static decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	static long[] GL => Strs.Select(long.Parse).ToArray();
	static string Str => ReadLine();
	static string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	static int N;
	void Solve()
	{
		var I = G;
		N = I[0];
		WriteLine(ToString(Calc(Get(), Get(), I[1] - 1)));
	}
	static int[] Get() => G.Select(i => i - 1).ToArray();
	static string ToString(int[] p) => string.Join(" ", p.Select(i => i + 1));
	static int[] Calc(int[] p, int[] q, int K)
	{
		// if (K == 0) return p;
		// if (K == 1) return q;
		// if (K < 6) return Calc(q, Mult(q, Inv(p)), K - 1);
		int[] ip = Inv(p), iq = Inv(q), x = Mult(q, ip, iq, p), y = Mult(ip, q, p, iq);
		switch (K % 6)
		{
			case 0: return Mult(Pow(x, K / 6), q, p, iq, Pow(y, K / 6 - 1));
			case 1: return Mult(Pow(x, K / 6), q, Pow(y, K / 6));
			case 2: return Mult(Pow(x, K / 6), q, ip, Pow(y, K / 6));
			case 3: return Mult(Pow(x, K / 6), q, ip, iq, Pow(y, K / 6));
			case 4: return Mult(Pow(x, K / 6 + 1), iq, Pow(y, K / 6));
			default: return Mult(Pow(x, K / 6 + 1), p, iq, Pow(y, K / 6));
		}
	}
	static int[] Inv(int[] a)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[a[i]] = i;
		return c;
	}
	static int[] Mult(int[] a, int[] b)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[i] = a[b[i]];
		return c;
	}
	static int[] Mult(params int[][] a)
	{
		if (a.Length == 0) return MakeArray(N, i => i);
		var x = a[0];
		for (var i = 1; i < a.Length; i++) x = Mult(x, a[i]);
		return x;
	}
	static int[] Pow(int[] a, int b)
	{
		var p = new int[N];
		var done = new bool[N];
		for (var i = 0; i < N; i++)
			if (!done[i])
			{
				done[i] = true;
				var cycle = new List<int> { i };
				var x = a[i];
				while (x != i) { cycle.Add(x); done[x] = true; x = a[x]; }
				var L = cycle.Count;
				var c = (b + L) % L;
				for (var j = 0; j < L; j++) p[cycle[j]] = cycle[(j + c) % L];
			}
		return p;
	}
}


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

signed main(){
  int A,B,K;
  cin>>A>>B>>K;
  for(int i=0;i<K;i++){
    if(i%2){
      if(B%2)B--;
      A+=B/2;
      B/=2;
    }
    else{
      if(A%2)A--;
      B+=A/2;
      A/=2;
    }
    //cout<<A<<" "<<B<<endl;
  }
  cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

bool f = false;

void solve(int dep,const string& S,string op,int sum) {
	if (f)return;
	if (dep == 4) {
		if (sum == 7) {
			f = true;
			cout << (char)S[0] << (char)op[0] << (char)S[1] <<(char)op[1] <<(char)S[2] << (char)op[2] <<(char) S[3] << "=7" << endl;
		}
		return;
	}
	string temp1 = op;
	string temp2 = op;

	temp1 += '+';
	solve(dep + 1, S, temp1, sum + (S[dep] - '0'));
	temp2 += '-';
	solve(dep + 1, S, temp2, sum - (S[dep] - '0'));
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	string ABCD; cin >> ABCD;
	string op;
	solve(1,ABCD,op,ABCD[0] - '0');
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

void solve(const vector<ll> &a, vector<int> &dp0, vector<int> &dp1){
  const int n = a.size();
  ll sum = 0;
  REP(i,n){
    dp0[i + 1] = dp0[i] + (a[i] == 0 ? 2 : a[i] % 2);
    dp1[i + 1] = min(dp0[i], dp1[i]) + ((a[i] + 1) % 2);

    dp0[i + 1] = min<ll>(dp0[i + 1], sum + a[i] % 2);
    sum += a[i];
  }
}

int main(){
  const int n = getInt();

  vector<ll> a(n);
  REP(i,n) a[i] = getInt();


  vector<int> dpl0(n + 1);
  vector<int> dpl1(n + 1);
  vector<int> dpr0(n + 1);
  vector<int> dpr1(n + 1);
  solve(a, dpl0, dpl1);
  reverse(a.begin(), a.end());
  solve(a, dpr0, dpr1);
  reverse(dpr0.begin(), dpr0.end());
  reverse(dpr1.begin(), dpr1.end());

  int ans = n + n;
  REP(i,n+1){
    // printf("%d %d %d (%d %d %d %d)\n", dpl0[i] + dpr0[i], dpl0[i] + dpr1[i], dpl1[i] + dpr0[i], dpl0[i], dpl1[i], dpr0[i], dpr1[i]);
    ans = min(ans, dpl0[i] + dpr0[i]);
    ans = min(ans, dpl0[i] + dpr1[i]);
    ans = min(ans, dpl1[i] + dpr0[i]);
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 4992
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any) = pw.print(s)
fun println(s: Any) = pw.println(s)

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

fun main() {
    val N = nextInt()
    val A = nextLongList()
    val ans = A.reduce { u, v -> gcd(u, v) }
    println(ans)
}

tailrec fun gcd(a: Long, b: Long): Long {
    if (a < b) return gcd(b, a)
    if (b == 0L) return a
    if (a <= 0L) throw IllegalArgumentException()
    return gcd(b, a % b)
}

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

using ll = long long;


ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r;
string s, t, u;
ll v, w, x, y, z;

int main() {

    cin >> n >> d;
    x = d + d + 1;

    cout << (n + x - 1) / x << endl;

}




Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e15
ll vec[200009];
ll cum[200009];
ll M;
int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    M=(1e9)+7;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&vec[i]);
    }
    for(i=n;i>=1;i--)
    {
        cum[i]=(cum[i+1]+(vec[i]%M))%M;
    }
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        a=vec[i]%M;
        b=cum[i+1];
        a=(a*b)%M;
        ans=(ans+a)%M;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <functional>
#include <set>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	int n;
	cin >> n;
	pair<pair<string, int>, int> res[101];
	for (int i = 0; i < n; i++)
	{
		cin >> res[i].first.first >> res[i].first.second;
		res[i].first.second *= - 1;
		res[i].second = i + 1; 
	}
	sort(res, res + n);
	for (int i = 0; i < n; i++)
	{
		cout << res[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll power(ll x,ll k,ll mo)
{
	ll cnt=1;
	while(k){
		if(k&1) cnt=cnt*x%mo;
		x=x*x%mo;
		k>>=1;
	}
	return cnt;
}
ll phi(ll n)
{
	ll res=n,t=n;
	for(ll i=2;i*i<=t;i++)
		if(t%i==0){
			res-=res/i;
			while(t%i==0) t/=i;
		}
	if(t>1) res-=res/t;
	return res;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0) {x=1;y=0; return a;}
	ll g;
	g=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return g;
}
ll solve(ll A,ll M)
{
	if(M==1) return 1;
	ll phiM,At,t,x,y,g;
	phiM=phi(M);
	g=gcd(M,phiM);
	t=solve(A,g);
	At=power(A,t,M);
	
	exgcd(M/g,phiM/g,x,y);
	
	x=x*(((t-At)%phiM+phiM)%phiM)/g;
	x=((x%(phiM/g)+phiM/g)%(phiM/g)+phiM/g);
	return x*M+At;
}
int main()
{
	int Q;
	cin>>Q;
	while(Q--){
		ll A,M;
		cin>>A>>M;
		cout<<solve(A,M)<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 

const int Mod = 1e9 + 7;
const int MAX_N = 405; 
int N, C, A[MAX_N], B[MAX_N]; 
int f[MAX_N][MAX_N], sum[MAX_N][MAX_N]; 
int fpow(int x, int y) { 
	int res = 1; 
	while (y) {
		if (y & 1) res = 1ll * res * x % Mod; 
		x = 1ll * x * x % Mod; 
		y >>= 1; 
	} 
	return res; 
} 
int main () { 
	scanf("%d %d", &N, &C); 
	for (int i = 1; i <= N; i++) scanf("%d", A + i);
	for (int i = 1; i <= N; i++) scanf("%d", B + i); 
	for (int i = 1; i <= N; i++) 
		for (int j = A[i]; j <= B[i]; j++) 
			for (int k = 0; k <= C; k++) sum[i][k] = (sum[i][k] + fpow(j, k)) % Mod;
	f[0][0] = 1; 
	for (int i = 1; i <= N; i++) { 
		for (int j = 0; j <= C; j++) { 
			for (int k = 0; k <= j; k++) { 
				f[i][j] = (f[i][j] + 1ll * f[i - 1][k] * sum[i][j - k]) % Mod; 
			} 
		} 
	} 
	printf("%d\n", f[N][C]); 
    return 0; 
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
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*b/gcd(a,b);}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint b(n-1); rep(i,n-1) cin >> b[i];
    int res=0;
    rep(i,n-2) res+=min(b[i],b[i+1]);
    res+=b[0]+b[n-2];
    cout<<res<<endl;
}

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

using namespace std;

int main(){
    string s; cin >> s;
    int cnt_win=0, cnt_lose=0;
    int num_g=0, num_p=0;
    for(char c : s){
        if(c=='g'){
            if(num_p<num_g){
                ++num_p;
                ++cnt_win;
            } else{
                ++num_g;
            }
        } else{
            if(num_p<num_g){
                ++num_p;
            } else{
                ++num_g;
                ++cnt_lose;
            }
        }
    }
    cout << cnt_win-cnt_lose << endl;
    return 0;
}


Measured memory_bytes: 512
using System;

namespace ITP1_9_D
{
    class Program
    {
        static void Main(string[] args)
        {

            string str = Console.ReadLine();
            string str_rev = null;
            int num = int.Parse(Console.ReadLine());

            for (int i=0; i<num; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                string operate = input[0];
                string str_for = "";
                string str_back = "";
                int a = int.Parse(input[1]);
                int b = int.Parse(input[2]);
                int len = b - a + 1;

                switch (operate)
                {
                    case "print":                      
                        string output = str.Substring(a, len);
                        Console.WriteLine(output);

                        break;
                    
                    case "reverse":
                        if (a != 0)
                        {
                            str_for = str.Substring(0, a);
                        }
                        if (b != str.Length)
                        {
                            str_back = str.Substring((b + 1));
                        }

                        string str_sub = str.Substring(a, len);
                        char[] cs = str_sub.ToCharArray();
                        Array.Reverse(cs);
                        str_rev = new string(cs); 

                        str = str_for + str_rev + str_back;

                        break;
       
                    case "replace":
                        char[] str_cs = str.ToCharArray();
                        char[] cs2 = input[3].ToCharArray();
                        for (int k=0; k<input[3].Length; k++)
                        {
                            int pos = a + k;
                            str_cs[pos] = cs2[k];
                        } 

                        str = new String(str_cs);

                        break;
                        
                }
            }
        }
    }
}

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

int main(){
  unsigned int A, B, C, D, areaAB, areaCD;
  
  cin >> A >> B >> C >> D;

  areaAB = A*B;
  areaCD = C*D;

  if(areaAB > areaCD) cout << areaAB << endl;
  else if (areaAB < areaCD) cout << areaCD << endl;
  else cout << areaAB << endl;
  
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from collections import deque

N, K, *P = map(int, open(0).read().split())

def slide(A, K, cmp=lambda a, b: a > b):
    res = []
    Q = deque()
    for i, a in enumerate(A):
        while Q and cmp(A[Q[-1]], a):
            Q.pop()
        Q.append(i)
        if Q[0] == i - K:
            Q.popleft()
        res.append(Q[0])
    return res[K - 1:]

mi = slide(P, K)
ma = slide(P, K, lambda a, b: a < b)

B = [mi != i or ma != i + K for i, (mi, ma) in enumerate(zip(mi, ma[1:]))]

A = [0] + list(accumulate(x < y for x, y in zip(P, P[1:])))
S = [y - x != K - 1 for x, y in zip(A, A[K - 1:])]

ans = 1 + sum(b for b, s in zip(B, S[1:]) if s)
if S[0] and not all(S):
    ans += 1
print(ans)

Measured memory_bytes: 39772
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define F first
#define S second
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e9;
const int MAX_N = 1e5;
int par[MAX_N];
int ufrank[MAX_N];
int ufsize[MAX_N];
void init(int ufsize_of_tree){
    for (int i = 0; i < ufsize_of_tree; i++)
    {
        par[i] = i;
        ufrank[i] = 0;
        ufsize[i] = 1;
    } 
}
int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(ufrank[x] < ufrank[y]){
        par[x] = y;
    int sx = ufsize[x], sy = ufsize[y];
    ufsize[x] = ufsize[y] = sx + sy;
    }else{
        par[y] = x;
        if(ufrank[x] == ufrank[y]) ufrank[x]++;
        int sx = ufsize[x], sy = ufsize[y];
        ufsize[x] = ufsize[y] = sx + sy;
    }
}
bool same(int x,int y){
    return find(x) == find(y);
}
int main(){

    int n,m;cin>>n>>m; init(n);
    vector<int> p(n); rep(n){int x;cin>>x;p[i] = --x;}
    rep(m){
        int a,b;cin>>a>>b; a--,b--;
        unite(a,b);
    }
    //////////////////////////////////
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(same(p[i],i) || i == p[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

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 V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int n, ans;
int main() {
	string h;
	cin >> n >> h;
	for (int i = 1; i < h.length(); ++i) {
		if (h[i] != h[i - 1]) { ++ans; }
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToList();
        List<int> operations = new List<int>();
        for (int i = 1; i <= n; i++)
        {
            //操作列のn個目に挿入する場合は
            int currentBack = 0;
            int insertOps = 0;
            for (int j = a.Count - 1; j >= 0; j--)
            {
                if (a[j] < i) currentBack++;
                if (a[j] == i)
                {
                    if (operations.Count < currentBack + insertOps + i - 1)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                    else
                    {
                        operations.Insert(currentBack + insertOps + i - 1, i);
                        insertOps++;
                    }
                }
            }
        }
        Console.WriteLine(string.Join("\n", operations));
    }
}

Measured memory_bytes: 11348
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N = int(input())

max_n = 100
ans = defaultdict(int)

for x in range(1, max_n):
    for y in range(1, max_n):
        for z in range(1, max_n):
            val = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if val <= N:
                # print(x, y, z, val)
                ans[val] += 1

for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 75952
import java.util.*;

class Main {
    static Integer[] dp;
    static int INF = (int) 1e9 + 7;

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int[] arr = new int[N];
        int max = 0;
        for(int i = 0; i < N-1; i++) {
            int curr = s.nextInt()-1;
            max = Math.max(max, curr);
            arr[curr]++;
        }
        for(int i = 0; i < N; i++) {
            System.out.println(arr[i]);
        }
    }
}

Measured memory_bytes: 70932
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long
#define f(n)  for(int i=0;i<n;i++) 
#define pb push_back
#define take(t) int t;cin>>t
#define np nake_pair
#define vi vector<int>
#define all(v)   v.begin(),v.end()  
#define w(t)   while(t--)
void speed (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
  
 speed();
 long long int n,k;
cin>>n>>k;


   
    long long int min=n;
    long long int r=n%k;
    if(abs(r-k)<r){
        cout<<abs(r-k);
    }
    else{
        cout<<r;
    }

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

int N, K;

int coin(int K, int num) {
    if (K <= num) return 0;
    else {
        int cnt=0;
        while (K>num) {
            num *= 2;
            ++cnt;
        }
        return cnt;
    }
}

double ans=0.0;

int main() {
    cin >> N >> K;
    for (int i=1; i<=N; ++i) ans += pow(0.5, (double)coin(K, i));

    cout << setprecision(12) << 1.0 * ans / N << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

//C 4:00

signed main() {
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	// |  |A|  |B|  | 
	int dis = max(a, b) - min(a, b) - 1;
	if (dis % 2 == 0) {
		cout << "Borys\n";
	}
	else {
		cout << "Alice\n";
	}
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import math
# n進数の各位の和


def base_10_n(x, n):
    if x == 0:
        return 0
    tmpx = x
    a = int(math.log(x, n))
    ans = 0
    for i in range(a, -1, -1):
        ans += tmpx // n**i
        tmpx %= n**i
    ans += tmpx
    return ans


def s(n, r):
    if n == 0:
        return 0
    return n % r + s(n // r, r)


def main():
    N = int(input())
    ans = 10**12
    for j in range(N+1):
        # c = base_10_n(N-j, 6)
        # d = base_10_n(j, 9)
        c = s(j,6)
        d = s(N-j,9)
        ans = min(ans, c+d)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
  int k,s,srx=0;
  scanf("%d%d",&k,&s);
  for(int x=0;x<=k;x++) 
  {for(int y=0;y<=k;y++) 
  {int z=s-x-y;
  if(0<=z&&z<=k)
  srx++;}}
  printf("%d\n",srx);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

int main(){
  int n,x,t;
  cin >> n >> x >> t;
  int ans = (n+x-1)/x;
  cout << ans*t << endl;
}


Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{
	static long K;

	//|x - K|を計算
	static long Diff(long x){
			long diff = 0;
			if(x >= K){
					diff = x - K;
			}else{
					diff = K - x;
			}

			return diff;
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		long N = long.Parse(line[0]);
		K = long.Parse(line[1]);

		//二個前までの数を格納する配列
		long[] before = new long[2];
		//最小値を格納
		long min = N;

		if(N == K){
				min = 0;
		}
		else if(N < K){
				min = Math.Min(N, (K - N));
		}
		else{
				long rem = N % K;
				min = Math.Min(rem, (K-rem));
		}

		Console.WriteLine(min);

	}
}



Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int l,r;
  rep(i,(int)s.size()){
    if((char)s[i]=='A') {l=i; break;}
  }
  for(int i=(int)s.size(); i>=0;i--){
    if((char)s[i]=='Z') {r = i; break;}
  }
  cout << r-l+1 << endl;
  return  0;
}


Measured memory_bytes: 640
import sys

def isTriangle(num1, num2, num3):
    if num1 == num2 or num2 == num3 or num3 == num1:
        return False
    if num1 + num2 <= num3 or num1 + num3 <= num2 or num2 + num3 <= num1:
        return False
    return True



n = int(sys.stdin.readline())
line = sys.stdin.readline()

if not "" == line.rstrip():
        nums = line.rstrip().split(" ")

count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if isTriangle( int(nums[i]), int(nums[j]), int(nums[k]) ):
                count += 1

print(count)

Measured memory_bytes: 9212
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int a; char op; int b;
  while (cin >> a >> op >> b) {
    if (op == '?') {
      return 0;
    } else {
      if (op == '+') {
        cout << a + b << '\n';
      } else if (op == '-') {
        cout << a - b << '\n';
      } else if (op == '*') {
        cout << a * b << '\n';
      } else {
        cout << a / b << '\n';
      }
    }
  }


  return 0;
}


Measured memory_bytes: 3116
n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(input()))

def f(x,y,z,arr,ca,cb,cc):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],ca+1,cb,cc)
        f(x, y + arr[0], z, arr[1:],ca,cb+1,cc)
        f(x, y, z + arr[0], arr[1:],ca,cb,cc+1)
        f(x, y, z, arr[1:],ca,cb,cc)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (ca + cb + cc - 3))
f(0,0,0,l,0,0,0)
print(min(ans))

Measured memory_bytes: 4984
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
using namespace std;

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

    int sum = accumulate(W.begin(), W.end(), 0);
    int lsum = 0;
    int out = 1000000000;
    for (int w : W) {
        lsum += w;
        sum -= w;
        out = min(out, abs(sum - lsum));
    }

    cout << out << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c; cin>>a>>b>>c;
	if (b-a==c-b) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars
    };
    match s
        .iter()
        .position(|&s_i| s_i == 'C')
        .and_then(|i_c| s.iter().skip(i_c + 1).position(|&s_i| s_i == 'F'))
    {
        None => println!("No"),
        Some(_) => println!("Yes"),
    };
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B,C;
#define FOR(i,a,n) for(ll (i)=(a);(i)<(n);(i)++);
ll tmp,ans;
int main(){
    cin >>A >>B >>C;
if (C<=A+B){
    ans=C+B;
}else{

        ans=A+B+B+1;
}   

cout <<ans <<endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll memo[5000][5000];
ll a[5001];
int n;

ll cake(int l, int r, int s)
{
    if (memo[l][r] != -1)
        return memo[l][r];

    if (r - l == 0)
    {
        if (s)
            return memo[l][r] = 0;
        return memo[l][r] = a[l];
    }

    if (s)
        return memo[l][r] = (a[l] > a[r] ? cake(l + 1, r, 0) : cake(l, r - 1, 0));

    return memo[l][r] = max(cake(l + 1, r, 1) + a[l], cake(l, r - 1, 1) + a[r]);
}
int main()
{
    rep(i, 5000) rep(j, 5000) memo[i][j] = -1;

    cin >> n;
    rep(i, n)
    {
        int d;
        cin >> d;
        a[i] = a[n + i] = d;
    }
    ll ans = 0;

    rep(i, n)
    {
        ans = max(ans, cake(i, i + n - 1, 0));
    }

    OP(ans);

    return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N;
  cin >> N;
  ll A[N], front[N], back[N];
  rep(i, N) cin >> A[i];

  front[0] = A[0];
  back[N-1] = A[N-1];
  rep(i, N-1) front[i+1] = max(front[i], A[i+1]);
  rrep(i, N-1) back[i] = max(back[i+1], A[i]);

  rep(i, N){
    if(i == 0){
      cout << back[1] << endl;
    }
    else if(i == N-1){
      cout << front[N-2] << endl;
    }
    else{
      cout << max(front[i-1], back[i+1]) << endl;
    }
  }
  return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;
    if(S.size() == T.size()){
    for(int i = 0; i < S.size(); i++)
      {cout << S.at(i) << T.at(i) ;
      }
    }
    else{for(int i = 0; i < T.size(); i++)
      {cout << S.at(i) << T.at(i) ;
      }
    cout << S.at(S.size()-1); 
    }
    cout << endl;
      
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll ans=0;
  int cnt=0;
  rep(i,2*n){
    if(i%2==0){
      if(s[i]=='B') s[i]='W';
      else s[i]='B';
    }
    if(s[i]=='B') cnt++;
  }
  if(cnt!=n){
    cout<<ans<<endl;
    return 0;
  }
  ans=1;
  cnt=0;
  rep(i,2*n){
    if(s[i]=='W') cnt++;
    else{
      (ans*=cnt)%=mod;
      cnt--;
    }
  }
  FOR(i,1,n+1){
    (ans*=i)%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 720
import numpy as np

n = int(input())
a_list = list(map(int, input().split()))

alice_point = 0
bob_point = 0
for i in range(n):
    argmax_a = np.argmax(a_list)
    max_a = np.max(a_list)
    if i % 2 == 0: # If Alice takes a card
        alice_point += max_a
    else: # If Bob takes a card
        bob_point += max_a
    del a_list[argmax_a] # No confidence -> Review how to delete list element!

print(alice_point - bob_point)

Measured memory_bytes: 12388
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    if w % 2 == 0:
        line1 = "#." * (int(w/2))
        line2 = ".#" * (int(w/2))
    else:
        line1 = "#." * (w//2) + "#"
        line2 = ".#" * (w//2) + "."
    if h % 2 == 0:
        for _ in range(int(h/2)):
            print(line1)
            print(line2)
    else:
        for _ in range(h//2):
            print(line1)
            print(line2)
        print(line1)
    print()


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

#define TOT 2000001

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

    bool e = true;

    for (int i = 0; i < s.size(); i++)
    {
        if (i % 2 == 0 && s[i] == 'L')
        {
            e = false;
            break;
        }

        if (i % 2 != 0 && s[i] == 'R')
        {
            e = false;
            break;
        }
    }

    if (e)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int memo[3][301];

int main(){
	for(int n,m;~scanf("%d%d",&n,&m);){
		for(int i=0;i<3;i++)for(int j=0;j<=m;j++)	memo[i][j]=(j?-1:0);

		int ans=0;
		while(n--){
			getchar();	while(getchar()!='\n');
			int cost,prm[3];
			scanf("%d%d%d%d",&cost,prm,prm+1,prm+2);
			for(int i=0;i<3;i++)for(int j=0;j+cost<=m;j++){
				if(memo[i][j]==-1)	continue;
				memo[i][j+cost]=max(memo[i][j+cost],memo[i][j]+prm[i]);
				ans=max(ans,memo[i][j+cost]);
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>
#include <functional>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


// Input graph must be acyclic
int longest_path(const Graph &DAG) {
  int N = DAG.size();
  
  Graph Inv(N);
  for (int a = 0; a < N; a++) {
    for (auto b: DAG[a]) {
      Inv[b].push_back(a);
    }
  }

  vector<int> len(N, -1);

  function<void(int)> set_len =
    [&](int v) {
      if (len[v] != -1) return;
      // 入次数0
      if (Inv[v].empty() ) {
        len[v] = 0;
        return;
      }
      
      int nax = 0;
      for (int u : Inv[v]) {
        set_len(u);
        nax = max(nax, len[u]);
      }
      len[v] = nax + 1;
    };
  
  for (int i = 0; i < N; i++) {
    set_len(i);
  }

  // 自分のノードへの距離を0からとしているので, +1する必要があるときはすること！！
  return *max_element(len.begin(), len.end());
}

// Topological sort and cycle detection
class DAG {
  int N;
  Graph G;
  vector<int> visited; // never visited 0, visited 1, visited twice 2

  void dfs(int v) {
    if (visited[v] == 2) {
      is_acyclic = false;
      return;
    } else if (!visited[v]) {
      visited[v] = 2;
      for (int nv: G[v]) {
        dfs(nv);
      }
      visited[v] = 1;
      sorted.push_back(v);
    }
  }
  
public:
  vector<int> sorted;
  DAG(int n) : N(n), G(n), visited(n) {}
  DAG(const Graph  &G) : N(G.size()), G(G), visited(G.size()) {}
  bool is_acyclic = true;
  
  void add_arc(int a, int b) {
    // assert(0 <= a && a < N && 0 <= b && b < N);
    G[a].push_back(b);
  }

  void tsort() {
    for (int i = 0; i < N; i++) {
      if (!visited[i]) dfs(i);
    }
    reverse(sorted.begin(), sorted.end());
  }
};


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

  Graph G(N * (N - 1));

  auto get = [&] (int a, int b) {
               if (a > b) swap(a, b);
               return (a * N + b);
             };

  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    a--;
    int prev = get(i, a);
    // cout << "this is prev: "<< prev << endl;
    for (int j = 0; j < N - 2; j++) {
      int b; cin >> b;
      b--;
      int cur = get(i, b);
      // cout << prev << " " << cur << endl;
      G[prev].push_back(cur);
      prev = cur;
    }
  }

  DAG dag(G);
  dag.tsort();
  if (!dag.is_acyclic) {
    cout << -1 << endl;
    return 0;
  }

  cout << longest_path(G) + 1 << endl;
}


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



typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*ll n,x,t;
    cin>>n>>x>>t;
   
   
    ll i=1;
    while()
    {
        
        
        
        
        
    }*/
    string s;
    cin>>s;
    ll i = 0 ; ll sum=0;
    while(i<s.size())
    {
        ll g = int(s[i])-48;
        //cout<<g<<"\n";
        sum=sum+g;
        
        i++;
    }
    if(sum%9==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    
    
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll y = n / i;
        ans += i * (y + 1) * y / 2;
    }

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


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N;
    cin >> N;
    set<string> S;
    REP(i, N) {
        string tmp;
        cin >> tmp;
        S.insert(tmp);
    }
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(rbegin(ret), rend(ret));
  return (ret);
}

vector<ll> cnt;

int main()
{
	ll n,k;
	cin >> n >> k;
	cnt = vector<ll>(k+1);
	ll ans = 0;
	for(ll i=1;i<=k;i++)
	{
		vector<ll> a = divisor(i);
		vector<ll> b(a.size());
		for(ll j = 0;j<a.size();j++)
		{
			
			(b[j] += mod_pow(k/a[j],n-1,MOD))%=MOD;
			for(ll k = j+1;k<a.size();k++)
			{
				if(a[j]%a[k]==0)b[k]=(b[k]-b[j]+MOD)%MOD;
			}
			//cout<<';'<<a[j]<<';'<<b[j]<<endl;
		}
		for(ll j=0;j<a.size();j++)
		{
			(ans += a[j]*b[j])%=MOD;
		}
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4048