akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

const double PI = 3.14159265358979;

double slope(P a, P b) {
	if (a.first != b.first) return (double)(a.second - b.second) / (double)(a.first - b.first);
	return (double)INF;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	map<P, int> mp;
	rep(i, n) mp[p[i]] = i;
	sort(all(p));
	int k = 0;
	vector<P> q(n * 2);
	rep(i, n) {
		while (k > 1 && slope(q[k - 2], q[k - 1]) >= slope(q[k - 1], p[i]) - EPS) k--;
		q[k] = p[i]; k++;
	}
	int t = k;
	for (int i = n - 2; i >= 0; i--) {
		while (k > t && slope(q[k - 2], q[k - 1]) >= slope(q[k - 1], p[i]) - EPS) k--;
		q[k] = p[i]; k++;
	}
	q.resize(k);
	vector<double> ans(n);
	if (k == 3) {
		ans[mp[q[0]]] = 0.5;
		ans[mp[q[1]]] = 0.5;
	}
	else {
		rep(i, k - 1) {
			int pre = i - 1;
			if (i == 0) pre = k - 2;
			double d = atan(slope(q[i], q[i + 1])) - atan(slope(q[pre], q[i]));
			if (d < 0) d += PI;
			ans[mp[q[i]]] = d * 0.5 / PI;
		}
	}
	for (double i : ans) cout << i << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,k,s;
  cin>>n>>k>>s;
  for(int i=0; i<k; i++){
    cout<<s<<" ";
  }
  if(s==1000000000){
    s=s-2;
  }
  for(int i=k; i<n; i++){
    cout<<s+1<<" ";
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int main(){
	int n;
	scanf("%d", &n);
	int min = 10000, max = 0, t, A[10001]{};
	r(i, n){
		scanf("%d", &t);
		if(t < min) min = t;
		if(t > max) max = t;
		A[t]++;
	}
	A[min]--;
	cout << min;
	for(int i = min; i <= max; i++){
		r(j, A[i]){
			cout << ' ' << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>

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

using namespace std;

int main()
{
    unordered_map<string, int> ump;
    int N, M;
    int ans = 0;
    cin >> N;
    REP(i, N) {
        string s;
        cin >> s;
        ump[s]++;
    }
    cin >> M;
    REP(i, M) {
        string t;
        cin >> t;
        if (ump.count(t) == 1) {
            ump[t]--;
        }
    }
    for (auto itr : ump) {
        if (itr.second > ans) {
            ans = itr.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
m = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
  u, k, *v = map(int, input().split())
  for j in v:
    m[u-1][j-1] = 1
for i in range(n):
  print(" ".join(map(str,m[i])))


Measured memory_bytes: 5680
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("SUN", 7);
        map.put("MON", 6);
        map.put("TUE", 5);
        map.put("WED", 4);
        map.put("THU", 3);
        map.put("FRI", 2);
        map.put("SAT", 1);
        println(map.get(in.next()));
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21332
n = int(input())

jpy = 0
btc = 0

for i in range(n):
  s = input().split()
  a = float(s[0])
  b = s[1]
  if b == 'JPY':
    jpy += a
  elif b == 'BTC':
    btc += a

btc = btc * 380000
print(jpy + btc)

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

int main(){
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    vector<int> interval(N);
    for ( int i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    
    int intvl;
    for ( int i = 0; i < N-1; ++i){
        intvl = A.at(i+1) - A.at(i);
        interval.at(i) = intvl;
    }
    interval.at(N-1) = A.at(0) + K - A.at(N-1);
    
    int max;
    max = *max_element(interval.begin(), interval.end());
    
    cout << K - max << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;

int H, W;
ll dp[1005][1005];
char grid[1005][1005];

int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> H >> W;
    F0R(i,H) F0R(j,W) cin >> grid[i][j];
    dp[0][0] = 1;
    F0R(i,H){
        F0R(j,W){
            if (grid[i][j] == '#') continue;
            if (i >= 0 && j >= 1 && grid[i][j-1] == '.') dp[i][j] = (dp[i][j-1] + dp[i][j]) % INF;
            if (i >= 1 && j >= 0 && grid[i-1][j] == '.') dp[i][j] = (dp[i-1][j] + dp[i][j]) % INF;
        }
    }
    finish(dp[H-1][W-1]);













	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
    A.at(i)--;
  }

  vector<ll> B(N);
  for (ll i = 0; i < N; i++)
  {
    B.at(A.at(i))++;
  }

  ll ans0 = 0;
  for (ll i = 0; i < N; i++)
  {
    ll tmp = B.at(i) * (B.at(i) - 1) / 2;
    ans0 += tmp;
  }

  for (ll i = 0; i < N; i++)
  {
    ll a = A.at(i);
    ll b = B.at(a);

    ll ans = ans0;
    ans -= b * (b - 1) / 2;
    ans += (b - 1) * (b - 2) / 2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-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 a[4];

int main() {
    rep(i, 4) cin >> a[i];
    sort(a, a+4);
    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    vector<vector<char>> a(H, vector<char>(W));
    REP(i, H){
        REP(j, W){
            cin >> a[i][j];
        }
    }

    vector<bool> HC(H, false);
    vector<bool> WC(W, false);

    REP(i, H){
        REP(j, W){
            if(a[i][j] == '#'){
                HC[i] = true;
                WC[j] = true;
            }
        }
    }

    REP(i, H){
        REP(j, W){
            if(HC[i] && WC[j]){
                cout << a[i][j];
            }
        }
        if(HC[i]) cout << endl;
    }
    return 0;
}

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

int K, X, ans;
int cnt = 1;

int main(){
  cin >> K;

    rep(i, K){
      X = (X*10 + 7) % K;
    if (X % K == 0) {
      ans = cnt;
      break;
    }
    cnt ++;
  }
  if (X % K == 0)  cout << ans << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main(){
	int N,r=0,b=0;
	cin >> N;
	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='R') r+=1;
		else b+=1;
	}
	if(r>b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll n;
    cin >> n;
    ll ans = 0;
    ll numa = 0, numb = 0, numab = 0;
    for(ll i=0;i<n;i++){
        string s;
        cin >> s;
        for(ll j=0;j<s.length()-1;j++){
            if(s[j] == 'A' and s[j+1] == 'B'){
                ans++;
            }
        }
        if(s[s.length()-1] == 'A' and s[0] == 'B'){
            numab++;
        }else if(s[s.length()-1] == 'A'){
            numa++;
        }else if(s[0] == 'B'){
            numb++;
        }
    }
//    cout << numa << numb << endl;
//    cout << ans << endl;
//    ll l = max(numa, numb);
//    ll s = min(numa, numb);
//    if((l-s) >= numab){
//        ans += s + numab;
//    }else{
//        ans += (l+s+numab)/2;
//    }
    ll fina = numa + numab;
    ll finb = numb + numab;
    if(numa == 0){
        finb--;
    }
    if(numb == 0){
        fina--;
    }

    cout << max(0LL,min(fina, finb)) + ans << endl;
}

Measured memory_bytes: 256
local mma, mmi = math.max, math.min
local mfl, mce = math.floor, math.ceil
local function comp(a, b)
  return a < b
end
local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[1]) then return 1 end
  if not comp(x, ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, W = io.read("*n", "*n")
local v, w = {}, {}
local low_w = true
for i = 1, n do
  w[i], v[i] = io.read("*n", "*n")
end

local function solve_low_w()
  local t = {}
  for i = 1, W do t[i] = 0 end
  for i = 1, n do
    for j = W - w[i], 1, -1 do
      if 0 < t[j] then
        t[j + w[i]] = mma(t[j + w[i]], t[j] + v[i])
      end
    end
    t[w[i]] = mma(t[w[i]], v[i])
  end
  local ret = 0
  for i = 1, W do ret = mma(ret, t[i]) end
  return ret
end

local function solve_low_v()
  local t = {}
  for i = 1, 200000 do t[i] = 0 end
  local v_cursum = 0
  for i = 1, n do
    local vlim = mmi(v_cursum, 200000 - v[i])
    for j = vlim, 1, -1 do
      if 0 < t[j] then
        if t[j + v[i]] == 0 then
          t[j + v[i]] = t[j] + w[i]
        else
          t[j + v[i]] = mmi(t[j + v[i]], t[j] + w[i])
        end
      end
    end
    if t[v[i]] == 0 then
      t[v[i]] = w[i]
    else
      t[v[i]] = mmi(t[v[i]], w[i])
    end
    v_cursum = v_cursum + v[i]
  end
  local ret = 0
  for i = 200000, 1, -1 do
    if 0 < t[i] and t[i] <= W then ret = i break end
  end
  return ret
end
print(solve_low_v())


Measured memory_bytes: 2304
def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]
cmb[0][0]=1
for i in range(51):
    for j in range(51):
        if i!=50 and j!=50:
            cmb[i+1][j+1]+=cmb[i][j]
        if i!=50:
            cmb[i+1][j]+=cmb[i][j]

for i in range(1,51):
    for j in range(2,51):
        cmb[i][j]+=cmb[i][j-1]

N,K,T,S=map(int,input().split())
a=list(map(int,input().split()))

must0=[i for i in range(18) if S>>i &1==0]
must1=[i for i in range(18) if T>>i &1==1]

A=[]
for val in a:
    check=True
    for j in must0:
        check=check&(val>>j &1==0)
    for j in must1:
        check=check&(val>>j &1==1)
    if check:
        A.append(val)

if not A:
    print(0)
    exit()

bit=[]
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)

for i in range(len(A)):
    temp=0
    for j in range(len(bit)):
        temp+=(A[i]>>bit[j] &1==1)*2**j
    A[i]=temp

ans=0
n=len(bit)
data=[0]*(2**n)
for i in range(2**n):
    t=set([])
    for a in A:
        data[a&i]+=1
        t.add(a&i)
    temp=0
    for val in t:
        temp+=cmb[data[val]][min(K,data[val])]
    ans+=temp*(-1)**popcount(i)
    for val in t:
        data[val]=0

print(ans)


Measured memory_bytes: 76468
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  int M;
    int C;
  cin >>N>>M>>C;
  vector<int> vec(M);
  rep(i,M) {
cin >>vec.at(i);
  }
  
  int data[N][M];
  rep(i,N) {
rep(j,M) {
cin >>data[i][j];
}
  }

  int count=0;
  rep(i,N) {
    int sum=C;
    rep(j,M) {
      sum +=data[i][j]*vec.at(j);
    }
    if(sum>0) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  int a,b;
  cin >> a>>b;
  
  vector<string> p(a);
 
  rep(i,b+2){
  cout << "#";
  }
  cout << endl;
  
  rep(i,a){
    cout << "#";
    cin >>p[i];
    cout << p[i];
    cout << "#" << endl;
  }
  
  rep(i,b+2){
    cout << "#";
  }
  cout << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define int long long

#define PI pair <ll, ll>
#define f first
#define s second

using namespace std;

typedef long long ll;

ll n, A[400010], L[400010], R[400010];

signed main() {
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++) scanf("%lld", &A[i]);
    vector <PI> V(0);
    V.push_back(PI(1, ll(9e18)));
    ll ans = 0;
    for(int i = 2; i <= n; i++) {
        ll a = A[i - 1], b = A[i];
        if(a > b) {
            ll cnt = 0;
            while(b * 4 <= a) b *= 4, cnt++;
            if(cnt) V.push_back(PI(i, cnt));
        } else {
            while(a < b) {
                ans += (i - V.back().f);
                if(!--V.back().s) V.pop_back();
                a *= 4;
            }
        }
        L[i] = ans;
    }
    V.clear();
    V.push_back(PI(n, ll(9e18)));
    ans = 0;
    for(int i = n - 1; i >= 1; i--) {
        ll a = A[i + 1], b = A[i];
        if(a > b) {
            ll cnt = 0;
            while(b * 4 <= a) b *= 4, cnt++;
            if(cnt) V.push_back(PI(i, cnt));
        } else {
            while(a < b) {
                ans += (V.back().f - i);
                if(!--V.back().s) V.pop_back();
                a *= 4;
            }
        }
        R[i] = ans;
    }
    ll nwans = 9e18;
    for(int i = 1; i <= n + 1; i++) nwans = min(nwans, (L[i - 1] + R[i]) * 2 + (i - 1));
    printf("%lld\n", nwans);
    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
int m , n , i , j , k;
char a , b , c;
int main(){
	scanf("%c%c%c" , &a , &b , &c);
	if(a == 'A' && b == 'B' && c == 'C') printf("ARC");
	else printf("ABC");
	return 0;
} 

Measured memory_bytes: 3752
//116B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
   int s = 0, tmp=0;
   cin >> s;
   vector<int>L{s};
   while(true){
       //cout << L.back() << endl;
       if(L.back()%2==0){
           L.push_back(L.back()/2);
       }else{
           L.push_back(3*L.back() +1);
       }
       tmp = count(L.begin(), L.end(), L.back());
       if(tmp==2){
           cout << L.size()<< endl;
           break;
       }
     
       }
}

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

char invert(char c){
    if(!isalpha(c)) return c;
    return islower(c)?toupper(c):tolower(c); 
}

int main(){
    char x[1001];
    while(true){
        scanf("%s", x);
        if(x[0] == '0' && x[1] == '\0') break;
        int ans = 0;
        int i = 0;
        while(x[i]){
            ans += x[i] - '0';
            i++;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3216
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func isSorted(p []int) bool {
	for i := 0; i < len(p); i++ {
		if p[i] != i+1 {
			return false
		}
	}

	return true
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt()
	}

	if isSorted(p) {
		fmt.Println("YES")
		return
	}

	pc := make([]int, n)

	for i := 0; i < n-1; i++ {
		for j := i+1; j < n; j++ {
			copy(pc, p)
			pc[i], pc[j] = pc[j], pc[i]
			if isSorted(pc) {
				fmt.Println("YES")
				return
			}
		}
	}

	fmt.Println("NO")
}

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

Measured memory_bytes: 6336
#include <iostream> // cout, endl, cin
#include <iomanip>
#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 <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int64_t N, M;
    cin >> N >> M;
    int64_t ans = abs(N - 2) * abs(M - 2);
    cout << ans << endl;
}

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

int main(void){
    int A,B,C,X; cin >> A >> B >> C >> X;
    int ans=0;

    for(int x=0; x<=A; x++){
        for(int y=0; y<=B; y++){
            for(int z=0; z<=C; z++){
                if(500*x+100*y+50*z==X) ans++;
            }
        }
    }

    cout << ans << endl;
}

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


const int N=1e5+10;


int n,m;
vector<int>A[N],B[N];
int a[N],b[N];

int tot,cnt;
int La[N],Ne[N<<1],To[N<<1],Col[N<<1],Val[N<<1];
int Sz[N],Dep[N],D[N],fa[N][20],Top[N],Son[N],dfn[N];
int X[N],Y[N],U[N],V[N],Ans[N],C[N],pos[N],vis[N];

void Add(int x,int y,int c,int d)
{
	tot++;
	To[tot]=y;
	Col[tot]=c;
	Val[tot]=d;
	Ne[tot]=La[x];
	La[x]=tot;
}


void dfs1(int x)
{
	Sz[x]=1;
	for(int j=La[x];j;j=Ne[j])
	{
		int v=To[j];
		if(!Sz[v])
		{
			fa[v][0]=x;
			D[v]=Val[j];
			C[v]=Col[j];
			Dep[v]=Dep[x]+1;
			dfs1(v);
			Sz[x]+=Sz[v];
			if(Sz[v]>Sz[Son[x]]) Son[x]=v;
		}
	}
}

void dfs2(int x,int top)
{
	dfn[x]=++cnt;
	pos[x]=top;
	if(Sz[x]>1) dfs2(Son[x],top);
	for(int j=La[x];j;j=Ne[j])
	{
		int v=To[j];
		if(Dep[v]>Dep[x]&&v!=Son[x]) dfs2(v,v);
	}
}

int lca(int x,int y)
{
	if(Dep[x]<Dep[y]) swap(x,y);
	int k=Dep[x]-Dep[y];
	for(int i=0;i<=17;i++) if(k&(1<<i)) x=fa[x][i];
	if(x==y) return x;
	for(int i=17;i>=0;i--) 
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}

int tr[N<<2],g[N<<2];

void Change(int x,int l,int r,int v,int dis,int opt)
{
	if(l==r)
	{
		tr[x]=dis;
		g[x]=opt;
		return;
	}
	int mid=l+r>>1;
	if(v<=mid) Change(x<<1,l,mid,v,dis,opt);
	else Change(x<<1|1,mid+1,r,v,dis,opt);
	tr[x]=tr[x<<1]+tr[x<<1|1];
	g[x]=g[x<<1]+g[x<<1|1];
}

int S1,S2;

void Ask(int x,int l,int r,int ql,int qr)
{
	if(l==ql&&r==qr)
	{
		S1+=tr[x];
		S2+=g[x];
		return;
	}
	int mid=l+r>>1;
	if(qr<=mid) Ask(x<<1,l,mid,ql,qr);
	else if(ql>mid) Ask(x<<1|1,mid+1,r,ql,qr);
	else Ask(x<<1,l,mid,ql,mid),Ask(x<<1|1,mid+1,r,mid+1,qr);
}

void Q1(int x,int f)
{
	while(pos[x]!=pos[f])
	{
		Ask(1,1,n,dfn[pos[x]],dfn[x]);
		x=fa[pos[x]][0];
	}
	Ask(1,1,n,dfn[f],dfn[x]);
}

void Q(int x,int y)
{
	S1=0,S2=0;
	int t=lca(x,y);
	//cout<<"a "<<x<<' '<<y<<' '<<t<<endl;
	Q1(x,t);
	Q1(y,t);
	if(vis[t]) S2-=2;
	else S1-=D[t]*2;
}
	

int main()
{
	cin>>n>>m;
	for(int i=1;i<n;i++)
	{
		int x,y,c,d;
		scanf("%d%d%d%d",&x,&y,&c,&d);
		Add(x,y,c,d);
		Add(y,x,c,d);
	}
	dfs1(1);
	for(int i=0;i<=16;i++) 
		for(int j=1;j<=n;j++) fa[j][i+1]=fa[fa[j][i]][i];
	dfs2(1,1);
	for(int i=2;i<=n;i++) Change(1,1,n,dfn[i],D[i],0);
	for(int i=1;i<=n;i++) A[C[i]].push_back(i);
	for(int i=1;i<=m;i++)
		scanf("%d%d%d%d",&X[i],&Y[i],&U[i],&V[i]);
	for(int i=1;i<=m;i++) B[X[i]].push_back(i);
	for(int i=1;i<n;i++) a[i]=A[i].size(),b[i]=B[i].size();
	for(int i=1;i<n;i++)
	{
		if(!b[i]) continue;
		for(int j=0;j<a[i];j++)
		{
			int x=A[i][j];
			vis[x]=1;
			Change(1,1,n,dfn[x],0,1);
		}
		for(int j=0;j<b[i];j++)
		{
			int x,y,dis;
			x=V[B[i][j]],y=U[B[i][j]],dis=Y[B[i][j]];
			Q(x,y);
			//cout<<"A "<<B[i][j]<<' '<<S1<<' '<<S2<<endl;
			Ans[B[i][j]]=S1+dis*S2;
		}
		for(int j=0;j<a[i];j++)
		{
			int x=A[i][j];
			vis[x]=0;
			Change(1,1,n,dfn[x],D[x],0);
		}
	}
	for(int i=1;i<=m;i++) printf("%d\n",Ans[i]);
}
	
	
 

Measured memory_bytes: 32124
#include <algorithm>
#include <cstdio>
typedef long long ll; 
const ll INF = 1e18; 
int arr[100005]; 
char op[100005]; 
ll dp[100005][3]; 
int main()
{
	// freopen("ARC066-E.in", "r", stdin); 
	int n;
	scanf("%d", &n); 
	for (int i = 0; i < n - 1; i++)
		scanf("%d %c", arr + i, op + i); 
	scanf("%d", arr + n - 1); 
	dp[0][0] = arr[0]; 
	dp[0][1] = dp[0][2] = -INF; 
	for (int i = 1; i < n; i++)
	{
		if (op[i - 1] == '+')
		{
			dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]) + arr[i];
			dp[i][1] = dp[i - 1][1] - arr[i]; 
			dp[i][2] = dp[i - 1][2] + arr[i]; 
		}
		else
		{
			dp[i][0] = -INF; 
			dp[i][1] = std::max(dp[i - 1][0], dp[i - 1][1]) - arr[i]; 
			dp[i][2] = std::max(dp[i - 1][1], dp[i - 1][2]) + arr[i]; 
		}
	}
	printf("%lld\n", std::max(dp[n - 1][0], std::max(dp[n - 1][1], dp[n - 1][2])));
	return 0; 
}


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

int main()
{
    int n;cin>>n;
    string s;cin>>s;
    int i;
    for(i=0;i<s.length();i++)
    {
        if(s.at(i)+n<='Z')cout<<char(s.at(i)+n);
        else cout<<char(s.at(i)+n-26);
    }
    cout<<endl;
}


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

int main(){
    char S[10];
    int i, j, len;
    long long int a, ans=0;

    scanf("%s", S);
    len = strlen(S);

    for(i=0; i<(1<<(len-1)); i++){
        a = S[0] - '0';

        for(j=0; j<len-1; j++){
            if((i>>j) & 1){
                ans += a;
                a=0;
            }
            a = a*10 + S[j+1]-'0';
        }
        ans += a;   
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  int ans = 1, tmp = a.front();
  bool up = true, down = true;
  FOR(i, 1, n) {
    if (up && down) {
      if (tmp > a[i]) up = false;
      else if (tmp < a[i]) down = false;
    } else if (up) {
      if (tmp > a[i]) {
        ++ans;
        up = down = true;
      }
    } else if (down) {
      if (tmp < a[i]) {
        ++ans;
        up = down = true;
      }
    }
    tmp = a[i];
  }
  cout << ans << '\n';
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(24) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p(m);
    for (int i = 0; i < m; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    for (int i = 0; i < m; i++)
    {
        if (n >= 2 && p[i].first == 1 && p[i].second == 0)
        {
            cout << -1 << endl;
            return;
        }
    }
    vector<int> number(n, -1);
    for (int i = 0; i < m; i++)
    {
        if (number[p[i].first - 1] == -1)
        {
            number[p[i].first - 1] = p[i].second;
        }
        else
        {
            if (p[i].second != number[p[i].first - 1])
            {
                cout << -1 << endl;
                return;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (n != 1 && i == 0 && number[i] == -1)
        {
            number[i] = 1;
        }
        else if (n != 1 && i == 0 && number[i] == -1)
            number[i] = 0;
        else if (number[i] == -1)
        {
            number[i] = 0;
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << number[i];
    }
    cout << endl;
}

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


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    a,b,c = map(int, input().split())
    k=int(input())
    ans="Yes"
    if b<=a:
        while True:
            if k<=0:
                ans="No"
                break
            k-=1
            b=b*2
            if b>a:
                break
    if c<=b:
        while True:
            if k<=0:
                ans="No"
                break
            k-=1
            c=c*2
            if c>b:
                break
    print(ans)














if __name__ == "__main__":

    main()


Measured memory_bytes: 72820
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n, ret = -1;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int j = (int)(i * 1.08);
    if (j == n) {
      ret = i;
      break;
    }
  }
  if (ret < 0) {
    cout << ":(" << endl;
  } else {
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string s; int k, cnt=0;
    cin >> s >> k;
    for(int i=0; i<k; i++){
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }else{
            cnt++;
        }
    }
    if(cnt==k) cout << 1 << endl;
    return 0;
}

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

int main()
{
    int x,y;
    cin >> x >> y;
    int temp=0;
    for (int i = 0; i <= x; i++)
    {
        temp = x - i;
        if(2*i+4*temp == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int n, m, q;
vector<int> a, b, c, d;

int ans;
void dfs(vector<int> tmp)
{
    if (tmp.size() == n + 1)
    {
        int cnt = 0;
        rep(i, q)
        {
            if (tmp[b[i]] - tmp[a[i]] == c[i])
            {
                cnt += d[i];
            }
        }
        ans = max(ans, cnt);
        return;
    }

    tmp.push_back(tmp.back());
    while (tmp.back() < m + 1)
    {
        dfs(tmp);
        tmp.back()++;
    }
    // int last = tmp.back();
    // for (int i = last; i < m + 1; i++)
    // {
    //     vector<int> tt = tmp;
    //     tt.push_back(i);
    //     dfs(tt);
    // }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> tmp(1, 1);
    dfs(tmp);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN=100005;
const int mod=1e9+7;
char ch[MAXN];
int vis[30];
int main()
{
  int len;scanf("%d",&len);
  scanf("%s",ch+1);
  for(int i=1;i<=len;i++)vis[ch[i]-'a'+1]++;
  int ans=1;
  for(int i=1;i<=26;i++)ans=1LL*ans*(vis[i]+1)%mod;
  ans--;if(ans<0)ans+=mod;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(int argc,char* argv[]){
  double tmp;
  double max=-1.0,min = 999999999.0;

  while(scanf("%lf",&tmp) != EOF){

    if(tmp > max){
      max = tmp;
    }

    if(tmp < min){
      min = tmp;
    }
    
  }

  printf("%.1lf\n",max-min);

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
 
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  double degree, s, l ,h;
  degree = M_PI * c / 180;
  s = a * b * sin(degree) / 2;
  l = a + b + sqrt(a*a + b*b - 2*a*b*cos(degree));
  h = b * sin(degree);
  printf("%lf\n%lf\n%lf\n", s, l, h);
 
  return 0;
}


Measured memory_bytes: 2088
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l)
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    long long X, K, D; cin >> X >> K >> D;
    X = abs(X);
    long long count = X / D;
    if (count < K) {
        if ((K - count - 1) % 2 == 0) {
            X = abs((X-count * D)-D);
        }
        else {
            X = X - count * D;
        }
        cout << X << endl;
    }
    else {
        cout << X - K * D << endl;
    }
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<cstdlib>

#define INFTY 10*10*10*10*10*10*10*10*10+1

void mergeSort(int *, int, int);
void merge(int *, int, int, int);

int n, *A, compN = 0;


int main(){
    int i;
    
    scanf("%d",&n);
    A = (int *)malloc(sizeof(int) * n);
    for(i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }
    
    
    mergeSort(A, 0, n);
    for(i = 0; i < n; i++){
        printf("%d",A[i]);
        if(i == n-1){
            printf("\n");
            break;
        }
        printf(" ");
    }
    
    printf("%d\n",compN);
    
    free(A);
    return 0;
}

void mergeSort(int *A, int left, int right){
    int mid;
    //static int n=-1;
    //n++;
    if(left+1 < right){ // when there are more than 3 elements
        mid = (left + right) / 2;
        mergeSort(A, left, mid);
        //printf("%d  left:%d, mid:%d\n",n,left,mid);
        mergeSort(A, mid, right);
        //printf("%d  mid:%d, right:%d\n",n,mid,right);
        merge(A, left, mid, right);
    }
}



void merge(int *a, int left, int mid, int right){
    int i, j, k;
    int n1, n2;
    int *a1, *a2;
    n1 = mid - left;
    n2 = right - mid;
    a1 = (int *)malloc(sizeof(int) * n1 + 1);
    a2 = (int *)malloc(sizeof(int) * n2 + 1);
    
    for(i = 0; i < n1; i++){
        a1[i] = a[left + i];
    }
    for(i = 0; i < n2; i++){
        a2[i] = a[mid + i];
    }
    // put sentinel into last element
    a1[n1] = INFTY;
    a2[n2] = INFTY;
    
    i = j = 0;
    for(k = left; k < right; k++){
        if(a1[i] < a2[j]){
            a[k] = a1[i];
            i++;
            //printf("%d < %d\n",a1[i],a2[j]);
        }else{
            a[k] = a2[j];
            j++;
            //printf("%d >= %d\n",a1[i],a2[j]);
        }
        compN++;
    }
    
    free(a1);
    free(a2);
}

            
            





Measured memory_bytes: 6276
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        if (N < B) {
            long f = (A * N)/B;
            long b = N/B;
        	System.out.println(f - A * b);
        } else {
        	N = B-1;
            long f = (A * N)/B;
            long b = N/B;
        	System.out.println(f - A * b);
        }
    }
}

Measured memory_bytes: 35528
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

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

    if (h == 1 || w == 1) {
        print(1);
        return 0;
    }
    print((h * w + 1) / 2);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    string s;
    cin >> s;
    vector<ll> l;
    vector<char> lc;
    s += '.';
    int temp = 1;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != s[i - 1]) {
            l.push_back(temp);
            lc.push_back(s[i - 1]);
            temp = 1;
        } else
            ++temp;
    }

    ll ans = 0;
    for (int i = 0; i < l.size(); ++i) {
        ans += l[i] * (l[i] + 1) / 2;
    }
    for (int i = 0; i < lc.size() - 1; ++i) {
        if (lc[i] == '<' && lc[i + 1] == '>') {
            ans -= min(l[i], l[i + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			String inputLine;
			while ((inputLine = br.readLine()) != null) {

				final String[] inputNumbers = inputLine.split(" ");

				final Integer x = Integer.valueOf(inputNumbers[0]);
				final Integer y = Integer.valueOf(inputNumbers[1]);

				List<Integer> list = new ArrayList<>();
				list.add(x);
				list.add(y);

				if(list.stream().allMatch(e-> e.equals(0))) {
					break;
				}

				list.sort(Comparator.naturalOrder());

				System.out.println(list.get(0) + " " + list.get(1));
			}
		}
	}
}


Measured memory_bytes: 33288
n, k = list(map(int, input().split()))

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

res = Base_10_to_n(n, k)
print(len(res))

Measured memory_bytes: 2940