akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
#define MAX_N 100010

int N,Q, marked[MAX_N], visited[MAX_N];
typedef pair<char, int> QUERY;
stack<QUERY> query;
int parent[MAX_N];

int par[MAX_N]; // root
int rank[MAX_N]; // depth of tree

// 要素数nで初期化
void init(int n) {
for (int i=0;i<n; i++) {
    par[i] = i;
    rank[i] = 0;
    }
}

// 木の根を求める
int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] =  find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;

    par[x] = y; // parent of x is y

    /*
    if (rank[x] <= rank[y]) {
        par[x] = y;
        if (rank[x] == rank[y]) rank[y]++;
    } else {
        par[y] = x;
    }
    */
}

void solve() {
    long long int ans = 0;

    for(int i=2;i<=N;i++) {
        if(marked[i] == false) {
            unite(i, parent[i]);
        }
    }

    int num = query.size();
    while(!query.empty()) {
        QUERY q = query.top(); query.pop();
        char op = q.first;
        int index = q.second;
        if(op == 'M') { // Mark
            marked[index] = false;
            unite(index, parent[index]);
        } else if(op == 'Q') { // Query
            ans += find(index);
        }
    }
    cout << ans << endl;
}

main() {
    while(1) {
        cin >> N >> Q;
        if(N==Q&&N==0) break;
        memset(marked,0,sizeof(marked));
        memset(parent,0,sizeof(parent));
        init(N+2);
        set<int> s;

        marked[1] = 1; // node 1 is already marked 
        parent[1] = 1;
        for(int i=2;i<=N;i++) {
            int d;
            cin >> d;
            parent[i] = d;
        }

        // Question
        s.insert(1); 
        for(int i=0;i<Q;i++) {
            char op;
            int index;
            cin >> op >> index;
            if(op == 'M' && s.find(index) != s.end()) continue;
            if(op == 'M') {
                marked[index] = true;
                s.insert(index);
            }
            query.push(make_pair(op, index));
        }
        solve();
    }
}

Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 100005
#define INF 9223372036854775807LL
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
int main()
{
    vector<ll>vt;
    ll i,j,k,l,n,m,r;
    in(n);in(k);
    ll arr[n+1];
    for(i=1;i<=n;i++)
        in(arr[i]);
    map<ll,ll>mp;
    i=1;
    while(1LL)
    {
        if(mp[i]==1)
        {
            m=i;
            break;
        }
        vt.pb(i);
        mp[i]=1;
        i=arr[i];
    }
    for(i=0;i<vt.size();i++,k--)
    {
        if(!k)
        {
            cout<<vt[i]<<'\n';
            exit(0);
        }
        if(vt[i]==m)break;
    }
    vector<ll>pt;
    for(;i<vt.size();i++)pt.pb(vt[i]);
    k++;
    k%=pt.size();
    if(k==0)k=pt.size()-1;
    else k--;
    cout<<pt[k];endl;
}


Measured memory_bytes: 19144
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	vector<int> a(9);
	int n;
	cin >> n;
	rep(i, n) {
		int p;
		cin >> p;
		if (p < 3200)
			a[p / 400]++;
		else
			a[8]++;
	}
	int P = 0;
	rep(i, 8) if (a[i]) P++;
	if (P) {
		cout << P << " " << P + a[8] << endl;
	} else {
		cout << 1 << " " << a[8] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N,M,C = map(int,input().split())
B = np.array(list(map(int,input().split())))
count=0
for i in range(N):
	A = np.array(list(map(int,input().split())))
	if np.dot(A,B)+C>0:
		count+=1
print(count)

Measured memory_bytes: 12424
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct rect {
	int x0,y0,x1,y1;
} RECT;

void proc(int n, int r);
int area_unit_scan(RECT *rs, int n, int y);
int perimeter_unit_scan_y(RECT *rs, int n, int y);
int perimeter_unit_scan_x(RECT *rs, int n, int x);

int compare_int(const void *n1, const void *n2);
int compare_rect_x0(const void *r1, const void *r2);
int compare_rect_y0(const void *r1, const void *r2);

int main()
{
	int n, r;
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) {
			break;
		}

		proc(n, r);
	}
	return 0;
}

void proc(int n, int r)
{
	int i;
	RECT *rs;
	int *xs, *ys;
	int area, perimeter;

	rs = calloc(n, sizeof(RECT));
	xs = calloc(n * 2, sizeof(int));
	ys = calloc(n * 2, sizeof(int));

	area = 0;
	perimeter = 0;

	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &rs[i].x0, &rs[i].y0, &rs[i].x1, &rs[i].y1);
		xs[2 * i] = rs[i].x0;
		xs[2 * i + 1] = rs[i].x1;
		ys[2 * i] = rs[i].y0;
		ys[2 * i + 1] = rs[i].y1;
	}

	qsort(ys, n * 2, sizeof(int), compare_int);
	qsort(rs, n, sizeof(RECT), compare_rect_x0);
	/* area */
	for (i = 0; i < 2 * n - 1; i++) {
		if (ys[i] == ys[i + 1]) {
			continue;
		}

		area += (ys[i + 1] - ys[i]) * area_unit_scan(rs, n, ys[i]);
	}

	if (r == 2) {
		/* perimeter (horizontal) */
		for (i = 0; i < 2 * n - 1; i++) {
			if (ys[i] == ys[i + 1]) {
				continue;
			}

			perimeter += (ys[i + 1] - ys[i]) *
				perimeter_unit_scan_y(rs, n, ys[i]);
		}

		/* perimeter (vertical) */
		qsort(xs, n * 2, sizeof(int), compare_int);
		qsort(rs, n, sizeof(RECT), compare_rect_y0);

		for (i = 0; i < 2 * n - 1; i++) {
			if (xs[i] == xs[i + 1]) {
				continue;
			}

			perimeter += (xs[i + 1] - xs[i]) *
				perimeter_unit_scan_x(rs, n, xs[i]);
		}
	}

	printf("%d\n", area);
	if (r == 2) {
		printf("%d\n", perimeter);
	}

	free(rs);
	free(xs);
	free(ys);
}

