akhauriyash/Code-Regression huggingface dataset:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

X = I()

if X >= 30:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27096
n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for j in range(n):
        if s[j] == t[ti]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1
print(ans)


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

typedef long long int ll;
typedef vector<int> vi; 
typedef pair<int,int> pi; 
typedef vector<ll> vll; 


#define F first;
#define S second;
#define PB push_back;
#define MP make_pair;
#define rep(i, a, b) for (int i=a; i<b; i++)

int main(){
	ll t;
	cin >>t;
	ll arr[3];
    ll k=10;
    ll prev=1;
    rep(i,0,3){
        arr[i] = (t%k)/prev;
        k*=10;
        prev *= 10;
    }

    rep(i,0,3){
        if(arr[i]==1){
            arr[i]=9;
        }
        
        else if(arr[i] ==9)
        {
            arr[i]=1;
        }
        
    }
    rep(i,0,3){
        cout<<arr[2-i];
    }


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e6+4;
 
int main()                  
{
    string s;
    cin>>s;
    
    if(s[0]=='R' and s[1]=='R' and s[2]=='R')
    cout<<3;
    else if((s[0]=='R' and s[1]=='R') or (s[1]=='R' and s[2]=='R'))
    cout<<2;
    else if(s[0]=='S' and s[1]=='S' and s[2]=='S')
    cout<<0;
    else
    cout<<1;
    
    return 0;
}


Measured memory_bytes: 3520
def f(x):
    if x % 2 == 0:
        if ((x-1) // 2) % 2 == 0:
            return 0 ^ x
        else:
            return 1 ^ x
    else:
        if (x // 2) % 2 == 0:
            return 0
        else:
            return 1

a, b = [int(x) for x in input().split()]

result = f(a-1) ^ f(b)
print(result)


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

using ll = long long;


struct edge {
    int from, to;
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

void add_edge(graph& g, int from, int to) {
    g[from].push_back((edge){from, to});
}

int scc(graph& G, std::vector<int>& cmp) {
    int V = G.size();
    std::vector<vector<int>> g(V), rg(V);
    std::vector<bool> used(V, false);
    std::vector<int> vs;
    cmp.resize(V);
    for(int i=0; i<V; ++i) {
        for(auto e : G[i]) {
            g[i].push_back(e.to);
            rg[e.to].push_back(i);
        }
    }
    std::function<void(int)> dfs = [&g, &vs, &used, &dfs](int v) {
        used[v] = true;
        for(auto i : g[v]) {
            if(!used[i]) {
                dfs(i);
            }
        }
        vs.push_back(v);
    };
    std::function<void(int, int)> rdfs = [&rg, &cmp, &used, &rdfs](int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for(int i : rg[v]) {
            if(!used[i]) {
                rdfs(i, k);
            }
        }
    };
    for(int v=0; v<V; ++v) {
        if(!used[v]) {
            dfs(v);
        }
    }
    std::fill(used.begin(), used.end(), false);
    int k = 0;
    for(int i=vs.size()-1; i>=0; --i) {
        if(!used[vs[i]]) {
            rdfs(vs[i], k++);
        }
    }
    return k;
}

vector<vector<int>> build_graph(graph const& g, vector<int> const& cmp, int K) {
    int V = g.size();
    std::vector<std::set<int>> s(K);
    std::vector<std::vector<int>> res(K);
    for(int i=0; i<V; ++i) {
        for(auto e : g[i]) {
            s[cmp[i]].insert(cmp[e.to]);
        }
    }
    for(int i=0; i<K; ++i) {
        for(auto j : s[i]) {
            if(i != j) {
                res[i].push_back(j);
            }
        }
    }
    return res;
}


int main() {
    int N;
    while(cin >> N, N) {
        graph g(N);
        vector<double> p(N);
        for(int i=0; i<N; ++i) {
            int m;
            cin >> p[i] >> m;
            for(int j=0; j<m; ++j) {
                int a;
                cin >> a;
                a--;
                add_edge(g, i, a);
            }
        }
        vector<int> cmp;
        const int k = scc(g, cmp);
        auto g2 = build_graph(g, cmp, k);
        vector<bool> flag(k);
        double res = 1;
        for(auto& v : g2) {
            for(auto to : v) {
                flag[to] = true;
            }
        }
        for(int i=0; i<k; ++i) {
            if(!flag[i]) {
                double t = 1;
                for(int j=0; j<N; ++j) {
                    if(cmp[j] == i) {
                        t *= p[j];
                    }
                }
                res *= (1 - t);
            }
        }
        cout << fixed << setprecision(10) << res << endl;
    }
}


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

int main()
{
  string s;
  cin >> s;
  ll int white_num = 0;
  ll int cnt = 0;
  rep(i,s.size()){
    if(s.at(i)=='W')
    {
      cnt += i;
      white_num++;
    }
  }
  ll int max = 0;
  rep(i, white_num)
  {
    max += i;
  }
  
  cout <<cnt - max << endl;
}

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

int main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    ll ct_orgn=0;
    ll la=0,lb=0,sa=0,sb=0;
    ll aa=0,ab=0,ba=0,bb=0;
    for(int i=0;i<N;i++){
        cin >> S[i];
        int jg=0;
        if(S[i][0]=='B' && S[i][S[i].size()-1]=='A') ba++;
        else if(S[i][0]=='B') sb++;
        else if(S[i][S[i].size()-1]=='A') la++;


        for(int j=0;j<S[i].size();j++){
            if(S[i][j]=='A') jg=1;
            else if(jg==1 && S[i][j]=='B'){
                jg=0;
                ct_orgn++;
            }
            else if(jg==1 && S[i][j]!='A') jg=0;
        }
    }
    ll ans=0;

    if(ba!=0){
        if(sb==0 && la==0) ans = ct_orgn + ba - 1;
        else if((sb!=0 && la==0) || (sb==0 && la!=0)) ans = ct_orgn + ba;
        else if(sb!=0 && la!=0) ans = ct_orgn + ba + 1 + min(sb-1,la-1);
    }
    else{
        ans = ct_orgn + min(sb,la);
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
n,m = gets.split(" ").map(&:to_i)
as = []
m.times do
  as << gets.split(" ").map(&:to_i)
end

graph = []

def reset_g(graph, as, n)
  (0...n).each do |i|
    (0...n).each do |j|
      graph[i] ||= []
      graph[i][j] = 0
    end
  end

  as.each do |a|
    graph[a[0]-1][a[1]-1] = 1
    graph[a[1]-1][a[0]-1] = 1
  end
  graph
end

visited = {}

def reset_v(visited, n)
  (1..n).each do |i|
    visited[i] = false
  end
  visited
end

def dfs(current, tmp_g, visited)
  return if visited[current]
  visited[current] = true
  tmp_g[current-1].each.with_index(1) do |node,i|
    if node == 1
      dfs(i, tmp_g, visited)
    end
  end
end

ans = 0
m.times do |i|
  tmp_g = reset_g([], as, n)
  visited = reset_v(visited, n)

  a = as[i]
  tmp_g[a[0] - 1][a[1] -1] = 0
  tmp_g[a[1] - 1][a[0] -1] = 0
  dfs(1, tmp_g, visited)
  flg = false
  n.times do |j|
    if !flg && !visited[j+1]
      flg = true
      ans += 1
    end
  end
end

puts ans

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

int N;
int idx;
int zero;
int one;
int as[114514];

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    int a;
    scanf("%d", &a);
    if (a == 0) zero++;
    else if (a == 1) one++;
    else as[idx++] = a;
  }

  sort(as, as+idx);
  if (zero%2 == 1 && one == 0 && idx) {
    swap(as[0], as[idx-1]);
    idx--;
    sort(as, as+idx);
  }

  if (idx >= 2 && as[idx-2] == 2 && as[idx-1] == 3) {
    swap(as[idx-1], as[idx-2]);
  }

  for (int i=0; i<idx; i++) printf("%d\n", as[i]);
  if (zero%2 == 1 && one == 0) {
    for (int i=0; i<zero-1; i++) puts("0");
    if (idx >= 0 && zero < N) printf("%d\n", as[idx]);
    puts("0");
  } else {
    if (zero%2 == 1) {
      zero--;
      one--;
      while (zero--) puts("0");
      puts("1");
      puts("0");
      while (one--) puts("1");
    } else {
      while (zero--) puts("0");
      while (one--) puts("1");
    }
  }
}

Measured memory_bytes: 3288
from collections import defaultdict
import heapq as hq
N = int(input())
dicUD = defaultdict(list)
dicRL = defaultdict(list)
dicRUp = defaultdict(list)
dicDLp = defaultdict(list)
dicRDm = defaultdict(list)
dicULm = defaultdict(list)
for i in range(N):
    X,Y,U = input().split()
    X,Y = map(int,(X,Y))
    if U == "L":
        hq.heappush(dicRL[Y],(X,"L"))
        hq.heappush(dicDLp[X+Y],(X-Y,"L"))
        hq.heappush(dicULm[X-Y],(X+Y,"L"))
    if U == "R":
        hq.heappush(dicRL[Y],(X,"R"))
        hq.heappush(dicRUp[X+Y],(X-Y,"R"))
        hq.heappush(dicRDm[X-Y],(X+Y,"R"))
    if U == "U":
        hq.heappush(dicUD[X],(Y,"R"))
        hq.heappush(dicRUp[X+Y],(X-Y,"L"))
        hq.heappush(dicULm[X-Y],(X+Y,"R"))
    if U == "D":
        hq.heappush(dicUD[X],(Y,"L"))
        hq.heappush(dicDLp[X+Y],(X-Y,"R"))
        hq.heappush(dicRDm[X-Y],(X+Y,"L"))
time = 10000000
for dic in (dicUD,dicRL,dicRUp,dicDLp,dicRDm,dicULm):
    for q in dic.values():
        cur = -1000000
        dir = "L"
        while q:
            X,U = hq.heappop(q)
            if U == "R":
                dir = "R"
            elif U == "L":
                if dir == "R":
                    time = min(time,(X-cur)*5)
                dir = "L"
            cur = X
if time == 10000000:
    print("SAFE")
else:
    print(time)

Measured memory_bytes: 227188
#include <iostream>
using namespace std;
typedef long long ll;
ll GCD(ll a, ll b) {
    return (a == 0) ? b : GCD(b % a, a);
}
ll LCM(ll a, ll b) {
    return a * b / GCD(a, b);
}
int main() {
    int a[3], m[3];
    while (1) {
        cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2];
        if (!a[0]) {
            break;
        }
        int move[3];
        for (int i=0; i<3; ++i) {
            int val = 1;
            for (int j=1; j<=m[i]; ++j) {
                val = a[i] * val % m[i];
                if (val == 1) {
                    move[i] = j; break;
                }
            }
        }
        ll ans = LCM(LCM(move[0], move[1]), move[2]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1156
Q=int(input())
mod=1000003
def calc():
    x,d,n=map(int,input().split())
    if x==0:
        return 0
    elif d==0:
        return pow(x,n,mod)
    else:
        revd=pow(d,mod-2,mod)
        start=x*revd%mod
        if start+n-1>=mod:
            return 0
        else:
            #print(kaijo[(x*revd+(n-1))%mod],gyaku[(x*revd-1)%mod],pow(d,n,mod))
            return kaijo[(x*revd+(n-1))%mod]*gyaku[(x*revd-1)%mod]*pow(d,n,mod)%mod
kaijo=[0]*mod
kaijo[0]=1
for i in range(1,mod):
    kaijo[i]=kaijo[i-1]*i%mod
gyaku=[0]*mod
gyaku[mod-1]=pow(kaijo[mod-1],mod-2,mod)
for i in range(mod-1,0,-1):
    gyaku[i-1]=gyaku[i]*i%mod
for i in range(Q):
    print(calc())

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

#define mod 1000000007

int cnt=0;

vector< vector<char> > v;
vector< vector<bool> > vis;
vector< vector<int> > path;

int h,w;

int countPaths(int i, int j){
    if(i>=h||j>=w)
        return 0;
    
    if(v[i][j]=='#')
        return path[i][j]=0;
    
    if(i==(h-1)&&j==(w-1))
        return path[i][j]=1;
    
    if(path[i][j]!=-1)
        return path[i][j];
    
    return path[i][j]= (countPaths(i+1, j)%mod + countPaths(i, j+1)%mod)%mod;
    
}
int32_t main() {
	// your code goes here
	cin>>h>>w;
	v = vector< vector<char> > (h, vector<char> (w));
	path = vector< vector<int> > (h, vector<int> (w,-1));
	for(int i=0; i<h; i++){
	    for(int j=0; j<w; j++)cin>>v[i][j];
	}
	vis = vector< vector<bool> > (h, vector<bool> (w,0));
	cout<<(countPaths(0,0));
	
	return 0;
}


Measured memory_bytes: 5504
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

set<int> row_sit;
set<int> row_stand;
set<int> col_sit;
set<int> col_stand;
vector<pair<pair<int,int>, int> > order;

int main() {
    int r,c,q,a,b,o;
    while(scanf("%d%d%d", &r, &c, &q), r|c|q) {
        order.clear();
        row_sit.clear();
        row_stand.clear();
        col_sit.clear();
        col_stand.clear();
        for(int i=0; i<q; ++i) {
            scanf("%d%d%d", &a, &b, &o);
            order.push_back(make_pair(make_pair(a,b),o));
        }

        reverse(order.begin(), order.end());
        int ans = 0;

        for(int i=0; i<order.size(); ++i) {
            a = order[i].first.first;
            b = order[i].first.second;
            o = order[i].second;

            if(o == 0) {
                if(a == 0) {
                    if(row_stand.find(b) != row_stand.end()) continue;
                    row_sit.insert(b);
                }else{
                    if(col_stand.find(b) != col_stand.end()) continue;
                    col_sit.insert(b);
                }
            }else{
                if(a == 0) {
                    if(row_sit.find(b) != row_sit.end()) continue;
                    if(row_stand.find(b) != row_stand.end()) continue;
                    ans += c - col_sit.size() - col_stand.size();
                    row_stand.insert(b);
                }else{
                    if(col_sit.find(b) != col_sit.end()) continue;
                    if(col_stand.find(b) != col_stand.end()) continue;
                    ans += r - row_sit.size() - row_stand.size();
                    col_stand.insert(b);
                }
            }
        }

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

Measured memory_bytes: 0
#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>
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 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;
//g++ -std=c++1z temp.cpp
//./a.exe


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

string s;
    cin>>s;
    bool ch=true;
    rep(i,s.size()){
        if(i%2==1){
            if(s[i]=='R')ch=false;
        } else {
            if(s[i]=='L')ch=false;
        }
    }
    if(ch)fin("Yes");
    else fin("No");





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

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
ok = max(a)*max(f)
ng = -1

while ok-ng > 1:
    mid = (ok+ng)//2
    t = 0
    for i in range(n):
        t += max(0,a[i]-int(mid/f[i]))
    if t > k:
        ng = mid
    else:
        ok = mid

print(ok)

Measured memory_bytes: 119500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()


int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> d(n+1);
  d[0] = 0;
  for (int i = 1; i <= n; i++) d[i] = d[i-1] + p[i-1];
  int ans = 0;
  rep(i, n - k + 1){
    int now = d[i+k] - d[i];
    ans = max(ans, now);
  }
  double res = (double)(ans + k)/ 2;
  cout << fixed << setprecision(7) << res << endl;
}

Measured memory_bytes: 1792
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b,x) = scan "%f %f %f" Tuple3.make

let () =
  let v = 2.0 *. x /. a /. b in
  let theta =
    if v <= a then
      Float.pi /. 2.0 -. Float.atan (v /. b)
    else
      let v = 2.0 *. (a *. a *. b -. x) /. a /. a in
      Float.atan (v /. a)
  in
  Printf.printf "%.10f\n" @@ theta /. Float.pi *. 180.0


Measured memory_bytes: 1152
import java.util.*;
class Main {

    int trialNum;
    
    Main() {
        trialNum = 0;
    }

    int findMin(int[] h, int start, int end) {
        int min = h[start];
        for(int i = start; i <= end; i++) {
            if(min > h[i]) min = h[i];
        }
        return min;
    }

    int[] findZeroPos(int[] h, int start, int end) {
        List<Integer> list = new ArrayList<>();
        for(int i = start; i <=end; i++) {
            if(h[i] == 0) list.add(i);
        }
        int[] zeroPos = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            zeroPos[i] = list.get(i);
        }
        return zeroPos;
    }

    void watering(int[] h, int start, int end, int n) {
        for(int i = start; i <= end; i++) {
            h[i] -= n;
        }
        trialNum += n;
    }

    void growFlower(int[] h, int l, int r) {
        if(l >= r) {
            trialNum += h[l];
            return;
        }
        else {
            if(h[l] == 0) l++;
            if(h[r] == 0) r--;
            int min = findMin(h, l, r);
            watering(h, l, r, min);
            int[] zeroPos = findZeroPos(h, l, r);
            growFlower(h, l, zeroPos[0]-1);
            for(int i = 1; i < zeroPos.length; i++) {
                growFlower(h, zeroPos[i-1]+1, zeroPos[i]-1);
            }
            growFlower(h, zeroPos[zeroPos.length-1], r);
        }
    }

    void print(int[] h) {
        for(int i = 0; i < h.length; i++) {
            System.out.print(h[i]+" ");
        }
        System.out.print("\n");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }
        Main myG = new Main();
        myG.growFlower(h, 0, N-1);
        System.out.println(myG.trialNum);
    }
}

Measured memory_bytes: 23892
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;

int main()
{
    bool ans=true;
    int n,place,tmp=0,cnt=0;
    cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++)cin>>p[i];
    
    for(int i=0;i<n;i++){
        if(p[i]!=i+1 and cnt==0){
            place=i;
            cnt++;
        }else if(p[i]!=i+1 and 1<=cnt){
            tmp=p[i];
            p[i]=p[place];
            p[place]=tmp;
            cnt++;
        }
    }
    
    if(3<=cnt)ans=false;
    for(int i=0;i<n;i++){
        if(p[i]!=i+1){
            ans=false;
            break;
        }
    }
    
    if(ans==true)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N=int(raw_input())
flag=True
n=0
for i in range(1,10**3+1):
    if i*(i+1)/2==N:
        n=i
        flag=False
        break

if flag:
    print "No"
else:
    print "Yes"
    set_num=n+1
    set_size=n
    print set_num
    num=1
    for i in range(set_num):
        num1=num
        ans = str(set_size)+" "
        for j in range(set_size):
            ans+=str(num1)+" "
            if j+1<i:
                num1+=1
            elif j+1==i:
                num1+=j+2
            else:
                num1+=j+1
        print ans[:-1]
        num+=i
        

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>> a[i];
    map<ll,ll>x;
    rep(i,n){
        ll now = a[i];
        x[now]++;
    }
    vector<ll>k;
    vector<ll>s;
    for(auto itr=x.begin();itr!=x.end();itr++){
        if((itr->second)>=2){
            k.push_back(itr->first);
        }
        if((itr->second)>=4){
            s.push_back(itr->first);
        }
    }
    sort(k.begin(),k.end());
    reverse(k.begin(),k.end());
    sort(s.rbegin(),s.rend());
    ll res=0;
    if((ll)k.size()<=1&&(ll)s.size()==0){
        cout << 0 << endl;
    }
    else{
    if(s.size()!=0){
        res = s[0]*s[0];
    }
    if(k.size()>=2){
        chmax(res,k[0]*k[1]);
    }
    cout << res << endl;
    }
    return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;
string s;
vector<ll> dir;
vector<ll> ans;

void input() {
  IN(s);
  N = s.size();
  REP(i, N) {
    dir.push_back((s[i]=='L' ? -1 : 1));
    ans.push_back(0);
  }
}

void solve() {
  ll p = 0;
  while(p < N) {
    ll begin = p;
    while(dir[p] == dir[p+1]) {
      p++;
      if (p == N-1) break;
    }
    ll end = p;

    ll group = end - begin + 1;
    ll ter = (dir[p]==1?end:begin);
    ans[ter] += group/2 + group%2;
    ans[ter + dir[p]] += group/2;

    p++;
  }
  REP(i, N) {
    cout << ans[i] << " ";
  }
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 2412
s = input()
t = input()
s_set = set(list(s))
t_set = set(list(t))
if not t_set.issubset(s_set):
    print(-1)
else:
    ans = 0
    pre_idx = -1
    cnt = 0
    for i in range(len(t)):
        if t[i] not in s[pre_idx+1:]:
            ans += len(s)
            pre_idx = -1
            cnt = 0
        if pre_idx == -1:
            idx = s[pre_idx+1:].find(t[i])
        else:
            idx = s[pre_idx+1:].find(t[i]) + pre_idx + 1
        cnt = idx+1
        pre_idx = idx
    print(ans+cnt)

Measured memory_bytes: 4084
#include<stdio.h>

int main(void){
	unsigned long long int n, fact;
	
	scanf("%llu", &n);
	
	fact = n * (n-1);
	n = n-2;
	
	while(n>1){
		fact = fact * n;
		n = n--;
	}
	
	printf("%llu\n", fact);
	
	return 0;
	
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int d,t,s;
  cin>>d>>t>>s;
  int ans = t*s;
  if(d<=ans)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    int sum,A;
    sum = 0;
    for(int i=0;i<M;i++) {
        cin>>A;
        sum+=A;
    }
    int ans = N-sum;
    if(ans<0) ans = -1;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(){
  int n,i,S=0,h=0;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    if(h<p[i])h=p[i];
    S+=p[i];
    }
  printf("%d",S-h/2);
  return 0;
  }
  

Measured memory_bytes: 128
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

vector<set<int>> gr(100005);
vector<set<int>> gr2(100005);
int comp[100005];
int nod[100005];


void DFS(int idx,int cc)
{
    comp[idx]=cc;
    nod[cc]++;
    for(auto x:gr[idx])
    {
        if(!comp[x])
        {
            DFS(x,cc);
        }
    }
}

int32_t main()
{
    IOS;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n,m,k,i,u,v;
        cin>>n>>m>>k;
        for(i=0;i<m;i++)
        {
            cin>>u>>v;
            gr[u].insert(v);
            gr[v].insert(u);
        }
        for(i=0;i<k;i++)
        {
            cin>>u>>v;
            gr2[u].insert(v);
            gr2[v].insert(u);
        }
        u=1;
        for(i=1;i<=n;i++)
        {
            if(!comp[i])
            {
                DFS(i,u++);
            }
        }
        // for(i=1;i<=n;i++)
        //     cout<<comp[i]<<" ";
        for(i=1;i<=n;i++)
        {
            int ans=nod[comp[i]]-1-gr[i].size();
            for(auto x:gr2[i])
            {
                if((comp[x]==comp[i])&&(!gr[i].count(x)))
                {
                    ans--;
                }
            }
            cout<<ans<<" ";
        }
        
    }

    return 0;
}

Measured memory_bytes: 31104
import math

a, b, C = map(float, input().split())

S = 0.5 * a * b *  math.sin(math.radians(C))
L = a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))

print(f"{S} {L} {h}")


Measured memory_bytes: 5708
import java.util.*;

class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a=sc.next();
		String[] b = a.split("");
		int[] c = new int[4];
		for (int i=0;i<4;i++) {
			c[i]=Integer.parseInt(b[i]);
		}

		Map<Integer,String> map = new HashMap<Integer,String>();
		map.put(0,"+");
		map.put(1,"-");

		int[] d = new int[3];
		loop:for (Integer i=0;i<2;i++) {
			if (i==0) {
				d[0]=c[0]+c[1];
			}else {
				d[0]=c[0]-c[1];
			}
			for (Integer k=0;k<2;k++) {
				if (k==0) {
					d[1]=d[0]+c[2];
				}else {
					d[1]=d[0]-c[2];
				}
				for (Integer m=0;m<2;m++) {
					if (m==0) {
						d[2]=d[1]+c[3];
						if (d[2]==7) {
							System.out.println(c[0]+map.get(i)+c[1]+map.get(k)+c[2]+map.get(m)+c[3]+"=7");
							break loop;
						}
					}else {
						d[2]=d[1]-c[3];
						if (d[2]==7) {
							System.out.println(c[0]+map.get(i)+c[1]+map.get(k)+c[2]+map.get(m)+c[3]+"=7");
							break loop;
						}
					}
				}
			}
		}
	}
}

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

