akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


#A
"""
x,y = LI()
f = [0,1,2,1,3,1,3,1,1,3,1,3,1]
if f[x] == f[y]:
    print("Yes")
else:
    print("No")
"""
#B
"""
h,w = LI()
a = SR(h)
print("#"*(w+2))
for i in range(h):
    print("#",end = "")
    for j in a[i]:
        print(j,end = "")
    print("#")
print("#"*(w+2))
"""
#C
"""
h,w = LI()
ans = float("inf")
x = w//2
y = h//2
if not w%2:
    for i in range(1,h):
        if (h-i)%2 == 0:
            ans = min(ans,abs(w*i-w*(h-i)//2))
        ans = min(ans,abs(w*i-x*(h-i)))
else:
    for i in range(1,h):
        if (h-i)%2 == 0:
            ans = min(ans,abs(w*i-w*(h-i)//2))
        if w*i < x*(h-i):
            ans = min(ans,abs(w*i-(x+1)*(h-i)))
        elif w*i < (x+1)*(h-i):
            ans = min(ans,h-i)
        else:
            ans = min(ans,abs(w*i-x*(h-i)))
if not h%2:
    for i in range(1,w):
        if (w-i)%2 == 0:
            ans = min(ans,abs(h*i-h*(w-i)//2))
        ans = min(ans,abs(h*i-y*(w-i)))
else:
    for i in range(1,w):
        if (w-i)%2 == 0:
            ans = min(ans,abs(h*i-h*(w-i)//2))
        if h*i < y*(w-i):
            ans = min(ans,abs(h*i-(y+1)*(w-i)))
        elif h*i < (y+1)*(w-i):
            ans = min(ans,w-i)
        else:
            ans = min(ans,abs(h*i-y*(w-i)))
print(ans)
"""

#D
n = I()
a = LI()
q = []
s = 0
for i in range(n):
    heappush(q,a[i])
    s += a[i]
fl = [s]

for i in range(n,2*n):
    heappush(q,a[i])
    s -= heappop(q)
    s += a[i]
    fl.append(s)
q = []
s = 0
for i in range(2*n,3*n)[::-1]:
    heappush(q,-a[i])
    s += a[i]
fr = [s]

for i in range(n,2*n)[::-1]:
    heappush(q,-a[i])
    s += heappop(q)
    s += a[i]
    fr.append(s)
print(max(list(map(lambda x: x[0]-x[1], zip(fl,fr[::-1])))))
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 121384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		double kekka;
		int kekka2;
		
		if((1<=a)&&(a<=10)) {
			kekka = a+Math.pow(a,2)+Math.pow(a,3);
			kekka2 = (int)kekka;
			System.out.println(kekka2);
		}
		
		sc.close();

	}

}

Measured memory_bytes: 35844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

ll n;
set<string> st;

void dfs(string s,char mx) {
  if(s.length()==n) st.insert(s);
  else for(char c='a';c<=mx;c++) dfs(s+c,((c==mx)?(char)(mx+1):mx));
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n;
  dfs("",'a');
  for(string i:st) printf("%s\n",i.c_str());
  return 0;
}

Measured memory_bytes: 12416
#include <iostream>

using namespace std;
int main (){
    int h,n;
    cin >> h >> n;
    int s=0;
    int t;
    for (int i = 0; i < n; i++){
        cin >> t;
        s+=t;
    }
    if(s<h) cout << "No\n";
    else cout << "Yes\n";
}


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

int32_t main()
{
    int n, k;
    
    cin >> n >> k;
    vector<double> arr;
    arr.push_back(0);
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        arr.push_back( (double)((x * (x + 1)) / 2.0) / (double)x );
    }
    vector<double> pf(n + 2);
    for(int i = 1; i <= n; i++)
        pf[i] = pf[i - 1] + arr[i];
    double ans = pf[k];
    for(int i = k; i <= n; i++)
        ans = max(ans, pf[i] - pf[i - k]);
    cout << fixed << setprecision(12) << ans << '\n';
  
	return 0;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

