akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N,sum=0;
  cin >> N;
  int L[N*2];
  for(int i=0; i<2*N; i++){
    cin >> L[i];
  }sort(L,L+2*N,greater<int>());
  for(int i=1; i<2*N; i+=2){
    sum+=L[i];
  }cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if (all_of(s.begin(),s.end(),[](char t){return t=='A';}) || all_of(s.begin(),s.end(),[](char t){return t=='B';})){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
import math

D, G = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(D)]

digit = '0' + str(D) + 'b'
ans = float('INF')
for i in range(2**D):
    bit = list(str(format(i, digit)))
    p = 0
    cnt = 0
    last = -1
    for j in range(D):
        if bit[j] == '1':
            p += lst[j][1] + lst[j][0]*100*(j+1)
            cnt += lst[j][0]
        else:
            last = j
    r = G - p
    if r > 0 and last > -1:
        tmp = math.ceil(r/(100*(last+1)))
        if tmp < lst[last][0]:
            cnt += tmp
            ans = min(ans, cnt)
    elif r <= 0:
        ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 3064
H, M = map(int, input().split())

heights = list(map(int, input().split()))

adjacent_heights = {i:[0] for i in range(H)}

for i in range(M):
    A, B = list(map(int, input().split()))
    adjacent_heights[A-1].append(heights[B-1])
    adjacent_heights[B-1].append(heights[A-1])

is_good = [1 if heights[i] > max(adjacent_heights[i]) else 0 for i in range(H)]

print(sum(is_good))

Measured memory_bytes: 34600
main :: IO ()
main = do
  [n,z,w] <- map read.words <$> getLine :: IO [Int]
  as <- map read.words <$> getLine :: IO [Int]
  if length as > 1
    then
      let a_n = last as
          a_n_1 = (last.init) as
          diff0 = abs (w - a_n)
          diff1 = abs (a_n - a_n_1)
      in print $ maximum [diff0, diff1]
    else
      print $ abs (head as-w)


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

ll p2[55];
ll in[25];
int n,m;
map<pair<int,int>,int> mp;
vector<int> G[55];
bool used[55];

bool dfs(int f, int t, int k) {
    if (used[f]) return 0;
    used[f] = 1;
    bool flg = 0;
    for (int i = 0; i < G[f].size(); i++) {
        if (G[f][i] == t) {
            in[k] |= (1LL << mp[{f,G[f][i]}]);
            return 1;
        }
        flg |= dfs(G[f][i], t, k);
        if (flg) {
            in[k] |= (1LL << mp[{f,G[f][i]}]);
            return 1;
        }
    }
    return 0;
}

void st(int f, int t, int k) {
    memset(used,0,sizeof(used));
    dfs(f,t,k);
}