int compare_int(const void *n1, const void *n2)
{
	return *(const int*)n1 - *(const int*)n2;
}

int compare_rect_x0(const void *r1, const void *r2)
{
	return ((const RECT*)r1)->x0 - ((const RECT*)r2)->x0;
}

int compare_rect_y0(const void *r1, const void *r2)
{
	return ((const RECT*)r1)->y0 - ((const RECT*)r2)->y0;
}

int area_unit_scan(RECT *rs, int n, int y)
{
	int i;
	int sum, xe;
	sum = 0;
	xe = 0;
	for (i = 0; i < n; i++) {
		int x0, x1;
		if (y < rs[i].y0 || rs[i].y1 <= y) {
			continue;
		}
		x0 = rs[i].x0 > xe ? rs[i].x0 : xe;
		x1 = rs[i].x1 > xe ? rs[i].x1 : xe;
		sum += x1 - x0;
		xe = x1;
	}
	return sum;
}

int perimeter_unit_scan_y(RECT *rs, int n, int y)
{
	int i;
	int count, xe;
	count = 0;
	xe = 0;
	for (i = 0; i < n; i++) {
		if (y < rs[i].y0 || rs[i].y1 <= y) {
			continue;
		}
		if (count == 0 || xe < rs[i].x0) {
			count += 2;
		}
		xe = rs[i].x1 > xe ? rs[i].x1 : xe;
	}
	return count;
}

int perimeter_unit_scan_x(RECT *rs, int n, int x)
{
	int i;
	int count, ye;
	count = 0;
	ye = 0;
	for (i = 0; i < n; i++) {
		if (x < rs[i].x0 || rs[i].x1 <= x) {
			continue;
		}
		if (count == 0 || ye < rs[i].y0) {
			count += 2;
		}
		ye = rs[i].y1 > ye ? rs[i].y1 : ye;
	}
	return count;
}

Measured memory_bytes: 1048
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (void)
{
    intmax_t a;
    char s[11];

    scanf("%jd", &a);
    scanf("%s", s);

    if (a >= 3200)
        puts(s);
    else
        puts("red");

    return 0;
}


Measured memory_bytes: 128
x1, y1, x2, y2 = map(int, input().split())
x3 = x2+(y1-y2)
y3 = y2+(x2-x1)
x4 = x1+(y1-y2)
y4 = y1+(x2-x1)

print(str(x3)+" "+str(y3)+" "+str(x4)+" "+str(y4))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    int ans=0;
    rep(i,105){
        if(i==0) continue;
        rep(j,n) h[j]--;
        int cnt=0,pre=h[0];
        if(pre>=0) cnt++;
        rep(j,n-1){
            if(pre<0 && h[j+1]>=0) cnt++;
            pre=h[j+1];
        }
        ans+=cnt;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize, m: usize, c: i64,
        b: [i64; m],
        a: [[i64; m]; n],
    }

    println!(
        "{}",
        a.iter()
            .filter(|a| { a.iter().zip(b.iter()).map(|(a, b)| a * b).sum::<i64>() + c > 0 })
            .count()
    );
}