struct Mo {
  static constexpr int MAX_N = 512345;
  int left[MAX_N], right[MAX_N], order[MAX_N];
  int width;
  int nl, nr, ptr, li, sz;
  Mo(int n) : width((int)sqrt(n)), nl(0), nr(0), ptr(0), li(0) {}
  /* [l, r) */
  void insert(int l, int r) {
    left[li] = l;
    right[li++] = r;
  }

  void build() {
    iota(order, order + li, 0);
    sort(order, order + li, [&](int a, int b) {
      const int ab = left[a] / width, bb = left[b] / width;
      return ab != bb ? ab < bb
                      : (ab & 1 ? right[a] < right[b] : right[b] < right[a]);
    });
  }

  inline int process() {
    if (ptr == li) return (-1);
    const auto id = order[ptr];
    while (nl > left[id]) add(--nl);
    while (nr < right[id]) add(nr++);
    while (nl < left[id]) del(nl++);
    while (nr > right[id]) del(--nr);
    return (order[ptr++]);
  }
  inline void add(int idx);
  inline void del(int idx);
};

int c[512345];
int cnt[512345];
int sum;

void Mo::add(int idx) {
  if (cnt[c[idx]]++ == 0) sum++;
}

void Mo::del(int idx) {
  if (--cnt[c[idx]] == 0) sum--;
}

int ans[512345];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  for (int i = 0; i < N; i++) cin >> c[i];
  Mo mo(N);
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    mo.insert(--l, r);
  }
  mo.build();
  for (int i = 0; i < Q; i++) {
    int idx = mo.process();
    ans[idx] = sum;
  }
  for (int i = 0; i < Q; i++) cout << ans[i] << "\n";
  return 0;
}


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

vector<int> a[100001];
int d[100001];

int N;

int func(int index)
{
	if (a[index].size() == 0)
	{
		return 0;
	}
	else
	{
		vector <int> b;
		int mx = 0, t = 0;
		for (int i : a[index])
		{
			b.push_back(func(i));
		}
		sort(b.begin(), b.end());
		for (int i = b.size() - 1; i >= 0; i--)
		{
			b[i] += t++;
			mx = max(mx, b[i]);
		}
		return mx + 1;
	}
}

int main()
{
	int g;
	cin >> N;
	for (int i = 2; i <= N; i++)
	{
		cin >> g;
		a[g].push_back(i);
	}
	cout << func(1);
}

Measured memory_bytes: 13568
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(final String[] args) {
        final Task task = new Task();
        task.solve();
    }
}

class Task {

