akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define emp emplace
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 200100;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll N,Q,a,b,c,d,e,M,X;
ll A[MAXN];
ll B[MAXN];
map<ll,ll> p;
ll ans;
vi V[MAXN];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>M;
	for(int i=1;i<=N;++i)cin>>A[i];
	for(int i=0;i<M;++i){
		cin>>a>>b;V[a].pb(b);V[b].pb(a);
	}
	for(int i=1;i<=N;++i){
		int ok=1;
		for(auto t:V[i])if(A[t]>=A[i])ok=0;
		ans+=ok;
	}
	cout<<ans;
}

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

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

    ll n, i, sum=0L;
    cin >> n;
    for(i=1; i<=n;i++) {
        if((i%3==0 && i%5==0)||(i%3==0)||(i%5==0)) continue;
        else sum += i;
    }
    cout << sum << "\n";

    return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

template <typename T>
void precision_cout(T x, int n, bool is_endl = false) {
    cout << fixed << setprecision(n) << x;
    if (is_endl) cout << endl;
}

template <typename T>
T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

template <typename T>
T radian(T angle) {
    return angle * M_PI / 180.0;
}

void solve() {
    int h, w, k;
    cin >> h >> w >> k;

    int black_cnt = 0;
    char c[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
            if (c[i][j] == '#') black_cnt++;
        }
    }

    int patterns = 0, black_to_red;
    for (int h_bit = 0; h_bit < (1<<h); h_bit++) {
        for (int w_bit = 0; w_bit < (1<<w); w_bit++) {
            black_to_red = 0;

            for (int i = 0; i < h; i++) {
                if (h_bit & (1<<i)) {
                    for (int j = 0; j < w; j++) {
                        if (c[i][j] == '#') black_to_red++;
                    }
                }
            }

            for (int i = 0; i < w; i++) {
                if (w_bit & (1<<i)) {
                    for (int j = 0; j < h; j++) {
                        if (c[j][i] == '#' && !(h_bit & (1<<j))) {
                            black_to_red++;
                        }
                    }
                }
            }

            if (black_cnt - black_to_red == k) {
                patterns++;
            }
        }
    }

    cout << patterns << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 3532
N = int(input())
px = list(map(int,input().split()))

