akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long int lli;
#define tc int t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>



int main() {
	fastio;
    lli n;
    cin>>n;
    lli a[n],ans=0,x;
    unordered_map<lli,lli> fr;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        fr[x]++;
        a[i]=x;
    }
    for(auto it: fr)
    {
        ans+=((it.s)*(it.s-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<ans-fr[a[i]]+1<<"\n";
    }
    return 0;
}


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

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	int n, k; cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		ans += 2*min(x, k-x);
	}
	cout << ans << '\n';

	return 0;   
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string N;
  int flag=0;
  cin>>N;
  for(int i=0;i<N.size();i++){
    if(N.at(i)=='7')flag=1;
  }
  if(flag==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int M, N;
	cin >> M >> N;

	int result = 0;

	for( int i = 0; i < M; ++i ) {
		int x = 0;

		for( int j = 0; j < N; ++j ) {
			bool y;
			cin >> y;
			x += y;
		}

		result = max( result, x );
	}

	cout << result << endl;
}



Measured memory_bytes: 3220
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from pprint import pprint

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Dijkstra(g, s):
    d = {}
    q = []
    heapq.heappush(q, (0, s))

    while q:
        c, u = heapq.heappop(q)
        if u in d:
            continue
        d[u] = c
        for v in g[u]:
            if v not in d:
                heapq.heappush(q, (g[u][v] + c, v))
    return d


@mt
def slv(N, XY, YS, XT, YT, XYR):
    p = [(XY, YS, 0, -1), (XT, YT, 0, -2)]
    for i, (x, y, r) in enumerate(XYR):
        p.append((x, y, r, i))

    def cost(p1, p2):
        c = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) - p1[2] - p2[2]
        return max(0, c)

    g = defaultdict(dict)
    for i in range(N+2):
        for j in range(N+2):
            if i == j:
                continue
            d = cost(p[i], p[j])
            g[p[i][3]][p[j][3]] = d
            g[p[j][3]][p[i][3]] = d

    return Dijkstra(g, -1)[-2]


def main():
    XS, YS, XT, YT = read_int_n()
    N = read_int()
    XYR = [read_int_n() for _ in range(N)]
    print(slv(N, XS, YS, XT, YT, XYR))


if __name__ == '__main__':
    main()


Measured memory_bytes: 147044
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<' '<<a<<' '<<b;
	return 0;
}

Measured memory_bytes: 256
// IN THE NAME OF GOD
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 15;
int n, a[MAXN], ans;
map <int, int> pos;
vector <int> vect;
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i], vect.pb(a[i]);
  sort(vect.begin(), vect.end());
  for(int i = 0; i < (int)vect.size(); i++) pos[vect[i]] = i;
  for(int i = 0; i < n; i++) if(abs(i - pos[a[i]]) % 2) ans++;
  cout << ans / 2 << endl;
}


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

