akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n)]
INF = float('inf')
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)

res = []
shortest = n + 1
for s in range(n):
    dist = [-1] * n
    prev = [-1] * n
    q = deque()
    q.append(s)
    dist[s] = 0
    while len(q) != 0:
        v = q.popleft()
        for nv in g[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                prev[nv] = v
                q.append(nv)
    for t in range(n):
        if t == s:
            continue
        if dist[t] == -1:
            continue
        for nt in g[t]:
            if nt == s:
                temp = [s]
                cur = t
                while cur != s:
                    temp.append(cur)
                    cur = prev[cur]
                if shortest > len(temp):
                    shortest = len(temp)
                    res = temp
if shortest == n + 1:
    print(-1)
    exit()
print(len(res))
for v in res:
    print(v + 1)

# def bfs(sv):
#     dist = [INF] * n
#     pre = [-1] * n
#     q = deque()
#     q.append(sv)
#     dist[sv] = 0
#     while q:
#         v = q.popleft()
#         for nv in g[v]:
#             if dist[nv] == INF:
#                 continue
#             pre[nv] = v
#             dist[nv] = dist[v] + 1
#             q.append(nv)
#     print(dist)
#     best = (INF, -1)
#     for v in range(n):
#         if v == sv:
#             continue
#         for nv in g[v]:
#             if nv == sv:
#                 best = min(best, (dist[nv], nv))
#                 print(sv, best)
#                 # print(best)
#     if best[0] == INF:
#         return [0] * (n + 1)
#     print(pre)
#     v = best[1]
#     print('v', v)
#     res = []
#     while v != -1:
#         res.append(v)
#         v = pre[v]
#     print('res', res)
#     return res


# ans = [0] * (n + 1)
# for s in range(n):
#     now = bfs(s)
#     if len(now) < len(ans):
#         print('aa')
#         ans = now
#         print(ans)
# if len(ans) == n + 1:
#     print(-1)
#     exit()
# print(len(ans))
# for v in ans:
#     print(v)


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

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

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = map(int, raw_input().split())
h = sorted([input() for i in range(N)])

print min(h[i + K - 1] - h[i] for i in range(N - K + 1))

Measured memory_bytes: 9576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int K = Integer.parseInt(scanner.nextLine());
        String S = scanner.nextLine();
        if (K >= S.length()) {
            System.out.println(S);
        } else {
            String s = S.substring(0,K);
            System.out.println(s + "...");
        }
    }
}


Measured memory_bytes: 26988
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut a : Vec<i32> = input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect();
    a.sort();

    println!("{}", a[0] + a[1]);
}



Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int x,n;
	cin >> x >> n;
	vector<int> p(n);
	vector<bool> ex(102,false);
	for(int i=0;i<n;i++)
	{
		cin >> p[i];
		ex[p[i]]=true;
	}
	
	int ans;
	int mn=100000;
	for(int i=0;i<=101;i++)
	{
		if(!ex[i])
		{
			if(abs(x-i)<mn)
			{
				ans=i;
				mn=abs(x-i);
			}
		}
	}
	cout << ans << endl;







}

Measured memory_bytes: 3192
void main()
{
    long n, m;
    rdVals(n, m);
    long[] h = rdRow;

    long[][] edge = new long[][](n);
    foreach (i; 0 .. m)
    {
        long a, b;
        rdVals(a, b);
        --a, --b;
        edge[a] ~= b, edge[b] ~= a;
    }

    long result;
    foreach (i; 0 .. n)
    {
        bool ok = true;
        foreach (e; edge[i])
        {
            if (h[i] <= h[e]) ok = false;
        }
        if (ok) ++result;
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

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.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
  int N;
  cin >> N;
  
  vector<int> as(N);
  rep(i, N) cin >> as.at(i);
  
  sort(as.begin(), as.end());
  reverse(as.begin(), as.end());
  
  int alice = 0, bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      alice += as.at(i);
    }
    else {
      bob += as.at(i);
    }
  }
  
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;