    public void solve() {
        try(final Scanner scanner = new Scanner(System.in);) {
            final int n = scanner.nextInt();
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();

            final int sum = IntStream.rangeClosed(1, n).parallel().filter(i -> {
                int sumEachDigit = 0;
                int j = i;
                while (j > 0) {
                    sumEachDigit += j % 10;
                    j /= 10;
                }
                return (a <= sumEachDigit && sumEachDigit <= b);
            }).sum();
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 30416
#include<stdio.h>
int main()
{
  int N;
  int D1[101],D2[101];
  scanf("%d",&N);
  for(int i=0;i<N;i++){scanf("%d %d",&D1[i],&D2[i]);}
  int check=0;
  
  for(int i=0;i<N-2;i++){
    if(D1[i]==D2[i] && D1[i+1]==D2[i+1] && D1[i+2]==D2[i+2]){
      check = 1;
      break;
    }
  }
  if(check==0){printf("No");}else{printf("Yes");}
}



Measured memory_bytes: 1732
#include <bits/stdc++.h>
 using namespace std;
 
string s;
int main()
{
	getline(cin , s);
	int sum = 0;
	for(int i=0;i<s.length();i++)
	{
		sum += s[i]-'0';
	}
	if(sum%9==0)	cout << "Yes"<<endl;
	else cout << "No"<<endl;
	return 0;
}

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int money=sc.nextInt();
		int price_cake=sc.nextInt();
		int price_donut=sc.nextInt();
		
		money=money-price_cake;
		money=money-(money/price_donut)*price_donut;
		System.out.println(money);
	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
    int h, w;
    while (1)
    {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if ((i + j) % 2 == 0){
                    cout << "#";
                }
                else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr <<  #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }

vec<int> bin(int a,int n)
     {
           vec<int> b;
     	while(a>0)
     		 {
     		 	b.pb(a%2);
     		 	a/=2;
     		 }
    while(sz(b)<n)
    	b.pb(0);
    reverse(all(b));
    return b;



     }


void solve()
{   
	
int n,m,x;
cin>>n>>m>>x;
  int c[n];
  int a[n][m];
  for(int i=0;i<n;i++)
  	   {   cin>>c[i];
  	   	for(int j=0;j<m;j++)
  	   		  cin>>a[i][j];
  	   }
        int ans=LONG_MAX;
        int tot=(1<<n);


  	   for(int i=0;i<tot;i++)
  	   	   {   
               vec<int> b= bin(i,n);
               int cc[m]={0};
               int ll=0;
               for(int j=0;j<n;j++)
               	   { 
               	   	  if(b[j]==1)
               	   	  	  {   ll+=c[j];
               	   	  	  	  for(int k=0;k<m;k++)
               	   	  	  	  	   { 
               	   	  	  	  	   	cc[k]=cc[k]+a[j][k];


               	   	  	  	  	   }



               	   	  	  }

               	   }
               	   int f=0;

               	  // display(cc)
               	   for(int k=0;k<m;k++)
               	   	  {
               	   	  	if(cc[k]<x)
               	   	  		{f=1;}

               	   	  }
               	   	  if(f==0)
               	   	  	  ans=min(ans,ll);

  	   	   }

  	   	    if(ans==LONG_MAX)
  	   	    	cout<<-1;
  	   	    else
  	   	    	cout<<ans;



}
signed main()
{fast
    int t;
 t=1;
 
 //  cin>>t;
  while(t--)
     {
      solve();
     }
 
 
 
}

Measured memory_bytes: 3656
N = int(input())
digit = len(str(N))
one = 9
three = 900
five = 90000

if digit == 6:
    print(str(five+three+one))
elif digit == 5:
    print(str(three+one+(N-9999)))
elif digit == 4:
    print(str(three+one))
elif digit == 3:
    print(str(one+N-99))
elif digit == 2:
    print(str(one))
else:
    print(str(N))

Measured memory_bytes: 3064
def main():
    input = sys.stdin.readline
    try:
        H,W = map(int,input().split())
        s = [list(input()) for _ in range(H)]
        dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
        for i in range(H):
            for j in range(W):
                if s[i][j] == ".": continue
                cnt = 0
                for d in dir4:
                    nx = i + d[0]
                    ny = j + d[1]
                    if not (0 <= nx < H): continue
                    if not (0 <= ny < W): continue
                    if s[nx][ny] == "#": cnt += 1
                if cnt == 0:
                    print("No")
                    exit()
        print("Yes")
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int a[200005], z[200005];
vector<int> g[200005], b = {}, c = {};

void dfs(int x, int p) {
    z[x] = (int)c.size();
    for (int i : g[x]) if (i != p) {
        int w = 0, y = 0;
        if (a[i] > c.back()) c.push_back(a[i]), y = -1;
        else w = (int)(lower_bound(c.begin(), c.end(), a[i]) - c.begin()), y = c[w], c[w] = a[i];
        dfs(i, x);
        if (y == -1) c.pop_back();
        else c[w] = y;
    }
}

int main() {
    ios::sync_with_stdio(false);
    int n, u, v;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    b.push_back(a[1]);
    c.push_back(a[1]);
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    dfs(1, 1);
    for (int i = 1; i <= n; i++) cout << z[i] << '\n';
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t;
  while (cin >> t) {
    while (t--) {
      lli A, B, C, D;
      cin >> A >> B >> C >> D;

      if (0) ;
      else if (A < B) cout << "No" << endl;
      else if (D < B) cout << "No" << endl;
      else if (B <= C) cout << "Yes" << endl;
      else {
        lli g = __gcd(B, D);
        lli mx = (A % g) + (B - g);
        cout << (C < mx ? "No" : "Yes") << endl;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

string a(string s,string t,string u) {
	string::size_type pos = s.find(t);
	while (pos != string::npos) {
		s.replace(pos, t.size(), u);
		pos = s.find(t, pos + u.size());
	}
	return s;
}

int main() {
	string s;
	getline(cin, s);
	s = a(s, "apple", "PEACH");
	s = a(s, "peach", "apple");
	s = a(s, "PEACH", "peach");
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 1192
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))

lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

Measured memory_bytes: 15188
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]

AB.sort()
res=0
cnt=0

for a,b in AB:
	if cnt+b<m:
		cnt+=b
		res+=a*b
	else:
		res+=a*(m-cnt)
		break

print(res)

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  
  for (int i = 0; i < N; i++) {
    S = S.substr(N-1) + S.substr(0,N-1);
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
x = [[] for i in range(N)]
y = [[] for i in range(N)]
for i in range(N):
    A.append(int(input()))
    for j in range(A[i]):
        tmpX, tmpY = map(int, input().split())
        x[i].append(tmpX-1)
        y[i].append(tmpY)
ans = 0

for case in range(2**N):
    flag = True
    honest = 0
    for i in range(N):
        if (case >> i)&1 == False:  continue
        for j in range(A[i]):
            if (case >> x[i][j])&1 != y[i][j]:
                flag = False
        honest += (case >> i)&1

    if flag:
        ans = max(ans, honest)

print(ans)

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t, a[105];
    cin >> t;
    for(int i=0; i<t; i++) {
        cin >> a[i];
    }
    for(int i=0; i<t; i++) {
        if(a[i]%2 == 0) {
            if(a[i]%3 != 0 && a[i]%5 != 0) {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    REP(i, M) { cin >> L[i] >> R[i]; }
    int left = 0;
    int right = N;
    REP(i, M) {
        left = max(left, L[i]);
        right = min(right, R[i]);
    }
    int tmp = right - left + 1;
    if(tmp >= 0) {
        cout << tmp << endl;
    } else
        cout << "0" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double d=sqrtl(a),e=sqrtl(b),f=sqrtl(c);
    if(a+b+2*d*e<c){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
}    
    


Measured memory_bytes: 256
n = int(input())
tree = [None] * (n + 1)
preot = list(map(int, input().split()))
inot = list(map(int, input().split()))


def reconstruct(pretree, intree):
    if not pretree:
        return -1
    root = pretree[0]
    i = intree.index(root)
    tree[root] = (reconstruct(pretree[1:i + 1], intree[:i]), reconstruct(pretree[i + 1:], intree[i + 1:]))
    return root


def postorder(i):
    if i == -1: return
    l, r = tree[i]
    for v in postorder(l): yield v
    for v in postorder(r): yield v
    yield i


reconstruct(preot, inot)

print(*postorder(preot[0]))

Measured memory_bytes: 7776
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int count = 0;
        for (int i = 0;i < s.length();++i){
            if(s.charAt(i) == '1')++count;
        }
        System.out.println(count);
    }





}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N;
    ll ans=0;
    cin>>N;
    vector<int> A(N+1), B(N);
    rep(i,N+1)cin>>A[i];
    rep(i,N){
        cin>>B[i];
        ans+=min(B[i],A[i]+A[i+1]);
        if(A[i]<B[i]){
            A[i+1]=max(A[i+1]-(B[i]-A[i]),0);
        }
    }
    Out(ans);
    return 0;
}

Measured memory_bytes: 1024
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st; char ch;
    while(cin>>ch)
    {
        if(ch>='A'&&ch<='Z')cout<<'A'<<en;
        else cout<<'a'<<en;
    }
}




Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}

int main() {
  int h, w;
  string tmp;
  cin >> h >> w;
  vector<vector<string>> px(w);
  
  //1行目
  for(int i = 0; i < w+2; i++) {
    cout << "#";
  }
  cout << endl;
  
  //2行目から最終行1つ前まで
  for(int i = 0; i < h; i++) {
    cout << "#";
    cin >> tmp;
    for(int j = 0; j < w; j++) {
      cout << tmp.at(j);
    }
    cout << "#" << endl;
  }
  
  //最終行
  for(int i = 0; i < w+2; i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

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

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

int main(){
    int N;
    int K;
    int HList[100001] = {0};
    int dp[100201] = {1145141919};

    for(int i = 0; i < 100001;i++){
        dp[i] = 1145141919;
    }
    cin >>N>>K;

    dp[0] = 0;

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

    for(int i = 0; i <= N-1;i++){
        for(int j = 0;j<=K;j++){
            dp[i+j] = min(dp[i+j],dp[i] + abs(HList[i+j] - HList[i]));
        }
    }

    cout <<dp[N-1]<<endl;
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/


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

using namespace std;

#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define ALL(x) x.begin()m,x.end()

typedef long long LL;

int main()
{
    int T;scanf("%d",&T);
    while(T--){
        LL a,b,res;
        scanf("%lld %lld",&a,&b);
        LL small = min(a,b);
        LL big = max(a,b);
        LL cnt = 0;
        res = a*b;
        unordered_set<LL> si1;
        unordered_set<LL> si2;
        si1.insert(small);
        si2.insert(big);

        LL K = sqrt(res) - 2;

        if(res > 10){
            cnt += K*2;
            if(K >= small) cnt--;
        }
        else K = 0;

        //printf("%lld\n",cnt);

        for(LL i = K+1; i <res;i++){
            if(si1.count(i)) continue;
            LL j = res/i;
            if(i*j == res) j--;

            while(j > 0 && si2.count(j)) j--;
            if(j <= K) break;
            else {si2.insert(j);cnt++;}
        }

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


    return 0;
}


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

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

using namespace std;

class UF {
	public:
	static const int ufmax=1052;
	int ufpar[ufmax],ufrank[ufmax],ufcnt[ufmax];
	UF() { init();}
	void init(){int i; rep(i,ufmax) { ufpar[i]=i; ufrank[i]=0; ufcnt[i]=1; } }
	int find(int x) {	return (ufpar[x]==x)?(x):(ufpar[x] = find(ufpar[x]));}
	int operator[](int x) {return find(x);}
	int count(int x) {return ufcnt[find(x)];}
	void unite(int x,int y) {
		x = find(x); y = find(y);
		if(x==y) return;
		if(ufrank[x]<ufrank[y]) ufpar[x]=y, ufcnt[y]+=ufcnt[x];
		else {ufpar[y]=x; ufcnt[x]+=ufcnt[y]; if(ufrank[x]==ufrank[y]) ufrank[x]++;}
	}
};

#define fi first
#define se second


int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		using pii = pair<int,int>;
		using P = pair<int,pii>;
		vector<P> v(m);
		rep(i,m){
			cin>>v[i].se.fi>>v[i].se.se>>v[i].fi;
		}
		sort(v.begin(), v.end());
		UF uf;
		vector<int> w;
		for(auto x: v){
			int a=x.se.fi,b=x.se.se;
			a--,b--;
			if(uf[a] == uf[b]) continue;
			uf.unite(a,b);
			w.push_back(x.fi);
		}
		cout<<w[n/2-1]<<endl;
	}
}

Measured memory_bytes: 3196
N=int(input())
S=[input() for _ in range(N)]
S_=list(set(S))

ans_d={s:0 for s in S_}
for s in S:
    ans_d[s]+=1

M=max(set(ans_d.values()))
for k,v in sorted(ans_d.items()):
    if v==M:
        print(k)

Measured memory_bytes: 59460
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N, A, B; cin >> N >> A >> B;
  if(A > B)cout << 0 << endl;
  else if(A == B)cout << 1 << endl;
  else{
    if(N == 1)cout << 0 << endl;
    else if(N == 2)cout << 1 << endl;
    else cout << (A+(N-1)*B)-((N - 1)*A+B)+1 << endl;
  }
  return 0;
}


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

using namespace std;

int main(){
  int N,K; cin >> N >> K;
  
  double sum = 0.0;
  
  for(int i = 1; i <= N; i++){
    int a = i; double cnt = 1.0;
    while( a < K){
      a *= 2;
      cnt *= 0.5;}
    sum += cnt;}
  
  sum /= N;
  
  cout << setprecision(9) << sum << endl; return 0;}

Measured memory_bytes: 256
//@Author- sitanshu
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair 
#define mii map<int, int>
#define umii unordered_map<int, int>
#define vi vector<int>
#define vl vector<ll>
#define clr(val) memset(val,0,sizeof(val))
const ll MAX = 1000009, MOD = 1e9 + 7;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);


void solve()
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<vector<int>> v(3, vector<int>(n));
    v[0][0] = a; v[1][0] = b; v[2][0] = c;
    for(int i = 1; i < n; i++)
    {
        cin >> a >> b >> c;
        
        v[0][i] = max(v[1][i-1], v[2][i-1])+a;
        v[1][i] = max(v[0][i-1], v[2][i-1])+b;
        v[2][i] = max(v[0][i-1], v[1][i-1])+c;
    }

    cout << max(v[0][n-1], max(v[1][n-1], v[2][n-1])) << endl;
}



int main()
{
    //OJ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t = 1;
    while(t--)
    {
        solve();
    }  
    return 0;
}

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

using namespace std;
int n,x;
map<int,int> f;
int nr,v[100001];
vector<int> w;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        if(f.count(v[i])==0)
            w.push_back(v[i]);
        f[v[i]]++;
    }
    if(w.size()==3)
    {
        int fr=f[v[1]];
        for(int i=1;i<=n;i++)
            if(f[v[i]]!=fr)
        {
            cout<<"No";
            return 0;
        }
        int ans=(w[0]^w[1]);
        if(ans==w[2])
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }
    if(w.size()==2&&(w[0]==0||w[1]==0))
    {
        int nr1=w[0];
        int nr2=w[1];
        if(nr2==0)
            swap(nr1,nr2);
        if(f[nr2]==2*f[nr1])
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }
    if(w.size()==1&&w[0]==0)
    {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 4472
#!/usr/bin/env python3
from sys import stdin


def solve(tc):
    n = int(stdin.readline().strip())
    ai = list(map(int, stdin.readline().split()))

    adj = [[] for i in range(n)]
    for i in range(n - 1):
        adj[ai[i] - 1].append(i + 1)

    for children in adj:
        print(len(children))



LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')

tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Measured memory_bytes: 44192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    if (a >= b) {
      ans += a;
      a--;
    } else {
      ans += b;
      b--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define ll long long
#define N 100086
#define inf 1000000000
using namespace std;
int n,h[N];
int A,B;
bool jud(ll k)
{
    ll cnt=0;
    for(int i=1;i<=n;i++){
        ll tmp=h[i]-k*B;if(tmp<0)continue;
        ll num=tmp/A;
        cnt+=((tmp%A)?(num+1):num);
    }
    return cnt<=k;
}
int main()
{
    scanf("%d%d%d",&n,&A,&B);A-=B;
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    int l=0,r=inf;
    while(l<r){
        int mid=(l+r)/2;
        if(jud(mid))r=mid;else l=mid+1;
    }
    cout<<l<<endl;
    return 0;
}


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

int main() {
  vector<int> v(5);
  for (int i = 0; i < 5; i++) cin >> v[i];

  int ans = 1000;
  int cnt = 0;
  do {
    int sum = 0;
    for (int i = 0; i < 5; i++) {
      if (i == 4) {
        sum += v[i];
        break;
      }
      sum += v[i] / 10 * 10;
      v[i] % 10 ? sum += 10 : sum;
    }

    ans = min(ans, sum);
  } while (next_permutation(v.begin(), v.end()));

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

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	
	int n, a, b;

	/* 各桁の数字 */
	int dig;

	/* 和 */
	
	int ans = 0;

	cin >> n >> a >> b;;

	/* 自然数の各桁の数字の和を計算 */
	
	for (int i = 1; i <= n; i++) {
		int sum = 0;
		int num = i;
		while (num) {
			dig = num % 10;
			sum = sum + dig;
			num = num / 10;
		}

		if (a <= sum && sum <= b) {
			ans += i;
		}

	}
	
	cout << ans << endl;


}

Measured memory_bytes: 384
n = int(input())
ratios = []
for _ in range(n):
    ratios.append(tuple(map(int,input().split())))

a, b = 1, 1

for i in range(n):
    ra, rb = ratios[i]
    m = max(-(-a // ra), -(-b // rb))
    a, b = ra * m, rb * m

print(a + b)


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

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2 * 60 + m2 - (h1 * 60 + m1) - k;
    return 0;    
}

Measured memory_bytes: 3568
<?php
// Your code here!
fscanf(STDIN,"%d",$n);

$input = trim(fgets(STDIN));
$h = explode(" ",$input);

$cnt = 1;
$max = $h[0];

for($i=1;$i<$n;$i++){
    if($h[$i] >= $max){
        $cnt++;
        $max = $h[$i];
    }
}

echo $cnt;
?>


Measured memory_bytes: 4604
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
	int M = stdIn.nextInt();
	int m=(M*(M-1))/2; //偶数を２つ選ぶ
	int n=(N*(N-1))/2; //奇数を２つ選ぶ
	System.out.println(m+n);
    }
}
	    
	    


Measured memory_bytes: 21716
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		long e = in.nextInt();
		if (e == 0) return false;

		long min = 1<<30;

		for (long y=0; y*y<=e; y++) {
			for (long z=0; y*y+z*z*z<=e; z++) {
				long x = e - y*y - z*z*z;
				min = Math.min(min, x + y + z);
			}
		}

		out.println(min);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 32960
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#define MOD 1000000007

typedef long long ll;
using namespace std;

int main(void) {
    int i;
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a>=b){
        if(c>=a){
            for(i=0;i<k;i++){
                c *= 2;
            }
        }else{
            for(i=0;i<k;i++){
                a *= 2;
            }
        }
    }else{
        if(b>=c){
            for(i=0;i<k;i++){
                b *= 2;
            }
        }else{
            for(i=0;i<k;i++){
                c *= 2;
            }
        }
    }
    cout << a+b+c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    vector<ll>v(n);
    rep(i, n){
        cin>>v[i];
    }
    sort(v.begin(), v.end(), greater<ll>());
    int now = 0;
    ll ans = 0;
    rep(i, n-1){
        ans += v[now];
        if(i == 0) now++;
        else if(i%2 == 0) now++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4840
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}


#define int ll
void solve(){
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0) {
				cout << "DENIED" << endl;
				return;
			}
		}
	}
	cout << "APPROVED" << endl;
}
#undef int
int main() {
	init();
	solve();
}

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

namespace ABC165A
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            int[] AB = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int A = AB[0];
            int B = AB[1];