int main() {
    p2[0] = 1;
    for (int i = 1; i <= 50; i++) p2[i] = p2[i-1] * 2;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int f,t;
        cin >> f >> t;
        mp[{f,t}] = i + 1;
        mp[{t,f}] = i + 1;
        G[f].push_back(t);
        G[t].push_back(f);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        int f,t;
        cin >> f >> t;
        st(f,t,i);
    }
    ll ans = 0;
    for (int i = 0; i < (1 << m); i++) {
        // cout << i << endl;
        int cnt = 0;
        ll flag = 0;
        for (int j = 0; j < m; j++) {
            if (i & (1 << j)) {
                cnt++;
                flag |= in[j];
            }
        }
        int c = 0;
        while (flag > 0) {
            c += flag % 2;
            flag /= 2;
        }
        if (cnt & 1) {
            ans -= p2[n - c - 1];
            // cout << p2[n-c-1] << " " << ans << endl;
        } else {
            ans += p2[n - c - 1];
            // cout << p2[n-c-1] << " " << ans << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 操作によって「同じ色の石同士の相対順序」は変わらない
# さらに全操作終了後はW...WB...Bとなる.
# よって各Wに対して、その左方にあるBの(場所は関係ない)数(だけ)を求めれば
# その総和が答えとなる。
S = input()
ans = 0
cnt_black = 0
for s in S:
    if s == 'B':
        cnt_black += 1
    else:
        ans += cnt_black
print(ans)

Measured memory_bytes: 3500
#include<cstdio>
const int maxn = 110;
int tag[maxn*maxn];
int tmp[maxn*maxn];
int ans[maxn][maxn];
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m)){
		int times,cnt = 1,change = 1;
		scanf("%d",&times);
		for(int i = 1; i <= times; i++){
			scanf("%d",&tag[i]);
			for(int j = 1; j<=tag[i]; j++){
				tmp[cnt] = i; cnt++;
			}
		}
		cnt = 1;
		for(int i = 1; i<=n; i++){
			if(change == 1){
				for(int j = 1; j<=m; j++){
					ans[i][j] = tmp[cnt];
					cnt++;
				}
			}else {
				for(int j = m; j>=1; j--){
					ans[i][j] = tmp[cnt];
					cnt++;
				}
			}
			change = change * -1;
		}
		for(int i = 1; i<=n; i++){
			for(int j = 1; j<=m; j++){
				if(j == 1) printf("%d ",ans[i][j]);
				else printf("%d ",ans[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int bef = a[0], direct = 0, ans = 1;

  rep(i, 1, n) {
    if (direct == 0) {
      if (a[i] > bef)
        direct = 1;
      else if (a[i] < bef)
        direct = 2;
    } else {
      if ((a[i] > bef && direct == 2) || (a[i] < bef && direct == 1)) {
        direct = 0;
        ans++;
      }
    }
    bef = a[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long a[n];
  long b[n];
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  // long sum[n];
  // sum[0]=a[0];
  // for(i=1;i<n;i++){
  //   sum[i]=sum[i-1]+a[i];
  // }
  long odd,even;
  odd=0;
  even=0;
  long curSum = 0;
  for(i=0;i<n;i++){
    if(i%2==0){
      if(curSum+a[i]<=0){
        odd+=1-(curSum+a[i]);
        a[i]+=1-(curSum+a[i]);
      }
    }else{
      if(curSum+a[i]>=0){
        odd+=1+(curSum+a[i]);
        a[i]-=1+(curSum+a[i]);
      }
    }
    curSum += a[i];
  }
  curSum=0;
  for(i=0;i<n;i++){
    if(i%2==1){
      if(curSum+b[i]<=0){
        even+=1-(curSum+b[i]);
        b[i]+=1-(curSum+b[i]);
      }
    }else{
      if(curSum+b[i]>=0){
        even+=1+(curSum+b[i]);
        b[i]-=1+(curSum+b[i]);
      }
    }
    curSum += b[i];
  }
  cout<<min(odd,even);
}


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

const int maxn = 200010;

int n, X, Y;

const int mod = 1e9+7;

pair<int,int> a[maxn];

int mc[maxn], mi[maxn];
int inv[maxn];

vector<int> g[maxn];
void add(int x,int y) {
//	cout<<x<<' '<<y<<endl;
	g[x].push_back(y);
	g[y].push_back(x);
}

int cc[maxn];

int vis[maxn];
int bfs(int x) {
	int ret = 1, cnt = 0;
	queue<int> q;
	vis[x] = 1; q.push(x);
	while(!q.empty()) {
		x = q.front(); q.pop(); cc[a[x].first]++;
		ret = 1ll * ret * (++cnt) % mod * inv[cc[a[x].first]] % mod;
		for(auto y: g[x]) if(vis[y] != 1) { vis[y] = 1; q.push(y); }
	}
	vis[x] = 2; q.push(x);
	while(!q.empty()) {
		x = q.front(); q.pop(); cc[a[x].first]--;
		for(auto y: g[x]) if(vis[y] != 2) { vis[y] = 2; q.push(y); }
	}
	return ret;
}

int main() {
	scanf("%d%d%d", &n, &X, &Y);
	for(int i = 1; i <= n; ++i) mc[i] = mod;
	inv[0] = inv[1] = 1;
	for(int i = 2; i <= n; ++i) inv[i] = -1ll * (mod / i) * inv[mod % i] % mod;
	for(int i = 2; i <= n; ++i) if(inv[i] < 0) inv[i] += mod;
	for(int i = 1; i <= n; ++i) {
		int c, w; scanf("%d%d", &c, &w);
		a[i] = {c, w};
		if(w < mc[c]) { mc[c] = w; mi[c] = i; }
	}
	int m1 = mod, i1 = -1, m2 = mod, i2 = -1;
	for(int i = 1; i <= n; ++i) {
		if(mc[i] < m1) { m2 = m1, i2 = i1, m1 = mc[i], i1 = i; }
		else if(mc[i] < m2) { m2 = mc[i], i2 = i; }
	}
	for(int i = 1; i <= n; ++i) {
		int c, w; tie(c, w) = a[i];
		if(mi[c] != i && mc[c] + w <= X) add(mi[c], i);
		if(c != i1 && m1 + w <= Y) add(mi[i1], i);
		if(c != i2 && m2 + w <= Y) add(mi[i2], i);
	}
	long long ans = 1;
	for(int i = 1; i <= n; ++i) if(!vis[i]) ans = ans * bfs(i) % mod;
	cout << ans << endl;
}


Measured memory_bytes: 18024
#include <iostream>
#include <string>
using namespace std;
int main() {
    int H, W;
    string S, t;
    cin >> H >> W;
    for (int i = 0; i < W + 2; i++) t += "#";
    cout << t << endl;
    for (int i = 0; i < H; i++) {
        cin >> S;
        cout << '#' << S << '#' << endl;
    }
    cout << t << endl;
}

Measured memory_bytes: 256
// by jojifrank
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

unordered_map<ll,ll> ma;
ll sum = 0;
void solve()
{
    int n; cin>>n;
    rep(i,0,n)
    {
        ll x; cin>>x;
        sum+=x;
        ma[x]++;
    }
    int q; cin>>q;
    while(q--)
    {
        ll b,c; cin>>b>>c;
        sum+=ma[b]*(c-b);
        ma[c]+=ma[b];
        ma[b] = 0;
        cout<<sum<<endl;
    }
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7100
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    for a in 1..10 {
        for b in 1..10 {
            if n == a * b {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
#define W(x) cout<<x<<endl
#define WW(x,y) cout<<x<<' '<<y<<endl;
#define in(x) cin>>x
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll power(ll x,ll y){
    ll res = 1;
    
    while(y>0){
        if(y&1)res = (res*x);
        y>>=1;
        x = (x*x);
    }
    return res;
}

ll power(ll x,ll y,ll p){
    ll res = 1;
    x%=p;
    while(y>0){
        if(y&1)res = (res*x)%p;
        y>>=1;
        x = (x*x)%p;
    }
    return res;
}


int main(){
	fastio();
	int n,k;
	cin>>n>>k;
	set<int> st;
	for(int i = 1; i<=n; i++)st.insert(i);
	for(int i = 0; i<k; i++){
		int d,x;
		cin>>d;
		for(int j = 0; j<d; j++){
			cin>>x;
			st.erase(x);
		}
	}
	cout<<st.size()<<"\n";
}

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

int main(){
  int n,ans=0;cin>>n;
  string s;cin>>s;

  int w=0,r=n-1;
  while(w<=r){
    while(w<n&&s.at(w)=='R') w++;
    while(r>0&&s.at(r)=='W') r--;
    if(w<r) ans++;
    w++;r--;
  }

  cout<<ans;
}

Measured memory_bytes: 3720
class Combination
  def initialize(a, b, d)
    @a, @b, @d, @x, @y = a, b, d, 0, 0
  end

  def measure
    @a * @x - @b * @y
  end

  def go_next
    @x += 1 until measure >= @d
    @y += 1 until measure <= @d
  end

  def total_number
    @x + @y
  end

  def total_mass
    @a * @x + @b * @y
  end

  def ok?
    measure == @d
  end

  def to_a
    [@x, @y]
  end

  def movable?
    return true
  end
end

class Combination2 < Combination
  def initialize(a, b, d)
    @a, @b, @d, @x, @y = a, b, d, 0, 0
    if @a < @b
      @y += 1 until measure >= @d
    else
      @x += 1 until measure >= @d
    end
  end

  def measure
    @a * @x + @b * @y
  end

  def go_next
    if @a < @b
      @x += 1
      @y -= 1 if measure - @b >= @d
    else 
      @y += 1
      @x -= 1 if measure - @a >= @d
    end
  end

  def movable?
    if @a < @b
      @y > 0
    else
      @x > 0
    end
  end
end

def select_best(cs)
  return c1.ok? ? c1 : c2 if c1.ok? ^ c2.ok?
  return c1 if c1.total_number < c2.total_number
  return c2 if c1.total_number > c2.total_number
  return c1 if c1.total_mass < c2.total_mass
  return c2 if c1.total_mass > c2.total_mass
  return c1
end

loop do
  a, b, d = gets.split.map(&:to_i)
  break if a == 0
  c1, c2, c3 = Combination.new(a, b, d), Combination.new(b, a, d), Combination2.new(a, b, d)
  cs = [c1, c2, c3]
  loop do
    if cs.any?(&:ok?)
      n = cs.map {|c| c.ok? ? c.total_number : Float::INFINITY}.min
      cs.each {|c| c.go_next until c.ok? or c.total_number > n or !c.movable?}
      c = cs.min_by {|c| [c.ok? ? 0 : 1, c.total_number, c.total_mass]}
      puts (c == c1 ? c1.to_a : c == c2 ? c2.to_a.reverse : c3.to_a) * " "
      break
    else
      c1.go_next
      c2.go_next
      c3.go_next if c3.movable?
    end
  end
end


Measured memory_bytes: 6896
//14
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int b[41][4];
    fill(b[0],b[41],1<<30);
    b[0][0]=0;
    int f=0;
    int cp=0,ct=0;
    for(int i=0;i<n;i++){
      int p,t;
      cin>>p>>t;
      for(int j=0;j<4;j++){
	if(j<3){
	  if(abs(p-cp)*(j+1)<=(t-ct)){
	    b[i+1][j+1]=min(b[i+1][j+1],b[i][j]+abs(p-cp));
	  }
	}
	int cct=ct+(j+1)*cp;
	if(p<=t-cct){
	  b[i+1][1]=min(b[i+1][1],b[i][j]+cp+p);
	}
      }
      if(!f&&*min_element(b[i+1],b[i+2])==1<<30){
	f=i+1;
      }
      cp=p;
      ct=t;
    }
    if(f){
      cout<<"NG "<<f<<endl;
    }else{
      cout<<"OK "<<*min_element(b[n],b[n+1])+cp<<endl;
    }
  }
  return 0;
}
      

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

using namespace std;

int main() {
  int t;
  cin >> t;
  while (t--) {
    int gx, gy;
    cin >> gx >> gy;
    int p;
    cin >> p;
    // (x1,y1),(x2,y2)
    int data[20][20][20][20] = {{{{0}}}};
    for (int i = 0; i < p; i++) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      data[x1][y1][x2][y2] = data[x2][y2][x1][y1] = 1;
    }
    // (x,y)
    int cnt[20][20] = {{0}};
    cnt[0][0] = 1;
    for (int y = 0; y <= gy; y++) {
      for (int x = 0; x <= gx; x++) {
	if (!data[x][y][x + 1][y]) {
	  cnt[x + 1][y] += cnt[x][y];
	}
	if (!data[x][y][x][y + 1]) {
	  cnt[x][y + 1] += cnt[x][y];
	}
      }
    }
    if (cnt[gx][gy]) {
      cout << cnt[gx][gy] << endl;
    } else {
      cout << "Miserable Hokusai!" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3700
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int H,n;
    scanf("%d%d", &H, &n);
    vector<ll> a(n),b(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld%lld", &a[i], &b[i]);
    }

    vector<ll> dp(H+10005,LINF);
    dp[0]=0;
    int j;
    for(i=0; i<H; i++) {
        if(dp[i]==LINF) continue;
        for(j=0; j<n; j++) {
            dp[i+a[j]]=MIN(dp[i+a[j]], dp[i]+b[j]);
        }
    }
    ll ans=LINF;
    for(i=H; i<H+10005; i++) {
        ans=MIN(ans,dp[i]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;

	struct V { ULL Z = 1, U = 0, zp = 0; };

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		vector<UL> S(N + 1); rep(i, N) S[i + 1] = S[i] ^ A[i];
		if (S[N] != 0) {
			ULL Z = 1, U = 0;
			ULL u = 0;
			rep(i, N) {
				if (S[i + 1] == 0) { Z += U; Z %= M; }
				if (S[i + 1] == S[N]) { u = Z; U += Z; U %= M; }
			}
			cout << u << endl;
		}
		else {
			ULL zn = 0;
			vector<V> Q(1 << 20);
			rep(i, N) {
				if (S[i + 1] == 0) {
					zn++;
				}
				else {
					UL p = S[i + 1];
					Q[p].Z += Q[p].U * (zn - Q[p].zp); Q[p].Z %= M;
					Q[p].U += Q[p].Z; Q[p].U %= M;
					Q[p].zp = zn;
				}
			}
			ULL ans = 0;
			for (V &v : Q) ans += v.U;
			ans %= M;
			ULL ansbuf = 1; rep(i, zn - 1) ansbuf = ansbuf * 2 % M;
			ans += ansbuf;
			ans %= M;
			cout << ans << endl;
		}
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 28800
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	S := []byte(getString())
	n := len(S)

	N := n*(n-1)/2 + 1
	a := make(map[byte]int)
	for _, v := range S {
		a[v]++
	}
	for _, v := range a {
		N -= v * (v - 1) / 2
	}
	out(N)
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ps(n);
    for(int i=0; i<n; i++) cin >> ps.at(i);

    vector<int> as(n);
    iota(as.begin(), as.end(), 1);
    int cnt = 0;
    for(int i=0; i<n; i++)
    {
        if(ps.at(i) != as.at(i)) cnt++;
    }

    if(cnt==0 || cnt==2) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int N){
        par.assign(N,0);
        rank.assign(N,0);
        REP(i,N) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) swap(x,y);

        //x becomes root
        par[y]=x;
        if(rank[x]==rank[y]) rank[x]++;
    }
};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,L; cin >> N >> K >> L;
    UnionFind uf1(N), uf2(N);
    REP(i,K){
        int p,q; cin >> p >> q;
        p--; q--;
        uf1.unite(p,q);
    }
    REP(i,L){
        int r,s; cin >> r>> s;
        r--; s--;
        uf2.unite(r,s);
    }

    map<PII,int> mp;
    REP(i,N){
        int x = uf1.find(i);
        int y = uf2.find(i);
        mp[{x,y}]++;
    }
    REP(i,N){
        int x = uf1.find(i);
        int y = uf2.find(i);
        cout << mp[{x,y}] << " ";
    }
    cout << endl;


}

Measured memory_bytes: 15104
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int maxarr = *max_element(arr,arr+n);
  int minarr = *min_element(arr,arr+n);
  //cout<<minarr<<" "<<maxarr<<endl;
  int min = INT_MAX,cur = 0,k=0;
  for(int i=minarr;i<=maxarr;i++)
  {
    cur=0;
    for(int j=0;j<n;j++)
    {
      cur+=(int)pow(i-arr[j],2);
    }
    //cout<<min<<" "<<cur<<endl;
    if(min>cur){
      min = cur;
      k=i;
    }
  }
  cout<<min<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int m = stdIn.nextInt();
        int d = stdIn.nextInt();
        int count = 0;
        
        
        for(int i = 1; i <= m; i++){
            for(int j = 10; j <= d; j++){
                int k = j % 10;
                int h = j / 10;
                if(i == k * h && k != 1 && h != 1){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	int ans = 0;
	int x = 0;

	for (char c : S) {
		if (c == 'I') {
			x++;
		}
		else {
			x--;
		}
		if (x > ans) ans = x;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 100005;

int n,L;
int a[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> L;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int i = 1;i < n;i++)
		if (a[i] + a[i + 1] >= L)
		{
			cout << "Possible" << endl;
			for (int j = 1;j < i;j++)
				cout << j << endl;
			for (int j = n - 1;j >= i;j--)
				cout << j << endl;
			return 0;
		}
	cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[310][310];


int mat_N=310;
int mat_M=310;
// long long, including mod calculation
struct mat{
	long long a[310][310];
	mat(){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=0;}
	mat(int s){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=(i==j)*s;}
	mat operator+(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-()const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=-a[i][j];
		return ret;
	}
	mat operator*(const long long &k)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]*k%mod;
		return ret;
	}
	// assuming mat_N = mat_M
	// by changing here, you can use for graph problems (ex. a[i][j]=min(a[i][k]+a[k][j]))
	mat operator*(const mat &m)const{
		mat ret;
		for(int k=0;k<mat_N;k++)for(int i=0;i<mat_N;i++)for(int j=0;j<mat_N;j++){
			ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j])%mod;
		}
		return ret;
	}
};
mat I=mat(1);
mat pw(mat a,long long t){
	mat ret=I;
	while(t){
		if(t&1){
			ret=ret*a;
		}
		t/=2;
		a=a*a;
	}
	return ret;
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;a=a*a%mod;
	}
	return ret;
}
int rnk(mat a){
	int ret=0;
	for(int i=0;i<mat_M;i++){
		int at=-1;
		for(int j=ret;j<mat_N;j++){
			if(a.a[j][i]){
				at=j;break;
			}
		}
		if(!~at)continue;
		if(at!=ret){
			for(int j=0;j<mat_M;j++)swap(a.a[at][j],a.a[ret][j]);
		}
		for(int j=0;j<mat_N;j++){
			if(ret==j)continue;
			if(a.a[j][i]==0)continue;
			for(int k=0;k<mat_M;k++){
				a.a[j][k]=(a.a[j][k]^a.a[ret][k]);
			}
		}
		ret++;
	}
	return ret;
}

int main(){
	int a,b;scanf("%d%d",&a,&b);
	mat_N=a;
	mat_M=b;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
	}
	mat A;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		A.a[i][j]=p[i][j];
	}
	int R=rnk(A);
	long long ret=(pw(2,a)+mod-pw(2,a-R)%mod)%mod*pw(2,b)%mod*d2%mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 2816
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<Integer>();
    while (sc.hasNext()) {
      list.add(sc.nextInt());
    }
    List<Integer> listB = new ArrayList<Integer>(new HashSet<>(list));
    System.out.println(listB.size());
  }
}

Measured memory_bytes: 21332
#include <stdio.h>

int saidai(int a, int b){
    int i, tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    } 
     
    while(a%b != 0){
        i = a%b;
        a = b;
        b = i;
    }
    
   return b;
    
}


int main(void){
    int a, b;
    while(scanf("%d %d", &a, &b) != EOF){
        int c, d;
        c = saidai(a,b);
        d = a/c*b;
       printf("%d %d\n", c, d);
    };
    
    
    return 0;
}



Measured memory_bytes: 2040
import java.util.*;

class Main{
 public static void main(String[] args){
 
  Scanner scan = new Scanner(System.in).useDelimiter("\\s\\n*");

  int W=scan.nextInt(),H=scan.nextInt(),x=scan.nextInt(),y=scan.nextInt(),r=scan.nextInt();

  if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){System.out.println("Yes");}
  else{System.out.println("No");}
 }
}

Measured memory_bytes: 26304
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli N,A,C=0,B,D=0;
  string S1,S2;
  cin >> S1 >> S2;
  Sort(S1);
  Sort(S2);
  Rev(S2);
  if(S1<S2)Out("Yes");
  else Out("No");
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll x;cin>>x;
  ll count=0;
  count+=x/11*2;
  x%=11;
  
  if(x>=1 &&x<=6)count++;
  else if(x>=7)count+=2;
  cout<<count<<endl;
}
    

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for _ in range(h)]
d1=[[0]*(w+1) for _ in range(h+1)]
d2=[[0]*(w+1) for _ in range(h+1)]
for i in range(h):
  k=1
  for j in range(w):
    if s[i][j]=='.':d1[i+1][k]+=1
    else:k=j+2
  for j in range(w):
    if s[i][j]=='.':d1[i+1][j+1]+=d1[i+1][j]
