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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() + 2;
        long c = sc.nextLong();

        long[] dists = new long[n];
        long[] values = new long[n];

        long[] clockwise = new long[n];
        long[] counterClockwise = new long[n];

        for (int i = 1; i < n - 1; i++) {
            dists[i] = sc.nextLong();
            values[i] = sc.nextLong();
        }
        dists[n - 1] = c;

        for (int i = 1; i < n; i++) {
            clockwise[i] = clockwise[i - 1] + values[i];
            counterClockwise[i] = counterClockwise[i - 1] + values[(n - 1) - i];
        }

        long[] clockwiseValues = new long[n];
        long[] clockwiseValuesToZero = new long[n];
        long[] counterClockwiseValues = new long[n];
        long[] counterClockwiseValuesToZero = new long[n];
        for (int i = 1; i < n; i++) {
            clockwiseValues[i] = Math.max(clockwiseValues[i - 1], clockwise[i] - dists[i]);
            clockwiseValuesToZero[i] = Math.max(clockwiseValuesToZero[i - 1], clockwise[i] - (dists[i] * 2));

            counterClockwiseValues[i] = Math.max(counterClockwiseValues[i - 1], counterClockwise[i] - (c - dists[(n - 1) - i]));
            counterClockwiseValuesToZero[i] = Math.max(counterClockwiseValuesToZero[i - 1], counterClockwise[i] - (c - dists[(n-1)-i]) * 2);
        }

        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            long tmp = Math.max(
                clockwiseValues[i] + counterClockwiseValuesToZero[(n - 1) - i - 1],
                clockwiseValuesToZero[i] + counterClockwiseValues[(n - 1) - i - 1]
            );
            ans = Math.max(tmp, ans);
        }
        System.out.print(ans);
    }
}


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

struct TopologicalSort {
   vector<int> used, indeg, res;
   vector<set<int>> G;

   TopologicalSort() {}
   TopologicalSort(int n):G(n), used(n, 0), indeg(n, 0) {}

   void add_edge(int s, int t) {
      G[s].emplace(t);
      indeg[t]++;
   }

   void bfs(int s) {
      queue<int> que;
      que.emplace(s);
      used[s] = 1;
      while(!que.empty()) {
         int v = que.front(); que.pop();
         res.emplace_back(v);
         for(int u:G[v]) {
            indeg[u]--;
            if(indeg[u] == 0 && !used[u]) {
               used[u] = 1;
               que.emplace(u);
            }
         }
      }
   }

   vector<int> build() {
      int n = G.size();
      for(int i=0; i<n; ++i) if(indeg[i] == 0 && !used[i]) bfs(i);

      return res;
   }
};