Measured memory_bytes: 2084
/*	AtCoder ARC090C Candies
	1st Edition:2018.1.28 Sunday
	Algorithm:Greedy
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;

#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define stop system("PAUSE")
#define ForG(a,b,c) for(rg int (a)=c.head[b];(a);(a)=c.E[a].nxt)
#define For(a,b,c) for(rg int (a)=(b);(a)<=(c);++a)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define shl(x,y) ((x)<<(y))
#define shr(x,y) ((x)>>(y))
#define mp make_pair
#define pb push_back
#define rg register
#ifdef ONLINE_JUDGE
#define hash rename_hash
#define next rename_next
#define prev rename_prev
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef double db;
const ll inf=1000000007LL;
const double EPS=1e-10;
const ll inf_ll=(ll)1e18;
const ll maxn=105LL;
const ll mod=1000000009LL;

int n;
int a[2][maxn];
int pref[2][maxn];

int main(){
	scanf("%d",&n);
	For(i,0,1) For(j,1,n){
		scanf("%d",&a[i][j]);
		pref[i][j]=pref[i][j-1]+a[i][j];
	}
	int ans=0;
	For(i,1,n) ans=max(ans,pref[0][i]+pref[1][n]-pref[1][i-1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
if r-l+1>=2019:
    print(0)
else:
    ans=2018
    for i in range(l,r):
        I=i%2019
        for j in range(i+1,r+1):
            J=j%2019
            ans=min(ans,I*J%2019)
    print(ans)

Measured memory_bytes: 41692
import sys

sys.setrecursionlimit(10 ** 9)


# map(int, sys.stdin.read().split())


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    P = list(map(float,input().split()))

    dp = [[0 for _ in range(N+1)] for i in range(N+1)]   #i枚投げたときの　j表が出た枚　のdpが確立
    dp[0][0] =1
    for i in range(1,N+1):
        for j in range(0,i+1):
            dp[i][j] = dp[i-1][j] * (1-P[i-1]) + dp[i-1][j-1]*P[i-1]

    n = (N+1)//2

    print(sum(dp[N][n:]))
    pass

if __name__ == "__main__":
    main()


Measured memory_bytes: 223932
#include <iostream>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  
  int k = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i != j){
        k += d[i]*d[j];
      }
    }
  }
  cout << k/2;


  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int path[505][505] = {};

void solve(vector<int> v, int lev){
    if(v.size() == 1) return;
    vector<int> w, x;
    rep(j,v.size()){
        if(j%2) x.push_back(v[j]);
        else w.push_back(v[j]);
    }
    rep(i,w.size()){
        rep(j,x.size()){
            path[w[i]][x[j]] = lev;
            path[x[j]][w[i]] = lev;
        }
    }
    solve(w, lev+1);
    solve(x, lev+1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v;
    rep(i,n) v.push_back(i+1);
    solve(v, 1);
    rep(i,n){
        for(int j = i+2; j <= n; ++j){
            cout << path[i+1][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    long A, B, C;
    cin >> A >> B >> C;

    if (A + B >= C)
        cout << B + C << endl;
    else
        cout << A + B + B + 1<< endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long double const pi=acos(-1);

int main() {
    
     long double a,b,x,temp;
     cin>>a>>b>>x;
     if(x<((a*a*b)/2))
     {
         temp=(a*b*b)/(2*x);
         
     }
     else
     temp=((2*(a*a*b-x))/(a*a*a));
     cout<<fixed<<setprecision(10)<<(atan(temp)*180)/pi;
     

  return 0;
    
}
    


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  ll ans=0;
  ll a[n][n];
  rep(i,n) {
    rep(j,n) cin >> a[i][j];
  }
  rep(i,n) {
    REP(j,i,n) ans+=min(a[i][j],a[j][i]);
  }
  pr(ans);
  return 0;
}


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

int	main()
{
	int	N, M, K, A;
	int	count = 0;
	int	*food;

	scanf("%d %d\n", &N, &M);
	food = (int *)calloc((M + 1), sizeof(int));
	for (int i = 0; i < N; i++)
	{
		scanf("%d ", &K);
		for (int i = 0; i < K; i++)
		{
			scanf("%d ", &A);
			food[A]++;
		}
	}
	for (int i = 0; i <= M; i++)
	{
		if (food[i] == N)
			count++;
	}
	printf("%d\n", count);
	return (0);
}

Measured memory_bytes: 128
'use strict'

const main = (input) => {
    const s = input.split('\n')[0]
    const k = parseInt(input.split('\n')[1])

    for(let i = 0; i < k; i++){
        if(s[i] !== '1'){
            console.log(s[i])
            return
        }
    }
    console.log('1')
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include<cstdio>

#define MAXN 1000
int N,cnt;
int X[MAXN+5],Y[MAXN+5],d[35];

int abs(int x){
    return x>0?x:-x;
}

void Print(int x,int y){
    for(int i=1;i<=cnt;i++){
        if(abs(x)>abs(y)){
            if(x>0) putchar('R'),x-=d[i];
            else putchar('L'),x+=d[i];
        }
        else{
            if(y>0) putchar('U'),y-=d[i];
            else putchar('D'),y+=d[i];
        }
    }
}

int main(){
    scanf("%d",&N);
    bool p[2]={0};
    for(int i=1;i<=N;i++){
        scanf("%d%d",X+i,Y+i);
        p[(abs(X[i])+abs(Y[i]))&1]=1;
    }
    if(p[0]&&p[1])
        return puts("-1"),0;
    for(int i=30;i>=0;i--)
        d[++cnt]=1<<i;
    if(p[0])
        d[++cnt]=1;
    printf("%d\n%d",cnt,d[1]);
    for(int i=2;i<=cnt;i++)
        printf(" %d",d[i]);
    for(int i=1;i<=N;i++)
        puts(""),Print(X[i],Y[i]);
}
//

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 
const double PI=3.14159265358979323846;



ll kaijo[2000010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i < 2000010;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}
 
ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}
 
ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd,N-2)) % N) % N;
}

int main(void){
    ll x,y,z,k;
	cin>>x>>y>>z>>k;
	vector<ll>a(x),b(y),c(z),d,ans;
	for(int i=0;i<x;i++)cin>>a[i];
	for(int i=0;i<y;i++)cin>>b[i];
	for(int i=0;i<z;i++)cin>>c[i];
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			d.push_back(a[i]+b[j]);
		}
	}
	sort(d.begin(),d.end(),greater<ll>());
	sort(c.begin(),c.end(),greater<ll>());
	ll L = min(k,(ll)d.size());
	for(int i=0;i<L;i++){
		for(int j=0;j<z;j++){
			ans.push_back(d[i]+c[j]);
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());
	for(int i=0;i<k;i++)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 44048
import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    ans = 0
    for i in range(N - 2):
        a = L[i]
        for j in range(i + 1, N - 1):
            k = bisect_left(L, a + L[j])
            ans += (k - 1 - j)

    print(ans)


if __name__ == "__main__":
    main()


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

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

    ll r = 0;
    ll g = 0;
    ll b = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else if (s[i] == 'B') b++;
    }

    ll ans = 1;
    ans = r * g * b;
    for (int j = 0; j < n; ++j) {
        for (int i = 0; i < j; ++i) {
            int k = j + j - i;
            if (k < n) {
                if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
ll arr[L];
ll dp[L];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll i,n;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> arr[i];
	for(i=1;i<n;i++)
	{
		dp[i] = dp[i-1] + abs(arr[i] - arr[i-1]);
		if(i!=1)
			dp[i] = min(dp[i-2] + abs(arr[i] - arr[i-2]),dp[i]);
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
*/
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
/**/ 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
const long long inf = 1e18;
 
