akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
//setprecision(15)

int main() {
	int N, X[100]; cin >> N;
	int sum = 0;
	rep(i, N) {
		cin >> X[i];
		sum += X[i];
	}
	int mid = sum / N;
	int ans = 0;
	rep(i, N) ans += (X[i] - mid) * (X[i] - mid);
	for (int i = 1; i <= sum % N; i++) {
		int tmp = 0;
		rep(j, N) tmp += (X[j] - (mid+i)) * (X[j] - (mid+i));
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

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

    ll ct = min(C, A + B + 1LL);
    ll bt = B;

    cout << bt + ct << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque

def bfs(K:int) -> list:
    hasChecked = [False]*(K+1)
    cost_list = [0]*(K+1)
    cost_list[1] = 1
    
    que = deque([(cost_list[1], 1)])
    
    while que:
        cost, res = que.popleft()
        if hasChecked[res]:
            continue
        
        hasChecked[res] = True
        cost_list[res] = cost
        
        if not hasChecked[10*res%K]:
            que.appendleft((cost, 10*res%K))
            
        if not hasChecked[(res+1)%K]:
            que.append((cost+1, (res+1)%K))
            
            
    return cost_list


K = int(input())
cost_list = bfs(K)
print(cost_list[0])


Measured memory_bytes: 10564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll X,Y;cin >> X >> Y;
  int size = 0;
  while(X<=Y){
    X<<=1;
    ++size;
  }
  cout << size << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

	private static BufferedReader br;
	private static int[][] cells;

	static {
		cells = new int[14][14];
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	public static void main(String[] args) throws IOException {
		String line;
		int x, y, size, blind = 0, max = 0;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			StringTokenizer st = new StringTokenizer(line, ",");
			x = Integer.parseInt(st.nextToken()) + 2;
			y = Integer.parseInt(st.nextToken()) + 2;
			size = Integer.parseInt(st.nextToken());
			set(x, y, size);
		}
		for (x = 2; x < 12; x++) {
			for (y = 2; y < 12; y++) {
				if (cells[x][y] == 0) {
					blind++;
				}
				if (max < cells[x][y]) {
					max = cells[x][y];
				}
			}
		}
		System.out.println(blind + "\n" + max);
	}

	private static void set(int x, int y, int size) {
		cells[x][y]++;
		cells[x - 1][y]++;
		cells[x + 1][y]++;
		cells[x][y - 1]++;
		cells[x][y + 1]++;
		if (size >= 2) {
			cells[x - 1][y - 1]++;
			cells[x - 1][y + 1]++;
			cells[x + 1][y - 1]++;
			cells[x + 1][y + 1]++;
		}
		if (size >= 3) {
			cells[x - 2][y]++;
			cells[x + 2][y]++;
			cells[x][y - 2]++;
			cells[x][y + 2]++;
		}
	}
}

Measured memory_bytes: 16860
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[101],sum=0,ans=0,t;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  t=round(sum/(double)n);
  for(int i=0;i<n;i++) ans+=pow(a[i]-t,2);
  cout<<ans<<endl;
  return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    int n, x, t;
    cin >> n >> x >> t;
    cout << t * (n / x) + t * ((n % x) > 0);

	return 0;
}

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



int main()
{
    ios::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;
    n %= k;
    ll a = n;
    ll b = abs(n-k);
    cout << min(a,b);
    return 0;
}


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

using namespace std;

void makeCombination(int[], int, int, int, vector<int>&);
bool isMakeable(int[], int, int);

int main()
{
    int n;
    int A[20];

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

    int q;
    cin >> q;

    for(int i = 0; i < q; i++) {
        int tmp;
        cin >> tmp;
        if(isMakeable(A, n, tmp)) cout << "yes" << endl;
        else cout << "no" << endl;
    }

}

void makeCombination(int A[], int i, int n, int partialSum, vector<int> &makeableNum)
{
    if (i == n) makeableNum.push_back(partialSum);
    else {
        makeCombination(A, i + 1, n, partialSum + A[i], makeableNum);
        makeCombination(A, i + 1, n, partialSum, makeableNum);
    }
}

bool isMakeable(int A[], int n, int target)
{
    vector<int> makeableNum;

    makeCombination(A, 0, n, 0, makeableNum);
    
    for (int i = 0; i < makeableNum.size(); i++) {
        if (makeableNum.at(i) == target) return true;
    }
    
    return false;
}