int main(){
    ll n;
    vector<ll> vec;
    cin >> n;
    for (int i = 0; i < 5; i++) {
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(), vec.end());
    ll tmp = vec[0];
    ll ans = 5 + (n-1)/tmp;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int s = Integer.parseInt(sc.next());

		// 皿何枚まで考慮すればいいか？
		int maxDish = s / 3;

		// 皿の数を増やしながら答えを求めて足していく
		long result = 0;
		for (int dish = 1; dish <= maxDish; dish++) {
			result += calc(s - (dish * 3), dish);
			result = result % 1000000007;
		}

		System.out.println(result);
	}

	// みかんを何人かで分けるとき、何通りか求める関数
	// 例 calc(7, 3)→7個のみかんを3人で分ける→36通り
	static long calc(long mikan, long hito) {
		BigInteger a = BigInteger.valueOf(1);
		BigInteger b = BigInteger.valueOf(1);
		for (long i = 1; i < hito; i++) {
			a = a.multiply(BigInteger.valueOf(mikan + hito - i));
			b = b.multiply(BigInteger.valueOf(i));
		}
		BigInteger r = a.divide(b);
		r = r.remainder(BigInteger.valueOf(1000000007));
		return r.longValue();
	}
}

Measured memory_bytes: 55604
#include<iostream>
#include<vector>

using namespace std;
 
int main(){
    int n,k,q; 
    cin>>n>>k>>q;
    vector<int> a(q);
    for(int i=0;i<q;i++){
        cin>>a[i];
        a[i]--;
    } 
    vector<int> p(n,k-q);
    for(int i=0;i<q;i++){
        p[a[i]]++;
    }
    for(int i=0;i<n;i++){
        if(p[i]<=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
 
}

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

int n;
int MAXIMUM=100005;
long INF = 1e15;
// W:未訪問
// G:訪問する候補
// B:訪問済み
int W=0,G=1,B=2;
vector<pair<int,int>> adj[100005];
long d[100005];
void dijkstra(int K){
  priority_queue<pair<int,int>> PQ;
  int u,minv;
  int color[MAXIMUM];
  // d[n]:Tに属する頂点と V - T に属する頂点をつなぐ辺の中で重みが最小の辺の重みを記録

  //初期化
  for(int i=0;i<n;i++){
    d[i]=INF;
    color[i]=W;
  }

  d[K]=0;
  PQ.push(make_pair(0,K));
  color[K] = G;

  while (!PQ.empty()) {
    pair<int,int> f = PQ.top();
    PQ.pop();
    u = f.second;
    // 頂点を訪問済に
    color[u] = B;
    //最小値を取り出し、それが最短でなければ無視
    if( d[u]<f.first*(-1)) continue;

    //訪問済みでないかつ辺がつながっている頂点の中でコストが最小の辺を選択
    for(int j=0;j<adj[u].size();j++){
      int v = adj[u][j].first;
      if(color[v]== B) continue;
      if(d[v]>d[u]+adj[u][j].second){
        d[v]=d[u]+adj[u][j].second;
        PQ.push(make_pair(d[v]*(-1),v));
        color[v]=G;
      }
    }
  }


}

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

  int Q,K;
  cin>>Q>>K;
  dijkstra(K-1);
  for(int i=0;i<Q;i++){
      int x,y;
      cin>>x>>y;
      cout<<d[x-1]+d[y-1]<<endl;
  }

}


Measured memory_bytes: 12132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			int[] A = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int[] b = new int[N];

			long s = 0;
			long[] sum = new long[2];
			for (int i = 0; i < N; i++) {
				s += A[i];
				sum[i % 2] += A[i];
			}

			b[0] = (int)(s - 2 * sum[1 % 2]);
			for (int i = 1; i < N; i++) {
				b[i] = 2 * A[i - 1] - b[i - 1];
			}

			for (int i = 0; i < N; i++) {
				Console.Write(b[i] + " ");
			}
			Console.WriteLine();
		}
	}
}


Measured memory_bytes: 29784
#include <stdio.h>