using namespace std;

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

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

bool custom_sort(int &x, int &y)
{
    if(x<y)
        return 1;
    else
        return 0;
}

void always_ignore_function_name()
{
    int h, w,k;
    cin>>h>>w>>k;
    int cnt=0;
    int n1=power(2,h), n2=power(2,w);
    char c[h][w];
    rep(i,h)
    {
        rep(j,w)
        {
            cin>>c[i][j];
        }
    }
    rep(i1,n1)
    {
        rep(j1,n2)
        {
            int k1=0;
            rep(i,h)
            {
                rep(j,w)
                {
                    if(((1LL<<i)&i1)==0 && ((1LL<<j)&j1)==0 && c[i][j]=='#')
                        k1++;
                }
            }
            if(k1==k)
            {
                // cout<<i1<<" "<<j1<<endl;
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        always_ignore_function_name();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3804
import heapq
import sys
input = sys.stdin.readline

INF = 10 ** 18

class Edge():
    def __init__(self, start, end, cost):
        self.start = start
        self.end = end
        self.cost = cost
    def __str__(self):
        return 'Edge: {} -> {}, cost {}'.format(self.start, self.end, self.cost)

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            if dist[e.end] > dist[v] + e.cost:
                dist[e.end] = dist[v] + e.cost
                heapq.heappush(h, (dist[e.end], e.end))
    return dist


n = int(input())
es = [[] for i in range(n)]

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    es[a-1].append(Edge(a-1, b-1, c))
    es[b-1].append(Edge(b-1, a-1, c))

q, k = map(int, input().split())
k -= 1

d = dijkstra(n, es, k)

for j in range(q):
    x, y = map(int, input().split())
    print(d[x-1] + d[y-1])




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

#define int long long int

const int MAX_N = 2 * 1E5 + 10, mod = 1E9 + 7;
vector<int> gr[MAX_N];
int res = 0, n;
vector<int> powers(MAX_N);

int pw(int a, int p)
{
    int cur = a, ans = 1;
    while (p > 0) {
        if (p & 1) ans = (ans * cur) % mod;
        p /= 2;
        cur = (cur * cur) % mod;
    }
    return ans;
}

int inv(int x)
{
    return pw(x, mod - 2);
}

int DFS(int v, int p)
{
    res = (res + powers[n - 1]) % mod;
    int sz = 1, num = 0;
    for (auto d : gr[v])
    {
        if (d == p) continue;
        int cur_sz = DFS(d, v);
        res = (res - powers[cur_sz]) % mod;
        sz += cur_sz;
        num++;
    }
    if (p != -1)
    {
        int cur_sz = n - sz;
        res = (res - powers[cur_sz]) % mod;
        num++;
    }
    res = (res + num - 1) % mod;
    return sz;
}

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

    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        gr[a].push_back(b);
        gr[b].push_back(a);
    }

    powers[0] = 1;
    for (int i = 1; i <= n; i++)
        powers[i] = (powers[i - 1] * 2) % mod;

    DFS(0, -1);

    int y = (res * inv(powers[n])) % mod;
    if (y < 0) y += mod;
    cout << y << "\n";

    return 0;
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define FR first
#define SE second
#define MOD 1000000007

using namespace std;

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

int sumv[200005];

void add(int x) {
  for(;x;x-=lowbit(x)) sumv[x]++;
}

int sum(int x,int n) {
  int s=0;
  for(;x<=n;x+=lowbit(x)) s+=sumv[x];
  return s;
}

namespace SGT {

ll mulv[800000],sumv[800000];

inline void pushup(int o) {
  sumv[o]=(sumv[o*2]+sumv[o*2+1])%MOD;
}

inline void pushdown(int o) {
  if (mulv[o]!=1) {
  	mulv[o*2]=mulv[o*2]*mulv[o]%MOD;
  	mulv[o*2+1]=mulv[o*2+1]*mulv[o]%MOD;
  	sumv[o*2]=sumv[o*2]*mulv[o]%MOD;
  	sumv[o*2+1]=sumv[o*2+1]*mulv[o]%MOD;
  	mulv[o]=1;
  }
}

void build(int l,int r,int o) {
  mulv[o]=1;
  if (l==r) return;
  else {
  	int m=((l+r)>>1);
  	build(l,m,o*2);
  	build(m+1,r,o*2+1);
  }
}

void update1(int l,int r,int o,int p,int q) {
  if (l==r) sumv[o]=q;
  else {
  	pushdown(o);
  	int m=((l+r)>>1);
  	if (m>=p) update1(l,m,o*2,p,q);
  	else update1(m+1,r,o*2+1,p,q);
  	pushup(o);
  }
}

void update2(int p) {
  mulv[1]=mulv[1]*p%MOD;
}

int query(int l,int r,int o,int lx,int rx) {
  if (l>=lx&&r<=rx) return sumv[o];
  else {
  	pushdown(o);
  	int m=((l+r)>>1);
  	if (m>=rx) return query(l,m,o*2,lx,rx);
  	if (m<lx) return query(m+1,r,o*2+1,lx,rx);
  	return (query(l,m,o*2,lx,rx)+query(m+1,r,o*2+1,lx,rx))%MOD;
  }
}

}

int num[200005],pre[200005];
pr val[200005];

inline ll C(ll n) {
  return (n*(n-1)>>1)%MOD;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	scanf("%d",&num[i]);
  	val[i]=pr(num[i],i);
  }
  sort(val+1,val+n+1);
  pre[0]=1;
  for(int i=1;i<=n;i++) {
    if (val[i].FR<i) {
    	puts("0");
    	return 0;
	}
	pre[i]=(ll)pre[i-1]*(val[i].FR-i+1)%MOD;
  }
  int s=0;
  for(int i=1;i<=n;i++) {
  	add(num[i]);
  	s=(s+sum(num[i]+1,n))%MOD;
  }
  int ans=(ll)s*pre[n]%MOD;
  SGT::build(1,n,1);
  s=1;
  for(int i=n;i>0;i--) {
  	int x=val[i].SE,v=val[i].FR;
  	ans=(ans+(ll)pre[i-1]*SGT::query(1,n,1,x,n)%MOD*C(v-i+1))%MOD;
  	ans=(ans-(ll)pre[i-1]*SGT::query(1,n,1,1,x)%MOD*C(v-i+1)%MOD+MOD)%MOD;
  	SGT::update2(v-i);
  	SGT::update1(1,n,1,x,s);
  	s=(ll)s*(v-i+1)%MOD;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 16640
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
sum = a.inject(:+)
memo = 0
min = 10000000000
a.each.with_index do |num, index|
  break if (index == (a.size-1))
  memo += num
  tmp = (memo - (sum-memo)).abs
  min = tmp if (tmp < min)
end

puts min

Measured memory_bytes: 16516
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    REP(i,a+1) REP(j,b+1) REP(k,c+1) if(500*i+100*j+50*k==x) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

void solve()
{
  ll a,b;
  cin >> a >> b;
  ll prod = a*b;

  if (a==1 && b == 1)
  {
    cout << 0 << endl;
    re;
  }

  ll cnt = sqrt(prod);
  if (prod == cnt*cnt)
    cnt--;

  ll ans = 2*cnt;

  ll res = prod/cnt - (prod%cnt?0:1);

  if (res==cnt)
    ans--;

  if (a <= cnt)
    ans--;
  if (b <= cnt)
    ans--;

  cout << ans << endl;

}

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

  ll t = 1;
  cin >> t;
  while (t--)
  {
    solve();
  }
}



Measured memory_bytes: 3664
s = input()
ans = 'WA'
c_ctn = 0
low_ctn = 0
if s[0] == 'A':
    for i in range(2, len(s) - 1):
        if s[i] == 'C':
            c_ctn += 1
for i in s:
    if i.islower():
        low_ctn += 1
if c_ctn == 1 and low_ctn == len(s) - 2:
    ans = 'AC'
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int pos1=0,pos2=0,cnt=0;
void getPos(int a[],int n,int pp[],int qq[])
{
    cnt++; int flag1=0,flag2=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==pp[i] && flag1!=2)
            flag1=1;
        else
            flag1=2;
        if(a[i]==qq[i]  && flag2!=2)
            flag2=1;
        else
            flag2=2;
    }
    if(flag1==1)
        pos1=cnt;
    if(flag2==1)
        pos2=cnt;
}
int main()
{
    int n,ans;
    cin>>n;
    int p[n],q[n],perm[n];
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];
    for(int i=0;i<n;i++) perm[i]=i+1;

    do
    {
        getPos(perm,n,p,q);
    }while(next_permutation(perm,perm+n));

    ans=pos1-pos2;
    //cout<<pos1<<" "<<pos2<<endl;
    if(ans<0)
        cout<<ans*(-1)<<endl;
    else
        cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn=1e5+5;
long long Ans[Maxn];
int N,M,S,T,Vis[Maxn];
long long DistA[Maxn],DistB[Maxn],D[Maxn];
vector<pair<long long,long long> >A[Maxn],B[Maxn];

void SPFA1(){
	memset(Vis,0,sizeof Vis);
	for(int i=1;i<=N;i++)DistA[i]=1e15;
	queue<int>Q;Q.push(S);
	DistA[S]=0,Vis[S]=1;
	while(!Q.empty()){
		int front=Q.front();Q.pop();Vis[front]=0;
		for(int i=0;i<A[front].size();i++){
			if (DistA[A[front][i].first]>DistA[front]+A[front][i].second){
				DistA[A[front][i].first]=DistA[front]+A[front][i].second;
				if(!Vis[A[front][i].first])Q.push(A[front][i].first),Vis[A[front][i].first]=1;
			}
		}
	}
}
void SPFA2(){
	memset(Vis,0,sizeof Vis);
	for(int i=1;i<=N;i++)DistB[i]=1e15;
	queue<int>Q;Q.push(T);
	DistB[T]=0,Vis[T]=1;
	while(!Q.empty()){
		int front=Q.front();Q.pop();Vis[front]=0;
		for(int i=0;i<B[front].size();i++){
			if (DistB[B[front][i].first]>DistB[front]+B[front][i].second){
				DistB[B[front][i].first]=DistB[front]+B[front][i].second;
				if(!Vis[B[front][i].first])Q.push(B[front][i].first),Vis[B[front][i].first]=1;
			}
		}
	}
}

int main()
{
	scanf("%d%d%d%d",&N,&M,&S,&T);
	for(int i=1,u,v,a,b;i<=M;i++){
		scanf("%d%d%d%d",&u,&v,&a,&b);
		A[u].push_back(make_pair(v,a));
		A[v].push_back(make_pair(u,a));
		B[u].push_back(make_pair(v,b));
		B[v].push_back(make_pair(u,b));
	}
	SPFA1(),SPFA2();
	for(int i=1;i<=N;i++)D[i]=DistA[i]+DistB[i];
	Ans[N]=D[N];
	for(int i=N-1;i;i--)
		Ans[i]=D[i],Ans[i]=min(Ans[i],Ans[i+1]);
	for(int i=1;i<=N;i++)Ans[i]=1e15-Ans[i];
	for(int i=1;i<=N;i++)printf("%lld\n",Ans[i]);
	return 0;
}

Measured memory_bytes: 20224
use std::io::Read;
use std::collections::HashMap;

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

    let answer = solve(&buf);

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

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

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut factors: HashMap<usize, usize> = HashMap::new();
    for i in 2..(n + 1) {
        let f = prime_factorization(i);
        for x in f {
            *factors.entry(x.0).or_insert(0) += x.1;
        }
    }

    const MOD: usize = 1_000_000_007;
    let mut ans: usize = 1;
    for x in factors {
        ans = ans * (x.1 + 1) % MOD;
    }
    return ans.to_string();
}

