akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	int two = 0, five = 0;
	int x = 2, cnt = 1;
	while (x <= n) {
		two += (n / x);
		x *= 2;
		cnt++;
	}
	x = 5, cnt = 1;
	while (x <= n) {
		five += n / (x * 2);
		x *= 5;
		cnt++;
	}
	cout << min(two, five) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define MOD 1000000007
using namespace std;

int main(){
	fast_io;
	ll n,d;
	cin>>n>>d;
	vector<vector<ll>> v(n,vector<ll>(d));
	for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            ll x;
            cin>>x;
            v[i][j]=x;
        }
	}
	ll cnt=0;
	for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ll sum = 0;
            for(int k=0;k<d;k++){
                sum = sum + (abs(v[j][k]-v[i][k])*abs(v[j][k]-v[i][k]));
            }
            long double x;
            x = sqrt(sum);
            if(x==floor(x)){
                cnt++;
            }
        }
	}
	cout<<cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a[5];
    int k;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>k;
    if(a[4]-a[0]>k){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
   return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>

using namespace std;

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

    int max_loop = max(A, B);

    for (int K=0; K<max_loop; K++) {
        if (abs(A-K) == abs(B-K)) {
            cout << K;
            return 0;
        }
    }

    cout << "IMPOSSIBLE";
    return 0;
}   


Measured memory_bytes: 384
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Function (on)
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  xs <- rgetl 8 words
  ys <- rgetl 8 words
  zs <- rgetl 8 words
  mapM_ (putStrLn . unwords) $ solve xs ys zs

solve :: [[String]] -> [[String]] -> [[String]] -> [[String]]
solve xs ys zs = x1 ++ y1 ++ z1 ++ rs
  where
    (x1,x2) = top2 xs
    (y1,y2) = top2 ys
    (z1,z2) = top2 zs
    (rs,_) = top2 $ x2 ++ y2 ++ z2
    
top2 :: [[String]] -> ([[String]],[[String]])
top2 xs = (take 2 sxs, drop 2 sxs)
  where
    sxs = sortBy (compare `on` (toDbl . (!!1))) xs

toInt :: String -> Int
toInt s = read s

toDbl :: String -> Double
toDbl s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine


tests :: [Test]
tests = [
  "test1" ~: ([["5", "22.88"],["3", "23.00"]],[["10", "24.79"],["18", "25.46"],["16", "26.23"]]) ~=? top2 [["18", "25.46"],["16", "26.23"],["3", "23.00"],["10", "24.79"],["5", "22.88"]]
  ]

Measured memory_bytes: 4304
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j += i)
      if (j % 2 == 1)
        ++vec[j];
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += vec[i] == 8;

  cout << ans << endl;
}


Measured memory_bytes: 3600
// AOJ 0172: Doctor's Research Rooms
// 2018.1.24 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char rm; int light; } Q;
Q q[491520]; int top, end;
Q *used[15][32768];

int rm[15][15], s_rm[15];
int sw[15][15], s_sw[15];

char *msg[7] = {0,
"You can go home in %d steps.\n",
"You can not switch off all lights.",
"Help me!",
"Move to room %d.\n",
"Switch on room %d.\n",
"Switch off room %d.\n" };

typedef struct { char msg, rm; } T;
T res[30000]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
while (c < '0') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

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