for j in range(w):
  k=1
  for i in range(h):
    if s[i][j]=='.':d2[k][j+1]+=1
    else:k=i+2
  for i in range(h):
    if s[i][j]=='.':d2[i+1][j+1]+=d2[i][j+1]
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    d1[i][j]+=d2[i][j]-1
  ans=max(ans,max(d1[i]))
print(ans)

Measured memory_bytes: 142636
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int chmax(int& a,int b){
	if(b > a){
		a=b;
	}
	return a;
}
int chmin(int& a,int b){
	if(b < a){
		a=b;
	}
	return a;
}
struct node{
	vi edges;
	vi cost;
	vi dist;
	int ans;
	node():ans(inf){}
};
int N,M;
node nl[10000+10];
int dijkstra(){
	int ans=0;

	priority_queue<pii,vector<pii>,greater<pii> >q;
	q.push(mp(0,0));
	while(!q.empty()){
		node &n=nl[q.top().second];int d=q.top().first;q.pop();
		if(n.ans > d){
			n.ans=d;
		}else{
			continue;
		}
		for(int i=0;i<n.edges.size();i++){
			node &next=nl[n.edges[i]];
			if(next.ans > d+n.dist[i]){
				q.push(mp(d+n.dist[i],n.edges[i]));
			}
		}
	}
	for(int i=1;i<N;i++){
		int mi=inf;
		node &n=nl[i];
		for(int j=0;j<n.edges.size();j++){
			node &next=nl[n.edges[j]];
			if(n.dist[j] + next.ans== n.ans && mi >  n.cost[j]){
				mi=n.cost[j];
			}
		}
		ans+=mi;
	}

	return ans;
}
int main(){
	while(cin >> N >> M,N || M){
	rep(i,M){
		int u,v,d,c;
		cin >> u >> v >> d >> c;
		u--;
		v--;
		nl[u].edges.pb(v);
		nl[u].cost.pb(c);
		nl[u].dist.pb(d);
		nl[v].edges.pb(u);
		nl[v].cost.pb(c);
		nl[v].dist.pb(d);

	}
	cout << dijkstra() << endl;
	fill(nl,nl+10000+10,node());
	}
	return 0;
}