fn prime_factorization(mut n: usize) -> HashMap<usize, usize> {
    let mut result: HashMap<_, _> = HashMap::new();

    for d in 2.. {
        if d * d > n {
            break;
        }
        while n % d == 0 {
            *result.entry(d).or_insert(0) += 1;
            n /= d;
        }
    }

    if n != 1 {
        result.insert(n, 1);
    }

    return result;
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
using namespace std;

int n,t,s;
int a[3001],b[3001];
int dp[3001][3001];
int front[3001],back[3001];

int main(){
  scanf("%d%d%d",&n,&t,&s);
  for(int i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);

  for(int i=0;i<=n;i++)
    for(int j=0;j<=s;j++)dp[i][j] = -1;
  dp[0][0] = 0;

  for(int i=0;i<n;i++)
    for(int j=0;j<=s;j++){
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
      if(0<=dp[i][j] && j + b[i] <= s)
	dp[i+1][j+b[i]] = max(dp[i+1][j+b[i]],dp[i][j] + a[i]);
    }

  for(int i=0;i<=n;i++)front[i] = dp[i][s];
  
  for(int i=0;i<=n;i++)
    for(int j=0;j<=t-s;j++)dp[i][j] = -1;
  dp[n][0] = 0;
  
  for(int i=n;i>0;i--)
    for(int j=0;j<=t-s;j++){
      dp[i-1][j] = max(dp[i-1][j],dp[i][j]);
      dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
      if(0<=dp[i][j] && j + b[i] <= t-s)
	dp[i-1][j+b[i]] = max(dp[i-1][j+b[i]],dp[i][j] + a[i]);
    }
 
  for(int i=0;i<=n;i++)back[i] = dp[i][t-s];
 
  int ans = 0;
  for(int i=0;i<n;i++)ans = max(ans,front[i]+back[i]);
  printf("%d\n",ans);
}

Measured memory_bytes: 35000
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    ll a = v[0], b = v[1], c = 0;
    for (int i = 2; i < n; ++i) {
        c ^= v[i];
    }
    if(a+b < c || ((a+b)&1) != (c&1)){
        puts("-1");
        return 0;
    }
    ll E = (a+b-c)/2, x = 0, y = 0;
    for (int i = 50; i >= 0; --i) {
        if((E >> i)&1) x += 1LL << i, y += 1LL << i;
    }
    for (int i = 50; i >= 0; --i) {
        if(!((E >> i)&1) && ((c >> i)&1)) {
            if(x + (1LL << i) <= a) x += 1LL << i;
            else y += 1LL << i;
        }
    }
    if((x^y) == c && x && x+y == a+b && a >= x) cout << a-x << "\n";
    else puts("-1");
    return 0;
}