            int num = K;
            bool ans = false;
            while (num <= B)
            {
                if (A <= num && num <= B) ans = true;
                num += K;
            }

            if (ans) Console.WriteLine("OK");
            else Console.WriteLine("NG");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 19148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define INF 10000000000
ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s, t;

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

    while(cin >> n >> w){
        ll weight[n], value[n];
        rep(i, n){
            cin >> weight[i] >> value[i];
        }
        ll dp[n + 1][w + 1];
        rep(i, n){
            dp[i][0] = 0;
        }
        rep(i, w + 1){
            dp[0][i] = 0;
        }
        rep(i, 1, n + 1){
            rep(j, 1, w + 1){
                if(weight[i - 1] > j){
                    dp[i][j] = dp[i - 1][j];
                }else{
                    dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
                }
            }
        }
        cout << dp[n][w] << endl;
    }
}



Measured memory_bytes: 79232
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  string S; cin >> S;
  int N = S.size();
  LL cnt = 0;
  LL num_b = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'B') ++num_b;
    else             cnt += num_b;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

string s;
int main(){
	cin >> s;
	s+="DD";
	//vector<char> x(0);
	ll acount = 0,ans = 0;
	REP(i,s.size()){
		if(s.at(i) == 'A'){
			acount++;
		}
		else if(s.at(i) == 'B' && s.at(i+1) == 'C'){
			ans+=acount;
			i++;
		}
		else{
			acount = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
lis=[]
while True:
	w,h=[int(x) for x in input().split()]
	if w==0 and h == 0:
		break
	else:
		lis.append([w,h])
for x in lis:
	w,h=x[1],x[0]
	for i in range(h):
		for j in range(w):
			print("#",end="")
		print()
	print()


Measured memory_bytes: 7012
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	string s;
	cin>>s;
	int g=count(s.begin(),s.end(),'g'),p=count(s.begin(),s.end(),'p');
	cout<<(g-p)/2<<endl;
	return 0;
}



Measured memory_bytes: 512
import math

def main():
  N = int(input())
  K = int(input())
  x_i = input().split()
  x_i = [ int(x) for x in x_i ]
  ans = 0

  for i in range(0, N):
    ans += 2 * min(math.fabs(x_i[i] - 0), math.fabs(x_i[i] - K)) 

  print(int(ans))

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  string s;
  cin >> s;

  for(int i = 1; i <= s.size(); i++){
    if(i % 2){
      cout << s.at(i - 1);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt() + sc.nextInt() + sc.nextInt();
		if(a >= 22)
			System.out.println("bust");
		else
			System.out.println("win");
	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#define LL long long
using namespace std;
LL n;
LL a[100011];
LL ans1,ans2,num,minn;
LL read()
{
	LL _=0,__=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}
	return _*__;
}
int main()
{
	n=read();minn=1e9+7;
	for(int i=1;i<=n;i++)
	a[i]=read();
	sort(a+1,a+n+1);
	ans1=a[n];
	if(ans1%2==0)
	{
		num=ans1/2;
		for(int i=1;i<=n;i++)
		{
			if(abs(a[i]-num)<minn)
			{
				minn=abs(a[i]-num);
				ans2=a[i];
			}
		}
		
	}
	else 
	{
		num=ans1/2;
		for(int i=1;i<=n;i++)
		{
			LL nm=min(abs(a[i]-num),abs(a[i]-num-1));
			if(nm<minn)
			{
				minn=nm;
				ans2=a[i];
			}
		}
	}
	printf("%lld %lld\n",ans1,ans2);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    long a,b,c,d ; 
    long long F , G;

    cin >> a >> b>>c >>d;
    F = a * b ; 
    G = c*d ;
    if (F >= G )
    {
        cout << F ;
    }
    else if (F <= G )
    {
        cout << G ;
    }

    return 0;
}


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

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (t * s >= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int a, b, c;

int gcd(int x, int y){
    int t;
    if( x < y ){
        t = y;
        y = x;
        x = t;
    }
    while( y ){
        t = x%y;
        x = y;
        y = t;
    }
    return x;
}

int abs(int x){
    return x<0?-x:x;
}

int main(){
    cin >> a >> b >> c;
    while( a || b || c ){
        bool possible = true;
        int d = 0, x1, x2, u1, u2, s;
        while( d*d < b*b - 4*a*c ) d++;
        possible = (d*d == b*b - 4*a*c);
        if( possible ){
            s = (- b - d)/abs(- b - d);
            x1 = abs(- b - d);
            if( x1 ){
                u1 = 2*a/gcd(x1, 2*a);
                x1 = -s*x1/gcd(x1, 2*a);
                u2 = a/u1;
                x2 = c/x1;
            }else{
                u1 = 1;
                u2 = a;
                x2 = b;
            }
            if( u1 < u2 || (u1 == u2 && x1 < x2) ){
                int t = x1;
                x1 = x2;
                x2 = t;
                t = u1;
                u1 = u2;
                u2 = t;
            }
            cout << u1 << ' ' << x1 << ' ' << u2 << ' ' << x2 << endl;
        }else{
            cout << "Impossible" << endl;
        }
        cin >> a >> b >> c;
    }
    return 0;
}

Measured memory_bytes: 1156
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		
		// 計算
		long result = 0;
		
		HashMap<Long, Long> map = new HashMap<Long, Long>();
		for(long m = 2; m <= sqrt(n); m++){
		    if(n == 1) break;
		    if(n%m == 0){
		        while(n%m == 0){
		            n = n/m;
		            map.put(m, map.getOrDefault(m, 0L)+1);
		        }
		    }
		}
		if(n != 1) map.put(n, map.getOrDefault(n, 0L)+1);
    	for(Long l : map.values()){
    	    long temp = 0;
    	    for(int i = 1; i <= l; i++){
    	        temp += i;
    	        if(temp <= l) result++;
    	    }
    	}
		
		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}




Measured memory_bytes: 26324