#define NMAX 200100
#define INF 2000000000

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

typedef unsigned long long ull;
typedef long long int lli;

using namespace std;

// std::ifstream cin("f.in");
// std::ofstream cout("f.out");

int n, m;
vector<pair<int, int> > drinks;

int main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        drinks.push_back({a, b});
    }

    sort(drinks.begin(), drinks.end());
    ull price = 0; 
    int i = 0;

    while(m)
    {
        ull numDrinks = MIN(m, drinks[i].second);
        price += numDrinks * drinks[i].first;
        m -= numDrinks;
        i++;
    }

    cout << price << '\n';

    return 0;
}   

Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <set>

using namespace std;

int n;
char s[4];
set<char> st;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%s",s),st.insert(s[0]);
	printf("%s\n",st.size()==3 ? "Three" : "Four");
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vi a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    a.pb(x),b.pb(y);
    bool f=*max_element(all(a))>=*min_element(all(b));
    cout<<(f?"":"No ")<<"War"<<endl;
}

Measured memory_bytes: 256
n = int(input())
S = input()
from collections import Counter
ans = 0
for i in range(1,n):
    f = S[:i]
    b = S[i:]
    f = set(f)
    #print(f)
    #print(S[:i],S[i:])
    cnt = 0
    for v in f:
        #print(v)
        if v in b:
            cnt += 1
    ans = max(ans,cnt)