int main()
{
	int n, m, i, j, s, t, ans;
	int room, light;

	while (n = in()) {
		m = in();
		memset(s_rm, 0, sizeof(s_rm));
		memset(s_sw, 0, sizeof(s_sw));

		for (i = 0; i < m; i++){
			s = in()-1, t = in()-1;
			rm[s][s_rm[s]++] = t;
			rm[t][s_rm[t]++] = s;
		}

		light = 0; for (i = 0; i < n; i++) if (in()) light |= 1 << i;

		for (i = 0; i < n; i++) {
			j = in(); while (j--) sw[i][s_sw[i]++] = in()-1;
			qsort(sw[i], s_sw[i], sizeof(int), cmp);
        }

		memset(used, 0, sizeof(used));
		q[0].rm = 0, q[0].light = light; top = 0, end = 1;
		used[0][light] = q;

		ans = 3;
		while (top < end) {
			s = q[top].rm, t = q[top].light;

			if (s == n-1) {
				if (t == 1<<(n-1)) { ans = 1; break; }
				ans = 2;
			}

			for (i = 0; i < s_sw[s]; i++) if (sw[s][i] != s) {
//			for (i = 0; i < s_sw[s]; i++) {
				light = t ^ (1<<sw[s][i]);
				if (used[s][light] == 0) {
					used[s][light] = q + top;
					q[end].rm = s, q[end++].light = light;
				}
			}

			for (i = 0; i < s_rm[s]; i++) {
				room = rm[s][i];
				if (t & (1<<room)) {
					if (used[room][t] == 0) {
						used[room][t] = q + top;
						q[end].rm = room, q[end++].light = t;
					}
				}
			}

			top++;
		}
 
		if (ans > 1) puts(msg[ans]);
		else {
			Q p = q[top];
			sz = 0;
			while (1) {
				Q nxt = *used[p.rm][p.light];
				if (nxt.rm == p.rm && nxt.light == p.light) break;
				if (p.rm != nxt.rm) res[sz].msg = 4, res[sz++].rm = p.rm;
				else for (i = 0; i < n; i++) if ((p.light & (1<<i)) ^ (nxt.light & (1<<i))) {
					if (p.light & (1<<i)) res[sz].msg = 5; else res[sz].msg = 6;
					res[sz++].rm = i;
					break;
				}
				p = nxt;
			}
			printf(msg[ans], sz);
			while (sz--) printf(msg[res[sz].msg], 1 + res[sz].rm);
		}
    }
    return 0;
}


Measured memory_bytes: 5868
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
    char card1[200]={};
    int i=0,j=0,k=0,number=0,m,length;

    while(scanf("%s",card1)==1){
            if(strcmp(card1,"-")==0){
             exit(0);
         }
        length=strlen(card1);
        scanf("%d",&number);//シャッフル回数
    while(scanf("%d",&m)==1){
        if(k==number){break;}
        k++;
        char card2[200]={};
        strncpy(card2,card1,m);
        
        for(i=0,j=m;i<=length;i++,j++){
            card1[i]=card1[j];
        }
        strcat(card1,card2);
    }
    printf("%s\n", card1);
    i=0;j=0;k=0;
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int N, M;
vint vec;
vint half;

int main() {
    while (cin >> N >> M) {
        if (N == 0) break;
        half.clear(); vec.clear();
        half.PB(0);
        for (int i = 0; i < N; ++i) {int a; cin >> a; vec.PB(a); half.PB(a);}
        for (int i = 0; i < N; ++i) for (int j = i; j < N; ++j) half.PB(vec[i] + vec[j]);
        sort(ALL(half));
        half.erase(unique(ALL(half)), half.end());
        
        //COUT(half);
        
        int res = 0;
        for (int i = 0; i < half.size(); ++i) {
            int h = half[i];
            int rem = M-h;
            
            int id = upper_bound(ALL(half), rem) - half.begin();
            --id;
            if (id < 0) continue;
            
            chmax(res, h + half[id]);
        }
         
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
import Control.Monad
import Data.List

getInt = read <$> getLine :: IO Int
getInts = map read . words <$> getLine :: IO [Int]


calc l = calc_ 1234567890 0 0 l
calc_ min w ct [] = ct
calc_ min w ct (a:as) | a<min     = calc_ a w ct as
                      | (a-min)>w = calc_ min (a-min) 1 as
                      | (a-min)<w = calc_ min w ct as
                      | otherwise = calc_ min w (ct+1) as

main = do
    [n, t] <- getInts
    as <- getInts
    print $ calc as



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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    int x = 1000-(n%1000);
    if (x == 1000) {
        x = 0;
    }
    cout << x << "\n";

    return 0;
}


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

using namespace std;

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

class CommonIO {
public:
    CommonIO() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(false);
    }
    ~CommonIO() {}

    template <class T>
    void scan(T &v) {
        std::cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        std::cout << v;
    }
    template <class T>
    void print(std::vector<T> &v) {
        if (v.size() == 0) return;
        print(*v.begin());
        for (auto it = ++v.begin(); it != v.end(); ++it) {
            print(' ');
            print(*it);
        }
    }
    template <class T>
    void print(std::vector< std::vector<T> > &grid) {
        if (grid.size() == 0) return;
        print(*grid.begin());
        for (auto it = ++grid.begin(); it != grid.end(); ++it) {
            print('\n');
            print(*it);
        }
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(' ');
        print(rest...);
    }

    template <class T>
    void printl(T v) {
        print(v);
        std::cout << '\n';
    }
    template <class T, class... Rest>
    void printl(T v, Rest... rest) {
        print(v);
        print(' ');
        printl(rest...);
    }
} io;

int main() {
    double a, b, x;
    io.scan(a, b, x);
    double V = a * a * b;

    double theta;
    if (x > V / 2.0) {
        theta = atan(2.0 / a / a / a * (V - x));
    } else {
        theta = atan(a * b * b / 2.0 / x);
    }
    theta *= 180.0 / M_PI;
    cout << fixed << setprecision(10);
    io.printl(theta);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "YES" : "NO";
}

int main(){
    int n; cin >> n;
    double sum = 0;

    rep(i,n){
        double x; string y;
        cin >> x >> y;

        if(y == "JPY"){
            sum += x;
        }else{
            sum += 380000.0 * x;
        }
    }

    cout << sum << endl;
}

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() {
	int n; scanf("%d", &n);
	map<ll, vector<int>>mp;
	mp[0].push_back(0);
	ll s = 0;
	rep(i, n) {
		ll a; scanf("%lld", &a);
		s += a;
		mp[s].push_back(i + 1);
	}
	int Max = 0;
	for (auto&p : mp) {
		Max = max(Max, p.second.back() - p.second.front());
	}
	printf("%d\n", Max);
}

Measured memory_bytes: 25024
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  while(const int n = getInt()){
    vector<int> a(n);
    vector<int> b(n);

    REP(i,n) a[i] = getInt();
    REP(i,n) b[i] = getInt();

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());

    for(int i = 0; i < n - 1; i += 2){
      if(a[i] > b[i/2]){
        printf("%d\n", i + 1);
        goto end;
      }
    }
    puts("NA");
  end:;
  }
  return 0;
}

