akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <utility>

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

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

    int a,b;
    int i = 1;
    int ans = 0;

    priority_queue<pii, vector<pii>, function< bool (pii,pii)  >> pq(
        [](pii a,pii b) {
            return a.first > b.first;
        }
    );

    auto comp = [](pii a,pii b)-> bool {
        return a.second < b.second;
    };
    priority_queue<pii, vector<pii>, decltype(comp)> pq2(comp);

    rep(i,n){
        cin >> a >> b;
        pq.push(make_pair(a,b));
    }

    while(i <= m){
        if(!pq.empty()){
            if(i >= pq.top().first){
                int tmp = pq.top().first;
                while(tmp >= pq.top().first && !pq.empty()){
                    pii tmp = pq.top();
                    pq2.push(tmp);
                    pq.pop();
                }
            }
        }

        if(!pq2.empty()){
                if(pq2.top().first <= i){
                    pii tmp2 = pq2.top();
                    ans += tmp2.second;
                    pq2.pop();
                } 
        }
        i++;
    }

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

Measured memory_bytes: 2548
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    //std::stack<int> stack;
    vector<int> a(9);
    for(int i = 0; i < 9; i++){
        cin >> a[i];
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    string ans = "No";
    bool judge[9];
    for(int i = 0; i < 9; i++){
        judge[i] = false;
    }
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < n; j++){
            if(a[i] == b[j]){
                judge[i] = true;
            }
        }
    }
    for(int i = 0; i < 3; i++){
        if((judge[i*3] && judge[i*3+1]) && judge[i*3+2]){
            ans = "Yes";
            break;
        }
        if((judge[i] && judge[i+3]) && judge[i+6]){
            ans = "Yes";
            break;
        }
    }
    if((judge[0] && judge[4]) && judge[8]){
        ans = "Yes";
    }
    if((judge[2] && judge[4]) && judge[6]){
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;

        for (int i=a; i<=b; i++) {
            if (c % i == 0)
                count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26388
import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    int[] a = new int[n];
    int[] b = readln.chomp.split.to!(int[]);
    a[0] = b[0], a[1] = b[0];
    foreach (i; 1 .. n-1) {
        a[i] = min(a[i], b[i]);
        a[i+1] = b[i];
    }
    a.sum.writeln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    ll a = n,b = 1;
    for(ll i = sqrt(n)+1;i > 0;i--){
        if(n%i == 0){
            a = i;
            b = n/i;
            break;
        }
    }
    string s = to_string(a),t = to_string(b);
    cout << max(s.size(),t.size()) << endl;
    return 0;
}

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

int main(){
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		string s;
		map<string, int> mp;
		cin >> s;
		int size = s.size();
		for(int j = 1; j < size; j++){
			string t1(s.begin(), s.begin() + j);
			string t2(s.begin() + j, s.end());
			string t3(t1.rbegin(), t1.rend());
			string t4(t2.rbegin(), t2.rend());
			mp[t1+t2]++;
			mp[t1+t4]++;
			mp[t3+t2]++;
			mp[t3+t4]++;
			mp[t2+t1]++;
			mp[t2+t3]++;
			mp[t4+t1]++;
			mp[t4+t3]++;
		}
		cout << mp.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1004
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int N;

int main(){
    cin>>N;

    int x=N%10;
    string ans;
    if(x==3){
        ans="bon";
    }else if(x==0 || x==1 || x==6 || x==8){
        ans="pon";
    }else{
        ans="hon";
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,h;
    cin>>n>>k;
    int count=0;
    for (int i=0;i<n;i++) {
        cin>>h;
        if (h>=k) {
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main(){
  string s;
  cin >> s;
  set<char> st;
  rep(i, s.size()) st.insert(s[i]);
  if(s.size() == st.size()) cout << "yes" << ln;
  else cout << "no" << ln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  int sum = 0;
  rep(i,N){
    cin >> v[i];
    sum+=v[i];
  }
  sort(all(v));
  if(sum%10==0){
    bool zero = true;
    for(int &x: v){
      if(x%10!=0){
        sum-=x;
        zero = false;
        break;
      }
    }
    if(zero) cout << 0 << endl;
    else cout << sum << endl;
  }else cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	N := 5
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}

	var max int
	for i, n := range d {
		digit := digit(n, 1)
		if digit == 0 {
			continue
		}
		if abs(digit-10) > max {
			max = abs(digit - 10)
			d[i] += max
			tmp := d[0]
			d[0] = d[i]
			d[i] = tmp
		} else {
			d[i] += abs(digit - 10)
		}
	}

	d[0] -= max

	var res int
	for i := N - 1; i >= 0; i-- {
		res += d[i]
	}

	fmt.Println(res)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func digit(num, place int) int {
	r := num % int(math.Pow(10, float64(place)))
	return r / int(math.Pow(10, float64(place-1)))
}

func countDigits(i int) (count int) {
	for i != 0 {

		i /= 10
		count = count + 1
	}
	return count
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

Int gcd(Int a, Int b) { return b == 0 ? a : gcd(b, a%b); }

int n;
Int m, a[32];
double p[32];

double f(Int b) {
    Int x = 1;
    rep (i, n) if (b&(1<<i)) {
        const Int g = gcd(x, a[i]);
        if ((double)x/g*a[i] > 2e18) return 0;
        x = x/g*a[i];
        if (x > m) return 0;
    }
    return m / x;
}

int main() {
    cin >> n >> m;
    rep (i, n) cin >> a[i];
    rep (i, n) cin >> p[i];
    rep (i, n) p[i] /= 100;
    double ans = 0;
    rep (b, 1<<n) if (b) {
        int c = 0;
        double q = 1.0;
        rep (i, n) if (b&(1<<i)) {
            c++;
            q *= p[i];
        }
        ans += q * f(b) * (c%2 ? 1 : -1);
    }
    printf("%.12f\n", ans);
    return 0;
}

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

using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
 
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

const int M = 1e3 + 10;
const int INF = 1e9; 

int dp[1<<14];

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

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < (1<<n); ++i)
    {
        dp[i] = INF;
    }

    dp[0] = 0;

    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        int otvara = 0;
        for(int j = 0; j < b; ++j)
        {
            int c;
            cin >> c;
            --c;
            otvara += (1<<c);
        }

        for(int j = 0; j < (1<<n); ++j)
        {
            ckmin(dp[j|otvara], dp[j] + a);
        }
    }

    cout << ((dp[(1<<n)-1] == INF) ? -1 : dp[(1<<n)-1]) << "\n";
}


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

namespace AOJ0218 {
	class Program {
		static void Main(string[] args) {
			Console.WriteLine(Solve());
		}


		static string Solve() {
			switch (Console.ReadLine()) {
				case "1 1 0":
				case "0 0 1":
					return "Open";
				default:
					return "Close";
			}

		}
	}
}

Measured memory_bytes: 5396
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

struct FordFulkerson {
    struct edge {
        int to;
        int cap;
        int rev;
    };

    int dfs(int s, int t, int mn) {
        if (s == t) return mn;
        visited[s] = true;
        for (int i = 0; i < table[s].size(); i++) {
            edge &e = table[s][i];
            if (visited[e.to] || e.cap <= 0) continue;
            int diff = dfs(e.to, t, min(mn, e.cap));
            if (diff > 0) {
                e.cap -= diff;
                table[e.to][e.rev].cap += diff;
                return diff;
            }
        }
        return 0;
    }

    int V;
    vector<vector<edge> > table;
    vector<bool> visited;
public:
    FordFulkerson(int v) {
        V = v;
        table.resize(V);
        visited.resize(V);
    }

    void add_edge(int from , int to, int cap) {
        table[from].push_back((edge){to, cap, (int) table[to].size()});
        table[to].push_back((edge){from, 0, (int) table[from].size() - 1});
    }

    int calc(int s, int t) {
        int flow = 0;
        while (true) {
            fill(visited.begin(), visited.end(), false);
            int f = dfs(s, t, INF);
            if (f == 0) break;
            flow += f;
        }
        return flow;
    }
};


signed main() {
    int X, Y, E;
    cin >> X >> Y >> E;

    FordFulkerson ff = FordFulkerson(X + Y + 2);
    for (int i = 0; i < E; i++) {
        int x, y;
        cin >> x >> y;
        ff.add_edge(x, X + y, 1);
    }
    for (int i = 0; i < X; i++) {
        ff.add_edge(X + Y, i, 1);
    }
    for (int i = 0; i < Y; i++) {
        ff.add_edge(X + i, X + Y + 1, 1);
    }

    cout << ff.calc(X + Y, X + Y + 1) << endl;

    return 0;
}


Measured memory_bytes: 3424
group = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]
a,b = gets.split.map(&:to_i)
switch = false
i = 0
while i < group.size
  if group[i].include?(a) && group[i].include?(b)
    switch = true
  end
  i += 1
end

if switch
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3964
from operator import itemgetter

n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]

ab.sort()
ab.sort(key=itemgetter(1))
t = 0
for a, b in ab:
    t += a
    if t > b:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 44024
#include<stdio.h>
#include<string.h>

int main(void){
    int sum,i;
    char X[1001];

    while(1){
        scanf("%s",X);
        if(X[0]=='0') break;
        sum=0;

        for(i=0;i<strlen(X);i++){
            sum+=X[i]-'0';
        }

        printf("%d\n",sum);
    }

    return 0;
}


Measured memory_bytes: 2044
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define inf 2e15
const int minnodes=1005;
#define ll long long

#define EPS 0.000000001
#define N 2000000 


 
int32_t main()
{
    IOS;

    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    int sum = 0;
    for(int i = 0;i < n;i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    sort(v.begin(),v.end());
    int fans = 1;
    for(int ans = 1;ans*ans <= sum;ans++)
    {
        if(sum % ans == 0)
        {
            int det = ans;
            int dec = 0;
            vector<int> r; 
            for(int i = 0;i < n;i++)
            {
                if(v[i] % det != 0)
                {
                    dec -= v[i]  % det;
                    r.push_back(det - v[i] % det);

                }
            }
            if(r.size() == 0)
                fans = max(fans,det);
            int req = 0;
            sort(r.begin(),r.end());
            for(auto diff : r)
            {
                req += diff;
                if(req > k)
                    break;
                dec += det - diff;
                if(req + dec >= 0)
                {
                    fans = max(fans,det);
                    break;
                }
            }
            det = sum / ans;
            dec = 0;
            r.clear();
            for(int i = 0;i < n;i++)
            {
                if(v[i] % det != 0)
                {
                    dec -= v[i]  % det;
                    r.push_back(det - v[i] % det);

                }
            }
            if(r.size() == 0)
                fans = max(fans,det);
            req = 0;
            sort(r.begin(),r.end());
            for(auto diff : r)
            {
                req += diff;
                if(req > k)
                    break;
                dec += det - diff;
                if(req + dec >= 0)
                {
                    fans = max(fans,det);
                    break;
                }
            }

        }

        
    }
    cout << fans;
}
 

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

int main()
{
  vector<int> p(5), r(5);
  int i, t;
  while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4], p[0]) {
    t = 0;
    for (i = 0; i < 5; i++) {
      if (p[i] == 3 && !(t&4)) t ^= 4;
      else if (p[i] != 3 && !(t&p[i])) t ^= p[i];
    }
    if (t == (1+2)) for (i = 0; i < 5; i++) if (p[i] == 1) r[i] = 1; else r[i] = 2;
    else if (t == (2+4)) for (i = 0; i < 5; i++) if (p[i] == 2) r[i] = 1; else r[i] = 2;
    else if (t == (4+1)) for (i = 0; i < 5; i++) if (p[i] == 3) r[i] = 1; else r[i] = 2;
    else for (i = 0; i < 5; i++) r[i] = 3;

    for (i = 0; i < 5; i++) cout<<r[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*
	
	@Raghul
*/
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
ll ans[100005];
ll fastpow(ll a,ll b){
	if(b==0)
		return 1LL;
	ll temp=fastpow(a,b/2);
	temp=temp*temp;
	if(b%2==1)
		temp=temp*a;
	return temp;
}	
void solve(){
	ll n, k;
	cin>>n>>k;
	ll a[n+1], sum = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	ll prefix[n+1] = {0};
	for(int i=1;i<=n;i++)	prefix[i] = prefix[i-1]+a[i];
	ll maxi = 1e9;
	for(int i=1;i<=n-k+1;i++){
		maxi = min(maxi, a[i+k-1]-a[i]);
	}
	cout<<maxi;
	return;
}
int main(){ 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T;
    T = 1;
    while(T--){
    	solve();
    }
    return 0;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; string s;
  cin >> n >> s;
  vector<P> v(n+1); // first: E, second: W
  v[0] = {0,0};
  REP(i,n) {
    int e = v[i].first, w = v[i].second;
    if (s[i] == 'E') e++;
    else w++;
    v[i+1] = {e,w};
  }

  int ans = INF;
  REP(i,n) {
    int l = v[i].second-v[0].second;
    int r = v[n].first-v[i+1].first;
    ans = min(ans, l+r);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int cap_1 = H % 2 == 1 && W % 2 == 1 ? 1 : 0;
        int cap_2 = H % 2 * (W / 2) + W % 2 * (H / 2);
        int[] appearance = new int[26];
        for (int i = 0; i < H; i++) {
            String a = sc.next();
            for (int j = 0; j < W; j++) {
                appearance[a.charAt(j) - 'a']++;
            }
        }
        for (int i = 0; i < 26; i++) {
            if (appearance[i] % 2 == 1) {
                cap_1--;
            } else if (appearance[i] % 4 == 2) {
                cap_2--;
            }
            if (cap_1 < 0 || cap_2 < 0) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 22996
#include <iostream>
int main(){
	int H,W;
	while(true){
		std::cin >> H >> W;
		if(0 == H&&0 == W)break;
		for(int a = 0;a < H;a++){
			for(int b = 0;b < W;b++){
				std::cout << "#";
			}
			std::cout <<std::endl;
		}
		std::cout <<std::endl;	}
}

Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main()
{
	bool c=false,f=false;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
	{
        if(s[i]=='C') c=true;
        if(s[i]=='F'&&c) f=true;
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define INF 20000000000000000
using ll = long long;

vector<ll> coutdp(100001);

int main(){
    fill(coutdp.begin(),coutdp.begin()+100001,INF);
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n+1);
    for(ll i=1;i<=n;i++)   cin >> h[i];
    coutdp[1] = 0;
    for(ll i=2;i<=n;i++){
        for(ll j=1;j<=k&&i-j>=1;j++){
            coutdp[i] = min(coutdp[i],coutdp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << coutdp[n] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,n,a[100000],cnt,x[2];
	long long s;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	sort(a,a+n);
	cnt=0;
	for(i=n-1;i>=1;i--)	{
		if(a[i]==a[i-1])	{
			x[cnt]=a[i];
			i--;
			cnt++;
			if(cnt==2)	break;
		}
	}
	if(cnt!=2)	s=0;
	else s=(long long)x[0]*x[1];
	printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 512
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    h = [int(input().rstrip('\n')) for _ in range(n)]
    h.sort()
    ma = 10 ** 10
    for i in range(k-1, n):
        ma = min(ma, abs(h[i] - h[i-k+1]))
    print(ma)


if __name__ == '__main__':
    slove()


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


int main() {

    int N; cin >> N;
    vector<int> P(N);
    forn(i,N) cin >> P[i];
    vector<int> Q = P;
    sort(P.begin(), P.end());
    int cnt = 0;
    forn(i,N) {
        if (P[i] != Q[i]) {
            cnt++;
        }
    }
    if (cnt == 2 || cnt == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

	vector<pair<long long int, long long int>> p;

	for(int i = 0; i < N; i++)
	{
		long long int a, b;
		cin >> a >> b;
		p.push_back(make_pair(b, a));
	}

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

	long long int cnt = 0;
	for(int i = 0; i < N; i++)
	{
		cnt += p[i].second;
		if(cnt > p[i].first)
		{
			cout << "No" << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    string s;
    cin>>s;
    char zero='0';
    char one='1';
    int n=s.length();
    int cnt=0;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
           if(zero==s[i+1]) s[i+1]=one;
           else s[i+1]=zero;
           
           cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main(){
  ll s;
  cin >> s;
  cout << "0 0 1000000000 1 " << 999999999-(s-1)%1000000000 << ' ' << (s-1)/1000000000+1 << endl;
}

Measured memory_bytes: 3640
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	println!("{}", (m-1)*(n-1) );
}

Measured memory_bytes: 4352
/* Read input from STDIN. Print your output to STDOUT*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll> adj[10000];
int main()
{
    ll n,i,j,k,l,m,o,p,q,r,s,t,a[300001],prefix[30001],suffix[300001],x,y;
    cin>>n>>x>>y;
    map<ll,ll> mp;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(j!=i)
            {
                m=i;
                o=j;
                if(m>o)
                swap(m,o);
                s=o-m;
                r=abs(x-o)+abs(y-m)+1;
                p=abs(x-m)+abs(y-o)+1;
                mp[min({s,p,r})]++;
            }   
        }
    }
    for(i=1;i<=n-1;i++)
    cout<<mp[i]<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int ans = 0;
    int n; sc(n);
    int d[n]; fo(i, n) sc(d[i]);
    for(int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    printf("%d", ans);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

int main() {
	long long n,i,j,k;
	cin>>n>>k;
	long long h[n],a=0;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	sort(h,h+n);
	for(i=0;i<n-k;i++)
	a+=h[i];
	cout<<a;
	return 0;
}

Measured memory_bytes: 1792
# python3.5

import sys

n = int(sys.stdin.readline())
ns = sys.stdin.readline().split()

for i in range(0, len(ns)): 
    ns[i] = int(ns[i]) 

ns.sort()

if ns[0] == 0:
	print(0)
else:
	res = 1
	for i in ns:
		res = res * i
		if res > 1000000000000000000:
			res = -1
			break
	print(res)

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

int main() {
  int n; cin>>n;
  vector<int> a(n+1), b(n+1);
  rep(i, n) cin>>a[i+1];

  for (int i = n; i > 0; --i) {
    int sum = 0;
    for (int j = 2*i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }
  vector<int> ans;
  rep(i, n+1) if (b[i]) ans.push_back(i);
  cout << ans.size() << endl;
  rep(i, ans.size()) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 209
#define pi pair<int,int>
using namespace std;
typedef long long ll;
map<int,int>m;
long long  power(long long  x, long long y)
{
    if (y == 0)
        return 1LL;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}
int main()
{
    ll n;
    cin>>n;
    for(ll i=0;i<=1000;i++)
    {
        for(ll j=0;j<=1000;j++)
        {
            ll x1=pow(i,5);
            ll x2=pow(-i,5);
            ll y1=pow(j,5);
            ll y2=pow(-j,5);

//            if(i==100 && j==99)
//            {
//                puts("x");
//                cout<<x1<<" "<<y1<<endl;
//            }

            if(x1-y1 == n)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
            if(x2-y2 == n)
            {
                cout<<-i<<" "<<-j<<endl;
                return 0;
            }
            if(x1-y2 == n)
            {
                cout<<i<<" "<<-j<<endl;
                return 0;
            }
            if(x2-y1 == n)
            {
                cout<<-i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    return 0;
}
/*
490099501
*/


Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] < a[i + 1]) ans++;
	}
	cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    int s = 0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        s += p[i];
    }
    sort(p.begin(),p.end(),greater<int>());

    cout << s - p[0] / 2 << endl;
    
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	enum Order {
		North(1, 0), East(0, 2), South(0, 1), West(2, 0), Right(2, 1), Left(1,
				2);

		final int from, to;

		Order(int from, int to) {
			this.from = from;
			this.to = to;
		}

		public void rool(int[] dice) {
			int ura = 7 - dice[to];
			dice[to] = dice[from];
			dice[from] = ura;
		}
	}

	public static void main(String[] args) {
		Map<String, Order> map = new HashMap<String, Main.Order>();
		for (Order order : Order.values()) {
			map.put(order.name(), order);
		}
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int size = in.nextInt();
			if (size == 0) {
				break;
			}
			int[] dice = { 1, 2, 3 };
			int count = 1;
			for (int i = 0; i < size; i++) {
				map.get(in.next()).rool(dice);
				count += dice[0];
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
n = gets.to_i
cards = gets.split(' ').map(&:to_i)
count = 1
alice = []
bob = []

cards.sort!.reverse!

until cards.empty?
	if count.odd?
		alice << cards.shift
	else
		bob << cards.shift
	end
	count += 1
end

ans = 0
ans = alice.inject(:+) - bob.inject(:+)

puts ans.abs

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1000006;
const ll MOD = 1000000007;

ll k, a[100];
/*********************GoodLuck***********************/
int main () {
    IOS();

    while (cin >> k) {
        ll n = 50;
        cout << n << endl;
        REP (i, n) {
            if (i < k % n) {
                a[i] = k/n + n - 1 + n - k % n + 1;
                cout << a[i] << " \n"[i==n-1];
            } else {
                a[i] = k/n + n - 1 - (k % n);
                cout << a[i] << " \n"[i==n-1];
            }
        }


#ifdef tmd
        ll ans= 0;
        while (true) {
            ll mx = 0;
            REP (i, n) {
                if (a[i] >= a[mx]) {
                    mx = i;
                }
            }
            if (a[mx] < n) {
                break;
            }
            ans++;
            a[mx] -= n;
            REP (i, n) {
                if (i != mx) {
                    a[i] += 1;
                }
            }

        }
        cout << ans << endl;
#endif

    }
    return 0;
}


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

using namespace std;

int CountOfJOI[3];
const string target = "JOI";

int main() {
	int len, curPos, k;
	string input;

	k = 0;
	cin >> input;
	len = input.size();
	curPos = 0;
	while (curPos < len) {
		if (input[curPos] != 'J') {
			++curPos;
			continue;
		}
		memset(CountOfJOI, 0, sizeof(CountOfJOI));
		for (int i = 0; i < 3; ++i) {
			while (curPos < len && input[curPos] == target[i]) {
				++curPos;
				++CountOfJOI[i];
			}
		}
		if (CountOfJOI[1] <= CountOfJOI[0] && CountOfJOI[1] <= CountOfJOI[2]) {
			k = max(k, CountOfJOI[1]);
		}
	}
	cout << k << endl;

	return 0;
}


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

int main() {
  int A,B,C,D,E,K;
 cin >> A;
 cin >>B;
  cin >>C;
  cin >>D;
  cin >>E;
  cin >>K;
	if(E-A < K+1){
    cout << "Yay!" << endl;
    }
  else{
  cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]


flag = True
count=0
while(flag):
    for i in range(N):
        if A[i]%2 == 1 :
            flag=False
            break
        else:
            A[i] /= 2
    if flag:
        count += 1

print(count)

Measured memory_bytes: 3060
/*
AizuOnline A0096
Title Sum of 4 Integers II
*/
#include <stdio.h>
#define min(x,y) (((x)<(y))?(x):(y))

int sum;
long long p(int s,int n)
{
  int i;
  long long sum;

  if(n==1)
    {
      if(s <= 1000)
	return(1);
      else
	return(0);
    }
  if(s==0)
    return(1);
  if(n==3 && s<=1000)
    return((s+1)*(s+2)/2);
  if(n==2)
    {
      if(s <= 1000)
	return(s+1);
      else if(s <= 2000)
	return(2001-s);
      else
	return(0);
    }
  sum=0;
  for(i=0;i<=min(s,1000);i++)
    sum += p(s-i,n-1);
  return(sum);
}
//
main()
{
  int n;

  while(EOF!=scanf("%d",&n))
    {
      printf("%lld\n",p(n,4));
    }
return(0);
}

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

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    // ランクの大きい方に併合
    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

LL N, M;
vector<pair<LL, LL>> AB;

void input()
{
  cin >> N >> M;
  AB.resize(M);
  REP(i, M)
  {
    cin >> AB[i].first >> AB[i].second;
  }
}

void solve()
{
  // 橋がすべて崩落している状況から逆に考えてゆく（グラフ問題では枝の削除は難しいため）
  UnionFind<LL> tree(N);
  vector<LL> ans(M, 0);
  ans[M-1] = combination(N, 2); //すべての頂点の組み合わせ

  // 今回は崩落前の評価をしなくて良いため、2番めの橋を復元したときまで考えればいい。
  INV_REP(i, M-2)
  {
    // i+1で2番めの橋を復元したときまで
    LL indexA = AB[i+1].first-1;
    LL indexB = AB[i+1].second-1;
//    cout << indexA << ", " << indexB << endl;
    if(tree.same(indexA, indexB))
    {
      ans[i] = ans[i+1];
    }
    else
    {
      // 2 * 2
      ans[i] = ans[i+1] - tree.getSize(indexA) * tree.getSize(indexB);

      tree.unite(indexA, indexB);
    }
  }

  REP(i, M)
  {
    cout << ans[i] << "\n";
  }
}

int main()
{
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 6016
from collections import Counter

S=input()
freq=sorted(list(dict(Counter(S)).items()),key=lambda w:w[1])
length={chr(ord('a')+i):0 for i in range(26)}
while len(freq)>1:
    minimum1=freq.pop(0)
    minimum2=freq.pop(0)
    for c in minimum1[0]+minimum2[0]:
        length[c]=length[c]+1
    freq.append((minimum1[0]+minimum2[0],minimum1[1]+minimum2[1]))
    freq=sorted(freq,key=lambda w:w[1])

retval=0
for s in S:
    retval+=max(length[s],1)
print(retval)



Measured memory_bytes: 6168
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
typedef long long ll;
typedef double D;
typedef vector<ll> VL;
typedef set<ll> SL;
ll M= 1e9+7;	

void solve()
{
	ll a; cin>>a;cout<<(a+ a*a + a*a*a)<<endl;
}

int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--)
    {
	    solve();
    }
    
    return 0;
}




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

using namespace std;

using int64 = long long;

int main() {
  int N;
  int S[5] = {};
  string X = "MARCH";
  cin >> N;
  for(int i = 0; i < N; i++) {
    string x;
    cin >> x;
    auto p = X.find(x[0]);
    if(p == string::npos) continue;
    S[p]++;
  }
  int64 sum = 0;
  for(int i = 0; i < 5; i++) {
    for(int j = i + 1; j < 5; j++) {
      for(int k = j + 1; k < 5; k++) {
        sum += 1LL * S[i] * S[j] * S[k];
      }
    }
  }
  cout << sum << endl;
}


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

using namespace std;

#define int long long
#define F first
#define S second
#define mpr make_pair
#define pii pair<int,int>

typedef long long ll;
const int maxn = 1e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;

int n, s;
int cnt[maxn], a[maxn], dp[maxn];

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

    cin>> n;
    for(int i = 1, u, v, w; i < n; i++)
    {
        cin>> u >> v >> w; u++; v++;
        (a[v] ^= w);
        (a[u] ^= w);
    }

    for(int v = 1; v <= n; v++) cnt[a[v]]++;
    int ans = 0;
    for(int i = 0; i < 16; i++)
    {
        if(i == 0) ans += cnt[i];
        else ans += cnt[i]/2;
        (cnt[i] &= 1);
        cnt[0] = 0;
    }

    /// dp = maximum tedad daste
    for(int msk = 0; msk < (1<<16); msk++)
    {
        dp[msk] = -inf;
        int X = 0, id, is = 0;
        for(int i = 0; i < 16; i++)
            if((1<<i) & msk)
            {
                if(cnt[i]&1) (X ^= i);
                if(cnt[i]) is = 1;
                id = i;
            }

        if(X == 0 && msk > 0)
        {
            if(!is)
            {
                dp[msk] = 0;
                continue;
            }

            if(__builtin_popcount(msk) == 1)
            {
                dp[msk] = cnt[id]/2;
                if(id == 0) dp[msk] = cnt[id];
            }
            else
            {
                dp[msk] = 1;
                for(int s = ((msk-1)&msk); s; s = ((s-1)&msk))
                    dp[msk] = max(dp[msk], dp[s] + dp[msk^s]);
            }
        }
    }

    int msk = (1<<16)-1;
    cout<< n-(dp[msk]+ans);
}

/*
2
T 30
W 1
3
T 1
W 1
T 1
*/


Measured memory_bytes: 4928
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, m, v, p;
        cin>>n>>m>>v>>p;
        vl vec(n);
        rep(i, n)   cin>>vec[i];
        sort(all(vec));
        vl pref(n);
        ll cur = 0;
        rep(i, n){
            cur += vec[i];
            pref[i] = cur;
        }
        ll ans = 0;
        rep(i, n){
            ll nv = v;
            nv -= (i+1);
            bool poss = false;
            ll j = upper_bound(all(vec), vec[i] + m) - vec.begin();
            if(n - j >= p)  continue;
            else{
                nv -= (n - j);
                if(v <= 0)  {ans++;poss = true;}
                else{
                    ll np = p - (n - j) - 1;
                    if(j - i - 1 <= np) ans++;
                    else{
                        nv -= np;
                        ll del = (j - np - 1 - i)*(vec[i] + m) - (pref[j-np-1] - pref[i]);
                        if(del >= nv*m) ans++;
                    }
                }
            }
        }
        cout<<ans;
    }
}

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

typedef long long LL;

const int N = 2e5 + 10;
int n;
char s[N];

int main(){
    while(~scanf("%s", s)){
        LL ans = 0;
        n = strlen(s);
        int cnt = 0;
        for(int i=n-1; i>=0; i--){
            if(s[i] == 'B'){
                ans += cnt;
            } else {
                cnt++;
            }
        }
        printf("%lld\n", ans);
    }
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
 
 
 
int main() {
    long long int N, A, B;
    cin >> N >> A >> B;
 
    long long int count1 = N/(A+B);
    long long int count2 = N%(A+B);
    long long int blue = 0;
 
    blue += count1*A;
    if (A <= N%(A+B)) blue += A;
    else blue += N%(A+B);
 
 
 
    cout << blue << endl;
 
    return 0;
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;


int main(){
    int N,K;
    cin >> N >> K;
    N -= K;
    int cnt = 1;
    while(N > 0){
        N -= (K - 1);
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;



signed main(void) {
  int n; cin >> n;
  ll minZ = INFL, maxZ = -INFL, minW = INFL, maxW = -INFL;
  rep(i,n) {
    ll x, y; cin >> x >> y;
    chmin(minZ,x+y);
    chmax(maxZ,x+y);
    chmin(minW,x-y);
    chmax(maxW,x-y);
  }
  pl(max(maxZ-minZ, maxW - minW))
  return 0;
}


Measured memory_bytes: 3652
(defn input []
  (list
    (Integer/parseInt (read-line))
    (read-line)))

(defn CutAndCount [[N S]]
  (->> (range 1 N)
    (map #(split-at % S))
    (map #(map distinct %))
    (map #(map (partial apply str) %))
    (map (fn [x] (map #(clojure.string/includes? (rest x) (str %)) (first x))))
    (map #(filter identity %))
    (map count)
    (apply max)))

(-> (input)
  CutAndCount
  println)

Measured memory_bytes: 70732
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
using Int = long long;
vector<int> doit(const vector<int> &A)
{
    int N = A.size();
    vector<int> B(N);
    for (int i = 0; i < N/2; i++) {
        B[N/2-1-i] = A[i];
        B[N/2+i] = A[N-1-i];
        if (i % 2) swap(B[N/2-1-i], B[N/2+i]);
    }
    if (N % 2 == 1) B[N-1] = A[N/2];
    return B;
}
Int sumdiff(const vector<int> &A) 
{
    Int diff = 0;
    for (int i = 0; i < A.size()-1; i++) {
        diff += abs((Int)A[i+1] - A[i]);
    }
    return diff;
}
void print(const vector<int> &A)
{
    for (int i = 0; i < A.size(); i++) cout << A[i] << ' ';
    cout << endl;
}
int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<int> B = doit(A);
    Int b = sumdiff(B);
    sort(A.rbegin(), A.rend());
    vector<int> C = doit(A);
    Int c = sumdiff(C);
    cout << max(b, c) << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <set>
#include <cmath>
using namespace std;

int main(){
  int n;

  while(cin >> n ,n){
    int num;
    set<int> s[2];

    for(int i = 0 ; i < n ; i++){
      cin >> num;
      s[0].insert(num);
    }

    for(int i = 1 ; i <= 2*n ; i++){
      if(s[0].find(i) == s[0].end()){
	s[1].insert(i);
      }
    }


    bool turn = false;
    int field = 0;

    while(true){
      if(s[0].size() == 0 || s[1].size() == 0){
	break;
      }

      set<int>::iterator it;
      for(it = s[turn].begin() ; it != s[turn].end() ; it++){
	if(field < *it){
	  s[turn].erase(it);
	  field = *it;
	  turn = abs(1-turn);
	  break;
	}
      }     

      if(it == s[turn].end()){
	field = 0;
	turn = abs(1-turn);
      } 
    }

    cout << s[1].size() << endl;
    cout << s[0].size() << endl;
  }

  return 0;
}

Measured memory_bytes: 1200