int main(void){
	int moneyset[3] = {100,500,1000};
	int num[3];
	int a,b,r,i,n;
	while(1){
		scanf("%d%d",&a,&b);
		if(a == 0 && b == 0){break;}
		r = b - a;
		for(i = 2; i >= 0; i--){
			num[i] =  r / moneyset[i];
			r %= moneyset[i];
		}
		for(i = 0; i < 3; i++){
			printf("%d%c",num[i], i != 2 ? ' ' : '\n');
		}

	}

	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <random>
using namespace std;

int main() {
	int n;
	int *t;
	cin >> n;
	t = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> t[i];
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		int p, x, tmp=0,sum=0;
		cin >> p >> x;
		p--;
		tmp = t[p];
		t[p] = x;
		for (int s = 0; s < n; s++)
		{
			sum += t[s];
		}
		cout << sum << endl;
		t[p] = tmp;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

a,b,c,d = map(int, input().split())

ba = (d>=abs(b-a))
#print(ba)

bc = (d>=abs(c-b))
#print(bc)

ac = (d>=abs(c-a))
#print(ac)

if ac:
    print("Yes")
else:
    if( ba and bc ):
        print("Yes")
    else:
        print("No")


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

 int H, N;
 cin >> H >> N;

 vector<int> A(N);
 vector<int> B(N);
 for (int i = 0; i < N; i++) {
   cin >> A[i] >> B[i];
 }

 // i 番目までの魔法からダメージの総和が j になるように選んだときの魔法消費量の総和の最小値
 vector<vector<int>> dp(N + 1, vector<int>(H + 1, 100000000));

 dp[0][0] = 0;

 for (int i = 0; i < N; i++) {
   for (int j = 0; j <= H; j++) {
     if (j <= A[i]) {
       dp[i+1][j] = min(dp[i][j], B[i]);
     } else {
       dp[i+1][j] = min(dp[i][j], dp[i+1][j - A[i]] + B[i]);
     }
   }
 }

 cout << dp[N][H] << endl;

}


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

bool isSquareNumber (int num);

int main () {

    int N, D;
    cin >> N >> D;

    int X[N][D];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {

            int dist = 0;
            for (int k = 0; k < D; k++) {
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }

            if (isSquareNumber(dist)) ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

bool isSquareNumber (int num) {

    for (int i = 1; i * i <= num; i++) {
        if (i * i == num) {
            return true;
        }
    }

    return false;
}

Measured memory_bytes: 256
using System;

namespace ABC100A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int[] ints = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int a = ints[0];
            int b = ints[1];

            if (Math.Max(a, b) <= 8)
            {
                Console.WriteLine("Yay!");
                return;
            }
            Console.WriteLine(":(");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define Arman_Sykot ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 
using namespace std;

int main()
{
/*********************/
// Author:
        Arman_Sykot;
/*********************/
    
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes" << "\n";
		
	else
		cout << "No" << "\n";
    
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <iomanip>

using namespace std;

using ll = long long;

ll pascal[51][51];

void make_table()
{
    for (int n = 0; n < 51;n++)
    {
        for (int r = 0; r <= n;r++)
        {
            if(r == n || r == 0)
            {
                pascal[n][r] = 1LL;
            }
            else
            {
                pascal[n][r] = pascal[n - 1][r - 1] + pascal[n - 1][r];
            }
        }
    }
}

int main()
{
    int N, A, B;
    vector<ll> v;

    cin >> N >> A >> B;

    v.resize(N);

    make_table();

    for (int i = 0; i < N;i++)
    {
        cin >> v[i];
    }

    sort(v.begin(), v.end(), greater<ll>());

    ll sum = accumulate(v.begin(), v.begin() + A, 0LL);

    double ans = sum / (double)A;

    ll num;
    if (v[0] != v[A - 1])
    {    
        int cntn = count(v.begin(), v.end(), v[A - 1]);
        int cntr = count(v.begin(), v.begin() + A, v[A - 1]);
        num = pascal[cntn][cntr];
    }
    else
    {
        num = 0;
        int cntn = count(v.begin(), v.end(), v[A - 1]);

        for (int i = A; i <= B; i++)
        {
            int cntr = i;
            num += pascal[cntn][cntr];
        }
    }

    cout << fixed;
    cout << setprecision(6) << ans << endl << num << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    cout<<(((n*m)%2==0)?"Even":"Odd")<<endl;
    
    return 0;
}



Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n,r;
	while (cin >> n>>r) {
		if (!n)break;
		int a[50];
		int b[50];
		for (int i = 0; i < n; ++i)a[i] = n - i;
		for (int i = 0; i < r; ++i) {
			int s, e, j = 0;
			cin >> s>> e;
			for (; j < e; j++) b[j] = a[s + j - 1];
			for (; j < s + e - 1; j++)b[j] = a[j - e];
			for (; j < n; ++j)b[j] = a[j];
			for (j = 0; j < n; ++j)a[j] = b[j];
		}
		cout << a[0] << endl;
		
	}
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const   int NUM = 7;

int main()
{
 int inputNum;
 cin >> inputNum;
 
 //拆数 
 int g, s,b;
 b = inputNum/100;
 s = (inputNum - b*100)/10;
 g = inputNum - b*100- s*10; 
 //cout << "b = "<< b <<"s= "<< s << "g=" << g<< endl;
 
 if(g== NUM || s == NUM || b ==NUM)
  cout << "Yes" ;
 else 
  cout << "No" ;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  ll x;
  ll a[100];
  cin >> n >> x;
  REP(i, n)
  {
    cin >> a[i];
  }

  sort(a, a + n);
  ll cum[100];
  cum[0] = a[0];

  FOR(i, 1, n)
  {
    cum[i] = cum[i - 1] + a[i];
  }

  REP(i, n)
  {
    if (x < cum[i])
    {
      cout << i << endl;
      return 0;
    }
    else if (x == cum[i])
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n - 1 << endl;
}


Measured memory_bytes: 256
from sys import exit

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

for i in range(n-2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print('Yes')
        exit()
    
print('No')

Measured memory_bytes: 62364
/*AOJ-ITP-4-4*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(br.readLine());
        String numsArray[] = br.readLine().split(" ");
        long sum = 0;
        int max=-1000000;
        int min=1000000;
        int tmp=0;
        for(int i=0; i<num; i++){
            tmp = Integer.parseInt(numsArray[i]);
            if(tmp>max){
                max = tmp;
            }
            if(tmp<min){
                min = tmp;
            }
            sum = sum+tmp;
        }
        System.out.println(min+" "+max+" "+sum);
    }
}

Measured memory_bytes: 28436
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl A(N+1); rep(i, N+1) cin >> A[i];
    vl B(N); rep(i, N) cin >> B[i];
    
    ll ans = 0;
    for (ll i = N-1; i >= 0; i--) {
        ll rem = min(B[i], A[i+1]);
        ans += rem;
        B[i] = max(B[i]-rem, 0ll);
        rem = min(A[i], B[i]);
        ans += rem;
        A[i] = max(A[i]-rem, 0ll);
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 1792
N, K = map(int, input().split())

ans = 0
for i in range(1, N + 1):
    if i >= K:
        ans += 1
    else:
        p = 1
        while i < K:
            i *= 2
            p *= 1 / 2
        ans += p
ans /= N
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m, t;
	cin >> n >> m >> t;

	int ans = 0;

	set<pii> S;
	vector<int> c(m + 5);
	vector<vector<pii>> g(n + 5);

	for(int i = 0; i < t; i++){
		int x, y;
		cin >> x >> y;
		g[x].push_back({x, y});
		c[y]++;
	}

	for(int i = 1; i <= m; i++)
		S.insert({c[i], i});

	for(int i = 1; i <= n; i++){
		int cur = g[i].size();
		for(auto &el : g[i]){
			int y = el.second;
			S.erase(pii(c[y], y));
			c[y]--;
			S.insert(pii(c[y], y));
		}

		int add = 0;
		if(!S.empty()){
			auto mx = *(S.rbegin());
			add += mx.first;
		}

		ans = max(ans, cur + add);
		for(auto &el : g[i]){
			int y = el.second;
			S.erase(pii(c[y], y));
			c[y]++;
			S.insert(pii(c[y], y));
		}

	}

 	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 34872
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 


signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
        
	
	string s;
	int n;
	cin >> n;
	cin >> s;
	int k = s.size();
	n%=26;
	for(int i=0;i<k;i++){
		int c = s[i]-'A';
		c = (c+n)%26;
		s[i] = ( 'A' + c );
	}
	cout << s << endl;
	
    

return 0;
}
///....


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


string s, t;
int dp[3001][3001];


int main(){
    cin >> s;
    cin >> t;
    for(int i = 1; i <= s.length(); i++){
        for(int j = 1; j <= t.length(); j++){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    string ret = "";
    int i = s.length(), j = t.length();
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i - 1][j]){
            i--;
        }else if(dp[i][j] == dp[i][j - 1]){
            j--;
        }else{
            ret = s[i - 1] + ret;
            i--; j--;
        }
    }
    cout << ret << endl;
}


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



int main()
{
  int a,b;
  cin >> a >> b;
  int M = max(a,b);
  int m = min(a,b);
  for (int i = 0; i < M; i++)
  {
    cout << m;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using ll =long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    vector<int>l(n);
    rep(i,n)cin>>l[i];

    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int ans=0;

    rep(i,k){
        ans+=l[i];
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N,M,C;
  cin>>N>>M>>C;
  vector<int> B(M);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i,M) cin>>B[i];
  rep(i,N){
    rep(j,M){
      cin>>A[i][j];
    }
  }
  int ans=0;
  
  rep(i,N){
    int sum=C;
    rep(j,M) sum += A[i][j]*B[j];
    if (sum>0) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 10000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n;
	cin >> n;
	int c[502], s[502], f[502];
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	rep(i, n - 1) {
		int now = 0;
		for (int j = i; j < n - 1; j++) {
			if (now % f[j] == 0) {
				now = max(now, s[j]) + c[j];
			}
			else {
				now = max(s[j], (now / f[j] + 1) * f[j]) + c[j];
			}
		}
		cout << now << endl;
	}
	cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

// Point ...
type Point struct {
	x int
	y int
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W, A := nextInt(), nextInt(), []string{}
	for i := 0; i < H; i++ {
		A = append(A, nextLine())
	}

	fmt.Printf("%d\n", AGC033A(H, W, A))
}

// AGC033A ...
func AGC033A(H, W int, A []string) (res int) {
	queue := []Point{}
	board, dist, visited := make([][]byte, H), make([][]int, H), make([][]bool, H)
	for i := 0; i < H; i++ {
		board[i], dist[i], visited[i] = make([]byte, W), make([]int, W), make([]bool, W)
		for j, char := range A[i] {
			board[i][j] = byte(char)
			dist[i][j] = 1000000
			if char == '#' {
				dist[i][j] = 0
				queue = append(queue, Point{j, i})
			}
		}
	}

	moves := []Point{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}
	for len(queue) != 0 {
		current := queue[0]
		queue = queue[1:]

		if visited[current.y][current.x] {
			continue
		}
		visited[current.y][current.x] = true

		for _, mv := range moves {
			next := Point{current.x + mv.x, current.y + mv.y}
			if next.x < 0 || next.y < 0 || W <= next.x || H <= next.y {
				continue
			}

			ct := dist[current.y][current.x] + 1
			if ct < dist[next.y][next.x] {
				dist[next.y][next.x] = ct
				queue = append(queue, next)
				if res < ct {
					res = ct
				}
			}
		}
	}

	return
}


Measured memory_bytes: 49864
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

typedef long long LL;
const int mod = 1000000007;

map<LL, LL>m1;

LL f(LL n);

int main(){
  LL n;
  m1[1] = 2, m1[2] = 4, m1[3] = 5;
  scanf("%lld", &n);
  printf("%lld\n", f(n));
  return 0;
}
LL f(LL n){
  if(m1[n] != 0) return m1[n];
  LL n1 = n>>1;
  LL n2 = (n-(LL)1)>>1;
  LL n3 = (n-(LL)2)>>1;
  return m1[n] = (f(n1)%mod + f(n2)%mod + f(n3)%mod)%mod;
}


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

// why am I so weak

int n;
int a[100055];
int cnt[100055];

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

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

	int res = 0;
	
	vector<int> vec;

	for (int i = 0; i <= (int)1e5; i++) {
		if (cnt[i] > 1) {
			vec.push_back(i);
		}
	}

	for (int i = 0; i < (int)vec.size(); i++) {
		int cur = vec[i];

		if (cnt[cur] < 2) continue;

		int j = i + 1;

		while (j < (int)vec.size() && cnt[cur] > 1) {
			if (cnt[vec[j]] < 2) {
				j++;
				continue;
			}

			cnt[vec[j]]--;
			cnt[cur]--;
		}

		while (cnt[cur] > 1) {
			if (cnt[cur] == 2) {
				res--;
				cnt[cur] = 1;
				break;
			}
			cnt[cur] -= 2;
		}

		i = j - 1;
	}

	for (int i = 0; i <= (int)1e5; i++) res += cnt[i];

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

	return 0;
}


Measured memory_bytes: 1152
N,*ps=$<.read.split.map(&:to_i)

h = {}
ps.each do |n|
    if h[n]
        h[n+1] = h[n]+1
        h.delete(n)
    else
        h[n+1] = 1
    end
end
ret = N - h.max_by{|k,v|v}[1]
p ret

Measured memory_bytes: 33788
#include <iostream>
#include <cstdio>

const int MAXN = 3000;
const int MOD = 1e9 + 7;

int n, m, ans;
int dp[MAXN | 1][MAXN | 1][2];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i <= n; ++i) dp[0][i][i == 0] = 1;
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int k = 0; k <= 1; ++k) {
				/*
				dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
				dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
				dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MOD;
				dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
				*/
				/*
				if (j < n) dp[i + 1][j + 1][k | (j == 0)] = (dp[i + 1][j + 1][k | (j == 0)] + dp[i][j][k]) % MOD;
				dp[i + 1][j][k | (j == 0)] = (dp[i + 1][j][k | (j == 0)] + dp[i][j][k] * 2) % MOD;
				if (j) dp[i + 1][j - 1][k | (j == 1)] = (dp[i + 1][j - 1][k | (j == 1)] + dp[i][j][k]) % MOD;
				*/
				// if (k == 0 && j == 0) continue;
				if (j > 0) {
					int kk = k | (j == 1);

					dp[i + 1][j - 1][kk] = (dp[i + 1][j - 1][kk] + dp[i][j][k]) % MOD;
					dp[i + 1][j][k | (j == 1)] = (dp[i + 1][j][k | (j == 1)] + dp[i][j][k]) % MOD;
				}
				if (j < n) {
					dp[i + 1][j + 1][k] = (dp[i + 1][j + 1][k] + dp[i][j][k]) % MOD;
					dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % MOD;
				}
			}
		}
	}
	for (int i = 0; i <= n; ++i) ans = (ans + dp[m][i][1]) % MOD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 70656
n, x, y = map(int, input().split())

ret = [0] * n

for i in range(n):
    for j in range(i+1, n):
        norm = min(j-i, abs(j-(x-1)) + abs(i-(y-1)) + 1,
                   abs(j-(y-1)) + abs(i-(x-1)) + 1)
        ret[norm] = ret[norm] + 1

for i in range(n-1):
    print(ret[i+1])


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


int main(){
 long long n,b,x,m,c=0,k;
 cin >>n>>k;
 int a[n];
 for(int i=0;i<n;i++)cin >>a[i];

 sort(a,a+n);
 for(int i=0;i<k;i++){
    c+=a[i];
 }
 cout << c << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;

int main() 
{

 fast();
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  ll n,k;
  cin >> n >> k;
  str s;
  cin >> s;
  ll c = 0;
  f(i,0,n-1){
    if(s[i]==s[i+1])
      c++;
  }
  cout<<min(c+2*k,n-1);
 
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	char a,b; cin >> a >> b;
	if (a=='H'){
		if (b=='H'){
			print('H');
		}else {
			print('D');
		}
	}else {
		if (b=='H'){
			print('D');
		}else {
			print('H');
		}
	}
}

Measured memory_bytes: 256
import math
#from functools import reduce
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
k = int(input())
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum += math.gcd(math.gcd(i,j),l)
print(sum)


Measured memory_bytes: 67860
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a <= 5)	puts("0");
	else if(a <= 12)	printf("%d\n",b / 2);
	else printf("%d\n", b);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
	char a;
	int ans = 0,MAX = -1;
	for(int i=1;i<=3;i++){
		cin>>a;
		if(a == 'R'){
			ans++;
		}
		else
			ans = 0;
		MAX = max(ans,MAX);
	}
	cout<<MAX;
	return 0;
}

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

void solve(long long X, long long A)
{
    if (X < A)
        cout << "0" << endl;
    else
        cout << "10" << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long X;
    scanf("%lld", &X);
    long long A;
    scanf("%lld", &A);
    solve(X, A);
    return 0;
}


Measured memory_bytes: 256
import itertools
L,R = map(int,input().split())
if R-L >= 2018:
    ans = 0
else:
    ij = [i%2019 for i in range(L, min(L+2019, R+1))]
    ans = 2018
    for v in itertools.combinations(ij, 2):
        ans = min(ans, (v[0]*v[1])%2019)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int n,y;
    cin>>n>>y;
    for(int a=0;a<=n;a++)
    {
        for(int b=0;b<=n-a;b++)
        {
            int c=n-a-b;
            if(a*10000+b*5000+c*1000==y)
            {
                cout<<a<<" "<<b<<" "<<c<<" ";
                return 0;
            }
        }
    }
    cout<<"-1"<<" "<<"-1"<<" "<<"-1";
}


Measured memory_bytes: 3548
# C - Traveling Salesman around Lake

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

total = 0
mx = 0

for i in range(N):
    if i == N - 1:
        dist = K - A[i] + A[0]
    else:
        dist = A[i + 1] - A[i]
    if mx < dist:
        mx = dist
    total += dist

print(total - mx)


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

int main() {
  long long A,B,C;
  cin >> A >> B >> C;
  long long K;
  cin >> K;
  if ( K<=A+B && K>=A && A!=0 ){
    cout << A;
  }
  if ( K<=A+B && K<A && A!=0 ){
    cout << K;
  }
  if ( K<=A+B && A==0 ){
    cout << 0;
  }
  if ( K>A+B ){
    cout << A-(K-A-B);
  }
    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll linf = 9e18;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    map<int, int> factor;
    int x = m;
    for (int i = 2; i * i <= x; i++) {
        while (m % i == 0) {
            factor[i]++;
            m /= i;
        }
    }
    if (m != 1) factor[m]++;


    COMinit();
    ll ans = 1;
    for (auto i : factor) {
        ll k = i.second;
        ans *= COM(n - 1 + k, k);
        ans %= MOD;
    }

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


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    printf("%d\n", 800 * N - ((N / 15) * 200));
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

string S;
bool flag = false;
ll cnt[212345];
ll ans = 0;
int N;

int main(){
	
	cin>>S;
	
	fill( cnt, cnt+212345, 0 );
	
	N = S.size();
	REP( i, N ) if( S[i] == 'W' ) cnt[i] = 1;
	N--;
	while( N-- ){
		cnt[N] += cnt[N+1];
	}
	REP( i, S.size() ) if( S[i] == 'B' ) ans += cnt[i];
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int k;
  cin>>k;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int dp[n]={0};
  for(int i=1;i<n;i++)
  {
    vector<int> v1;
    for(int j=i-1;j>=max(i-k,0);j--)
    {
      v1.push_back((abs(arr[i]-arr[j])+dp[j]));

    }
    sort(v1.begin(),v1.end());
    dp[i]=v1[0];
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,ans=0;
    cin >> n >> k;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    for(int i=0;i<k;i++){
        ans += p[i];
    }
    cout << ans << endl;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<0<<endl;
		return 0;
	}
	if((a+b)%2==0){
		cout<<(a+b)/2<<endl;
		return 0;
	}
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int N, val;
int all_xor = 0, i_ip1_xor;
vector<int> A;

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){ cin >> val; A.pb(val); }
    for(int i = 0; i < N; i+=2){
        i_ip1_xor = A[i] ^ A[i+1];
        all_xor = all_xor ^ i_ip1_xor;
    }

    for(int i = 0; i < N; i++) cout << (all_xor ^ A[i]) << " ";
    return 0;
    
}

Measured memory_bytes: 4168
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int dp[3003][3002][2];
int n , m;

int alpha(int i , int j , int ok)
{
	if(i > j)return 0;
	int &abs = dp[i][j][ok];
	if(abs != -1)return abs;
	int ans = 0;
	if(!ok)
	{
		int a1 = A[i] + alpha(i+1 ,  j , 1-ok);
		int a2 = A[j] + alpha(i , j-1 , 1-ok);
		ans = max(a1 , a2);
	}
	else 
	{
		int a1 = alpha(i+1 ,  j , 1-ok) - A[i];
		int a2 = alpha(i , j-1 , 1-ok) - A[j];
		ans = min(a1 , a2);
	}
	return abs = ans;
}

void solve()
{
	cin >> n;

	loop(i,0,n)cin >> A[i];

	mset(dp , -1);

	int ans = alpha(0 , n-1 , 0);

	cout << ans;
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 144624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	string S;
	cin >> S;
	int SS = S.size();

	int X, Y;
	cin >> X >> Y;

	int yomu = 0;
	while (S[yomu] == 'F') {
		X--;
		yomu++;
	}

	map<int, int> yoko;
	map<int, int> tate;

	int muki = 0;

	while (yomu < SS) {
		if (S[yomu] == 'T') {
			muki++;
			yomu++;
		}
		else {
			int nagasa = 0;
			while (yomu < SS && S[yomu] == 'F') {
				nagasa++;
				yomu++;
			}
			if (muki % 2) tate[nagasa]++;
			else yoko[nagasa]++;
		}
	}

	vector<int> kouho;
	kouho.push_back(0);

	for (auto itr : yoko) {

		map<int, int> kouho2;
		for (int i : kouho) {
			rep(ii, itr.second + 1) {
				kouho2[i + (2 * ii - itr.second) * itr.first] = 1;
			}
		}

		kouho.clear();
		for (auto itr2 : kouho2) {
			kouho.push_back(itr2.first);
		}
	}
	int XOK = 0;
	for (int i : kouho) {
		if (i == X) XOK = 1;
	}

	kouho.clear();
	kouho.push_back(0);

	for (auto itr : tate) {

		map<int, int> kouho2;
		for (int i : kouho) {
			rep(ii, itr.second + 1) {
				kouho2[i + (2 * ii - itr.second) * itr.first] = 1;
			}
		}

		kouho.clear();
		for (auto itr2 : kouho2) {
			kouho.push_back(itr2.first);
		}
	}
	int YOK = 0;
	for (int i : kouho) {
		if (i == Y) YOK = 1;
	}

	if (XOK && YOK) co("Yes");
	else co("No");
	
	Would you please return 0;
}

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

using namespace std;

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

#define int ll


main(){
	string s,t;
	cin >> s >> t;
	
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5 + 10;
int A[MAX];
int main ()
{
    int N;cin >> N;
    for(int i=1;i<=N;i++)cin >> A[i];
    int res=0,ans=0;
    for(int i=2;i<=N;i++){
        if(A[i]<=A[i-1]){
            res++;
        }
        else{
            ans = max(ans,res);
            res = 0;
        }
    }
    ans = max(ans,res);
    cout<<ans;
    return 0;
}
/*
*/






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



int main(){
	int n,m,q;
	cin >> n >> m >> q;
	vector<vector<int>> qs(q,vector<int>(4));
	rep(i,q)rep(j,4)scanf("%d",&qs[i][j]);
	vector<int> test(n,1);
	test[n-1]=0;
	int point,ans=0,i=0;
  while(true){
		point = 0;
		test[n-1]++;
		rep(j,n){
			if(test[n-j-1]==m+1){
				test[n-j-2]++;
				test[n-j-1]=0;
			}
		}
		for(int j=1;j<n;j++){
			if(test[j] == 0)test[j] = test[j-1];
		}
		rep(j,q){
			if(test[qs[j][1]-1]-test[qs[j][0]-1] == qs[j][2]){
				point += qs[j][3];
			}
		}
		ans = max(point, ans);
		i++;
		if(test[0]==m) break;
	}
	cout << ans <<endl;
}

Measured memory_bytes: 3704
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
string a;
int main()
{
	int n,k=0,a,b;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>a>>b;
		k += b-a+1;
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	vector<int64> pp(nn+1);
	for(int64 ii = 1;ii <= nn;ii++)
	{
		cin >> pp[ii];
	}
	for(int64 ii = 1;ii <= nn;ii++)
	{
		if(ii != pp[ii])
		{
			continue;
		}
		if(ii == nn)
		{
			pp[ii] ^= pp[ii - 1];
			pp[ii - 1] ^= pp[ii];
			pp[ii] ^= pp[ii - 1];
			ans++;
			continue;
		}
		if(ii != nn)
		{
			pp[ii] ^= pp[ii + 1];
			pp[ii + 1] ^= pp[ii];
			pp[ii] ^= pp[ii + 1];
			ans++;
			continue;
		}
	}
	cout << ans << endl;
	return 0;
}

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

const int MAXN = 55;

int n, a, p, e = 0, o = 0;

int main()
{
	cin >> n >> p;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (a&1) o++;
		else e++;
	}
	if (o == 0) {
		if (p == 0) cout << (1ll<<e) << endl;
		else cout << 0 << endl;
	} else {
		cout << (1ll<<(o-1+e)) << endl;
	}
	return 0;
}



Measured memory_bytes: 256