Measured memory_bytes: 1284
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n

for i in range(1, n):    
  step1 = dp[i-1] + abs(h[i]-h[i-1])
  if i - 2 >= 0:
    step2 = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(step1, step2)
  else:
    dp[i] = step1

print(dp[-1])

Measured memory_bytes: 52208
import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine
 a<-replicateM n getLine
 b<-replicateM m getLine
 putStrLn(f a b 0 0 0 m (n-m+1))
  where f a b h i j m l |h==m ="Yes"
                        |i==l ="No"
                        |j>=l&&h==0 =f ((map (\x->(tail x)))a) b 0 (i+1) 0 m l
                        |otherwise =if (take m (a!!j))==b!!h then (f a b (h+1) i (j+1) m l)
                                                             else (f a b 0 i (j+1) m l)

Measured memory_bytes: 764
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(l[K-1])

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec AC(N, 0), WA(N, 0);
    REP(i,0,M) {
        ll p;
        string S;
        cin >> p >> S;
        if(S == "AC") AC[p-1] = 1;
        else if(S == "WA" && AC[p-1] == 0) ++WA[p-1];
    }
    ll nAC = 0, nWA = 0;
    REP(i,0,N) {
        nAC += AC[i];
        nWA += AC[i] * WA[i];
    }
    PS(nAC); PR(nWA);

    return 0;
}

/*



*/