Measured memory_bytes: 3676
from sys import stdin,stdout
n=int(stdin.readline())
#map(int,stdin.readline().split())
if 400<=n<=599:print(8)
if 600<=n<=799:print(7)
if 800<=n<=999:print(6)
if 1000<=n<=1199:print(5)
if 1200<=n<=1399:print(4)
if 1400<=n<=1599:print(3)
if 1600<=n<=1799:print(2)
if 1800<=n<=1999:print(1)

Measured memory_bytes: 9216
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from bisect import bisect_left
setrecursionlimit(1000000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]


def main():
    from builtins import int, map
    S, W = map(int, input().split())
    if S <= W:
        print("unsafe")
    else:
        print("safe")

if __name__ == '__main__':
    main()

Measured memory_bytes: 64896
# -*- coding: utf-8 -*-
import math

N, K = [int(a) for a in input().split(" ")]

sum = 0
for i in range(1, N+1):
    k = math.ceil(math.log2(K) - math.log2(i)) if i < K else 0
    p =  1 / (N * math.pow(2, k))
    
    # print(str(i) + ': ' + str(k))
    sum = sum + p

print(sum)

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

int main() {
  int Aprice,Bprice,ABprice,Aneed,Bneed;
  cin >> Aprice >> Bprice >> ABprice >> Aneed >> Bneed;

  int Anum = Aneed;
  int Bnum = Bneed;
  int ABnum = 0;
  int ans = INT_MAX;

  while (true) {
    int total = Aprice*Anum +
      Bprice*Bnum +
      ABprice*ABnum;

    ans = min(ans, total);

    if (Anum == 0 && Bnum == 0) {
      break;
    }

    Anum != 0 and --Anum;
    Bnum != 0 and --Bnum;
    ABnum += 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
s = input()
l = [1] * N

# S: 1, W: 0
for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)):
  l[0] = a0
  l[1] = a1

  for i in range(1, N - 1):
    if s[i] == 'o':
      if l[i] == 1:
        l[i + 1] = l[i - 1]
      else:
        l[i + 1] = not l[i - 1]
    else:
      if l[i] == 1:
        l[i + 1] = not l[i - 1]
      else:
        l[i + 1] = l[i - 1]
  
  if s[-1] == 'o':
    if l[-1] == 1:
      flag = l[0] == l[-2]
    else:
      flag = l[0] != l[-2]
  else:
    if l[-1] == 1:
      flag = l[0] != l[-2]
    else:
      flag = l[0] == l[-2]
  if flag:
    if s[0] == 'o':
      if l[0] == 1:
        flag = l[-1] == l[1]
      else:
        flag = l[-1] != l[1]
    else:
      if l[0] == 1:
        flag = l[-1] != l[1]
      else:
        flag = l[-1] == l[1]

  if flag:
    s = ''.join(['S' if i == 1 else 'W' for i in l])
    print(s)
    exit()

