akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<string, ll>;



int main(int argc, char const *argv[]) {
    ll n, k;
    ll min=INF;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());

    for (ll j = v.at(0); j <= v.at(n-1); ++j) {
        ll sum=0;
        for (int i = 0; i < n; ++i) {
            sum+=pow((v.at(i)-j), 2);
        }
        chmin(min, sum);
    }

    cout << min << endl;
    return 0;
}

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

using namespace std;


int partition(vector<int> &A,int p,int r){
	int x = A[r];
	int i = p - 1;
	
	for (int j = p; j < r; j++){
		if (A[j] <= x){
			i++;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	int tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;

	return i+1;
}




int main(){
	int n; cin >> n;
	vector<int> A(n);

	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	int index = partition(A,0,n-1);	
	int par = A[index];

	for (int i = 0; i < n; i++){
		if(A[i] == par and i == index){
			cout << "[" << A[i] << "]" << " "; 
		}else if (i != n-1){
			cout << A[i] << " ";
		}else{
			cout << A[i];
		}
	}
	cout << endl;


return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define prev prev228
#define all(x) (x).begin(), (x).end()

int n;
long long ans;
long long x[500000];
long long y[500000];

map<int, int> xx, yy;

void up()
{
    int xmin = (*xx.begin()).first;
    int ymin = (*yy.begin()).first;
    auto it = xx.end();
    it--;
    int xmax = (*it).first;
    auto is = yy.end();
    is--;
    int ymax = (*is).first;
    ans = min(ans, 1LL * (xmax - xmin) * (ymax - ymin));
}

void del1(int val)
{
    if (xx[val] == 1) xx.erase(val);
    else xx[val]--;
}

void del2(int val)
{
    if (yy[val] == 1) yy.erase(val);
    else yy[val]--;
}

void add1(int val)
{
    xx[val]++;
}

void add2(int val)
{
    yy[val]++;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
        if (y[i] < x[i]) swap(x[i], y[i]);
    }
    vector<pair<int, int> > s;
    for (int i = 0; i < n; i++)
    {
        s.push_back({x[i], y[i]});
    }
    sort(all(s));
    for (int i = 0; i < n; i++)
    {
        xx[x[i]]++;
        yy[y[i]]++;
    }
    ans = 1e18;
    up();
    for (int i = 0; i < n; i++)
    {
        pair<int, int> r = s[i];
        del1(r.first);
        del2(r.second);
        add1(r.second);
        add2(r.first);
        up();
    }
    cout << ans;
}


Measured memory_bytes: 28272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t=1;
	//cin>>t;
	while(t--)
	{
		long long int n,k,j,m,mi;
		cin>>n>>k;
		long long int a[n],i,dp[n];
		for(i=0;i<n;i++)cin>>a[i];
		dp[0]=0;
		dp[1]=abs(a[1]-a[0]);
		for(i=2;i<n;i++)
		{
			j=1;
			mi=1e17;
			while(j<=k&&i>=j)
			{
				m=dp[i-j]+abs(a[i]-a[i-j]);
				mi=min(mi,m);
				j++;
			}
			dp[i]=mi;
		}
		cout<<dp[n-1]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int a,b;
  string s;
  cin >> a >> b >> s;
  
  for(int i = 0; i < s.size(); i++) {
    if(i == a) {
      if(s[i] != '-') {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if(s[i] == '-') {
        cout << "No" << endl;
        return 0;
      }
    }    
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int memo[100001];
int dp(int h[],int n){
if(memo[n]!=-1)
return memo[n];
else{
	
memo[n]=min(abs(h[n]-h[n+1])+dp(h,n+1),abs(h[n]-h[n+2])+dp(h,n+2));
}
return memo[n];

}

int main(){
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(memo,-1,sizeof(memo));
int n;
cin>>n;
int H[n];
for(int i=0;i<n;i++)
cin>>H[i];
memo[n-1]=0;
memo[n-2]=abs(H[n-1]-H[n-2]);
	dp(H,0);
cout<<memo[0];
return 0;

}

Measured memory_bytes: 4992
#include <iostream>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;

int main()
{
  int a,b,c,k,i=0;
  cin >> a >> b >> c >> k;
  while(i<k){
    if(a>=b)
      b=b*2;
    else if(c<=b)
      c=c*2;
    if(a<b && b<c) break;
    i++;
  }
  if(i==k) cout << "No\n";
  else cout << "Yes\n"; 
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n, a, b, c, d; cin>>n>>a>>b>>c>>d;
    a--, b--, c--, d--;
    string s; cin>>s;
    bool valid = true;
    for(int i=a+1; i+1<c; i++){
        if(s[i] == '#' && s[i+1] == '#') valid = false;
    }

    for(int i=b+1; i+1<d; i++){
        if(s[i] == '#' && s[i+1] == '#') valid = false;
    }

    if(!valid){
        cout << "No" << endl;
    }
    else{
        if(a < b && b < c && c < d){
            cout << "Yes" << endl;
        }
        else if(a < c && c < b && b < d){
            cout << "Yes" << endl;
        }
        else{
            bool jump = false;
            for(int i=b-1; i+2<n && i+1<=d; i++){
                if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
                    jump = true;
                }
            }

            if(jump){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
    }
}

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

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    for(int i = 0; i < n; ++i)  cin >> b[i];
    for(int i = 0; i < n; ++i)  cin >> c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        int foo = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        int bar = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += (ll)foo * bar;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for (int i = 0; i < n; i++){
        int cnt = 0;
        if (a[i] != b[i]) cnt++;
        if (b[i] != c[i]) cnt++;
        if (c[i] != a[i]) cnt++;

        if(cnt == 2) ans++;
        else if(cnt >= 3) ans += 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
s = deque(input())
q = int(input())
li = [list(map(str, input().split())) for _ in range(q)]

frag = True

for i in range(q):
    que = li[i]
    if que[0] == "1":
        if frag:
            frag = False
        else:
            frag = True
    else:
        f = que[1]
        c = que[2]
        if frag:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)

if frag:
    print("".join(s))
else:
    s.reverse()
    print("".join(s))

Measured memory_bytes: 44660
/*
    アリナ・グレイはかわいい
*/

#include<bits/stdc++.h>
using namespace std;
#define itn int
#define endl "\n"

int main(void){
    int n;
    cin >> n;
    int u[n],a[n/2],b[n/2];
    for(int i = 0;i < n;i++){
        cin >> u[i];
        if(i % 2 == 0)a[i/2] = u[i];
        else b[i/2] = u[i];
    }
    int mp[100005] = {},mp2[100005] = {};
    for(int i = 0;i < n/2;i++)mp[a[i]]++,mp2[b[i]]++;
    
    int mx[2] = {},mx2[2] = {},num = 0,num2 = 0;
    for(int i = 0;i < 100001;i++){
        int fir = i,sec = mp[i];
        if(sec >= mx[0]){
            mx[1] = mx[0];
            mx[0] = sec;
            num = fir;
        } else if(sec >= mx[1]){
            mx[1] = sec;
        }
    }
    for(int i = 0;i < 100001;i++){
        int fir = i,sec = mp2[i];
        if(sec >= mx2[0]){
            mx2[1] = mx2[0];
            mx2[0] = sec;
            num2 = fir;
        } else if(sec >= mx2[1]){
            mx2[1] = sec;
        }
    }
    if(num != num2)cout << n - mx[0]- mx2[0] << endl;
    else {
        cout << min((n-mx[0]-mx2[1]),(n-mx[1]-mx2[0])) << endl;
    }
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int H,W;
	std::cin >> H >> W;
	char sub;
	int count = 26;
	// 英小文字のそれぞれの個数をカウントする
	int lst[count];
	// 初期化
	for (size_t i = 0; i < count; i++) {
		lst[i] = 0;
	}
	for (size_t i = 0; i < H; i++) {
		for (size_t j = 0; j < W; j++) {
			std::cin >> sub;
			lst[sub - 'a'] += 1;
		}
	}
	// 全ての英小文字に対してmod4をとる
	for (size_t i = 0; i < count; i++) {
		lst[i] %= 4;
	}

	// mod4を取り、1,2,3になる文字の数を取得
	int one,two,three;
	one = two = three = 0;
	for (size_t i = 0; i < count; i++) {
		if (lst[i] == 1) {
			one++;
		}
		if (lst[i] == 2) {
			two++;
		}
		if (lst[i] == 3) {
			three++;
		}
	}


	bool flag = false;

	// 偶数列 * 偶数列ならば、全ての文字は4で割り切れなければならない
	if (H % 2 == 0 && W % 2 == 0) {
		if (one == 0 && two == 0 && three == 0) {
			flag = true;
		}
	}
	// 奇数列 * 奇数列
	else if (H % 2 == 1 && W % 2 == 1) {
		// mod4で1になる文字が1つ、2になるのは縦/2+横/2の数以下ならば良い
		if (one == 1 && three == 0 && two <= (H/2 + W/2)) {
			flag = true;
		}
		// mod4で3になる文字が1つ、2になるのは縦/2+横/2-1以下ならば良い
		if (one == 0 && three == 1 && two <= (H/2 + W/2 - 1)) {
			flag = true;
		}
	}
	// 偶数列 * 奇数列
	else {
		int temp;
		if (H % 2 == 1) {
			temp = W;
		}
		else if (W % 2 == 1) {
			temp = H;
		}
		int syo,amari;
		syo = temp / 4;
		amari = temp % 4;
		if (one == 0 && three == 0){
			if (amari == 0) {
				if (two % 2 == 0 && two <= syo * 2) {
					flag = true;
				}
			}
			else {
				if (two % 2 == 1 && (two - amari/2) <= syo * 2) {
					flag = true;
				}
			}
		}
	}

	if (flag) {
		std::cout << "Yes" << '\n';
	}
	else {
		std::cout << "No" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long int
int main()
{
 int n;
  cin>>n;
  ll a[3*n];
  for(int i=0;i<3*n;i++)
    cin>>a[i];
  sort(a,a+3*n);
  ll ans=0;
  for(int i=n;i<3*n;i=i+2)
    ans+=a[i];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int m;
  cin >> m;
  int n = (int)s.size();
  for (int i = 0; i < n; i += m) {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    
    int n, weight;
    int v[100], w[100];
    
    cin >> n >> weight;
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];
    
    int dp[101][10001] = {};
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= weight; j++){
            if(j >= w[i]) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    
    cout << dp[n][weight] << endl;
    
}



Measured memory_bytes: 7056
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    lli n,k;
	cin>>n>>k;
	lli a[n];
    for(lli i=0;i<n;i++)cin>>a[i];
    lli ans[max(n+1,k+1)];
    ans[0]=0;//,ans[1]=abs(a[1]-a[0]);
    for(lli i=0;i<=k;i++)ans[i]=abs(a[i]-a[0]);
    if(n<=k){
    	cout<<ans[n-1];return 0;
	}
	//for(lli i=2;i<n;i++)ans[i]=min(ans[i-1]+abs(a[i]-a[i-1]),ans[i-2]+abs(a[i]-a[i-2]));
    for(lli i=k+1;i<n;i++){
    	lli t=INF;
		for(lli j=1;j<=k;j++)t=min(t,ans[i-j]+abs(a[i]-a[i-j]));
    	ans[i]=t;
	}
	
	cout<<ans[n-1];
    //couta(ans,n);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

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

  int n;
  cin >> n;

  int last;
  cin >> last;

  int last_dir = 0, ans = 1;
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;

    if (x != last) {
      if (x < last) {
        if (last_dir == 1) {
          ans++;
          last_dir = 0;
        } else {
          last_dir = -1;
        }
      }

      if (x > last) {
        if (last_dir == -1) {
          ans++;
          last_dir = 0;
        } else {
          last_dir = 1;
        }
      }

      last = x;
    }
  }

  cout << ans << endl;
}


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

int main(void){
  int n, i;
  cin >> n;
  //９以下9x9で表せる
  if (n <= 9){
    cout << "Yes";
    return 0;
  }
  
  for (i=1; i<=9; ++i){
    //1~9で割り切れる時
    if (n % i == 0){
      //商が９以下の時
      if (n/i <= 9){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
from collections import deque
h, w, s, t = input().split()
h, w = int(h), int(w)
mp = ["#" * (w + 2)] + ["#" + input() + "#" for _ in range(h)] + ["#" * (w + 2)]
checked = [[False] * (w + 2) for _ in range(h + 2)]
edges = {chr(c):[] for c in range(ord("A"), ord("Z") + 1)}
for y in range(1, h + 1):
  for x in range(1, w + 1):
    if mp[y][x] == "|" and not checked[y][x]:
      nx, ny = x, y
      start = mp[ny - 2][nx]
      while mp[ny][nx] == "|":
        checked[ny][nx] = True
        ny += 1
      goal = mp[ny + 1][nx]
      edges[start].append(goal)
      edges[goal].append(start)
    
    if mp[y][x] == "-" and not checked[y][x]:
      nx, ny = x, y
      start = mp[ny][nx - 2]
      while mp[ny][nx] == "-":
        checked[ny][nx] = True
        nx += 1
      goal = mp[ny][nx + 1]
      edges[start].append(goal)
      edges[goal].append(start)

que = deque()
que.append((0, s))
used = {}
used[s] = True
while que:
  cost, node = que.popleft()
  if node == t:
    print(cost)
    break
  for to in edges[node]:
    if not to in used:
      used[to] = True
      que.append((cost + 1, to))
 


Measured memory_bytes: 6016
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		
		long[] map = new long[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextLong();
		}
		
		Arrays.sort(map);
		
		int index = Arrays.binarySearch(map, K);
		//そのものがある
		if (index >= 0) {
			System.out.println("POSSIBLE");
			return;
		}
		//対象より大きいのがない
		if (~index >= N) {
			System.out.println("IMPOSSIBLE");
			return;
		}
		
		for (int i = 0; i < (N - 1); i++) {
			long A = map[i];
			if (Arrays.binarySearch(map, A + 1) >= 0 || Arrays.binarySearch(map, A - 1) >= 0) {
				System.out.println("POSSIBLE");
				return;
			}
			
			if (Arrays.binarySearch(map, A + A + 1) >= 0 || Arrays.binarySearch(map, A - A - 1) >= 0) {
				System.out.println("POSSIBLE");
				return;
			}
			
			if (A > K && Arrays.binarySearch(map, A - K) >= 0) {
				System.out.println("POSSIBLE");
				return;
			}
		}

		System.out.println("IMPOSSIBLE");
	}

}

Measured memory_bytes: 50040
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
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;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
	int n,s;
	while(cin>>n>>s,n|s){
		vi r(n);
		REP(i,n){
			cin>>r[i];
		}
		sort(ALL(r));
		int ans=0;
		REP(i,n){
			ans+=r.end()-lower_bound(r.begin()+i+1,r.end(),s-r[i]+1);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1252
#include<iostream>

int main(){
    int x, p;
    std::cin >> x;
    p = x-(x/10)*10;
    if(p == 3){
        std::cout << "bon" << "\n";
    }else if(p==2||p==4||p==5||p==7||p==9){
        std::cout << "hon" << "\n";
    }else{
        std::cout << "pon" << "\n";
    }
    return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>
int main(void){
	int N;
    scanf("%d", &N);
    int i, j, min, n=0, P[N];
	for(i=0; i<N; i++){
      scanf("%d",&P[i]);
    }
    min = P[0];
    for(i=0; i<N; i++){
        if(P[i] <= min){
           	n++;
            min = P[i];
        }
    }
    printf("%d",n);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ull unsigned long long
#define endl '\n'
#define ll long long
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define line cout<<"-------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mx=300009;
int main()
{
    ll n; 
    cin>>n; 
    ll ans=0; 
    for(ll i=0;i<n;i++)
    {
        ll x; cin>>x; 
        ans=__gcd(ans,x);
    }
    cout<<ans<<endl; 
    
}


Measured memory_bytes: 3528
N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()


if N%2==0:
  al=A[(N-1)//2]
  ar=A[N//2]
  bl=B[(N-1)//2]
  br=B[N//2]
  print(int(((br+bl)/2-(ar+al)/2)*2+1))
else:
  mini=A[(N-1)//2]
  maxi=B[(N-1)//2]
  print(maxi-mini+1)

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

/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  /* 縦と横の長さ */
  int h, w;
  cin >> h >> w;

  /* 盤面 */
  vector<string> f(h);
  rep(i, h) { cin >> f[i]; }

  /* スタート地点とゴール地点 */
  vector<P> s;
  rep(i, h) {
    rep(j, w) {
      if (f[i][j] == '.') {
        s.push_back(make_pair(i, j));
      }
    }
  }

  int mx = 0;

  rep(i, s.size()) {
    // 各セルの最短距離 (訪れていないところは -1 としておく)
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[s[i].first][s[i].second] = 0;  // スタートを 0 に

    // 「一度見た頂点」のうち「まだ訪れていない頂点」を表すキュー
    queue<pair<int, int>> que;
    que.push(make_pair(s[i].first, s[i].second));  // スタートを push

    ////////////////////////////////////////
    /* 幅優先探索を実施 */
    ////////////////////////////////////////

    /* キューが空になるまで */
    while (!que.empty()) {
      pair<int, int> current_pos = que.front();  // キューの先頭を見る (C++
                                                 // ではこれをしても pop しない)
      int x = current_pos.first;
      int y = current_pos.second;
      que.pop();  // キューから pop を忘れずに

      // 隣接頂点を探索
      for (int direction = 0; direction < 4; ++direction) {
        int next_x = x + dx[direction];
        int next_y = y + dy[direction];
        if (next_x < 0 || next_x >= h || next_y < 0 || next_y >= w)
          continue;                              // 場外アウトならダメ
        if (f[next_x][next_y] == '#') continue;  // 壁はダメ

        // まだ見ていない頂点なら push
        if (dist[next_x][next_y] == -1) {
          que.push(make_pair(next_x, next_y));
          dist[next_x][next_y] =
              dist[x][y] + 1;  // (next_x, next_y) の距離も更新
        }
      }
    }

    rep(k, h) {
      rep(t, w) { mx = max(mx, dist[k][t]); }
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf
sumarr :: [Int] -> [Int]
sumarr [x] = []
sumarr (x:y:ys) = x+y : sumarr (x+y:ys)

solin :: [Int] -> Int
solin w = solsc (sumarr (0:w))

solsc :: [Int] -> Int
solsc x = solve x (last x)

solve :: [Int] -> Int -> Int
solve (x:y:ys) z
    | abs (z-x*2) < abs (z-y*2) = abs (z-x*2)
    | otherwise = solve (y:ys) z

main = do
    _ <- getLine
    w <- map read . words <$> getLine
    let answer = solin w
    print answer



Measured memory_bytes: 1020
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.toList.U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine
    ys <- U.toList.U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine
    print $ solve xs ys

modulus :: Int
modulus = 1000000007

solve (x:xs) ys0 = go 1 rxs rys
  where
    rxs = (x, x) : go0 x xs
    (y:ys) = reverse ys0
    rys = reverse $ (y, y) : go0 y ys
    go0 acc (z:zs)
      | acc < z = (z, z) : go0 z zs
      | otherwise = (1, z) : go0 acc zs
    go0 _ [] = []

    go !acc ((lx, ux):rxs) ((ly, uy):rys)
      | max lx ly <= min ux uy = go (acc * (min ux uy - max lx ly + 1) `mod` modulus) rxs rys
      | otherwise = 0
    go acc _ _ = acc `mod` modulus

Measured memory_bytes: 19324
import java.util.*;

public class Main{
  	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();			//N
 		int[] A = new int[N];
      	int num = 0;
      	for(int i=0;i<N;i++){
          int j = 0;
          int k = sc.nextInt();
          while(j<num&&A[j]!=k){
            j++;
          }
          if(j>=num){
            A[j]=k;
            num++;
          }
        }
      System.out.println(num);
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
long long n,k,f[10001],P=1000000007ll;
long long qpow(long long a,int x){
    if(x<0)return 1;
    long long s=1ll;
    while(x){
		if(x&1)s=(s*a)%P;
		a=(a*a)%P;
		x=x/2;
	}
    return s;
}
int main(){
    cin>>n>>k;
    f[0]=1ll;
    for(int i=1;i<n;++i){
		for(int j=i;j;--j)
			f[j]=(f[j+1]+f[j-1])%P;
			f[0]=f[1];
		}
    cout<<f[n-k]*qpow(2ll,n-k-1)%P<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    vector<int> A( N );
    for( auto &x : A )
    {
        cin >> x;
    }
    int MAX = *max_element( ALL( A ) );
    int MIN = *min_element( ALL( A ) );
    int res = INT_MAX;
    for( int i = MIN; i <= MAX; ++i )
    {
        int tmp = 0;
        REP( j, N )
        {
            tmp += pow( A[ j ] - i, 2 );
        }
        res = min( res, tmp );
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main()
{
  vector < int > v;
  string s;
  cin >> s;
  int sz = s.size();
  for(int i = 0; i < sz; i++){
    if(s[i] != 'B')
    v.push_back(s[i]-48);
    else{
       if(!v.empty())
       v.pop_back();
    }
  }
  for(int i = 0; i < v.size(); i++)
  cout << v[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int h,m;
	cin>>h>>m;
	string a[h];
	for(int i=0;i<h;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=m+2;i++)
	{
		cout<<'#';
	}
	cout<<endl;
	for(int i=0;i<h;i++)
	{
		cout<<'#';
		cout<<a[i];
		cout<<'#'<<endl;
	}
	for(int i=1;i<=m+2;i++)
	{
		cout<<'#';
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
*h, = map(int, input().split())

dp = [float('inf')] * N
dp[0] = 0

for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[i] - h[i - 1])
    else:
        dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2])

print(dp[-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  if(k%2 == 0) cout << "-1";
  else if(k%5 == 0) cout << "-1";
  else {
    int nana = 7;
    int ans = 1;
    for(int i = 0; i <= k; i++) {
      if(nana % k == 0) {
        cout << ans;
        break;
      }
      else if(i == k) {
        cout << "-1";
      }
      ans++;
      nana = (nana*10 + 7)%k;
      
    }
  }
}



Measured memory_bytes: 3624
H, W = map(int, (input().split()))
# Hが縦、Wが横!
rows = []
for _ in range(0, H):
    rows.append(input())

x = [0, 1, -1,  0,  1, -1, 1, -1]
y = [1, 1,  1, -1, -1, -1, 0,  0]
for row_i in range(0, H):
    result_col = ""
    # ここの処理で隣接部分を吐き出して,result_colに数値を詰める
    for col_i in range(0, W):
        if rows[row_i][col_i] == "#":
            result_col += "#"
            # これもし爆弾だったら周囲のマスに数値足して行ったほうが賢い?
            # いやどうせ九方向集めるなら一緒か。
            continue
        mines = 0
        for i in range(0, 8):
            dx = col_i + x[i]
            dy = row_i + y[i]
            if dx >= W or dx < 0 or dy >= H or dy < 0:
                continue
            if rows[dy][dx] == "#":
                mines += 1
        result_col += str(mines)
    print(result_col)


Measured memory_bytes: 3064
N = int(input())
TA = [list(map(int, input().split(" "))) for _ in range(N)]

n_t, n_a = 1, 1
for t, a in TA:
    # print(n_t/t, n_a/a)
    v = max(-(-n_t//t), -(-n_a//a))
    n_t, n_a = t*v, a*v

print(n_t+n_a)


Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
	int w,h,x,y,r,sw,yh,a,b;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x<w && y<h){
		sw=w-x+r;
		yh=h-y+r;
		a=x-r;
		b=y-r;
		if(a<0 || b<0){
			printf("No\n");
		}
		else if(0<=sw && 0<=yh){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#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()
{
    int d, t, s;
    cin >> d >> t >> s;
    
    if (d <= t*s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}

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

s = []
s_is10 = []
s_not10 = []
for i in range(N):
    x = int(input())
    s.append(x)
    if x % 10 == 0:
        s_is10.append(x)
    else:
        s_not10.append(x)
        
sum_s = sum(s)
s_not10 = sorted(s_not10)
i = 0
while sum_s % 10 == 0:
    if len(s_not10) <= i:
        sum_s = 0
        break
    
    sum_s -= s_not10[i]
    if sum_s % 10 != 0:
        break
    else:
        sum_s += s_not10[i]
    i += 1
    
print(sum_s)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		int s = sc.nextInt();
		boolean b[] = new boolean[10000];
		Arrays.fill(b, false);
		b[s] = true;
		int i = 1;
		while(true) {
			i++;
			if(s % 2 == 0) s /= 2;
			else s = s * 3 + 1;
			if(b[s]) {
				System.out.println(i);
				return;
			}
			b[s] = true;
		}
	}


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


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

int main(){
    int n;
    cin >> n;
    vector<long long int> memo(n+1);
    memo[0] = 2;
    memo[1] = 1;
    for(int i = 2; i <= n; i++){
        memo[i] = memo[i-1] + memo[i-2];
    }
    cout << memo[n] << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

ll cnt[26] = { 0 };
int main()
{
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) {
		cnt[S[i] - 'a']++;
	}
	ll ans = S.size() * (S.size() - 1) / 2 + 1;
	for (int i = 0; i < 26; i++) {
		ans -= cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
ll gcd(ll x,ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D;
    if(A%D!=0)A+=D;
    if(C%B!=0)C+=B;
    if(A/D>=C/B)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll h,ans=0,pow=1;cin>>h;
  while(h>=1) {
    ans+=pow;
    h/=2;
    pow*=2;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    r = n*800 - n//15*200
    return r

print(main())


Measured memory_bytes: 7824
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vvll time(n,vll(10)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> time.at(i).at(j) ;
		}
	}
	vvll p(n,vll(11)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin >> p.at(i).at(j) ;
		}
	}
	ll ans = -10000000000000 ;
	for(int i=1;i<(1<<10);i++){
		bitset<15> bit(i) ;
		ll sub = 0 ;
		for(int j=0;j<n;j++){
			ll cnt = 0 ;
			for(int k=0;k<10;k++){
				cnt += bit[k]&&time.at(j).at(k) ;
			}
			sub += p.at(j).at(cnt) ;
		}
		ans = max(ans,sub) ;
	}
	cout << ans << endl ;
}


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

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    vector<int> edges[2000];
    for(int i=0; i<N-1; i++){
        edges[i].push_back(i+1);
        edges[i+1].push_back(i);
    }
    edges[X].push_back(Y);
    edges[Y].push_back(X);

    vector<int> ans(N);
    for(int s=0; s<N; s++){
        vector<int> dist(N, 1e9);
        queue<int> que;
        dist[s] = 0;
        que.push(s);
        while(que.size()){
            int i = que.front(); que.pop();
            for(int j : edges[i]) if(dist[j] == 1e9){
                dist[j] = dist[i] + 1;
                que.push(j);
            }
        }
        for(int i=s+1; i<N; i++) ans[dist[i]]++;
    }
    for(int i=1; i<N; i++) cout << ans[i] << endl;
    return 0;
}


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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 55;
LL a[N];
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n;
	LL ans = 0;
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			ans += a[i] * a[j];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>

using namespace std;

#define INF (1LL << 60)

typedef long long Int;
typedef pair<Int, Int> P;

priority_queue<P, vector<P>, greater<P> > qp;

Int n,m,c,dist[100001];
vector<P> edge[100001];
P node,tmp;

void dijkstra(Int start){
    Int from,to,i,d;
    fill(dist,dist+n+1,INF);
    node.first = 0LL;
    node.second = start;
    qp.push(node);
    while(!qp.empty()){
        node = qp.top();
        qp.pop();
        from = node.second;
        d = node.first;
        if(d>dist[from]){
            continue;
        }
        dist[from] = d;
        for(i=(edge[from].size())-1; i>=0; i--){
            tmp = edge[from][i];
            to = tmp.first;
            d = tmp.second;
            if(dist[to]>dist[from]+d){
                dist[to] = dist[from]+d;
                tmp.first = dist[to];
                tmp.second = to;
                qp.push(tmp);
            }
        }
    }
}

int main(void){
    Int i,a,b,d,ans=INF,now,sum=0LL;
    scanf("%lld%lld%lld",&n,&m,&c);
    for(i=0LL; i<m; i++){
        scanf("%lld%lld%lld",&a,&b,&d);
        tmp.second=d;
        tmp.first=b;
        edge[a].push_back(tmp);
        tmp.first=a;
        edge[b].push_back(tmp);
        sum+=d;
    }
    dijkstra(1LL);
    for(i=1LL; i<=n; i++){
        tmp.first = dist[i];
        tmp.second = i;
        qp.push(tmp);
    }
    while(!qp.empty()){
        node = qp.top();
        qp.pop();
        now = node.second;
        for(i=(edge[now].size())-1; i>=0; i--){
            tmp = edge[now][i];
            if(dist[tmp.first]==-1){
                sum -= tmp.second;
            }
        }
        ans = min(ans,dist[now]*c+sum);
        dist[now]=-1;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 16360
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void print_int(int n)
{
    printf("%d\n",n);
    
}

void sort(int a[], int n)
{
    int h, i, j;

    for(h = 1; h < n / 9; h = h * 3 + 1)
        continue;

    for(; h > 0; h /= 3)
    {
        for(i = h; i < n; i++)
        {
            j = i;
            while(j >= h && a[j] < a[j-h])
            {
                swap(&a[j], &a[j-h]);
                j -= h;
            }
        }
    }
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
}

void intcpy(int a[], const int b[], int count)
{
    for(int i = 0; i < count; i++)
    {
        a[i] = b[i];
    }
}

int list_sum(int a[], int n)
{
    int sum = 0;

    for(int i = 0; i < n; i++)
    {
        sum += a[i];
    }

    return sum;
}


void permutate(int s[], int count, int n)
{
    if(n == count)
        return;

    for(int i = n; i < count; i++)
    {
        swap(&s[i], &s[n]);

        if(i != n)
        {
            //intcpy(result[j++], s, count);
        }
        
        permutate(s, count, n+1);
        swap(&s[i], &s[n]);
    }
}



int main(void)
{
    long long n;
    long long ans = 0;
    scanf("%lld", &n);
    long long inf = sqrtl(n);
    //printf("%lld\n", inf);
    for (long long i = 1; i < inf; i++)
    {
        if(n%i == 0)
        {
            ans +=  n/i - 1;
        }
         
    }
    if(n%inf == 0)
    {
        int m = n/inf-1;
        if(m != 0 && n / m == n % m)
        {
            ans += m;
        }
    }

    printf("%lld\n", ans);
    
    return 0;
}



Measured memory_bytes: 128
n = int(input())
k, *b = map(int, input().split())
t = sum(1<<i for i in b)
for i in range(1 << k):
    tmp = 0
    rs = []
    for j in range(k):
        if i & (1 << j) != 0:
           tmp |= 1 << b[j]
           rs.append(b[j])
    print(str(tmp)+":",*rs) 


Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[200005];
int32_t main(){
	int n,ans=0;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		ans+=ar[i];
	}
	cout<<ans-n;
}


Measured memory_bytes: 256
n = int(input())
mochi = []
for i in range(n):
    mochi.append(int(input()))

mochi_use = sorted(mochi,reverse = True)

ans = 1

for i in range(n-1):
    if mochi_use[i] > mochi_use[i+1]:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdint.h>

int main(void){
  int n, i, max=1, min=1000000000;
  int a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a>max){
      max=a;
    }
    if(a<min){
      min=a;
    }
  }
  printf("%d\n",max-min);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
#define NIL -1

int parent[MAX], left[MAX], right[MAX];
int n, D[MAX], H[MAX];

int getDepth(int u){
  int d = 0;
  while(parent[u] != NIL){
    u = parent[u];
    d++;
  }
  return d;
}
void setDepth(int u, int p){
  D[u] = p;
  if(right[u] != NIL){
    setDepth(right[u], p+1 );
  }
  if(left[u] != NIL){
    setDepth(left[u], p+1 );
  }
}

int seTHeight(int u){
  int h1 = 0;
  int h2 = 0;
  if( right[u] != NIL ){
    h1 = seTHeight(right[u]) + 1;
  }
  if( left[u] != NIL ){
    h2 = seTHeight(left[u]) + 1;
  }
  return H[u] =(h1 > h2 ? h1 : h2);
}

int seTSibling(int u){
  if(parent[u] == NIL ) return NIL;
  if(left[parent[u]] != u && left[parent[u]] != NIL ) return left[parent[u]];
  if(right[parent[u]] != u && right[parent[u]] != NIL) return right[parent[u]];
  return NIL;
}

void printChildren(int u){

  int i, c;
  int deg = 0;

  printf("node %d: ", u);
  printf("parent = %d, ", parent[u]);
  printf("sibling = %d, ", seTSibling(u));
  if(left[u] != NIL ) deg++;
  if(right[u] != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(parent[u] == NIL) printf("root\n");
  else if(left[u] == NIL && right[u] == NIL ) printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i, d, v, l, r;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)  parent[i] = left[i] = right[i] = NIL;

  for( i = 0 ; i < n ; i++){
    scanf("%d", &v);
    scanf("%d", &l);
    scanf("%d", &d);
    left[v] = l;
    right[v] = d;
    if(l != NIL ) parent[l] = v;
    if(d != NIL ) parent[d] = v;
  }
  for( i = 0 ; i < n ; i++){
    if( parent[i] == NIL ) r = i;
  }

  setDepth(r, 0);
  seTHeight(r);

  for( i = 0 ; i < n ; i++) printChildren(i);

  return 0;
}



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

long long n,x;
long long arr[100005];

long long gcd(long long a,long long b){
    if (a < b)swap(a, b);
    return b == 0 ? a : gcd(b, a % b);
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> x;
	for(long long i = 0;i < n;++i){
		cin >> arr[i];
	}
	arr[n] = x;
	sort(arr,arr+n+1);
	
	long long ans = 0;
	for(long long i = 1;i <= n;++i){
		ans = gcd(arr[i]-arr[i-1],ans);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, s[55], t[55];
bool d[55], g[55][55];

bool dfs(int x) {
    d[x] = true;
    bool all_visited = true;
    rep(i, 0, n) {
        if (!d[i]) {
            all_visited = false;
            break;
        }
    }
    if (all_visited) return true;

    bool res = false;
    rep(i, 0, n) {
        if (g[x][i] && !d[i]) res = dfs(i);
    }
    return res;
}

int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        s[i] = a-1, t[i] = b-1;
        g[a-1][b-1] = g[b-1][a-1] = true;
    }
    int cnt = 0;
    rep(i, 0, m) {
        g[s[i]][t[i]] = g[t[i]][s[i]] = false;
        bool ans = dfs(0);
        if (!ans) cnt++;
        g[s[i]][t[i]] = g[t[i]][s[i]] = true;
        rep(i, 0, n) d[i] = false;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    A = list(sorted(list(map(int, input().split())), reverse=True))

    ans = A[0]
    n = 1
    for i in range(1, N):
        if n == N - 1:
            break
        ans += A[i]
        n += 1
        if n == N - 1:
            break
        ans += A[i]
        n += 1
        if n == N - 1:
            break

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


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

#define F first
#define S second
#define PB push_back
#define all(x) x.begin(), x.end()

typedef long long ll; 
typedef double ld;

const int N = 100 + 10, M = 1000 + 10; 

int a[N];

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, sum = 0;
	cin>> n;
	for(int i = 0; i < n; i++)
		cin>> a[i], sum += a[i];
	int id = 0;
	for(int i = 1; i < n; i++)
		if(abs(a[i]*n-sum)<abs(a[id]*n-sum))
			id = i;
	cout<< id << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int n,d;cin>>n;
    long long int arr[n+1];
    for(int i=0;i<=n;i++)arr[i]=0;
    for(int i=0;i<n-1;i++){
        cin>>d;
        arr[d]++;
    }
    for(int i=1;i<=n;i++){
        cout<<arr[i]<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 5220