akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N;
vector<vector<pair<int, int>>> x;

int main() {
  cin >> N;
  x.resize(N);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    x[i].resize(A);
    for (int j = 0; j < A; j++) {
      int x1, x2;
      cin >> x1 >> x2;
      x[i][j] = make_pair(x1, x2);
    }
  }

  int res = 0;
  for (int i = 1; i < (1 << N); i++) {
    bool consistent = true;

    for (int j = 0; j < N; j++) {
      bool is_honest = (i & (1 << j)) > 0;
      if (!is_honest) {
        continue;
      }

      for (auto p : x[j]) {
        int target = p.first - 1;
        bool target_is_honest = (i & (1 << target)) > 0;
        if ((target_is_honest ? 1 : 0) != p.second) {
          consistent = false;
        }
      }
    }

    if (consistent) {
      int tmp = bitset<32>(i).count();
      if (tmp > res)
        res = tmp;
    }
  }
  cout << res << endl;

  return 0;
}


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

using namespace std;

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

    int res = t.size();
    for (int i = 0; i < static_cast<int>(s.size() - t.size() + 1); i++) {
        int r = 0;
        for (int j = 0; j < static_cast<int>(t.size()); j++) {
            if (s[i + j] != t[j]) {
                r++;
            }
        }

        res = min(res, r);
    }

    cout << res << endl;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>
#include <utility>
static const int MAXN = 2e5 + 2;
static const int MAXM = 2e5 + 4;
static const int INF = 0x3fffffff;

int n, m;
std::pair<int, int> p[MAXN];

namespace sgt {
// Range increment, range maximum query

static const int MAXN = ::MAXM * 2;
int sz;
struct node { int l, r, lch, rch; int max, tag; } t[MAXN];

inline void apply(int idx, int val) {
    t[idx].max += val;
    t[idx].tag += val;
}
inline void push(int idx) {
    if (t[idx].tag == 0 || t[idx].lch == -1) return;
    apply(t[idx].lch, t[idx].tag);
    apply(t[idx].rch, t[idx].tag);
    t[idx].tag = 0;
}
inline void update(int idx) {
    if (t[idx].lch == -1) return;
    push(idx);
    t[idx].max = std::max(t[t[idx].lch].max, t[t[idx].rch].max);
}

inline int build(int L, int R) {
    int idx = sz++;
    t[idx].l = L, t[idx].r = R; t[idx].tag = 0;
    if (L == R) {
        t[idx].lch = t[idx].rch = -1;
        t[idx].max = L - (::m + 1);
    } else {
        int M = (L + R) >> 1;
        t[idx].lch = build(L, M);
        t[idx].rch = build(M + 1, R);
        update(idx);
    }
    return idx;
}

int QL, QR, QV;

inline int query(int idx) {
    push(idx);
    if (t[idx].l >= QL && t[idx].r <= QR) return t[idx].max;
    int ans = -INF;
    if (t[t[idx].lch].r >= QL) ans = std::max(ans, query(t[idx].lch));
    if (t[t[idx].rch].l <= QR) ans = std::max(ans, query(t[idx].rch));
    update(idx);
    return ans;
}
inline int query(int L, int R) { QL = L, QR = R; return query(0); }

inline void modify(int idx) {
    push(idx);
    if (t[idx].l >= QL && t[idx].r <= QR) { apply(idx, QV); return; }
    if (t[t[idx].lch].r >= QL) modify(t[idx].lch);
    if (t[t[idx].rch].l <= QR) modify(t[idx].rch);
    update(idx);
}
inline void modify(int L, int R, int V) { QL = L, QR = R, QV = V; modify(0); }

}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf("%d%d", &p[i].first, &p[i].second);
    std::sort(p, p + n);

    int ans = n - m;
    sgt::build(0, m + 1);
    int ptr = 0;
    for (int i = 0; i <= m; ++i) {
        while (ptr < n && p[ptr].first == i) {
            sgt::modify(0, p[ptr].second, +1);
            ++ptr;
        }
        ans = std::max(ans, sgt::query(i + 1, m + 1));
        sgt::modify(0, m + 1, -1);
    }

    printf("%d\n", std::max(ans, 0));

    return 0;
}


Measured memory_bytes: 11136
#include<iostream>

using namespace std;