Measured memory_bytes: 4816
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
//using vi = vector<int>;
//using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
//using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


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

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



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

	if(n % 2 == 0 ){

		cout << n << endl;
	}
	else{
		cout << n*2 << endl;
	}

	
	//system("pause");



	


}
	


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int givenNumber = scanner.nextInt();
        int tmp = 0;
        int target = 0;
        int orgNum = givenNumber;
        while(0 < givenNumber) {
            tmp = givenNumber % 10;
            target += tmp;
            givenNumber /= 10;
        }
        if(orgNum % target == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int main(){
    int x, y;
    while(1){
        scanf("%d %d", &x, &y);
        if (x==0 && y==0) break;
        else if (x<=y){
            printf("%d %d\n", x, y);
        }
        else{
            printf("%d %d\n", y, x);
        }
        
    }
    return 0;
}


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

ll divisor=1e9+7;
int main(){
	string s;
	cin>>s;
	string ans=s=="ARC"?"ABC":"ARC";
	puts(ans);
}

Measured memory_bytes: 3628
N = int(input())

d = 2

ans = 0

while d*d <= N:
    if N % d != 0:
        d += 1
        continue
        # Nがdで割り切れないとき，何もせずdを一歩進める。例えば d = 4 のときは，それ以前に d = 2 の時でNを割り切ってしまっているので，N % 4 != 0 と出る。

    z = d

    while N % z == 0:
         N //= z
         z *= d

         ans += 1

    while N % d == 0:
        N //= d

if N != 1:
    ans += 1

print(ans)

Measured memory_bytes: 9076
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    int[] a = new int[N];
    long sum=0;


    int[] numHist = new int[100001];
    Arrays.fill(numHist, 0);
    for(int i=0; i<N; i++){
      numHist[sc.nextInt()]++;
    }

    for(int i=0; i<100001; i++){
      sum += i * numHist[i];
    }

    int Q = sc.nextInt();
    int[] b = new int[Q];
    int[] c = new int[Q];

    for(int i=0; i<Q; i++){
      b[i] = sc.nextInt();
      c[i] = sc.nextInt();

      int diff = c[i] - b[i];
      sum = sum + diff * numHist[b[i]];

      numHist[c[i]] += numHist[b[i]];
      numHist[b[i]] = 0;



      System.out.println(sum);
    }

    return;
  }
}

Measured memory_bytes: 63044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 200005;
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ta = (c - 1)/b;
    int op = (a-1)/d;
   // cout << ta <<' '<<op<<'\n';
    if (ta <= op) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[i + n / 2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3560
import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

string sdir = "URDL";
int dx[] = {0, 0, 0, -1};
int dy[] = {-1, 0, 1, 0};

int main(){
	vector<string> v(9);

	rep(i, 9){
		cin >> v[i];
		v[i] += '0';
	}

	int x = 0, y = 0;
	int dir = 1;
	do{
		dir += 3;
		rep(i, 4){
			int ndir = (dir+i)%4;
			int nx = x + dx[ndir];
			int ny = y*2 + dy[ndir];
			if(nx < 0 || nx >= 5 ||ny < 0 || ny >= 9) continue;
			if(v[ny][nx] == '0') continue;
			x += dx[ndir]+(ndir==1);
			y += dy[ndir];
			dir = ndir;
			cout << sdir[ndir];
			break;
		}
	}while(x!=0||y!=0);

	cout << endl;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = ((int)b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(), c.end()
#define sz(c) ((int)c.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

const int MOD = 1e9 + 7;
int fact(int n) {
  int r = 1;
  rep(i, 1, n + 1) {
    r *= i;
    r %= MOD;
  }
  return r;
}

signed main() {
  
  int N, M;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << endl;
  } else if (abs(N - M) == 1) {
    cout << fact(N) * fact(M) % MOD << endl;
  } else {
    cout << 2 * fact(N) * fact(M) % MOD << endl;
  }
}

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

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

    ll ans = 0;
    for (int i = 0; i < S.size(); i++) {
        ll tmp = 0;
        while (true) {
            if (i + tmp >= S.size()) break;

            if (S[i + tmp] == 'A' || S[i + tmp] == 'G' || S[i + tmp] == 'C' || S[i + tmp] == 'T') {
                tmp++;
            } else {
                break;
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, Z, W;
const ll MAX_N  = 2000;
ll a[MAX_N];

int main(){
  cin >> N >> Z >> W;
  REP(i, N) cin >> a[i];

  if(N == 1) {
    cout << abs(a[0] - W) << endl;
    return 0;
  }
  ll L = a[N - 1], B = a[N - 2];

  cout << max(abs(L - W), abs(L - B)) << endl;



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

typedef long long    ll;
typedef long double  ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(ll N, ll K) {
  ll res = 0;
  while (res++, N >= K) N /= K;
  return res;
}

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

  ll N, K;
  cin >> N >> K;

  auto ans = solve(N, K);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
const int mod = 998244353 ;
const int inf = 1e9 + 5;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 1e5 + 5 ;
int n ;
int h[maxn] ;
int dp[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1)
    cin >> h[i] ;
    rep(i,0,n-1) dp[i] = inf ;
    dp[0] = 0 ;
    dp[1] = abs(h[1]-h[0]) ;
    rep(i,2,n-1)
    {
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2])) ;
    }
    cout << dp[n-1] << "\n" ;
    return 0 ;
}


Measured memory_bytes: 1024
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
d = {}
e = {}
cnt = 0
for i in range(1, n+1):
    d[i] = B[i-1]
for i in range(1, n):
    e[i] = C[i-1]
for i in range(n):
    cnt += d[A[i]]
    if i != 0:
        if A[i] == 1:
            continue 
        else:
            if A[i] == A[i-1] + 1:
                cnt += C[A[i]-2]
print(cnt)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define PI 3.14159265358979323846264338327950L

int main(void) {
	int a, b, h, m;
	scanf("%d%d%d%d", &a, &b, &h, &m);

	long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
	                            double)m / 60.0);

	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
	                  b) * cosl(rad);

	printf("%20.20Lf\n", sqrtl(rsq));

	return 0;
}

