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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] numArr = str.split("");

		int sum = 0;
		for(String s : numArr) {
			int n = Integer.parseInt(s);
			sum += n;
		}

		if(sum % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main() {
    
    int a, b;
    cin >> a >> b;
    if(a>=13) cout << b << endl;
    else if(a>5 && a<13)cout << b/2 << endl;
    else cout << "0" << endl;
    
    
    
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RS(a) string  a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
const int maxn=2e5+5;
int mx;
vector<int>adj[maxn];
bool vis[maxn];
int cnt;
void dfs(int v)
{
    vis[v]=1;
    cnt+=1;
    for(auto it:adj[v])
    {
        if(!vis[it])
        {
            dfs(it);
        }
    }
    mx=max(mx,cnt);
}
signed main()
{
    fastio;
    R(n);
    R(m);
    fr(i,1,m+1)
    {
        R(x);R(y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    fr(i,1,n+1)
    {
        if(!vis[i])
        {
            dfs(i);
        }
        cnt=0;
    }
    cout<<mx<<endl;

}


Measured memory_bytes: 20852
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
string S;
const ll P = 1e9+7;

int main(){
	cin >> S;
	int N = S.size();

	vector<vector<ll>> dp(N+1, vector<ll>(13));
	dp[0][0] = 1;
	for(int i=0; i<N; i++){
		for(int k=0; k<13; k++){
			if(S[i]=='?'){
				for(int d=0; d<10; d++){
					dp[i+1][(10*k+d)%13] += dp[i][k];
				}
			} else {
				dp[i+1][(10*k+(S[i]-'0'))%13] = dp[i][k];
			}
		}
		for(int k=0; k<13; k++) dp[i+1][k] %= P;
	}

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

	return 0;
}


Measured memory_bytes: 13696
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	M := nextInt()
	// P := make([]int, M)
	// Y := make([]int, M)
	city := make([][]Pair, N+1)
	cityIdx := make([]int, M+1)
	cityKen := make([]int, M+1)
	for i := 0; i < M; i++ {
		p := nextInt() // 県
		y := nextInt() // 年
		city[p] = append(city[p], Pair{a: i + 1, b: y})
	}
	log.Println(city)
	for i := 1; i < N+1; i++ {
		sort.Sort(Pairs(city[i]))
		for j := 0; j < len(city[i]); j++ {
			cityIdx[city[i][j].a] = j + 1
			cityKen[city[i][j].a] = i
		}
	}
	for i := 1; i < M+1; i++ {
		fmt.Printf("%06d%06d\n", cityKen[i], cityIdx[i])
	}
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, pow(2LL, N)) {
        if (K != __builtin_popcount(i))
            continue;
        cout << i << ":";
        REP(j, N) {
            if ((i >> j) & 1)
                cout << " " << j;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3340
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

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

int main() {

long long int a,b,c,k,f;

cin>>a>>b>>c>>k;
  if(k<=a)
  cout<<k;
  
 else if((k-a-b)<=0)
 cout<<a;
 
 else
 {
     
     f=k-a-b;
 cout<<a-f;

}

	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>

int main(){
    std::string s;

    std::cin >> s;

    if(s == "Sunny"){
        std::cout << "Cloudy" << std::endl;
    }else if(s == "Cloudy"){
        std::cout << "Rainy" << std::endl;
    }else if(s == "Rainy"){
        std::cout << "Sunny" << std::endl; 
    }

    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, 0, N) cin >> h[i];
    int ans = 0;
    rep(i, 0, N) if(h[i] >= K) ans++;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

int main(){
    int a,b;
    cin >> a >> b;
    printf("%d %d %.10f\n", a/b, a%b, (double)a/(double)b);

    return 0;
}



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

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

using namespace std;

const int inf = 4000;

int main(void){
  int n,ma,mb;
	cin >> n >> ma >> mb;

	vector<int> a(n), b(n), c(n);
	rep(i, n) { 
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[41][401][401];
	rep(i,41) rep(j,401) rep(k,401) dp[i][j][k] = inf+1;
	dp[0][0][0] = 0;
	
	rep(i, n) rep(ta, 401) rep(tb, 401) {
        if (ta + a.at(i) > 400 || tb + b.at(i) > 400) continue;
		dp[i + 1][ta + a.at(i)][tb + b.at(i)] = min(dp[i + 1][ta + a.at(i)][tb + b.at(i)], dp[i][ta][tb] + c.at(i));
		dp[i + 1][ta][tb] = min(dp[i + 1][ta][tb], dp[i][ta][tb]);
	}
	

	int k = 1, ans = inf+1;
	while (ma* k <= 400 && mb * k <= 400) {
		ans = min(dp[n][ma*k][mb*k], ans);
		++k;
	}

	if (ans > inf) cout << -1 << endl;
	 else cout << ans << endl;
  }



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

int main() {
  string X;
  string Y;
  cin >> X >> Y;
  
  if (X[0] == Y[2] && X[1] == Y[1] && X[2] == Y[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
//run: g++ -std=c++14 -o run_sol.exe solution.cpp -DLOCAL_JUDGE
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

int main() {
    #ifdef LOCAL_JUDGE
        freopen("../input.txt", "rt", stdin);
        freopen("../output.txt", "wt", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    for (int a, b; cin >> a >> b;) {
        if (a > 9 || b > 9) {
            cout << "-1\n";
            continue;
        }
        cout << a * b << "\n";
    }
return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
 
p = list(map(int, input().split()))
 
p = [(e+1) / 2 for e in p]
 
s = sum(p[0:k])
s_max = s
 
for i in range(n-k):
  s = s - p[i] + p[i+k]
  if s_max < s:
    s_max = s
    
print(s_max)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>(),T=in<string>();
	sort(ALL(S));
	sort(ALL(T),greater<char>());

	out(S<T ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 256
def fctr(n):
    f = []
    c = 0
    for i in range(2,int(n**0.5)+1):
        while n%i==0:
            c+=1
            n = n//i
        if c!=0:
            f.append([i,c])
            c = 0

    if n!=1:
        f.append([n,1])

    return f


N,P = list(map(int,input().split()))
s = fctr(P)

ans = 1

for i in range(len(s)):
    ans *= s[i][0] ** (s[i][1]//N)
        

print(ans)
        
            

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>

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

int main() {
    int A; cin >> A;
    int B; cin >> B;
    
    int count = 0;
    rep2(i, A, B+1) {
        string st = to_string(i);
        string str = st;
        reverse(str.begin(), str.end());

        if (st == str) count++; 
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>

#define int long long

using namespace std;

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b) {
        b *= 2;
        --k;
    }
    while (b >= c) {
        c *= 2;
        --k;
    }
    if (k >= 0) cout << "Yes";
    else cout << "No";
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}

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

typedef long long LL;
#define PB push_back

using namespace std;

int main(){
  int n;
  cin >> n;
  vector <int > a;
  for(int i=0; i <n; i++){
    int x;
    cin >> x;
    a.PB(x);
  }

  sort(a.begin(), a.end());
  LL s = 0;
  for(int i=0; i < n-1; i++){
    s+= a[i];
  }
  if(s > a[n-1]){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
dp = [0]*(n+1)

spots = [0]
spots = spots + list(map(int, input().split())) + spots
sum_cost = 0
for i in range(n+2):
  if i+1 > n+1:
    break
  sum_cost += abs(spots[i+1] - spots[i])
for i in range(1,n+1):
  d = sum_cost - abs(spots[i]-spots[i+1]) - abs(spots[i-1]-spots[i]) + abs(spots[i-1] - spots[i+1])
  print(d)
  


Measured memory_bytes: 14944
fn main(){
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    let s: &str = buf.trim();

    let ans = if s == "SSS" { 0 }
    else if s == "RRR" { 3 }
    else if vec!["RRS", "SRR"].contains(&s) { 2 }
    else{ 1 };

    println!("{}", ans)
}


Measured memory_bytes: 2124
N=int(input())
#S=input()
#A,B,T=map(int,input().split())
A=list(map(int,input().split()))
m=10**19
count=0
for i in A:
    if abs(i)<m:
        m=abs(i)
    if i<0:
        count+=1
if count%2==0:
    print(sum([abs(i) for i in A]))
else:
    print(sum([abs(i) for i in A])-2*m)


Measured memory_bytes: 65440
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
struct pt {
    int x, y;
};
pt p[N];
main() {
    int n = readInt();
    for (int i = 1; i <= n; i++) {
        p[i].x = readInt();
        p[i].y = readInt();
    }
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; ++j) {
            mp[{p[i].x - p[j].x, p[i].y - p[j].y}]++;
            if (p[i].x - p[j].x != p[j].x - p[i].x || p[i].y - p[j].y != p[j].y - p[i].y) {
                mp[{p[j].x - p[i].x, p[j].y - p[i].y}]++;
            }
        }
    }
    int mx = 0, x = p[1].x, y = p[1].y;
    for (auto it : mp) {
        if (it.second >= mx) {
            mx = it.second;
            x = it.first.first;
            y = it.first.second;
//        cout <<
        }
    }
    cout << n - mx;
}


Measured memory_bytes: 384
#include <iostream>
#include <atcoder/mincostflow>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1000000000000;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[52][52];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cin >> a[i][j];
    }
    mcf_graph<ll, ll> g(n * n + n * 2 + 2);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            g.add_edge(n * n + i, i * n + j, 1, INF - a[i][j]);
        }
    }
    for(int j = 0; j < n; j++){
        for(int i = 0; i < n; i++){
            g.add_edge(i * n + j, n * n + n + j, 1, INF - a[i][j]);
        }
    }
    for(int i = 0; i < n; i++){
        g.add_edge(n * n + n * 2, n * n + i, k, 0);
    }
    for(int j = 0; j < n; j++){
        g.add_edge(n * n + n + j, n * n + n * 2 + 1, k, 0);
    }
    g.add_edge(n * n + n * 2, n * n + n * 2 + 1, k * n, INF * 2);
    P ans = g.flow(n * n + n * 2, n * n + n * 2 + 1, k * n);
    cout << (INF * n * k * 2 - ans.second) / 2 << endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(g.get_edge(i * n + j).flow) cout << 'X';
            else cout << '.';
        }
        cout << endl;
    }
}


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

def main():
	N,X = map(int,input().split())
	m = []
	for i in range(N):
		m.append(int(input()))
	re = X - sum(m)
	min_m = min(m)
	add_d = re//min_m
	print(N+add_d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,now=0;
    string s;
    cin>>n>>m>>s;
    vector<int> a(n,0);
    
    for(int i=0;i<n-1;i++){
        a.at(i)=now;
        if(s.at(i)=='A'&&s.at(i+1)=='C') now++;
    }
    a.at(n-1)=now;
    
    int b,c;
    while(m--){
        cin>>b>>c;
        cout<<a.at(c-1)-a.at(b-1)<<"\n";
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,x[105],m,p[205],g[205][205],f[205][205],mxf,t,vz[205],ans=1e9,a,b;
vector <int> q;

bool isP(int n){
    if(n<3) return 0;
    int s=sqrt(n);
    for(int i=2;i<=s;i++){
        if(!(n%i)) return 0;
    }
    return 1;
}

bool DFS(int nod, int x){
    int b;
    vz[nod]=1;
    q.push_back(nod);
    if(nod==m+1){
        mxf=x;
        return 1;
    }
    for(int i=0;i<=m+1;i++){
        if(!vz[i] && g[nod][i]-f[nod][i]){
            b=DFS(i,min(x,g[nod][i]-f[nod][i]));
            if(b) return 1;
        }
    }
    q.pop_back();
    return 0;
}

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    x[0]=-1;
    for(int i=1;i<=n;i++){
        cin >> x[i];
        if(x[i-1]!=x[i]-1){
            if(m) p[++m]=x[i-1]+1;
            p[++m]=x[i];
        }
    }
    p[++m]=x[n]+1;
    for(int i=1;i<=m;i++){
        if(p[i]%2) a++;
        else b++;
        for(int j=i+1;j<=m;j++){
            if(isP(p[j]-p[i])){
                if(p[i]%2){
                    g[0][i]=1;
                    g[i][j]=1;
                    g[j][m+1]=1;
                }
                else{
                    g[0][j]=1;
                    g[j][i]=1;
                    g[i][m+1]=1;
                }
            }
        }
    }
    while(DFS(0,1e9)){
        for(int i=1;i<q.size();i++){
            f[q[i-1]][q[i]]+=mxf;
            f[q[i]][q[i-1]]-=mxf;
        }
        t+=mxf;
        q.clear();
        mxf=0;
        for(int i=0;i<=m+1;i++) vz[i]=0;
    }
    for(int i=0;i<=t;i++){
        ans=min(ans,i+((a-i)/2+(b-i)/2)*2+((a-i)%2)*3);
    }
    cout << ans;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B,C=LI()
K=II()

print(A + B + C - max(A,B,C) + max(A,B,C)*(2**K))


Measured memory_bytes: 9224
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

int a[1010];

int main(){
	int n,m;
	while(cin >> n >> m,n){
		rep(i,n) cin >> a[i];
		int sum=0;
		rep(i,n) sum+=a[i];
		sort(a,a+n);
		for(int i=n-m;i>=0;i-=m) sum-=a[i];
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    vector<int> w(10);
    vector<int> k(10);
    for(int i = 0; i < 10; i++){
        cin >> w[i];
    }
    for(int i = 0; i < 10; i++){
        cin >> k[i];
    }
    sort(w.begin(), w.end(), greater<int>());
    sort(k.begin(), k.end(), greater<int>());
    cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("fence.out", "w", stdout);
#endif

    int n, a;
    cin >> n >> a;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    int m = 2501;
    vector<vector<vector<long long>>> dp(n + 1, vector(n + 1, vector<long long>(m, 0)));
    dp[n][0][0] = 1;
    for (int i = n - 1; ~i; --i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k < m; ++k) {
                dp[i][j][k] = (j - 1 >= 0 && k - arr[i] >= 0 ? dp[i + 1][j - 1][k - arr[i]] : 0) + dp[i + 1][j][k];
            }
        }
    }

    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += dp[0][i][a * i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 55224
import sys


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


def bellman_ford(edges, N, start):
    dist = [float("inf") for _ in range(N)]
    dist[start] = 0
    # 辺の情報を見ることを1ループとすると
    # 1回のループで,最低でも1つの頂点について，スタートからの最短距離が求まる
    # つまり,スタートからの全ての頂点への距離は，
    # スタートを除いた頂点の数である,(N-1)回のループで求まる．
    for i in range(2 * N):
        for fro, to, cost in edges:
            if dist[to] > dist[fro] - cost:
                dist[to] = dist[fro] - cost
                # N回目に頂点の更新があると，負の経路がある
                if i == N - 1:
                    dist[to] = -float("inf")
    return dist


def main():
    N, M = map(int, input().split())
    edge = []
    for i in range(M):
        a, b, c = map(int, input().split())
        edge.append((a - 1, b - 1, c))
    D = bellman_ford(edge, N, 0)

    print(-1 * D[-1])


if __name__ == "__main__":
    main()


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

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

int main() {
  int N, K; cin >> N >> K;
  int g = -1, m = -1;
  for(int i=0; i<N; i++) {
    int p; cin >> p;
    if(i == 0) g = p;
    else g = gcd(g, p);
    m = max(m, p);
  }
  if(K % g == 0 && K <= m) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            Console.WriteLine(N % 2 == 0 ? N : N * 2);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
#include <map>
#include <algorithm>
#include <queue>
#include <chrono>
#include <array>
#include <random>
#include <fstream>
#include <list>
typedef int long long ll;

using int64 = long long;
using namespace std;

int W, H;
char mas[500][500];
int min_cost[500][500];

int main(){
    
    ll n;
    cin>>n;
    ll pret=0;
    ll prex=0,prey=0;
    while(n>0){
        ll t,a,b;
        cin>>t>>a>>b;
        ll kyori=abs(a-prex+b-prey);
        t=t-pret;
        if(kyori>t){
            cout<<"No"<<endl;
            return 0;
        }
       
        if(kyori%t!=0){
            kyori-=t;
            if(kyori%2!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        
        n--;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.AtCoder_Begginer_Contest_161
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);

            string[] A = Console.ReadLine().Split(' ');

            int sum = 0;
            foreach (var a in A)
            {
                sum += int.Parse(a);
            }

            double limit = sum / (4.0 * M);

            int count = 0;
            foreach (var a in A)
            {
                if (limit <= int.Parse(a))
                {
                    count++;
                }
            }

            Console.WriteLine(M <= count ? "Yes" : "No");
            //Console.ReadKey();
        }
    }
}


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

int main() {
    int N=0;
    cin >> N;

    vector<int> A(N, -1);
    rep(i, N) cin >> A.at(i);

    vector<pair<int, int>> B;
    rep(i, N){
        B.push_back(make_pair(A.at(i), i+1));
    }

    sort(B.begin(), B.end());
    rep(i,N){
        cout << B.at(i).second << " ";

        if(i == N-1){
            cout << endl;
        }
    }
}   


Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }
    long long sum = std::accumulate(a.begin(), a.end(), 0LL);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= b[i]) continue;
        ans = std::max(ans, sum - b[i]);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3516
import java.util.Scanner;

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

        int max = Math.max(A + B, A - B);
        max = Math.max(max, A * B);
        System.out.println(max);
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  vector<int> C(N);
  for (int i=0; i<M; i++){
    cin >> a >> b;
    C.at(a-1)++;
    C.at(b-1)++;
  }
  for (int i=0; i<N; i++)
    cout << C.at(i) << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
for i in range(1,10):
    for j in range(1,10):
        if N==i*j:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int x;
	std::cin >> x;
	std::cout << 3 * x * x << '\n';
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

/**
 * O(n)
 */
fun <T>elementCountMap(list: List<T>): Map<T, Long> {
    val countMap = mutableMapOf<T, Long>()
    for (e in list) {
        countMap[e] = (countMap[e] ?: 0) + 1
    }
    return countMap
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readLongList()
    val countMap = elementCountMap(aList)
    var all = 0L
    for (e in countMap) {
        all += e.value * (e.value - 1) / 2
    }

    for (a in aList) {
        println(all - countMap[a]!!  + 1)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 105832
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define mins(a,b) a = min(a,(decltype(a))(b))
#define maxs(a,b) a = max(a,(decltype(a))(b))

struct node {
	ll x, y, s;
	vector<int> link;
};
vector<node> nod;
void f(int ind, ll v, vector<int>& vec) {
	nod[ind].s = v;
	vec.push_back(ind);
	for (int& i : nod[ind].link) if (nod[i].s == -1) f(i, v,vec);
}
int main() {
	ll N;
	cin >> N;
	nod.resize(N);
	for (node& n : nod) n.s = -1;
	unordered_map<ll, int> mpx, mpy;
	REP(i, 0, N) {
		cin >> nod[i].x >> nod[i].y;
		if (mpx.count(nod[i].x) > 0) {
			nod[i].link.push_back(mpx[nod[i].x]);
			nod[mpx[nod[i].x]].link.push_back(i);
		}
		else mpx[nod[i].x] = i;
		if (mpy.count(nod[i].y) > 0) {
			nod[i].link.push_back(mpy[nod[i].y]);
			nod[mpy[nod[i].y]].link.push_back(i);
		}
		else mpy[nod[i].y] = i;
	}
	vector<vector<int>> vec;
	REP(i, 0, N) {
		if (nod[i].s == -1) {
			vec.emplace_back(vector<int>());
			f(i, vec.size() - 1, vec.back());
		}
	}
	vector<unordered_set<int>> usex(vec.size());
	vector<unordered_set<int>> usey(vec.size());
	REP(i, 0, vec.size()) {
		for (int& j : vec[i]) {
			usex[i].insert(nod[j].x);
			usey[i].insert(nod[j].y);
		}
	}
	ll ans = 0;
	REP(i, 0, vec.size()) {
		ans += usex[i].size() * usey[i].size() - vec[i].size();
	}
	PRI(ans);
	return 0;
}




Measured memory_bytes: 25896
import os
import numpy as np

if os.path.exists('input.txt'):
    test_mode = True
else:
    test_mode = False

if test_mode:
    f = open('input.txt')
    
def get_input():
    if test_mode:
        return f.readline().rstrip()
    else:
        return input().rstrip()

input_line = get_input().split()
X = int(input_line[0])
Y = int(input_line[1])

kame = float((Y - 2*X)/2)
turu = float(X - kame)

if turu >= 0 and kame >= 0 and turu.is_integer() and kame.is_integer() :
    print('Yes')
else:
    print('No')

if test_mode:
    f.close()

Measured memory_bytes: 27156
#include <bits/stdc++.h>
 
int main() { 
    int N, M;
    std::cin >> N >> M;

    constexpr int INF = std::numeric_limits<int>::max();
    std::vector<int> to[N];

    for (int i = 0; i < M; ++i) {
        int A, B;
        std::cin >> A >> B;
        --A;
        --B;

        to[A].push_back(B);
        to[B].push_back(A);
    }

    std::queue<int> q;
    std::vector<int> dist(N, INF);
    std::vector<int> pre(N, -1);

    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        const int v = q.front();
        q.pop();

        for (int u : to[v]) {
            if (dist[u] != INF) { 
                continue;
            }

            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    for (int i = 0; i < N; ++i) {
        if (i == 0) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << pre[i] + 1 << std::endl;;
        }
    }
}


Measured memory_bytes: 10540
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		int h,o,n = Integer.valueOf(sc.next());

		for (; n>0; n--,System.out.println(h>>2)) {

			for (h = 0, o = 0; o < 3;) {

				switch (sc.next().charAt(1)) {

				case 'I':

					h++;

					if((h&3)==0) h |= 3;

					break;

				case 'O':

					h += (((h&3)+1)<<2);

					h&=~3;

					break;

				default:

					o++;

					break;

				}

			}

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    int N = in(), L = in();
    VS ss = in<string>(N);

    sort(ALL(ss));
    for (auto s : ss) cout << s;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870
struct pig
{
    int x,y;
}info[200100];
int cnt,n,a[200100],c[200100],xo,xt,yo,yt,len,num;
long double ans;
bool cmp1(pig a,pig b)
{
    return a.y < b.y;
}
bool cmp(pig a,pig b)
{
    if(a.x == b.x)return a.y > b.y;
    return yo < yt ? a.x < b.x : a.x > b.x;
}
int find(int L,int R,int x)
{
    if(L == R) return L;
    int mid = (L + R) >> 1;
    if(c[mid] < x) return find(mid + 1,len,x);
    else return find(L,mid,x);
}
int main()
{
    scanf("%d%d%d%d",&xo,&yo,&xt,&yt);if(xt < xo)swap(xo,xt),swap(yo,yt);
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)scanf("%d%d",&info[i].x,&info[i].y);
    sort(info + 1,info + 1 + n,cmp);
    len=0;  c[0]=-0x7fffffff;
    for(int i = 1;i <= n;i++)
    {
        if(info[i].x > max(xt,xo) || info[i].y > max(yt,yo) || info[i].y < min(yo,yt) || info[i].x < min(xo,xt))continue;
        int tmp;
        if(info[i].y>c[len]) tmp = ++len;
        else tmp = find(1,len,info[i].y);
        c[tmp]=info[i].y;
    }
    ans = (long double)(abs(xt - xo) + abs(yt - yo)) * 100 - (20 - 5 * pi) * len;
    if(len == min(abs(xt - xo),abs(yt - yo)) + 1)ans += 5 * pi;
    printf("%.15Lf\n",ans);
}

Measured memory_bytes: 2560
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    print(max(A)-min(A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9068
n = int(input())
amounts = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]

INF = 10 ** 6
dp = [INF] * (n + 1)
dp[0] = 0
dp[1] = 1
for i in range(2, n + 1):
  for a in amounts:
    r = i - a
    if r >= 0:
      dp[i] = min(dp[i], dp[r] + 1)
print(dp[n])

Measured memory_bytes: 41964
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    int n;cin>>n;
    map<pair<ll,ll>,int> mp;
    int zero=0;
    rep(i,n){
        ll a,b;cin>>a>>b;
        if(a==0&&b==0){
            zero++;
            continue;
        }
        ll g=gcd(a,b);//片方が0だともう片方の絶対値が出てくる
        a/=g;b/=g;
        /*if(b<0||(b==0&&a<0)){
            b*=-1;a*=-1;//第3象限と第4象限の座標をそれぞれ第1象限と第2象限にまとめる
        }*/
        mp[{a,b}]++;
        mp[{-a,-b}]+=0;
        mp[{b,-a}]+=0;
        mp[{-b,a}]+=0;
    }
    vector<ll> s(2*n+1,1);
    rep(i,n*2){
        s[i+1]=s[i]*2;
        s[i+1]%=mod;
    }
    ll res=1;
    for(auto& p:mp){
        ll a=p.first.first,b=p.first.second;
        int x=p.second;
        if(x==-1)continue;//すでにtで見られている
        x+=mp[{-a,-b}];
        int t=mp[{-b,a}]+mp[{b,-a}];
        ll tmp=1;
        tmp+=s[x]-1;tmp%=mod;
        tmp+=s[t]-1;tmp%=mod;
        res*=tmp;res%=mod;
        mp[{-b,a}]=-1;mp[{-a,-b}]=-1;mp[{a,b}]=-1;mp[{b,-a}]=-1;
        //cout<<a<<" "<<b<<" "<<x<<" "<<t<<" "<<res<<endl;
    }
    res+=zero;
    res=(res+mod-1)%mod;
    cout<<res<<endl;
}


Measured memory_bytes: 56336
l=[c for c in input()]
l1=[-1]
l2=[]
for i,j in enumerate(l):
  if j not in 'ACGT':
    l1.append(i)
l1.append(len(l))
for i in range(len(l1)-1):
  l2.append(l1[i+1]-l1[i]-1)
print(max(l2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

string str;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    //int ;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> str;
    ll ans = 0, cnt = 0;
    for(auto it : str) {
        cnt += (it == 'B');
        ans += cnt * (it == 'W');
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> t(n), v(n);
    int en = 0;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        en += t[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<double> ub(2 * en + 1);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 2 * sum + 1; j <= 2 * (sum + t[i]); j++) {
            ub[j] = v[i];
        }
        sum += t[i];
    }
    sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 2 * (sum + t[i]) + 1; j <= 2 * en; j++) {
            chmin(ub[j], v[i] + (j - 2 * (sum + t[i])) / 2.0);
        }
        for (int j = 2 * sum; j > 0; j--) {
            chmin(ub[j], v[i] + (2 * sum - j) / 2.0);
        }
        sum += t[i];
    }
    for (int i = 1; i <= 2 * en; i++) {
        chmin(ub[i], i / 2.0);
    }
    for (int i = 2 * en; i >= 1; i--) {
        chmin(ub[i], (2 * en - i) / 2.0);
    }
    double res = 0;
    ub[0] = 0;
    for (int i = 1; i <= 2 * en; i++) {
        // cout << ub[i] << endl;
        res += (ub[i] + ub[i - 1]) / 4.0;
    }
    cout << fixed << setprecision(10) << res << endl;
}


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

int main()
{
	for(int x,y,s;cin>>x>>y>>s && x|y|s;){
		int res=0;
		for(int a=1;a<=s;a++)
			for(int b=a;a+b<=s;b++)
				if(a*(100+x)/100+b*(100+x)/100==s)
					res=max(res,a*(100+y)/100+b*(100+y)/100);
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#include <cmath>


using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = max({a + b, a - b, a * b});

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int h,w,n;
int main()
{
	h=read(); w=read(); n=read();
	int ans=h+w;
	for(int i=0;i<=h;i++)
		for(int j=0;j<=w;j++)
			if((h-i)*(w-j)<=h*w-n)ans=std::min(ans,i+j);
	writeln(ans);
	return 0;
}

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

using namespace std;

int N,Y;
int main(){
    cin >> N >> Y;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=N-i; j++){
            int k = ( N - ( i + j ) );
            if( i * 10000 + j * 5000 + k * 1000 == Y ){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {

    int n;
    cin >> n;
    map<int, int> counter;
    rep(i, n) {
        int a;
        cin >> a;
        counter[a]++;
        counter[a + 1]++;
        counter[a - 1]++;
    }

    int m = (*max_element(counter.begin(), counter.end(), [](const pair<int, int> &p1, const pair<int, int> &p2) {
        return p1.second < p2.second;
    })).second;

    cout << m << endl;

}

Measured memory_bytes: 4736
n, m, x = map(int, input().split())
listA = list(map(int, input().split()))

count=0
listA.sort()
index=0
while True:
    if listA[index]<x and index<len(listA):
        count+=1
        index+=1
    else:
        break

print(min([count, len(listA)-count]))

Measured memory_bytes: 3060
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n]
    }

    let mut max = a[0];

    let mut fum_total = 0;

    for i in 1..n {
        if max > a[i] {
            fum_total += max - a[i];
        }

        max = cmp::max(max, a[i]);
    }

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

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2704