akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int cmp(long *b1, long *b2){ // 昇順
    if(*b1 > *b2) return 1;
    else if(*b1 < *b2) return -1;
    else return 0;
}



int main(){
  int n;
  scanf("%d",&n);
  long a[n];
  long ai[n];
  long aj[n];
  F(i,0,n){
    scanf("%ld",a+i);
    ai[i]=a[i]+i+1;
    aj[i]=i+1-a[i];
  }
  qsort(ai,n,sizeof(long),cmp);
  qsort(aj,n,sizeof(long),cmp);
  int i=0,j=0;
  long ans=0;
  while(i+1<n && j<n){
    long tmpi=1,tmpj=0;
    while(ai[i]==ai[i+1] && i+1<n){
      tmpi++;
      i++;
    }
    while(ai[i]!=aj[j] && ai[i]>aj[j] && j<n) j++;
    while(ai[i]==aj[j] && j<n){
      tmpj++;
      j++;
    }
    ans += tmpi*tmpj;
    i++;
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 7848
N = gets.to_i
R = Array.new(N).map{Array.new(2)}
for i in 0..N-1
 R[i][0],R[i][1] = gets.chomp.split(" ");
end
_sort = R.sort_by {|x| x[1].to_i}.reverse.sort_by {|x| [x[0], i += 1]}
for i in 0..N-1
 m = R.index([_sort[i][0],_sort[i][1]])
  puts m+1
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;

const int maxn=100000+5;

int cd(ll a){
	int res=0;
	while(a){
		a/=10;
		res++;
	}
	
	return res;
}

int main(){
	vector<ll> a;
	int init=0;
	
	for(int i=1ll; i<=9ll; i++) a.pb(i);
	
	while(a.size()<=maxn){	
		int temp=a.size();
		for(int i=init; i<(int) temp; i++){
			int num=a[i];
			if(num%10>=1) a.pb(num*10ll+(num%10)-1);
			a.pb(num*10ll+(num%10));
			if(num%10<9) a.pb(num*10ll+(num%10)+1);
		}		
		init=temp;
	}
		
	int k; cin>>k;
	cout<<a[k-1];
			
	return 0;
}


Measured memory_bytes: 2420
def examA():
    N, X, T = LI()
    ans = (1 + (N-1)//X)*T
    print(ans)
    return

def examB():
    N = SI()
    s = 0
    for n in N:
        s += int(n)
    if s%9==0:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    now = A[0]
    cnt = 0
    for i in range(N):
        if now>A[i]:
            cnt += now-A[i]
        if now<A[i]:
            now = A[i]
    ans = cnt
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 33024
package main

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

func main() {
	N, M, C := ReadInt(), ReadInt(), ReadInt()
	B := ReadInts(M)
	ans := 0
	for i := 0; i < N; i++ {
		A := ReadInts(M)
		sum := C
		for j := 0; j < M; j++ {
			sum += A[j] * B[j]
		}
		if sum > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1848
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int n,p;
    cin >> n >> p;
    if(n == 1)
    {
        cout << p << "\n";
        return 0;
    }
    long long int ans = 1,i = 2;
    while(i <= sqrt(p))
    {
        long long int count = 0;
        while(p % i == 0)
        {
            p /= i;
            count++;
        }
        if(count >= n)
        {
            ans *= (int)pow(i,(count / n));
        }
        i++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
<?php

$data = array();
while ($line = fgets(STDIN)) {
    $value = (int)rtrim($line);
    if (0 === $value) break;
    if (10000 < $value) continue;
    $data[] = $value;
}

$i = 1;
foreach ($data as $value) {
    printf("Case %d: %d\n", $i, $value);
    $i++;
}

Measured memory_bytes: 16496
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n, k, s;
	cin >> n >> k >> s;
	vector<long long int> a(n);
	if(n == k){
		for(int i=0;i<n;i++){
			a.at(i) = s;
		}
	}else{
		if(s == 1e9){
			if(k == 0){
				for(int i=0;i<n;i++){
					a.at(i) = s-1;
				}
			}else{
				for(int i=0;i<k+1;i++){
					if(i%2 == 0){
						a.at(i) = 1;
					}else{
						a.at(i) = s-1;
					}
				}
				for(int i=k+1;i<n;i++){
					a.at(i) = s-2;
				}
			}
		}else{
			if(s != 1){
				if(k == 0){
					for(int i=0;i<n;i++){
						a.at(i) = s-1;
					}
				}else{
					for(int i=0;i<k+1;i++){
						if(i%2 == 0){
							a.at(i) = 1;
						}else{
							a.at(i) = s-1;
						}
					}	
					for(int i=k+1;i<n;i++){
						a.at(i) = s+1;
					}
				}	
			}else{
				if(k == 0){
					for(int i=0;i<n;i++){
						a.at(i) = 2;
					}
				}else{
					for(int i=0;i<k;i++){
						a.at(i) = 1;
					}
					for(int i=k;i<n;i++){
						a.at(i) = 2;
					}
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << a.at(i) << " ";
	}
}

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

lld mod = 1000000007;

lld binpow(lld x, lld n){
    if(n == 0) return 1;
    if(n == 1) return x;
    lld t = binpow(x,n/2) % mod;
    if(n % 2 == 0) return t * t % mod;
    else return t * t % mod * x % mod;
}

int main() {
    lld N,K;
    cin >> N >> K;
    lld ans = 0;
    lld memo[100001];
    fillnum(memo,-1);
    for (int i = K; i > 0; i--) {
        memo[i] = binpow(K/i,N);
        for (int j = 2*i; j <= K; j+=i) {
            memo[i] = (memo[i] - memo[j] + mod) % mod;            
        }
        ans = (ans + memo[i] * i) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4428
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

long long T;
long long N, K[1 << 18], L[1 << 18], R[1 << 18];
long long A1[1 << 18], A2[1 << 18];
vector<long long> X[1 << 18];

void init() {
	for (int i = 0; i <= N + 2; i++) A1[i] = 0;
	for (int i = 0; i <= N + 2; i++) A2[i] = 0;
}

vector<long long> calc(vector<pair<long long, long long>> D) {
	for (int i = 0; i <= N + 2; i++) X[i].clear();
	for (int i = 0; i < D.size(); i++) X[D[i].first].push_back(D[i].second);

	priority_queue<long long, vector<long long>, less<long long>> Q;
	vector<long long> R, S;
	for (int i = N; i >= 1; i--) {
		for (long long j : X[i]) Q.push(j);
		if (!Q.empty()) { R.push_back(Q.top()); Q.pop(); }
	}

	sort(R.begin(), R.end());
	reverse(R.begin(), R.end());
	S.push_back(0);
	for (int i = 0; i < R.size(); i++) S.push_back(S[S.size() - 1] + R[i]);
	return S;
}

long long solve() {
	// 準備
	init();
	long long BASE = 0;
	vector<pair<long long, long long>> V1, V2;

	// 前処理
	for (int i = 1; i <= N; i++) {
		BASE += min(L[i], R[i]);
		if (L[i] >= R[i] && K[i] > 0) V1.push_back(make_pair(K[i], L[i] - R[i]));
		if (L[i] < R[i] && K[i] < N) V2.push_back(make_pair(N - K[i], R[i] - L[i]));
	}

	// 計算
	vector<long long> B1 = calc(V1);
	vector<long long> B2 = calc(V2);
	for (int i = 1; i <= N; i++) A1[i] = B1[min(i, (int)B1.size() - 1)];
	for (int i = 1; i <= N; i++) A2[N + 1 - i] = B2[min(i, (int)B2.size() - 1)];

	long long Answer = 0;
	for (int i = 1; i <= N; i++) Answer = max(Answer, A1[i] + A2[i + 1]);
	return BASE + Answer;
}

int main() {
	cin >> T;
	for (int i = 1; i <= T; i++) {
		cin >> N;
		for (int j = 1; j <= N; j++) cin >> K[j] >> L[j] >> R[j];
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 29876
import itertools
import math

D,G=map(int,input().split())
p=[0]*D
c=[0]*D

for i in range(D):
    p[i],c[i]=map(int,input().split())
    
ans=10**7

for ite in itertools.product([0,1], repeat=D):
    temp=0
    tn=0
    for i in range(len(ite)):
        temp+=ite[i]*(c[i]+100*(i+1)*p[i])
        tn+=p[i]*ite[i]
    if temp>=G:
        ans=min(ans,tn)
    else:
        for i in range(len(ite)-1,-1,-1):
            if ite[i]==0:
                if math.ceil((G-temp)/((i+1)*100)) <=p[i]-1 :#その難易度の問題を1問残しで埋めて目標に届くなら:
                    ans=min(ans,tn+math.ceil( (G-temp)/((i+1)*100) ) )
                else:
                    temp+=(i+1)*100*(p[i]-1)
                    tn+=p[i]-1
                    
print(int(ans))

    
    
    





Measured memory_bytes: 42864
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int x,y;
	cin>>x>>y;
	float n;
	int ans = -1;
	for(float i=0;i<=100000;i++){
		if(floor(i*.08)==x && floor(i*0.1)==y){
			ans = floor(i);
			break;
		} 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
                int n = sc.nextInt();
                boolean can = true;
                Stack<String> talk = new Stack<String>();
                for(int i=1;i<=n&&can==true;i++) {
                	String t = sc.next();
                	if(t.equals("A"))
                		talk.push(t);
                	else if(t.equals("Un")) {
                		if(talk.isEmpty())
                			can = false;
                		else if(talk.pop().equals("A"))
                				can = true;
                	}
                }
                if(can && talk.isEmpty())
                	System.out.println("YES");
                else
                	System.out.println("NO");
        }
    }
}



Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 300 + 5;
ll h[N], f[N][N];

int main()
{
	ll n,k;
	scanf("%lld %lld",&n,&k);
	for (ll i = 1; i <= n; ++i)
		scanf("%lld",&h[i]);
	memset(f,INF,sizeof(f));
	for(ll i = 1; i <= n; ++i)
		f[i][1] = h[i];
	//f记录最少次数 
	for(ll i = 2; i <= n; ++i)
		for(ll j = 2; j <= i; ++j)
			for(ll p = 1; p < i; ++p) 
				f[i][j] = min(f[i][j], f[p][j - 1] + max(0LL, h[i] - h[p]));
	ll ans = f[0][0];
	for(ll i = n - k; i <= n; ++i)
		ans = min(ans, f[i][n - k]);
	if(n == k)
		printf("0\n");
	else 
		printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var aGroup = new int[7] {1, 3, 5, 7, 8, 10, 12};
            var bGroup = new int[4] { 4,6,9,11};
            var r = ReadIntArray();
            if (aGroup.Contains(r[0]) && aGroup.Contains(r[1]) ||
                bGroup.Contains(r[0]) && bGroup.Contains(r[1]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 11348
cnt = 0
def insertionSort(A, n, g):
  global cnt
  for i in range(g,n):
    v = A[i]
    j = i - g
    while (j >= 0 and A[j] > v ):
      A[j+g] = A[j]
      j = j - g
      cnt += 1
    A[j+g] = v

def shellSort(A, n):
  global cnt
  cnt = 0
  
  m = 0
  b=n
  while b > 0:
    b = b // 4
    m += 1
    
  G = []
  base = 1
  for i in range(0,m):
    G.insert(0,base)
    base = base * 3 + 1

  print(m)
  strG = [str(i) for i in G]
  print(" ".join(strG))
  for i in range(m):
    insertionSort(A, n, G[i])

N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))

shellSort(A,N)
print(cnt)
for a in A:
  print(a)
        
        
        
        


Measured memory_bytes: 45500
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位


int main(void) {
    ll n, m, k;
    cin >> n >> m >> k;
    ll c[n], a[n][m];
    for(ll i = 0; i < n; i++){
        cin >> c[i];
        for(ll j = 0; j < m; j++)
            cin >> a[i][j];
    }
    ll ans = 1e+11;

    for(ll bit = 0; bit < (1 << n); bit++){
        vector<ll> s(m, 0);
        ll count = 0;
        for(ll i = 0; i < n; i++){
            if((bit & (1 << i))==false) continue;
           // cout << bit << " " << i << endl;
            for(ll j = 0; j < m; j++){
                s[j]+=a[i][j];
            }
            count += c[i];
        }
        bool ok = true;
        //cout << count << " ";
        for(ll i = 0; i < m; i++){
          //  cout << s[i] << " ";
            if(s[i]<k) ok = false;
        }
     //   cout << endl;
        if(ok==true)
            ans = min(ans, count);
    }
    if(ans ==1e+11)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
from collections import deque

N = int( input() ) + 1 # empty counts

hi = 0
while 1 << hi + 2 <= N:
  hi += 1

ans_A = deque()
ans_B = deque()
ptr = 1
for i in range( hi, -1, -1 ):
  ans_A.append( ptr )
  ans_B.append( ptr )
  ptr += 1
  if N >> i & 1:
    ans_A.append( ptr )
    ans_B.appendleft( ptr )
    ptr += 1

print( len( ans_A ) * 2 )
for i in range( len( ans_A ) ):
  print( ans_A[ i ], end = ' ' )
for i in range( len( ans_B ) ):
  print( ans_B[ i ], end = ' \n'[ i + 1 == len( ans_B ) ] )


Measured memory_bytes: 38384
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double result = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
    printf("%lf\n", result);
    return 0;
}



Measured memory_bytes: 3300
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long int ll;
typedef vector<long long int> vl;
typedef vector<string> vs;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define ABS(a) ((a)>0 ? (a) : (a * -1))



int main(){
	int flg, flg1;
	ll n, ans;
	ans = 1;

	cin >> n;
	vl a(n);
	vl b(n);

	flg = 0;
	flg1 = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
		if (i != 0) {
			if (b[i-1] == a[i]) {
				flg = 0;
			} else if (b[i-1] < a[i]) {
				flg = -1;
			} else if (b[i-1] > a[i]) {
				flg = 1;
			} else {
				flg = 2;
			}
		}

		if ((flg != flg1 && flg1 != 0) && flg != 0) {
			ans ++;
			flg1 = 0;
		} else if (flg == 2) {
			ans ++;
			flg1 = 0;
		} else {
			if(flg != 0) flg1 = flg;
		}
		
	}



	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#define REP(i, START, n, STEP) for(int i = START; i < (n); i += (STEP))
#define rep(i, n) REP(i, 0, n, 1)
using namespace std;

typedef long long int ll;

int main()
{
	int n;
	cin >> n;
	vector<double> v(n);
	rep(i, n)
	{
		cin >> v[i];
	}

	double newItem;
	sort(v.begin(), v.end(), greater<double>());
	while (v.size() > 1)
	{
		newItem = 0;
		newItem += v.back();
		v.pop_back();
		newItem += v.back();
		v.pop_back();
		newItem /= 2.0;
		v.push_back(newItem);
	}

	cout << setprecision(7) << fixed << v[0];

	return 0;
}

Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto H = ri;
	auto W = ri;
	writeln(max(0, N - H + 1) * max(0, N - W + 1));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

string LCS(string x, string y, int n, int m)
{
    int dp[n+1][m+1];

    FOR(i,0,n+1)
    {
        FOR(j,0,m+1)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;

            else if(x[i-1] == y[j-1])
                dp[i][j] = dp[i-1][j-1]+1;

            else 
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    int index = dp[n][m];
    char ans[index+1];
    ans[index] = '\0';

    int i = n,j=m;
    while(i>0 && j>0)
    {
        if (x[i-1] == y[j-1]) 
	{ 
		ans[index-1] = x[i-1];
		i--; j--; index--;
	} 

	else if (dp[i-1][j] > dp[i][j-1]) 
		i--; 
	else
		j--; 
    }

    return ans;
}

int main()
{
    HAPPY_CODING;

    string x,y;
    cin >> x >> y;

    string ans = LCS(x, y, x.length(),y.length());
    cout << ans << "\n";

    return 0;
}
/*

abcdef
adbcde
5

*/

Measured memory_bytes: 38796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int c[N];
int main(){
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	ll s=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	for(int i=2;i<=n;i++){
		ll d=c[i]-c[i-1];
		if(d*a<=b) s+=d*a;
		else s+=b;
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 4232
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Measured memory_bytes: 55008
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
struct Writer {
    s: String,
}
#[allow(unused_imports)]
use std::fmt::Display;
#[allow(dead_code)]
impl Writer {
    #[allow(dead_code)]
    pub fn new() -> Writer {
        Writer { s: String::new() }
    }
    #[allow(dead_code)]
    pub fn flush(&mut self) {
        print!("{}", self.s);
        self.s.clear();
    }
    pub fn write<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
    }
    pub fn writeln<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
        self.s.push('\n');
    }
    #[allow(dead_code)]
    pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) {
        if xs.len() == 0 {
            self.writeln("");
            return;
        }
        self.write(&format!("{}", xs[0]));
        for i in 1..xs.len() {
            self.write(&format!(" {}", xs[i]));
        }
        self.writeln("");
    }
}
#[allow(dead_code)]
fn main() {
    input!{
        a: u64,
        b: u64,
        c: u64,
        d: u64
    }
    println!("{}", max(a * b, c * d));
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n, m, x; cin >> n >> m >> x;
    ll ans = INF;
    vector<ll> C(n);
    vector<vector<ll>> A(n, vector<ll>(m));
    rep(i, n) {
        cin >> C[i];
        rep(j, m) cin >> A[i][j];
    }

    for (ll i = 0; i < (1 << n); i++){
        vector<ll> R(n);
        ll cnt = 0;
        rep(j, n){
            if((i>>j)&1){
                cnt += C[j];
                rep(k, m){
                    R[k] += A[j][k];
                }
            }
        }

        bool ok = true;
        rep(j, m){
            if(R[j] < x) ok = false;    
        }
        if(ok) ans = min(ans, cnt);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
 
int main() {
    int m, f, r;
    char rank[5][2] = {"A", "B", "C", "D", "F"};
    int flug;
    while (1) {
        scanf("%d%d%d", &m, &f, &r);
        if (m + f + r == -3)break;
        if (m + f >= 80) flug = 0;
        else if (m + f >= 65) flug = 1;
        else if (m + f >= 50) flug = 2;
        else if (m + f >= 30 && r >= 50) flug = 2;
        else if (m + f >= 30 && r <= 50) flug = 3;
        else flug = 4;
if(m==-1||f==-1) flug = 4;
        printf("%s\n", rank[flug]);
    }
    return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>
#include <stack>
using namespace std;
struct hollow{
    int n;
    int l;
};
int main(){
    int now=0,ans=0,t=0,c[20001];
    stack<int> d;
    stack<hollow>b;
    hollow temp;
    char a[20001];
    for(int i=0;i<20001;i++)a[i]='\0';
    scanf("%s",a);
    while(a[now]!='\0'){
        if(a[now]=='\\')d.push(now);
        if(a[now]=='/'&&!d.empty()){
            temp.n=now-d.top();
            temp.l=d.top();
            d.pop();
            while(!b.empty()&&b.top().l>temp.l){
                temp.n+=b.top().n;
                b.pop();
            }
            b.push(temp);
        }
        now++;
    }
    while(!b.empty()){
        c[t]=b.top().n;
        ans+=c[t];
        t++;
        b.pop();
        
    }
    printf("%d\n%d",ans,t);
    for(int i=t-1;i>=0;i--)printf(" %d",c[i]);
    printf("\n");
}

Measured memory_bytes: 2860
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;

int main(){
    ll x,k,d; cin >> x >> k >> d;
    if(x<0) x=-x;
    if(x!=0){
        if(x/d>k){
            cout << abs(x-k*d) << "\n"; 
            return 0;
        }
        k -= x/d;
        x  = x%d;
        if(abs(x-d)<abs(x) && k>0){
            x -= d; k--;
        }
    }
    //cout << k << "\n"; 
    if(k%2==0){
        cout << abs(x) << "\n";
    }else{
        if(abs(x+d) >= abs(x-d)){
            cout << abs(x-d) << "\n";
        }else{
            cout << abs(x+d) << "\n";
        }

    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++mp[a];
    }
    for(auto it : mp){
        if(it.second != 1){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
uint32 n, k;
std::vector<uint32> a;


bool c(uint32 o) {
	if (a[o] >= k) return true;
	std::vector<char> b(k, 0);
	b[0] = 1;
	int32 t;
	rep(i, 0, n) {
		if (i == o) continue;
		t = k - a[i] - 1;
		while (t >= 0) {
			b[t + a[i]] |= b[t];
			--t;
		}
	}
	rep(i, k - a[o], k) {
		if (b[i]) {
			return true;
		}
	}
	return false;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> n >> k;
	a.resize(n);
	rep(i, 0, n)
		std::cin >> a[i];
	std::sort(ALL(a));
	int32 l = -1, r = n;
	while (r - l > 1) {
		int32 mid = (l + r) >> 1;
		if (c((uint32)mid)) {
			r = mid;
		}
		else {
			l = mid;
		}
	}
	std::cout << r << "\n";
	return 0;
}

Measured memory_bytes: 384
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            string ss = Console.ReadLine();
            a -= b;
            int buf = 1;
            while (a > 0)
            {
                a -= b - 1;
                buf++;
            }
            Console.WriteLine(buf);

        }
    }
}


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

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

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;


int main() {
  int r, D, x;
  cin >> r >> D >> x;

  rep(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)

int main() {
    int n, r;
    while (cin >> n >> r && n) {
        int p, c;
        int a[n];
        rep(i, n) {
            a[i] = n - i;
            //cout << a[i] << " ";
        }
        //cout << endl;
        rep(i, r) {
            cin >> p >> c;
            rotate(a, a + p - 1, a + p + c - 1);
            /*
            rep(i, n) {
                cout << a[i] << " ";
            }
            cout << endl;*/
        }
        cout << a[0] << endl;
    }
}



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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, m, a[N], f[N], l[N], r[N], v[N], real[N];
vector<int> graph[N];
const int inf = 1e11;

void dfs(int u, int p){
    for(int i = 0; i < graph[u].size(); i++){
        int v = graph[u][i];
        if(v == p) continue;
        f[v] = f[u] + 1;
        dfs(v, u);
    }
}

void bye(){
    cout << "No\n";
    exit(0);
}
signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i =  1; i <= n - 1; i++){
        int u, v;
        cin >> u >> v;
        graph[u].pb(v); graph[v].pb(u);
    }
    dfs(1, 1);
    cin >> m;
    queue<int> q;
    for(int i = 1; i <= n; i++)
        l[i] = -inf, r[i] = inf;
    for(int i = 1; i <= m; i++){
        cin >> v[i];
        cin >> a[i];
        l[v[i]] = a[i];
        r[v[i]] = a[i];
        q.push(v[i]);
    }
    int prev = -1;
    for(int i = 1; i <= m; i++){//kiem tra tinh chan le
        int sum = (a[i] + f[v[i]]) % 2;
        if(prev == -1) prev = sum;
        if(sum != prev)
            bye();
        prev = sum;
    }
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int i = 0; i < graph[u].size(); i++){
            int w = graph[u][i];
            int temp = l[u] - 1;
            if(temp > l[w]){
                l[w] = max(temp, l[w]);
                q.push(w);
            }
        }
    }
    for(int i = 1; i <= n; i++)
        q.push(v[i]);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int i = 0; i < graph[u].size(); i++){
            int w = graph[u][i];
            int temp = r[u] + 1;
            if(temp < r[w]){
                r[w] = min(temp, r[w]);
                q.push(w);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(l[i] > r[i])
            bye();
    }
    cout << "Yes\n";
    for(int i = 1; i <= n; i++){
        cout << l[i] << "\n";
        for(int j = 0; j < graph[i].size(); j++){
            int w = graph[i][j];
            l[w] = max(l[w], l[i] - 1);
            r[w] = min(r[w], r[i] + 1);
        }
    }
}


Measured memory_bytes: 16128
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int M = 1e5 ;
int n , k ;
int a[M];
int dp[M];
int main()
{
    scanf ("%d%d" , &n ,&k);
    for (int i =0 ; i < n ;i++)scanf ("%d" ,a+i );
    dp[1] = abs(a[0] - a[1]);
    dp[0] = 0 ;
    for (int i = 2 ; i < n ; i++)
    {
        dp[i] = dp[i-1] + abs (a[i] - a[i-1]);
        for (int j = 2 ; j <= k && i-j >= 0 ; j++)
        {
            dp[i] = min ( dp[i] , abs( a[i] - a[i-j]  ) + dp[i-j]  );
        }
    }
    printf ("%d\n" , dp[n-1]);
}


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

const int N = 53;
ll n,A,a[N];
ll dp[N][N][N*N];

ll rec(int i,int cnt,int cur) {
    if(i == n && A*cnt == cur && cnt>0)
        return 1;
    else if(i == n)
        return 0;
    ll& cache = dp[i][cnt][cur];
    if(cache != -1)
        return cache;
    ll ans = 0;
    ans += rec(i+1,cnt+1,cur+a[i]) + rec(i+1,cnt,cur);
    return cache = ans;
}

void solve(){
    cin >> n >> A;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;++i)
        cin >> a[i];
    cout << rec(0,0,0) << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 65304
/*        ,---,
               / _=_ \.~
              (,(OvO),) ##}
             ,-\(-"-) /{ #)\
             {  '---'  (   }\_
             {{ ).___|__( '}}  \_
             {  )       (  }}    \
             {  /        \ }}    /
             {  )       (  }  /  /
             ((_'_     _'_))_,\__\
       */
    // ____      _                _          _      _                  _                         _      
    //|  _ \ ___| |_ __ _ _ __ __| | ___  __| |    / \   _ __   ___    | | ____ _    ___ ___   __| | ___ 
    //| |_) / _ \ __/ _` | '__/ _` |/ _ \/ _` |   / _ \ | '_ \ / _ \   | |/ / _` |  / __/ _ \ / _` |/ _ \
    //|  _ <  __/ || (_| | | | (_| |  __/ (_| |  / ___ \| |_) |  __/   |   < (_| | | (_| (_) | (_| |  __/
    //|_| \_\___|\__\__,_|_|  \__,_|\___|\__,_| /_/   \_\ .__/ \___|   |_|\_\__,_|  \___\___/ \__,_|\___|
    //                                                  | |
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll; 
    typedef unsigned long long ull; 
    typedef pair<int, int> ii; 
    typedef vector<ii> vii;
    typedef vector<int> vi;
    typedef vector<unsigned long long int> vul;
    #define INF 1000000000
    typedef std::numeric_limits< double > dbl;

    double d = 3.14159265358979;
    ull f = 1000000007;

    int c[100000];
    
    ll haha(int a[], int n, int k){
        if(n <= k){
            int b[n];
            for(int i=0; i<n; i++){
                if(c[i]== -1){
                    c[i] = haha(a, i, k);
                    b[i] = abs(a[n] - a[i]) + c[i];
                }
                else{
                    b[i] = abs(a[n] - a[i]) + c[i];
                }
            }
            sort (b, b+n);
            return b[0];
        }
        int b[k];
        for(int i =1; i<=k; i++){
            if(c[n-i]==-1){
                c[n-i] = haha(a,n-i, k);
                b[i-1] = abs(a[n] - a[n-i]) + c[n-i];
            }else{
                b[i-1] = abs(a[n] - a[n-i]) + c[n-i];
            }
        }
        sort(b, b+k);
        return b[0];
    } 

    int main (){
        for(int i=0; i< 100000; i++){
            c[i] = -1;
        }
        c[0] = 0;

        int n,k; cin >> n >> k;
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        cout << haha(a, n-1, k);


    }

Measured memory_bytes: 54144
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner obj=new Scanner(System.in);
    int n=obj.nextInt();
    int m=obj.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++){
		a[i]=obj.nextInt();}
    Arrays.sort(a);
    int sum=0;
    for(int i=0;i<m;i++)
    sum=sum+a[i];  
    System.out.println(sum);
  }
}

Measured memory_bytes: 39280
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

typedef struct{
  int id;
  int d;
  int k;
  int *A;
  int color;
} Point;

Point *p;
int n,i,j,v,*queue,x=0,head=0,tail=0,LEN=0;

void enqueue(int x){
  queue[tail++]=x;
  if(tail>LEN) tail=0;
}

int dequeue(){
  int x;
  if(head!=tail){
  x=queue[head++];
  if(head>LEN) head=0;
  return x;
  }
  return -1;
}

void search(int u){
  p[u].color=0;
  p[u].d=0;
  enqueue(u);

  while(head!=tail){
    u=dequeue();

    for(v=0;v<p[u].k;v++) if(p[ p[u].A[v] ].color==-1){
	p[ p[u].A[v] ].color=0;
	p[ p[u].A[v] ].d=p[u].d+1;
	enqueue( p[u].A[v] );	
    }
    
    p[u].color=1;
  }
  
}

int main(){

  scanf("%d",&n);

  p = (Point *) malloc (sizeof( Point )*n);

  for(i=0;i<n;i++){
    scanf("%d%d",&p[i].id,&p[i].k);
    
    p[i].A=(int *)malloc(sizeof(int) * p[i].k);
    LEN+=p[i].k;

    p[i].color=-1;
    p[i].d=INT_MAX;
    
    for(j=0;j<p[i].k;j++){
      scanf("%d",&p[i].A[j]);
      p[i].A[j]--;      
    }
    
  }

  LEN++;
  queue=(int *)malloc(sizeof(int)*LEN);

  search(0);
  for(i=0;i<n;i++) printf("%d %d\n",p[i].id,(p[i].d==INT_MAX) ? (-1) : p[i].d);
  
  return 0;
}



Measured memory_bytes: 2104
import sys
sys.setrecursionlimit(pow(10,9))
class UnionFind():
    def __init__(self,n):
        self.root = [-1]*n
        self.rank = [1]*n
    def find(self,x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.find(self.root[x])
    def union(self,x,y):
        x,y = self.find(x),self.find(y)
        if x == y:return
        if self.rank[x]<self.rank[y]:
            x,y = y,x
        self.rank[x] += self.rank[y]
        self.root[y] = x

N,M = map(int,input().split())
P = list(map(lambda x:int(x)-1,input().split()))
T = UnionFind(N)
for i in range(M):
    x,y = map(lambda x:int(x)-1,input().split())
    T.union(x,y)
cnt = 0
for i in range(N):
    p = P[i]
    if T.find(i)==T.find(p):
        cnt+=1
print(cnt)

Measured memory_bytes: 14452
s=input()
n=len(s)

s_rev=s[::-1]

s_former=s[:(n-1)//2]
s_former_rev=s_former[::-1]

s_latter=s[(n+3)//2-1:]
s_latter_rev=s_latter[::-1]

if (s==s_rev) & (s_former==s_former_rev) & (s_latter==s_latter_rev):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

int main(){
	ll n, p; cin >> n >> p;
	vl a(n, 0), od(n+1, 0), ev(n+1, 0);
	rep(i, n) cin >> a[i];
	ev[0] = 1;
	rep(i, n){
		if (a[i] % 2){
			ev[i + 1] = ev[i] + od[i];
			od[i + 1] = od[i] + ev[i];
		}
		else{
			ev[i + 1] = ev[i] * 2;
			od[i + 1] = od[i] * 2;
		}
	}
	if (p){
		cout << od[n] << endl;
	}
	else{
		cout << ev[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, a;
  cin >> n >> a;
  bool ok = true;
  n %= 500;
  ok = (n <= a ? true : false);
  print((ok ? "Yes" : "No"));
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)
	{
		cout<<"YES"<<endl;
	}	
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 102;
char s[N], t[N];

int main() {
    int n;
    scanf("%d\n%s\n%s", &n, s, t);
    string res = "";
    for (int i = 0; i < n; i++) {
        res += s[i];
        res += t[i];
    }
    printf("%s", res.c_str());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    if (s[0] == s[1] && s[1] == s[2]) cout<<"Yes"<<endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;
long long n,h,he,xiao=2100000000;
int a[200000+10];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		h+=a[i];
	}
	for(int i=1;i<n;i++)
	{
		he+=a[i];
		h-=a[i];
		if(abs(he-h)<xiao)xiao=abs(he-h);
	}
	cout<<xiao<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int k,a,b;
    int t=0;
    std::cin>>k>>a>>b;
        if(a%k==0){
            t=1;
        }
    while(a!=b){
                a++;
        if(a%k==0){
            t=1;
        }
    }
    if(t==1){
        printf("OK");
    }else{
        printf("NG");
    }
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    if(a>b&&a>c)
    {
        if(b+c==a)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else if(b>a&&b>c)
    {
        if(a+c==b)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else{
        if(a+b==c)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 10000005;
#define ll long long

class TaskD {
private:
	Debugger debugger;
	vector<ll> primes;
	void getPrimes(){
		vector<bool> vis(maxN, false);
		for(int i = 2; i < maxN; i++){
			if(!vis[i]){
				primes.push_back(i);
				for(int j = i; j < maxN; j+=i){
					vis[j] = true;
				}
			}
		}
	}

public:
	void solveOne(int it){
		ll n;
		cin >> n;
		if(n == 1){
			cout << 0 << endl;
			return;
		}
		getPrimes();
		int ans = 0;
		for(ll p : primes){
			int e = 0;
			while(n % p == 0){
				n/=p;
				e++;
			}
			int curr = 1;
			while(e > 0){
				e-=curr;
				if(e >= 0){
					ans++;
				}
				curr++;
			}
		}
		if(n > 1){
			ans++;
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 12904
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main()
{
    int p, q, r;
    cin >> p >> q >> r;
    cout << p + q + r - max({p, q, r}) << endl;

    return 0;
}

Measured memory_bytes: 256
/*                                              不开long long见祖宗                                                           */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
int sum=0;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a;
		cin>>a;
		sum+=a;
	}
	if(sum>n) cout<<-1;
	else cout<<n-sum;
	return 0;
}


Measured memory_bytes: 3600