Measured memory_bytes: 4080
#include <stdio.h>
int main (int argc, char * argv[])
{
    int n[6];//サイコロの数
    int a,b;
    int q;
    for(int i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d %d",&a,&b);
        if((a==n[5] && b==n[4])||(a==n[0] && b==n[1])||(a==n[4] && b==n[0])||(a==n[1] && b==n[5])){
            printf("%d\n",n[2]);
        }else if((a==n[0] && b==n[2])||(a==n[2] && b==n[5])||(a==n[5]&& b==n[3])||(a==n[3] && b==n[0])){
            printf("%d\n",n[4]);
        }else if((a==n[2] && b==n[1])||(a==n[1] && b==n[3])||(a==n[3] && b==n[4])||(a==n[4] && b==n[2])){
            printf("%d\n",n[5]);
        }else if((a==n[0] && b==n[4])||(a==n[4] && b==n[5])||(a==n[5] && b==n[1])||(a==n[1] && b==n[0])){
            printf("%d\n",n[3]);
        }else if((a==n[0] && b==n[3])||(a==n[3] && b==n[5])||(a==n[5] && b==n[2])||(a==n[2] && b==n[0])){
            printf("%d\n",n[1]);
        }else {
            printf("%d\n",n[0]);
        }
    }
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int d;cin>>d;
    vin c(26);rep(i,26)cin>>c[i];
    vvin s(d,vin(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    vin last(26,0);int sum,tmp;ll m;
    vin ans(d);
    rep(i,d){
        m=-INF;
        rep(j,26){
            sum=0;
            sum+=s[i][j];
            rep(k,26){
                if(k==j)continue;
                sum-=c[k]*(i+1-last[k]);
            }
            if((ll)sum>m){
                tmp=j;
                m=(ll)sum;
            }
        }
        ans[i]=tmp;
        last[tmp]=i+1;
    }
    rep(i,d)cout<<ans[i]+1<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
long long x,k,d;
int main() {
	cin>>x>>k>>d;
	if(x<0) {
		x*=-1;
	}
	if(x/d>k) {
		cout<<x-k*d;
	}
	else {
		long long y;
		while(x>=0) {
			y=x;
			x-=d;
			k--;
		}
		if (k%2==0) {
			cout<<abs(x)<<endl;
		} else {
			cout<<abs(y)<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env ruby

(n, k) = gets.chomp.split(/ /).map(&:to_i)
s = gets.chomp
sarray = s.split(//).map(&:to_i)

f = sarray[0]
array = []
count = 0
sarray.each do |i|
  if f == i
    count += 1
  else
    array << count
    f = i
    count = 1
  end
end
array << count

#p array
if sarray[0] == 0
  array.unshift(0)
end
if sarray[-1] == 0
  array.push(0)
end

if (array.size % 2 == 0)
  array.push(0)
end

#p array
v = 0
if (array.size - 1 >= k * 2)
  (0..(k * 2)).each do |j|
    v += array[j]
  end
else
  v = array.inject(&:+)
end
max = v
#puts "max:#{v}"
las = (array.size - (k * 2 + 1) - 2)
#puts "last#{las}"
if las < 0
else
  0.step(las, 2) do |l|
    del = array[l] + array[l + 1]
    add = array[l + k * 2 + 1] + (array[l + k * 2 + 2])
#    puts "val #{v}, del #{del},add #{add},"
    v = v - del + add
    max = v if max < v
  end
end
puts max


Measured memory_bytes: 8828
n,t = map(int,input().split())
Route = [list(map(int,input().split())) for i in range(n)]
Costs = []
for i in range(n):
  if Route[i][1] <= t:
    Costs += [Route[i][0]]
if Costs == []:
  print('TLE')
else:
  print(min(Costs))

Measured memory_bytes: 3060
/*これはDouble Linked Listをlistを用いて書いたものです*/
#include <bits/stdc++.h>
using namespace std;

int main(){
    int q, x;
    char com[20];

    list<int> v;
    scanf("%d", &q);
    for(int i=0; i<q; i++){
        scanf("%s", &com);
        if(com[0]=='i'){                    /*insert*/
            scanf("%d", &x);
            v.push_front(x);
        }
        else if(com[6]=='L') v.pop_back();  /*deleteLast*/
        else if(com[6]=='F') v.pop_front(); /*deleteFirst*/
        else if(com[0]=='d'){               /*delete*/
            scanf("%d", &x);
            for(list<int>::iterator ite=v.begin(); ite!=v.end(); ite++){
                if(*ite==x){
                    v.erase(ite);
                    break;
                }
            }
        }
    }
    int i=0;
    for(list<int>::iterator ite=v.begin(); ite!=v.end(); ite++){
        if(i++) printf(" ");
        printf("%d", *ite);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 34416
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
__int128 bin_pow(__int128 base,__int128 deg,__int128 mod)
{
    if (deg==0)
        return 1;
    __int128 t=bin_pow(base,deg/2,mod);
    if (deg&1)
        return t*t%mod*base%mod;
    else
        return t*t%mod;
}
void solve()
{
    ll n;
    cin>>n;
    n*=2;
    ll was=n;
    vector <pll> p;
    vector <ll> x;
    for (ll i=2;i*i<=n;i++)
    {
        if (n%i==0)
        {
            int cnt=0;
            ll y=1;
            while (n%i==0)
                cnt++,n/=i,y*=i;
            x.pb(y);
            p.pb({i,cnt});
        }
    }
    if (n>1)
        p.pb({n,1}),x.pb(n);
    int sz=p.size();
    ll ans=INFLL;
    for (int mask=0;mask<(1<<sz);mask++)
    {
        __int128 a=1;
        for (int i=0;i<sz;i++)
        {
            if ((mask>>i)&1)
                a*=x[i];
        }
        __int128 b=was/a;
        __int128 phi=1;
        for (int i=0;i<sz;i++)
        {
            if ((mask>>i)&1)
                continue;
            phi*=x[i];
            phi/=p[i].fi;
            phi*=p[i].fi-1;
        }
        __int128 now=b-1;
        now=(now*bin_pow(a,phi-1,b))%b;
        if (now==0)
            ans=min(ans,(ll)(a*b));
        else {
            ans = min(ans, (ll)(now * a));
        }
    }
    cout<<ans<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
  //  cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
            ll N;cin>>N;
            map<ll,ll> m;
            rep(i,N){
                     ll a;cin>>a;
                     m[a]=i+1;
                     }
            rep(i,N){
                     cout<<m[i+1]<<" ";
                     }
            cout<<endl;
                                 
                                 
    }



Measured memory_bytes: 7040
#include <cstdio>
#include <algorithm>

using namespace std;

int v[110],v1[110],v2[110],v3[110];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n,w,a,b,x,sol=0;
    scanf("%d%d",&n,&w);
    int l=1,l1=0,l2=0,l3=0;
    scanf("%d%d",&x,&v[1]);
    for(int i=2;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        if(a==x) v[++l]=b;
        else if(a==x+1) v1[++l1]=b;
        else if(a==x+2) v2[++l2]=b;
        else v3[++l3]=b;
    }
    sort(v+1,v+l+1);
    reverse(v+1,v+l+1);
    for(int i=1;i<=l;i++) v[i]+=v[i-1];
    sort(v1+1,v1+l1+1);
    reverse(v1+1,v1+l1+1);
    for(int i=1;i<=l1;i++) v1[i]+=v1[i-1];
    sort(v2+1,v2+l2+1);
    reverse(v2+1,v2+l2+1);
    for(int i=1;i<=l2;i++) v2[i]+=v2[i-1];
    sort(v3+1,v3+l3+1);
    reverse(v3+1,v3+l3+1);
    for(int i=1;i<=l3;i++) v3[i]+=v3[i-1];
    for(int i=0;i<=l;i++)
        for(int i1=0;i1<=l1;i1++)
            for(int i2=0;i2<=l2;i2++)
                for(int i3=0;i3<=l3;i3++)
                    if((1LL*x*i+1LL*i1*(x+1)+1LL*i2*(x+2)+1LL*i3*(x+3))<=w) sol=max(sol,v[i]+v1[i1]+v2[i2]+v3[i3]);
    printf("%d",sol);
    return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];


void solve()
{
     cin >> n;
     int ans = 0;
     for (int i = 2; i * i <= n; i++)
     {
          if ( n % i == 0)
          {
               int cnt = 0;
               while ( n % i == 0 ) cnt++, n /= i;

               // cout << cnt << " " << i << endl;
               int val = 0, j = 1;
               while (val + j <= cnt)
               {
                    ans++;
                    val = val + j;
                    j++;
               }
          }
     }

     if (n >= 2) ans++;
     cout << ans << endl;

}

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

     int test = 1;
     // cin >> test;
     while (test--)solve();


}





Measured memory_bytes: 3656
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=400100,Mx=200000;
int n,m,c[N],o1[N],o2[N],tot1,tot2;
struct line{int x1,y1,x2,y2;}Line[N];
struct node{int x,y,opt;}p[N];
struct hx{int x1,x2,y;}h[N];
bool operator<(const node a,const node b){return a.y<b.y;}
bool operator<(const hx a,const hx b){return a.y<b.y;}
int lowbit(int x){return x&(-x);}
void Add(int x,int d){while(x<=Mx){c[x]+=d;x+=lowbit(x);}}
int query(int x){int ret=0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
int query(int l,int r){return query(r)-query(l-1);}
int main(){
	int all=gi();
	for(int i=1;i<=all;i++){
		int x1=gi(),y1=gi(),x2=gi(),y2=gi();
		Line[i]=(line){x1,y1,x2,y2};
		o1[++tot1]=x1;o1[++tot1]=x2;
		o2[++tot2]=y1;o2[++tot2]=y2;
	}
	sort(o1+1,o1+tot1+1);tot1=unique(o1+1,o1+tot1+1)-o1-1;
	sort(o2+1,o2+tot2+1);tot2=unique(o2+1,o2+tot2+1)-o2-1;
	for(int i=1;i<=all;i++){
		Line[i].x1=lower_bound(o1+1,o1+tot1+1,Line[i].x1)-o1;
		Line[i].x2=lower_bound(o1+1,o1+tot1+1,Line[i].x2)-o1;
		Line[i].y1=lower_bound(o2+1,o2+tot2+1,Line[i].y1)-o2;
		Line[i].y2=lower_bound(o2+1,o2+tot2+1,Line[i].y2)-o2;
	}
	for(int i=1;i<=all;i++){
		int x1=Line[i].x1,y1=Line[i].y1,x2=Line[i].x2,y2=Line[i].y2;
		if(x1==x2){
			if(y1>y2)swap(y1,y2);
			p[++m]=(node){x1,y1,1};p[++m]=(node){x1,y2+1,-1};
		}
		else{
			if(x1>x2)swap(x1,x2);
			h[++n]=(hx){x1,x2,y1};
		}
	}
	sort(h+1,h+n+1);sort(p+1,p+m+1);int pos=1,ans=0;
	for(int i=1;i<=n;i++){
		while(pos<=m && p[pos].y<=h[i].y){Add(p[pos].x,p[pos].opt);pos++;}
		ans+=query(h[i].x1,h[i].x2);
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 8752
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

map<ll, ll> prime;
void factrization(ll n) {
  for(ll i=2; i*i<=n; i++) {
    while(n%i==0) {
      prime[i]++;
      n/=i;
    }
  }
  
  if(n>1) prime[n]++;
}



ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll fa[MAX], rf[MAX];

ll C(ll n, ll k) {
  if(k==0) return 1;
  if(n==k) return 1;
  return fa[n]*rf[k]%MOD*rf[n-k]%MOD;
}


int main(void) {
  ll N, M;
  cin >> N >> M;
  
  fa[0]=rf[0]=1;
  for(ll i=1; i<MAX; i++) {
    fa[i]=fa[i-1]*i%MOD;
    rf[i]=moP(fa[i], MOD-2);
  }
  
  
  ll ans=1;
  factrization(M);
  for(auto it=prime.begin(); it!=prime.end(); it++) {
    moC(ans, *, C(N-1+it->second, it->second));
  }
  
  pt(ans);
}


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

int fib(int n);

int main(){
	int n;
	cin >> n;
	cout << fib(n) << endl;
}
	
int fib(int n){
	int num1 = 1,num2 = 1;
	int temp = 0;
	if(n == 0 || n == 1) return 1;
	
	for (int i = 1;i < n;i++){
		temp = num2;
		num2 = num1 + num2;
		num1 = temp;
	}
		return num2;
}

Measured memory_bytes: 3080
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int LC[10][10];
int L[10][10]; 
int F[10][10]; 

void init() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            L[i][j] = LC[i][j];
            F[i][j] = 0;
        }
    }
}

void input() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cin >> LC[i][j];
        }
    }
}

void output() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cout << F[i][j];
            if ( j + 1 < 10 ) cout << " ";
        }
        cout << endl;
    }
}

void flip( int r, int c ) {
    F[r][c] = 1;
    L[r][c] = !L[r][c];
    if ( r - 1 >= 0 ) L[r-1][c] = !L[r-1][c];
    if ( r + 1 < 10 ) L[r+1][c] = !L[r+1][c];
    if ( c - 1 >= 0 ) L[r][c-1] = !L[r][c-1];
    if ( c + 1 < 10 ) L[r][c+1] = !L[r][c+1];
}

bool solve( int r ) {
    if ( r >= 10 ) {
        for ( int i = 0; i < 10; ++ i ) {
            if ( L[r-1][i] == 1 ) return false;
        }
        return true;
    }
    if ( r == 0 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            init();
            for ( int j = 0; j < 10; ++ j ) {
                if ( i & ( 1 << j ) ) flip( r, j );
            }
            if ( solve( r + 1 ) ) return true;
        }
        return 0;
    } else if ( r < 10 ) {
        for ( int i = 0; i < 10; ++ i ) {
            if ( L[r-1][i] ) {
                F[r][i] = 1;
                flip( r, i );
            }
        }
        if ( solve( r + 1 ) ) return true;
    }

    return false;
}