int main() {
   int V, E; cin >> V >> E;
   TopologicalSort tp(V);
   for(int i=0; i<E; ++i) {
      int u, v; cin >> u >> v;
      tp.add_edge(u, v);
   }
   auto res = tp.build();
   for(int i=0; i<V; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 5784
#include <algorithm>
#include <array>
#include <iostream>
#include <tuple>
#include <vector>

using treasure_type = std::tuple<int, int>;

treasure_type maximum(const treasure_type& a, const treasure_type& b) {
  if (std::get<0>(a) == std::get<0>(b)) {
    return treasure_type{std::get<0>(a), std::min(std::get<1>(a), std::get<1>(b))};
  } else if (std::get<0>(a) > std::get<0>(b)) {
    return a;
  } else {
    return b;
  }
}

treasure_type solve(int wmax, const std::vector<treasure_type>& ts) {
  std::array<std::vector<treasure_type>, 2> dp{};
  dp[0].resize(wmax + 1);
  dp[1].resize(wmax + 1);
  for (auto i = 0u; i <= wmax; ++i) {
    dp[0][i] = treasure_type{0, 0};
  }

  for (auto i = 0u; i < ts.size(); ++i) {
    const auto& ti  = ts.at(i);
    const auto& dpp = dp.at(i % 2);
    auto& dpn       = dp.at((i + 1) % 2);
    for (auto j = 0u; j <= wmax; ++j) {
      if (j >= std::get<1>(ti)) {
        const auto& dppi2 = dpp[j - std::get<1>(ti)];

        dpn[j] = maximum(dpp.at(j), treasure_type{std::get<0>(ti) + std::get<0>(dppi2),
                                                  std::get<1>(ti) + std::get<1>(dppi2)});
      } else {
        dpn[j] = dpp.at(j);
      }
    }
  }

  return dp.at(ts.size() % 2).at(wmax);
}

auto main() -> int {
  for (int c = 1;; ++c) {
    int w;
    std::cin >> w;
    if (w == 0) break;

    int n;
    std::cin >> n;
    std::vector<treasure_type> ts{};
    for (int i = 0; i < n; ++i) {
      int vi, wi;
      std::scanf("%d,%d", &vi, &wi);
      ts.push_back(treasure_type{vi, wi});
    }

    const auto ans = solve(w, ts);
    std::cout << "Case " << c << ":\n"
              << std::get<0>(ans) << "\n"
              << std::get<1>(ans) << std::endl;
  }
}

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

using namespace std;

using ll = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  int n, m, j;
  cin >> n >> m;
  int ki = 1, gu;
  if (m%2) {
    gu = m+2;
  } else {
    gu = m+1;
  }
  vector<pair<int, int>> match(m);
  for (int i = 0; i < m; i++) {
    j = m-i;
    if (j%2) {
      match.at(i) = make_pair(ki, ki+j);
      ki++;
    } else {
      match.at(i) = make_pair(gu, gu+j);
      gu++;
    }
  }
  sort(match.begin(), match.end());
  for (int i = 0; i < m; i++) {
    cout << match.at(i).first << " " << match.at(i).second << endl;
  }

  return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    string tmp;
    cin >> tmp;
    vector<ll> s;
    rep(i,tmp.size()) s.push_back( tmp[i] - '0' );

    ll ans = 0;
    rep(i,s.size()) ans += pow(10,i) * s[s.size()-1-i];

    rep(bit,(1<<(s.size()-1)))
    {
        vector<int> S;
        rep(i,s.size()-1)
        {
            if (bit & (1<<i)) S.push_back(i);
        }

        ll old = 0;
        if( S.size() > 1 )
        {
            for (int i = 0; i < (int)S.size(); ++i)
            {
                for( int j = old; j < S[i]+1;j++)
                {
                    ans += pow(10,S[i]+1-j-1) * s[j];
                }
                //cout << S[i] << " " << ans << endl;
                old = S[i]+1;
            }
            for( int j = old; j < s.size(); j++)
            {
                ans += pow(10,s.size()-j-1) * s[j];
            }
            //cout << S[S.size()-1] << " " << ans << endl;
        }
        else
        {
            for (int i = 0; i < (int)S.size(); ++i)
            {
                for( int j = old; j < S[i]+1;j++)
                {
                    ans += pow(10,S[i]+1-j-1) * s[j];
                }
                for( int j = S[i]+1; j < s.size(); j++)
                {
                    ans += pow(10,s.size()-j-1) * s[j];
                }
                //cout << S[i] << " " << ans << endl;
                old = S[i];
            }
        }
        //cout << endl;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 1e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
string s;

void solve(){
    bool flag = true;
    if(s[0]!='A') flag=false;
    int count=0,spot=0;
    for(int i=2;i<=s.size()-2;i++){
        if(s[i]=='C') {
            count++;
            spot=i;
        }
    }
    debug(flag);
    if(count != 1) flag=false;
    debug(spot);
    for(int i=1;i<s.size();i++){
        if(i != spot && ('A' <= s[i] && s[i] <= 'Z')) flag =false;
    }
    debug(flag);
    if(flag) cout << "AC" << "\n";
    else cout <<"WA" <<"\n";
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> s;
    solve();
    
    return 0;
}


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

int main(){
    bool die[31] = {};
    int N;
    for(int i=0;i<28;i++){
        cin>>N; die[N] = true;
    }
    for(int i=1;i<=30;i++){
        if(!die[i]) printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 1148
import sys
sys.setrecursionlimit(1000000)

WALL = 100
w, h = map(int,input().split())
lst = [[WALL] + list(map(int,input().split())) + [WALL] for i in range(h)]
lst.insert(0, [WALL] * (w + 2))
lst.append([WALL] * (w + 2))

visited = [[0] * (w + 2) for _ in range(h + 2)]
hold = []
app = hold.append

def search(x, y):

  if lst[x][y] == WALL:
    visited[x][y] = 3
    return 3

  if lst[x][y] == 1:
    visited[x][y] = 2
    return 2

  visited[x][y] = 1
  app((x, y))

  if not x % 2:
    pairs = [(x - 1, y - 1), (x - 1, y), (x, y - 1), (x, y + 1), (x + 1, y - 1), (x + 1, y)]
  else:
    pairs = [(x - 1, y), (x - 1, y + 1), (x, y - 1), (x, y + 1), (x + 1, y), (x + 1, y + 1)]
  
  ret = 0
  for t in pairs:
    tx, ty = t[0], t[1]
    v = visited[tx][ty]
    a = 0
    if not v:
      a = search(tx, ty)
    elif v == 3:
      a = 3
    elif v == 2:
      a = 2
    if a > ret:
      ret = a
  return ret

def main():

  for x in range(1, h + 1):
    for y in range(1, w + 1):
      if not visited[x][y] and not lst[x][y]:
        stat = search(x, y)
        for point in hold:
          visited[point[0]][point[1]] = stat
        hold.clear()
  
  ans = 0
  for x in range(1, h + 1):
    for y in range(1, w + 1):
      if lst[x][y]:
        if not x % 2:
          pairs = [(x - 1, y - 1), (x - 1, y), (x, y - 1), (x, y + 1), (x + 1, y - 1), (x + 1, y)]
        else:
          pairs = [(x - 1, y), (x - 1, y + 1), (x, y - 1), (x, y + 1), (x + 1, y), (x + 1, y + 1)]
        for t in pairs:
          tx, ty = t[0], t[1]
          if (visited[tx][ty] in [0,3]) and (lst[tx][ty] in [WALL, 0]):
            ans += 1
  
  print(ans)

main()


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

typedef vector< int > vi;
typedef vector< vi > vvi;

vvi adjList;
int n;
int c[100000];
vi ans;
vector<bool> visited;
bool flag = false;

void dfs(int u, int v){
	if(u == v) { flag = true; ans.push_back(c[u]); return; }
    if(flag) return;

    visited[u] = true;
    ans.push_back(c[u]);
    for(int i = 0; i < adjList[u].size(); i++){
        if(!visited[adjList[u][i]]){
            dfs(adjList[u][i], v);
        }
    }
	if(!flag) ans.pop_back();
}

void display(int k){
    k--;
    map<int, int> data;
    map<int, vi> freq;

    for(int i : ans){
        data[i]++;
       // cout << i << ' ';
    }

    for(auto i : data){
        freq[i.second].push_back(i.first);
    }

    for(auto i : freq){
        sort(freq[i.first].begin(), freq[i.first].end(), greater<int>());
    }
    /*for(auto i : freq){
        cout << i.first << " : ";
        for(int x : i.second)
            cout << x << ' ';
        cout << endl;
    }*/
    for(auto i = freq.rbegin(); i != freq.rend(); i++){
//        cout << k << endl;
        if(k < (i->second.size())){
            cout << i->second[k];
            return;
        }
        else{
            k -= i->second.size();
        }
    }


    //cout << max_freq << endl;
    //for(auto i = data.rbegin(); i != data.rend(); i++){
     //   cout << i->first << ' ' << i->second << endl;
     //   if(k == 0 || i->second == max_freq){

            //cout << i->first;
            //return;
       // }
   // }
    //data.clear();


}

int main(){
    long long int q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    long long int one_litre = min(q * 4, min(s, h * 2));
    long long int ans;
    if(2 * one_litre < d){
        ans = one_litre * n;
    }
    else{
        ans = d * (n / 2);
        ans += (n % 2) * one_litre;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
long long dp[1000005][2];

int main()
{
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  S += '0';
  int N = S.size();
  for (int i = 0; i < N + 1; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < N + 1; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      int x = S[i] - '0';
      x += j;
      for (int a = 0; a < 10; a++)
      {
        int ni = i + 1, nj = 0;
        int b = a - x;
        if (b < 0)
        {
          nj = 1;
          b += 10;
        }
        dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
      }
    }
  }
  int ans = dp[N][0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17028
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;



int main(){

    int N, K;
    char S[50];
    cin >> N >> K;
    cin >> S;

    S[K-1] = S[K-1] + 0x20;

    cout << S;

    return 0;
}

//g++ ファイル名 --input-charset=utf-8 --exec-charset=cp932
//日本語出力するときのやつ

Measured memory_bytes: 256
/*
	@author: cheerioskun
*/

#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;


int main(){
	fast_io
	int N;
	cin>>N;
	int temp;
	int flag = 0;
	for(int i=0;i<N;++i){
		cin>>temp;
		if(temp%2==0){
			flag += (temp%3 != 0) && (temp%5 != 0);
		}
	}
	cout<< ((flag == 0) ? "APPROVED": "DENIED") << endl;
	
	

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	
	int p= m/n;
	
	repr(i, p, 1){
		ll x = m - (i * (n-1));
		if(x % i ==0){
			cout << i <<"\n";  return 0;
		}
	
	}
	
	return 0;
}


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

typedef long long ll;

int main() {
    int A, B, C, a, b, c, ans = 0;
    cin >> A >> B >> C;
    while (true) {
        if (A % 2 || B % 2 || C % 2) {
            cout << ans << endl;
            break;
        }
        if (A == B && B == C) {
            cout << "-1\n";
            break;
        }
        a = (B + C) / 2;
        b = (C + A) / 2;
        c = (A + B) / 2;
        A = a;
        B = b;
        C = c;
        ans++;
    }
}

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

int n;

vector< pair<int, int> > red, blue;

bool small(pair<int, int> l, pair<int, int> r){
    //cout << l.first << l.second << r.first << r.second << endl;
    if( ( l.first < r.first) && (l.second < r.second)) return true;
    return false;
}

int main(){
    cin >> n;
    int x, y;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        red.push_back(make_pair(x,y));
    }
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        blue.push_back(make_pair(x, y));
    }
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    /*
    cout << "red" << endl;
    for(int i = 0; i < n; i++){
        cout << red[i].first << " " << red[i].second << endl;
    }
    cout << "blue" << endl;
    for (int i = 0; i < n; i++)
    {
        cout << blue[i].first << " " << blue[i].second << endl;
    }
    */

    vector<bool> flag(n, false);
    int count = 0;
    for(int i = 0; i < n; i++){
        int maxy = -1;
        int candi = -1;
        for(int j = 0; j < n; j++){
            if(flag[j]) continue;
            if(small(red[j], blue[i])){
                //cout << maxy << endl;
                if(maxy < red[j].second){
                    maxy = red[j].second;
                    //cout << "test1" << endl;
                    candi = j;
                }
                //cout << maxy << j << i << endl;
            }
        }
        if (candi != -1)
        {
            flag[candi] = true;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main(){
	long long int   N = 0 ,A, B, C, K;
	string S;
	cin >> A >> B >> C >> K;
  
  if (K <= A) cout << K << endl;
  else if (K <= A + B) cout << A <<endl;
  else cout << 2*A + B -K << endl;
}


Measured memory_bytes: 3620
s = input()

result = []
result_1 = ["A","C","G","T"]
end = False
sum = 0

for i in range(len(s)):
    temporary = i
    sum = 0
    while True:
        if end == True:
            break
        for x in result_1:
            try:
                if s[temporary] == x:
                    sum += 1
                    temporary += 1
                    break
            except:
                end = True
        else:
            result.append(sum)
            break

print(max(result))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
char a[1010][1010];
char th[6][6]={"aab","c.b","cdd"};
char fo[6][6]={"aabc","ddbc","efgg","efhh"};
char fi[6][6]={"aabbc","dde.c","ffegg","..hij","..hij"};
char si[9][9]={"aadg..","bbdg..","cceh..","..ehjj","..fikk","..fill"};
char se[9][9]={"aabbcc.","ddeef..","gg..fhh","..ij..k","..ij..k","....lmn","....lmn"};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    if(n<3)
        return cout<<-1<<endl,0;
    int i,j,k;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            a[i][j]='.';
    if(n==3)
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                a[i][j]=th[i][j];
    else
    {
        if(n%4==0)
        {
            for(i=0;i<4;i++)
                for(j=0;j<4;j++)
                    a[i][j]=fo[i][j];
            for(k=4;k<n;k+=4)
                for(i=0;i<4;i++)
                    for(j=0;j<4;j++)
                        a[i+k][j+k]=fo[i][j];
        }
        else if(n%4==1)
        {
            for(i=0;i<5;i++)
                for(j=0;j<5;j++)
                    a[i][j]=fi[i][j];
            for(k=5;k<n;k+=4)
                for(i=0;i<4;i++)
                    for(j=0;j<4;j++)
                        a[i+k][j+k]=fo[i][j];
        }
        else if(n%4==2)
        {
            for(i=0;i<6;i++)
                for(j=0;j<6;j++)
                    a[i][j]=si[i][j];
            for(k=6;k<n;k+=4)
                for(i=0;i<4;i++)
                    for(j=0;j<4;j++)
                        a[i+k][j+k]=fo[i][j];
        }
        else if(n%4==3)
        {
            for(i=0;i<7;i++)
                for(j=0;j<7;j++)
                    a[i][j]=se[i][j];
            for(k=7;k<n;k+=4)
                for(i=0;i<4;i++)
                    for(j=0;j<4;j++)
                        a[i+k][j+k]=fo[i][j];
        }
    }
    for(i=0;i<n;i++)
        cout<<a[i]<<'\n';
    cout<<endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	int64_t ans = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> vec.at(i);

	}
	for (int i = 0; i < N-1; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			ans += vec.at(i) * vec.at(j);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
#define wis(x) "[" << #x << " : " << x << "] " << 
typedef long long ll;

const int MAXN = 2e5 + 10, MOD = 1e9 + 7, INF = 1e9 + 5;

map <string, int> cnt;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	string str;
	cin >> n;
	while(n--){
		cin >> str;
		cnt[str]++;
	}
	cout << "AC x " << cnt["AC"] << '\n' << "WA x " << cnt["WA"] << '\n' << "TLE x " << cnt["TLE"] << '\n' << "RE x " << cnt["RE"] << '\n';
}


Measured memory_bytes: 3664
f=lambda line,x:line[0]*x+line[1]
def _add_line(line,k,l,r):
    m=(l+r)//2
    if not data[k]:
        data[k]=line
        return
    lx,mx,rx=X[l],X[m],X[r-1]
    left,mid,right=f(line,lx)<f(data[k],lx),f(line,mx)<f(data[k],mx),f(line,rx)<f(data[k],rx)
    if left and right:
        data[k]=line
        return
    if not left and not right:return
    if mid:data[k],line=line,data[k]
    if left!=mid:_add_line(line,2*k+1,l,m)
    else:_add_line(line,2*k+2,m,r)
def add_line(line,a,b):
    L,R=a+N0,b+N0
    a0,b0=a,b
    sz=1
    while L<R:
        if R&1:
            R-=1
            b0-=sz
            _add_line(line,R-1,b0,b0+sz)
        if L&1:
            _add_line(line,L-1,a0,a0+sz)
            L+=1
            a0+=sz
        L>>=1
        R>>=1
        sz<<=1
def query(k):
    x=X[k]
    k+=N0-1
    s=10**18
    while k>=0:
        if data[k]:
            t=f(data[k],x)
            if t<s:s=t
        k=(k-1)//2
    return s
n,*t=map(int,open(0).read().split())
t,v=t[:n],t[n:]
st=sum(t)*2
m=a=i=0
N0=2**(st).bit_length()
data=[None]*(2*N0+1)
X=list(range(st+1))+[10**18]*N0
i=b=0
add_line((.5,0),0,st+1)
for u,w in zip(t,v):
    u+=u+i
    add_line((0,w),i,u)
    #add_line((1,b-i),i,st)
    #add_line((-1,w+u),0,u)
    add_line((-.5,w+i/2),0,i+1)
    add_line((.5,w-u/2),u,st+1)
    i,b=u,w
add_line((-.5,st/2),0,st+1)
a=x=0
for i in range(1,st+1):
    y=query(i)
    a+=(x+y)/4
    x=y
print(a)

Measured memory_bytes: 49628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        int b[100010],c[100010],m = -1;
        memset(c, 0, sizeof(c));
        for(int i=1; i<=n; i++)
        {
            cin>>b[i]; c[b[i]] ++;
            m = max(m, b[i]);
        }
        int ans = 0;
        for(int i=0; i<=m; i++)
            ans = max(ans, c[i]+c[i+1]+c[i+2]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
l=list(map(int,input().split()))
N=n
mod=10**9+7
fac=[1]*(N+3)
inv=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    fac[i]=t
t=pow(fac[N+2],mod-2,mod)
for i in range(N+2,0,-1):
    inv[i]=t
    t*=i
    t%=mod
def comb(n,r):
    if r>n or r<0:
        return 0
    return fac[n]*inv[n-r]*inv[r]%mod
import collections
c=collections.Counter(l)
l=list(c.items())
l.sort()
ans=0
t=0
for i,j in l:
    t+=j
    if t<k:
        continue
    for x in range(1,j+1):
        ans+=i*comb(j,x)*comb(t-j,k-x)
        ans%=mod
t=0
for i,j in l[::-1]:
    t+=j
    if t<k:
        continue
    for x in range(1,j+1):
        ans-=i*comb(j,x)*comb(t-j,k-x)
        ans%=mod
print(ans)

Measured memory_bytes: 27916
#include <bits/stdc++.h>
using namespace std;
#define maxN 1000001
#define mod 1000000007
#define maxLL 1000000000000000000
#define PI 3.14159265358979323846264338327950L
typedef long long ll;

bool compared(int a,int b){
	return a < b;
}

int cmp(const void *a,const void *b){
	return(*(int*)b - *(int*)a);
}

int GCD(int a,int b){
	return b?GCD(b,a%b):a;
}

int LCM(int a,int b){
	return a/__gcd(a,b)*b;
}

int main(){
	int x;
	cin>>x;
	cout<<LCM(360,x)/x<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[30000];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

int N, K;
int A[500];
inline bool keisan(int k) {
	int a[500];
	int ouchaku = 0;
	rep(j, N) {
		a[j] = A[j] % k;
		ouchaku = max(ouchaku, min(a[j], (k - a[j]) % k));
		if (ouchaku > K) return false;
	}
	pakuri_sort(N, a);
	int x = 0, y = N - 1;
	int tmp = a[0] + a[N - 1] - k;
	int kazu = a[0] + k - a[N - 1];
	while (x + 1 < y) {
		if (tmp <= 0) {
			tmp += a[++x];
			kazu += a[x];
		}
		else {
			tmp += a[--y] - k;
			kazu += k - a[y];
		}
	}
	if (kazu / 2 <= K) {
		printf("%d", k);
		return true;
	}
	return false;
}

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


	cin >> N >> K;
	int goukei = 0;
	rep(i, N) {
		cin >> A[i];
		goukei += A[i];
	}

	int yakusuu[30000];
	int M = 0;
	int sq = sqrt(goukei);
	rep1(i, sq) {
		if (goukei % i == 0) {
			yakusuu[M++] = i;
			if (i * i != goukei) {
				if (keisan(goukei / i)) return 0;
			}
		}
	}

	for (int i = M - 1; i >= 0; i--) {
		if (keisan(yakusuu[i])) return 0;
	}

	Would you please return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
w, v = [], []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)

V = [[], [], [], []]
for wi, vi in zip(w, v):
  V[wi - w[0]].append(vi)

for vv in V:
  vv.sort(reverse=True)

ans = 0
for i in range(len(V[0]) + 1):
  for j in range(len(V[1]) + 1):
    for k in range(len(V[2]) + 1):
      for l in range(len(V[3]) + 1):
        if w[0] * i + (w[0] + 1)* j + (w[0]+2)*k + (w[0] + 3) * l <= W:
          ans = max(ans, sum(V[0][:i]) +sum(V[1][:j]) +sum(V[2][:k]) +sum(V[3][:l])) 
print(ans)

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

int main() {
  // ここにプログラムを追記
  int kingaku,ichien;
  cin >> kingaku >> ichien;
  int amari = kingaku % 500;
  if(ichien - amari >=0){
    cout << "Yes" << endl;
  }else{
  	 cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];
        public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long min = Math.min(b-1,n);
        if(a == 1){
            System.out.println(0);
            return;
        }
        if(b == 1){
            System.out.println(0);
            return;
        }
        if(n == 1){
            System.out.println(a/b-(1/b)*a);
            return;
        }
        System.out.println((min * a)/b);
    }
}


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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;

    ump<ll, ll> mp;
    rep(i, n) { mp[a[i]]++; }
    ll ans = 0;
    each(e, mp) { ans += e.S * (e.S - 1) / 2; }
    rep(i, n) {
        cout << ans - (mp[a[i]] - 1) << '\n';
    }
}

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


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


int main() {
  ios::sync_with_stdio(0);
  int k;
  string s;
  cin >> k;
  cin >> s;
  if (s.size() <= k)
    cout << s << '\n';
  else {
    for (int i = 0; i < k; i++) {
      cout << s[i];
    }
    cout << "...\n";
  }
    
  return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
    float a,b,c,d,e,f,o,i;
    float x,y;

    while (scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!= EOF){


    y=(c*d-a*f)/(b*d-a*e);
    x=(c-b*y)/a;
    printf("%.3f %.3f\n",x,y);
    }
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x)  // cout << #x << " = " << (x) << endl;

bool is_valid(int x, int n) {
  return 0 <= x and x < n;
}

pair<long long, long long> count(int i, int j, const vector<string> &grid, vector<vector<int>> &mark) {
  const int h = grid.size();
  const int w = grid[0].size();

  int black = 1;
  int white = 0;

  mark[i][j] = 1;

  queue<pair<int, pair<int, int>>> Q;
  Q.push({0, {i, j}});

  vector<pair<int, int>> delta = {{ 1, 0},
                                  { 0, 1},
                                  {-1, 0},
                                  { 0,-1}};

  while (!Q.empty()) {
    int parity = Q.front().first;
    int i = Q.front().second.first;
    int j = Q.front().second.second;
    Q.pop();
    // cout << i << " " << j << endl;

    for (auto d : delta) {
      int next_i = i + d.first;
      int next_j = j + d.second;
      int next_parity = !parity;

      if (!is_valid(next_i, h) or !is_valid(next_j, w)) continue;
      if (mark[next_i][next_j]) continue;
      if (next_parity == 0 and grid[next_i][next_j] == '.') continue;
      if (next_parity == 1 and grid[next_i][next_j] == '#') continue;

      mark[next_i][next_j] = 1;
      Q.push({next_parity, {next_i, next_j}});

      if (next_parity == 0) {
        black++;
      } else {
        white++;
      }
      // cout << "  " << next_i << " " << next_j << endl;
    }
  }
  D(black); D(white);

  return {black, white};
}

int main() { IO;
  int h, w;
  cin >> h >> w;

  vector<string> grid(h);
  for (auto &line : grid) cin >> line;

  vector<vector<int>> mark(h);
  for (auto &v : mark) {
    v.resize(w);
  }

  long long ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (grid[i][j] == '#' and mark[i][j] == 0) {
        auto cnt = count(i, j, grid, mark);
        ans += cnt.first * cnt.second;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using vpi = vector<pair<int, int>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)

const char nl = '\n';
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    int n; cin >> n;
    vi h(n);
    F0R (i, n) cin >> h[i];
    vi dp(n, 2e9);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    FOR (i, 2, n - 1) {
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1] << endl;

    return 0;
}


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

int main(){
  int A[5];
  for(int i = 0; i <5; ++i) cin >> A[i];
  int k;
  cin >> k;
  if(A[4]-A[0] > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
A=[[0,0]for i in range(n)]
B=[[0,0] for i in range(m)]
E=[1]*n
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
for i in range(m):
    B[i][0],B[i][1]=map(int,input().split())
for i in range(n):
    c=abs(A[i][0]-B[0][0])+abs(A[i][1]-B[0][1])
    for j in range(1,m):
        if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])<c:
            c=abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])
            E[i]=j+1
for i in range(n):
    print(E[i])

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define N 300010
#define M 500010

typedef long long ll;
const int INF = 1 << 30;
const int Mod = 1000000007;

int n;
priority_queue<int, vector<int>, greater<int> > Q;
priority_queue<int> q;
ll f[N], g[N];
int a[N];

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
	
	int n; scanf("%d", &n);
	
	for (int i = 1; i <= 3 * n; ++i) scanf("%d", &a[i]);
	
	ll s = 0;
	for (int i = 1; i <= n; ++i) Q.push(a[i]), s += a[i];
	f[n] = s;
	for (int i = n + 1; i <= 2 * n; ++i)
	{
		if (a[i] > Q.top()) 
		{
			s = s - Q.top() + a[i];
			Q.pop(), Q.push(a[i]);
		}
		f[i] = max(f[i - 1], s);
	}
	
	s = 0;
	for (int i = 3 * n; i >= 2 * n + 1; --i) q.push(a[i]), s += a[i];
	g[2 * n + 1] = s;
	for (int i = 2 * n; i > n; --i)
	{
		if (a[i] < q.top())
		{
			s = s - q.top() + a[i];
			q.pop(), q.push(a[i]);
		}
		g[i] = min(g[i + 1], s);
	}
	
	ll res = -1ll << 60;
	for (int i = n; i <= 2 * n; ++i) res = max(res, f[i] - g[i + 1]);
	cout << res << endl;
	return 0; 
}

Measured memory_bytes: 5240
#include <iostream>
#include <algorithm>
#include <tuple>

using namespace std;

tuple<int,int,int> a[10010];
int t[101];
int n,w;
int k=0;
int x,y;

int root(int x)
{
     if(t[x]==x)
     {
          return x;
     }
     else
     {
          t[x]=root(t[x]);
          return t[x];
     }
}

void unite(int x,int y)
{
     t[root(x)]=root(y);
}

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

int main()
{
     cin >> n;
     for(int i=0;i<n;i++)
     {
          t[i]=i;
          for(int j=0;j<n;j++)
          {
               cin >> w;
               if(w==-1)
               {
                    continue;
               }
               a[k]=make_tuple(w,i,j);
               k+=1;
          }
     }
     sort(a,a+k);
     w=0;
     for(int i=0;i<k;i++)
     {
          x=get<1>(a[i]);
          y=get<2>(a[i]);
          if(same(x,y))
          {
               continue;
          }
          unite(x,y);
          w+=get<0>(a[i]);
     }
     cout << w << endl;
     return 0;
}


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

#define PI acos(-1.0)
#define nl '\n'

typedef long long int ll;
typedef unsigned long long int  llu;
const int mod = 1e9+7;

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

    ll n,i,j,k;
    cin>>n>>k;
    ll sum[n+5]= {0};
    ll a[n+5];
    for(i=1; i<=n+1; i++)
    {
        a[i]=i;
        sum[i]=sum[i-1]+a[i];
    }
    ll ans=0;
    for(i=k; i<=n+1; i++)
    {
        ll x=sum[i];
        ll y=sum[n+1]-sum[n+1-i];
        ans=ans+(y-x+1)%mod;
        ans=ans%mod;
    }
    cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 6664
#include<stdio.h>
#include<algorithm>
using namespace std;
int x[110000];
int p[110000];
int t[110000];
int s[110000];
int tmp[110000];
int r[110000];
long long sum[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",x+i);
	int b;
	long long c;
	scanf("%d%lld",&b,&c);
	for(int i=0;i<b;i++){
		scanf("%d",p+i);p[i]--;
	}
	for(int i=0;i<=a;i++)t[i]=i;
	for(int i=0;i<b;i++){
		swap(t[p[i]],t[p[i]+1]);
	}
	for(int i=0;i<=a;i++)s[t[i]]=i;
	for(int i=0;i<=a;i++)r[i]=i;
	while(c){
		if(c%2){
			for(int i=0;i<=a;i++)tmp[i]=s[r[i]];
			for(int i=0;i<=a;i++)r[i]=tmp[i];
		}
		c/=2;
		for(int i=0;i<=a;i++)tmp[i]=s[s[i]];
		for(int i=0;i<=a;i++)s[i]=tmp[i];
	}
	for(int i=0;i<a;i++){
		sum[r[i]]+=x[i];
		sum[r[i+1]]-=x[i];
	}
	for(int i=0;i<a;i++){
		if(i)sum[i]+=sum[i-1];
		printf("%lld\n",sum[i]);
	}
}

Measured memory_bytes: 4352
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];

// void dfs1(ll v, ll par)
// {
// 	c[v] = a[v];
// 	for(auto u:adj[v]){
// 		if(u==par)
// 			continue;
// 		dfs1(u,v);
// 		c[v] += c[u];
// 	}
// 	//bug2(c[v],v)
// }

// void dfs2(ll v, ll par, ll bef)
// {
// 	ll g,bx;
// 	g = (c[v]+b[v])/2;
// 	bx = c[v] - g;
// 	if(abs(b[v])>c[v] || g<0 || bx<0 || (c[v]+b[v])%2!=0 || g>bef)
// 		ans=1;
// 	for(auto u:adj[v]){
// 		if(u==par)
// 			continue;
// 		dfs2(u,v,g);
// 	}
// }



int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

string s;
cin >> n >> s;
fr(i,0,n)
	if(s[i]=='W')
		k++;
ll ans=0;
fr(i,0,k)
{
	if(s[n-i-1]!='W')
		ans++;
}
cout << ans;

 eNd();
  return 0;
 
}

Measured memory_bytes: 3776
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

task = []
heapq.heapify(task)

N, M = map(int, input().split())

A = [[] for i in range(M+1)]
for i in range(N):
    a, b = map(int, input().split())
    if a > M: continue
    A[a].append(b)

ans = 0
for i in range(1,M+1):
    for b in A[i]:
        heapq.heappush(task, -b)
    if len(task) > 0:
        ans += heapq.heappop(task)*(-1)

print(ans)





Measured memory_bytes: 93324
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

vector<int> pre, in, post;
int pos;

void reconstruction(int l, int r)
{
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));

	reconstruction(l, m);
	reconstruction(m + 1, r);

	post.push_back(root);
}

