akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ALL(a) (a).begin(),(a).end()

ll a, b, x;
ll f(ll n) {
	if (n == -1)return 0;
	return n / x + 1;
}

int main(void) {
	cin >> a >> b >> x;
	cout << f(b) - f(a - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int A, B; cin >> A >> B;
    cout << (((A % 3 == 0) || (B % 3 == 0) || ((A+B) % 3 == 0)) ? "Possible" : "Impossible") << endl;
    return 0;
}

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

using namespace std;

struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};

int main()
{
  int N, M, S, P[100], T[100], K[100];
  bool mine[100];

  while(scanf("%d %d %d", &N, &M, &S), N) {
    for(int i = 0; i < N; i++) {
      scanf("%d %d %d", &P[i], &T[i], &K[i]);
    }
    StronglyConnectedComponents g(N);
    memset(mine, false, sizeof(mine));
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      g.add_edge(--x, --y);
      if(x == y) mine[x] = true;
    }

    vector< vector< int > > dag;
    g.build(dag);
    vector< vector< int > > component(dag.size());
    for(int i = 0; i < N; i++) component[g[i]].push_back(i);

    int dp[101][10001] = {{}};
    int deq[10001], deqv[10001];
    int ret = 0;

    for(int i = 0; i < dag.size(); i++) {
      if(component[i].size() == 1 && !mine[component[i][0]]) {
        int now = component[i][0];
        for(int k = S; k >= T[now]; k--) {
          dp[i][k] = max(dp[i][k], dp[i][k - T[now]] + P[now]);
        }
      } else {
        for(int j : component[i]) {
          for(int k = 0; k < T[j]; k++) {
            int s = 0, t = 0;
            for(int l = 0; l * T[j] + k <= S; l++) {
              int val = dp[i][l * T[j] + k] - l * P[j];
              while(s < t && deqv[t - 1] <= val) --t;
              deq[t] = l;
              deqv[t++] = val;
              dp[i][l * T[j] + k] = deqv[s] + l * P[j];
              if(deq[s] == l - K[j]) ++s;
            }
          }
        }
      }
      for(int k = 0; k <= S; k++) {
        ret = max(ret, dp[i][k]);
        for(int j : dag[i]) dp[j][k] = max(dp[j][k], dp[i][k]);
      }
    }

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

Measured memory_bytes: 7356
#-*- coding: utf-8 -*-
import math
a,b,h,m = map(float,input().split())
s = abs((0.5*m + 30*h) - 6*m)
if s > 180:
  s = 360 - s

y = s * (math.pi / 180)
x = math.sqrt(a*a+b*b-2*a*b*math.cos(y))
print(x)

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

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int main(){
    int w,h;
    while(cin>>w>>h){
        if(w==0&&h==0)break;
        int data[20][20];
        rep(i,h){
            rep(j,w){
                cin>>data[i][j];
            }
        }
        int dp[20][20];
        rep(i,20)rep(j,20)dp[i][j]=0;
        rep(i,w){
            if(data[0][i]==0){
                dp[0][i]=1;
            }
        }
        
        for(int i=0;i<h-1;i++){
            for(int j=0;j<w;j++){
                if(j-1>=0 && data[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
                if(data[i+1][j]==0)dp[i+1][j]+=dp[i][j];
                if(data[i+1][j]==2){
                    int c=1;
                    while(data[i+1+2*c][j]==2)c++;
                    if(i+1+c*2<=h-1&&data[i+1+c*2][j]==0){
                        dp[i+1+c*2][j]+=dp[i][j];
                    }
                    else if(i+1+c*2>h-1){
                        dp[h-1][j]+=dp[i][j];
                    }
                }
                if(j+1<w && data[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
            }
        }
        int ans=0;
        rep(i,w){
            ans+=dp[h-1][i];
        }
        cout<<ans<<endl;
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	LL K; cin >> K;
	LL ans = 0;
	FOR(b, 1, N + 1) {
		// [1..N] mod b >=K
		// [0..b-1][b..2b-1]...[(m-1)b...mb-1][mb mb+(N%b)]
		LL block=0;
		if ((N + 1) / b && b - K > 0) {
			block = (N + 1) / b * (b - K);
		}

		LL modulo = 0;
		if ((N + 1) % b) {
			modulo += max(0LL,N % b - K+1);
		}
		ans += block + modulo;
	}
	if (K == 0)ans -= N;



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 	string s;cin>>s;
  	bool check = false;
    for(int i=0;i<s.size()-1;++i)
    {
     	if(s[i]==s[i+1])
           check = true;
    }
    
           if(check)cout<<"Bad";
           else cout<<"Good";
  
  
  
}


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

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

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

	vector<int> higher(N, 1);
	for (int i = 0; i < M; ++i) {
		int A, B;
		cin >> A >> B;
		A--;
		B--;

		if (H[A] >= H[B]) {
			higher[B] = 0;
		}
 
		if (H[B] >= H[A]) {
			higher[A] = 0;
		}
	}

	cout << accumulate(higher.begin(), higher.end(), 0) << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define SE second
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define ll long long
#define LLI long long int
#define REP(i,a,b) for(long long i=a;i<b;i++)
#define PER(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define Arrays(a, size) sort((a), (a)+(size))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
using namespace std;

int _dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int _dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

ll a[100001];
//vector<int> a;
ll n,m;
int main(){
    cin>>n>>m;
    if(n>=13){
        cout<<m<<endl;
    }else if(n<=5){
        cout<<0<<endl;
    }else{
        cout<<m/2<<endl;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
using namespace std;
signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	long long a[53];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 0;
	sort(a, a + n, greater<int>());
	if (a[0] > 2 * n) {
		for (int i = 1; i < n; i++) {
			long long cnt = (a[0] - a[i]) / (n + 1);
			for (int j = 0; j < i; j++) {
				a[j] -= cnt*(n - (i - 1));
			}
			for (int j = i; j<n; j++) {
				a[j] += cnt*i;
			}
			ans += cnt*i;
		}
	}
	sort(a, a + n, greater<long long>());
	while (a[0] - a[n - 1]>n) {
		a[0] -= n;
		for (int i = 1; i < n; i++) {
			a[i] += 1;
		}
		ans += 1;
		sort(a, a + n, greater<long long>());
	}
	if (a[n - 1] > n - 1) {
		ans += (a[n - 1] - (n - 1))*n;
		long long tmp = a[n - 1] - (n - 1);
		for (int i = 0; i < n; i++) {
			a[i] -= tmp;
		}
	}
	while (a[0] > n - 1) {
		a[0] -= n;
		for (int i = 1; i < n; i++) {
			a[i] += 1;
		}
		ans += 1;
		sort(a, a + n, greater<long long>());
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Scanner;

/* static int java.util.Arrays.binarySearch(int[] a, int key); */


public class Main {
    Scanner sc = new Scanner(System.in);
    int n;
    int a[];
    public void run(){
        n = sc.nextInt();
        a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        solve();
    }
    public void solve(){
        int ans = 0;
        for(int i = 0; i < n; i++) {
            ans += a[i] - 1;
        }

        System.out.println(ans);
    }

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

    static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
    static class Edge{
        int to, cost;
        public Edge(int a, int b){
            this.to = a;
            this.cost = b;
        }
    }
    class MyComparator implements Comparator {
        @Override
        public int compare (Object arg0, Object arg1) {
            int x = ((Pair)arg0).first;
            int y = ((Pair)arg1).first;

            if (x < y) {
                return 1;
            } else if (x > y) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class UnionFind{
        int par[];
        int rank[];

        //n要素で初期化
        public UnionFind(int maxn){
            par = new int[maxn];
            rank = new int[maxn];

            for(int i = 0; i < maxn; i++){
                par[i] = i;
                rank[i] = 0;
            }
        }

        //木の根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }
            else {
                return par[x] = find(par[x]);
            }
        }

        // xとyの属する集合を併合
        void unite (int x, int y){
            x = find(x);
            y = find(y);
            if(x == y){
                return;
            }

            if(rank[x] < rank[y]){
                par[x] = y;
            }
            else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        // xとyが同じ集合に属するか否か
        boolean same(int x, int y){
            return find(x) == find(y);
        }
    }

}

Measured memory_bytes: 26024
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100
int c[MAXN+5];
int main(){
    int n,t,cnt=0;
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(b>t) continue;
        c[++cnt]=a;
    }
    if(cnt==0){
        printf("TLE");
        return 0;
    }
    sort(c+1,c+cnt+1);
    printf("%d",c[1]);
    return 0;
}


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

using namespace std;

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

template <class T>
inline T iceil(T a, T b) {
    return (a + b - 1) / b;
}

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

    if (K == 1) {
        cout << 1 << endl;
        cout << 1 << endl;
        return 0;
    }

    int N = iceil(K, 4) * 2;
    auto ans = Vec<int>(N, N, 0);
    for (int x = 0; x < N; ++x) {
        for (int y = 0; y < N; ++y) {
            ans[x][y] = (x + y) % N + x % 2 * N;
        }
    }

    int del = N * 2 - K;
    for (auto& v : ans) {
        for (auto& e : v) {
            if (e >= N * 2 - del) e -= N;
        }
    }

    cout << N << endl;
    for (auto& v : ans) {
        for (auto& e : v) {
            cout << e + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<ll> a(N), b(N), c(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> c[i];
	}

	sort(begin(a), end(a));
	sort(begin(b), end(b));
	sort(begin(c), end(c));

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (upper_bound(begin(a), end(a), b[i] - 1) - begin(a)) * (end(c) - upper_bound(begin(c), end(c), b[i]));
	}

	cout << ans << endl;
}

Measured memory_bytes: 2560
//author Eterna
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define maxn 1000
#define eps 1e-15
#define MOD ((int)(1e9+7))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x&-x)
#define mid (L+R)/2
#define Lson (index*2)
#define Rson (index*2+1)
using namespace std;
typedef long long ll;
inline int read() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
int n, m, arr[maxn + 5];
int main(void) 
{
	while (cin >> n >> m && (m&&n)) {
		bool flag = false;
		int ans = 0;
		for (int i = 1; i <= n; i++)arr[i] = read();
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++) {
				int sum = arr[i] + arr[j];
				if (sum > ans&&sum <= m) {
					flag = true;
					ans = sum;
				}
			}
		if (flag)cout << ans << endl;
		else cout << "NONE" << endl;
	}
	//system("pause");
	return 0;
}



Measured memory_bytes: 3108
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,m = i_map()
    if n == 1 or m == 1:
        print(abs(n*m - 2))
        exit()

    t = n*2 + (m-2)*2
    print(n*m - t)

if __name__=="__main__":
    main()


Measured memory_bytes: 67396
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

db p[6] , q[6];

int main(){
  rep(i,0,6) cin >> p[i] , p[i] /= 100;
  rep(i,0,6) cin >> q[i] , q[i] /= 100;
  auto get = [&](db x) {
    db res = 0;
    rep(i,0,6) res += max(x * p[i] , (1 - x) * q[i]);
    return res;
  };
  db l = 0 , r = 1;
  rep(i,0,200) {
    db m1 = (2 * l + r) / 3;
    db m2 = (l + r * 2) / 3;
    if(get(m1) < get(m2))
      r = m2;
    else
      l = m1;
  }
  printf("%.12f\n",get((l + r) / 2));
  return 0;
}


Measured memory_bytes: 256
def toi(a)
	b = []
	a.each do |n|
		b << n.to_i
	end
	b	
end
a=toi(gets().split)
i = 0
x = a[0]
y = a[1]
z = a[2]
while x <= y
	if z.modulo(x) == 0
		i += 1
	end
	x +=1
end

puts i

Measured memory_bytes: 8628
//
//  main.cpp
//  Making Triangle
//
//  Created by Parsa Alimohammadi on 5/31/1399 AP.
//  Copyright © 1399 Parsa Alimohammadi. All rights reserved.
//

#include <iostream>
#include <algorithm>

using namespace std;

int n,l[101],ans;

int main()
{
    cin >> n;
    
    for (int i=0; i<n; i++)
        cin >> l[i];
        
    for (int i=0; i<n; i++)
    {
        for (int j=i+1; j<n; j++)
        {
            for (int jj=j+1; jj<n; jj++)
            {
                if (l[j]==l[i] || l[j] == l[jj] || l[i] == l[jj])
                    continue;
                if (l[i]+l[j] > l[jj] && l[j]+l[jj] > l[i] && l[i] + l[jj] > l[j])
                    ans++;

            }
            
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3588
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

const int maxn = 5005;

vector<int> G[maxn];
vector<int> e[maxn];
int n;
int size[maxn];

int dp[maxn][maxn];
int g[maxn];
const int mod = 1e9 + 7;

void init(){
    g[0] = 1;
    for(int i = 1;i < maxn;i++){
        if(i & 1){
            g[i] = 0;
        }else{
            g[i] = 1LL * g[i - 2] * (i - 1) % mod;
        }
    }
}

void add(int &a, int b){
    a += b;
    if(a >= mod){
        a -= mod;
    }
}

void Dp(int u, int fa){
    dp[u][0] = 0;
    dp[u][1] = 1; 
    size[u] = 1;
    for(auto v : G[u]){
        if(v == fa)
            continue;
        Dp(v, u);
        for(int k = size[u] + size[v];k >= 0;k--){
            int tmp = 0;
            for(int i = max(0, k - size[u]);i <= min(k, size[v]);i++){
                add(tmp, 1LL * dp[v][i] * dp[u][k - i] % mod);
            }
            dp[u][k] = tmp;
        }
        size[u] += size[v];
    }
    for(int i = 1;i <= size[u];i++){
        //cout << u << " " << i << " " << dp[u][i] << endl;
        add(dp[u][0], 1LL * g[i] * (mod - 1) % mod * dp[u][i] % mod);
    }
    //cout << u << " " << 0 << " " << dp[u][0] << endl;
}

int main(){
    init();
    cin >> n;
    for(int i = 1;i < n;i++){
        int u, v;
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    Dp(1, 0);
    cout << (mod - dp[1][0]) % mod << endl;
    return 0;
}


Measured memory_bytes: 97536
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int n,tot;
int a[505*505],b[505],cnt[505],x[505];
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[x[i]=read()]=i;
	for(int i=1;i<=n*n;i++) if(a[i]) b[++tot]=a[i];
	for(int i=1;i<=n;i++) cnt[i]=i-1;
	for(int i=1;i<=n*n;i++)if(!a[i])for(int j=1;j<=n;j++)if(cnt[b[j]]){a[i]=b[j];cnt[b[j]]--;break;}
	for(int i=1;i<=n;i++) cnt[i]=n-i;
	for(int i=n*n;i>=1;i--)if(!a[i])for(int j=n;j>=1;j--)if(cnt[b[j]]){a[i]=b[j];cnt[b[j]]--;break;}
	bool flag=1;
	for(int i=1,num=0,j;i<=n;i++,num=0)
	{
		for(j=1;j<=n*n;j++) if(a[j]==i){num++;if(num==i) break;}
		if(j!=x[i]){flag=0;break;}
	}
	puts(flag?"Yes":"No");
	if(flag) for(int i=1;i<=n*n;i++) printf("%d ",a[i]);
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	if(a[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	ll ans = 0;
	rep(i, n-1){
		if(a[i+1] > a[i] + 1){
			cout << -1 << endl;
			return 0;
		}

		if(a[i+1] == 0) continue;

		if(a[i+1] == a[i] + 1){
			ans++;
		}else{
			ans += a[i+1];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAXN 100100
#define int long long
#define M 1000000007
using namespace std;
int dp[MAXN][2];
int pai[MAXN];
vector<int> vizinhos[MAXN];

inline int mod(int a,int m){
	int r = a%m;
	if(r<0)r+=m;
	return r;
}

void DFS(int x,int p){
	for(int i=0;i<vizinhos[x].size();i++){
		int u = vizinhos[x][i];
		if(u==p)continue;
		pai[u]=x;
		DFS(u,x);
	}
}

int solve(int id,int paiP){
	if(dp[id][paiP]!=-1)return dp[id][paiP];
	int caso1=1;//pai foi pintado
	int caso2=1;
	int flag = true;
	
	for(int i=0;i<vizinhos[id].size();i++){
		
		int u = vizinhos[id][i];
		
		if(u==pai[id])continue;
		flag = false;
		caso1=mod(caso1*solve(u,0),M);   	
		caso2=mod(caso2*solve(u,1),M);   	
	}	
		 			  		  
	if(paiP==1){
		return dp[id][paiP]=mod(caso1,M);
	}
	return dp[id][paiP]=mod(caso1+caso2,M);	
}



int32_t main(){
	int n;
	cin>>n;
	int x,y;
	memset(dp,-1,sizeof(dp));
	
	for(int i=1;i<n;i++){
		cin>>x>>y;
		vizinhos[x].push_back(y);
		vizinhos[y].push_back(x);
	}
	
	pai[1]=-1;
	DFS(1,-1);
	cout<<solve(1,0)<<endl;		
}

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

int main(){
    int N; cin >> N;
    vector<string> s(N);
    vector<int> t(N); for(int i = 0; i < N; ++i) cin >> s[i] >> t[i];
    string X; cin >> X;

    bool flag = false;
    int res = 0;

    for(int i = 0; i < N; ++i) {
        if(X == s[i]) {
            flag = true;
            continue;
        }

        if(flag == true) {
            res += t[i];
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[300005];
int n,i,cati;
long long sum;
int main()
{
    cin>>n;
    for(i=1;i<=3*n;i++)
        cin>>a[i];
    sort(a+1,a+3*n+1);
    for(i=3*n-1;i>=0,cati<n;i-=2)
        sum+=1LL*a[i],cati++;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

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

    int N, X;
    cin >> N >> X;

    vector<int> L;

    for (int i = 0; i < N; i++)
    {
        int Li;
        cin >> Li;
        L.push_back(Li);
    }

    int c = 0;
    int sum = 0;
    
    for (int i = 0; i < N; i++)
    {
        if (sum >= X)
        {
            break;
        }
        else
        {
            sum += L[i];
            c++;
        }
    }

    if (sum <= X)
    {
        cout << c + 1 << endl;
    }
    else
    {
        cout << c << endl;
    }
    
}

Measured memory_bytes: 256
datas = gets.split(" ").map{|nn|nn.to_i}
n = datas[0]
m = datas[1]
datas = gets.split(" ").map{|nn|nn.to_i}
if n >= m
  puts "0"
else
datas.sort!{|a,b|a<=>b}

kukan = datas[-1] - datas[0]

#n-1個の空白区間を探す
emps = []
i = 1
while(i < datas.length)
  emps << datas[i] - datas[i-1]
  i += 1
end

emps.sort!.reverse!
(n-1).times do|nn|
  kukan -= emps[nn]
end
puts kukan.to_s
end

Measured memory_bytes: 9976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int A[] = new int[N];
		for(int i = 0;i < N;i++) {
			A[i] = sc.nextInt();
		}
		boolean b = true;
		int count = 0;
		int countmax = 0;

		while(b) {
			count = 0;
			for(int i = 0;i < N;i++) {
				if(A[i] % 2 == 0) {
					count++;
				}
			}
			if(count == A.length) {
				for(int i = 0;i < N;i++) {
					A[i] = A[i]/2;
				}
				countmax++;

			}else{
				b = false;
			}
		}
		System.out.println(countmax);

//		Arrays.sort(S);
//		int count = 0;
//		for(int i = 1;i < S.length;i++) {
//			if(S[i] == S[i-1])continue;
//			count++;
//		}
//		System.out.println(count);
	}
}


Measured memory_bytes: 23252
/*
    CCBESTGIRL
*/

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    queue<ll> q;
    for(int i = 1 ; i<=9 ; i++){
        q.emplace(i);
    }
    ll x;
    while(n--){
        x = q.front();
        q.pop();
        if(x%10!=0){
            q.emplace(10 * x + x%10 -1);
        }
        q.emplace(10*x + x%10);
        if(x%10!=9){
            q.emplace(10 *x + x%10 + 1);
        }
    }
    cout<<x;

    return 0;
}


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

int main() {
    string S;
    long long ans = 0, res;
    cin >> S;

    for (int i = 0; i < (1 << (S.size() - 1)); ++i) {
        res = S[0] - '0';
        for (int j = 0; j < S.size() - 1; ++j) {
            if (i & (1 << j)) {
                ans += res;
                res = 0;
            }
            res = res * 10 + (S[j + 1] - '0');
        }
        ans += res;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
while True:
    height, width = map(int, input().split())
    if height == 0 and width == 0:
        break
    for h in range(height):
        for w in range(width):
            if (h + w) % 2 == 0:
                print("#", end="")
            elif (h + w) % 2 == 1:
                print(".", end="")
        print("")
    print("")
    


Measured memory_bytes: 7012
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

struct Node {
    string s;
    int score, pos;
    Node() {}
    Node(string a, int b, int c) {
        s = a; score = b; pos = c;
    }
    bool operator<(const Node &rhs)const {
        if (s != rhs.s) return s < rhs.s;
        else return score > rhs.score;
    }
};

vector<Node>v;

int main() {
    int n; cin >> n;
    rep1(i, 1, n) {
        string s; int p; cin >> s >> p;
        v.pb(s, p, i);
    }
    sort(v.begin(), v.end());
    for (auto i : v) cout << i.pos << endl;
    return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500 * i + 100 * j + 50 * k) == X:
                ans += 1
                
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rp(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int dice[7],cdice[7];
	lp(i,1,7){
		cin>>dice[i];
		cdice[i]=dice[i];
	}
	int n,x,y;
	cin>>n;
	rp(i,n){
		cin>>x>>y;
		lp(j,1,7){
			dice[j]=cdice[j];
		}
		int f=0;
		while(1){
			if((dice[2]==x||dice[5]==x)&&(dice[1]==y||dice[6]==y)){
				int a=dice[1],b=dice[2],c=dice[3],d=dice[4],e=dice[5],f=dice[6];
			dice[1]=a;
			dice[2]=d;
			dice[3]=b;
			dice[4]=e;
			dice[5]=c;
			dice[6]=f;
			}
			
			if(dice[1]==x&&dice[2]==y)break;
		while(1){
			if(dice[1]==x||dice[2]==x||dice[5]==x)break;
			int a=dice[1],b=dice[2],c=dice[3],d=dice[4],e=dice[5],f=dice[6];
			dice[1]=d;
			dice[2]=b;
			dice[3]=a;
			dice[4]=f;
			dice[5]=e;
			dice[6]=c;
			//cout<<1<<endl;
			}
		while(1){
			if(dice[2]==y)break;
			int a=dice[1],b=dice[2],c=dice[3],d=dice[4],e=dice[5],f=dice[6];
			dice[1]=a;
			dice[2]=d;
			dice[3]=b;
			dice[4]=e;
			dice[5]=c;
			dice[6]=f;
			//cout<<1<<endl;
			}
		}
		cout<<dice[3]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

inline void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

inline void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

inline void coutPrecision(ld ans){
    cout << fixed << setprecision(20) << ans << endl;
}

inline bool isKaibun(string s){
    rep(i, s.size() / 2){
        if(s[i] != s[s.size()-1 -i]){
            return false;
        }
    }
    
    return true;
}

int main(){
    ld a, b;
    cin >> a >> b;
    
    ll result = a* b;
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 3744
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;

	writeln(max(0, C - (A - B)));
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
High=[int(x) for x in input().split()]
D=[]
for i in range(N):
	D.append(T-int(High[i])*0.006-A)
	if D[i]<=0:
		D[i]=-D[i]
	
for i in range(N):
	if D[i]==min(D):
		print(i+1)
	

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

#define int long long

using namespace std;

const int maxn = 5005;
int succ[maxn];
int val[maxn];
int n, k;

int go(int u) {
    //cout << "go at " << u << '\n';
    bool vis[maxn];
    for (int i = 0; i <= n; i++) vis[i] = false;
    int taken = 0;
    int sum = 0;
    int res = -1e9;
    while (!vis[u] && taken < k) {
        vis[u] = true;
        sum += val[u];
        //cout << "add " << u << '\n';
        res = max(res, sum);
        taken++;
        u = succ[u];
    }
    int start = u;
    bool flag = false;
    int cycle = 0;
    int len = 0;
    while ((u != start || !flag)) {
        cycle += val[u];
        res = max(res, sum);
        //cout << "cycle " << u << '\n';
        flag = true;
        len++;
        u = succ[u];
    }
    int rem = k-taken;
    int full = max((rem/len)-1,(int)0);
    taken += full*len;
    sum += cycle*full;
    res = max(res, sum);
    //cout << "cycle sum: " << cycle << " length: " << len << " current sum: " << sum  << " res: " << res << '\n';
    u = succ[u];
    while (taken < k) {
        sum += val[u];
        res = max(res, sum);
        taken++;
        u = succ[u];
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> succ[i];
        succ[i]--;
        //cout << i << " " << succ[i] << '\n';
    }
    for (int i = 0; i < n; i++) {
        cin >> val[i];
        //cout << "val of " << i << " is " << val[i] << '\n';
    }
    int res = -1e9;
    for (int i = 0; i < n; i++) {
        //cout << "go " << i << " = " << go(i) << '\n';
        res = max(res, go(i));
    }
    cout << res << '\n';
}
/*

 */

Measured memory_bytes: 3728
a, b, c = map(int, input().split())
 
if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
    print(0)
elif a == b == c:
    print(-1)
else:
    num = 0
    while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0):
        a, b, c = (b+c)/2, (a+c)/2, (a+b)/2
        num += 1
    print(num)

Measured memory_bytes: 9264
N, M = map(int, input().split())
rs = [-1] * (N+1)
rs[0] = 1
rs[1] = 1
for m in range(M):
  am = int(input())
  rs[am] = 0
for n in range(1, N):
  rs[n+1] = 0 if rs[n+1] == 0 else rs[n]+rs[n-1]
#print(rs)
print(rs[N]%1000000007)


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, n;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  int ans = INT_MAX;
  rep(i,n-k+1){
    ans = min(ans, abs(h[i]-h[i+k-1]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    let ans = n * n * n;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = INF;
  for (int k = 0; k <= 2*max(x,y); ++k) {
    int tmp = c*k;
    tmp += a*max(0,x-k/2);
    tmp += b*max(0,y-k/2);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

typedef long long LL;
using namespace std;

string h;

int main()
{
	cin >> h;
	LL ans = 0;
	int cnt = 0;
	for(int i = h.size() - 1; i >= 0; i--) {
		if(h[i] == 'B') {
			ans += h.size() - i - 1 - cnt;
			cnt++;
		}
		
	}
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll d = B - A, res;
    res = min(B - 1, N - A);
    if(d % 2 == 0)
        res = min(res, d / 2);
    else {
        ll nd = N - B;
        ll na = N - A;
        if((nd + na) % 2)
            nd++;
        res = min(res, (nd + na) / 2);
        nd = A - 1;
        ll nb = B - 1;
        if((nd + nb) % 2)
            nd++;
        res = min(res, (nd + nb) / 2);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#define ll long long 
#define rep(n) for(int i=0;i<n;++i)
using namespace std;
int main(void){
    // Your code here!

int n;
cin>>n;
vector<string> vec(n);
rep(n){
    cin>>vec[i];
    sort(vec[i].begin(), vec[i].end());
}

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


ll count=1, ans=0;
for(int i=0;i<n-1;i++){
    if(vec[i]==vec[i+1]){
        count++;
    }else{
        ans+=(count*(count-1))/2;
        count=1;
    }    
}
 ans+=(count*(count-1))/2;
cout<<ans;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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;}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  bool flg = false;
  REP2(i, 1, 10) REP2(j, 1, 10)
  {
    int res = i*j;
    if (n == res)
    {
      flg = true;
      break;
    }
  }
  if (flg) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {


    while (1) {
        int n, x;
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0) {
            break;
        } else {
            int count = 0;

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j < i; j++) {
                    for (int k = 1; k < j; k++) {
                        if (i + j + k == x) {
                            count++;
                        }
                    }
                }
            }
            printf("%d\n", count);
        }
    }

    return 0;
}


Measured memory_bytes: 2104
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(d)]
for i in range(d):
    cand=0
    for j in range(26):
        if s[i][cand]<s[i][j]:
            cand=j
    print(cand+1)

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  string s = (n ? "" : "0");
  while(n) {
    int a = n%(-2);
    n /= -2;
    if(a < 0) a += 2, ++n;
    s += (char)(a+'0');
  }
  reverse(all(s));
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);


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

int n,k,count = 0;
cin >> n >> k;
vi d(k),ans(n,0);

rep(i,k){
  cin >> d[i];
  vi a(d[i]);
  rep(j,d[i]){
    cin >> a[j];
    rep(l,n){
      if(l+1 == a[j]) ans[l]++;
    }
  }
}
rep(l,n){
  if(ans[l] == 0) count++;
}
cout << count << endl;




//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3664