akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::option::Option;
use std::str::FromStr;

fn solve() -> Option<i32> {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let a: i32 = sc.next();
    let op: char = sc.chars()[0];
    let b: i32 = sc.next();

    match op {
        '+' => Some(a + b),
        '-' => Some(a - b),
        '*' => Some(a * b),
        '/' => Some(a / b),
        _ => None,
    }
}

fn main() {
    while let Some(ans) = solve() {
        println!("{}", ans);
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5036
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int n, t, a,h;
	
	cin >> n >> t >> a;
	int ans = 0;
	int gap = 1 << 30;
	rep(i, n) {
		cin >> h;
		int d = abs((t * 1000 - h * 6) - a * 1000);
		if (gap > d) {
			gap = d;
			ans = i;
		}
	}
	cout << ans+1;
	return 0;
}


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

int main(){
  int n,pre; cin >>n >>pre;
  int cnt = 1, jud = 0;
  int a;
  while(cin >>a){
    if(jud==1 && a<pre) cnt++, jud=0;
    else if(jud==2 && a>pre) cnt++, jud=0;
    else if(jud==0 && a>pre) jud=1;
    else if(jud==0 && a<pre) jud=2;
    pre = a;
  }
  cout << cnt << endl;
  return 0; 
}

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

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

  queue<ll> q;
  for (ll i = 1; i <= 9; i++) q.push(i);

  ll x;
  rep(i, k) {
    x = q.front();
    q.pop();
    if (x % 10 != 0) q.push(10 * x + x % 10 - 1);
    q.push(10 * x + x % 10);
    if (x % 10 != 9) q.push(10 * x + x % 10 + 1);
  }

  cout << x << endl;
  return 0;
}


Measured memory_bytes: 4984
N = int(input())
AList = list(map(int, input().split()))

def getNum(a, b):
    while(True):
        if a == 0:
            return b
        a, b = max(a, b), min(a, b)
        a %= b

leftGBC, rightGBC= [AList[0]], [AList[-1]]
for i in range(1, N):
    leftGBC.append(getNum(leftGBC[i - 1], AList[i]))
for i in range(1, N):
    rightGBC.append(getNum(rightGBC[i - 1], AList[N - i - 1]))

rightGBC.reverse()

ans = max(leftGBC[-2], rightGBC[1])
for i in range(0, N-2):
    ans = max(getNum(leftGBC[i], rightGBC[i + 2]), ans)

print(ans)