Measured memory_bytes: 11036
#include <iostream>
#include <algorithm>
#include <string>
#define INF 100000

using namespace std;

int dp[1000][1000];
string X, Y;

int lcs(int i,int j){
  if(i < 0 || j < 0) return 0;
  if(dp[i][j] != INF) return dp[i][j];

  if(X[i] == Y[j]){
    dp[i][j] = lcs(i-1, j-1) + 1;
    return dp[i][j];
  } else {
    dp[i][j] =  max(lcs(i-1,j), lcs(i, j-1));
    return dp[i][j];
  }
}

void clear(){
  for(int i = 0;i < X.size();i++){
    for(int j = 0;j < Y.size();j++){
      dp[i][j] = INF;
    }
  }
}

int main(){
  int q;

  cin >> q;

  for(int i = 0;i < q;i++){
    cin >> X >> Y;
    
    clear();
    
    cout << lcs(X.size()-1, Y.size()-1) << endl;
  }

  return 0;
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int main()
{
	string s;
	cin>>s;
	int n=s.length();
	printf("%c%d%c\n",s[0],n-2,s[n-1]);
	return 0;
}


Measured memory_bytes: 256
import math
import calendar
import fractions
import itertools

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

n = int(input())
a = map(int, input().split())
b = []
ans = 0
for i in a:
    c = i
    cnt = 0
    while c % 2 == 0 and cnt < 2:
        c /= 2
        cnt += 1
    b.append(cnt)
if my_index(b, 1) == False:
    if b.count(2) + 1 >= b.count(0):
        ans = 1
    else:
        ans = 0
else:
    if b.count(2) >= b.count(0):
        ans = 1
    else:
        ans = 0
if ans == 1:
    print("Yes")
else:
    print("No")


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

int main(){
    int h, w; cin >> h >> w;
    int c[10][10], d[h][w];
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(i,h) rep(j,w) cin >> d[i][j];

    rep(k,10) rep(i,10) rep(j,10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    int ans = 0;

    rep(i,h) rep(j,w) {
        if(abs(d[i][j]) == 1) continue;
        ans += c[d[i][j]][1];
    }
    cout << ans << endl;
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i)   for(int i##_to_ = (t), i = (f); i <  i##_to_; i++)
#define downto(f, t, i)  for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i >  i##_to_; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '



signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int H, W, N; scanf("%d%d%d", &H, &W, &N);
    vector<int> A(N);
    times(N, i) scanf("%d", &A[i]);

    vector<vector<int>> C(H, vector<int>(W, 0));
    int color = 0, count = 0;
    times(H, i) times(W, j) {
        int jj = (i % 2) ? (W - 1 - j) : (j);
        ++count;
        if(count > A[color]) {
            ++color;
            count = 1;
        }
        C[i][jj] = color + 1;
    }

    times(H, i) {
        times(W, j) printf("%d ", C[i][j]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define inf 10000000000
using namespace std;

ll arr[100005];

int main(){
    ll n,k;
    cin>>n>>k;
    for(ll x=0; x<n; x++)cin>>arr[x];
    sort(arr,arr+n);
    ll mn=inf;
    for(ll x=0; x<=n-k; x++){
        mn=min(mn,arr[x+k-1]-arr[x]);
    }
    cout<<mn;
    return 0;
}



Measured memory_bytes: 1024
a = list(input().split())

stack = []

for ch in a:
    if ch in ['+', '-', '*']:
        b = int(stack.pop())
        a = int(stack.pop())

        if ch == '+':   stack.append(a+b)
        elif ch == '-': stack.append(a-b)
        else:           stack.append(a*b)
    else:   stack.append(ch)

print(stack[0])


Measured memory_bytes: 5596
#include <cstdio>
#include <cstdlib>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (node *)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL)root = z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
    if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 26016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> a(n+2);
  a[0] = 0;
  REP(i, 1, n) cin >> a[i];
  a[n+1] = 0;

  int sum = 0;
  rep(i, n+1) sum += abs(a[i+1]-a[i]);
  
  REP(i, 1, n){
    int res = sum-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]);
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	long long S = 0;
	for (auto& x : A) { cin >> x; S -= x; }
	for (auto& x : B) { cin >> x; S += x; }

	long long aa = 0, bb = 0;
	for (int i = 0; i < N; ++ i) {
		if (A[i] < B[i]) {
			if ((B[i]-A[i]) % 2 == 0) {
				aa += (B[i]-A[i]) / 2;
			} else {
				bb += 1;
				aa += (B[i]+1-A[i]) / 2;
			}
		} else if (A[i] > B[i]) {
			bb += A[i]-B[i];
		}
	}
	if (aa > S || bb > S) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
    ll n, m, x;
    cin >> n >> m >> x;
    ll c[n];
    ll 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 = 1e9;
    for (ll bit = 0; bit < (1 << n); bit++){
        ll cost = 0;
        ll comp[m];
        for (ll i = 0; i < m; i++) comp[i] = 0;
        for (ll i = 0; i < n; i++) {
            if (bit & (1 << i)){
                cost += c[i];
                for (ll j = 0;j < m;j++){
                    comp[j] += a[i][j];
                }
            }
           
        }
        bool flag = true;
        for (ll i = 0; i < m;i++) {
            if (comp[i] < x) flag = false;
        }
            if (flag) ans = min(ans, cost);
    }
    if (ans == 1e9) cout << "-1" << endl;
    else cout << ans << endl;
}


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

namespace _0296
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] yen = new int[] { 1, 5, 10, 50, 100, 500 };
            Console.WriteLine(RArInt().Select((x, i) => new { x, i }).Sum(y => y.x * yen[y.i]) >= 1000 ? 1 : 0);
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 20376
import java.util.*;

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

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

		List<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}

		for (int i = 0; i < n - 1 + m; i++) {
			g[sc.nextInt() - 1].add(sc.nextInt() - 1);
		}

		TopologicalSort ts = new TopologicalSort(g);

		int[] parents = new int[n];
		Iterable<Integer> order = ts.order();
		for (int i : order) {
			//System.out.print("S:  ");
			//System.out.println(i);
			for (int j = 0; j < g[i].size(); j++) {
				parents[g[i].get(j)] = i + 1;
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(parents[i]);
		}
	}

	private static class TopologicalSort {
		List<Integer>[] g;
		Queue<Integer> q = new LinkedList<>();
		boolean visited[];

		public TopologicalSort(List<Integer>[] g) {
			this.g = g;
			visited = new boolean[g.length];

			for (int v = 0; v < g.length; v++) {
				if (!visited[v]) dfs(v);
			}
		}

		public Iterable<Integer> order() {
			Stack<Integer> reverse = new Stack<>();
			for (int i : q) {
				reverse.push(i);
			}
			List<Integer> a = new ArrayList();
			while (!reverse.isEmpty())
				a.add(reverse.pop());
			return a;
		}

		private void dfs(int v) {
			if (visited[v]) return;
			visited[v] = true;
			for (Integer i : g[v]) {
				dfs(i);
			}
			q.offer(v);
		}
	}
}


