akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		q[i] = p[i];
	}
	sort(q.begin(), q.end());
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] != q[i]) {
			cnt++;
		}
	}
	if (cnt == 0 or cnt == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int, int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<ll> > vvl;
typedef vector<ll> vl;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define puts(s) cout<<(s)<<endl
#define inf (1000000007)
#define nil -1

int main() {
	string s, e;
	cin >> s >> e;
	int n = s.size() + e.size();
	rep(i, 0, n) {
		cout << (i % 2==0 ? s[i/2] : e[i/2]);
	}
	cout << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            var h = new HashSet<char>(s);

            Console.WriteLine(s.Length == h.Count ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 13396
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
 
class bipartite_matching {
public:
    int n;
    vector<vector<int>> g;
    vector<int> match;
 
    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}
 
    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
 
    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for (int v = 0; v < n; ++v) {
            if (match[v] == -1) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }
 
private:
    vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w == -1 || (!used[w] && dfs(w))) {
                match[v] = u; match[u] = v;
                return true;
            }
        }
        return false;
    }
};
 
int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}
 
int n, m;
int a[500], b[500];
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    while (cin >> n >> m && n) {
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
 
        bipartite_matching bm(n + m);
 
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (gcd(a[i], b[j]) != 1) {
                    bm.add_edge(i, n + j);
                }
            }
        }
 
        cout << bm.maximum_matching() << '\n';
    }
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    ll h, n = 1, ans = 0;
    cin>>h;
    while(h!=0){
        ans += n;
        h /= 2;
        n *= 2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
W,H,x,y = map(int,input().split())
answer = -1
if x == W/2:
    answer += 1
    if y == H/2:
        answer += 1
    print(str(W*H/2)+' '+str(answer))
    exit()
 
elif y == H/2:
    answer += 1
    if x == W/2:
        answer += 1
    print(str(W*H/2)+' '+str(answer))
    exit()
else:
    print(str(W*H/2)+' '+str(0))
    

Measured memory_bytes: 3064
N, M = map(int, input().split())
s = []
c = []
for _ in range(M):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)

for i in range(0, 999):
    i = str(i)
    if len(i) == N:
        tf = True
        for j in range(M):
            if i[s[j] - 1] != str(c[j]):
                tf = False
                break
        if tf == True:
            print(i)
            exit()

print(-1)


Measured memory_bytes: 8992
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;

    static int n, c;
    static int[] S, T, C;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        c = in.nextInt();
        S = new int[n];
        T = new int[n];
        C = new int[n];
        for(int i = 0; i < n; i++) {
            S[i] = in.nextInt();
            T[i] = in.nextInt();
            C[i] = in.nextInt();
        }

        int[] memo = new int[200005];
        int[] counts = new int[200005];
        for(int j = 1; j <= c; j++) {
            Arrays.fill(memo, 0);
            for(int i = 0; i < n; i++) {
                if(j == C[i]) {
                    int si = S[i];
                    int ti = T[i];
                    memo[2*si-1]++;
                    memo[2*ti]--;
                }
            }
            for(int i = 1; i < 200005; i++) {
                memo[i] += memo[i-1];
            }
            for(int i = 0; i < 200005; i++) {
                if(memo[i] > 0) {
                    counts[i]++;
                }
            }
        }

        int ans = Arrays.stream(counts).max().getAsInt();
        print(ans);
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }

    static void print(float i) {
        System.out.println(i);
    }
}