Measured memory_bytes: 14400
N,E[21][21];
T0(f,c){
	int i,tsum=0;
	for(i=2;i<=N;i++)
		if(i!=f&&E[c][i])
			tsum+=T0(c,i)+2*E[c][i];
	//printf("T0_%d(%d)=%d\n",f,c,tsum);
	return tsum;
}
T1(f,c,l){
	int i,tsum=E[c][l]+T2(c,l);
	for(i=2;i<=N;i++)
		if(i!=f&&i!=l&&E[c][i])
			tsum+=T0(c,i)+2*E[c][i];
	//printf("T1_%d(%d,%d)=%d\n",f,c,l,tsum);
	return tsum;
}
T2(f,c){
	int l,t,tmin=1e9;
	for(l=2;l<=N;l++)
		if(l!=f&&E[c][l]){
			t=T1(f,c,l);
			if(t<tmin)
				tmin=t;
		}
	if(tmin==1e9)
		tmin=0;
	//printf("T2_%d(%d)=%d\n",f,c,tmin);
	return tmin;
}
main(){
	for(;scanf("%d",&N),N;){
		int i,j,bn[21]={0};
		for(i=0;i<N-1;i++){
			int a,b,t;
			scanf("%d%d%d",&a,&b,&t);
			E[a][b]=E[b][a]=t;
			bn[a]++,bn[b]++;
		}
		//´ª1{µ©©©ÁÄ¢È¢ÍNU·éKvª³¢ÌÅÁ·(1Íc·)
		for(i=2;i<=N;i++)
			if(bn[i]==1)
				for(j=1;j<=N;j++)
					E[i][j]=E[j][i]=0;
		printf("%d\n",T2(0,1));
		memset(E,0,sizeof(E));
	}
	exit(0);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>

int N;

void dfs(char s[], char mx){
    if(strlen(s) == N){
        printf("%s\n",s);
    }else{
        for(char c = 'a' ; c <= mx ; c++){
            char t[12];
            snprintf(t, 12, "%s%c", s,c);
            dfs(t, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main(){
    scanf("%d",&N);
    dfs("",'a');
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    vector<int> v(4,0);
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=="AC")
            v[0]++;
        else if(s=="WA")
            v[1]++;
        else if(s=="TLE")
            v[2]++;
        else if(s=="RE")
            v[3]++;
    }
    cout<<"AC x "<<v[0]<<endl;
    cout<<"WA x "<<v[1]<<endl;
    cout<<"TLE x "<<v[2]<<endl;
    cout<<"RE x "<<v[3]<<endl;
}


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

#define int long long

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int a[111],b[111],c[111],d[111];

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

    rep(i,N)cin>>a[i]>>b[i];
    rep(i,M)cin>>c[i]>>d[i];

    rep(i,N){
        int mi=LLONG_MAX;
        rep(j,M)chmin(mi,abs(a[i]-c[j])+abs(b[i]-d[j]));

        rep(j,M)if(abs(a[i]-c[j])+abs(b[i]-d[j])==mi){
            cout<<j+1<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///find_by_order, order_of_key

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main()
{
    #ifdef ljuba
    auto pocetakChronoSata123 = high_resolution_clock::now();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);       
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, m, k;

    cin >> n >> m >> k;

    vector<ll> a, b;

    a.pb(0LL);
    b.pb(0LL);

    for(int i = 0; i < n; ++i)
    {
        int num;
        cin >> num;
        a.pb(num + a.back());
    }

    for(int i = 0; i < m; ++i)
    {
        int num;
        cin >> num;
        b.pb(num + b.back());
    }

    int ans = 0;
    for(int i = 0, j = m; i <= n; ++i)
    {
        if(a[i] > k)
            break;
        while(a[i] > k - b[j])
            --j;

        ans = max(ans, i + j);
    }

    cout << ans << '\n';

    #ifdef ljuba
    auto krajChronoSata123 = high_resolution_clock::now();
    auto trajanje = duration_cast<microseconds>(krajChronoSata123 - pocetakChronoSata123);
    cout << "----------------------------------------------------\n";
    cout << "Vreme u milisekundama: " << (ld)trajanje.count() / 1000.00 << '\n';
    #endif
    return 0;
}

Measured memory_bytes: 7908
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int digit_sum(int n) {
    int ret = 0;
    while(n > 0) {
        ret += n%10;
        n /= 10;
    }
    return ret;
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    rep2(i,1,n+1) {
        if(a <= digit_sum(i) && digit_sum(i) <= b) ans += i;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<bool> expo(n + 1);

  expo.at(1) = 1;
  for (int b = 2; b <= n; b ++) {
    int v = b * b;
    while (v <= n) {
      expo.at(v) = 1;
      v *= b;
    }
  }
  for (int i = n; i >= 1; i --) {
    if (expo.at(i)) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std ;
const int N = 1e7 + 4;
void FastInputOutput()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline ll LLD()
{
    ll ret;
    scanf("%lld", &ret);
    return ret;
}
inline int D()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
void bin( int x )
{
    if(!x)
        return;
    bin( x / 2 );
    cout << x % 2 ;
}
bool checkPrimeNumber(int n)
{
    bool flag = true;
    for(int j = 2 ; j <= n ; ++j)
    {
        if (n % j == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}
bool cmp(string last, string first)
{
    if(last.size() < first.size())
        return 1;
    return 0;
}
int calculateDigit(int n)
{
    double temp = (double)(n);
    double a = 0.39908-(0.434294 * n);
    double b = log10( n ) ;
    double c = ( n + 0.5 ) * b ;
    double ans = c - abs( a ) ;
    return ceil(ans) ;
}
int findDigits(int n)
{
    double E = 2.71828182845904523536;
    double PI = 3.141592654;

    if (n < 0)
        return 0;
    if (n <= 1)
        return 1;

    double x = ((n * log10(n / E) +
                 log10(2.0 * PI * n) /
                 2.0));

    return floor(x) + 1;
}
ll fact(ll n)
{
    ll ans = 1 ;
    for(ll i = 1 ; i <= n ; ++i)
        ans *= i ;
    return ans ;
}

int arr[ N ];
int main()
{
    FastInputOutput() ;
    int a , b , c , d ;
    cin >> a >> b >> c >> d ;
    int mxac = max(a , c) ;
    int mnbd = min(b , d) ;
    int ans = mnbd - mxac ;
    cout << max(0 , ans);

}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Control.Monad.ST
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Set as Set

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

solve :: Int -> Set.Set Int -> Int
solve n as = runSTUArray func ! n
  where
    func = do
      arr <- newArray (0, 100000) 0 :: ST s (STUArray s Int Int)
      mapM_ (iter arr) [0..100000]
      return arr
    iter a 0 = writeArray a 0 1
    iter a 1 = writeArray a 1 1
    iter a i = do
      v1 <- readArray a (i - 2)
      v2 <- readArray a (i - 1)
      let r1 = if Set.member (i - 2) as then 0 else v1
      let r2 = if Set.member (i - 1) as then 0 else v2
      writeArray a i ((r1 + r2) `mod` 1000000007)

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  as <- readIntLines
  print . solve n $ Set.fromList as

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

namespace AtCoder
{
    class Solver
    {
        private readonly long[] L;
        private Dictionary<Tuple<int, long>, long> memo;
        public Solver()
        {
            L = new long[51];
            L[0] = 1;
            for (int i = 1; i <= 50; ++i) { L[i] = L[i - 1] * 2 + 3; }
            memo = new Dictionary<Tuple<int, long>, long>();
        }
        public long Solve(int N, long X)
        {
            if (X <= 0) { return 0; }
            if (N == 0) { return 1; }
            var key = new Tuple<int, long>(N, X);
            if (!memo.ContainsKey(key))
            {
                long sum = 0;
                long M = L[N - 1];
                if (X - 1 > 0)     { sum += Solve(N - 1, Math.Min(X - 1, M)); }
                if (X - M - 1 > 0) { sum += 1; }
                if (X - M - 2 > 0) { sum += Solve(N - 1, Math.Min(X - M - 2, M)); }
                memo[key] = sum;
            }
            return memo[key];
        }
    }
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }

        static void Main(string[] args)
        {
            long[] V = ReadLongs();
            Console.WriteLine(new Solver().Solve((int)V[0], V[1]));
        }
    }
}


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

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

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

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



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



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



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

	LL N; cin >> N;
	VVI G(N);
	FOR(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	VL dist0(N, INF), distN(N, INF);
	function<void(int, int, int, const VVI&, VL&) > dfs = [&](int v, int p, int d, const VVI& G, VL &dist) {
		dist[v] = d;
		for (auto nx : G[v]) {
			if (nx == p)continue;
			dfs(nx, v, d + 1, G, dist);
		}
	};
	dfs(0, -1, 0, G, dist0);
	dfs(N - 1, -1, 0, G, distN);
	LL ans = 0;
	FOR(i, 0, N) {
		if (dist0[i] <= distN[i])ans++;
		else ans--;
	}
	cout << (ans > 0 ? "Fennec" : "Snuke") << endl;

	return 0;
}


Measured memory_bytes: 16640
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define INF INT_MAX/3
#define pi 2*acos(0.0)
#define eps 1e-14

const int MAX_N = 1e+3;
const int MAX_M = 1e+2;
int n;
int a[MAX_N];
bool is_prime[1000000];
int prime[1000000];

int sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return p;
}

int main() {
	while (cin >> n)
		cout << sieve(n) << endl;
	return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


class RMQ{
public:
    int n;
    vector<int> dat;
    // 初期化
    void init(int n_){
        n=1;
        while(n<n_)n*=2;
        dat.resize(n * 2 - 1, INT_MAX);
    }
    // k番目の値(0-indexed)をaに変更
    void update(int k,int a){
        // 葉の節点
        k+=n-1;
        dat[k]=a;
        // のぼりながら更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    // [a,b)の最小値を求める
    // kは節点の番号、l,rはその節点が[l,r)に対応づいていることを表す
    // したがって、外からはquery(a,b,0,0,n)として呼ぶ
    int _query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l)return INT_MAX;
        else if(a<=l&&r<=b)return dat[k];
        int vl=_query(a,b,k*2+1,l,(l+r)/2);
        int vr=_query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
    int query(int a,int b){
        return _query(a,b,0,0,n);	
    }
};



int N;
int P[200010];
int RP[200010];
RMQ rmq[2];


// [l, r)
pii query(int l, int r){
    int v1= rmq[l % 2].query(l, r);
    int x1 = RP[v1];
    int v2 = rmq[(l % 2) ^ 1].query(x1, r);
    int x2 = RP[v2];
    return pii(x1, x2);
}

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

    for(int i = 0; i < 2; i++)
        rmq[i].init(N);

    for(int i = 0; i < N; i++){
        rmq[i % 2].update(i, P[i]);
    }

    priority_queue<pair<pii, pii> , vector<pair<pii, pii>>, greater<pair<pii, pii> > > pq;    
    
    int l = 0;
    int r = N;
    pii p = query(l, r);
    int x1 = p.first;
    int x2 = p.second;

    vector<int> ans;

    // [l, x1), (x1, x2), (x2, r)
    pq.push(make_pair(pii(P[x1], P[x2]), pii(0, N)));

    while(pq.size()){
        pair<pii, pii> pp = pq.top(); pq.pop();
        ans.push_back(pp.first.first);
        ans.push_back(pp.first.second);
        const int l = pp.second.first;
        const int r = pp.second.second;
        // [l, r)を分割する
        int x1 = RP[pp.first.first];
        int x2 = RP[pp.first.second];
        if(x1 - l != 0){
            pii p = query(l, x1);
            pq.push(make_pair(pii(P[p.first], P[p.second]), pii(l, x1)));
        }
        if(x2 - (x1 + 1) != 0){
            pii p = query(x1 + 1, x2);
            pq.push(make_pair(pii(P[p.first], P[p.second]), pii(x1 + 1, x2)));
        }
        if((r - (x2 + 1) != 0)){
            pii p = query(x2 + 1, r);
            pq.push(make_pair(pii(P[p.first], P[p.second]), pii(x2 + 1, r)));
        }
    }


    for(int a : ans){
        cout << a << " ";
    }
    cout << endl;
    

    return 0;
}


Measured memory_bytes: 10208
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())
A = list(map(int, input().split()))
D = [int(input()) for _ in range(N)]
"""

A, B = map(int, input().split())

total = 1
number = 0

while True:
    if total >= B:
        break

    number += 1
    total = (total - 1) + A

print(number)

# while True:
#     if total >= B:
#         break
#     index += 1
#     if index == 1:
#         total += A
#     else:
#         total += A - 1
#
#
# print(index)

# def main():


# if __name__ == '__main__':
#     main()


Measured memory_bytes: 3572
def my_bsearch (array,target)
  head=0
  tail=array.length-1
  while head<=tail
    center=(tail+head)/2
    if array[center][0] == target
      return center
    elsif array[center][0] < target
      head = center + 1
    else
      tail = center - 1
    end
  end
  #puts "now head=#{head}, tail=#{tail}\narr[#{head}]=#{array[head]}, arr[#{tail}]=#{array[tail]}, target=#{target}"
  if tail==-1 
    return 0
  elsif head==array.length 
    return array.length
  end
  if array[tail][0]<=target
    return tail+1
  else 
    return head-1
  end
end


n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i|i = i.to_i}
arr = []
now_pos = 0
head=0
tail=0
a.each_with_index{|elm,i|
  #puts "#{elm}, #{i}"
  if arr == [] 
    arr<<[elm,i]
  elsif arr.length==1
    if arr[0][0] <=elm
      arr<<[elm,i]
    else
      arr.insert(0,[elm,i])
    end
  else
    # 挿入箇所にぶたん
    arr.insert(my_bsearch(arr,elm),[elm,i])
  end
  #puts "now arr = #{arr}"
}
#pp arr
b=[]
arr.each{|elm|
  b<<elm[1]+1
}
puts b.join(" ")

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

using namespace std;

typedef pair<int,int> ii;

const int N = 1e5 + 7;

vector<int> adj[N];
int n, m, f[N], indeg[N];
bool vis[N];

int main()
{
    //freopen("G.inp","r",stdin);
    //freopen("G.out","w",stdout);

    cin >> n >> m;

    for(int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        ++indeg[v];
    }

    queue <int> q;
    vector <int> ts;

    for(int i = 1; i <= n; i++)
    {
        if(!indeg[i]) q.push(i);
    }

    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        ts.push_back(u);

        for(int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i];
            --indeg[v];
            //cout << v << " " << indeg[v] << "\n";
            if(!indeg[v])
            {
                q.push(v);
                f[v] = max(f[v], f[u] + 1);
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans, f[i]);
    cout << ans;
}


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

using namespace std;

const int N = 1e5 + 100;

typedef pair<int,int> pii;

pii a[N];
int n, cnt;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[i] = pii(x, i);
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (i % 2 != a[i].second % 2)
			cnt++; 	
	}
	return cout << cnt / 2, 0;
}

Measured memory_bytes: 1024
n, t = gets.chomp.split.map(&:to_i)
time_ary = gets.chomp.split.map(&:to_i)

stop_time = 0
time_ary.each_with_index do |time, idx|
  break if idx == time_ary.size - 1
  if (suspension = time_ary[idx + 1] - (time + t)) > 0
    stop_time += suspension
  end
end
puts (time_ary[-1] + t - stop_time)

Measured memory_bytes: 17924
use proconio::input;

fn main() {
	input!(n: usize);
	input!(a: usize);
	input!(x: [usize; n]);

	// 0～jまでで、k個使って、sを作れる総数
	let mut dp: Vec<Vec<Vec<usize>>> = vec![vec![vec![0; 3000]; 70]; 70];
	dp[0][0][0] = 1;
	for j in 0..n {
		for k in 0..n {
			for s in 0..50*50 {
				if dp[j][k][s] == 0 {
					continue;
				}
				// 使わない場合
				dp[j+1][k][s] += dp[j][k][s];
				// 使う場合
				dp[j+1][k+1][s+x[j]] += dp[j][k][s];
			}
		}
	}
	// できたDPのうち、条件に合うものを数え上げる。
	// この問題では、カードをi枚選んだとき合計がi*Aになるのが条件(平均がAなので)。
	// 0～Nまでで、i個使って、合計がi*Aになるもの
	let mut ans = 0;
	for i in 1..n+1 {
		ans += dp[n][i][i*a];
	}
	println!("{}", ans);
}


Measured memory_bytes: 117112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();

		double min=999;

		double ans = 0;
		int cnt = 0;

		for (int i = 0; i < N; i++) {
			ans = Math.abs((T - sc.nextInt() * 0.006) - A);

			if (ans < 0) {
				ans = -ans;
			}
			if (min > ans) {
				min = ans;
				cnt = i;
			}
		}

		System.out.println(cnt + 1);
	}
}


Measured memory_bytes: 24276
x, n = map(int, input().split())
if n != 0:
    p = [int(i) for i in input().split()]
    # print(p)
    # print(4 in p)
    diff = 0
    while True:
        # print(x - diff)
        if x - diff in p and x + diff in p:
            # print('inp')
            diff += 1
            continue
        else:
            if x - diff not in p:
                print(x - diff)
            else:
                print(x + diff)
            break

else:
    print(x)


Measured memory_bytes: 9192
n = int(input())
s = input()
r=0
g=0
b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="B":
        b+=1
    else:
        g+=1
ans=r*b*g

for i in range(n):
    for g in range(i+1,n):
        if s[i]!=s[g] and 2*g-i<n:
            if s[2*g-i]!=s[i] and s[2*g-i]!=s[g]:
                ans-=1

print(ans)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    vector<char> v;
    int x = 0;
    each (c, s) {
      if (v.empty()) v.push_back(c);
      else {
        if (v.back() != c) {
          v.pop_back();
          ++x;
        } else {
          v.push_back(c);
        }
      }
    }
    cout << x*2 << endl;
  }
  
  return 0;
}


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

int main() {

	int A, B;
	cin >> A >> B;

	if (1 == A) {
		if (2 == B) {
			cout << 3 << endl;
		}
		else {
			cout << 2 << endl;
		}
	}
	if (2 == A) {
		if (1 == B) {
			cout << 3 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	if (3 == A) {
		if (1 == B) {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>

int main(){
	std::string S;
	int cnt = 0;
	int max = 0;

	std::cin >> S;

	for(auto s : S){
		if(s=='A'||s=='C'||s=='G'||s=='T') cnt++;
		else cnt=0;

		if(max < cnt) max=cnt;
	}

	std::cout << max << std::endl;

	return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split()))

l = []
r = []
for i in range(n):
  l.append(i+a[i])
  r.append(i-a[i])

count_l = collections.Counter(l)
count_r = collections.Counter(r)

ans = 0
for i in count_l:
  ans += count_r.get(i,0) * count_l[i]
      
print(ans)

Measured memory_bytes: 63284
#include <stdio.h>
#include <string.h>
 
typedef unsigned long long ull;
 
char buf1[101], buf2[101], buf3[101];
int l1, l2, l3;
void rev(char b[], int n) {
    int i,t;
    for(i = 0; i < (n+1)/2; i ++) {
        t=b[i];b[i]=b[n-i-1];b[n-i-1]=t;
    }
}
int main() {
    int tn,ti,c,i,x;
    scanf("%d",&tn);
    for(ti=0;ti<tn;ti++){
        scanf("%s%s",&buf1,&buf2);
        l1 = strlen(buf1); l2 = strlen(buf2);
        rev(buf1, l1); rev(buf2, l2);
        for(i=l1;i<100;i++)buf1[i]='0';
        for(i=l2;i<100;i++)buf2[i]='0';
        c=0,l3=0;
        for(i=0;i<100;i++){
            x=buf1[i]-'0'+buf2[i]-'0'+c;
            if(x>=10)x-=10,c=1;
            else c=0;
            if(x)l3=i;
            buf3[i]=x+'0';
        }
        l3++;
        buf3[l3]=0;
        rev(buf3, l3);
        if(l3>80)
            puts("overflow");
        else
            puts(buf3);
    }
    return 0;
}

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

int main()

{
    char a, b, c ;
    scanf("%c %c %c", &a, &b, &c) ;

    if(a=='A' && b=='B' && c=='C')
    {
        printf("ARC\n") ;
    }

    else if(a=='A' && b=='R' && c=='C')
    {
        printf("ABC\n") ;
    }

    return 0;
}

Measured memory_bytes: 1648
#include <cstdio>

char s[5];

int main(){

	scanf("%s",&s);
  	
  	if( s[0] == s[1] && s[1] == s[2] )puts("Yes");
  	else if( s[1] == s[2] && s[2] == s[3] )puts("Yes");
  	else puts("No");
  
}

Measured memory_bytes: 128
const m = 10^9+7
function main()
    s = pread(Int)
    anss = zeros(Int, s+6)
    anss[3:5] .= 1
    for i in 6:s
        anss[i] = (anss[i-1] + anss[i-3]) % m
    end
    if s < 3
        println(0)
    else
        println(anss[s])
    end
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 197164
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    long double res = 0;

    rep(i, n) {
        for (int j =i+1; j < n; j++) {
            long double d = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            d = sqrt(d);
            res += d;
        }
    }

    res *= 2;
    res /= n;

    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll q;
  cin >> q;
  set<ll> st;
  REP(i,q){
    ll com;
    cin >> com;
    if(com == 0){
      ll x; cin >> x;
      st.insert(x);
      cout << st.size() <<endl;
    }
    else if(com == 1){
      ll x; cin >> x;
      cout << (st.find(x) != st.end()) <<endl;
    }
    else{
      ll x;
      cin >> x;
      st.erase(x);
    }
  }
  return 0;
}




Measured memory_bytes: 12396
#include <iostream>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;

typedef pair<int, int> P;

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

    reverse(S.begin(), S.end());

    long dp[S.length()+1][13];
    for(int i=0; i<=S.length(); i++){
        for(int j=0; j<13; j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    long dg = 1;
    for(int i=0; i<S.length(); i++){
        for(int j=0; j<13; j++){
            long num;
            if(S[i] != '?'){
                num = dg*(S[i] - '0') + j;
                num = num % 13;
                dp[i+1][num] = dp[i+1][num] + dp[i][j];
                dp[i+1][num] = dp[i+1][num] % MOD;
            }else{
                for(int k=0; k<10; k++){
                    num = dg*k + j;
                    num = num % 13;
                    dp[i+1][num] = dp[i+1][num] + dp[i][j];
                    dp[i+1][num] = dp[i+1][num] % MOD;
                }
            }
        }
        dg = dg*10%13;
    }

    cout << dp[S.length()][5] << endl;

    return 0;
}


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    double ans;
    ans=(w*h)/2;
    cout<<ans<<' ';
    if(x==w/2 & y==h/2){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}


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

int main(){

    int A,B,N,M,H,W;
    int i,j,k;
    int min = 1000000000;
    int max = 0;
    int a,b,c,d;
    int count=0,count_two=0,v;
    char cam[50][50];

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

    cin >> H >> W;

    for(i=0;i<H;i++)cin >> cam[i];

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){

            if(cam[i][j] == '#'){
  
                for(k=0;k<4;k++){
                    if(j+dx[k] < 0 || j+dx[k] > W-1 || i+dy[k] < 0 || i+dy[k] > H-1 )continue;
                    if(cam[i+dy[k]][j+dx[k]] == '#'){
                        count++;
                    }
                }
                
                if(count == 0){
                cout << "No" << endl;
                return 0;
                }

            count = 0;

                }
            }
        
        }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b){
  if(a%b==0)return b;
  return gcd(b,a%b);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,x;
  cin >> n >> x;
  vector<int>vec(n);
  rep(i,n)cin >> vec[i];
  if(n==1){
    cout << abs(vec[0]-x) << endl;
    return 0;
  }
  vector<ll>l(n);
  
  rep(i,n){
    l[i]=abs(vec[i]-x);
  }
  ll ans=l[0];
  rep(i,n){
    ans=gcd(ans,l[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
n = int(input())
p_list = list(map(int, input().split()))
count = 0
for i in range(len(p_list)-2):
  if (p_list[i]<p_list[i+1] and p_list[i+1]<p_list[i+2]) or (p_list[i]>p_list[i+1] and p_list[i+1]>p_list[i+2]):
    count += 1
print(count)

Measured memory_bytes: 3060
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a = List.fill(sc.nextInt())(sc.nextDouble()).zipWithIndex
  val average = a.map(_._1).sum / a.length
  val (_, i) = a.minBy(i => (average - i._1).abs)
  println(i)
}


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

using namespace std;

int a[2], k;

int main() {
    cin >> a[0] >> a[1] >> k;
    for(int i = 0; i < k; ++i) {
        if(a[i % 2] % 2 == 1)
            --a[i % 2];
        a[not(i % 2)] += (a[i % 2] / 2);
        a[i % 2] /= 2;
     //   cout << a[0] << ' ' << a[1] << endl;
    }
    cout << a[0] << ' '  << a[1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
int a,b,c,d,q;
ll li[100010],lo[100010];
string s,w;

int main(){
	cin >> s >> w >> q;
	REP(i,0,s.size()){
		if(s[i]=='A') li[i+1]=(li[i]+1);
		if(s[i]=='B') li[i+1]=(li[i]+2);
	}
	REP(i,0,w.size()){
		if(w[i]=='A') lo[i+1]=(lo[i]+1);
		if(w[i]=='B') lo[i+1]=(lo[i]+2);
	}
	
	REP(i,0,q){
		cin >> a >> b >> c >> d;
		cout << ((li[b]-li[a-1])%3==(lo[d]-lo[c-1])%3?"YES":"NO") << endl;
	}
	
	return 0;
}


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

int main() {
  //input
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  rep(j, N) {
    cin >> B.at(j);
  }
  vector<int> C(N-1);
  rep(k, N-1) {
    cin >> C.at(k);
  }
  //calc
  int pre = -100;
  int score = 0;
  int AA;
  rep(i,N) {
    AA = A.at(i);
    score += B.at(AA-1);
    if ( AA - pre == 1 ) {
      score += C.at(pre-1);
    }
    pre = AA;
  }
  //output
  cout << score << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);

function gcd($a, $b) {
    if ($b === 0) {
        return $a;
    }
    return gcd($b, $a % $b);
}
function lcm($a, $b) {
    return $a * $b / gcd($a, $b);
}

$lcm = lcm($c, $d);

function ndiv_cnt($x) {
    global $c;
    global $d;
    global $lcm;

    $tmp1 = intdiv($x, $c);
    $tmp2 = intdiv($x, $d);

    return $x - (intdiv($x, $c) + intdiv($x, $d) - intdiv($x, $lcm));
}

echo ndiv_cnt($b) - ndiv_cnt($a - 1);


Measured memory_bytes: 4604
import bisect
N,M,K= map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dpA = [0]*(N+1)
dpB = [0]*(M+1)

for i in range(1,N+1):
    dpA[i] = dpA[i-1] + A[i-1]

for i in range(1,M+1):
    dpB[i] = dpB[i-1] + B[i-1]

ans = 0
for i in range(N+1):
    if dpA[i] > K:
        continue
    indexB = bisect.bisect_right(dpB, K - dpA[i])
    ans = max(ans, i + indexB - 1)

print(ans)

Measured memory_bytes: 47460
#include <string.h>
int main(void){
    int x,i,j,Num;
    int InNumA,InNumB;
    
    char Input[1001],tmp[1001],Order[10];
    
    scanf("%s",Input);
//    printf("ppp %s \n",Input);
    scanf("%d",&Num);
    for(j=0;j<Num;j++){
        scanf("%s",Order);
        scanf("%d %d",&InNumA,&InNumB);
        x=0;
        if(strcmp(Order,"print")==0){
            for(i=InNumA;i<=InNumB;i++){
                printf("%c",Input[i]);
            }printf("\n");
        }
        
        if(strcmp(Order,"replace")==0){
            scanf("%s",tmp);
            x=0;
            for(i=InNumA;i<=InNumB;i++){
                Input[i]=tmp[x];
                x++;
            }
        }
        if(strcmp(Order,"reverse")==0){
            x=InNumB;
            for(i=InNumA;i<=InNumB;i++){
                tmp[x]=Input[i];
                x--;
            }
            for(i=InNumA;i<=InNumB;i++){
                Input[i]=tmp[i];
            }
        }
    }
}


Measured memory_bytes: 2080
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	long long int  N, H, W, A, B, **ans, flag = 0, i, j, ans_0 = 0, ans_W = 0, len, AB, sum, res, count;

//	int count[1000000000] = { 0 };

	scanf("%lld %lld %lld", &N, &A, &B);
	if (A == 0){
		printf("0\n");
		return 0;
	}

	AB = A + B;

	count = N / AB;
	res = N % AB;
//	printf("N=%lld AB=%lld A=%lld, B=%lld, res=%lld \n", N, AB, A, B, res);
	sum = count * A;
	if (res > A){
		sum += A;
	}
	else{
		sum += res;
	}

	printf("%lld\n", sum);

	/*
	ans = (int **)malloc(sizeof(int *)* H);


	for (i = 0; i<H; i++) {
		ans[i] = (int *)malloc(sizeof(int)* W);
	}

	for (i = 0; i < H; i++){
		for (j = 0; j < W; j++){
			ans[i][j] = 0;
		}
	}
	*/

	return 0;

}
    


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

using namespace std;

long long inf=1000000007;

int main(){
	long long n,m;
	cin>>n>>m;
	vector<long long> card(n);
	for(int i=0;i<n;i++) cin>>card.at(i);
	sort(card.begin(),card.end());

	priority_queue<pair<long long,long long>> change;
	for(int i=0;i<m;i++){
		long long b,c;
		cin>>b>>c;
		change.push(make_pair(c,b));
	}

	long long numoftop=change.top().second;

	for(int i=0;i<n;i++){
		if(change.size()>0 && card.at(i)<change.top().first){
			card.at(i)=change.top().first;
			numoftop--;

			if(numoftop<=0){
				change.pop();
				if(change.size()>0) numoftop=change.top().second;
			}
		}
	}

	long long ans=0;

	for(auto a:card) ans+=a;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3188
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int nax=1007;

int n;
char wcz[nax];

map <string,ll> mapa[nax];

ll wyn;

int main()
{
	scanf("%d%s", &n, wcz);
	for (int i=0; i<(1<<n); i++)
	{
		string s="";
		for (int j=0; j<n; j++)
			if (i&(1<<j))
				s+=wcz[j];
		for (int j=n-1; j>=0; j--)
			if (!(i&(1<<j)))
				s+=wcz[j];
		mapa[__builtin_popcount(i)][s]++;
	}
	for (int i=0; i<(1<<n); i++)
	{
		string s="";
		for (int j=n-1; j>=0; j--)
			if (i&(1<<j))
				s+=wcz[j+n];
		for (int j=0; j<n; j++)
			if (!(i&(1<<j)))
				s+=wcz[j+n];
		wyn+=mapa[__builtin_popcount(i)][s];
	}
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 73984
import math


def primefac(x):
    fac = []
    for i in range(2, int(math.sqrt(x)) + 1 + 1):
        if x % i != 0:
            continue
        ex = 0
        while x % i == 0:
            ex += 1
            x = x // i
        fac.append((i, ex))

    if x != 1:
        fac.append((x, 1))
    return fac


def ans(fac):
    count = 0
    for _, ex in fac:
        for i in range(1, 10 ** 12):
            ex -= i
            if ex < 0:
                break
            else:
                count += 1
    return count


if __name__ == "__main__":
    N = int(input())
    fac = primefac(N)
    # print(fac)
    print(ans(fac))


Measured memory_bytes: 63152
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  int N,M;
  scanf("%d",&N);
  getchar();
  str line;
  getline(cin,line);
  int T[N],sum = 0;
  split_str(line,' '){
    T[cnt] = i_str(res);
    sum += i_str(res);
  }
  scanf("%d",&M);
  int P[M],X[M],ans[M];
  rep(i,M){
    scanf("%d%d",&P[i],&X[i]);
    ans[i] = sum + (X[i] - T[P[i] - 1]);
  }

  for(int i:ans) printf("%d\n",i);

  return 0;
}

Measured memory_bytes: 256
(defun main ()
  (let* ((n (read))
         (a (+ (expt 10 9) 7))
         (power 1)
         (rst 0))
    (loop for i from 1 to n
      do (setf power (* i (mod power a)))
         '(format t "~A~%" power)
      )
    (mod power a)))

(format t "~A~%" (main))


Measured memory_bytes: 12900
#include <bits/stdc++.h>
using namespace std;
#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++)


int main() {
  long mod=2019;
  string s;
  cin >> s;
  int n=s.size();
  map<long,long>memo;
  vector<long>t(n+1);
  t[n]=0;
  memo[t[n]]++;
  vector<long>ten(n+1);
  ten[0]=1;
  rep2(i,1,n+1){
    ten[i]=ten[i-1]*10%mod;
  }
  for(int i=n-1;i>=0;i--){
    t[i]=(t[i+1]+(s.at(i)-'0')*ten[n-i-1])%mod;
    memo[t[i]]++;
  }
  

  long ans=0;
  for(auto p:memo){
    auto v=p.second;
    ans+=v*(v-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6728
for i in range(20000):
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        print(a//b)
    if op == '?':
        break


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

int data[600][600];
int data_s[600][600];
int L[200009];
int R[200009];
int p[100009];
int q[100009];

int main(int argc, char** argv) {
    int N, M, Q;
    cin >> N >> M >> Q;
    for (int i = 1; i <= M; i++) {
        cin >> L[i] >> R[i];
        data[L[i]][R[i]]++;
    }
    for (int i = 1; i <= Q; i++) cin >> p[i] >> q[i];
    for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) data_s[i][j] = data_s[i][j - 1] + data[i][j];
    for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) data_s[i][j] = data_s[i - 1][j] + data_s[i][j];
    for (int i = 1; i <= Q; i++) {
        int ans = 0;
        ans += data_s[q[i]][q[i]] - data_s[p[i] - 1][q[i]] - data_s[q[i]][p[i] - 1] + data_s[p[i] - 1][p[i] - 1];
        cout << ans << endl;
    }
}


Measured memory_bytes: 5888