Measured memory_bytes: 119604
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    sort(_all(a));
    cout << a.back() - a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int S, W;
	cin >> S >> W;

	if(S <= W) cout << "unsafe" << endl;
	else cout << "safe" << endl;


	return 0;
}


Measured memory_bytes: 3612
A = input()
B = input()

if len(A) > len(B):
  print("GREATER")
elif len(A) < len(B):
  print("LESS")
else:
  for i in range(len(A)):
    if int(A[i]) > int(B[i]):
      print("GREATER")
      exit()
    if int(A[i]) < int(B[i]):
      print("LESS")
      exit()
  print("EQUAL")

Measured memory_bytes: 3064
from collections import deque
a = input()
c = input()
d = []
alist = list(a)
adeque = deque(a)
count = 0
for i in range(int(c)):
  e = input().split()
  d.append(e)
for i in range(int(c)):
  if d[i][0]=="1":
    count = count + 1
  else:
    if d[i][1] == "1" and count % 2 == 0:
      adeque.appendleft(d[i][2])
    elif d[i][1] == "2" and count % 2 == 1:
      adeque.appendleft(d[i][2])
    else:
      adeque.append(d[i][2])
alist = list(adeque)
if count % 2 == 1:
  l = len(alist)
  for x in range(int(l//2)):
    alist[x],alist[l-x-1] = alist[l-x-1],alist[x]
answer = "".join(alist)
print(answer)
      

Measured memory_bytes: 123000
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  char x;
  cin>>x;
  if(x=='A') cout<<"T\n";
  else if(x=='T') cout<<"A\n";
  else if(x=='C') cout<<"G\n";
  else if(x=='G') cout<<"C\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;


public class Main {

	public static void main(String[] args) throws IOException{
		IndexList index = new IndexList();
		index.show();
	}
}

class IndexList{
	private Object[] index;
	public IndexList() throws IOException{
		index = createIndex();
	}
	private Object[] createIndex() throws IOException{
		ArrayList<String[]> index = new ArrayList<String[]>();
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		while((buf = bf.readLine()) != null){
			index.add(buf.split(" "));
		}
		return index.toArray();
	}
	public void show(){
		sort();
		String word = ((String[])index[0])[0];
		for(int i = 0; i < index.length; i++){
			StringBuffer buf = new StringBuffer();
			String[] data = (String[])index[i];
			word = (word.compareTo(data[0]) == 0)? word : data[0];
			System.out.println(word);
			buf.append(data[1]);
			while(i + 1 < index.length && word.compareTo(((String[])index[i + 1])[0]) == 0){
				buf.append(" " + ((String[])index[++i])[1]);
			}
			System.out.println(buf.toString());
		}
	}
	private void sort(){
		Arrays.sort(index, new Comparator<Object>() {
			@Override
			public int compare(Object o1, Object o2) {
				int difference = ((String[])o1)[0].compareTo(((String[])o2)[0]);
				if(difference == 0){
					return Integer.parseInt(((String[])o1)[1]) - Integer.parseInt(((String[])o2)[1]);
				}else{
					return difference;
				}
			}
		});	
	}
}

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

const int N = 10;
int a[N], p[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 5; i++) {
    p[i] = i;
  }
  sort(p, p + 5);
  int ans = 1234567;
  while (true) {
    int cur = 0;
    for (int i = 0; i < 5; i++) {
      if (cur % 10 != 0) {
        int k = 10 - (cur % 10);
        cur += k;
      }
      cur += a[p[i]];
    }
    ans = min(ans, cur);
    if (!next_permutation(p, p + 5)) {
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
N=int(input())
SP=[input().split() for l in range(N)]
for n,sp in enumerate(SP):
    sp.append(n+1)
    sp[1]=100-int(sp[1])
SP.sort(key = 
lambda x: (x[0], x[1])
)
for s,p,t in SP:
    print(t)

Measured memory_bytes: 38256
#include<stdio.h>

double h[10001];

main(){
     int i=0;
     int j,l;
     double high,temp;
     while(scanf("%lf",&high)!=EOF){
       h[i]=high;
       i++;
     }
     for(j=i-1;j>0;j--){
       for(l=0;l<j;l++){
	 if(h[l]<h[l+1]){
	   temp=h[l];
	   h[l]=h[l+1];
	   h[l+1]=temp;
	 }
       }
     }

     printf("%.1f\n",h[0]-h[i-1]);

  return 0;
}

Measured memory_bytes: 0
N=int(input())
A=list(map(int,input().split()))
m={}
for i in range(N):
  if A[i] in m:
    m[A[i]] += 1
  else:
    m[A[i]] = 1
ans = 0
for k,n in m.items():
  if k <= n:
    ans += n-k
  else:
    ans += n
print(ans)



Measured memory_bytes: 21584
#include<bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct matrix{
	int s[3][3];
	matrix(){memset(s,0,sizeof s);}
	int*operator[](int x){return s[x];}
};
matrix operator*(matrix a,matrix b){
	matrix c;
	for(int j=0;j<3;++j)
		for(int i=0;i<3;++i)
			for(int k=0;k<3;++k)
				c[i][k]=(c[i][k]+1ll*a[i][j]*b[j][k])%mod;
	return c;
}
matrix operator^(matrix x,int y){
	matrix ret;for(int i=0;i<3;++i)ret[i][i]=1;
	while(y){
		if(y&1)ret=ret*x;
		x=x*x;y>>=1;
	}
	return ret;
}
int x[100010],f[100010];
//a(n) = 4*a(n-1) - 2*a(n-2) + a(n-3) for n>2.
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	matrix start,S,T;start[0][0]=start[0][2]=1;
	T[0][2]=1;
	T[1][0]=1,T[1][2]=mod-2;
	T[2][1]=1,T[2][2]=4;
	auto get=[&](int x){if(x==1)return 1;return(start*(T^(x-1)))[0][2];};
	int xn=gi(),n=gi();for(int i=1;i<=n;++i)x[i]=gi();x[++n]=xn;
	for(int i=1;i<=n;++i){
		f[i]=get(x[i]);
		f[i]=(f[i]-S[0][2]+mod)%mod;
		if(i<n){
			S=S*T;
			S[0][0]=(S[0][0]+f[i])%mod;
			S[0][2]=(S[0][2]+f[i])%mod;
			S=S*(T^(x[i+1]-x[i]-1));
		}
	}
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 1024
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


n = int(input())
val = math.ceil(n/1000)
print(1000*val - n)










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

int main() {
	string a;
	int b;
  cin>>a;
	if(a[0]=='1')b++;
	if(a[1]=='1')b++;
	if(a[2]=='1')b++;
	cout<<b<<endl;
  return 0;
	}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
n = N
for a in (reversed(A)):
    if n*2 > N:
        B[n-1] = a
        n -= 1
        continue
    total = 0
    for i in range(2,N+2):
        if n*i <= N:
            total += B[n*i-1]
        else:
            if a == total % 2:
                B[n-1] = 0
            else:
                B[n-1] = 1
            break
    n -= 1

M = sum(B)
print(M)
C = [str(n+1) for n, v in enumerate(B) if v == 1]
print(' '.join(C))


Measured memory_bytes: 17588
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head

int main()
{
	ios::sync_with_stdio(false);
#ifdef RG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	bool flag = true;
	rep(i, 0, s.length()) {
		if (i % 2 == 0) {
			if (s[i] != 'h') {
				flag = false;
				break;
			}
		}
		else {
			if (s[i] != 'i') {
				flag = false;
				break;
			}
		}
	}
	if (s.length() % 2 == 1) flag = false;
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
cs =[list(map(int, input().split())) for _ in range(10)]
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
cs = warshall_floyd(cs)
As = [list(map(int, input().split())) for _ in range(H)]
ans = 0
for A in As:
    for a in A:
        if a != -1:
            ans += cs[a][1]
print(ans)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a;
  cin >> b;
  int diff = b - a;

  int aa=0;
  int bb=0;
  for(int i = 1;i<diff;i++){
    aa = aa + i;
  }
  bb = aa + diff;

  cout << bb-b<<endl;
  return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s, front;
    cin >> s;
    bool flip = false;
    int q;
    cin >> q;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            swap(s, front);
            flip = !flip;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                front += c;
            }
            else {
                s += c;
            }
        }
    }
    reverse(all(front));
    front += s;
    cout << front << endl;
    return 0;
}



