akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A>=10 || B>=10) {
			System.out.println(-1);
		}else {
		int ans = A * B;
		System.out.println(ans);
	    }
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a.begin(), a.end());
  int median;
  if(n%2 == 0) median = (a[n/2-1]+a[n/2])/2;
  else median = a[(n-1)/2];
  long long ans = 0;
  for(int i=0; i<n; i++){
    ans += abs(a[i]-median);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans=0;
	int ar[n];
	int br[n];
	for (int i=0;i<n;i++){
		cin>>ar[i];
		br[i]=0;
	}
	for (int i=1;i<n;i++){
		if (ar[i]==ar[i-1]&&br[i-1]==0){
			br[i]=1;
			ans++;
		}
	}
	printf ("%d\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a[7],b[7],c[7],k;
	for(k=0;k<=6;k++)
	{
		scanf("%d %d",&a[k] ,&b[k]);
		c[k]=a[k]-b[k];
	}
	for(k=0;k<=6;k++)
	{
		printf("%d\n",c[k]);
	}
	return 0;
}

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

int main(){
    int n, temp;
	cin >> n;
	vector<int> v(n),m(n);
	int cmax = 0;
	for (int i=0;i<n;i++){
		cin >> temp;
		cmax = max(cmax, temp);
        m[i] = cmax;
        v[i] = temp;
	}
	cmax = 0;
	for (int i=n-1; i>0; i--){
		temp = max(cmax,m[i-1]);
		cmax = max(cmax, v[i]);
		m[i] = temp;
	}
	m[0] = cmax;
	for (int x: m){
		cout << x << endl;
	}
		
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  double ans = 0;
  cin >> n;
  vector<PII> a(n);
  rep(i, n) cin >> a[i].first >> a[i].second;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      ans += sqrt((a[i].first - a[j].first) * (a[i].first - a[j].first) + (a[i].second - a[j].second) * (a[i].second - a[j].second));
    }
  }
  ans=ans *2/ n;
  cout << setprecision(20) << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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



int main() {
	int n, k;
	cin >> n >> k;
	if (500 * n >= k)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    /*LIS*/
    multiset<int> s;
    for(int i = 0; i < n; i++){
        auto it = s.lower_bound(a[i]);
        if(it == s.begin()){
            s.insert(a[i]);
        }else{
            s.erase(--it);
            s.insert(a[i]);
        } 
    }
    cout << s.size() << endl;
    return 0;
}


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

void solve() {
  int n; int64_t d; cin >> n >> d;
  d *= d;
  int ans = 0;
  while (n--) {
    int64_t x, y; cin >> x >> y;
    ans += x * x + y * y <= d;
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

void dice_north(int d[], int b[])	//北側に回転
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[1];
	d[1] = b[5];
	d[2] = b[2];
	d[3] = b[3];
	d[4] = b[0];
	d[5] = b[4];
}

void dice_south(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[4];
	d[1] = b[0];
	d[2] = b[2];
	d[3] = b[3];
	d[4] = b[5];
	d[5] = b[1];
}

void dice_west(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[2];
	d[1] = b[1];
	d[2] = b[5];
	d[3] = b[0];
	d[4] = b[4];
	d[5] = b[3];
}

void dice_east(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[3];
	d[1] = b[1];
	d[2] = b[0];
	d[3] = b[5];
	d[4] = b[4];
	d[5] = b[2];
}

int main(void){
	int dice1[5];
	int box[5];
	int dice2[5];
	int i, j;
	char kaiten[4] = { 'N', 'S', 'W', 'E' };
	int d = 0;

	for (i = 0; i < 6; i++) {
		scanf("%d", &dice1[i]);
	}
	for (i = 0; i < 6; i++) {
		scanf("%d", &dice2[i]);
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if ((dice1[0] == dice2[0]) && (dice1[1] == dice2[1]))
				if ((dice1[2] == dice2[2]) && (dice1[3] == dice2[3]))
					if ((dice1[4] == dice2[4]) && (dice1[5] == dice2[5]))
						d = 1;
			dice_east(dice2, box);
		}
		dice_north(dice2, box);
	}

	dice_west(dice2, box);
	dice_south(dice2, box);

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if ((dice1[0] == dice2[0]) && (dice1[1] == dice2[1]))
				if ((dice1[2] == dice2[2]) && (dice1[3] == dice2[3]))
					if ((dice1[4] == dice2[4]) && (dice1[5] == dice2[5]))
						d = 1;
			dice_east(dice2, box);
		}
		dice_north(dice2, box);
	}
	
	if (d == 1)
		printf("Yes\n");
	else
		printf("No\n");

	//scanf("%d", i);
	return 0;
}