int main() {
    vector<string> e;
    string s;
    while (getline(cin, s), s != "END_OF_TEXT") {
        e.push_back(s);
    }
    int y = 0, x = 0;
    string buffer = "";
    char c;
    while (cin >> c, c != '-') {
        if (c == 'a') {
            x = 0;
        } else if (c == 'e') {
            x = e[y].size();
        } else if (c == 'p') {
            x = 0;
            y = max(0, y-1);
        } else if (c == 'n') {
            x = 0;
            y = min((int)e.size()-1, y+1);
        } else if (c == 'f') {
            if (x < (int)e[y].size()) {
                x ++;
            } else if (y+1 < (int)e.size()) {
                x = 0;
                y ++;
            }
        } else if (c == 'b') {
            if (0 < x) {
                x --;
            } else if (0 <= y-1) {
                x = e[y-1].size();
                y --;
            }
        } else if (c == 'd') {
            if (x < (int)e[y].size()) {
                e[y] = e[y].substr(0,x) + e[y].substr(x+1);
            } else if (y+1 < (int)e.size()) {
                e[y] += e[y+1];
                e.erase(e.begin() + y + 1);
            }
        } else if (c == 'k') {
            if (x < (int)e[y].size()) {
                buffer = e[y].substr(x);
                e[y] = e[y].substr(0,x);
                x = e[y].size();
            } else if (y+1 < (int)e.size()) {
                buffer = "\n";
                e[y] += e[y+1];
                e.erase(e.begin() + y + 1);
            }
        } else if (c == 'y') {
            if (buffer == "") {
                // nothing
            } else if (buffer == "\n") {
                e.insert(e.begin() + y + 1, e[y].substr(x));
                e[y] = e[y].substr(0,x);
                x = 0;
                y ++;
            } else {
                e[y] = e[y].substr(0,x) + buffer + e[y].substr(x);
                x += (int)buffer.size();
            }
        }
    }
    for (int i=0; i<(int)e.size(); ++i) {
        cout << e[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#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) << " "

int main(){
    int n;cin>>n;
    pair<string, pair<int,int>> p[n];
    rep(i,n){
        string s;int m;cin>>s>>m;
        p[i]=make_pair(s,make_pair(-1*m,i+1));
    }
    sort(p,p+n);
    rep(i,n){
        co(p[i].second.second);
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
const int MOD = 1000000007;


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
        int s,w; cin >> s >> w;
        if(w>=s) cout << "unsafe" << endl;
        else cout << "safe" << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();

    String ans = "";
    for (int i = 0; i < s.length(); i++) {
      for (int j = 0; j < alpha.length(); j++) {
        if (alpha.charAt(j) == s.charAt(i)) {
          if (j + n > 25) {
            ans = ans + String.valueOf(alpha.charAt(j + n - 26));
          } else {
            ans = ans + String.valueOf(alpha.charAt(j + n));
          }
        }
      }
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 148920
#include <bits/stdc++.h>
using namespace std;
const int N=200010;
int fi[N],ne[N],la[N],a[N],d[N];
int i,j,k,n,m,x,y,t;
void add(int x,int y){
	k++;a[k]=y;
	if (fi[x]==0)fi[x]=k;else ne[la[x]]=k;
	la[x]=k;
}
void dfs(int be,int x,int la){
	for (int i=fi[x];i;i=ne[i])
		if (a[i]!=la&&a[i]!=y){
			if (a[i]==be){
				printf("Yes\n");
				exit(0);
			}
			dfs(be,a[i],x);
		}
}
int main(){
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);add(x,y);add(y,x);
		d[x]++;d[y]++;
	}
	for (i=1;i<=n;i++)if (d[i]&1){printf("No\n");return 0;}
	x=0; for (i=1;i<=n;i++)if (d[i]>=6){printf("Yes\n");return 0;}else if (d[i]==4)x++;
	if (x>=3){printf("Yes\n");return 0;}
	if (x<=1){printf("No\n");return 0;}
	x=0;y=0;
	for (i=1;i<=n;i++)if (d[i]==4){if (x)y=i;else x=i;}
	dfs(x,x,-1);
	printf("No\n");
	return 0;
}

Measured memory_bytes: 4096
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	x := make([]int, n)
	y := make([]int, n)

	for i := 0; i < n; i++ {
		x[i] = nextInt() - 1
		y[i] = nextInt() - 1
	}
	var tl []int = []int{0, 1, 2, 3, 4, 5, 6, 7}
	pall := permutations(tl[:n])

	ans := 0.0
	for _, path := range pall {
		for i := 0; i < len(path)-1; i++ {
			dist := (x[path[i]]-x[path[i+1]])*(x[path[i]]-x[path[i+1]]) + (y[path[i]]-y[path[i+1]])*(y[path[i]]-y[path[i+1]])
			ans += math.Sqrt(float64(dist))
		}
	}
	ans = ans / float64(len(pall))
	fmt.Println(ans)
}

// 順列
// 順列作成 (ランダム順)
// var tl []int = []int{1, 2, 3, 4, 5, 6, 7, 8}
// pall := permutations(tl)
//   -> [[],[],[]]
// 数値リスト化 例
//	pallnum := make([]int, len(pall))
//	for i := 0; i < len(pall); i++ {
//		tmp := 0
//		for j := 0; j < n; j++ {
//			tmp += pall[i][j] * pow(10, n-j-1)
//		}
//		pallnum[i] = tmp
//	}
func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 9332
#include <algorithm>
#include<string>
#include<iostream>
using namespace std;
int main() {
    int N,K,Q;
    cin >> N >> K >> Q;
    int po[N];
    for(int i=0;i<N;++i){
        po[i]=0;
    }
    int s;
    for(int j=0;j<Q;++j){
        cin >> s;
        po[s-1]+=1;
    }
    for(int i=0;i<N;++i){
        if(Q-po[i]<K){
               cout << "Yes"<<endl;
        }else{
               cout << "No"<<endl;
        }
    }
    return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<bool> AC(n, false);
	vector<int> WA(n, 0);
	for (int i = 0; i < m; i++)
	{
		int p;
		string s;
		cin >> p >> s;
		p--;

		if (AC[p] == false)
		{
			if (s == "WA")
			{
				WA[p]++;
			}
			else if(s == "AC")
			{
				AC[p] = true;
			}
		}
	}
	int sumAC = 0, sumWA = 0;
	for (int i = 0; i < n; i++)
	{
		if (AC[i])
		{
			sumAC++;
			sumWA += WA[i];
		}
	}
	cout << sumAC << " " << sumWA << endl;
}

Measured memory_bytes: 640
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:char,
    b:char,
    }
    println!("{}",if a as usize >b as usize{">"}else if a==b{"="}else{"<"})
}

Measured memory_bytes: 2112
#include <stdio.h>
int main()
{
int a[3],least,i,j,temp;

scanf("%d%d%d",&a[0],&a[1],&a[2]);

for(i=1;i<3;i++)
for(j=0;j<3-i;j++)
{
if(a[j]>=a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}

}

printf("%d",a[0]+a[1]);

}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  string s;
  cin >> s;
  int q;
  cin >> q;
  bool inv = false;
  string prefix, suffix;
  for (int step = 0; step < q; ++step) {
    int type;
    cin >> type;
    if (type == 1) {
      inv = !inv;
      continue;
    }
    char c;
    cin >> type >> c;
    if ((type == 1) ^ inv) {
      prefix += c;
    } else {
      suffix += c;
    }
  }
  if (inv) {
    swap(prefix, suffix);
    reverse(s.begin(), s.end());
  }
  reverse(prefix.begin(), prefix.end());
  cout << (prefix + s + suffix) << endl;
  return 0;
}