Measured memory_bytes: 4192
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

const int N=3e5+10;
int n,a[N];
int main() {
    R(n);
    REP(i,3*n) R(a[i]);
    sort(a,a+3*n);
    LL ans=0;
    REP(i,n) ans+=a[3*n-2-i*2];
    W(ans);
    return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll n, ans = 0; cin >> n;
    int a[n]; REPI(i, n) cin >> a[i];

    sort(a, a + n);

    for(ll i = 0; i < n - 2; i++)
        for(ll j = i + 1; j < n - 1; j++)
            for(ll k = j + 1; k < n; k++)
                if(a[i] < a[j] + a[k] && a[j] < a[k] + a[i] && a[k] < a[i] + a[j])
                    ans++;

    cout << ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
string S;
int x[100000][2]; int c = 0;
int main() {
	while (getline(cin, S)) {
		if (S.size() == 0) { c++; continue; }
		string T[2]; int ok = 0;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == ',') { ok++; }
			else { T[ok] += S[i]; }
		}
		x[stoi(T[0])][c]++;
	}
	for (int i = 0; i < 99999; i++) { if (x[i][0] >= 1 && x[i][1] >= 1) { cout << i << ' ' << x[i][0] + x[i][1] << endl; } }
	return 0;
}

Measured memory_bytes: 3016
#include <iostream>
#include <queue>
#include <set>