int main()
{
	int n, x;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		pre.push_back(x);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		in.push_back(x);
	}
	pos = 0;
	reconstruction(0, n);

	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", post[i]);
	}
	printf("\n");
	return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int n, l[200], ans = 0;
    cin >> n;
    rep(i, n) cin >> l[i];

    qsort(l, n, sizeof(int), compare_int);

    for (int i = 0; i < n - 2; i++)
    {
        for (int j = i + 1; j < n - 1; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k])
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

using namespace std;

int main() {
    int N;
    long int ans = 0;
    cin >> N;
    for (int a = 1; a < N + 1 ; a++){
        if(a%3==0){

        }else if(a%5==0){

        }else{
            ans += a;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3592
#include <stdio.h>
int ans;int gcd(int a, int b) {if (a<b) a+=b,b=a-b,a-=b;if (!b) return a;a%=b,ans++;return gcd(a,b);}
int main() {int a,b;while (scanf("%d %d",&a,&b)!=EOF && (a || b)) ans=0,a=gcd(a,b),printf("%d %d\n",a,ans);return 0;}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
    int N, K;
    string S;
    cin >> N >> K;
    K--;
    cin >> S;
    REP(i, N) {
        if (i == K) {
            printf("%c", S[i] - 'A' + 'a');
        } else {
            printf("%c", S[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

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


int main() {
	int N, X; cin >> N >> X;
	int a[N];
	for (int i = 0; i < N; i++) {
		int y; cin >> y;
		a[i] = abs(y - X);
	}

	int ans = a[0];
	for (int i = 1; i < N && ans != 1; i++) {
		ans = gcd(ans, a[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i+=2){
    int cnt = 0;
    for(int j=1; j<=i; j++){
      if(i%j == 0) cnt++;
    }
    if(cnt == 8) ans++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string r;
  cin>>r;
  int n=r.size();
  if(n%2){
    cout<<"No";
  }
  else{
    string t="";
    for(int i=1;i<=n/2;++i)t+="hi";
    cout<<((t==r)?"Yes":"No");
  }
  return 0;
}

Measured memory_bytes: 256