print(ans)


Measured memory_bytes: 3316
#include <string>
#include <iostream>
#include <cmath>
#include <vector>

using std::cin;
using std::cout;
using std::string;
using std::vector;

int minmp(const vector<int>& xs, int a, int b, int c) {
  using std::abs;
  
  int n = xs.size();
  int min = a + b + c;
  
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j == i) {
	continue;
      }
      for (int k = 0; k < n; ++k) {
	if (k == i || k == j) {
	  continue;
	}
	int m = abs(xs[i] - a) + abs(xs[j] - b) + abs(xs[k] - c);
	if (m < min) {
	  min = m;
	}
      }
    }
  }

  return min;
}

int minmp_comb(const vector<int>& xs, int a, int b, int c) {
  int min = minmp(xs, a, b, c);

  int n = xs.size();
  if (n == 3) {
    return min;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      vector<int> ys;
      ys.push_back(xs[i] + xs[j]);
      for (int k = 0; k < n; ++k) {
	if (k == i || k == j) {
	  continue;
	}
	ys.push_back(xs[k]);
      }
      int m = minmp_comb(ys, a, b, c) + 10;
      if (m < min) {
	min = m;
      }
    }
  }
  return min;
}

int main(int argc, char* argv[]) {
  int n, a, b, c;
  vector<int> xs;

  cin >> n >> a >> b >> c;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    xs.push_back(x);
  }
  cout << minmp_comb(xs, a, b, c);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_set>