Measured memory_bytes: 1348
import sys
input = sys.stdin.readline

a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[list(map(int,input().split())) for _ in range(m)]

ans=min(a)+min(b)
for i in range(m):
  ans=min(ans,(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2]))

print(ans)

Measured memory_bytes: 39224
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
  double n,k;
  cin >> n >> k;
  int half = ceil(n/2.0);
  if(k <= half){
      P("YES");
  }else{
      P("NO");
  }
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s,d;
    cin >> s >> d;
    rep(i,2*n){
        if(i%2==0){
            cout << s[i/2];
        }
        else{
            cout << d[(i-1)/2];
        }
    }

    return 0;
}

Measured memory_bytes: 3552
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/****@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*****/
/**********************************************************/

#include <bits/stdc++.h>
using namespace std;
//              Typedefs
typedef long long               ll;
typedef unsigned long long      ull;

//              Templates
template<class T>               using min_heap = \
                                priority_queue<T, \
                                std::vector<T>, std::greater<T>>;

//              Basic-Defs
#define PB                      push_back
#define MP                      make_pair
#define SP                      " "
#define NL                      "\n"
#define all(v)                  v.begin(), v.end()

//              DEBUG--SECTION
#define DE                      cout<<"HERE\n";
#define DE1(x)                  cout<<x<<"###\n";
#define DE2(x,y)                cout<<x<<"####"<<y<<"\n";
#define Pause                   system("pause");

//              Functions
#define clr(arr,value)          memset(arr,value,sizeof(arr))
#define __FAST_IO               ios_base::sync_with_stdio(0);\
                                cin.tie(0);cout.tie(0);
#define NUM1(x)                 __builtin_popcount(x)
#define LCM(x,y)                (x*y)/__gcd(x,y)

//              Sizes--Math     0123456789
#define MOD                     1000000007   //1e9+7 
#define MAX                     100050      
#define INF                     1e18
#define PI                      acos(-1)
#define eps                     1e-6

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    
    ll i,j,k,n,m,T; //basic variables
    ll ans = 0;
    for(i=1;i<=5;i++){
    	cin>>n;
    	if(n==0) ans=i;
    }
    cout<<ans<<NL;


    /// Don't forget to set array size....
    return 0;
}




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