Measured memory_bytes: 1128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    if(n>=m){cout<<0<<endl;return 0;}
    vector<int> x(m);
        rep(i,m) cin>>x.at(i);
        sort(all(x));
    vector<P> sa(m-1);
    rep(i,m-1) sa[i]=P(x[i+1]-x[i],i);
    sort(all(sa));
    int ans=0;
    rep(i,m-n){
        ans +=sa[i].first;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long;

multiset<ll, greater<ll>> leader; // scores of leaders'

ll n, q;
ll raw_score[1000005];
ll sorted_score[1000005];
string com;
ll x;

inline ll f(ll r);

int main()
{
    scanf("%lld %lld", &n, &q);
    for (int i = 0; i < n; i++) {
        scanf("%lld", raw_score + i);
        sorted_score[i] = raw_score[i];
    }

    leader.insert(-1ll * 5ll * 1'000'000'000ll);
    leader.insert(5ll * 1'000'000'000ll);
    
    sorted_score[n] = -1ll * 5ll * 1'000'000'000ll;
    sorted_score[n + 1] = 5ll * 1'000'000'000ll;
    sort(sorted_score, sorted_score + n + 2, greater<>());

    for (int i = 0; i < q; i++) {
        cin >> com;
        scanf("%lld", &x);
        
        if (com == "ADD") {
            leader.insert(raw_score[x - 1]);
        }
        else if (com == "REMOVE") {
            leader.erase(leader.find(raw_score[x - 1]));
        }
        else if (com == "CHECK") {
            //binary search
            ll invalid = -1;
            ll valid = 1'000'000'000; //2 * 1e9
            
            if (f(valid) > x) {
                puts("NA");
                continue;
            }

            while (valid - invalid > 1) {
                ll mid = (invalid + valid) / 2;

                if (f(mid) <= x) {
                    valid = mid;
                }
                else {
                    invalid = mid;
                }
            }

            printf("%lld\n", valid);
        }
    }
    
}

inline ll f(ll r)
{
    ll cnt = 0;
    ll s, t;
    t = 0;
    for (auto i: leader) {
        s = t;
        t = lower_bound(sorted_score, sorted_score + n + 2, i, greater<>())
            - begin(sorted_score);

        ll key = sorted_score[s] - r;

        cnt += (begin(sorted_score) + t) -
            upper_bound(sorted_score + s, sorted_score + t, key, greater<>());
    }

    return cnt;
}


Measured memory_bytes: 18960
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 = sc.nextInt();

		if (n % 500 <= a) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long B, long long X){
    if(X < A || A+B < X) {
        cout << NO << endl;
    } else {
        cout << YES << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long X;
    scanf("%lld",&X);
    solve(A, B, X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=b-1;i>=a;i--)
#define mod 1000000007
#define pb push_back
#define son ll t; cin>>t;while(t--)
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mpr make_pair
#define ff first
#define ss second
#define inf 5e18
#define dex(x,y) fixed<<setprecision(x)<<y
void start()
{
        #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #endif
}

int32_t main()
{
    fst
    int n;
    cin>>n;
    int a[n];
    fr(i,0,n)
    cin>>a[i];
    int dp[n+1];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    fr(i,2,n)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        //cout<<dp[i]<<' ';
    }
    cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 5116
// https://atcoder.jp/contests/abc130/tasks/abc130_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

// x, yが中心を通っていたら複数解
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    // ｘが幅の中央 AND ｙが高さの中央なら複数解
    cout << (double)w * h / 2 << " ";
    if (x * 2 == w && y * 2 == h) {
        cout << "1\n";
    } else {
        cout << "0\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,s,f,t[501]={};
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>c>>s>>f;
    for(int j=1;j<=i;j++)
      t[j]=c+max(s,(t[j]+f-(t[j]%f==0?f:t[j]%f)));
  }
  for(int i=1;i<=n;i++) cout<<t[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,win,lose;
string s;

int  solve(){
    int cunt_p=0,cunt_g=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='g'){
            if(cunt_p<cunt_g){
                cunt_p++; win++;
            }else cunt_g++;
        }else{
            if(cunt_p<cunt_g){
                cunt_p++;
            }else{
                cunt_g++; lose++;
            }
        }
    }
    
    return win-lose;
    
}
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);

    cin>>s;
    
    cout<<solve()<<"\n";
    
    
    return 0;
}


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

using P=pair<ll,ll>;

std::vector<P> cal(ll x){
  std::vector<P> v;
  std::vector<bool> prime(sqrt(x)+1,true);

  for (int i = 2; i < sqrt(x); i++) {
    if(prime[i]==false)continue;
    for (int j = i+i; j < sqrt(x); j+=i) {
      prime[j]=false;
    }

  }

  for (int i = 2; i < sqrt(x); i++) {
    if(prime[i]==false)continue;
    else if(x%i==0 && x/i>0){
      ll cnt=0;
      while (x/i>0 && x%i==0) {
        x/=i;
        cnt++;
      }
      v.push_back(P(i,cnt));
    }
  }
  if(x!=1)v.push_back(P(x,1));

  return v;

}

int main(){
  ll n;
  std::cin >> n;

  if(n==1){
    std::cout << 0 << '\n';
    return 0;
  }

  std::vector<P> v;

  ll ans=0;
  v=cal(n);
  if(v.size()==0){
    std::cout << 1 << '\n';
    return 0;
  }

  for (P p:v) {
    int temp=p.second;
    int ncnt=0;
    if(temp==1)ncnt=1;
    else
    for (int i = 1; i <= temp; i++){
      temp-=i;
      ncnt++;
    }
    ans+=ncnt;
  }

  std::cout << ans << '\n';





  return 0;
}


Measured memory_bytes: 3836
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int a = scanner.nextInt();
        boolean flg = false;

        if(a>81) {
        	System.out.println("No");
        }else {

        	for(int i=9;i>0;i--) {
        		if(a%i==0&&a/i<=9) {
        			flg = true;
        			break;
        		}
        	}

        	if(flg) {
        		System.out.println("Yes");
        	}else {
        		System.out.println("No");
        	}
        }
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

const int mod = 1e9+7;

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

    map<int,ll> factor;
    for(int k=2; k<=n; k++){
        int tmp = k;
        for(int i=2; i<=tmp; i++){
            while(tmp%i==0){
                factor[i]++;
                tmp/=i;
            }
        }
    }
    // for(auto f : factor){
    //     cout << f.first << ":" << f.second << endl;
    // }

    int ans=1;
    for(auto f : factor){
        ans=(ans*(f.second+1))%mod;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ac = [0 for i in range(n)]
wa = [0 for i in range(n)]
a = 0
b = 0
for i in range(m):
  s,t = map(str,input().split())
  if ac[int(s)-1] == 0:
    if t == "AC":
      a += 1
      ac[int(s)-1] = 1
    else:
      b += 1
      wa[int(s)-1] += 1
for i in range(n):
  if ac[i] == 0:
    b -= wa[i]
print(a,b)

Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define long long long long
using namespace std;
long long n,i,j,rt,cnt,sz[200005],rnd[200005];
long long l[200005],r[200005];
long long ans,m,a[200005],val[200005];
long long nwnd(long long x)
{
	cnt++;
	l[cnt]=r[cnt]=0;
	sz[cnt]=1;val[cnt]=x;rnd[cnt]=rand()*32768+rand();
	return cnt;
}
void pushup(long long x)
{
	sz[x]=1+sz[l[x]]+sz[r[x]];
}
void split(int x,long long y,long long &sl,long long &sr)
{
	if (!x)
	{
		sl=sr=0;
		return;
	}
	if (val[x]<=y)
	{
		split(r[x],y,r[x],sr);
		sl=x;
		pushup(x);
		return;
	}
	else
	{
		split(l[x],y,sl,l[x]);
		sr=x;
		pushup(x);
		return;
	}
}
int merge(int x,int y)
{
	if (!x||!y) return x+y;
	if (rnd[x]>rnd[y])
	{
		r[x]=merge(r[x],y);
		pushup(x);
		return x;
	}
	else
	{
		l[y]=merge(x,l[y]);
		pushup(y);
		return y;
	}
}
int main()
{
	cin>>n>>m;
	fz1(i,n)
	{
		cin>>a[i];
		a[i]-=m;
		a[i]+=a[i-1];
	}
	rt=nwnd(0);
	fz1(i,n)
	{
		long long t1,t2;
		split(rt,a[i],t1,t2);
		ans+=sz[t1];
		rt=merge(merge(t1,nwnd(a[i])),t2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  rep(i, 0, a + 1) {
    rep(j, 0, b + 1) {
      if(c == i * b + j * a - ((i * j) * 2)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

int main(void){
    
    int K,N;
    cin >> K >> N;
    
    int A[N];
    
    for(int i = 0; i < N;i++)cin >> A[i];
    
    int D[N];
    
    for(int i = 0; i < N-1;i++){
        D[i] = A[i+1] - A[i]; 
    }
    
    D[N-1] = abs(K - A[N-1]) + abs(A[0]);
    
    sort(D,D+N);
    int sum = 0;
    for(int i = 0; i< N-1;i++){
        //cout << D[i] << endl;
        sum += D[i];
    }
    
    cout << sum << endl;
    
    
    
    
    
}


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

static const int K = 10001;

void CountingSort(int A[], int B[], int n) {
  int C[K];
  for (int i = 0; i < K; i++) {
    C[i] = 0;
  }
  for (int j = 0; j < n; j++) {
    C[A[j]]++;
  }
  for (int i = 1; i < K; i++) {
    C[i] = C[i] + C[i-1];
  }

  for (int j = n-1; j >= 0; j--) {
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
  }
}

int main() {
  int n;
  cin >> n;
  int A[n], B[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  CountingSort(A, B, n);
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << B[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 18728