int main() {
    int N;
    std::cin >> N;

    std::priority_queue<std::pair<long long, long long>> que;
    for (long long i = 1; i <= N; i++) {
        long long P;
        std::cin >> P;
        que.push(std::make_pair(P, i));
    }

    std::multiset<long long> s;
    s.insert(0);
    s.insert(0);
    s.insert(N + 1);
    s.insert(N + 1);

    long long ans = 0;
    while (!que.empty()) {
        auto p = que.top();
        que.pop();

        long long P = p.first;
        long long i = p.second;

        s.insert(i);
        auto itr = s.lower_bound(i);

        long long w = *(std::prev(itr, 2));
        long long x = *(std::prev(itr, 1));
        long long y = *(std::next(itr, 1));
        long long z = *(std::next(itr, 2));

        ans += P * ((x - w) * (y - i) + (i - x) * (z - y));
    }
    std::cout << ans << "\n";
}

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

int A[1000000];
int n;
long long cnt;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
	for (int i = g; i < n; i++)
	{
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v)
		{
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n)
{
	for (int h = 1; ; )
	{
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--)
	{
		insertionSort(A, n, G[i]);
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &A[i]);
	}
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--)
	{
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++)
	{
		printf("%d\n", A[i]);
	}
    return 0;
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200000], b[200000];
signed main(){
  int n;
  scanf("%lld", &n);
  rep(i,n)scanf("%lld%lld", &a[i], &b[i]);
  rep(i,n)a[i] += b[i];
  sort(a, a+n, greater<int>());
  int ans = 0;
  rep(i,n)ans -= b[i];
  // printf("%lld\n", ans);
  // rep(i,n)printf("%lld\n", a[i]);
  int f = 0;
  rep(i,n){
    if(f == 0)ans += a[i];
    f = !f;
  }
  printf("%lld\n", ans);
  return 0;
}