int main(){
  long long n, d, x, y;
  cin >> n >> d;
  int ans = 0;
  for(int i=0; i<n; ++i){
    cin >> x >> y;
    if(sqrt(x*x + y*y) <= d) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3672
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	public static final int SIZE = 1005;
	public static long dp[][];

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		dp = new long[SIZE][SIZE];

		for(int i = 0; i < SIZE; i++){
			for(int k = 0; k < SIZE; k++){

				dp[i][k] = -1;
			}
		}

		int num_ball = scanner.nextInt();
		int num_box = scanner.nextInt();

		System.out.println(recursive(num_ball,num_box));
    }

	public static long recursive(int num_ball,int num_box){

		if(dp[num_ball][num_box] != -1){

			return dp[num_ball][num_box];
		}

		if(num_ball == 0){

			return 1;
		}else if(num_box == 1){

			return 1;
		}

		long ret = 0;

		for(int next_box = 1; next_box <= num_box; next_box++){
			int next_ball = num_ball-next_box;
			if(next_ball < 0)break;

			ret += recursive(next_ball,next_box);
			ret %= MOD;
		}

		return dp[num_ball][num_box] = ret;
	}
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 34808
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        
        System.out.print("2018/01/");
        System.out.print(N.charAt(8));
        System.out.println(N.charAt(9));
        
    }
}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
int pre[100005],suf[100005];
int arr[100005];
int main(){
	string s;long long k;
	cin>>s>>k;
	for(int i=0;i<min((long long)s.size(),k);i++){
		if(s[i]>='2'){cout<<s[i]<<endl;return 0;}
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  bool prim[10001];
  fill(prim,prim+10001,true);

  for(int i=2;i*i<10001;i++){
    if(prim[i]){
      for(int j=i*2;j<10001;j+=i){
        prim[j]=false;
      }
    }
  }

  vector<int>p;
  for(int i=2;i<10001;i++)
    if(prim[i])p.push_back(i);

  int n;
  while(cin >> n,n){
    int ans=0,sum=0;

    for(int i=0,j=0;j<p.size();){
      while(sum>n)sum-=p[i++];
      while(sum<n)sum+=p[j++];
      if(sum==n)ans++,sum+=p[j++];
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long A,B,C;
    cin >> A >> B >> C;
    long long ans = 0;
    for(int i = 0; i < 100000000; i++){
        if(ans%B == C){
            cout << "YES" << endl;
            return 0;
        }
        ans += A;
    }
    cout << "NO" << endl;
}

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

typedef pair<ll, int> P;

template <class T>
struct BIT {
	int n;
	vector<T> x;
	BIT(int n_ = 0) : n(n_), x(n + 1, 0) {}
	int size() const { return n; }
	T sum(int r) const {
		T S = 0;
		for(r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
		return S;
	}
	T sum(int l, int r) const { return sum(r) - sum(l); }
	void add(int k, const T &a) {
		for(; k < n; k |= k + 1) x[k] += a;
	}
	void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
	int lower_bound(T x) {
		int ng = -1, ok = n - 1;
		while(abs(ng - ok) > 1) {
			int mid = (ng + ok) / 2;
			if(sum(0, mid + 1) >= x) ok = mid;
			else ng = mid;
		}
		return ok;
	}
};


BIT<ll> bit(100000);
ll a[100000];
ll ans[100000];

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

	int N;
	cin >> N;

	priority_queue<P, vector<P>, greater<P>> q;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		q.push({ a[i], i });
		bit.add(i, 1);
	}

	ll h = 0;
	for(int i = 0; i < N; i++) {
		if(a[i] < h) continue;
		ll sum = 0;

		while(q.size() && q.top().first <= a[i]) {
			ll b = q.top().first, idx = q.top().second;
			q.pop();
			sum += b - h;
			bit.add(idx, -1);
		}
		sum += bit.sum(i, N) * (a[i] - h);
		ans[i] = sum;
		h = a[i];
	}

	for(int i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 5104
l = input()
mod = 10 ** 9 + 7
n = len(l)
x = 1
y = 2
for i in range(1, n):
    if l[i] == "0":
        x, y = 3 * x, y
    else:
        x, y = 3 * x + y, 2 * y
print((x + y) % mod)

Measured memory_bytes: 45788
N, L = map(int,input().split())
apple = []
for i in range(N):
  apple.append(L)
  L += 1

eat = apple[0]
for j in apple:
  if j < 0:
    if j > eat:
      eat = j
  elif j == 0:
  	eat = 0
  else:
    if j < eat:
      eat = j
print(sum(apple) - eat)

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;

int main()
{_
    ll n , m;
    cin >> n >> m;
    if(n==1 and m==1) return cout << 1 , 0;
    if(n == 2) return cout << 0 , 0;
    if(n == 1) return cout << (m - 2 > 0 ? m-2 : 0 ) , 0;
    if(m == 1) return cout << (n - 2 > 0 ? n-2 : 0 ) , 0;
    ll t = (n-2) * m;
    cout << t - (2*n) + 4;
	return 0;
}
///SAliB


Measured memory_bytes: 256
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)];

import numpy as np
# n = 30
# k = 100
# np.random.seed(100)
# a = np.random.randint(0, 2, size=(n, n))

graph = [[] for _ in range(n)]
for i, row in enumerate(a):
    for j, value in enumerate(row):
        if value:
            graph[i].append(j)

# dp = [[None] * (k + 1) for _ in range(n)]
# def dfs(i, at=k):
#     if dp[i][at] is not None:
#         return dp[i][at]
#     if at == 1:
#         r = len(graph[i])
#         dp[i][at] = r
#         return dp[i][at]
#
#     cnt = 0
#     for nxt in graph[i]:
#         cnt += dfs(nxt, at - 1)
#     dp[i][at] = cnt
#     return cnt
#
# print([dfs(i, at=k) for i in range(n)])
#
# for v in dp:
#     print(v)

# -------
import numpy as np
a = np.array(a, dtype=int)

M = 10**9 + 7
def powmod(a, n):
    if n == 0:
        return np.eye(np.alen(a), dtype=int)
    if n % 2:
        return (powmod(a, n - 1).dot(a)) % M
    r = powmod(a, n // 2)

    calc = []
    for row in r.T:
        calc.append(((row * r) % M).sum(axis=-1))
    return np.array(calc).T % M

print(powmod(a, k).sum() % M)
#
# v = a
# for _ in range(k - 1):
#     v = (v @ a) % M
# print(v.sum() % M)


Measured memory_bytes: 21548
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

using namespace std;

/*
for(int i=0;i<n;i++)
printf("%d\n",n)
scanf("%d",&n)
*/

int n,a[300000];
long long int b,sm=0,sa,r=0;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sm+=a[i];
    }
    for(int i=0;i<n-1;i++){
        b+=a[i];
        sa=sm-b;
        //printf("%d %d\n",b,sa);
        if(i) r=min(abs(sa-b),r);
        else r=abs(sa-b);
        
    }
    printf("%lld\n",r);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int add(int a, int b){return  a + b > mod ? a + b - mod : a + b;}
int mul(int a, int b){return a * b >=    mod ? a * b % mod : a * b;}  
int n, k;
int v[105];
int dp[105][N], prefixsum[N]; 
int f(int i, int w){
    if(w < 0)return 0;
    if(i == 0){
        return w == 0 ? 1 : 0;
    }
    int &ans = dp[i][w];
    if(ans == -1){
        ans = 0;
        for(int j = 0; j <= v[i]; j++)
            ans = add(ans, f(i - 1, w - j));
    }
    return ans;
} 
int main(){
    //FL;
    FIN;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    for(int i = 0; i <= n; i++){
        if(i){
            prefixsum[0] = dp[i - 1][0];
            for(int j = 1; j <= k; j++)
                prefixsum[j] = add(prefixsum[j - 1], dp[i - 1][j]);
        }

        for(int w = 0; w <= k; w++){
            int &ans = dp[i][w];
            if(i == 0){
                ans = (!w ? 1 : 0);
                continue;
            }
            ans = 0;
            
            ans = prefixsum[w];
            if(w - v[i] - 1 >= 0)
                ans = ((ans - prefixsum[w - v[i] - 1] + mod) % mod) % mod;
        }
    }

    cout << dp[n][k] << '\n';

    EjecuteTime;
    return 0;
}       


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

#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;


int main(void){
	ll n,m;
	while(cin >> n >> m,n){
		ll p[1010];
		vector<ll> pp;

		rep(i,n) cin >> p[i];
		p[n]=0;
		
		rep(i,n+1)rep(j,n+1) pp.emplace_back(p[i]+p[j]);
		sort(pp.begin(),pp.end());

		ll ans=0LL;
		for(auto &i:pp){
			ll j=pp[upper_bound(pp.begin(),pp.end(),m-i)-pp.begin()-1];
			if(i+j>m) continue;
			ans=max(ans,i+j);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

ll n, dp[3][N];
vector<int>g[N];

void dfs(int v, int pr=0) {
	dp[0][v] = dp[1][v] = 1;

	for(int to : g[v]) {
		if(to == pr) continue;
		dfs(to, v);	
		dp[0][v] = (dp[0][v] * (dp[0][to] + dp[1][to])) % mod;
		dp[1][v] = (dp[1][v] * dp[0][to]) % mod;
	}
}

main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].pb(y);
		g[y].pb(x);
	}

	dfs(1);

	cout << (dp[0][1] + dp[1][1]) % mod;
    
    return 0;                                        
}

Measured memory_bytes: 14464
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int a[10010]={0};
int b[10010]={0};
int ans=1001,w;
void kotani(int i,int j,int c,int n);
int main(){
	while(1){
	int n;
	scanf("%d",&n);
		w=n;
		ans=n;
		if(n==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<=3;j++){
			memcpy(b,a,sizeof(int) *n);
			if(b[i]!=j){
				b[i]=j;
				kotani(0,1,1,n);
			}
		}
	}
	printf("%d\n",ans);
	}
}
void kotani(int i,int j,int c,int n){
	if(b[i]==b[j]&&j<n){
		kotani(i,j+1,c+1,n);
	}
	else{
		if(c>=4){
			int u=0;
			for(int z=j;z<n;z++){
				b[i+u]=b[z];
				u++;
			}
			ans=min(ans,n-c);
			kotani(0,1,1,n-c);
		}
		else if(i+1<n){
			kotani(i+1,i+2,1,n);
		}
	}
}

Measured memory_bytes: 3256
while True:
    Num,Total = map(int,input().split())
    if Num == 0 and Total == 0:
        break
    Count = 0
    for i in range(1,Num+1):
        for j in range(i+1,Num+1):
            for k in range(j+1,Num+1):
                if i + j + k == Total:
                    Count += 1
    print(Count)

Measured memory_bytes: 7652
#include <iostream>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int64_t i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

using namespace std;

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

	int64_t n, a, b; cin >> n >> a >> b;

	if ((b-a)%2==0) {
		cout << (b-a)/2 << "\n";
	} else {
		int64_t ans = b-1;	
		pMin(ans,n-a);
		{
			int64_t toLeft = a; // time
			pMin(ans, toLeft + (b-toLeft)/2);
		} 
		{
			int64_t toRight =n-b+1;
			pMin(ans, toRight + (n-a-toRight)/2);
		}
		cout<<ans<<"\n";
	}
	return 0;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main() {
    int n,q; cin>>n>>q;
    string s; cin>>s;
    int l[100005]={},r[100005]={},ac_cnt[100005]={};
    rep(i,q)cin>>l[i]>>r[i];
    repp(i,1,s.size()){
        ac_cnt[i] = ac_cnt[i - 1];
        if(s[i-1]=='A'&&s[i]=='C'){
            ac_cnt[i]++;
        }
    }
    rep(i,q){
        cout<<ac_cnt[r[i]-1]-ac_cnt[l[i]-1]<<endl;
    }
}

Measured memory_bytes: 2176
import math

def output(A,B,ang):
    return (A**2 + B**2 - 2 * A * B * math.cos(ang)) ** (1/2)

A,B,H,M = map(int,(input().split()))

H_ang = H / 12 * 2 * math.pi + M / 60 * math.pi / 6
M_ang = M / 60 * 2 * math.pi
if abs(H_ang-M_ang) > math.pi:
    ang = math.pi * 2 - abs(H_ang - M_ang)
else:
    ang = abs(H_ang - M_ang)

print(output(A,B,ang))


Measured memory_bytes: 9516
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    a= list(map(int, sys.stdin.readline().split()))
    b= list(map(int, sys.stdin.readline().split()))

    ans = 0
    for i in range(n):
        ans += min(a[i]+a[i+1],b[i])
        if a[i] < b[i]:
            a[i+1] = a[i+1] - (b[i]-a[i])
            if a[i+1]<0:
                a[i+1]=0
    print(ans)

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

int main(){
  int N;
  int l,r;
  cin >>N;
  int total=0;
  for (int i=0;i<N;i++){
    cin>>l>>r;
    total=total+r-l+1;
  }
  
  cout<<total<<endl;
  return 0;
}

  

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    char buf[30];
    int n,x,i,j,cnt;
    int tmp;
    while (1)
    {
        cnt = 0;
        fgets(buf,sizeof(buf),stdin);
        sscanf(buf, "%d %d",&n,&x);
        if (n == 0&&x==0)
        {
            break;
        }
        for (i=1;i<n-1;i++)
        {
            for (j=i+1;j<n;j++)
            {
                tmp = x-i-j;
                if (j<tmp && tmp<=n)
                {
                    //printf("%d %d\n",i,j);
                    cnt += 1;
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> f(n+1, 0);
    for(int i = 1; i<n; i++) {
        ll num;
        cin >> num;
        f[num]++;
    }
    for(int i = 1; i <= n; i++) {
        cout << f[i] << "\n";
    }
    return 0; 
} 

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

void BubbleSort(vector<pair<char,int>>& a)
{
    int N=a.size();
    for(int i=0;i<=N-2;i++){
        for(int j=N-1;j-1>=i;j--){
            if(a[j-1].second>a[j].second) swap(a[j-1],a[j]);
        }
    }
}

void SelectionSort(vector<pair<char,int>>& a)
{
    int N=a.size();
    for(int i=0;i<=N-2;i++){
        int mn=a[i].second,idx=i;
        for(int j=i+1;j<N;j++) if(a[j].second<mn){
            mn=a[j].second; idx=j;
        }
        swap(a[i],a[idx]);
    }
}

int main()
{
    int N; cin>>N;
    vector<pair<char,int>> a(N);
    for(int i=0;i<N;i++) cin>>a[i].first>>a[i].second;
    
    auto b=a;
    BubbleSort(a);
    SelectionSort(b);

    for(int i=0;i<N;i++) cout<<a[i].first<<a[i].second<<(i==N-1? '\n':' ');
    cout<<(a==a? "Stable":"Not stable")<<endl;
    for(int i=0;i<N;i++) cout<<b[i].first<<b[i].second<<(i==N-1? '\n':' ');
    cout<<(a==b? "Stable":"Not stable")<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define debug(x) std::cout << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2, n / 2))
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}




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

int main() {

  int N;
  cin >> N;

  vector<long long> a(N);
  for(int i = 0;i < N;i++) {
    cin >> a.at(i);
  }

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

  int m,mini = 1000000010;
  for(int i = 0;i < N;i++) {
    if(mini > abs(a.at(i)*2 - a.at(N-1))) {
      mini = abs(a.at(i)*2 - a.at(N-1));
      m = a.at(i);
    }
  }

  cout << a.at(N-1) << " " << m << endl;
  
}



Measured memory_bytes: 1532
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    string S;
    cin >> S;

    int b_cnt = 0, w_cnt = 0;
    for (auto c: S) c == 'B' ? b_cnt++ : w_cnt++;

    long long right = 0, left = 0;
    for (int i = 0; i < b_cnt; i++) right += (S.size() - i - 1);
    for (int i = 0; i < S.size(); i++) if (S[i] == 'B')left += i;

    cout << right - left << endl;

}

















































Measured memory_bytes: 640
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
using namespace std;
using ll =long long;
const ll maxn=1e5+5,inf=1e18+18;
ll n,k,m,a[maxn];
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++)m+=a[i];
	cout<<m;
		
}