min_ = px[0]
cnt = 1
for i in range(1, len(px)):
    min_ = min(px[i-1], min_)
    #print(i, min_)
    if min_ > px[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

int main() {
    // input, ready
    int N,M;
    cin >> N >> M;
    map<int,map<int,int>> duple_check;
    int ans_digit[3];
    memset(ans_digit,-1,sizeof(ans_digit));
    for (int i=0; i<M; i++) {
        int s,c;
        cin >> s >> c;
        duple_check[s][c]++;
        ans_digit[s-1]=c;
    }
    for (auto d: duple_check) {
        if (d.second.size() > 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    // resolve
    if (N==1) {
        if (M==0) cout << 0 << endl;
        else cout << ans_digit[0] << endl;
        return 0;
    }
    int ans=0;
    if (ans_digit[0] == -1) {
        ans_digit[0] = 1;
    } else if (ans_digit[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    for (int i=0; i<N; i++) {
        ans *= 10;
        if (ans_digit[i] == -1) ans +=0;
        else ans += ans_digit[i];
    }


    // output
    cout << ans << endl;
    // cout << fixed << setprecision(10) << middle << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {-1, 0, 1, 0};
char dir[4] = {'U', 'R', 'D', 'L'};

int main()
{
  int l, x, y, d;
  string str;
  bool a[11][11][11][11]; // current pos[h][w], next pos[h][w]

  while(cin>>str){
    l = str.size()+1;
    y = 1;
    fill(&a[0][0][0][0], &a[l+1][0][0][0], false);

    for(int i = 1; i < l; ++i)
      if(str[i-1] == '1')
	a[0][i-1][0][i] = a[0][i][0][i-1] = true;

    for(int i = 1; i <= 8; ++i){
      cin >> str;
      if(i%2){
	for(int j = 0; j < l; ++j)
	  if(str[j] == '1') 
	    a[y-1][j][y][j] = a[y][j][y-1][j] = true;
      } else {
	for(int j = 1; j < l; ++j)
	  if(str[j-1] == '1')
	    a[y][j-1][y][j] = a[y][j][y][j-1] = true;
	y++;
      }
    }

    x = y = d = 0;
    do {
      for(int i = 3; i < 7; ++i){
	int dx = x+xdir[(d+i)%4], dy = y+ydir[(d+i)%4];
	
	if(0 <= dx && dx < l && 0 <= dy && dy < l && a[y][x][dy][dx]){
	  cout << dir[(d+i)%4];
	  // cout<<": ("<<x<<", "<<y<<") -> ("<<dx<<", "<<dy<<")"<<endl;  
	  a[y][x][dy][dx] = false;
	  x = dx;
	  y = dy;
	  d = (d+i)%4;
	  break;
	}
      }
    } while(x+y != 0);
    
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

    for(int i = 0; i < s.length(); i++){
        
      if(s[i] == ','){
        
        s[i] = ' ';
      
      }
    
    }
  
  cout << s << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
vector<vpi> graph;
int ans[MX];

void dfs(int v, int p, int skip) {
    int c = 1;
    F0R(i, sz(graph[v])) {
        int nxt = graph[v][i].f;
        if (nxt == p) continue;
        if (c == skip) c++;
        ans[graph[v][i].s] = c;
        dfs(nxt, v, c);
        c++;
    }
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int K = 0;
    F0R(i, N) {
        vpi blank; graph.pb(blank);
    }
    F0R(i, N-1) {
        int A, B; cin >> A >> B; A--; B--;
        graph[A].pb({B, i});
        graph[B].pb({A, i});
        K = max(K, sz(graph[A]));
        K = max(K, sz(graph[B]));
    }

    cout << K << endl;

    dfs(0, -1, -1);
    F0R(i, N-1) {
        cout << ans[i] << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 11116
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;//T
 
Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
Node treeSearch(Node u, int k){
  while((u != NIL) && (k != u->key)){
    if (k < u->key){
    u = u->left;
    }
    else u = u->right;
  }
  return u;
}
 
Node treeSuccessor(Node x){
  Node y;
 
  if(x->right != NIL)
    return treeMinimum(x->right);
 /* y = x->parent;
 
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;*/
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
  if(z->left == NIL || z->right ==NIL)
    y = z;
  else y = treeSuccessor(z);
 
  if(y->left != NIL)
    x = y->left;
  else x = y->right;
 
  if(x != NIL)
    x->parent = y->parent;
  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else y->parent->right = x;
 
  if(y != z)
    z->key = y->key;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
   
  z = 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) {
    if(u->left != NIL) inorder(u->left);
    printf(" %d",u->key);
    if(u->right != NIL) inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    if(u->left != NIL) preorder(u->left);
    if(u->right != NIL) 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: 19360
#include <bits/stdc++.h>
using namespace std;

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

  sort(d, d + N);
  int i = d[N / 2], count = 0;
  while (i > d[N / 2 - 1]) {
    count++;
    i--;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int i;
  int n;  
  int t[500];
  int s[10000];
  int q;
  int cnt;
  int j;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&s[i]);  
}
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&t[i]); 
}
 
    for(i = 0 ; i < q ; i++){
      for(j = 0 ; j < n ; j++){
	if(s[j] == t[i]){cnt++;
       break;
    }
}
  }
  
  

    printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 640
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# [a, b].min が遅いので
def min(a, b)
  return a < b ? a : b
end

# [a, b].max が遅いので
def max(a, b)
  return a > b ? a : b
end

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i).sort
end
N, l_list = gets_n_and_i_list

total = 0

1.upto(N-1) do |i|
  a = l_list[i]
  k = i + 1
  num = 0
  i.times do |j|
    b = l_list[j]
    while k < N
      c = l_list[k]
      if c < a + b
        num += 1
      else
        break
      end
      k += 1
    end
    total += num
  end
end

puts total

Measured memory_bytes: 4220
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

LL H, W, N;
std::string field[1123];
LL Sx, Sy, xy[11];
LL ans;

LL d[1123456];
std::vector<edge>G[1123456];
void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(d, d + H * W + 1, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (d[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	try {
		in >> H >> W >> N;
		rep(i, H) { in >> field[i]; }

		rep(h, H)
		{
			rep(w, W)
			{
				if (field[h][w] == 'X') { continue; }
				else if (field[h][w] == 'S') { Sx = h; Sy = w; }
				else if (field[h][w] != '.') { xy[field[h][w] - '0'] = h*W + w; }
				if (h < H - 1)
				{
					if (field[h + 1][w] != 'X')
					{
						G[h*W + w].push_back({ (h + 1)*W + w,1 });
						G[(h + 1)*W + w].push_back({ h*W + w,1 });
					}
				}
				if (w < W - 1)
				{
					if (field[h][w + 1] != 'X')
					{
						G[h*W + w].push_back({ h*W + (w + 1),1 });
						G[h*W + (w + 1)].push_back({ h*W + w,1 });
					}
				}
			}
		}
		dijkstra(Sx*W + Sy);
		rep(i, N)
		{
			ans += d[xy[i + 1]];
			dijkstra(xy[i + 1]);
		}

		out << ans << std::endl;
		return 0;
	}
	catch (std::bad_alloc) { return 0; }
	catch (...) { return 0; }
}

Measured memory_bytes: 58320
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
ll n;ll a[200000];vector<ll> e[200000];multiset<ll> s;ll ans[200000];
void dfs(ll i, ll p)
{
    s.insert(a[i]);
    auto it=s.lower_bound(a[i]);ll d=-1;it++;                                   
    if(it!=s.end()){d=*it;s.erase(it);}
    ans[i]=s.size();
    for(auto j : e[i])
    {
        if(j==p)continue;
        dfs(j,i);
    }
    s.erase(a[i]);
    if(d!=-1)s.insert(d);
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n-1; ++i)
    {
        ll u,v;cin >> u >> v;u--;v--;
        e[u].push_back(v);e[v].push_back(u);
    }
    dfs(0,-1);
    for (int i = 0; i < n; ++i)
    {
        cout << ans[i] << "\n";
    }
    }

Measured memory_bytes: 29628
import math


def inp():
    return(int(input()))


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


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = 100000000000
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)


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

using namespace std;

const long long MOD = 1e9 + 7;
long long n;

long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

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

    cin >> n;
    if(n == 0){
        cout << 0 << '\n';
    } else {
        long long ans = binpow(10, n);
        ans = ((ans - 2 * binpow(9, n)) % MOD + MOD) % MOD;
        ans = (ans + binpow(8, n)) % MOD;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3592
n = int(input())

F = [int(input().replace(" ", ""), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]

answer = -float("inf")
for i in range(1, 2**10):
    temporary = 0
    for j in range(n):
        c = bin(i & F[j]).count("1")
        temporary += P[j][c]
    answer = max(answer, temporary)

print(answer)


Measured memory_bytes: 3188
#include <stdio.h>

int main()
{
    int card[4][13]={0};
    int i, j, n, num;
    char suit;
    const char suits[4]={'S', 'H', 'C', 'D'};
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf(" %c %d", &suit, &num);
        if     (suit=='S') card[0][num-1]=1;
        else if(suit=='H') card[1][num-1]=1;
        else if(suit=='C') card[2][num-1]=1;
        else if(suit=='D') card[3][num-1]=1;
    }

    for(i=0; i<4; i++) {
        for(j=0; j<13; j++) {
            if(card[i][j]==0) printf("%c %d\n", suits[i], j+1);
        }
    }
    return 0;
}

Measured memory_bytes: 596
abc = {'a':'b', 'b':'c', 'c':'d', 'd':'e', 'e':'f', 'f':'g', 'g':'h', 'h':'i', 'i':'j', 'j':'k', 'k':'l', 'l':'m', 'm':'n', 'n':'o', 'o':'p', 'p':'q', 'q':'r', 'r':'s', 's':'t', 't':'u', 'u':'v', 'v':'w', 'w':'x', 'x':'y', 'y':'z'}
c = input()
print(abc[c])

Measured memory_bytes: 3060
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

std::vector<LL> prime;
void MakePrime(LL n) {
	prime.emplace_back(2);
	for (int i = 3; i < n; i += 2) {
		bool a = false;
		for (int j = 3; j <= std::sqrt(i); j += 2) {
			if (i%j == 0) {
				a = true;
			}
		}
		if (a == false) {
			prime.emplace_back(i);
		}
	}
}

int n;
vector<LL> a;

int main() {
	MakePrime(2155);
	cin >> n;
	a.resize(n);
	REP(i, n)cin >> a[i];
	map<LL, pair<LL, LL>> cnts;
	for (auto v : a) {
		LL val = 1, another = 1;
		for (auto p : prime) {
			if (v % p != 0) continue;
			int cnt = 0;
			while (v % p == 0) {
				cnt++;
				v /= p;
			}
			if (cnt % 3 == 1) {
				val *= p;
				another *= p * p;
			}
			else if (cnt % 3 == 2) {
				val *= p * p;
				another *= p;
			}
		}
		if (v > 1) {
			LL tmp = sqrt(v);
			LL root = 0;
			for (int i = -1; i < 2; i++) if ((tmp + i) * (tmp + i) == v) root = tmp + i;
			val *= v;
			if (root) another *= root;
			else another *= v * v;
		}
		cnts[val].second = another;
		cnts[val].first++;
	}
	auto tmp = cnts;
	LL ans = 0;
	for (auto u : tmp) if (u.first != 1 && cnts[u.second.second] < u.second) ans += u.second.first;
	if (cnts[1].first != 0) ans++;
	cout << ans << endl;
}

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

using namespace std;

int main()
{
  int N, X;
  cin >> N >> X;

  vector<int> L(N);

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

  int D = 0;
  int ans = 1;

  for (int i = 0; i < N; i++) {
    D += L[i];
    if (D <= X) {
      ans += 1;
    }
  }

  cout << ans << endl;

  return 0;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	q *= 4, h *= 2;
	int x = min({ q,h,s });
	if (x * 2 <= d) {
		cout << x * n << endl;
	}
	else {
		cout << d * (n / 2) + x * (n % 2) << endl;
	}

	return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    ll k;
    for(k = 2; k * (k - 1) < 2 * N; ++k){}
    if(k * (k - 1) != 2 * N){
        cout << NO << endl;
        return;
    }

    vector<vector<ll>> ans(k);
    ll offset = 0;
    for(ll x = 0; x < k - 1; ++x){
        const ll len = k - 1 - x;
        for(ll i = 0; i < len; ++i){
            ans.at(x).push_back(i + offset);
            ans.at(x + i + 1).push_back(i + offset);
        }
        offset += len;
    }

    cout << YES << endl;
    cout << k << endl;
    REP(i, k){
        cout << k - 1 << ' ';
        REP(j, k - 1){
            cout << ans.at(i).at(j) + 1;
            if(j + 1 < k - 1){
                cout << ' ';
            }
        }
        cout << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
void solveA()
{
  long long a,b,tem;
  cin>>a>>b;
  tem=(a+b);
  if(tem%2==0)
  {
    cout<<tem/2<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
}
void solveB()
{
  int n,i,j,count;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  j=1;
  count=0;
  for(i=0;i<n;i++)
  {
    if(ar[i]!=j)
    {
      count++;
    }
    if(count>2)
    {
      cout<<"NO"<<endl;
      return;
    }
    j++;
  }
  cout<<"YES"<<endl;
}
void solveC()
{
  int a,b,x,y;
  cin>>a>>b;
  x=max(a,b);
  y=min(a,b);
  if((x-y)>=2)
  {
    cout<<2*x-1<<endl;
  }
  else
  {
    cout<<x+y<<endl;
  }
}
void solveD()
{
  int n,i,j;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  int count=n;
  for(i=n-1;i>=0;i--)
  {
    for(j=i-1;j>=0;j--)
    {
      if(ar[i]<ar[j])
      {
        count--;
        break;
      }
    }
  }
  cout<<count<<endl;
}
void solveE()
{
  int h,w,x,y,H,W;
  cin>>H>>W;
  cin>>h>>w;
  x=h*W;
  y=(H-h)*w;
  cout<<(H*W)-(x+y)<<endl;
}
void solveF()
{
  int n,m,c,i,j;
  cin>>n>>m>>c;
  int b[m];
  int ar[n][m];
  for(i=0;i<m;i++)
  {
    cin>>b[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      cin>>ar[i][j];
    }
  }
  int count=0;
  int sum;
  for(i=0;i<n;i++)
  {
    sum=0;
    for(j=0;j<m;j++)
    {
      sum=sum+ar[i][j]*b[j];
    }
    if((sum+c)>0)
    {
      count++;
    }
  }
  cout<<count<<endl;
}
void solveG()
{
  
}
int main()
{
 // solveA();
  //solveB();
 solveC();
 //solveD();
 //solveE();
// solveF();
  return 0;
}

Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int c[1010];

int main(void){
	int h,w,a,b,i,j,x,y,p;
	bool flag = false;
	cin >> h >> w;
	cin >> a >> b;
	for(i=0; i<=h; ++i){
		x = i*a+(h-i)*(w-a);
		for(j=0; j<=w; ++j){
			y = j*b+(w-j)*(h-b);
			if(x==y){
				x = i;
				y = j;
				flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	}
	if(flag){
		for(i=0; i<x; ++i){
			p = 0;
			for(j=0; j<y; ++j){
				if(!(p<a)){
					cout << "0";
					continue;
				}
				if(!(c[j]<b)){
					cout << "0";
					continue;
				}
				cout << "1";
				++c[j];
				++p;
			}
			for(j=y; j<w; ++j){
				if(!(p<a)){
					cout << "0";
					continue;
				}
				if(!(c[j]<h-b)){
					cout << "0";
					continue;
				}
				cout << "1";
				++c[j];
				++p;
			}
			cout << endl;
		}
		for(i=x; i<h; ++i){
			p = 0;
			for(j=0; j<y; ++j){
				if(!(p<w-a)){
					cout << "0";
					continue;
				}
				if(!(c[j]<b)){
					cout << "0";
					continue;
				}
				cout << "1";
				++c[j];
				++p;
			}
			for(j=y; j<w; ++j){
				if(!(p<w-a)){
					cout << "0";
					continue;
				}
				if(!(c[j]<h-b)){
					cout << "0";
					continue;
				}
				cout << "1";
				++c[j];
				++p;
			}
			cout << endl;
		}
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
	long long n, tmp, countp = 0;
	vector<long long> p;
	cin >> n;
	for (long long i = 0; i < n; i++) {
		cin >> tmp;
		p.push_back(tmp);
	}

	//これだとoxのときにその前をまきこめない
	//oxxのとき一気にoooにすればとくだが
	//ooxになってしまう可能性が...。

		for (long long i = 0; i < p.size() - 1; i++) {
			if (p[i] == i + 1) {
				//右隣とスワップ(ただし右隣があるなら)
				swap(p[i], p[i + 1]);
				countp++;
			}
		}
		if (p[p.size() - 1] == p.size()) {
			countp++;
		}


			cout << countp;




	return 0;
}



Measured memory_bytes: 1400
"""
author : halo2halo
date : 18,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

W = readline().rstrip()
wether = ['Sunny', 'Cloudy', 'Rainy']
ans = wether.index(W) + 1
print(wether[ans % 3])


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b,c;
int main(){
	while(scanf("%d %d %d",&a,&b,&c) && a!=-1){
		int ru=a*3600+b*60+c;
		ru=7200-ru;
		int ans1=ru/3600;
		int ans2=(ru%3600)/60;
		int ans3=(ru%60);
		ru*=3;
		int bns1=ru/3600;
		int bns2=(ru%3600)/60;
		int bns3=(ru%60);
		printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",ans1,ans2,ans3,bns1,bns2,bns3);
	}
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll ;
typedef long double ld ;
typedef vector< ll > vi ;
typedef pair<ll, ll > ii ;
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define se second
#define fi first
#define mod 1000000007
int main()
{
    ll n ;
    cin >> n ;
    ll a[n+1];
    for(int i = 0 ; i < n ; i ++ )
    {
        cin >> a[i];
    }
    if(n == 1)
    {
        cout << 1 <<endl ;
        return 0 ;
    }
    bool b = 0 ;
    ll ans =  0 ;
    int j , last;
    for(int i = 1 ; i < n ; i++ )
    {
        if(a[i] == a[i-1])
        {
            for( j = i ; j < n; j++ )
            {
                if(a[j-1] != a[j])
                    break ;
            }
            i = j ;
        }
        if(a[i] > a[i-1])
        {
            for( j = i ; j < n; j++ )
            {
                if(a[j-1] > a[j])
                    break ;
            }
            ans++;
            i = j ;
            last = j ;
        }
        else
        {
            for( j = i ; j < n; j++ )
            {
                if(a[j-1] < a[j])
                    break ;
            }
            ans++;
            i = j ;
            last = j ;
        }
    }
    if(last != n) ans++;
    cout << ans <<endl;
}


Measured memory_bytes: 1024
#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>;

int main() {
  vector<int> t(365);
  int d;
  vector<int> c(26);
  vector<vector<int>> s(365, vector<int>(26));
  cin >> d;
  rep(i,26) cin >> c[i];
  rep(i,365) {
    int mx = 0;
    rep(j,26) {
      int ins;
      cin >> ins;
      if (ins > mx) {
        t[i] = j + 1;
        mx = ins;
      }
      s[i][j] = ins;
    }
  }

  rep(i,365) {
    cout << t[i] << endl;
  }
}

Measured memory_bytes: 3680
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, k] <- map readInt . BS.words <$> BS.getLine
  print $ solve n k

solve :: Int -> Int -> Int
solve n k = if n `mod` k == 0 then 0 else 1

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


Measured memory_bytes: 380
#include <iostream> 
using namespace std;
int k[2020],f[2000005],a[2000005],g[2000005];
long long sum;
int main(){
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++) a[i+1]=s[i]-'0';
    int l=1;
    for(int i=n;i>=1;i--){
    	g[i]=l;
    	l*=10;
    	l%=2019;
    }
    for(int i=n;i>=1;i--){
    	f[i]=(f[i+1]+a[i]*g[i])%2019;
    	k[f[i]]++;
    }
    sum=k[0];
    sum+=(k[0]*(k[0]-1)/2);
    for(int i=1;i<=2018;i++){
    	sum+=(k[i]*(k[i]-1)/2);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 6048
# include"stdio.h"
# include"stdlib.h"
//# include"math.h"
int main(){
    int n;
    scanf("%d",&n);
    long long int a[n],x=0,y=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i==0)x=a[i];
        else y+=a[i];
    }
    long long int min=llabs(x-y);
    for(int i=0;i<n-1;i++){
        if(llabs(x-y)<min) min=llabs(x-y);
        if(llabs(x-y)==0) break;
        x+=a[i+1];
        y-=a[i+1];
    }
    printf("%lld\n",min);
}


Measured memory_bytes: 3264
import java.util.*;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),g=s.nextInt()/100;
		int[]dp=new int[g+1];
		Arrays.fill(dp,1,g+1,9000);
		for(int i=1;i<=n;++i) {
			int m=s.nextInt(),b=s.nextInt()/100;
			for(int j=g-1;j>=0;--j) {
				for(int k=1;k<=m;++k) {
					int t=Math.min(g,j+k*i+(k<m?0:b));
					dp[t]=Math.min(dp[t],dp[j]+k);
					if(t==g)
						break;
				}
			}
		}
		System.out.println(dp[g]);
	}
}


Measured memory_bytes: 21972
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  4 21:05:54 2016

@author: you
"""

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)

n = [a,b,c]

n.sort(reverse=True)

x = n[1] * n[2]

for i in range(3):
    if n[i] % 2 == 0:
        x = 0

print(x)


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll A(N);
  dll B;
  REP(i, 0, N) {
    cin >> A[i];
    if (i % 2 == 0) {
      B.emplace_back(A[i]);
    } else {
      B.emplace_front(A[i]);
    }
  }

  if (N % 2 == 1) {
    reverse(B.begin(), B.end());
  }

  cout << B[0];
  REP(i, 1, N) {
    cout << " " << B[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>

int main(void)
{
  int d;
  scanf("%d", &d);

  switch (d) {
  case 25 : puts("Christmas");  break;
  case 24 : puts("Christmas Eve");  break;
  case 23 : puts("Christmas Eve Eve");  break;
  case 22 : puts("Christmas Eve Eve Eve");  break;
  }

  return 0;
}


Measured memory_bytes: 128
/**
 * ?????\??????:????????¶??´?????????O(n^2)
 * 	    ????\???¶??´?????????O(n)
 * ?????\?????????????????????????????°???
 */
#include <stdio.h>

// ?????????????????°???
void trace(int A[], int N){
	int i;
	for(i = 0; i < N; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

// ?????\??????
void insertionSort(int A[], int N){
	int i,j,v;
	for(i = 1; i < N; i++){
		v = A[i]; // ?????°???????????????????´?
		j = i-1; // ???????????????????´?
		while(j >= 0 && A[j] > v){ // ???????????§???????´??????´?????????
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v; // ?????°???????????§??????????????????????????\???????´?
		trace(A, N); // ?????°????????°?????¶???
	}
}

int main(){
	//freopen("in.txt", "r", stdin);
	int i,N;
	int A[100];
	while(~scanf("%d", &N)) {
	    for(i = 0; i < N; i++) scanf("%d", &A[i]);
	    trace(A, N);
	    insertionSort(A, N);
	}
	return 0;
}

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

const int maxn = 2010, P = 1000000007;
int n, m, K, ans, f[4010][maxn][2], s[maxn];

int main() {
    scanf("%d %d %d", &n, &m, &K);
    f[0][0][0] = 1;
    for (int i = 1; i <= n + m; i++) {
        for (int j = 0; j <= m; j++) {
            s[j] = (1LL * (j ? s[j - 1] : 0) + f[i - 1][j][0] + f[i - 1][j][1]) % P;
        }
        for (int j = 0; j <= m; j++) {
            f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) % P;
            if (j) f[i][j][1] = (s[j - 1] - (j >= K ? s[j - K] : 0) + P) % P;
        }
        for (int j = 0; j <= m; j++) {
            int t = i * (K - 1) - j + 1;
            if (!((j - m) % (K - 1)) && t <= n && !((t - n) % (K - 1))) {
                (ans += f[i][j][1]) %= P;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 66640
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

dxdy4 = ((-1, 0), (0, -1), (0, 1), (1, 0))


def main():
    H, W = map(int, readline().split())
    Ch, Cw = map(int, readline().split())
    Dh, Dw = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1

    dist = [[INF] * W for _ in range(H)]
    dist[Ch][Cw] = 0
    seen = [[False] * W for _ in range(H)]
    queue = deque([(Ch, Cw)])
    while queue:
        x, y = queue.popleft()
        if seen[x][y]:
            continue
        seen[x][y] = True
        for dx, dy in dxdy4:
            nx, ny = x + dx, y + dy
            if (
                0 <= nx < H
                and 0 <= ny < W
                and not seen[nx][ny]
                and (dist[nx][ny] == -1 or dist[nx][ny] > dist[x][y])
                and S[nx][ny] == '.'
            ):
                dist[nx][ny] = dist[x][y]
                queue.appendleft((nx, ny))
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x + dx, y + dy
                if (
                    0 <= nx < H
                    and 0 <= ny < W
                    and not seen[nx][ny]
                    and dist[nx][ny] > dist[x][y] + 1
                    and S[nx][ny] == '.'
                ):
                    dist[nx][ny] = dist[x][y] + 1
                    queue.append((nx, ny))

    if dist[Dh][Dw] == INF:
        print(-1)
    else:
        print(dist[Dh][Dw])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 103876
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)*}
    };
}

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

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

fn main() {
    input! {
        s: i32
    }
    let upper2 = s / 100;
    let lower2 = s % 100;
    if upper2 <= 0 && lower2 <= 0 {
        println!("NA");
    } else if 1 <= upper2 && upper2 <= 12 && 1 <= lower2 && lower2 <= 12 {
        println!("AMBIGUOUS");
    } else if 1 <= upper2 && upper2 <= 12 {
        println!("MMYY");
    } else if 1 <= lower2 && lower2 <= 12 {
        println!("YYMM");
    } else if upper2 == 0 {
        if 1 <= lower2 && lower2 <= 12 {
            println!("MMYY");
        } else {
            println!("NA");
        }
    } else if lower2 == 0 {
        if 1 <= upper2 && upper2 <= 12 {
            println!("YYMM");
        } else {
            println!("NA");
        }
    } else {
        println!("NA");
    }
}


Measured memory_bytes: 4352
n, p = map(int, input().split())
a = list(map(int, input().split()))

dp = [[-1]*2 for _ in range(n)]


def use(i, j):
    if i >= n:
        return 1 if j == p else 0
    if dp[i][j] != -1:
        return dp[i][j]
    dp[i][j] = use(i+1, j)+use(i+1, (j+a[i]) % 2)
    return dp[i][j]


print(use(0, 0))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long int n;
  cin>>n;
  
  long long int minimum = n;
  for(long long int i=1;i*i<=n;i++){
    if(n%i==0){
      minimum = min(minimum,i+(n/i)-2);
    }
  }
  cout<<minimum<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    int ans = 0;
    long long sum = 0;
    vector<int> ds;
    for (int i = 0; i < n; i++)
        if (a[i] < b[i]) ans++, sum += b[i] - a[i];
        else if (a[i] > b[i]) ds.push_back(a[i] - b[i]);
    sort(ds.rbegin(), ds.rend());
    if (sum > 0) {
        for (int d : ds) {
            sum -= d; ans++;
            if (sum <= 0) break;
        }
    }
    if (sum > 0) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    while(true) {
        int N;
        cin >> N;
        if(N == 0) break;
        vector<int> w(N);
        REP(i, N) cin >> w[i];
        vector< vector<int> > dp(N+5, vector<int>(N+5));

        int ans = 0;
        FOR(len, 1, N-1) {
            // if(len%2==0) continue;
            REP(i, N - len) {
                if(i + len >= N) continue; 
                if(abs(w[i] - w[i+len]) <= 1 && (dp[i+1][i+len-1] == len - 1))
                    dp[i][i+len] = max(dp[i][i+len], dp[i+1][i+len-1] + 2);
                FOR(j, i, i+len) {
                    // if((j-i)%2 == 1 && (i+len - (j+1)) % 2 == 1)
                        dp[i][i+len] = max(dp[i][i+len], dp[i][j] + dp[j+1][i+len]);
                }
            }
        }
        ans = dp[0][N-1];
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

int N;
int A[100005];
long long sum;
long long ans = 1;
long long usable[100005];

int main() {
    scanf("%d", &N);
    for (int i = 0; i <= N; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= N; i++) sum += A[i];
    if (N == 0 && (A[0] == 0 || A[0] > 1)) {
        printf("-1\n");
        return 0;
    }
    if (A[0] != 1) usable[0] = 1;
    for (int i = 1; i <= N; i++) {
        long long add = min(sum, usable[i - 1] * 2);
        ans += add;
        usable[i] = add - A[i];
        if (usable[i] < 0) {
            printf("-1\n");
            return 0;
        }
        sum -= A[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h;
  cin >> w >> h;
  int n;
  cin >> n;
  int fw = 0,fh  = 0,Fw = w,Fh = h;
  int ww = w,hh = h;
  for(int i = 0;i<n;i++){
    int a,b,c;
    cin >> a >> b >> c;
    if(c == 1 && a > fw)
      fw = a;
    else if(c == 2&& a < Fw)
      Fw = a;
    else if(c == 3&& b > fh)
      fh = b;
    else if(c == 4&& b < Fh)
      Fh = b;
  }
  if((Fw-fw) > 0 && (Fh-fh) > 0)
  cout << (Fw-fw)*(Fh-fh) << endl;
  else
    cout << 0 << endl;
}



Measured memory_bytes: 256
from collections import *
from heapq import *
import sys
input=lambda :sys.stdin.readline().rstrip()


N=int(input())
XL=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])

lst=[0]
for i in range(1,N):

    X1,L1=XL[lst[-1]]
    X2,L2=XL[i]
    #print(X1,L1,"1")
    #print(X2,L2,"2")
    if X1+L1<=X2-L2:
        lst.append(i)
        #print(i,"1")
    else:
        if X1+L1>X2+L2:
            lst.pop()
            lst.append(i)
            #print(i,"2")

print(len(lst))


Measured memory_bytes: 65884
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define int long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
#define N 200005
int f[N],sum[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n,x,d;
	cin>>n>>x>>d;
	if(x==0&&d==0)
	{
		cout<<"1\n";return 0;
	}
	if(x<0&&d<0) x=-x,d=-d;
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+i-1;
	int k=__gcd(x,d);
	x/=k,d/=k;
	int ans=0;
	if(x>=0&&d>=0)
	{
		for(int i=0;i<=n;i++)
		{
			int l=sum[i],r=sum[n]-sum[n-i];
			if(l>r) swap(l,r);
			ans+=r-l+1;
			if(i+d<=n)
			{
				l=max(l,sum[i+d]+x);
				ans-=max(0LL,r-l+1);
			}
		}
	}
	else
	{
		if(x<0) x*=-1;
        if(d<0) d*=-1;
        for(int i=0;i<=n;i++)
        {
            int l=sum[i],r=sum[n]-sum[n-i];
            if(l>r) swap(l,r);
            ans+=r-l+1;
            if(i+d<=n)
            {
                r=min(r,sum[n]-sum[n-i-d]-x);
                l=max(l,sum[i+d]-x);
                ans-=max(0LL,r-l+1);
            }
        }
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <cstdlib>
#include <iterator>
using namespace std;
const int N = 1e5 + 7;
int a[N];
//#define TEST
int main()
{
#ifdef TEST
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n) {
		int num, maxV = 0;
		memset(a, 0, sizeof a);
		for (int i = 1; i <= n; ++i) {
			cin >> num;
			a[num]++;
			maxV = max(maxV, num);
		}
		a[n + 1] = 0;
		int cnt = a[0];
		for (int i = 1; i <= maxV; ++i) {
			int tmp = a[i] + a[i - 1] + a[i + 1];
			if(tmp > cnt) {
				cnt = tmp;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(A: "List[int]"):
    print("win" if A[0]+A[1]+A[2]<22 else "bust")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [int(next(tokens)) for _ in range(3)]  # type: "List[int]"
    solve(A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int a[5];
	for(int i=0;i<4;i++){
		scanf("%d",&a[i]);
	}
	int flag = 1;
	if (a[3]<=a[0] || a[2]>=a[1]) flag = 0;
	if (flag == 1) {
		sort(a,a+4);
		printf("%d",(a[2]-a[1]));

	}else printf("%d\n", 0);
	//printf("aaaa\n");

	return 0;
}

Measured memory_bytes: 256