print(-1)

Measured memory_bytes: 4980
S = input()

a = 0
b = 0

for i, s in enumerate(S):
    if i % 2 == 0:
        if s == '0':
            a += 1
        else:
            b += 1
    else:
        if s == '1':
            a += 1
        else:
            b += 1

print(min(a, b))


Measured memory_bytes: 3188
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
s = set()
for i in range(n+1):
    if a[i] in s:
        last = n-i
        t = a[i]
        break
    s.add(a[i])
for i in range(n+1):
    if a[i] == t:
        fir = i
        break 
soto = fir + last
class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(2*10**5+10)

for i in range(1,n+2):
    rm = 0
    if i <= soto+1:
        rm = comb(soto,i-1)
    print((comb(n+1,i) - rm)%mod)
    

Measured memory_bytes: 41472
/* ***********************************************
Author        :yang12138
Created Time  :2018年01月21日 星期日 21时14分45秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)
 
const int N=2005;
 
int B[N][N],W[N][N];
 
void add(int bit[N][N],int x,int y){
	bit[x][y]++;
}
 
int sum(int bit[N][N],int x,int y){
	return bit[x][y];
}
 
int get(int bit[N][N],int x1,int y1,int x2,int y2){
	if(!(x1<=x2 && y1<=y2)) return 0;
	return sum(bit,x2,y2)-sum(bit,x2,y1-1)-sum(bit,x1-1,y2)+sum(bit,x1-1,y1-1);
}
 
void solve(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		int x,y;
		char ch;
		scanf("%d %d %c",&x,&y,&ch);
		if(ch=='B') x+=k;
		x%=2*k,y%=2*k;
		x++,y++;
		add(W,x,y);
		/*
		if(ch=='W') add(W,x,y);
		else add(B,x,y);
		*/
	}
 
	for(int i=1;i<=2*k;i++){
		for(int j=1;j<=2*k;j++){
			W[i][j]+=W[i][j-1];
			B[i][j]+=B[i][j-1];
		}
	}
	for(int j=1;j<=2*k;j++){
		for(int i=1;i<=2*k;i++){
			W[i][j]+=W[i-1][j];
			B[i][j]+=B[i-1][j];
		}
	}
 
 
	int ans=0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			int tmp=0;
			tmp+=get(W,1,1,i,j)+get(W,i+1,j+1,i+k,j+k);
			tmp+=get(W,i+k+1,j+k+1,2*k,2*k)+get(W,1,j+k+1,i,2*k)+get(W,i+k+1,1,2*k,j);
			ans=max(ans,max(tmp,(n-tmp)));
			/*
			tmp+=get(B,1,j+1,i,j+k)+get(B,i+k+1,j+1,2*k,j+k);
			tmp+=get(B,i+1,1,i+k,j)+get(B,i+1,j+k+1,i+k,2*k);
			ans=max(ans,tmp);
 
			tmp=0;
			tmp+=get(B,1,1,i,j)+get(B,i+1,j+1,i+k,i+k);
			tmp+=get(B,i+k+1,j+k+1,2*k,2*k)+get(B,1,j+k+1,i,2*k)+get(B,i+k+1,1,2*k,j);
			tmp+=get(W,1,j+1,i,j+k)+get(W,i+k+1,j+1,2*k,j+k);
			tmp+=get(W,i+1,1,i+k,j)+get(W,i+1,j+k+1,i+k,2*k);
			ans=max(ans,tmp);
			*/
		}
	}
 
	printf("%d\n",ans);
}
 
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


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

