akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(long long, a, b, c, d);
	
	
	
	otp(max({ a * c, a * d, b * c, b * d }));
	
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
unsigned long long num_sum(unsigned long long n)
{
    unsigned long long sum = 0;
    while(n)
    {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int main()
{
    unsigned long long sum = 0,n,a,b,t;
    cin >> n >> a >> b;
    for(unsigned long long i = 1;i <= n;i++)
    {
        t = num_sum(i);
        if(a <= t && t <= b)
        {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

def warshall_floyd(v_count: int, matrix: list) -> list:
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix

A = [LIST() for _ in range(N)]
dist_matrix = warshall_floyd(N, deepcopy(A))

ans = 0
for i, j in combinations(range(N), 2):
    if A[i][j] != dist_matrix[i][j]:
        print(-1)
        break
    for k in range(N):
        if i == k or j == k:
            continue
        if A[i][k] + A[k][j] == A[i][j]:
            break
    else:
        ans += A[i][j]
else:
    print(ans)


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

 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a[n][m];
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
 
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    vector <ll> amari_10s = {1};
    REP(i, 223){
        ll num = (amari_10s[i] * 10)%2019;
        amari_10s.push_back(num);
    }
    string s; cin >> s;
    vector <ll> nums;
    ll n = 0;
    for(auto c: s){
        ll dig = c - '0';
        nums.push_back(dig);
        n++;
    }
    reverse(nums.begin(), nums.end());
    vector <ll> amaris = {0};
    REP(i, n){
        ll num = (amaris[i] + amari_10s[i%224] * nums[i]) % 2019;
        amaris.push_back(num);
    }
    map<ll,ll> m;
    REP(i, n+1){
        m[amaris[i]]++;
    }
    ll ans = 0;
    for(auto p: m){
        ans += p.second * (p.second-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long long n, m, d;
long long F[100005][2];
vector <long long> V[100005];

int main()
{
	long long x;
	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			cin >> x;
			F[x][0] = i;
			F[x][1] = j;
		}
	for (int i = 0; i < d; i++)
	{
		long long last = i;
		x = i+d;
		long long sum = 0;
		while (x <= n*m)
		{
			V[i].push_back(sum);
			if (last == 0)
				sum = 0;
			else
				sum += abs(F[last][0] - F[x][0]) + abs(F[last][1] - F[x][1]);
			last = x;
			x += d;
		}
		V[i].push_back(sum);
	}


	int q;
	cin >> q;
	while (q--)
	{
		long long l, r;
		cin >> l >> r;
		cout << V[l%d][r / d] - V[l%d][l / d]<<'\n';
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    string ans = "";
    while(N > 0){
        int md = N % 26;
        if(md == 0) {ans += 'z'; N = N/26 -1;}
        else {ans += 'a' + (md-1); N /= 26;}
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int maxn = 101111;
vector<pair<int,int> >graph[maxn];
bool vis[maxn];
int dis[maxn];

bool dfs(int u)
{
	vis[u] = true;
	for(int i = 0; i < graph[u].size(); i++)
	{
		int v = graph[u][i].first;
		long long c = graph[u][i].second;
		if(!vis[v])
		{
			dis[v] = dis[u] + c;
			if(!dfs(v))
				return false;
		}
		else
		{
			if(dis[v] != dis[u] + c)
				return false;
		}
	}
	return true;
}


int main()
{

	int n,m;
	scanf("%d %d",&n,&m);
	if(m == 0)
	{
		puts("Yes");
		return 0;
	}
	for(int i = 0 ; i < m ; i++)
	{
		int l,r;
		int d;
		scanf("%d %d %d",&l,&r,&d);
		graph[l].push_back({r,d});
		graph[r].push_back({l,-d});
	}
	for(int i = 1; i <= n ; i++)
	{
		if(!vis[i])
		{
			dis[i] = 0;
			if(!dfs(i))
			{
				puts("No");
				return 0;
			}
		}
	}

	puts("Yes");
	
	return 0;
}

Measured memory_bytes: 12160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i]!=t[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n;
	map<string,int> mp;
	rep(i,n){
		string s;
		cin>>s;
		if(mp.find(s)==mp.end())mp[s]=0;
		mp[s]++;
	}
	cin>>m;
	rep(i,m){
		string s;
		cin>>s;
		if(mp.find(s)==mp.end())mp[s]=0;
		mp[s]--;
	}
	int ans=0;
	for(auto&d:mp){
		chmax(ans,d.sc);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long int ans[100];
	long int  t[100],x[100];
	int n,m,p[100];
	int i,j;
	scanf("%d",&n);
	for (i = 0; i < n; i++)
	{
		scanf("%ld", &t[i]);
	}
	scanf("%d", &m);
	for (i = 0; i < m; i++)
	{
		scanf("%d %ld", &p[i], &x[i]);
	}
	for (i = 0; i < m; i++)
	{
		ans[i] = 0;
		for (j = 0; j < n; j++)
		{
			if (j == (p[i] - 1))
			{
				ans[i] = ans[i] + x[i];
			}
			else ans[i] = ans[i] + t[j];
		}
	}
	for (i = 0; i < m; i++)
	{
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val N = scanner.nextLong()
    val root = Math.sqrt(N.toDouble()).toLong()
    var minDigit = Integer.MAX_VALUE
    (1..root).forEach { sosuu ->
        if (N % sosuu == 0L) {
            val sosuu2 = N / sosuu
            val digit = F(sosuu, sosuu2)
            if (minDigit > digit) {
                minDigit = digit
            }
        }
    }
    println(minDigit)
}

fun F(A: Long, B: Long): Int = Math.max(A.toString().length, B.toString().length)

Measured memory_bytes: 23588
N = int(input())
L = input().split()
flag = 0
total = 0

for i in range(N):
  L[i] = int(L[i])
  total += L[i]

for i in range(N):
  if L[i]*2 >= total:
    print("No")
    flag = 1
    break

if flag == 0:
  print("Yes")

Measured memory_bytes: 9132
<?php
	fscanf(STDIN, "%d %d", $N, $Q);
	$a_array = array();
	$b_array = array();
	$p_array = array();
	$x_array = array();
	for ($i = 1; $i < $N; $i++) {
      fscanf(STDIN, "%d %d", $a, $b);
      $a_array[] = $a;
      $b_array[] = $b;
    }
	for ($i = 1; $i <= $Q; $i++) {
      fscanf(STDIN, "%d %d", $p, $x);
      $p_array[] = $p;
      $x_array[] = $x;
    }
	$tree = array();
	for ($i = 1; $i <= $N; $i++) {
      $tree[$i] = array();
    }

	for ($i = 0; $i < count($a_array); $i++) {
      $tree[$a_array[$i]][] = $b_array[$i];
    }

	$count_sum = array();
	for ($i = 0; $i < $N; $i++) {
      $count_sum[$i+1] = 0;
    }

	for ($i = 0; $i < count($p_array); $i++) {
      $count_sum[$p_array[$i]] += $x_array[$i];
    }

	$result = array();
	for ($i = 0; $i < $N; $i++) {
      $result[$i+1] = 0;
    }

	$result[1] = $count_sum[1];
	for ($i = 1; $i <= $N; $i++) {
      foreach($tree[$i] as $key => $v) {
        $result[$v] = $result[$i] + $count_sum[$v];
      }      
    }

	for ($i = 1; $i < $N; $i++) {
      echo ($result[$i].' ');
    }
	echo ($result[$i]);
?>

Measured memory_bytes: 260596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int par[200020];

int root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = root(par[x]);
	}
}
int main() {
	int n, q, p, a, b;
	int x, y;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
	for (int j = 0; j < q; j++) {
		cin >> p >> a >> b;
		if (p == 0) {
			x = root(a);
			y = root(b);
			if (x != y) {
				par[x] = y;
			}
		}
		else {
			if (root(a) == root(b)) {
				cout << "1" << endl;
			}
			else {
				cout << "0" << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4348
// 解き直し.
// ABC 136解説
// https://img.atcoder.jp/abc136/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int N;
LL K, S, A[505], G;

// 与えられた正の整数のすべての約数を抽出.
// @param X: 約数を抽出したい正の整数.
// @return ret: すべての約数.
vector<LL> div(LL X){
    vector<LL> ret;
    ret.push_back(1);
    for(LL d = 2; d * d <= X; d++){
        if(X % d == 0){
            ret.push_back(d);
            if(d * d != X) ret.push_back(X / d);
        }
    }
    ret.push_back(X);
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){

    // 1. 入力情報取得.
    scanf("%d %llu", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%llu", &A[i]);
        S += A[i];
        if(i == 0) G = A[i];
        else       G = __gcd(G, A[i]);
    }
    
    // 2. 解説通り.
    // S の 約数 を 計算.
    vector<LL> divisors = div(S);
    
    // 3. 各約数について, 操作の回数を計算.
    LL ans = G;
    for(auto &d : divisors){
        // 3-1. 各 A[i] を d で 割った余り を 確認.
        priority_queue<LL> r;
        for(int i = 0; i < N; i++) if(A[i] % d != 0) r.push(A[i] % d);
        
        // 3-2. d を 正にするもの, 負にするもの を 集計.
        int l = r.size();
        LL dPlus[l], dMinus[l];
        int index = 0;
        while(!r.empty()){
            // 余りを取得.
            LL v = r.top();
            r.pop();
            
            // d を 正 にする.
            dPlus[l - index - 1]  = d - v;
            // d を 負 にする.
            dMinus[l - index - 1] = -v;
            
            // index を increment.
            index++;
        }
        
        // 3-3. 前項で集計した結果の累積和を計算.
        // d を 正 にする.
        LL pCum[l];
        pCum[l - 1] = dPlus[l - 1];
        for(int i = l - 2; i >= 0; i--) pCum[i] = pCum[i + 1] + dPlus[i];
        
        // d を 負 にする.
        LL mCum[l];
        mCum[0] = dMinus[0];
        for(int i = 1; i < l; i++) mCum[i] = mCum[i - 1] + dMinus[i];
        
        // 3-4. 前項の累積和から, 操作回数が, K回以内で実現できるかをチェック.
        for(int i = 0; i < l - 1; i++){
            if(pCum[i + 1] + mCum[i] == 0 && pCum[i + 1] <= K){
                // 操作後の A の 全要素を割り切る正の整数について, 最大値を更新.
                ans = max(ans, d);
                break;
            }
        }
    }
    
    // 4. 出力 ～ 後処理.
    printf("%llu", ans);
    return 0;

}

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

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) {
        int a = scanner.nextInt() - 1;
        int b = scanner.nextInt() - 1;
        System.out.println((b + a - 1) / a);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    for(ll i=k;i<n;++i){
        if(a[i-k] >= a[i]){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 6424
def omoti(nums)
  min = 0
  stages = 0
  new_nums = nums.sort.reverse
  for i in 0..(new_nums.size - 1)
    if new_nums[i] == 0
      break
    end
    if i == 0
      min = new_nums[i]
      stages += 1
    end
    if new_nums[i] < min
      min = new_nums[i]
      stages += 1
    end
  end
  return stages
end

i = gets.to_i
#連続で書かれる数字を改行コード無しの配列に変換する
line = readlines.map {|e| e.chop.to_i}
puts omoti(line)

Measured memory_bytes: 1788
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
    while True:
        if a[i] + a[i-1] > x:
            if a[i] != 0:
                t = min((a[i] + a[i-1] - x), a[i])
                a[i] -= t
                cnt += t
            else:
                t = min((a[i] + a[i-1] - x), a[i-1])
                a[i-1] -= t
                cnt += t
        else:
            break
print(cnt)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main(){
    int r,c;
    cin>>r>>c;
    int a[r+1][c+1];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>a[i][j];
        }
    }
    for(int k=0;k<r+1;k++){
        a[k][c]=0;
    }
    
    for(int k=0;k<c+1;k++){
        a[r][k]=0;
    }
    
    for(int k=0;k<r;k++){
        for(int l=0;l<c;l++){
            a[k][c]+=a[k][l];
        }
    }
    for(int l=0;l<=c;l++){
        for(int k=0;k<r;k++){
            a[r][l]+=a[k][l];
        }
    }
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            cout<<a[i][j];
            if(j<c)cout<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3064
n=int(input())
a=[int(i) for i in input().split()]
#print(" ".join(list(map(str,a))))
for i in range(n):
    x=a[i]
    for j in range(i):
        if a[i-j-1]>a[i-j]:
            a[i-j-1],a[i-j]=a[i-j],a[i-j-1]
        else:
            break
    print(" ".join(list(map(str,a))))



Measured memory_bytes: 5612
n = int(input())
s = list(input())
t = list(input())

if s == t:
  print(n)
else:
  ans = n
  for i in range(n):
      if s[i:] == t[: - i]:
          print(ans)
          break
      else:
          ans += 1
  else:
      print(ans)


Measured memory_bytes: 9108
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int r, c;
int f[100000];

int convert(int x, int y) {
    if (y == 0) return x;
    if (x == r) return r + y;
    if (y == c) return r + c + r - x;
    return r + c + r + c - y;
}

int main() {
    int n, i;
    vector <pair<int, int> > v;
    vector <int> w;
    
    scanf("%d %d %d", &r, &c, &n);
    
    for (i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        
        if (x1 != 0 && x1 != r && y1 != 0 && y1 != c) continue;
        if (x2 != 0 && x2 != r && y2 != 0 && y2 != c) continue;
        
        v.push_back(make_pair(convert(x1, y1), i));
        v.push_back(make_pair(convert(x2, y2), i));
    }
    
    sort(v.begin(), v.end());
    
    for (i = 0; i < v.size(); i++) {
        int x = v[i].second;
        
        if (f[x] == 1) {
            if (w.back() != x) {
                puts("NO");
                
                return 0;
            }
            
            w.pop_back();
            f[x] = 0;
        } else {
            w.push_back(x);
            f[x] = 1;
        }
    }
    
    puts("YES");
    
    return 0;
}


Measured memory_bytes: 2672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y,z,w;
	cin >> x>> y>> z>>w;
    int ans;
    if(x*y<z*w)ans=z*w;
    else ans = x*y;
      cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);

  string ans = "";
  rep(i, b){
    ans += to_string(a);
  }
  cout << ans << endl;
  return 0;
}

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

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

  int cnt = 0;
  rep(i, 3){
    if (s[i] == 'R'){
      cnt++;
    }
  }
  if (cnt == 2 && s[1] != 'R') {
    cnt = 1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

const ll MAX = 1000010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

signed main(){
    COMinit();

    ll n,k,ans;cin>>n>>k;
    ans=k;
    vector<vector<ll>> E(n+1,vector<ll>(0));//辺
    vector<bool> v(n+1,true);
    for(int i=0;i < n-1;i++)
    {
        ll a,b;cin>>a>>b;
        E.at(a).pb(b);
        E.at(b).pb(a);
    }

    stack<ll> q;
    ans*=fac[k-1];ans%=mod;
    if(k-1-siz(E[1])>=0)ans*=finv[k-1-siz(E[1])];ans%=mod;
    
    for(int i=0;i < siz(E[1]);i++)
    {
        q.push(E[1][i]);
    }
    v[1]=false;

    while(q.size()>0){
        ll x=q.top();
        q.pop();
        v[x]=false;

        if(k>=2){
            ans*=fac[k-2];ans%=mod;
        }
        else ans=0;

        if(k-siz(E[x])-1>=0){
            ans*=finv[k-siz(E[x])-1];ans%=mod;
        }
        else ans=0;
        //cout<<ans<<endl;

        for(int i=0;i<siz(E.at(x));i++)
        {
            if(v[E[x][i]]) q.push(E.at(x).at(i));
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 30836
#define scanf_s scanf
#include<stdio.h>
int main(void) {
	int N, x, y, b, p, i, b2, p2, ryokin, flag;
	scanf_s("%d", &N);
	for (i = 0; i < N; i++) {
		scanf_s("%d %d %d %d", &x, &y, &b, &p);
		flag = 1;
		if ((b >= 5) && (p >= 2)) { 
			x *= 0.8; y *= 0.8; flag = 0;
		}	
		ryokin = (b * x) + (p * y);
		b2 = b; p2 = p;
		if (b2 < 5) { b2 = 5; }
		if (p2 < 2) { p2 = 2; }
		if ( (flag) && (ryokin > (b2 * (x * 0.8)) + (p2 * (y * 0.8)))) {
			ryokin = (b2 * (x * 0.8)) + (p2 * (y * 0.8));
		}
		printf("%d\n", ryokin);
	}
	return(0);
}

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

void Swap(int& a, int& b)
{
	int temp = a;
	a = b;
	b = temp;
}

int main()
{
	int N, num = 0, mini;
	int a[100]{};
	cin >> N;

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

	for (int i = 0; i < N; i++)
	{
	    mini = i;
		for (int j = i; j < N; j++)
		{
			if (a[j] < a[mini])
			{
				mini = j;
			}
		}
		if (i != mini)
		{
			Swap(a[i], a[mini]);
			num++;
		}
	}

	for (int i = 0; i < N; i++)
	{
		if (i != N - 1) cout << a[i] << " ";
		else if (i == N -1)cout << a[i] << endl;
	}
	cout << num << endl;
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Map<String,Integer>p=new HashMap<>();
        p.put("SUN",7);
        p.put("MON",6);
        p.put("TUE",5);
        p.put("WED",4);
        p.put("THU",3);
        p.put("FRI",2);
        p.put("SAT",1);
        System.out.println(p.get(new Scanner(System.in).next()));
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <utility>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

namespace BasicMath {
    // 最大公約数を求める(ユークリッドの互除法)
    static UInt GreatestCommonDivisor(UInt a, UInt b);
    // 最小公倍数を求める
    static UInt LeastCommonMultiple(UInt a, UInt b);

    UInt GreatestCommonDivisor(UInt a, UInt b) {
        if (b == 0) {
            return a;
        } else {
            if (a < b) {
                std::swap(a, b);
            }
            return GreatestCommonDivisor(b, a % b);
        }
    }
    UInt LeastCommonMultiple(UInt a, UInt b) {
        Int gcd = GreatestCommonDivisor(a, b);
        return a / gcd * b;
    }
#define GCD GreatestCommonDivisor
#define LCM LeastCommonMultiple

}
using namespace BasicMath;

int main(void) {
    Int n;
    cin >> n;
    Int result = 1;
    Int input;
    for (Int i = 0; i < n; ++i) {
        cin >> input;
        result = LCM(result, input);
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 3584
def bigcmb(N, R, MOD):
    if (R < 0) or (N < R):
        return 0
    R = min(R, N - R)
    fact, inv = 1, 1
    for i in range(1, R + 1):
        fact = (fact * (N - i + 1)) % MOD
        inv = (inv * i) % MOD
    return fact * pow(inv, MOD - 2, MOD) % MOD


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

exc = bigcmb(n, a, mod) + bigcmb(n, b, mod)
print((pow(2, n, mod) - exc - 1) % mod)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAXC 100000
// int dp[100005],a[100005],n,k=2;
//int max(int a, int b, int c){
//	return (max(a, max(b,c)));
//}
// vector<int> adj[100001];
//int count=0;
// bool visited[100001];
void dfs(int node, vector<int>adj[],vector<int>&dp, vector<bool>&visited){
	visited[node] = true;
	for(int i=0;i<adj[node].size();i++){
		if(!visited[adj[node][i]]){
			dfs(adj[node][i], adj, dp, visited);
			
			
		}
		dp[node] = max(dp[node], 1+dp[adj[node][i]]);
	}
}
int longest(vector<int> adj[], int node){
	vector<int> dp(node+1, 0);
	vector<bool>visited(node+1,false);
	for(int i=1;i<=node;i++){
		if(!visited[i])
		    dfs(i, adj, dp, visited);
	}
	int ans=0;
	for(int i=1;i<=node;i++){
		ans = max(ans, dp[i]);
	}
	return ans;
}
int main()
{
	int nodes, edges;cin>>nodes>>edges;
	vector<int> adj[nodes+1];
	for(int i=0;i<edges;i++){
		int x,y;cin>>x>>y;
		adj[x].push_back(y);
	}
	cout<<longest(adj, nodes);
}

Measured memory_bytes: 9472
l, r = input().split()
l = int(l)
r = int(r)

dp = [[[-1 for k in range(2)] for j in range(2)] for i in range(64)]

def bbin(num):
    res = []
    while num:
        res.append(num % 2)
        num //= 2

    return res

numr = bbin(r)
numl = bbin(l)
while len(numl) < len(numr):
    numl.append(0)

def rec(pos, brr, brl):
    global numl, numr, dp
    if pos < 0:
        return 1

    if dp[pos][brr][brl] != -1:
        return dp[pos][brr][brl]

    res = 0
    if brr:
        if brl:
            res = 3 * rec(pos - 1, brr, brl)
        else:
            if numl[pos] == 1:
                res = rec(pos - 1, brr, brl)
            else:
                res += (2 * rec(pos - 1, brr, 0))
                res += rec(pos - 1, brr, 1)
    else:
        if numr[pos] == 1:
            if brl:
                res += (2 * rec(pos - 1, 0, brl))
                res += rec(pos - 1, 1, brl)
            else:
                if numl[pos] == 1:
                    res += rec(pos - 1, 0, brl)
                else:
                    res += rec(pos - 1, 0, 0)
                    res += rec(pos - 1, 0, 1)
                    res += rec(pos - 1, 1, 0)
        else:
            if brl:
                res += rec(pos - 1, 0, brl)
            elif numl[pos] == 0:
                res += rec(pos - 1, 0, 0)

    dp[pos][brr][brl] = res % (10**9 + 7)
    return dp[pos][brr][brl]

c = 0
for i in range(len(numl) - 1, -1, -1):
    if numl[i] == 1:
        c += rec(i - 1, 1 if i < len(numl) - 1 else 0, 0)
        break
    else:
        c += rec(i - 1, 1 if i < len(numl) - 1 else 0, 1)

print(c % (10**9 + 7))

Measured memory_bytes: 3192
import sys
input = sys.stdin.readline

N = int(input())
left = []
right = []
left_inv = []
right_inv = []
for i in range(N):
    L, R = map(int, input().split())
    left.append((R, i))
    right.append((L, i))
    left_inv.append((-L, i))
    right_inv.append((-R, i))

def calc(left, right):
    left.sort(key=lambda p: -p[0])
    right.sort(key=lambda p: p[0])
    used = set()
    x = 0
    ans = 0
    while right or left:
        while right and right[-1][1] in used:
            right.pop()
        if right:
            y, i = right.pop()
            used.add(i)
            if x < y:
                ans += y - x
                x = y
        while left and left[-1][1] in used:
            left.pop()
        if left:
            y, i = left.pop()
            used.add(i)
            if y < x:
                ans += x - y
                x = y
    ans += abs(x)
    return ans

ans = max(calc(left, right), calc(left_inv, right_inv))
print(ans)

Measured memory_bytes: 127492
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
p, q, r = map(int, input().split())
#s = input()
#s,t = input().split()
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

ans = min([p+q, p+r, q+r])

print(ans)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,get_coin;
  
  
  cin >> a >> b;
  
  if ( a > b){
    get_coin = a;
    if ( a-1 >= b){
      get_coin += a-1;
    }
    else{
      get_coin += b;
    }
  }
  else{
    get_coin = b;
    if (b-1>= a){
      get_coin +=b-1;
    }
    else{
      get_coin += a;
    }
  }
  cout << get_coin << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<string.h>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define None cout<<"None"<<endl
#define GREATER cout<<"GREATER"<<endl
#define LESS cout<<"LESS"<<endl
#define EQUAL cout<<"EQUAL"<<endl
typedef long long ll;
using namespace std;

int main() {
	string A,B; cin >> A >> B;
	int a = A.size();
	int b = B.size();
	
	if (a > b) {
		GREATER;
		return 0;
	}
	else if (a < b) {
		LESS;
		return 0;
	}
	else {
		for (int i = 0; i < a; ++i) {
			if (A[i] > B[i]) {
				GREATER;
				return 0;
			}
			if (A[i] < B[i]) {
				LESS;
				return 0;
			}
		}
	}
	EQUAL;
}

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

#define ll long long
#define endl "\n"
#define int ll

const int INF = 2e15;

signed main ()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int h, n;
	cin >> h >> n;

	vector <int> dp(h + 1, INF);
	dp[0] = 0;

	while (n--) {
		int value, cost;
		cin >> value >> cost;

		for (int i = 0; i <= h; i++) {
			int j = min(i + value, h);
			dp[j] = min(dp[j], dp[i] + cost);
		}
	}

	cout << dp[h] << endl;

	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (n) {
        cnt++;
        n /= k;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
//key point is to take one as whole and other two as max diving each other 

ll minarea(ll h ,ll w){
    if(w%3==0)return 0;
    else{
        ll d=1e9;
        for(int i=1;i<w;i++){
            ll a=h*i;
            ll b=(w-i)*(h-h/2);
            ll c=(w-i)*(h/2);
            d=min(d,max({a,b,c})-min({a,b,c}));
        }
        return min(d,h);
    }
}
int main(){
    ll h,w;
    cin>>h>>w;
    cout<<min(minarea(h,w),minarea(w,h))<<endl;
}

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

namespace ITP1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var words = Console.ReadLine().Split(' ');
                var n = int.Parse(words[0]);
                var sum = int.Parse(words[1]);
                if (n == 0 && sum == 0)
                {
                    return;
                }

                var count = 0;
                for (var i = 1; i <= (n - 2); ++i)
                {
                    if (sum < (i + (i + 1) + (i + 2)))
                    {
                        break;
                    }

                    for (var j = i + 1; j <= (n - 1); ++j)
                    {
                        if (sum < (i + j + (j + 1)))
                        {
                            break;
                        }

                        var target = sum - (i + j);
                        if (j < target && target <= n)
                        {
                            ++count;
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 9700
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;

long long a,b,k;
bool flag = false;

int main()
{
    fastIO
    cin>>k;
    cin>>a>>b;
    

    for (int i = 1;i <= 100000;++i)
    {
       long long tmp = i*k;
        if (tmp >= a && tmp <= b) { flag = true; break; }
        else if (tmp > b) { flag = false; break; }
    }
    
    if (flag == true) cout<<"OK"; else cout<<"NG";
}


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cstdio>
#include <string>
#include <utility>
#include <iomanip>
#include <numeric>
#include <functional>
#include <list>
#include <regex>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <climits>
using namespace std;


typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

#define pb(c,num) c.push_back(num)

// loops
#define rep(i,n) for (int i = 0; i < n; ++i)
#define repi(i,k,n) for (int i = k; i <= n; ++i)
#define repr(i,k,n) for (int i = k; i >= n; --i)
#define tr(c, it) \
for(auto it = c.begin(); it != c.end(); ++it)


#define all(c) c.begin(), c.end()

// set,map
#define present(c, element) (c.find(element) != c.end())
//vectors
#define cpresent(c, element) (find(all(c), element) != c.end())





int main(){
    std::ios_base::sync_with_stdio(false);

//    ifstream input;
//    ofstream output;
//    input.open("input.in");
//    output.open("output.out");
    

int a, b;
cin >> a >> b;
if(a <= 9 && a>=1 && b <= 9 && b >=1){
    cout << a*b;
}
else cout << -1;



//    input.close();
//    output.close();
//
    
    return 0;
}
    


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
int bit[1000000];
int n;
int sum(int i){
    int s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}
void add(int i,int x){
    while(i <= n){
        bit[i] += x;
        i += i & -i;
    }
}

int main() {
    string s;
    cin >> s;
    n = s.size();
    int ap[26] = {},aq[26] = {};
    rep(i,0,s.size()){
        ap[s[i]-'a']++;
    }
    int ki = 0;
    rep(i,0,26){
        if(ap[i]%2)ki++;
    }
    if(ki > 1){
        cout << -1 << endl;
        return 0;
    }

//    rep(i,0,26) aq[i] = ap[i];
    string A,B,C;
    rep(i,0,s.size()){
        if(ap[s[i] - 'a'] % 2){
            if (aq[s[i]-'a'] < ap[s[i]-'a'] / 2) {
                aq[s[i]-'a']++;
                A += s[i];
            }else if(aq[s[i]-'a'] == ap[s[i]-'a'] / 2){
                aq[s[i]-'a']++;
                B += s[i];
            }else{
                aq[s[i]-'a']++;
            }
        }else {
            if (aq[s[i]-'a'] < ap[s[i]-'a'] / 2) {
                aq[s[i]-'a']++;
                A += s[i];
            }else{
                aq[s[i]-'a']++;
            }
        }
    }
    C = A;
    reverse(all(C));

    queue<int> chs[26];

    string D = A + B + C;

    rep(i,0,D.size()){
        chs[D[i] - 'a'].push(i);
    }

    vector<int> v;
    rep(i,0,s.size()){
        v.push_back(chs[s[i] - 'a'].front());
        chs[s[i] - 'a'].pop();
    }

    ll ans = 0;

    rep(i,0,n){
        ans += (i - sum(v[i]+1));
        add(v[i]+1,1);
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 3456
#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(map(int,input().split())))
    return x

def str_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np



# main code
S = input()

if S == "SSS":
    print(0)
    exit()
elif S == "SSR" or S == "SRS" or S == "RSS" or S == "RSR":
    print(1)
    exit()
elif S == "SRR" or S == "RRS":
    print(2)
    exit()
else:
    print(3)




Measured memory_bytes: 27100
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;

void solve(){
    ll n, d; cin >> n >> d;
    ll cnt = 0;
    f0(i, n){
        ll a, b; cin >> a >> b;
        if(a*a+b*b <= d*d) cnt++;
    }

    cout << cnt << nl;
}



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


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		int a=in.nextInt();
		int b=in.nextInt();
		out.println(gcd(a, b));
	}

	public static int gcd(int a,int  b){
		if(a==0)
			return b;
		return gcd(b%a, a);
	}
}


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

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

  int m = 1000000000;
  int count = 0;
  int x[n], y[n], h[n];
  while(count < n)
  {
      cin >> x[count] >> y[count] >> h[count];
      count++;
  }

  for(int cx=0; cx<=100; cx++)
  {
    for(int cy=0; cy<=100; cy++)
    {
        int ch;
        for(int i=0; i<n; i++)
        {
            if(h[i] == 0) continue;
            
            ch = max(h[i] + abs(x[i] - cx) + abs(y[i] - cy), 0);
            if(ch > 0) break;
        }

        bool ok = true;
        for(int i=0; i<n; i++)
        {
            if(h[i] != max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0))
            {
                ok = false;
                break;
            }
        }

        if(ok)
        {
            cout << cx << " " << cy << " " << ch;
            return 0;
        }
    }
  }
}

Measured memory_bytes: 256