Measured memory_bytes: 3656
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

long long ryuka(int n){

    long long array[n] ;
    array[0] = 2 ;
    array[1] = 1 ;

    for(int i=2;i<=n;++i){
        array[i] = array[i-1] + array[i-2] ;
    }

    return array[n] ;
}


int main() {

    int n ;
    cin >>n  ;

    cout << ryuka(n) << endl  ;

 return 0 ;
}  


Measured memory_bytes: 256
#include <stdio.h>

int match(char a[51][51],char b[51][51],int m,int I,int J){
    int i,j;
    for(i=0;i<m;i++)for(j=0;j<m;j++){
        if(b[i][j]!=a[i+I][j+J]){
            return 0;
        }
    }
    return 1;
}
int main(){
    int n,m,i,j,yes=0,area;
    scanf("%d %d",&n,&m);
    
    char a[51][51],b[51][51];
    for(i=0;i<n;i++)scanf("%s",a[i]);
    for(i=0;i<m;i++)scanf("%s",b[i]);

    area = n-m;
    for(i=0;i<=area;i++)for(j=0;j<=area;j++){
        if(a[i][j]==b[0][0]){
            yes=match(a,b,m,i,j);
            if(yes==1)goto OUT;
        }
    }
    OUT:
    if(yes==1)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
n=int(input())
list=[]
ans=0
sa=1
sas=0
for i in range(n):
    a=int(input())
    list.append(a)
list=sorted(list)
list.append(10000000000)
for i in range(n+1):
    if i!=0:
        if list[i]==list[i-1]:
            sa+=1
        else:
            sas=sa
            sa=1
            if sas%2!=0:
                ans+=1
print(ans)

Measured memory_bytes: 8284
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int cap = abc[0] - abc[1];
            Console.WriteLine(cap >= abc[2] ? 0 : abc[2] - cap);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int a, b, x;
	cin >> a >> b;

	if (b < 10) {
		x = b + a * 10;
	}
	if (10 <= b && b < 100) {
		x = b + a * 100;
	}
	if (b == 100) {
		x = b + a * 1000;
	}
	int res = sqrt(x);
	cout << (res*res == x ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, X, Y = map(int, readline().split())

answer = [0 for _ in range(0, N)]
for i in range(1, N+1):
    for j in range(i, N+1):
        distance1 = abs(i-j)
        distance2 = abs(X-i) + abs(Y-j) + 1
        distance3 = abs(X-j) + abs(Y-i) + 1
        min_distance = min(distance1, distance2, distance3)
        answer[min_distance] += 1
for i, a in enumerate(answer):
    if i != 0:
        print(a)

Measured memory_bytes: 49372
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ull = unsigned long long;

int main(){
    int n,m,a;
    ull ans=0LL;
    cin>>n>>m;
    priority_queue<int> que;
    for(int i=0;i<n;i++){
        cin>>a;
        que.push(a);
    }
    for(int i=0;i<m;i++){
        a=que.top();
        que.pop();
        que.push(a/2);
    }
    for(int i=0;i<n;i++){
        ans+=1LL*que.top();
        que.pop();
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define EPS (1e-10)
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n); rep(i, n)cin >> a[i];
	int sum4 = 0, sum2 = 0, sum = 0;
	rep(i, n) {
		if (a[i] % 4 == 0) {
			sum4++;
		}
		else if (a[i] % 2 == 0) {
			sum2++;
		}
		else {
			sum++;
		}
	}
	if (sum2 == 0) {
		if (sum4 + 1 >= sum)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (sum4 >= sum)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	//cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1024
s = input()

n = len(s)
ans = 0

for i in range(2**(n-1)):
    f = s[0]
    for j in range(n-1):
        if ((i >> j) & 1):
            f += "+"
        f += s[j+1]
    
    ans += sum(map(int, f.split("+")))

print(ans)

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

void SimpleSort(int* array,int n){
    int temp = 0;
    int i = 0;
    int j = 0;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(array[i]<array[j]){
                temp = array[i];
                array[i]=array[j];
                array[j]=temp;
            }
        }
    }
    return ;
}

int main(){
    int array[10];

    for(int k=0;k<10;k++){
        cin >> array[k];
    }

    SimpleSort(array,10);

    for(int i=0;i<3;i++)
    cout << array[i] << endl;

    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

 
int main(void){
 
    int i,sum = 0;
    
    char a[200000];
 
    
    scanf("%s",a);
    
    int b[200000];
    
    for(i = 0;i < 200000; i++){
        b[i] = 0;
    
    }
    i = 0;
    while(a[i] != '\0'){
        b[i] = a[i] - 48;
		//printf("%d\n", b[i]);
		sum += b[i];
		
		i++;
	}
	
	if(sum % 9 == 0){
	    printf("Yes\n");
	}
	else{
	    printf("No\n");
	}
	
}

Measured memory_bytes: 1844
#include <stdio.h>

int main() {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	if (A <= C) {
		if (B >= D) {
			printf("%d", D - C);
		} else {
			if(B>=C) printf("%d", B - C);
			else printf("%d",0);
		}
	} else {
		if(B>=D){
			if(D>=A) printf("%d",D-A);
			else printf("%d",0);
		}
		else{
			printf("%d",B-A);
		}
	}
	return 0;
}


Measured memory_bytes: 256