Measured memory_bytes: 1792
def num_handler(nums, item_count, count = 0)
  evens = nums.select {|item| item % 2 == 0}
  if evens.size == item_count
    new_evens = nums.map { |item| item / 2 }
    num_handler(new_evens, item_count, count + 1)
  else
    return count
  end
end

input = gets.to_i
nums = gets.chomp.split.map(&:to_i)
p num_handler(nums, input)

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<'='<<x<<endl
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}


void solve()
{

	ll i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	string s,t;
	cin>>s>>t;
	for(i=0;i<s.size();i++)
	{
	    if(s[i]!=t[i])
	    cnt++;
	}
	cout<<cnt;
}
int main() {
    fast
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w+", stdout);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int num_to = (int)Math.pow(2, n)-1;
			int[] a = in.nextIntArray(n);
			List<Integer> list = new ArrayList<>();

			for (int i = num_to; i > 0; i--) {
				int sum = 0;
				char bin[] = String.format("%"+n+"s",Integer.toBinaryString(i))
						.replace(' ', '0')
						.toCharArray();
				for (int j = bin.length-1; j >= 0 ; j--) {
					if (bin[j] == '1') {
						sum += a[j];
					}
				}
				list.add(sum);
			}

			int q = in.nextInt();
			int[] m = in.nextIntArray(q);
			for (int mi : m) {
				if (list.contains(mi)) {
					out.println("yes");
				} else {
					out.println("no");
				}
			}
		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 484808
import math
import collections

n = int(input())
s = 0
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

m = 0
l = collections.Counter(prime_factorize(n))
l2 = list(dict.values(l))
#for i in range(len(l2)):
#    s += int((math.sqrt(1 + 9 * l2[i])-1)/2)
for i in range(len(l2)):
    for j in range(n):
        if l2[i] >= j*(j+1)/2:
            m = j
        else:
            break


    s += m


print(s)


Measured memory_bytes: 9480
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
#define maxn 200000

bool number[maxn+5];
void isprime()
{
    int prime[maxn+5];
    int i,j,c=0;
    memset(number,true,sizeof(number));
    for(i=2;i<=maxn;i++)
    {
        if(number[i])
            prime[c++]=i;
        for(j=0;j<c&&prime[j]*i<=maxn;j++)
        {
            number[prime[j]*i]=false;
            if(i%prime[j]==0)
                break;
        }
    }
}
int main(){
    isprime();
    int n;
    cin>>n;
    while(true){
        if(number[n])
            break;
        n++;
    }
    cout<<n<<endl;
}


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

int main() {
  int n; cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  bool ans = true;
  for (int i=1; i<n; i++) {
    if (h[i] > h[i-1]) h[i]--;
    if (h[i] < h[i-1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n+1);
	for(int i=1;i<=n;++i){
		int A; cin>>A;
		a.at(i)=A;
	}
	int i=1,ans=0;
	for(int j=0;j<n&&i!=2;++j){
		i=a.at(i);
		++ans;
	}
	cout<<(i==2?ans:-1)<<"\n"s;
}

Measured memory_bytes: 640
N,M=map(int,input().split())

LPPP=[]
LPPM=[]
LPMP=[]
LPMM=[]
LMPP=[]
LMPM=[]
LMMP=[]
LMMM=[]
for i in range(N):
    x,y,z=map(int,input().split())
    LPPP.append(x+y+z)
    LPPM.append(x+y-z)
    LPMP.append(x-y+z)
    LPMM.append(x-y-z)
    LMPP.append(-x+y+z)
    LMPM.append(-x+y-z)
    LMMP.append(-x-y+z)
    LMMM.append(-x-y-z)
    
LPPP.sort(reverse=True)
LPPM.sort(reverse=True)
LPMP.sort(reverse=True)
LPMM.sort(reverse=True)
LMPP.sort(reverse=True)
LMPM.sort(reverse=True)
LMMP.sort(reverse=True)
LMMM.sort(reverse=True)
print(max(sum(LPPP[:M]),sum(LPPM[:M]),sum(LPMP[:M]),sum(LPMM[:M]),sum(LMPP[:M]),sum(LMPM[:M]),sum(LMMP[:M]),sum(LMMM[:M])))

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

int main()
{
    regex re[8];
    re[0] = "keyence.*";
    re[1] = "keyenc.*e";
    re[2] = "keyen.*ce";
    re[3] = "keye.*nce";
    re[4] = "key.*ence";
    re[5] = "ke.*yence";
    re[6] = "k.*eyence";
    re[7] = ".*keyence";
    string s;
    cin >> s;
    bool ret = false;
    for (int i = 0; i < 8; i++)
    {
        ret = ret || regex_match(s, re[i]);
    }
    cout << (ret ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
m = ["S","H","C","D"]
n = int(input())

deck = []
for i in range(n):
  mark, num = map(str, input().split())
  deck.append([mark,int(num)])

for check in m:
  for i in range(13):
    if not([check,i+1] in deck) :
      print(check,i+1)


Measured memory_bytes: 5596