Measured memory_bytes: 2108
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m;
	ll x;
	scanf("%d%d%lld",&n,&m,&x);
	for(i=0;i<10;i++)
	{
		x=x*n-m;
		printf("%d\n",x);
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    char p[1000][101];
    int h,w,i,j;
    scanf("%d%d",&h,&w);
    getchar();
    p[h][w];
    for(i=0;i<h;i++)
        gets(p[i]);
    for(i=0;i<h;i++){
        for(j=0;j<2;j++)
            printf("%s\n",p[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 2e18
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,k,p[maxn],c[maxn],vis[maxn],b[maxn],cnt,ans,pre[maxn];

inline void jud()
{
	ll tot=0,tmp=0,t2=-inf;
	rep(i,1,cnt) b[i+cnt]=b[i],tot+=c[b[i]],b[i+2*cnt]=b[i];
	rep(i,1,3*cnt) pre[i]=pre[i-1]+c[b[i]];
	if(tot>0)
	{
		ll q=k/cnt; tmp+=tot*q; ll z=k%cnt; if(!z) t2=0;
		if(q) z+=cnt,tmp-=tot;
		rep(i,1,cnt)
		{
			rep(j,i,3*cnt)
			{
				if(j-i+1>z) break;
				t2=max(t2,pre[j]-pre[i-1]);
			}
		}
	}
	else
	{
		tmp=0; if(!k) t2=0;
		rep(i,1,cnt)
		{
			rep(j,i,3*cnt)
			{
				if(j-i+1>k) break;
				t2=max(t2,pre[j]-pre[i-1]);
			}
		}
	}
	ans=max(ans,tmp+t2);
}

inline void dfs(int u,int rt)
{
	b[++cnt]=u; vis[u]=1;
	if(p[u]!=rt) dfs(p[u],rt);
	else jud();
}

int main()
{
	ans=-inf;
	n=read(); k=read(); rep(i,1,n) p[i]=read(); rep(i,1,n) c[i]=read();
	rep(i,1,n) if(!vis[i]) cnt=0,dfs(i,i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3996
N,M=map(int,input().split())
PY=[]
for i in range(M):
    p,y=map(int,input().split())
    PY.append([i,p,y])

PY_sort=sorted(PY,key=lambda x: x[2])

k=list(range(1,10**5+1))
v=[0]*10**5
cnt_dict=dict(zip(k,v))
arr=[]
for i,j,k in PY_sort:
    cnt_dict[j]+=1
    arr.append([i,str(j).zfill(6)+str(cnt_dict[j]).zfill(6)])

s = sorted(arr, key=lambda x: x[0])
for a,b in s:
    print(b)

Measured memory_bytes: 54388
void main()
{
    int[] abc = readln.split.to!(int[]);

    writeln(abc.all!(x => x == abc[0]) ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

LL n;

LL Pow(LL a, LL b, LL mod)
{
    LL res = 1;
    while (b)
    {
        if (b&1)
            res = (res*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

LL Euler(LL x)
{
    LL res = x;
    for (int i = 2;i <= x;i++)
    {
        if (x%i == 0)
        {
            while (x % i == 0)
                x /= i;
            res = res/i*(i - 1);
        }
    }
    if (x > 1)
        res = res/x*(x-1);
    return res;
}

LL Solve(int cnt, LL mod)
{
    LL res = 1e18;
    for (LL i = 1;i*i <= cnt;i++)
    {
        if (cnt%i == 0)
        {
//            cout << i << endl;
            if (Pow(10, i, mod) == 1)
                res = min(res, i);
            if (Pow(10, cnt/i, mod) == 1)
                res = min(res, cnt/i);
        }
    }
    if (res == 1e18)
        return 0;
    return res;
}

int main()
{
    int cnt = 0;
  	cin>>n;
    
        LL eul = Euler((9LL*n)/__gcd(7LL, n*9));
        LL res = Solve(eul, (9LL*n)/__gcd(7LL, n*9));
       if(res==0)res=-1;
	   cout<<res;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void){
	int n,a[4],t[100],i,c,j;
		cin>>n;
	for(i=0;i!=n;i++){
		t[i]=0;
	}
		for(i=0;i!=n*(n-1)/2;i++){
			for(j=0;j!=4;j++)
				cin>>a[j];
			if(a[2]<a[3])
				t[a[1]-1]+=3;
			else if(a[2]>a[3])
				t[a[0]-1]+=3;
			else{
				t[a[0]-1]++;
				t[a[1]-1]++;
			}
		}
	for(i=0;i!=n;i++){
		c=1;
		for(j=0;j!=n;j++){
			if(t[i]<t[j])
				c++;
		}
		cout<<c<<endl;
	}
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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 main() {
  int N;
  scanf("%d", &N);
  cout << N*N*N << endl;

}



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

struct Point{
    double x;
    double y;
};

void koch(int n, Point p1, Point p2){
    if(n==0) return;
    Point s,u,t;
    double th = M_PI*(60.0/180.0);
    s.x = (p1.x*2+p2.x*1)/3;
    s.y = (p1.y*2+p2.y*1)/3;
    t.x = (p1.x*1+p2.x*2)/3;
    t.y = (p1.y*1+p2.y*2)/3;
    u.x = (t.x-s.x)*cos(th) - (t.y-s.y)*sin(th) + s.x;
    u.y = (t.x-s.x)*sin(th) + (t.y-s.y)*cos(th) + s.y;

    koch(n-1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,p2);
}

int main(){
    int n;
    scanf("%d",&n);
    Point p1, p2;
    p1.x = p1.y = p2.y = 0.0;
    p2.x = 100.0;
    printf("%.8f %.8f\n",p1.x,p1.y);
    koch(n,p1,p2);
    printf("%.8f %.8f\n",p2.x,p2.y);
    return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vp;
int dp[100005][2];
//j=0 
int main(int argc,char const* argv[])
{
  int ans;
  string s;
  cin >> s;
  dp[0][0]=1;
  for(int i=0;i<int(s.size());i++)
    {//a+b=0;
      if(s[i]=='0') 
	{
	  dp[i+1][0]=dp[i][0];
	  dp[i+1][1]=dp[i][1];
	}
      else
	{
	  dp[i+1][1]=(dp[i][0]+dp[i][1])%MOD;
	}
      //a+b=1
      if(s[i]=='0')
	{
	  (dp[i+1][1]+=dp[i][1]*2%MOD) %=MOD;
	}
      else
	{
	  (dp[i+1][0]+=dp[i][0]*2%MOD) %=MOD;
	  (dp[i+1][1]+=dp[i][1]*2%MOD) %=MOD;
	}
    }
  ans=(dp[int(s.size())][0]+dp[int(s.size())][1])%MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,M;
    cin >> N >> M;
    ll sum = 0;
    map<ll,ll> mp;
    mp[0]++;
    rep(i,0,N){
        ll a;
        cin >> a;
        sum = (sum + a) % M;
        mp[sum]++;
    }
    ll ans = 0;
    for(auto p:mp){
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int a[N], b[N], c[M], d[M], ans[N];
  for (int i=0; i<N; i++)
    cin >> a[i] >> b[i];
  for (int i=0; i<M; i++)
    cin >> c[i] >> d[i];
  for (int i=0; i<N; i++) {
    int dis = INT_MAX, x = a[i], y = b[i];
    for (int j=0; j<M; j++) {
      if (dis > abs(x-c[j])+abs(y-d[j])) {
        dis = abs(x-c[j])+abs(y-d[j]);
        ans[i] = j+1;
      }
    }
  }
  for (int i=0; i<N; i++)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1000000
int main(){
	int n, i, j, ans = 0, prime[MAX];
	prime[0] = 0; prime[1] = 0;
	for (i = 2;i < MAX;i++) prime[i] = 1;
	for (i = 2;i < MAX;i++){
		if(prime[i] == 1){
			ans++;
			if(i < 1000) for (j = i * i;j < MAX;j += i) prime[j] = 0;
		}
		prime[i] = ans;
	}
	
	while (scanf("%d", &n) != EOF) printf("%d\n", prime[n]);
	return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

struct point {
    double x, y;
};

void koch (int d, point p1, point p2) {
    if (d == 0) return;
    point s, u, t;
    s.x = (p2.x - p1.x) / 3 + p1.x;
    s.y = (p2.y - p1.y) / 3 + p1.y;
    t.x = p2.x - (p2.x - p1.x) / 3;
    t.y = p2.y - (p2.y - p1.y) / 3;
    u.x = (t.x - s.x) * cos (pi / 3) - (t.y - s.y) * sin (pi / 3) + s.x;
    u.y = (t.x - s.x) * sin (pi / 3) + (t.y - s.y) * cos (pi / 3) + s.y;
    koch (d - 1, p1, s);
    cout << fixed << setprecision (15) << s.x << " " << fixed
         << setprecision (15) << s.y << "\n";
    koch (d - 1, s, u);
    cout << fixed << setprecision (15) << u.x << " " << fixed
         << setprecision (15) << u.y << "\n";
    koch (d - 1, u, t);
    cout << fixed << setprecision (15) << t.x << " " << fixed
         << setprecision (15) << t.y << "\n";
    koch (d - 1, t, p2);
}

int main() {
    point a, b;
    int n;
    cin >> n;
    a.x = 0, a.y = 0;
    b.x = 100, b.y = 0;

    cout << fixed << setprecision (15) << a.x << " " << fixed
         << setprecision (15) << a.y << "\n";
    koch (n, a, b);
    cout << fixed << setprecision (15) << b.x << " " << fixed
         << setprecision (15) << b.y << "\n";
}


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

#define X (INT_MAX/2-1)

int main () {
	int H, W;
	char maze[20][20];
	int d[400][400];

	cin >> H >> W;

	for (int s=0; s<H*W; s++)
		for (int g=0; g<H*W; g++)
			d[s][g] = X;

	for (int col=0; col<H; col++)
		for (int row=0; row<W; row++) {
			cin >> maze[col][row];
			if (maze[col][row] == '.') {
				if (col>0 && maze[col-1][row]=='.') {
					d[(col-1)*W+row][col*W+row] = 1;
					d[col*W+row][(col-1)*W+row] = 1;
				}
				if (row>0 && maze[col][row-1]=='.') {
					d[col*W+row-1][col*W+row] = 1;
					d[col*W+row][col*W+row-1] = 1;
				}
			}
		}

	for (int v=0; v<H*W; v++)
		for (int s=0; s<H*W; s++)
			for (int g=s+1; g<H*W; g++) {
				int tmp = d[s][v] + d[v][g];
				if (d[s][g] > tmp) {
					d[s][g] = tmp;
					d[g][s] = tmp;
				}
			}

	int max = -1;
	for (int s=0; s<H*W; s++)
		for (int g=s+1; g<H*W; g++) {
			if (max < d[s][g] && d[s][g] != X)
				max = d[s][g];
		}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,a,b;
    cin>>a>>b>>n;
    long long ans2 = -1;
    if (n>=b){
        ans2 = (a*(b-1))/b - a*((b-1)/b);
    }
    else ans2 = (a*(n))/b - a*((n)/b);
    cout<<ans2<<endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int palindrome_count = 0;
  int digit_num = 5;
  for (int i = a; i <= b; i++) {
    string check_num = to_string(i);
    int num_arr[digit_num];
    transform(begin(check_num), end(check_num), num_arr, [](char c){return c - '0';});
    for (int j = 0; j < digit_num; j++) {
      	if (j >= (digit_num - 1 - j)) {
        	palindrome_count++;
          	break;
        }
    	if (num_arr[j] != num_arr[digit_num - 1 - j]) {
        	break;
        }
    }
  }
  
  cout << palindrome_count << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<vector<pair<int,int>>> G(N+1,vector<pair<int,int>>(0));
  for(int i=0;i<N-1;i++){
    int u,v,w;
    cin >> u >> v >> w;
    G[u].push_back(make_pair(v,w));
    G[v].push_back(make_pair(u,w));
  }
  
  vector<int> state(N+1,-1);
  state[1] = 0;
  queue<int> Q;
  Q.push(1);
  while(!Q.empty()){
    int u = Q.front();
    Q.pop();
    for(int i=0;i<G[u].size();i++){
      int v = G[u][i].first;
      int w = G[u][i].second;
      if(state[v]==-1){
        state[v] = state[u] + w;
        state[v] %= 2;
        Q.push(v);
      }
    }
  }
  
  for(int i=1;i<=N;i++) cout << state[i] << endl;
  return 0;
}


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

int main(){
    string s,ans = "";
    cin >> s;
    for(int ix;ix<s.size();ix++){
        if(s.at(ix) == '0') ans += "0";
        if(s.at(ix) == '1') ans += "1";
        if(s.at(ix) == 'B' && !ans.empty()) ans.erase(ans.end()-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
n=int(input())
ans = 0
for i in range(1, n + 1):
    if i % 2 == 0:
        continue
    t = i
    c = 0
    for j in range(1, i + 1):
        if t % j == 0:
            c += 1
    if c == 8:
        ans += 1
print(ans)

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

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


Measured memory_bytes: 4412
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int num = 1;
        for (int i = 1 ; i <= n ; i++) {
            int x = i;
            int count = 0;
            while (x % 2 == 0) {
                count++;
                x /= 2;
            }
            if (count > max) {
                num = i;
                max = count;
            }
        }
        System.out.println(num);
    }

}

Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
vector<vector<ll>>adj(500000);
ll visited[500000]{0};
int main()
{
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        double num = (double)(sum)/(double)(4*m);
       // cout<<num<<endl;
        if(a[i]>=num)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 11904
#include <stdio.h>

int main(){
	int j,s_length = 0;
	char s[101],p[101];
	scanf("%s",s);
	scanf("%s",p);

	for(int i = 0; s[i] != '\0';i++) s_length++;

	for(int left = 0;s[left] != '\0';left++){
		for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
		if(p[j] == '\0'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}



Measured memory_bytes: 2628
import java.util.Scanner;

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

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				char[] c = String.valueOf(i).toCharArray();
				for (int j = 0; j < c.length; j++) {
					if (c[j] == '3') {
						flag = 1;
					}
				}
				if (flag == 1) {
					System.out.print(" " + i);
					flag = 0;
				}
			}
		}
		System.out.println();
		sc.close();
	}
}



Measured memory_bytes: 29456
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
//typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

int dp[101][101];
int lst[101][26];


void solve() {
	int X, Y; cin >> X >> Y;
	if (X % Y == 0)print(-1);
	else print(X);
}


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

	solve();
}




Measured memory_bytes: 256
def prePhase(u):
    left,right=T[u]
    if u==-1:return
    print(" {}".format(u), end="")
    prePhase(left)
    prePhase(right)


def inPhase(u):
    left,right=T[u]
    if u==-1:return
    inPhase(left)
    print(" {}".format(u), end="")
    inPhase(right)


def postPhase(u):
    left,right=T[u]
    if u==-1:return
    postPhase(left)
    postPhase(right)
    print(" {}".format(u), end="")


n=int(input())
A=sorted([list(map(int,input().split())) for i in range(n)])
T=[]
top=[i for i in range(n)]
for i in range(n):
    B=A[i]
    node,left,right=B[0],B[1],B[2]
    if left!=-1:top.remove(left)
    if right!=-1:top.remove(right)
    T.append([left,right])
top=top[0]

print("Preorder")
prePhase(top)
print()
print("Inorder")
inPhase(top)
print()
print("Postorder")
postPhase(top)
print()


Measured memory_bytes: 5624
n = gets.strip.to_i

a = [[0, 0, 0]]

enable = true
n.times do |i|
  a << gets.strip.split.map(&:to_i)
  j = i + 1
  # t: time
  t = a[j][0] - a[i][0]
  d = (a[j][1] - a[i][1]).abs + (a[j][2] - a[i][2]).abs
  # 移動距離が時間をオーバしている... 無理
  if t < d
    enable = false
  # 時間が距離をオーバしている場合
  # 残り時間が偶数であれば、折り返しで着地可能
  elsif t > d && (t - d).odd?
    enable = false
  end
end

puts enable ? 'Yes' : 'No'


Measured memory_bytes: 9468
#include<stdio.h>
#include<string.h>

char list[200][11], p = 0;
int check(char *s){
  int i;
  for (i = 0; i < p; i++){
    if(strcmp(list[i], s) == 0){
      return i;
    }
  }
  strcpy(list[i], s);
  p++;
  return i;
}

int main(){
  int N, M, count[201] = {0}, max = -100, q;
  char s[11];
  
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    scanf("%s",s);
    count[check(s)]++;
  }
  scanf("%d", &M);
  for (int i = 0; i < M; i++){
    scanf("%s", s);
    count[check(s)]--;
  }
  
  for (int i = 0; i < 200; i++){
    if(max < count[i]){
      max = count[i];
    }
  }
  
  printf("%d\n", max);
  
  return 0;
}
  

Measured memory_bytes: 128
import java.util.Queue
import java.util.LinkedList
class Job(val n:String,val c:Int)
{
    public var namae:String = n
    public var cost:Int = c
}
fun main(args: Array<String>) {
    //val n = readLine()!!.toInt()
    val input: List<String> = readLine()!!.split(" ").map { it.toString() }
    val q:Int =input[1].toInt()
    var t :Int=0
    val task: Queue<Job> = LinkedList<Job>()
    for (i in (1..input[0].toInt())) {
        val tmp = (readLine()!!.split(" ").map { it.toString() })
        task.add(Job(tmp[0], tmp[1].toInt()))
    }
    while (task.count()>0)
    {
        var i :Job = task.remove()
        if (i.cost>q)
        {
            t = t + q
            task.add(Job(i.namae,i.cost-q))
        }
        else
        {
            t = t + i.cost
            println(i.namae + " " + t)
        }
    }
}


Measured memory_bytes: 76980
a,b,c = map(int, input().split())

#sqrt(a)+sqrt(b) < sqrt(c)
#(sqrt(a)+sqrt(b))**2 < c
#a + 2*sqrt(a)*sqrt(b) + b < c
#2*sqrt(a)*sqrt(b) < c - a - b
#4ab < (c - a - b)**2

if 4*a*b < (c-a-b)**2 and c-a-b > 0:
    print("Yes") 
else:
    print("No")

Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s, t;
char ch[10];
int n, a, b, c, d, x, m[5];

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int A, B, K,i,j=0;
	int yakusuu[100];
	scanf("%d %d %d", &A, &B, &K);
	for (i = 1;i<=100;i++)
	{
		if ((A%i== 0 )&& (B%i == 0))
		{
			yakusuu[j] = i;
			j++;
		}
	}
	printf("%d\n", yakusuu[j - K]);
	return 0;
}


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

int power(int a, int x){
    if(x == 0) return 1;
    if(x % 2) return a * power(a * a, x / 2);
    return power(a * a, x / 2);
}

int main(){
    int d, n;
    cin >> d >> n;
    cout << power(100, d) * (n + (n == 100)) << "\n";
    return 0;
}

Measured memory_bytes: 256
W, H, N = list(map(int, input().split()))

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = max([xb, X[_]])
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = min([xe, X[_]])
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = max([yb, Y[_]])
    else:
        # Yiより大きいを黒
        ye = min([ye, Y[_]])
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = -1e9;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int solve(vector<int>b) {
	int num = 0;
	int ans=0;
	int pre = -1;
	for (auto a : b) {
		if (a > pre) {
			num++;
			ans=max(ans,num);
			pre = a;
		}
		else if (a == pre) {

		}
		else {
			pre = a;
			num = 1;
		}
	}
	return ans;
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
};
int main() {
	int N;cin>>N;
	vector<int>v(N);
	for (int i = 0; i < v.size(); ++i) {
		cin>>v[i];
	}
	Compress<int>comp(v);
	for (auto&a : v) {
		a=comp.mp[a];
	}
	int ans1=solve(v);

	for(auto&a:v){
		a=N-a;
	}
	int ans2=solve(v);
	cout<<max(ans1,ans2)<<endl;
	
	return 0;
} 

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

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

    vector<int> a(N + 1), b(N + 1);
    for (int i = 1; i <= N; ++i) a[i] = b[i] = N;

    ll black = ll(N - 2) * (N - 2);

    int H = N, W = N;

    while (Q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            if (x < W) {
                for (int i = x; i < W; ++i) {
                    b[i] = H;
                }
                W = x;
            }
            black -= b[x] - 2;

        } else {
            if (x < H) {
                for (int i = x; i < H; ++i) {
                    a[i] = W;
                }
                H = x;
            }
            black -= a[x] - 2;
        }
    }
    cout << black << endl;

    return 0;
}


Measured memory_bytes: 4808
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,d = get_nums_l()
    ans = 0
    for i in range(n):
        x,y = get_nums_l()
        dis_s = x**2 + y**2
        if d**2 >= dis_s:
            ans += 1
    print(ans)
main()

Measured memory_bytes: 69284
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int get_middle(int head, int tail){
    if((tail - head) % 2){
        return (tail + head) / 2;
    }else{
        return (tail + head + 1) / 2;
    }
}

bool binary_search(int* s, int num, int head, int tail){
    if (head == tail){
        if(s[head] == num){
            return true;
        }else{
            return false;
        }
    }else if(tail - head == 1){
        if(s[head] == num || s[tail] == num){
            return true;
        }else{
            return false;
        }
    }
    int middle = get_middle(head, tail);
    if(s[middle] == num){
        return true;
    }else if(s[middle] > num){
        return binary_search(s, num, head, middle - 1);
    }else if(s[middle] < num){
        return binary_search(s, num, middle + 1, tail);
    }
    printf("error\n");
    return false;
}      

int main(void){
    int n;
    scanf("%d", &n);

    int s[100000];
    for(int i = 0; i < n; i++){
        scanf("%d", &s[i]);
    }

    int q;
    scanf("%d", &q);

    int t[50000];
    for(int i = 0; i < q; i++){
       scanf("%d", &t[i]);
    }

    int cnt = 0;
    for(int i = 0; i < q; i++){
        if(binary_search(s, t[i], 0, n - 1)){
            cnt++;
        }
    }

    printf("%d\n", cnt);
}




Measured memory_bytes: 3792
N, x = map(int,input().split())
a = list(map(int,input().split()))

inf = float('inf')
ans = inf

time = [[inf] * N for _ in range(N)]

for i in range(N):
    tmp = inf
    for k in range(N):
        ni = i + k
        if ni > N - 1:
            ni %= N
        tmp = min(tmp, a[ni])
        time[i][k] = tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time[i][k]
    ans = min(ans, res)

print(ans)

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> svec(H);

    for (int i = 0; i<H; i++) {
        cin >> svec.at(i);
    }

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

    bool answer = true;

    for (int i = 0; i<H; i++) {
        for (int j = 0; j<W; j++) {
            if (svec.at(i).at(j) == '.') {
                continue;
            }
            bool exist = false;
            for (int d=0; d<4; d++) {
                const int ni = i + dx[d];
                const int nj = j + dy[d];

                if (ni < 0 || ni >= H) {
                    continue;
                }
                if (nj < 0 || nj >= W) {
                    continue;
                }
                if (svec.at(ni).at(nj) == '#') {
                    exist = true;
                }

            }if (!exist) {
                answer = false;
                break;
            }
        }
    }
    if (answer) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 2");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
            //POSSIBLE
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4 3");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
            WillReturn.Add("3 4");
            //IMPOSSIBLE
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("100000 1");
            WillReturn.Add("1 99999");
            //IMPOSSIBLE
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("5 5");
            WillReturn.Add("1 3");
            WillReturn.Add("4 5");
            WillReturn.Add("2 3");
            WillReturn.Add("2 4");
            WillReturn.Add("1 4");
            //POSSIBLE
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();
        SplitAct(InputList[0]);
        int N = wkArr[0];

        var ZenhanSet = new HashSet<int>();
        var KouhanSet = new HashSet<int>();

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            int A = wkArr[0];
            int B = wkArr[1];

            if (A == 1) {
                ZenhanSet.Add(B);
            }
            if (B == N) {
                KouhanSet.Add(A);
            }
        }
        ZenhanSet.IntersectWith(KouhanSet);

        if (ZenhanSet.Count>0) {
            Console.WriteLine("POSSIBLE");
        }
        else Console.WriteLine("IMPOSSIBLE");
    }
}


Measured memory_bytes: 37156
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

signed main(){
	string s;
	cin>>s;
	int out=0;
	int t=0;
	rep(i,s.size())if(s[i]=='W'){
		out+=i-t;
		t++;
	}

	cout<<out<<endl;
}


Measured memory_bytes: 640
def is_kaibun(word):
    result = True
    for i in range(len(word) // 2):
        if word[i] != word[len(word) - i - 1]:
            result = False
            break
    return result


def main():
    s = input()
    l = len(s)
    answer = is_kaibun(s) and is_kaibun(s[:(l - 1) // 2]) and is_kaibun(s[(l + 3) // 2 - 1:])
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cin(string, s, t);
    For(i, n+1){
        // Cout(string(s.begin() + i, s.end()), " ", string(t.begin(), t.end() - i), " ", n+i);
        if(string(s.begin() + i, s.end()) == string(t.begin(), t.end() - i)){
            Cout(n+i);
            break;
        }
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  // prep
  vector<int> acc(n+1);
  repeat(i,1,n) {
    if(s[i]=='C'&&s[i-1]=='A')
      acc[i+1]=acc[i]+1;
    else
      acc[i+1]=acc[i];
  }
  rep(t,q) {
    int l,r;
    cin>>l>>r;
    if(l>=2&&s[l-1]=='C'&&s[l-2]=='A')
      cout << acc[r]-acc[l-1]-1<<endl;
    else
      cout << acc[r]-acc[l-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b; cin >> a >> b;
  bool can = false;
  int n;
  for (int i=0; i < 1010; i++) {
  if(i*2/25 == a && i/10 == b){
  n = i;
    can = true;
    break;
  }
  }
  if (can) cout << n;
  else cout << -1;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;    
    
    vvl G(n);  // 辺の重みがすべて1のグラフ
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
    }

    ll sv, gv;
    cin >> sv >> gv;
    sv--;  gv--;
    
    // BFS。計算量はO(V+E)
    vvl dist(n, vl(3, -1));  // dist[v][x] : 頂点svから頂点vへの、移動回数を3で割った余りがｘとなる最短距離(-1のとき未訪問)
    queue<P> Q;
    dist[sv][0] = 0;
    Q.push(make_pair(sv, 0));
    while(!Q.empty()) {
        ll v = Q.front().first;
        ll x = Q.front().second;
        Q.pop();
        for(auto u : G[v]) {
            ll nx = (x+1)%3;
            if(dist[u][nx] == -1) {
                dist[u][nx] = dist[v][x] + 1;
                Q.push(make_pair(u, nx));
            }
        }
    }

    if(dist[gv][0] == -1) {
        out(-1);
    }
    else {
        out(dist[gv][0]/3);
    }

    re0;
}

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

int main()
{
	int n, k; cin >> n >> k;
	
	vector<int> l(n); for (int i = 0; i < n; i++) cin >> l[i];

	sort(l.begin(), l.end(), greater<int>());
	
	int ans = 0;
	for (int i = 0; i < k; i++) ans += l[i];
	
	cout << ans << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int H, W, A, B;
	cin>>H>>W>>A>>B;
	vector<vector<int>> ans(H, vector<int> (W,0));
	rep(i,H)rep(j,A)if(i>=B)ans[i][j] = 1;
	rep(j,W)rep(i,B)if(j>=A)ans[i][j] = 1;
	rep(i,H){rep(j,W)cout<<ans[i][j]; cout<<endl;}
	return 0;
}

// int main(){
// 	int H, W, A, B; 
// 	cin>>H>>W>>A>>B;
// 	vector<vector<int>> ans(H, vector<int> (W,0));
// 	bool can = true;
// 	if(B != 0 && B*3 < H)can = false;
// 	if(A != 0 && A*3 < W)can = false;
// 	if(!can){cout<<"No"<<endl; return 0;}
// 	rep(i,H)rep(j,W){
// 		int ok = 1;
// 		if(B != 0)if((i/B)%2 == 1){ok *= -1;}
// 		if(A != 0)if((j/A)%2 == 1){ok *= -1;}
// 		if(ok == 1)ans[i][j] = 1;
// 	}
// 	rep(i,H){rep(j,W)cout<<ans[i][j]; cout<<endl;}
// 	return 0;
// }

Measured memory_bytes: 5120
n=int(input())
s=input()
sirocnt=s.count('.')
kurocnt=0
ans=[sirocnt]
for i in range(n):
    if s[i]=='.':
        sirocnt-=1
    else:
        kurocnt+=1
    ans.append(sirocnt+kurocnt)
print(min(ans))

Measured memory_bytes: 11264
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M,X = map(int, readline().split())
data = np.array(read().split(), np.int64)
data = data.reshape(N,-1)
C = data[:,0]
A = data[:,1:]

cost = np.zeros(1<<N, np.int64)
ability = np.zeros((1<<N, M), np.int64)

for i in range(N):
  cost[1<<i:1<<(i+1)] = cost[:1<<i] + C[i]
  ability[1<<i:1<<(i+1)] = ability[:1<<i] + A[i]

ok = np.all(ability >= X, axis=1)

x = cost[ok]
answer = -1 if len(x) == 0 else x.min()
print(answer)

Measured memory_bytes: 27540
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m));
    vector<int> b(m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> A[i][j];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    for (int i = 0; i < n; i++)
    {
        int res = 0;
        for (int j = 0; j < m; j++)
            res += A[i][j] * b[j];
        cout << res << endl;
    }
}



Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){

  int N,M;
  cin>>N>>M;
  vector<bool>check(N,0);
  vector<int>p(M);
  vector<string>S(M);
  vector<int>pena(N,0);
  for(int i=0;i<=M-1;i++){
  
    cin>>p[i]>>S[i];
  }
  int ac=0;
  int penanum=0;
  for(int i=0;i<=M-1;i++){
  
    if(S[i]=="AC"){
    
      if(check[p[i]-1]==0){
      
        check[p[i]-1]=1;
        ac++;
      }
    }
    if(S[i]=="WA"){
    
      if(check[p[i]-1]==0){
      
        pena[p[i]-1]++;
      }
    }
  }
  for(int i=0;i<=N-1;i++){
  
    if(check[i]==1){
    
      penanum+=pena[i];
    }
  }
  cout<<ac<<" "<<penanum;
  return 0;
}

Measured memory_bytes: 7084