Measured memory_bytes: 94508
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,n;
int main(){
	cin>>n;
	for(int a=1;a<=n;a++)
		for(int b=1;b<=n;b++)
			for(int c=1;c<=n;c++){
				ans+=__gcd(__gcd(a,b),c);
			}
	cout<<ans;
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll sum = 0, lsum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  ll ans = 1LL << 60;
  for (int i = 0; i < n - 1; i++) {
    lsum += a[i];
    sum -= a[i];
    ans = min(ans, abs(lsum - sum));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
num = gets.to_i
ary = gets.split.map(&:to_i)

puts ary.join(" ")

for i in 1..num-1

  check = i

  while check >= 1 && ary[check - 1] > ary[check]

    ary[check - 1], ary[check] = ary[check], ary[check - 1]
    check -= 1
  end

  puts ary.join(" ")
end



Measured memory_bytes: 6892
from collections import Counter
def primes(n):
    pp = [True] * (n+1000)
    pp[0] = False
    pp[1] = False

    for i in range(2,n+1000):
        if pp[i]:
            for j in range(2,(n+1000)//i):
                pp[i*j] = False
    result = [i for i in range(n+1) if pp[i]]
    return result



if __name__=="__main__":
    N= int(input())

    pr = primes(N)
    counter = Counter()
    for p in pr:
        x = p
        while x <= N:
            counter[p] += N//x
            x *= p
    result = 1
    for x in counter.values():
        result = (result * (x+1)) % 1000000007
    print(result)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n,m;
double dp[3005][3005];
double ans;
int main()
{
	scanf("%d",&n);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		double p;
		scanf("%lf",&p);
		for(int j=0;j<i;j++)
		{
			dp[i][j+1]+=dp[i-1][j]*p;
			dp[i][j]+=dp[i-1][j]*(1-p);
		}
	}
	for(int i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	printf("%.11lf",ans);
	return 0;
}



Measured memory_bytes: 68992
#include <bits/stdc++.h>
#define maxn 100
#define maxv 1000
using namespace std;

int n,m;
int w[maxn];
int v[maxn];
int ar[maxn];
int dp[maxn*maxv+1];

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 0 ; i < n ; i++ )
		scanf("%d%d",&w[i],&v[i]);
	for( int i = 1 ; i <= n*maxv ; i++ )
		dp[i] = INT_MAX;
	for( int i = 0 ; i < n ; i++ )
		for( int j = n*maxv - v[i] ; j >= 0 ; j-- )
			if( dp[j] <= m )
				dp[j+v[i]] = min( dp[j+v[i]] , dp[j] + w[i] );
	for( int i = n*maxv ; i >= 0 ; i-- )
		if( dp[i] <= m ) {
			printf("%d\n",i);
			break;
		}
	return 0;
}


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

int main()
{
   ll n;cin>>n;
   int x=n%10;
   if(x==2||x==4||x==5||x==7||x==9) cout<<"hon"<<"\n";
   else if(x==0||x==1||x==6||x==8) cout<<"pon"<<"\n";
   else cout<<"bon"<<"\n";
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int h,w,k;
char g[10][10];
bool ok(int a,int b){
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if((a&(1<<i))==0 && (b&(1<<j))==0){
			   //都没被选中 
				if(g[i][j]=='#') ans++;
			}
		}
	}
	if(ans==k) return true;
	return false;
}
int main(int argc, char** argv) {	
	char t;
	int ans=0;
	cin>>h>>w>>k;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>g[i][j];
		}
	}
	for(int i=0;i<(1<<h)-1;i++){
		for(int j=0;j<(1<<w)-1;j++){
			if(ok(i,j)){
				ans++;
				//cout<<i<<" "<<j<<endl;
			} 
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	string a, b;
	cin >> a >> b;

	int ab = stoi(a + b);

	for(int i = 1; i < 1001; i++){
		if(ab == i * i){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

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

int partition(int* A, int p, int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}


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

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

    int k = partition(A, 0, n - 1);

    for(int i = 0; i < n; i++){
        if (i == k){
            printf("[%d] ", A[i]);
        }else if(i == n - 1){
            printf("%d\n", A[i]);
        }else{
            printf("%d ", A[i]);
        }
    }

}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,a[100010],b,ans;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

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

    for(ll i=0; i<n; i++){
        cin >> b;
        ans+=min( b , a[i] );
        b-=min( b , a[i] );
        ans+=min( b , a[i+1] );
        ll c = min( b , a[i+1] );
        b-=c;
        a[i+1]-=c;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string S, T;
  std::cin >> S;
  std::cin >> T;
  int count = 0;
  for(int i=0;i<3;i++) if(S[i]==T[i]) count++;
  std::cout << count << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

struct task {
    string name;
    int times;
};

int main()
{
    int n, q;
    int elaps = 0;
    queue<task> Q;

    cin >> n >> q;

    for(int i = 0; i < n; i++) {
        task tmp;
        cin >> tmp.name >> tmp.times;
        Q.push(tmp);
    }

    while(!Q.empty()) {
        task p = Q.front(); Q.pop();
        if(p.times <= q) {
            elaps += p.times;
            cout << p.name << " " << elaps << endl;
        }
        else {
            p.times -= q;
            elaps += q;
            Q.push(p);
        }
    }
    return 0;
}

Measured memory_bytes: 6332
class Integral
  def initialize
    @max = 600
    @area = 0
    @d = 0
  end

  def func(x)
    return (x ** 2)
  end

  def d=(val)
    @d = val
    @area = 0
  end

  def calc_area
    @d.step(@max - @d, @d){|i| @area += func(i) * @d}
    @area
  end
end

integral = Integral.new

while line = gets do
  integral.d = line.to_i
  puts integral.calc_area
end

Measured memory_bytes: 8584
import sys
from collections import deque
s=sys.stdin.readlines()
_,q=map(int,s[0].split())
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)


Measured memory_bytes: 16300
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(void){
  int n;
  vector<pair<int, int>> tasks;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }

  sort(tasks.begin(), tasks.end());

  int sum = 0;
  bool is_yes = true;

  for (auto v: tasks){
    sum += v.second;
    if(sum > v.first){
      is_yes = false;
      break;
    }
  }
  cout << (is_yes ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 2420
fun main(args: Array<String>) {
  readLine()!!
  val a = readLine()!!.split(" ").map { it.toInt() }
  var b = mutableMapOf<Int, Int>()
  for (x in a) {
    b[x] = if (x in b) b[x]!! + 1 else 1 
  }
  var sum = 0
  var cnt = 0
  for ((k, v) in b) {
    if (v % 2 == 0) {
      sum += 2
      cnt++
    } else {
      sum++
    }
  }
  println(sum - (cnt + 1) / 2 * 2)
}


Measured memory_bytes: 56372
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

fn main() {
    let (n, k) = read!(usize, usize);

    let mut ans = 0.0;

    for i in 1..(n + 1) {
        let mut point = 0;
        let mut p = 1.0 / n as f64; // i が出る確率
        point += i;
        while 1 <= point && point <= k - 1 {
            p *= 1.0 / 2.0;
            point *= 2;
        }
        ans += p;
    }
    println!("{}", &ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,m;
    cin>>n>>m;
    //答えの候補としてm/nより大きくなることはない
    //なんかn=1怖いから消しとこ
    if(n==1){cout<<m<<endl;return 0;}
    /*
    例えばある数kが答えになるときって
    k,k,...,k,mk (m>=1)みたいな時しか考えなくていい
     */
    for(ll i=m/n;i>=0;i--){
        if((m-i*(n-1))%i==0){
            cout<<i<<endl;return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    int H, W;
    cin >> H >> W;
    int Ch, Cw, Dh, Dw;
    cin >> Ch >> Cw >> Dh >> Dw;
    vector<vector<bool>> maze(H+2, vector<bool>(W+2,false)); // 道ならtrue
    rep(i,1,H+1) rep(j,1,W+1) {
        char c;
        cin >> c;
        if (c == '.') maze[i][j] = true;
    }

    vector<vector<int>> dist(H+2, vector<int>(W+2, 1000000000));
    priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> q;
    dist[Ch][Cw] = 0;
    q.push(make_pair(0,make_pair(Ch,Cw)));
    vector<int> dh0 = {0,-1,0,1}, dw0 = {1, 0, -1, 0};

    while (q.size()) {
//        cout << "enter" << endl;
        auto p = q.top();
        int d = p.first;
        int h = p.second.first;
        int w = p.second.second;
        q.pop();

        if (dist[h][w] < d) continue;
        if (h == Dh && w == Dw) break;

        rep(i,0,4) {
            int nh = h + dh0[i];
            int nw = w + dw0[i];
            if (in(nh,1,H+1) && in(nw,1,W+1)) {
                if (d < dist[nh][nw] && maze[nh][nw]) {
                    dist[nh][nw] = d;
                    q.push(make_pair(d,make_pair(nh,nw)));
                }
            }
        }

        rep(i,-2,3) rep(j,-2,3) {
            int nh = h + i;
            int nw = w + j;
            if (in(nh,1,H+1) && in(nw,1,W+1)) {
                if (d + 1 < dist[nh][nw] && maze[nh][nw]) {
                    dist[nh][nw] = d + 1;
                    q.push(make_pair(d+1,make_pair(nh,nw)));
                }
            }
        }
    }

    if (dist[Dh][Dw] == 1000000000) {
        cout << -1 << endl;
    } else {
        cout << dist[Dh][Dw] << endl;
    }
/*
    for (auto v : dist) {
        for (auto vv:v) {
            cout << vv << " ";
        }
        cout << endl;
    }
*/
}

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

#define PI 3.14159265359

int main() {
	double r;
	cin >> r;

	cout << fixed << setprecision(8) << r * r * PI << " ";
	cout << fixed << setprecision(8) << r * 2 * PI << endl;
}

Measured memory_bytes: 1288
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> v;
vector<int> x,d;
ll dp1[200010],dp[200010],sum = 0,mod = 998244353;
ll n,seg[400010],mx = 100000000000000;
void built(){
	for(int i = n-1;i>0;i--){
		seg[i] = max(seg[i<<1],seg[i<<1|1]);
	}
}

void update(int p,ll a){
	for(seg[p+=n] = a;p>1;p >>= 1){
		seg[p>>1] = max(seg[p],seg[p^1]);
	}
}

ll query(int l, int r){
	ll mn = 0;
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn = max(mn,seg[l++]);
		if(r&1) mn = max(mn,seg[--r]);
	}
	return mn;
}

int main(){
	ll i;
	cin >> n;
	for(i=0;i<n;i++){
		ll a,b; cin >> a >> b;
		v.push_back({a,b});
	}
	sort(v.begin(),v.end());
	for(i=0;i<n;i++){
		x.push_back(v[i].first);
		d.push_back(v[i].second);
	}
	dp[n] = 1;
	for(i=n - 1;i>=0;i--){
		auto it = lower_bound(x.begin(),x.end(),x[i] + d[i]);
		int j = it - x.begin();
		dp1[i] = query(i,j); dp1[i] = max(dp1[i],i);
		update(i,dp1[i]);
		dp[i] = (dp[i + 1] + dp[dp1[i] + 1])%mod;
	}
	cout << dp[0] << endl;
}

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

int main(){
    string s;
    cin >> s;
    for(int i=0;i<3;++i){
        if(s[i]=='1')s[i]='9';
        else s[i]='1';
    }
    cout << s <<endl;
    return 0;
}


Measured memory_bytes: 256
def move?(current_point, next_point)
  current_time, current_x, current_y = current_point
  next_time, next_x, next_y = next_point
  distance = (current_x - next_x).abs + (current_y - next_y).abs
  time = next_time - current_time

  return false if distance > time
  (distance - time).even?
end

count = gets.chomp.to_i
point_data = count.times.map { gets.chomp.split.map(&:to_i) }
current_point = [0, 0, 0]

point_data.each do |point|
  unless move?(current_point, point)
    puts 'No'
    exit true
  end
  current_point = point
end

puts 'Yes'


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

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



// Main Code
int main()
{
	ll a, b, c,x, y;
	cin>>a>>b>>c>>x>>y;
	if(2*c > (a+b))
	{
		cout<<a*x+y*b<<endl;
	}
	else
	{
		ll z =min(x, y);
		ll ans = z*c*2;
		x -= z, y -= z;
		if(x == 0)
		{
			ll l = y*c*2;
			l = min(l, y*b);
			cout<<(ans+l)<<endl;
		}
		else
		{
			ll r = x*c*2;
			r = min(r, x*a);
			cout<<(ans+r)<<endl;
		}
	}
}


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

int calc(int x, int y, int k, int b[][2000]) {
    int sum = 0;
    bool rev = y >= k;
    if (rev) y -= k;
    sum += b[x+k-1][y+k-1];
    if (x > 0) sum -= b[x-1][y+k-1];
    if (y > 0) sum -= b[x+k-1][y-1];
    if (x > 0 && y > 0) sum += 2 * b[x-1][y-1];
    sum += b[2*k-1][2*k-1] - b[2*k-1][y+k-1] - b[x+k-1][2*k-1] + b[x+k-1][y+k-1];
    if (x > 0) sum += b[x-1][2*k-1] - b[x-1][y+k-1];
    if (y > 0) sum += b[2*k-1][y-1] - b[x+k-1][y-1];
    return rev ? b[2*k-1][2*k-1] - sum : sum;
}

int main() {
    int n, k; cin >> n >> k;
    int b[2000][2000] = {}, w[2000][2000] = {};
    while (n--) {
        int x, y; char c; cin >> x >> y >> c;
        if (c == 'W') w[x%(2*k)][y%(2*k)]++;
        else b[x%(2*k)][y%(2*k)]++;
    }
    for (int x = 0; x < 2*k; x++)
        for (int y = 0; y < 2*k; y++) {
            if (x > 0) w[x][y] += w[x-1][y];
            if (y > 0) w[x][y] += w[x][y-1];
            if (x > 0 && y > 0) w[x][y] -= w[x-1][y-1];
            if (x > 0) b[x][y] += b[x-1][y];
            if (y > 0) b[x][y] += b[x][y-1];
            if (x > 0 && y > 0) b[x][y] -= b[x-1][y-1];
        }
    int ans = 0;
    for (int x = 0; x < k; x++)
        for (int y = 0; y < 2*k; y++) {
            int sum = 0;
            sum += calc(x, y, k, b);
            sum += calc(x, (y + k)%(2*k), k, w);
            ans = max(ans, sum);
        }
    cout << ans << endl;
}


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

const int MAXN=2e7+7;
long long a[MAXN];

int main()
{
	long long digit,n,KO=1;
	cin>>n;
	
	while(n>1)
	{
	
		digit=n/2;
		KO*=2;
		n=digit;
	}

	cout<<KO*2-1<< endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
        int a,b,c,n,ans,i,ii=0;
        cin >> a >> b >> c >> n;
        for(i=0;i<(n/a)+1;i++){
                for(ii=0;ii<(n/b)+1;ii++){
                        if((n-i*a-ii*b)%c==0&&(n-i*a-ii*b)>=0){
                                ans++;
                        }
                }
        }
        cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=2e5+10,P=1e9+7;
int n,X,Y;
int F[N],A[N],B[N],Fac[N],Inv[N],cnt[N];
vector<int> G[N],S[N],T;
bool cmp(int a,int b) {
  return B[a]<B[b];
}
int Find(int a) {
  return F[a]==a?a:F[a]=Find(F[a]);
}
int Pow(int a,int k) {
  int res=1;
  for(;k;k>>=1) {
    if(k&1) res=1ll*res*a%P;
    a=1ll*a*a%P;
  }
  return res;
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n,X,Y);
  for(int i=1;i<=n;++i) read(A[i],B[i]),G[A[i]].push_back(i),F[i]=i;
  for(int i=1;i<=n;++i) if(G[i].size()) {
    sort(G[i].begin(),G[i].end(),cmp);
    int j=0; while(j!=(int)G[i].size()-1&&B[G[i][0]]+B[G[i][j+1]]<=X) F[Find(G[i][++j])]=Find(G[i][0]);
    T.push_back(G[i][0]);
  }
  sort(T.begin(),T.end(),cmp);
  int p=0; while(p!=(int)T.size()-1&&B[T[0]]+B[T[p+1]]<=Y) F[Find(T[++p])]=Find(T[0]);
  for(int i=1;i<=p;++i) {
    for(auto v: G[A[T[i]]]) {
      if(B[T[0]]+B[v]<=Y) {
        F[Find(v)]=Find(T[0]);
      }
    }
  }
  if(T.size()>1) {
    for(auto v: G[A[T[0]]]) {
      if(B[T[1]]+B[v]<=Y) {
        F[Find(v)]=Find(T[1]);
      }
    }
  }
  Fac[0]=1;
  for(int i=1;i<=n;++i) Fac[i]=1ll*Fac[i-1]*i%P;
  Inv[n]=Pow(Fac[n],P-2);
  for(int i=n-1;~i;--i) Inv[i]=1ll*(i+1)*Inv[i+1]%P;
  for(int i=1;i<=n;++i) S[Find(i)].push_back(i);
  int res=1;
  for(int i=1;i<=n;++i) if(S[i].size()) {
    int t=Fac[S[i].size()];
    for(auto v: S[i]) {
      t=1ll*t*Fac[cnt[A[v]]]%P;
      ++cnt[A[v]];
      t=1ll*t*Inv[cnt[A[v]]]%P;
    }
    for(auto v: S[i]) --cnt[A[v]];
    res=1ll*res*t%P;
  }
  printf("%d\n",res);
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

	ll x = 7 % k;
	FOR(i,1,k+1) {
		if (x == 0) {
			cout << i << endl;
			return 0;
		}
		x = (10*x + 7) % k;
	}
	cout << -1 << endl;
}



Measured memory_bytes: 3588
/* ex6_2.c i18n
    dada__      */
#include<stdio.h>
#include<string.h>
#define SIZE 100

int main(void){
    int length;
    char word[SIZE];

    scanf("%s", word); //単語の入力
    length=strlen(word); //単語の長さの取得

    printf("%c%d%c", word[0], length-2, word[length-1]); //出力
    return 0;
}

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

int main(void)
{
	int i,j,k,c,min;
	int n,m;
	int x,y,t;
	char s;
	int r;
	int z[1000];
	int dpl[200][200],dps[200][200],**dp;
	
	while(1)
	{
		scanf("%d %d ",&n,&m);
		if(n==0 && m==0)break;
		
		for(i=0;i<200;i++){
			for(j=0;j<200;j++){
				if(i==j){
					dpl[i][j] = 0;
					dps[i][j] = 0;
				}else{
					dpl[i][j] = 1000001;
					dps[i][j] = 1000001;
				}
			}
		}
		
		for(i=0;i<m;i++){
			scanf("%d %d %d %c ",&x,&y,&t,&s);
			if(s=='L'){
				if(dpl[x-1][y-1]>t)dpl[x-1][y-1] = t;
				if(dpl[y-1][x-1]>t)dpl[y-1][x-1] = t;
			}else{
				if(dps[x-1][y-1]>t)dps[x-1][y-1] = t;
				if(dps[y-1][x-1]>t)dps[y-1][x-1] = t;
			}
		}
		
		c=1;
		while(c)
		{
			c=0;
			for(i=0;i<n;i++){
				for(j=i;j<n;j++){
					for(k=0;k<n;k++){
						if(dpl[i][j] > dpl[i][k] + dpl[k][j]){
							dpl[i][j] = dpl[i][k] + dpl[k][j];
							dpl[j][i] = dpl[i][j];
							c++;
						}
					}
				}
			}
		}
		
		c=1;
		while(c)
		{
			c=0;
			for(i=0;i<n;i++){
				for(j=i;j<n;j++){
					for(k=0;k<n;k++){
						if(dps[i][j] > dps[i][k] + dps[k][j]){
							dps[i][j] = dps[i][k] + dps[k][j];
							dps[j][i] = dps[i][j];
							c++;
						}
					}
				}
			}
		}
		
		scanf("%d ",&r);
		for(i=0;i<r;i++){
			scanf("%d ",&z[i]);
		}
		
		dp = (int **)malloc(sizeof(int)*r);
		for(i=0;i<r;i++){
			dp[i] = (int *)malloc(sizeof(int)*n);
		}
		
		for(i=0;i<r;i++){
			for(j=0;j<n;j++){
				dp[i][j] = -1;
			}
		}
		
		dp[0][z[0]-1] = 0;
		
		for(i=1;i<r;i++){
			for(j=0;j<n;j++){
				if(dp[i-1][j] >= 0){
					for(k=0;k<n;k++){
						if(dpl[z[i-1]-1][j] < 1000001 && dps[j][k] < 1000001 && dpl[k][z[i]-1] < 1000001){
							if(dp[i][k] < 0 || dp[i][k] > dpl[z[i-1]-1][j] + dps[j][k] + dpl[k][z[i]-1] + dp[i-1][j])
							dp[i][k] = dpl[z[i-1]-1][j] + dps[j][k] + dpl[k][z[i]-1] + dp[i-1][j];
						}
					}
					if(dpl[z[i-1]-1][z[i]-1] < 1000001 && ( dp[i][j] < 0 || dp[i][j] > dpl[z[i-1]-1][z[i]-1] + dp[i-1][j]) ){
						dp[i][j] = dpl[z[i-1]-1][z[i]-1] + dp[i-1][j];
					}
				}
			}
		}
		
		min = 1000001;
		for(i=0;i<n;i++){
			if(dp[r-1][i] >=0 && min > dp[r-1][i])min=dp[r-1][i];
		}
		
		printf("%d\n",min);
	}
	return 0;
}					
					
			
		
		

Measured memory_bytes: 4040
#include <stdio.h>
#define INF (1<<28)

int main() {
  int i, v, a, b;
  a = b = INF;
  for(i = 0; i < 3; ++i) {
    scanf("%d", &v);
    if(v < a) a = v;
  }
  for(i = 0; i < 2; ++i) {
    scanf("%d", &v);
    if(v < b) b = v;
  }
  printf("%d\n", a+b-50);
  return 0;
}

Measured memory_bytes: 1020
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
       n: chars 
    }
    let mut nn = n.clone();
    nn.reverse();
    println!("{}",
        if n == nn { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll A,B,C;
  cin>>A>>B>>C;
  if(B/A>=C) {
cout<<C<<endl;
  }
  else {
    cout<<B/A<<endl;
  }
}

Measured memory_bytes: 3564
N, M = map(int, input().split())
s = []
c = []
for i in range(M):
  si, ci = map(int, input().split())
  s.append(si)
  c.append(ci)
#print(s, c)

for i in range(M):
  if N != 1 and s[i] == 1 and c[i] == 0:
    print(-1)
    exit()
  
for i in range(M):
  for j in range(M):
    if i != j and s[i] == s[j] and c[i] != c[j]:
      print(-1)
      exit()

if N == 1:
  num = [0]
else:
  num = [1] +[0]*(N-1)
for i in range(M):
  num[s[i]-1] = c[i]
  
ans = [str(i) for i in num]
ans = "".join(ans)
print(ans)

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

struct Katana {
    int a, b;
};

int main()
{
    int n, h, min = 2000000000;
    long long *sum_table;
    Katana *katanas;
    scanf("%d%d", &n, &h);
    sum_table = new long long[n + 1];
    katanas = new Katana[n + 1];
    katanas[0].a = katanas[0].b = 2000000000;
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &katanas[i].a, &katanas[i].b);

    std::sort(katanas, katanas + n + 1,
        [](const Katana &a, const Katana &b){ return a.b > b.b; }
    );
    sum_table[0] = 0;
    for (int i = 1; i <= n; i++)
        sum_table[i] = sum_table[i - 1] + katanas[i].b;
    if (sum_table[n] >= h)
    {
        min = std::lower_bound(sum_table + 1, sum_table + n + 1, h) - sum_table;
    }
    for (int i = 1; i <= n; i++)
    {
        int count = (std::upper_bound(katanas + 1, katanas + n + 1, katanas[i].a, [](const int& i, const Katana& k){ return i >= k.b; }) - katanas) - 1;
        if (count > min) continue;
        long long rest = h - sum_table[count];
        if (rest > 0)
        {
            count += (rest + katanas[i].a - 1) / katanas[i].a;
        }
        if (count < min) min = count;
    }

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

    delete[] sum_table;
    delete[] katanas;
    return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <cstdio>
#define SIZ 10
using namespace std;

const vector<pair<
	pair<int,int>,
	vector<vector<int> >
> >pattern={
	{{13,3},{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	}},
	{{9,2},{
		{1,1,1},
		{1,1,1},
		{1,1,1},
	}},
	{{5,1},{
		{0,1,0},
		{1,1,1},
		{0,1,0},
	}},
};

int m[SIZ][SIZ];
vector<pair<pair<int,int>,int> >v;
bool dfs(int pat,int y,int x,int N,int d,int s){
	if(d==N)return s==0;
	if(s<(N-d)*5 || (N-d)*pattern[pat].first.first<s)return false;
	for(;pat<pattern.size();pat++,y=x=0)if(pattern[pat].first.first<=s){
		int nrow=pattern[pat].second.size(),ncol=pattern[pat].second[0].size();
		for(;y<=SIZ-nrow;y++,x=0){
			for(;x<=SIZ-ncol;x++){
				for(int dyx=0;dyx<nrow*ncol;dyx++)if(m[y+dyx/ncol][x+dyx%ncol]<pattern[pat].second[dyx/ncol][dyx%ncol])goto fail;
				for(int dyx=0;dyx<nrow*ncol;dyx++)m[y+dyx/ncol][x+dyx%ncol]-=pattern[pat].second[dyx/ncol][dyx%ncol];
				v[d]=make_pair(
					make_pair(x+ncol/2,y+nrow/2),
					pattern[pat].first.second
				);
				if(dfs(pat,y,x,N,d+1,s-pattern[pat].first.first))return true;
				for(int dyx=0;dyx<nrow*ncol;dyx++)m[y+dyx/ncol][x+dyx%ncol]+=pattern[pat].second[dyx/ncol][dyx%ncol];
				fail:;
			}
		}
	}
	return false;
}
int main(){
	int N,y,x,s=0;
	scanf("%d",&N);
	v.resize(N);
	for(y=0;y<SIZ;y++)for(x=0;x<SIZ;x++)scanf("%d",m[y]+x),s+=m[y][x];
	dfs(0,0,0,N,0,s);
	for(x=0;x<N;x++)printf("%d %d %d\n",v[x].first.first,v[x].first.second,v[x].second);
}

Measured memory_bytes: 1040
class Dice
  attr_accessor :a, :b, :c, :d, :e, :f

  def initialize(aaa, bbb, ccc, ddd, eee, fff)
    @a = aaa
    @b = bbb
    @c = ccc
    @d = ddd
    @e = eee
    @f = fff
  end

  def spin(char)
    aa = @a
    bb = @b
    cc = @c
    dd = @d
    ee = @e
    ff = @f

    if char == 'E'
      @a = dd
      @c = aa
      @d = ff
      @f = cc
    elsif char == 'N'
      @a = bb
      @b = ff
      @e = aa
      @f = ee
    elsif char == 'S'
      @a = ee
      @b = aa
      @e = ff
      @f = bb
    elsif char == 'W'
      @a = cc
      @c = ff
      @d = aa
      @f = dd
    end
  end
end

a, b, c, d, e, f = gets.split.map(&:to_i)
commands = gets.chomp

dice = Dice.new(a, b, c, d, e, f)

commands.size.times do |i|
  dice.spin(commands[i])
end

p dice.a



Measured memory_bytes: 6876
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(string S){
    vector<int> v(S.size()-1, 0);
    int n = 0;
    int ret = 0;
    for (int i = 0; i < S.size()-1; i++) {
        if (S[i] != S[i+1]) {
            v[i] = 1;
            n++;
        }
    }
    n = (S.size())/2;
    for (int i = 0; i < n; i++) {
        if (v[i] == 1) {
            ret = i+1;
        }
        if (v[v.size()-1-i] == 1) {
            ret = i+1;
        }
    }
    std::cout << S.size() - ret << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    string S;
    std::cin >> S;
    solve(S);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 1464
#include <stdio.h>

int main(void){
	int a,b,n,i;
	int pointOfA;
	int pointOfB;
	while(1){
		pointOfA = 0;
		pointOfB = 0;
		scanf("%d",&n);
		if(n == 0){break;}
		for(i = 0; i < n; i++){
			scanf("%d%d",&a,&b);
			if(a > b){
				pointOfA += (a + b);
			}else if(a == b){
				pointOfA += a;
				pointOfB += b;
			}else{
				pointOfB += (a + b);
			}
		}
		printf("%d %d\n",pointOfA,pointOfB);
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().split()))
ans = float('inf')
for i in range(1,n):
    a[i] += a[i-1]
for i in range(n-1):
    x = a[i]
    y = a[-1]-a[i]
    ans = min(ans,abs(x-y))
print(ans)

Measured memory_bytes: 92412
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


void solve(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    ll ans = 0, cnt = 0;
    rep(i, 0, s.size()){
        if(s[i]=='W'){
            ans += i-cnt;
            cnt ++;
        }
    }

    cout << ans << "\n";
}


int main() {
    solve();
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,i,l;
    string s;
    cin>>n>>s;
    if(n%2==1){cout<<"No";return 0;}
    l=s.length();
    for(i=0;i<l/2;i++){
        if(s[i]!=s[i+l/2]){cout<<"No";return 0;}
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
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();
		sc.close();
		
		int ans = a+b;
		
		if(ans < 10 ){
			System.out.println(ans);
		}else{
			System.out.println("error");
		}

	}

}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
	int i,j,h,w;
	while(1){
		scanf("%d%d",&h,&w);
		if(h==0&&w==0)break;
		for(j=0;j<h;j++){
			if(j%2==0){
				/* pattern a */
				for(i=0;i<w;i++){
					if(i%2==0){
						printf("#");
					}else{
						printf(".");
					}
				}
				printf("\n");
			}else{
				/* pattern b */
				for(i=0;i<w;i++){
					if(i%2==0){
						printf(".");
					}else{
						printf("#");
					}
				}
				printf("\n");
			}	
		}
		printf("\n");
	}
	return 0;
}

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007
#define println(x) cout << "[" << #x << ":" << x << "]\n"; 
#define print(x) cout << "[" << #x << ":" << x << "] "; 

const ll mxN = 1e18;

ll k;

int main(){
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cin >> k;
    bool flag = false;
    int p = 0, ans;
    for(int i=1; i<=1e6; i++){
	p = (p*10 + 7)%k;
	if(p == 0){
	    ans = i;
	    flag = true;
	    break;
	}
    }
    cout << (flag ? ans : -1) << "\n";
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    int res = 0;
    while (n) {
	res += (n%10 == 2);
	n/=10;
    }
    out(res);
    
    
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, A;
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G;
    vector<int> P(M);
    G.assign(M, vector<int>());
    rep(i, M) {
        int k;
        cin >> k;
        rep(j, k) {
            int g;
            cin >> g;
            g--;
            G[i].push_back(g);
        }
    }

    rep(i, M) { cin >> P[i]; }

    int res = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        vector<bool> nums(N);
        for (int i = 0; i < N; i++) {
            if (bit & (1 << i)) {
                nums[i] = true;
            }
        }

        bool judge = true;
        rep(j, M) {
            int cnt = 0;
            for (auto g : G[j]) {
                if (nums[g]) {
                    cnt++;
                }
            }
            if (cnt % 2 != P[j]) {
                judge = false;
                break;
            }
        }

        if (judge)
            res++;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve(N, C, AB):
    def edges_to_array(A, B, N, M):
        head = [-1] * (N + 1)
        nxt = [0] * (M + M)
        to = [0] * (M + M)
        for i in range(M):
            a = A[i]
            b = B[i]
            nxt[i << 1] = head[a]
            to[i << 1] = b
            head[a] = i << 1
            nxt[i << 1 | 1] = head[b]
            to[i << 1 | 1] = a
            head[b] = i << 1 | 1
        return head, nxt, to

    def EulerTour(head, nxt, to, root=1):
        N = len(head) - 1
        parent = [0] * (N + 1)
        ind_L = [0] * (N + 1)
        ind_R = [0] * (N + 1)
        i = -1
        tour = []
        stack = [-root, root]
        stack[0] = -root
        stack[1] = root
        while stack:
            v = stack.pop()
            tour.append(v)
            i += 1
            if v > 0:
                ind_L[v] = i
                p = parent[v]
                k = head[v]
                while k != -1:
                    w = to[k]
                    if w == p:
                        k = nxt[k]
                        continue
                    parent[w] = v
                    stack.append(-w)
                    stack.append(w)
                    k = nxt[k]
            else:
                ind_R[-v] = i
        return tour, ind_L, ind_R, parent
    head, nxt, to = edges_to_array(AB[::2], AB[1::2], N, N - 1)
    tour, ind_L, ind_R, parent = EulerTour(head, nxt, to)
    removed = [0] * (N + 1)
    answer = [N * (N + 1) // 2] * (N + 1)
    memo = [0] * (N + 1)
    for v in tour:
        if v > 0:
            memo[v] = removed[C[parent[v]]]
        else:
            v = -v
            removed[C[v]] += 1
            p = parent[v]
            x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
            x -= removed[C[p]] - memo[v]
            answer[C[p]] -= x * (x + 1) // 2
            removed[C[p]] += x
    for i, x in enumerate(removed):
        x = N - x
        answer[i] -= x * (x + 1) // 2
    return answer


N = int(readline())
C = (0,) + tuple(map(int, readline().split()))
AB = tuple(map(int, read().split()))
answer = solve(N, C, AB)
print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 178608
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>

using namespace std;

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

	int result = numeric_limits<int>::max();
	for(int i = 0; i < S.length() - 2; i++) {
		const auto s = S.substr(i, 3);
		const auto n = stoi(s, nullptr, 10);
		const auto d = abs(753 - n);
		result = min(result, d);
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
int MAX_N = 100100;
int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> coin(1, 1);
    vector<int> dp(MAX_N, INF); dp[0] = 0;
    for (int i = 6; i <= MAX_N; i *= 6) coin.push_back(i);
    for (int i = 9; i <= MAX_N; i *= 9) coin.push_back(i);
    sort(coin.begin(), coin.end());
    
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < coin.size(); j++) {
            if (i + coin[j] >= MAX_N) continue;
            if (dp[i+coin[j]] > dp[i] + 1) {
                dp[i+coin[j]] = dp[i] + 1;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main{

    int n;
    int[] p;
    int MAX = 10001;

    void solve(){
        Scanner sc = new Scanner(System.in);

        p = new int[MAX];
        for(int i=2; i<p.length; i++) p[i] = 1;
        for(int i=2; i<Math.sqrt(MAX)+1; i++){
            for(int j=i*2; j<MAX; j+=i){
                p[j] = 0;
            }
        }

        while(true){
            n = sc.nextInt();
            if(n==0) break;

            int cnt = 0;
            for(int i=0; i<=n; i++){
                if(p[i]==0) continue;
                int sum = 0;
                for(int j=i; j<=n; j++){
                    if(p[j]==0) continue;
                    sum += j;
                    if(sum==n){
                        cnt++;
                        break;
                    }
                    if(sum>n) break;
                }
            }

            System.out.println(cnt);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end());

const int MOD = 1000000007;
const int INF = INT_MAX;



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

    cout << n/3 << endl;


    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 760