using namespace std;

int main(void) {

    int n;
    cin >> n;

    // if(n==1){ cout<<4<<endl; return 0;}
    // if(n==2){ cout<<4<<endl; return 0;}

    vector<int> hist;

    int cnt = 1;
    int check = n;
    hist.push_back(check);
    // cout << "cnt:" << cnt << " ,check:" << check << endl;


    while(true) {

        cnt++;

        if (check % 2 == 0) {
            check /= 2;
        } else {
            check = (3 * check) + 1;
        }

        // cout << "cnt:" << cnt << " ,check:" << check << endl;


        if (find(hist.begin(), hist.end(), check) != hist.end()) {
            cout << cnt << endl;
            break;
        }

        // cout << "cnt:" << cnt << " ,check:" << check << endl;

        hist.push_back(check);
    }

    return 0;
}

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

#define ll long long
#define ld long double
#define mod 1000000007LL
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define pb(x) push_back(x)
#define fo(i, a, n) for (i = (a); i < (n); i++)
#define foe(i, a, n) for (i = (a); i <= (n); i++)
// clang-format off
#define vin(a) for (ll i = 0; i < sz(a); i++) { cin >> a[i]; } 
#define vout(a) for (auto x : a) { cout << x << " "; }
#define sws                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
// clang-format on
#define pd(x) cout << x
#define sd(x) cin >> x
#define nl cout << endl
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
// int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
void solve() {
  ll m, n;
  ll i, j;
  cin >> n >> m;
  ll x, y;

  ll ans = 0;
  fo(i, 0, n) {
    cin >> x >> y;
    if (m * m >= x * x + y * y)
      ans++;
  }

  cout << ans << endl;
}

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

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>