int main() {
    int n;
    while ( cin >> n ) {
        for ( int i = 0; i < n; ++ i ) {
            input();
            solve( 0 );
            output();
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>

using namespace std;
int dp[2019];
string s;

int main(){
    cin >> s;
    int len = s.size();
    memset(dp, 0, sizeof(dp));
    dp[s[0]-'0'] = 1;
    long long ans = 0;
    for (int i = 1; i < len; i++){
        int tmp[2019];
        memset(tmp, 0, sizeof(tmp));
        int d = s[i]-'0';
        tmp[d] = 1;
        for (int j = 0; j < 2019; j++){
            int r = (j*10+d)%2019;
            if (r == 0) ans += dp[j];
            tmp[r] += dp[j];
        }
        for (int j = 0; j < 2019; j++) dp[j] = tmp[j];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3708
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int main(){
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    ll ans = INF;

    for(int bit = 0; bit < (1<<n); ++bit){
        bool ok = true;
        vector<ll> g(m, 0);
        ll score = 0;
        for(int i = 0; i < n; ++i){
            if(bit & (1<<i)) {
                score += c[i];
                for(int j = 0; j < m; ++j) {
                    g[j] += a[i][j];
                }
            }
        }
        rep(i, m){
            if(g[i] < x){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, score);
        }

    }
        cout << (ans < INF ? ans : -1) << endl;

}

Measured memory_bytes: 3628