#define NIL -2000000000

typedef struct{
  int k;
  int lk;
  int rk;
}Node;

int main(){

  Node *A;
  int h,i,x;

  scanf("%d",&h);

  A = malloc((h+1)*sizeof(Node));

  for(i = 1 ; i <= h ; i++) A[i].k = A[i].lk = A[i].rk = NIL;


  for(i = 1 ; i <= h ; i++){
    scanf("%d",&x);

    A[i].k = x;
    if(i%2 == 0) A[i/2].lk = x;
    else if(i%2 == 1) A[i/2].rk =x;

  }

  for(i = 1 ; i <= h ; i++){

    printf("node %d: key = %d, ", i, A[i].k);
    if(i != 1) printf("parent key = %d, ",A[i/2].k);
    if(A[i].lk != NIL)  printf("left key = %d, ",A[i].lk);
    if(A[i].rk != NIL)  printf("right key = %d, ",A[i].rk);

    printf("\n");

  }

  return 0;

}



Measured memory_bytes: 2060
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt
import kotlin.math.tan

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val d = readInteger()
    val cList = readLongList()
    val sPerDay = Array(d) { readLongList() }
    val tArray = Array(d) { readInteger() }
    val m = readInteger()
    repeat(m) {
        val (toD, toQ) = readIntegerList()
        tArray[toD - 1] = toQ
        val score = calcScore(d, cList, sPerDay, tArray)
        out.println(score)
    }

//    for (i in 0 until d) {
//        var maxT = 1
//        var maxScore = Long.MIN_VALUE
//        for (j in 0 until 26) {
//            tArray[i] = j + 1
//            val tmpScore = calcScore(i + 1, cList, sPerDay, tArray)
//
//            if (tmpScore > maxScore) {
//                maxT = j + 1
//                maxScore = tmpScore
//            }
//        }
//
////        out.println("max score: $maxScore")
//        tArray[i] = maxT
//    }
//
//    for (t in tArray) {
//        out.println(t)
//    }
}

fun calcScore(d: Int, cList: List<Long>, sPerDay: Array<List<Long>>, tArray: Array<Int>): Long {
    var score = 0L
    val last = IntArray(26)
    for (i in 0 until d) {
        val contestNo = tArray[i] - 1
        score += sPerDay[i][contestNo]

        last[contestNo] = i + 1

        for (j in 0 until 26) score -= cList[j] * ((i + 1) - last[j])
    }

    return score
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 57928
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		if (s.equals("a") || s.equals("e") || s.equals("i") || s.equals("o") || s.equals("u")) {
			System.out.println("vowel");
		} else {
			System.out.println("consonant");
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;



int main(){
    string S; 
    cin >> S;
 
    if (S == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int x[N], y[N];
  vector<vector<int> >xarr(100005), yarr(100005);
  for(int i=0;i<N;++i) {
    cin>>x[i]>>y[i];
    xarr[x[i]].push_back(i);
    yarr[y[i]].push_back(i);
  }
  vector<vector<int> > group(100005);
  map<int, int> amap;
  queue<int> que;
  int state;
  int tmp = 0;
  map<int, int> xmap, ymap;
  for(int i=0;i<N;++i) {
    if(amap[i]>0) continue;
    que.push(i);
    amap[i]++;
    while(!que.empty()) {
      state = que.front();que.pop();
      group[tmp].push_back(state);
      if(xmap[x[state]]==0){ 
        for(int j=0;j<xarr[x[state]].size();++j) {
          if(amap[xarr[x[state]][j]]>0) continue;
          que.push(xarr[x[state]][j]);
          amap[xarr[x[state]][j]]++;
        }
        xmap[x[state]]++;
      }
      if(ymap[y[state]]==0) {
        for(int j=0;j<yarr[y[state]].size();++j) {
          if(amap[yarr[y[state]][j]]>0) continue;
          que.push(yarr[y[state]][j]);
          amap[yarr[y[state]][j]]++;
        }
        ymap[y[state]]++;
      }
    }
    tmp++;
  }
  ll ans = 0;
  for(int i=0;i<tmp;++i) {
    map<int, int> xmap, ymap;
    vector<int> xx, yy;
    for(int j=0;j<group[i].size();++j) {
      if(xmap[x[group[i][j]]]==0) xx.push_back(x[group[i][j]]);
      if(ymap[y[group[i][j]]]==0) yy.push_back(y[group[i][j]]);
      xmap[x[group[i][j]]]++;
      ymap[y[group[i][j]]]++;
    }
    ans += xmap.size()*ymap.size()-group[i].size();
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 28900