int main() {
	int R, G, B, n;
	cin >> R >> G >> B >> n;
	int cnt = 0;
	for (int i = 0;i < n / R + 1;i++) {
		for (int j = 0;j < (n - i * R) / G + 1;j++) {
			if ((n - i * R - j * G) % B == 0 && (n - i * R - j * G) / B >= 0) {
				cnt++;
			}
		}
	}
	cout << cnt;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    int a[3], k;
    int tmp;
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    scanf("%d", &k);

    for (int i = 1; i < 3; i++) {
        if (a[0] < a[i]) {
            tmp = a[0];
            a[0] = a[i];
            a[i] = tmp;
        }
    }

    for (int i = 0; i < k; i++)
        a[0] *= 2;
    
    printf("%d", a[0]+a[1]+a[2]);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int N, M;
int step[50001];
int song[50001];
string note[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
int getidx(string s){
  REP(i, 12)if(s == note[i]) return i;
  return -1;
}
bool dfs(int p, int idx){
  if(idx == M) return (p == N - 1 || p == N - 2) ;
  int d[3] = {-1, 1, 2};
  int dif[3] = {-1, 0, 1};
  REP(r, 3){
    int np = p + d[r];
    if(np >= 0 && np < N && (step[np] + dif[r] + 12) % 12 == song[idx] && dfs(np, idx + 1)){
      return true;
    }
  }
  return false;
}
bool dfs2(int p, int idx){
  if(idx == -1) return (p == -1);
  if(p >= N || p < 0) return false;
  int dif = (song[idx] - step[p]);
  if(dif == 11) dif = -1;
  if(dif == -11) dif = +1;
  if(abs(dif) >= 2) return false;
  if(dif == 0) return dfs2(p - 1, idx - 1);
  if(dif == 1) return dfs2(p - 2, idx - 1);
  if(dif == -1) return dfs2(p + 1, idx - 1);
  assert(false);
}

int main(){
  int T;
  cin>>T;
  while(T--){
    cin>>N>>M;
    REP(i, N){
      string s; cin>>s;
      step[i] = getidx(s);
      assert(step[i] != -1);
    }
    REP(i, M){
      string s; cin>>s;
      song[i] = getidx(s);
    }
    //bool ans = dfs(-1, 0);
    bool ans2 = (dfs2(N - 1, M - 1) || dfs2(N - 2, M - 1));
    if(ans2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1300
#include<cstdio>
#include<iostream>
long long s[100005];
long long dis[100005];
int main()
{
	long long n,i;
	scanf("%d",&n);
	long long sum=0;
	for(i=1;i<=n;i++)
	scanf("%lld",&s[i]),sum+=s[i];
	if(sum%(n*(n+1)/2))
	{
		printf("NO\n");
		return 0;
	}
	sum/=(n*(n+1))/2;
	dis[1]=s[1]-s[n];
	for(i=2;i<=n;i++)
	dis[i]=s[i]-s[i-1];
	long long cnt=0;
	for(i=1;i<=n;i++)
	{
		if((sum-dis[i]<0)||(sum-dis[i])%n)
		{
			printf("NO\n"); 
			return 0;
		}
		else cnt+=(sum-dis[i])/n;
	}
	if(cnt!=sum)printf("NO\n");
	else printf("YES\n");
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

string s;
li n;

li cnt[222];



int main() {
    cin >> n >> s;
    sz(s);
    rin{
        cnt[s[i] - 'a']++;
    }

    li res = 1;
    rep(i, 26) {
        res = (res * (cnt[i] + 1)) % MOD;
    }

    cout << res - 1 << endl;

    return 0;
}

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

int thesumofdigits (int N) {
  int sum;
  while(N>0){
    int d=N%10;
    sum+=d;
    N/=10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  
  int ha = thesumofdigits(N);
  
  if(N%ha == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    double N, K;
    cin >> N >> K;

    double ans = 0;
    int X;
    if (N >= K){
        ans = (N-K+1)/N;
        X = K-1;
    }
    else X = N;


    FOR(i, 1, X){
        //cout << pow(0.5, ceil(log2(K/i))) << endl;
        ans += pow(0.5, ceil(log2(K/i))) * (1/N);
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
double ans;

int main() {
    //cout.precision(10);
    int N;
    cin >> N;
    while(N--) {
        double in;
        cin >> in;
        ans += 1 / in;
    }
    cout << 1 / ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    s = [0]
    for i in a:
        s.append(s[-1]+i)
    S = []
    for i in range(n):
        for j in range(i+1,n+1):
            S.append(s[j]-s[i])
    ans = 0
    for i in range(max(S).bit_length())[::-1]:
        m = 0
        b = 1<<i
        s_ = []
        for j in S:
            if j&b:
                m += 1
                s_.append(j)
        if len(s_) >= k:
            ans += b
            S = [i for i in s_]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 66428
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int a[100010];
int b[40];

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

int main()
{
	int n,k;
	cin >> n >> k;
	
	double ans = 0;
	for(int i = 1; i <= n; i++){
		int tmp = i,cnt = 0;
		while(tmp < k) { tmp *= 2; cnt++; };
		ans += (double)1/(n*Pow(2,cnt));
	}
	
	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}


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


int  main()
{
	string str;
	
	int N;
	cin >> N;
	
	
	int count_o = 0;
	int temp;
	for(int n = 0; n<N; n++){
		cin >> temp;
		if(temp%2 == 1)	count_o++;
	}
	
	
	if(count_o%2 == 1){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	
	
	return 0 ;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
p = list(map(int,input().split()))
root = list(range(N))
depth = [1 for _ in range(N)]

def find(a,root):
    if root[a] == a:
        return a
    else:
        root[a] = find(root[a],root)
        return root[a]

def unite(a,b,root,depth):
    A = find(a,root)
    B = find(b,root)
    if A == B:
        return
    elif depth[A] > depth[B]:
        root[B] = A
        depth[A] += depth[B]
    else:
        root[A] = B
        depth[B] += depth[A]
for i in range(M):
    x,y = map(int,input().split())
    unite(x-1,y-1,root,depth)

order = [-1 for _ in range(N)]
for i in range(N):
    order[p[i]-1] = find(i,root)
count = 0
for i in range(N):
    if order[i] == root[i]:
        count += 1
print(count)

Measured memory_bytes: 81772
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>

const int Maxv = 200010; 
using namespace std; 

long long n, m;
std::string s, t; 

inline int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a; 
}

int main() {
    std::ios::sync_with_stdio(false); 
    std::cin >> n >> m >> s >> t; 
    long long l = n * m / __gcd(n, m); 
    
    for (int i = 0; i < n; i++) {
        if (i * m % n == 0 && s[i] != t[i * m / n]) {
            puts("-1"); 
            return 0; 
        }
    }

    std::cout << l; 

    return 0; 
}

Measured memory_bytes: 640
n = int(input())
battle = [input().split(" ") for i in range(n)]
result = [0] * 2
for i in battle:
  taro = i[0]
  hanako = i[1]

  if taro > hanako:
    result[0] += 3
  elif taro < hanako:
    result[1] += 3
  else:
    result[0] += 1
    result[1] += 1
print("{} {}".format(result[0], result[1]))


Measured memory_bytes: 5712
H, W, K = map(int, input().split())
X = []
for i in range(H):
  x = list(input())
  X.append(x)

def HandV():
  ans = 0
  for h in range(2**H): 
    for w in range(2**W):
      cnt=0
      for i in range(H):
        for j in range(W):
          if (h>>i)&1==0 and (w>>j)&1==0:
            if X[i][j]=='#':
              cnt+=1
      if cnt==K:
        ans+=1
  print(ans)
HandV()       

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

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

	int x[n][d];
	for(int in=0; in<n; in++){
		for(int id=0; id<d; id++){
			cin >> x[in][id];
		}
	}

	int counter =0;

	for(int in=0; in<n; in++){
		for(int jn=in+1; jn<n; jn++){

			int sum = 0;
			for(int id=0; id<d; id++){
				sum += 	(x[in][id]-x[jn][id])*(x[in][id]-x[jn][id]);
			}
			double distance = sqrt(sum);

			if(distance==(int)distance){
				counter += 1;
			}

		}
	}
	cout <<counter <<endl;

	return 0;
}


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

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

int main(){

  int n; cin>> n;
  int a[n][n];
  rep(i, n)rep(j, n) cin>> a[i][j];

  long long sum=0;
  rep(i, n)rep(j, i) sum+=min(a[i][j], a[j][i]);
  cout<< sum<< endl;

  return 0;
}


Measured memory_bytes: 3156
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
aa = [(num,i) for i,num in enumerate(a)]
aa.sort()
write(" ".join(map(str, [item[1]+1 for item in aa])))

Measured memory_bytes: 97912
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int freq[100008];

int main()
{	
	int n,x;
	cin>>n;
	int dc=0;
	int ans=1;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		freq[x]++;
		
	}
	if(freq[0]>1){cout<<0;return 0;
	}
	for(int i=1;i<100008;i++)
	{
		if(freq[i]>2){cout<<0;return 0;
		}
		if(freq[i]<=2 and freq[i])
		{
			ans=(ans*2)%mod;
		}
	}
	cout<<ans;
	
}

Measured memory_bytes: 640
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, d, maxHealth;
vector<vector<int>> X;

template <typename T>
struct fenwick_tree {
private:
   int n;
   vector <T> a;
public:
   void initialize(int k) {
      n=k;
      a.assign(n+1,0);
   }
   
   void update(int pos, T val) {
      for(;pos<=n;pos+=pos&(-pos)) a[pos]+=val;
   }
 
   T query(int pos) {
      T ans=0;
      for(;pos>=1;pos-=pos&(-pos)) ans+=a[pos];
      return ans;
   }
   
   T get(int from, int to) {
      return query(to)-query(from-1);
   }

   int lower_bound(T x){
      int index = 0;
      int sum = 0;
      for (int i = (log2(n) + 1); i >= 0; --i)
      {
         if((index+(1<<i)) <= n and (sum + a[index+(1<<i)]) < x){
            sum += a[index+(1<<i)];
            index += (1<<i);
         }
      }
      return index+1;
   }
};

fenwick_tree <int> bit;

int32_t main(){_
   
   cin>>n>>d>>maxHealth;

   for (int i = 0; i < n; ++i)
   {
      int x, h;
      cin >> x >> h;
      X.push_back({x, h});
   }

   X.push_back({-inf, -inf});
   sort(X.begin(), X.end());

   bit.initialize(n);

   int ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      int curr = X[i][1] - bit.query(i);
      if(curr <= 0)
         continue;
      vector<int> tt = {X[i][0] + 2*d, inf};
      auto it = upper_bound(X.begin(), X.end(), tt);
      --it;
      int idx = it - X.begin();
      int amt = (curr + maxHealth - 1) / maxHealth;
      ans += amt;
      int vals = amt * maxHealth;
      bit.update(i, vals);
      bit.update(idx+1, -vals);
   }
   
   cout<<ans;

   return 0;
}

Measured memory_bytes: 13868
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int MAX = 50001;

int main (int argc, char *argv[]) {
    vector<bool> v(MAX, true);
    vector<int> num(MAX, 0);
    for (int i = 2; i < sqrt(MAX); ++i) {
        if (v[i]) {
            for (int j = 0; i*(j+2) < MAX; ++j) {
                v[i*(j+2)] = false;
            }
        }
    }
    for (int i = 2; i < MAX/2 + 1; ++i) {
        if (v[i]) {
            for (int j = i; j < MAX; ++j) {
                if (v[j] && i+j <= MAX) {
                    num[i+j]++;
                }
            }
        }
    }
    int n;
    while (cin>>n, n) {
        cout<<num[n]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3060
H, W = map(int, input().split())

S = [None] * H

for h in range(H):
    S[h] = list(input())

flag_break = False

for h in range(H):
    if flag_break == False:
        for w in range(W):
            if S[h][w] == '#':
                if S[max(0, h-1)][w] != '#' and S[h][max(0, w-1)] != '#' and S[h][min(W-1, w+1)] != '#' and S[min(H-1, h+1)][w] != '#':
                    flag_break = True
                    break

if flag_break == True:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

string s, t, u;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s >> t >> u;
	cout << (s.back() == t.front() && t.back() == u.front() ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	int n, y;
	scanf("%d%d", &n, &y);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j + i <= n; j++) {
			if (y == 10000 * i + 5000 * j + 1000 * (n - i - j)) {
				printf("%d %d %d", i, j, n - i - j);
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a>>b>>c;
  rep(i,10){
    c=a*c-b;
    cout <<c<<endl;
  }
}

Measured memory_bytes: 3660
#include<cstdio>

int main(){
	char c;
	char boin[] = "aiueo";
	scanf("%c",&c);
	for(int i=0;i<5;i++){
		if(boin[i]==c){
			printf("vowel\n");
			return 0;
		}
	}
	printf("consonant\n");
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int cnt7 = 0, cnt5 = 0;
    rep(i, 3) {
        int N; cin >> N;
        if (N == 5) cnt5++;
        else if (N == 7) cnt7++;
    }

    if (cnt5 == 2 && cnt7 == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}



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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9


string comon_string(string s1, string s2){
    map<char, int> map1, map2;
    for(auto i : s1){
        map1[i]++;
    }
    for(auto i : s2){
        map2[i]++;
    }
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    string s;
    for(auto c : alphabet){
        rep(i,min(map1[c], map2[c])){
            s += c;
            
        }
    }
    return s;
}


int main(){
   
    
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n)  cin >> s[i];
    string ans = s[0];
   
    rep(i,n){
        ans = comon_string(s[i], ans);
   
        
    }
    cout << ans << endl;
     
     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int n;

int main(){
	cin >> n;
	
	cout << (n < 1200 ? "ABC" : "ARC") << endl;
	
	return 0;
}

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


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll one[200005],zero[200005],par[200005],n,pp[200005];
ll ans=0;

int f(int i)
{
	if(par[i]!=i)
	par[i]=f(par[i]);
	return par[i];
}
struct cmp
{
	bool operator() (const pair<pii,int> &a,const pair<pii,int> &b) const
	{
		pll lo=a.ff,hi=b.ff;
		if(lo.ff*hi.ss<hi.ff*lo.ss)return true;
		if(lo.ff*hi.ss==hi.ff*lo.ss)return a<b;
		return false;
	}
};

set<pair<pii,int> , cmp> s;

void merge(int a,int b)
{
	a=f(a),b=f(b);	
	if(a==b)return;
	par[a]=b;
	s.erase(mp(mp(one[a],zero[a]),a));
	s.erase(mp(mp(one[b],zero[b]),b));
	ans+=one[b]*zero[a];
	one[b]+=one[a];
	zero[b]+=zero[a];
	s.insert(mp(mp(one[b],zero[b]),b));
}


int main()
{ios_base::sync_with_stdio(false);
cin>>n;
rep(i,2,n)cin>>pp[i];
rep(i,1,n)
{
	par[i]=i;
	int x;
	cin>>x;
	if(x)one[i]++;
	else zero[i]++;
	s.insert(mp(mp(one[i],zero[i]),i));
	//ol(s.size());on;
}


rep(i,1,n-1)
{
	set<pair<pii,int>,cmp>:: iterator it =s.begin();
	int id=it->ss;
	if(id==1)
	{
		it++;
		id=it->ss;
	}

	merge(id,pp[id]);
}
ol(ans);
return 0;
}



Measured memory_bytes: 19072
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int ans = 0;
        for (int i=0;i<n;i++) {
            array[i] = sc.nextInt();
            ans += array[i];
        }
        int m = sc.nextInt();
        for (int i=0;i<m;i++) {
            int p = sc.nextInt();
            int x = sc.nextInt();
            System.out.println(ans - array[p-1] + x);
        }

    }
}

Measured memory_bytes: 23124
#include <stdio.h>

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

  int num,cnt,i,j;
  num=0;

  for(i=0;i<=a;i++){
    cnt=0;
    j=i;
    while(j){
      cnt++;
      j/=10;
    }
    if(cnt%2==1)  num++;
  }
  printf("%d\n",num);
  return 0;
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  double ans(0);

  for (int i = 1; i <= n; i++) {
    double p = 1.0 / n;
    for (int x = i; x < k; x *= 2) {
      p *= 0.5;
    }
    ans += p;
  }
  cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define DEBT 100000
int main(){
	double a=DEBT;
	int n,i;

	scanf("%d",&n);

	for(i=0;i<n;i++){
	a*=1.05;
	a=ceil(a/1000)*1000;
	}

	printf("%.0f\n",a);

	return 0;
}

Measured memory_bytes: 632
using System;
using System.Text;

// arihon p333
namespace ALDS1_14_C
{
    class Program
    {
        static int H, W, R, C;
        static char[][] field, pattern;
        static ulong[,] hash, tmp;
        static StringBuilder sb = new StringBuilder();

        static void Main(string[] args)
        {
            var t = scan;
            H = t[0]; W = t[1];
            field = new char[H][];
            hash = new ulong[H,W];
            tmp = new ulong[H, W];

            for (int i = 0; i < H; i++)
            {
                field[i] = Console.ReadLine().ToCharArray();
            }

            t = scan;
            R = t[0]; C = t[1];
            pattern = new char[R][];

            for (int i = 0; i < R; i++)
            {
                pattern[i] = Console.ReadLine().ToCharArray();
            }

            solve();

            Console.Write(sb);
        }
        static void solve()
        {
            if (R > H || C > W) return;

            //??????????????????????????\???????±???????
            ulong HP;
            compute_hash(pattern, R, C);
            HP = hash[0, 0];

            //?????????????????\????????????????????????????¨????
            compute_hash(field, H, W);
            for (int i = 0; i + R <= H; i++)
            {
                for (int j = 0; j + C <= W; j++)
                {
                    if (HP == hash[i, j]) sb.AppendLine(i + " " + j);
                }
            }
        }

        //a??????R*C?????¨????????¢?????????????????\????¨????
        static void compute_hash(char[][] a, int n, int m)
        {
            const ulong B1 = 9973;
            const ulong B2 = 100000007;

            ulong t1 = 1; //B1???C???
            for (int j = 0; j < C; j++) t1 *= B1;

            //???????????????????????\???????¨????
            for (int i = 0; i < n; i++)
            {
                ulong e = 0;
                for (int j = 0; j < C; j++) e = e * B1 + a[i][j];

                for (int j = 0; j + C <= m; j++)
                {
                    tmp[i, j] = e;
                    if (j + C < m) e = e * B1 - t1 * a[i][j] + a[i][j + C];
                }
            }

            ulong t2 = 1; //B2??????
            for (int i = 0; i < R; i++) t2 *= B2;

            //???????????????????????\???????¨????
            for (int j = 0; j + C <= m ; j++)
            {
                ulong e = 0;
                for (int i = 0; i < R; i++) e = e * B2 + tmp[i, j];

                for (int i = 0; i + R <= n; i++)
                {
                    hash[i, j] = e;
                    if (i + R < n) e = e * B2 - t2 * tmp[i, j] + tmp[i + R, j];
                }
            }

        }
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 60640
#include <iostream>
using namespace std;
int main()
{
	int l,r,mi=2000000005;
	cin>>l>>r;
	r=min(r,l+2019);
	for(int i=l;i<=r;i++)
	{
		for(int j=i+1;j<=r;j++)
		{
			mi=min(mi,((i%2019)*(j%2019))%2019);
		}
	}
	cout<<mi;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
    } else if (a.size() < b.size()) {
        cout << "LESS" << endl;
    } else {
        if (a > b) {
            cout << "GREATER" << endl;
        } else if (a < b) {
            cout << "LESS" << endl;
        } else {
            cout << "EQUAL" << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool s, n, e, w;
int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'S') {
			s = true;
		}
		else if (S[i] == 'N') {
			n = true;
		}
		else if (S[i] == 'E') {
			e = true;
		}
		else {
			w = true;
		}
	}
	if (s == true && n == true) {
		s = false;
		n = false;
	}
	if (e == true && w == true) {
		e = false;
		w = false;
	}
	if (s == false && n == false && e == false && w == false) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public  class Main {
    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            if ( a < b ) {
                System.out.println("a" + " "  + "<"  + " " +  "b" );
            }
            if ( a > b ) {
                System.out.println("a"  + " " + ">" +   " " +  "b" );
            }
            if ( a == b ) {
                System.out.println("a" + " "  + "=="  + " " + "b");
            }
        }
}




Measured memory_bytes: 26208
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int[] A = new int[N + 2];
    A[0] = 0;
    A[N + 1] = 0;
    long[] sum = new long[N + 2];
    for (int i = 1; i <= N; i++) {
      A[i] = Integer.parseInt(scanner.next());
    }
    for (int i = 0; i <= N; i++) {
      sum[i + 1] = sum[i] + Math.abs(A[i + 1] - A[i]);
    }
    scanner.close();

    for (int i = 1; i <= N; i++) {
      System.out.println(sum[N + 1] - (sum[i + 1] - sum[i - 1]) + Math.abs(A[i + 1] - A[i - 1]));
    }

  }

}


Measured memory_bytes: 50560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005,M=200005,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,ans[M];
bitset<N> h,a[N];
vector< pair<int,int> > e[N];
void work(int x){
	h[x]=1;
	for (auto t : e[x])
	if (!h[t.first]) work(t.first);
}
int main(){
	n=read();m=read();
	for (int i=1;i<=m;i++){
		int u=read(),v=read();
		e[u].push_back(make_pair(v,i));
	}
	for (int x=1;x<=n;x++){
		h.reset();h[x]=1;
		for (auto t : e[x]){
			int y=t.first;
			if (h[y]) ans[t.second]=1;
			else work(y);
		}
		a[x]|=h;
		h.reset();h[x]=1;
		reverse(e[x].begin(),e[x].end());
		for (auto t : e[x]){
			int y=t.first;
			if (h[y]) ans[t.second]=1;
			else work(y);
		}
	}
	for (int x=1;x<=n;x++)
	for (auto t : e[x]){
		int y=t.first,i=t.second;
		ans[i]^=a[y][x];
	}
	for (int i=1;i<=m;i++) puts(ans[i] ? "diff" : "same");
	return 0;
}

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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (auto &x : l) cin >> x;

  int a, b, c, mp, ans{1000000000};
  for (unsigned i = 0, n = 1 << N * 2; i != n; ++i) {
    a = b = c = 0;
    mp = -30;
    for (int j = 0; j != N; ++j) {
      switch ((i >> j * 2) & 3) {
        case 1:
          a += l[j];
          mp += 10;
          break;
        case 2:
          b += l[j];
          mp += 10;
          break;
        case 3:
          c += l[j];
          mp += 10;
          break;
      }
    }

    if (!a || !b || !c) continue;

    ans = min(ans, mp + abs(A - a) + abs(B - b) + abs(C - c));
  }

  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 1010

int main() {
   int n, m, k;
   cin >> n >> m >> k;
   for (int i = 0 ; i <= n ; ++i) {
      for (int j = 0 ; j <= m ; ++j) {
         if (i * j + (n - i) * (m - j) == k) {
            cout << "Yes" << endl;
            return 0;
         }
      }
   }
   cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

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

    int A, B, K; cin >> A >> B >> K;

    vector<int> cd;
    
    for (int a = 1; a <= A; ++a) {
        if (A % a == 0 && B % a == 0) cd.push_back(a);
    }

    sort(cd.begin(), cd.end());

    cout << cd[cd.size() - K] << "\n";

    return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a'){
    cout << "vowel" << endl;
  }else if (c == 'i'){
   cout << "vowel" << endl;
  }else if (c == 'u'){
   cout << "vowel" << endl;
  }else if (c == 'e'){
   cout << "vowel" << endl;
  }else if (c == 'o'){
   cout << "vowel" << endl;
  }else{
   cout << "consonant" << endl;
  }
    
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve(){
    ll n;
    cin>>n;
    ll a[n + 1];
    ll cnt = 0ll;
    map<ll, ll> mp; // i+a[i] count

    rep(i, 1, n){
        cin>>a[i];
        cnt += mp[1ll*i - a[i]];
        mp[1ll*i + a[i]]++;
    }
    cout<<cnt;
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

int main(){
	int a, b;
	cin >> a >> b;
	
	if (a + b > a - b && a + b > a * b) {
		cout << a + b << endl;
	}
	else if (a - b > a + b && a - b > a * b){
		cout << a - b << endl;
	}
	else if (a * b > a + b && a * b > a - b) {
		cout << a * b << endl;
	}
	else {
		cout << a << endl;
	}
	
	return 0;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


map<ll, ll> factorize(ll n) {
    map<ll, ll> res;
    res[1] = 1;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;

}

int main() {
    ll a, b;
    cin >> a >> b;

    map<ll, ll> f1 = factorize(a), f2 = factorize(b);

    int i = 0;
    for (auto e : f1) {
        if (f2.find(e.first) != f2.end()) i++;
    }
    cout << i << endl;

}


Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

ll N, K;
vector<ll> a;

void solve() {
  ll cost = LINF;

  vector<ll> mx(N);
  mx.at(0) = a.at(0);
  FOR(i, 1, N) { mx.at(i) = max(mx.at(i - 1), a.at(i)); }

  rep(bit, 1 << N) {
    vector<ll> idxs;
    rep(i, N) {
      if (bit & (1 << i)) idxs.push_back(i);
    }
    if (idxs.size() != K) continue;

    ll maxh = 0, sum = 0;
    rep(i, K) {
      ll idx = idxs.at(i);
      maxh = max(maxh, mx[idx]);
      if (a.at(idx) <= maxh) {
        sum += maxh - a.at(idx);
        maxh++;
      } else {
        maxh = a.at(idx);
      }
    }
    cost = min(cost, sum);
  }

  cout << cost << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  cin >> N >> K;
  a.resize(N);
  rep(i, N) { cin >> a.at(i); }
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
    	new C().doIt();
    }
    class C{
    	boolean all[][] = new boolean[5][401];
    	ArrayList<Point2D> array = new ArrayList<Point2D>();
    	int result = 0;
    	int n = 0;
    	void dfs(int deep,int num){
    		if(deep == 10){
//    			System.out.println(num);
//    			check();
    			result = Math.min(result,num);
    		}else{
    			for(int i = 1;i <= n;i++){
    				if(num+i >= result)continue;
    				int cnt = 0;
    				for(int j = 0;j < array.size();j++){
    					if(!all[(int)array.get(j).getY()][(int)array.get(j).getX() + num + i])cnt++;
    				}
    				if(cnt == n){
    					for(int j = 0;j < array.size();j++)all[(int)array.get(j).getY()][(int)array.get(j).getX() + num + i] = true;
//    					check();
    					dfs(deep+1,num+i);
    					for(int j = 0;j < array.size();j++)all[(int)array.get(j).getY()][(int)array.get(j).getX() + num + i] = false;
    				}
    			}
    		}
    	}
    	void clear(){
    		for(int i = 0;i < 5;i++){
    			for(int j = 0;j < 401;j++){
    				all[i][j] = false;
    			}
    		}
    		array.clear();
    	}
    	void check(){
    		for(int i = 0;i < 5;i++){
    			for(int j = 0;j < 40;j++){
    				System.out.print(all[i][j] ? 1:0);
    			}
    			System.out.println();
    		}
    	}
    	void doIt(){
            while(true){
            	n = sc.nextInt();
            	if(n == 0)break;
            	result = Integer.MAX_VALUE;
            	clear();
            	boolean map[][] = new boolean[5][n];
            	for(int i = 0;i < 5;i++){
            		String str = sc.next();
            		for(int j = 0;j < n;j++){
            			if(str.charAt(j) == 'X'){
            				map[i][j] = true;
            				array.add(new Point2D.Double(j,i));
            			}
            			else map[i][j] = false;
//            			System.out.print(map[i][j] ? 1:0);
            		}
//            		System.out.println();
            	}
            	for(int i = 0;i < array.size();i++){
//            		System.out.println(array.get(i).getX()+" "+array.get(i).getY());
            		all[(int)array.get(i).getY()][(int)array.get(i).getX()] = true;
            	}
//            	check();
            	dfs(1,0);
            	System.out.println(result+n);
            }
        }
    }
}

Measured memory_bytes: 29428
#include "bits/stdc++.h"
using namespace std;
int INF = 1e8;

int f(vector < pair<int, int> >vec) {
	sort(vec.begin(),vec.end());
	int res = INF;
	for (int i = 1;i<vec.size();++i) {
		if (0 == vec[i-1].second && 0 != vec[i].second) {
			res = min(res,vec[i].first- vec[i-1].first);
		}
	}
	return res;
}

int f(map<int, vector<pair<int, int>>>mp) {
	int res = INF;
	for (auto p:mp) {
		res = min(res,f(p.second));
	}
	return res;
}

int main() {
	int N; 
	cin >> N;
	vector<int>X(N), Y(N), U(N);
	for (int n = 0;n<N;++n) {
		char c;
		cin >> X[n]>> Y[n]>>c;
		if ('U' == c) {
			U[n] = 0;
		}
		if ('R' == c) {
			U[n] = 1;
		}
		if ('D' == c) {
			U[n] = 2;
		}
		if ('L' == c) {
			U[n] = 3;
		}
	}
	int ans = INF;
	for (int n = 0;n < 4;++n) {
		//正面衝突
		{
			map<int, vector<pair<int, int>>>mp;
			for (int m = 0; m < N; ++m) {
				if (0 != U[m] &&2 != U[m]) {
					continue;
				}
				mp[X[m]].emplace_back(Y[m],U[m]);
			}
			ans = min(ans,f(mp)*5);
		}
		//垂直衝突
		{
			map<int, vector<pair<int, int>>>mp;	
			for (int m = 0; m < N; ++m) {
				if (0 != U[m] && 1 != U[m]) {
					continue;
				}
				mp[X[m]+Y[m]].emplace_back(Y[m], U[m]);
			}
			ans = min(ans, f(mp) * 10);
		}
		//回転
		{
			for (int m = 0; m < N; ++m) {
				int px = X[m];
				int py = Y[m];
				X[m] = py;
				Y[m] = -px;
				U[m] = (U[m] + 1) % 4;
			}
		}
	}
	if (INF == ans) {
		cout << "SAFE"<<endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 48852
#include<iostream>

int main(){
  int i,a;
  int train[1000];

  i = -1;

  while(std::cin >> a){
    if(a == 0){
      std::cout << train[i] << std::endl;
      --i;
      continue;
    }
    ++i;
    train[i] = a;
  }
}

Measured memory_bytes: 3064
// D - Candidates of No Shortest Paths
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

// void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
// void vvprn(vector<vector<int>> &vv){ for(auto v:vv) vprn(v);cout<<"----\n"; }

#define INF (INT_MAX/2)

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

	vi a(M), b(M), c(M);
	for(int i=0; i<M; i++){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--; b[i]--;
	}

	vvi dist(N,vi(N, INF));//dist[from][to] from->to: cost of shortest path
	for(int i=0; i<N; i++) dist[i][i] = 0;
	// vvprn(dist);//

	for(int i=0; i<M; i++){//set cost of edge
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	// vvprn(dist);//

	// Warshall Floyd (set cost of shortest path)
	for(int r=0; r<N; r++)//relay point
		for(int s=0; s<N; s++)//start point
			for(int t=0; t<N; t++)//terminal point
				dist[s][t] = min(dist[s][t], dist[s][r] + dist[r][t]);
	// vvprn(dist);//

	int ans = 0;
	for(int t=0; t<M; t++) if(dist[a[t]][b[t]]<c[t]) ans++;
	cout<< ans <<endl;
}

Measured memory_bytes: 256