int main(){
	int x, a;
	std::cin>>x>>a;

	if(x<a)
		std::cout<<0<<std::endl;
	else
		std::cout<<10<<std::endl;

	return 0;
	
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	ans := 1
	for i := 2; i < x; i++ {
		if i*i > x {
			break
		}
		for j := i * i; j <= x; j *= i {
			if j > ans {
				ans = j
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

struct T {
  bool b = false;
  int w = 0;
} t;

int main() {
	int n, m;
	int p;
	int correct = 0, penalty = 0, temp = 0;
	std::string s;
	std::cin >> n >> m;
	std::vector<T> a (n+1);
	for(int i = 0; i < m; i++) {
		std::cin >> p >> s;
      	if(a[p].b == false) {
			if(s == "AC") {
				correct++;
				a[p].b = true;
			} else {
				a[p].w++;
			}
		}
	}

	for(int i = 1; i < a.size(); i++) {
		if(a[i].b) {
			penalty += a[i].w;
		}
	}
	std::cout << correct << " " << penalty;
	return 0;
}

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

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

int MOD = 1e9 + 7;
int INF = 1e9;
// ll INF = 1e18;

int n, r, c;
vector<ii> upp, downn, leftt, rightt; // {cord, idx}

int atEdge(int x, int y){
	return x == 0 || x == r || y == 0 || y == c;
}

int solve(){
	cin >> r >> c >> n;
	for(int i=0;i<n;i++){
		int x, y, xx, yy;
		cin >> x >> y >> xx >> yy;
		if(!atEdge(x, y) || !atEdge(xx, yy)) continue;
		// x y first
		if(x == 0)
			upp.push_back({y, i});
		else if(x == r)
			downn.push_back({y, i});
		else if(y == 0)
			leftt.push_back({x, i});
		else
			rightt.push_back({x, i});
		// xx yy
		if(xx == 0)
			upp.push_back({yy, i});
		else if(xx == r)
			downn.push_back({yy, i});
		else if(yy == 0)
			leftt.push_back({xx, i});
		else
			rightt.push_back({xx, i});
	}
	sort(upp.begin(), upp.end());
	sort(rightt.begin(), rightt.end());
	sort(downn.begin(), downn.end()); reverse(downn.begin(), downn.end());
	sort(leftt.begin(), leftt.end()); reverse(leftt.begin(), leftt.end());

	int in[100005]={};
	stack<int> st;
	for(auto p: upp){
		int x = p.second;
		// cerr << x << endl;
		if(!in[x])
			st.push(x), in[x] = 1;
		else{
			if(st.top() != x)
				return cout << "NO" << endl, 0;
			st.pop();
		}
	}
	for(auto p: rightt){
		int x = p.second;
		// cerr << x << endl;
		if(!in[x])
			st.push(x), in[x] = 1;
		else{
			if(st.top() != x)
				return cout << "NO" << endl, 0;
			st.pop();
		}
	}
	for(auto p: downn){
		int x = p.second;
		// cerr << x << endl;
		if(!in[x])
			st.push(x), in[x] = 1;
		else{
			if(st.top() != x)
				return cout << "NO" << endl, 0;
			st.pop();
		}
	}
	for(auto p: leftt){
		int x = p.second;
		// cerr << x << endl;
		if(!in[x])
			st.push(x), in[x] = 1;
		else{
			if(st.top() != x)
				return cout << "NO" << endl, 0;
			st.pop();
		}
	}
	cout << "YES" << endl;
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 2584
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;

	int total_white = count(s.begin(), s.end(), '.');
	int total_black = n - total_white;

	int ans = min(total_white, total_black);
	int white = 0;
	int black = 0;

	for (char c: s) {
		c == '.' ? white++ : black++;
		ans = min(ans, black + total_white - white);
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int n, k;
	cin >> n >> k;
	int keta = 0;
	while (n > 0) {
		n /= k;
		keta++;
	}
	cout << keta << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int main() {
	int n, m;
	int a[1010][2] = {0};
	int b;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i][0];
	}
	for (int i = 0; i < m; i++) {
		cin >> b;
		for (int j = 0; j < n; j++) {
			if (a[j][0] <= b) {
				a[j][1]++;
				break;
			}
		}
	}
	int max[2] = {0};
	for (int i = 0; i < n; i++) {
		if (max[1] < a[i][1]) {
			max[1] = a[i][1];
			max[0] = i+1;
		}
	}
	cout << max[0] << endl;
	return 0;
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 1e5 + 5;

typedef pair<int,int>   ii;

struct Dat1 {
    priority_queue<ll>  pq;
    ll  shift = 0;
}   L;
struct Dat2 {
    priority_queue<ll,vector<ll>,greater<ll> >  pq;
    ll  shift = 0;
}   R;

int len[N];
int lef[N];

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

    int n;  cin >> n;

    for(int i = 1 ; i <= n ; ++i)   {
        cin >> lef[i];
        int r;  cin >> r;
        len[i] = r - lef[i];
    }
    L.pq.push(lef[1]);
    R.pq.push(lef[1]);

    long long ans = 0;

    for(int i = 2 ; i <= n ; ++i)   {
        L.shift -= len[i];
        R.shift += len[i - 1];

        ll  optL = L.pq.top() + L.shift;
        ll  optR = R.pq.top() + R.shift;

        if (lef[i] < optL)  {
            ans += optL - lef[i];
            R.pq.push(optL - R.shift);
            L.pq.pop();
            L.pq.push(lef[i] - L.shift);
            L.pq.push(lef[i] - L.shift);
            continue;
        }
        if (lef[i] > optR)  {
            ans += lef[i] - optR;
            L.pq.push(optR - L.shift);
            R.pq.pop();
            R.pq.push(lef[i] - R.shift);
            R.pq.push(lef[i] - R.shift);
            continue;
        }
        L.pq.push(lef[i] - L.shift);
        R.pq.push(lef[i] - R.shift);
    }
    cout << ans << endl;
}

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

int main(){
  int N,ans=0,tmp=0;
  cin >> N;
  vector<int>a(N);
  while(tmp==0){
    for(int i=0;i<N;i++)
      cin >> a.at(i);
    for(int i=0;i<N;i++){
      if(a.at(i)%2==0)
        a.at(i)/=2;
      else{
        tmp++;
        break;}
      if(i==N-1)
        ans++;
    }
  }
    cout << ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<





int main(void){
	int A, B;
    cin >> A >> B;

    if(A>B*2){
        cout << A-B*2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int L = 200100;
    vector<int> A(N), bunpu(L);
    vector<vector<int64_t>> B(L,vector<int64_t>(2,0));
    rep(i,N){
        cin >> A.at(i);
        bunpu.at(A.at(i))++;
    }
    int64_t x;
    int64_t sum = 0;
    rep(i,L){
        if(i != 0){
            x = bunpu.at(i);
            B.at(i).at(0) = x*(x-1)/2;
            B.at(i).at(1) = (x-1)*(x-2)/2;
            sum += B.at(i).at(0);
        }
    }
    rep(i,N){
        cout << sum - B.at(A.at(i)).at(0) + B.at(A.at(i)).at(1) << endl;
    }
}   

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

int main(){
  int A , B , C , D;
  
  cin >> A >> B >> C >> D;
  
  if( A + B > C + D){
    cout << "Left" << endl;
  }
  if ( A + B == C + D){
    cout << "Balanced" << endl;
  }
  if ( A + B < C + D ){
    cout << " Right" << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

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

	int a;
	cin>>a;
	vector<string> v(a+15);
	forr(i,1,10)
		v[i]=to_string(i);
	int k=1,l=10;
	while(l<=a)
	{
		int x=v[k].back()-'0';
		if(x==0)
		{
			v[l++]=v[k]+char('0'+x);			
			v[l++]=v[k]+char('0'+x+1);	
		}
		else if(x==9)
		{
			v[l++]=v[k]+char('0'+x-1);
			v[l++]=v[k]+char('0'+x);
		}
		else
		{
			v[l++]=v[k]+char('0'+x-1);
			v[l++]=v[k]+char('0'+x);
			v[l++]=v[k]+char('0'+x+1);
		}
		if(l>a)	break;
		k++;
	}
	cout<<v[a];
	
	return 0;	
}

Measured memory_bytes: 6912
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif
ll N, A;
vl X;
vector<vvl> dp;
ll dfs(int n, ll sum, ll cnt) {
    if (n >= N) {
        if (cnt > 0 && sum == A * cnt) return 1;
        else return 0;
    }

    if (dp[n][sum][cnt] >= 0) return dp[n][sum][cnt];

    ll res = 0;
    res += dfs(n + 1, sum, cnt);
    res += dfs(n + 1, sum + X[n], cnt+1);

    dp[n][sum][cnt] = res;

    return res;
}

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

    cin >> N >> A;
    X = vl(N); REP(i, N) cin >> X[i];

    dp = vector<vvl>(N + MGN, vvl(50*N + MGN, vl(N+MGN, -1)));
    ll ans = dfs(0, 0, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 73088
#include<iostream>
#include<cstdio>
#include<queue>
const int N=55,INF=1e6;
char s[N][N];
const int fx[4]={1,-1,0,0},fy[4]={0,0,1,-1};
int h,w,d[N][N];
struct Node {
    int x,y;
    Node(int x=0,int y=0):x(x),y(y){}
};
std::queue<Node> q;
void bfs() {
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) d[i][j]=INF;
    d[1][1]=0;q.push(Node(1,1));
    while(!q.empty()) {
        Node c=q.front();q.pop();
        for(int i=0;i<4;i++) {
            int tx=c.x+fx[i],ty=c.y+fy[i];
            if(tx<1||ty<1||tx>h||ty>w||s[tx][ty]=='#'||d[tx][ty]<=d[c.x][c.y]+1) continue;
            d[tx][ty]=d[c.x][c.y]+1;q.push(Node(tx,ty));
        }
    }
    if(d[h][w]>=INF) printf("%d\n",-1);
    else {
        int ans=h*w-d[h][w]-1;
        for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans-=(s[i][j]=='#');
        printf("%d\n",ans);
    }
}
int main() {
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++) scanf("%s",s[i]+1);
    bfs();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int max_h = 0, sum = 0;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    max_h = max(h, max_h);
    if (max_h == h) {
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int A, B; cin >> A >> B;
	int ans = max(0, A-B*2);

	cout << ans << endl;



	return 0;

}


Measured memory_bytes: 256