akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i <= n; ++i)
#define arep(x,n) for (int x: n)
using namespace std;

int main()
{
    int x,y; cin >> x >> y;
    int m,n,p;
    bool ans;
    rep(i,x) {
        m = x - i;
        n = i;

        p = m*2 + n*4;
        if(p == y) {
            ans = true;
            break;
        } else {
            ans = false;
        }
    }

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

Measured memory_bytes: 3596
#include <iostream>
#include <string>
using namespace std;
const int INF = 1<<30;
template<typename T1, typename T2> T1 gcd(T1 a, T2 b) { return (b ? gcd(b, a % b) : a); }
template<class Type> class BinaryTree
{
    struct Node { Type val; Node *left, *right; };
    public:
        Node *root = nullptr;
        Node *insert(Node *p, Type x)
        {
            if(p == nullptr) { Node *q = new Node; q->val = x; q->left = q->right = nullptr; if(root == nullptr) root = q; return q; }
            else { if(x < p->val) p->left = insert(p->left, x); else p->right = insert(p->right, x); return p; }
        }
        bool find(Node *p, Type x)
        {
            if(p == nullptr) return false;
            else if(x == p->val) return true;
            else if(x < p->val) return find(p->left, x);
            else return find(p->right, x);
        }
        Node *remove(Node *p, Type x)
        {
            if(p == nullptr) return nullptr;
            else if(x < p->val) p->left = remove(p->left, x);
            else if(x > p->val) p->right = remove(p->right, x);
            else if(p->left == nullptr && p->right == nullptr) { delete p; return nullptr; }
            else if(p->right == nullptr) { Node *q = p->left; delete p; return q; }
            else if(p->left == nullptr) { Node *q = p->right; delete p; return q; }
            else if(p->right->left == nullptr) { Node *q = p->right; q->left = p->left; delete p; return q; }
            else
            {
                Node *q;
                for(q = p->right; q->left->left != nullptr; q = q->left);
                Node *r = q->left;
                q->left = r->right;
                r->left = p->left, r->right = p->right;
                delete p;
                return r;
            }
            return p;
        }
        void print() { inorder(root); cout << endl; preorder(root); cout << endl; }
        void inorder(Node *p) { if(p->left != nullptr) inorder(p->left); cout << " " << p->val;if(p->right != nullptr) inorder(p->right); }
        void preorder(Node *p) { cout << " " << p->val; if(p->left != nullptr) preorder(p->left); if(p->right != nullptr) preorder(p->right); }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    BinaryTree<int> bt;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;
        if(s == "print") bt.print();
        else
        {
            int x; cin >> x;
            if(s == "insert") bt.insert(bt.root, x);
            if(s == "find") cout << (bt.find(bt.root, x) ? "yes" : "no") << "\n";
            if(s == "delete") bt.remove(bt.root, x);
        }
        
    }
    return 0;
}




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

int main(){
    
    int a[3];
    int tmp;
    
    cin >> a[0] >> a[1] >> a[2];
    for(int ii=0;ii<3;ii++){
        for(int jj = 0;jj<3;jj++){
            if( ii != jj){
                if(a[ii] < a[jj]){
                    tmp = a[ii];
                    a[ii] = a[jj];
                    a[jj] = tmp;
                }
                
            }
        }
    }
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    
    return 0;
    
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main() {
  unsigned short *A, *B;

  int C[VMAX + 1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);

  for(i = 0; i <= VMAX; i++) C[i] = 0;

  for(i = 0; i < n; i++) {
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i = 1; i < VMAX; i++) C[i] = C[i] + C[i-1];

  for(j = 1; j <= n; j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++) {
    if( i > 1) printf(" ");
    printf("%d", B[i]);
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 9660
S = gets.chomp.chars
T = gets.chomp.chars

ans = T.size
(S.size - T.size + 1).times do |i|
    a = 0
    T.each_with_index do |t, j|
        a += 1 if S[i+j] != t
    end
    ans = a if a < ans
end

p ans



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

int main() {
	int a,b;

	cin >> a >> b ;
	
	long long ans = 0;
	long long now = 0;

	for (int i = a; i <= b; i++)
	{
		string s = to_string(i);
		if (s[0] == s[4] && s[1] == s[3]) {
			ans++;
		}
	}


	cout << ans  << endl;
}

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

int MAP(vector<vector<int> > &m, int i, int j){
	int w = m[0].size();
	int h = m.size();

	if(!(0 <= i && i < h && 0 <= j && j < w)){
		return 0;
	}

	if(m[i][j] == 0){
		return 0;
	}
	else if(m[i][j] = 1){
		m[i][j] = 0;
		MAP(m, i - 1, j - 1);
		MAP(m, i, j - 1);
		MAP(m, i + 1, j - 1);
		MAP(m, i - 1, j);
		MAP(m, i + 1, j);
		MAP(m, i - 1, j + 1);
		MAP(m, i, j + 1);
		MAP(m, i + 1, j + 1);
	}
	return 1;
}

int main(){
	int w, h;

	while(true){
		int count = 0;
		cin >> w >> h;

		if(w == 0 && h == 0){
			break;
		}

		vector<vector<int> > map(h, vector<int>(w, 0));

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> map[i][j];
			}
		}

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				count += MAP(map, i , j);
			}
		}

		cout << count << endl;
	}
}

Measured memory_bytes: 1376
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        repr(j, i + 1, n) {
            int k = 0;
            while ((i >> k & 1) == (j >> k & 1)) k++;
            cout << k + 1 << " \n"[j == n - 1];
        }
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

vector<string> s(8);
int64 dx[8] = {-1, -1, -1, 0, 0, 1, 1,1 };
int64 dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

bool in(int y, int x) {
  return 0<=y&&y<8&&0<=x&&x<8;
}

int canput(int y, int x, char c, bool f=0) {
  bool ok = 0;
  int res = 0;
  REP(k, 8) {
    int yy = y, xx=x;
    stack<PII> st;
    if (s[yy][xx] != '.') continue;
    int cnt = 0;
    while (in(yy+dy[k], xx+dx[k])) {
      yy += dy[k]; xx += dx[k];
      if (s[yy][xx] == '.' || s[yy][xx] == c) break;
      st.emplace(yy, xx);
      cnt++;
    }
    if (s[yy][xx] == c) {
      if (cnt >= 1) {
        ok = 1;
        res += st.size();
        if (f) {
          while (st.size()) {
            s[st.top().fs][st.top().sc] = c;
            st.pop();
          }
        }
      }
    }
  }
  if (f) {
    s[y][x] = c;
  }
  return res;
}

int main(void) {
  REP(i, 8) {
    cin >> s[i];
  }

  char cc[2] = {'o', 'x'};
  int64 cnt_turn = 0, turn = 0;
  while (cnt_turn < 2) {
    cnt_turn++;
    int64 mx = 0, yy, xx;
    for (int64 y = (turn ? 7 : 0); (turn ? y >= 0 : y < 8); (turn? y-- : y++)) {
      for (int64 x = (turn ? 7 : 0); (turn ? x >= 0 : x < 8); (turn? x-- : x++)) {
        int64 ret = canput(y, x, cc[turn]);
        if (ret > mx) {
          mx = ret;
          yy = y; xx = x;
          cnt_turn = 0;
        }
      }
    }
    if (mx) {
      canput(yy, xx, cc[turn], 1);
    }
    turn = 1-turn;
  }

  REP(i, 8) {
    cout << s[i] << endl;
  }
}




Measured memory_bytes: 3220
N,K,Q = map(int,input().split())
d = {}
for i in range(Q):
    A = int(input())
    d.setdefault(A,0)
    d[A] += 1
for i in range(1,N+1):
    pt = K-Q
    d.setdefault(i,0)
    pt += d[i]
    print('YNeos'[pt<1::2])

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i < N + 1; i += 2) {
    int cnt = 1;
    for (int j = 1; j <= i / 2; ++j) {
      if (i % j == 0) {
        ++cnt;
      }
    }
    if (cnt == 8) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


const long long int mod=1000000007;
int main(){
	cout << fixed << setprecision(18);
	string str;
	char ch;
	long long int n,l,a[200005],id,ma=0;
	cin>>n>>l;
	for(int i=1;i<=n;i++){
		cin>>a[i];	
	}
	for(int i=1;i<=n-1;i++){
		if(ma<a[i]+a[i+1]){
			id=i;
			ma=a[i]+a[i+1];	
		}
	}
	
	if(ma<l){
		cout<<"Impossible"<<endl;	
		return 0;
		
	}else{
			
		cout<<"Possible"<<endl;	
	}
	
	for(int i=1;i<id;i++){
		
		cout<<i<<endl;	
	}
	for(int i=n-1;i>id;i-=1){
		
		cout<<i<<endl;	
	}
	cout<<id<<endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;


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

  vector<pl> a(n);
  for(int i=0;i<n;i++){
    int p;cin>>p;
    a[i]=make_pair(p,i+1);
  }
  sort(a.begin(),a.end());

  for(int i=0;i<n-1;i++)
  cout<<a[i].second<<" ";
  cout<<a[n-1].second<<endl;
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))
sum_height = 0
max_height = A[0]
for i in range(1,len(A)):
    if A[i] < max_height:
        sum_height += max_height - A[i]
    else:
        max_height = A[i]
print(sum_height)



Measured memory_bytes: 32156
#include<stdio.h>

int parent[100001];
int flag[100001];
int sibling[100001];
int degree[100001];
int Left[100001];
int Right[100001];
int depth(int);
int height(int);
int n;
int main()
{
  int i,left,right,id;
  
  scanf("%d",&n);

  for(i=0; i<n; i++){
    parent[i] = -1;
    flag[i] = 1;
    sibling[i] = -1;
    degree[i] = 0;
  }

  for(i=0; i<n; i++){
    scanf("%d%d%d",&id,&left,&right);

    if(left!=-1){
      //Left[id]=left;
      parent[left]=id;
      sibling[left]=right;
      degree[id]++;
     }
    
    if(right!=-1){
      //Right[id]=right;
      parent[right]=id;
      sibling[right]=left;
      degree[id]++;
    }
  }
  
  for(i=0; i<n; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,parent[i],sibling[i],degree[i],depth(i),height(i));
    if(depth(i)==0)
      printf("root\n");
    else if(degree[i]==0)
      printf("leaf\n");

    else printf("internal node\n");
  }
  return 0;
}

int depth(int i){
  if(parent[i] == -1)return 0;
  else return depth(parent[i])+1;
}

int height(int i){
  int j,He,count=0;

  if(degree[i] == 0)return 0;

  else{
    for(j=0; j<n; j++){
      if(parent[j]==i){
	He = height(j)+1;
	if(He>count)count=He;
      }
    }
  }
    return count;
}
  



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main(void)
{
    string A, B;
    cin >> A >> B;

    if(A.size() > B.size())
    {
        cout << "GREATER" << endl;
        return 0;
    }
    else if(A.size() < B.size())
    {
        cout << "LESS" << endl;
        return 0;
    }
    else
    {
        for(int i = 0; i < A.size(); ++i)
        {
            if(A[i] > B[i])
            {
                cout << "GREATER" << endl;
                return 0;
            }
            else if(A[i] < B[i])
            {
                cout << "LESS" << endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    string s;
    cin >> s;
    if(s==".") return 0;
    string t;
    cin >> t;
    vector<string> vs,vt;
    int pre=-1;
    rep(i,s.length()){
      if(s[i]=='"'){
        vs.push_back(s.substr(pre+1,i-pre-1));
        pre=i;
      }
    }
    vs.push_back(s.substr(pre+1,s.length()-pre-1));
    pre=-1;
    rep(i,t.length()){
      if(t[i]=='"'){
        vt.push_back(t.substr(pre+1,i-pre-1));
        pre=i;
      }
    }
    vt.push_back(t.substr(pre+1,t.length()-pre-1));
    int count = 0;
    if(vs.size()!=vt.size()){
      cout << "DIFFERENT" << endl;
      goto next;
    }
    for(int i=0;i<vs.size();i+=2){
      if(vs[i]!=vt[i]){
        cout << "DIFFERENT" << endl;
        goto next;
      }
    }
    for(int i=1;i<vs.size();i+=2){
      if(vs[i]!=vt[i]){
        count++;
      }
    }
    if(count==0){
      cout << "IDENTICAL" << endl;
    }else if(count==1){
      cout << "CLOSE" << endl;
    }else{
      cout << "DIFFERENT" << endl;
    }
    next:;
  }
  return 0;
}



Measured memory_bytes: 3104
#include<stdio.h>

typedef long long lld;
int N; lld ba[202020], sum, s2, gap, dap=1ll<<50;

int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++) scanf("%lld", &ba[i]), sum+=ba[i];
	for(int i=0; i<N; i++){
		s2 += ba[i];
		if(i<N-1){
			gap = sum-s2*2;
			if(gap<0) gap *= -1;
			if(dap>gap) dap=gap;
		}
	}
	printf("%lld\n", dap);
	return 0;
}


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

int main() {
	
	int N,a=0,b=0,c=0,d=0;
	cin>>N;
	string str[N];
	
	for(int i=0;i<N;i++)
	{
		cin>>str[i];
		if(str[i]=="AC")
		{
			a++;
		}
		else if(str[i]=="WA")
		{
			b++;
		}
		else if(str[i]=="TLE")
		{
			c++;
		}
		else
		{
			d++;
		}
	}
	cout<<"AC x "<<a<<endl
		<<"WA x "<<b<<endl
		<<"TLE x "<<c<<endl
		<<"RE x "<<d<<endl;
    return 0;
}

Measured memory_bytes: 6676
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &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<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int f[SIZE][11],p[SIZE][11];
int v[1<<10];
int main(){
    int N;
    R(N);
    REP(i,N){
        REP(j,10)R(f[i][j]);
    }
    REP(i,N)REP(j,11)R(p[i][j]);
    REP(i,N){
        REPP(j,1,1<<10){
            int cnt=0;
            REP(k,10){
                if(f[i][k]&&((j>>k)&1))cnt++;
            }
            v[j]+=p[i][cnt];
        }
    }
    int an=-1e9;
    REPP(i,1,1<<10)an=max(an,v[i]);
    W(an);
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;

int main(){
    string s;
    cin >> s;
    map<ll, ll> ma;
    ma[0] = 0;
    vector<ll> nodes;
    for(ll i = 0; i < s.size(); i++){
        ll tmp = (nodes.size() ? nodes[nodes.size() - 1] : 0);
        nodes.push_back(tmp ^ (1 << (s[i] - 'a')));
    }
    vector<ll> d(nodes.size(), INF);
    for(ll i = 0; i < nodes.size(); i++){
        ll dis = INF;
        for(ll j = -1; j < 26; j++){
            ll tmp = nodes[i];
            if(j != -1) tmp ^= (1 << j);
            auto ite = ma.find(tmp);
            if(ite != ma.end()) dis = min(dis, ite->second);
        }
        d[i] = dis + 1;
        if(ma.find(nodes[i]) == ma.end()) ma[nodes[i]] = d[i];
        else ma[nodes[i]] = min(ma[nodes[i]], d[i]);
    }
    cout << d[d.size() - 1] << endl;
    return 0;
}


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

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

a, b, c, k = gets_i_list

if k.even?
  puts a - b
else
  puts b - a
end

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

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


int main(){

    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    int x = 0,y = 0;
    rep(i,s.size()-1){
        if(s[i]=='R'&&s[i+1]=='L'){
            x++;
        }
    }
    if(s[0]=='L')y++;
    if(s[s.size()-1]=='R')y++;

    if(x>k){
        x -= k;
        cout << n - 2*x -y <<endl;
    }else if(x==k){
        if(y==0&&k)y++;
        cout << n - y << endl;
    }else{
        cout << n -1 << endl;
    }

    return 0;
}  

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
int sort(const void *a,const  void *b)
{
    return *(int *)a - *(int *)b;
}
 
int main()
{
    int N,i,j;
    scanf("%d",&N);
    int X[N],tmp[N];
    for(i=0;i<N;i++){
        scanf("%d",&X[i]);   
        tmp[i] = X[i];            
    }
 
    qsort(X,N,sizeof(int),sort);
    
    for(i=0;i<N;i++){
        if( tmp[i] <= X[N/2-1] ){
            printf("%d\n",X[N/2]);
        }else{
            printf("%d\n",X[N/2-1]);
        }
    }
 
    return 0;
 
}

Measured memory_bytes: 3692
from collections import deque

n = int(input())
m = n * (n - 1) // 2
b = [[0, 0] for _ in range(m + 1)]
f = [0] * (m + 1)
q = deque()
for i in range(1, n + 1):
    a = list(map(int, input().split()))
    for j in range(n - 1):
        ma, mi = max(i, a[j]), min(i, a[j])
        x = (ma - 1) * (ma - 2) // 2 + mi
        if j == 0:
            f[x] += 1
            if f[x] == 2:
                q.append(x)
        else:
            if b[y][0] == 0:
                b[y][0] = x
            else:
                b[y][1] = x
        y = x
ans = 0
while q:
    ans += 1
    l = len(q)
    for _ in range(l):
        i = q.popleft()
        for j in range(2):
            k = b[i][j]
            f[k] += 1
            if f[k] == 2 and not k == 0:
                q.append(k)
print(ans if f[0] == n else -1)

Measured memory_bytes: 138768
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
pos = np.sort(a[a>0])
neg = np.sort(np.abs(a[a<0]))
zero = (a==0).sum()

INF = 2*(10**18)
l = -INF
r = INF

while(r-l>1):
    mid = (l+r)//2
    cnt = 0
    if mid >= 0:
        cnt = len(pos)*len(neg)  #(+) * (-)
        cnt += (len(pos)+len(neg)) * zero # 0 * (non-zero)
        cnt += (zero*(zero-1))//2 # 0 * 0
        x = np.searchsorted(pos, mid//pos, side='right').sum() #(+) * (+)
        x += np.searchsorted(neg, mid//neg, side='right').sum() #(-) * (-)
        x -= (pos*pos<=mid).sum()
        x -= (neg*neg<=mid).sum()
        cnt += x/2
    else:
        #積がmid以上になれば良い -> midよりも小さい
        cnt = (len(neg) - np.searchsorted(neg, abs(mid)//pos + (mid%pos!=0), side='left')).sum()
    #print(mid, cnt)
    #cnt := 積がmid以下になる物の数
    #k番目の数　-> それ以下のものがk個以上ある事が必要
    #cntがk個よりも少ない -> 条件を満たしていない
    #cntがそれ以上ならok
    if cnt < k:
        l = mid
    else:
        r = mid
print(r)


Measured memory_bytes: 32276
from itertools import combinations

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)

    name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for s in S:
        if s[0] in 'MARCH':
            name[s[0]] += 1

    lst = [i for i in name.values() if i]
    n = len(lst)
    if n < 3:
        print(0)
        return

    i = 0
    for a, b, c in combinations(name.keys(), 3):
        if all((name[a], name[b], name[c])):
            i += name[a] * name[b] * name[c]

    print(i)

main()


Measured memory_bytes: 10784
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
#define ALL(v) begin(v),end(v)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	int n;
	cin >> n;
	//vector<string> s(n);
	vector<int> ans(4);
	rep(i, n)
	{
		string s;
		cin >> s;
		if (s == "AC")
			++ans[0];
		else if (s == "WA")
			++ans[1];
		else if (s == "TLE")
			++ans[2];
		else
			++ans[3];
	}

	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
char s[105][105];
int n, m, flag;
int cnt[30];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++)scanf("%s", s[i]);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cnt[s[i][j] - 'a']++;
		}
	}
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)s[i][j] = ' ';
	for(int i = 0; i < n / 2; i++) {
		for(int j = 0; j < m / 2; j++) {
			int pos = -1;
			for(int k = 0; k <= 25; k++) {
				if(cnt[k] >= 4) {
					pos = k, cnt[k] -= 4;
					break;
				}
			}
			if(pos == -1)continue;
			s[i][j] = pos + 'a';
			s[n - i - 1][j] = pos + 'a';
			s[i][m - j - 1] = pos + 'a';
			s[n - i - 1][m - j - 1] = pos + 'a';
		}
	}
	/*for(int i = 0; i < n; i++) {
	  for(int j = 0; j < m; j++) {
	  printf("%c", s[i][j]);
	  }
	  printf("\n");
	  }*/
	if(n & 1) {
		for(int i = 0; i < m / 2; i++) {
			int pos = -1;
			for(int k = 0; k <= 25; k++) {
				if(cnt[k] >= 2) {
					pos = k, cnt[k] -= 2;
					break;
				}
			}
			if(pos == -1)continue;
			s[n / 2][i] = pos + 'a';
			s[n / 2][m - i - 1] = pos + 'a';
		}
	}
	/*for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			printf("%c", s[i][j]);
		}
		printf("\n");
	}*/
	if(m & 1) {
		for(int i = 0; i < n / 2; i++) {
			int pos = -1;
			for(int k = 0; k <= 25; k++) {
				if(cnt[k] >= 2) {
					pos = k, cnt[k] -= 2;
					break;
				}
			}
			if(pos == -1)continue;
			s[i][m / 2] = pos + 'a';
			s[n - i - 1][m / 2] = pos + 'a';
		}
	}
	int pos = 0;
	for(int i = 0; i <= 25; i++)if(cnt[i])pos = i;
	if(n & 1 && m & 1)s[n / 2][m / 2] = pos + 'a';
	/*for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			printf("%c", s[i][j]);
		}
		printf("\n");
	}*/
	for(int i = 0; i <= n / 2; i++) {
		for(int j = 0; j <= m / 2; j++) {
			if(s[i][j] == ' ' || s[i][m - j - 1] == ' ' || s[n - i - 1][m - j - 1] == ' ' || s[n - i - 1][j] == ' ') {
				flag = 1;
				break;
			}
			else if(s[i][j] != s[i][m - j - 1] || s[i][j] != s[n - i - 1][j] || s[n - i - 1][j] != s[n - i - 1][m - j - 1] || s[i][m - j - 1] != s[n - i - 1][m - j - 1]) {
				flag = 1;
				//printf("%d %d\n", i, j);
				//printf("%c %c %c %c\n", s[i][j], s[i][m - j - 1], s[n - i - 1][j], s[n - i - 1][m - j - 1]);
			}
		}
	}
	if(flag)printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
// 2014/09/05 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int N;
		cin >> N;

		if(N==0)
			break;

		if(N%1111==0){		// 全桁が同じ数字
			cout << "NA" << endl;
			continue;
		}

		int cnt = 0;

		while(N!=6174){
			int n[4];
			n[0] = N/1000;
			n[1] = N/100%10;
			n[2] = N/10%10;
			n[3] = N%10;

			sort(n, n+4);

			int L = n[3]*1000+n[2]*100+n[1]*10+n[0];
			int S = n[0]*1000+n[1]*100+n[2]*10+n[3];

			N = L-S;
			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
import collections

N,K=map(int,input().split())

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

a=[A[0]%K]

for i in range(1,N):
    a.append((a[len(a)-1]+A[i])%K)
a.append(0)
b=collections.Counter(a)
MC=b.most_common()
#print(MC)
ans=0
for i in range(len(MC)):
    n=MC[i][1]-1
    ans+=n*(n+1)//2
print(ans)

Measured memory_bytes: 19592
#include<iostream>
#include<string>
using namespace std; 
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5&&B==5&&C==7||A==5&&C==5&&B==7||A==7&&B==5&&C==5){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int times;
	cin >> times;
	bool * a = new bool[times];
	for (int i = 0; i<times; ++i)
	{
		int q, w, e;
		cin >> q >> w >> e;
		if (q + w>e&&q + e>w&&e + w>q)
		{
			if (q*q + w * w == e * e || w * w + e * e == q * q || q * q + e * e == w * w)
				a[i] = true;
			else a[i] = false;
		}
		else
		{
			a[i] = false;
		}
	}
	for (int i = 0; i<times; ++i)
	{
		if (a[i])    cout << "YES" << endl;
		else    cout << "NO" << endl;
	}

}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n;cin >> n;
    vector<LL> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    auto c = a,d = b;
    sort(ALL(c));
    sort(ALL(d));
    for (int i = 0; i < n; i++) {
        if(c[i]>d[i]){
            puts("No");
            return 0;
        }
    }
    vector<P> v(n);
    set<P> st;
    for (int i = 0; i < n; i++) {
        v[i] = mp(b[i],a[i]);
    }
    sort(ALL(v));
    for (int i = 0; i < n; i++) {
        st.insert(mp(-v[i].sc,-i));
    }
    int cnt=0;
    for (int i = 0; i < n; i++) {
        if(v[i].fs >= v[i].sc){
            auto q = st.find(mp(-v[i].sc,-i));
            if(q!=st.end()) st.erase(q);
            continue;
        }
        else cnt++;
        auto p = *st.lower_bound(mp(-v[i].fs,-INF));
        auto q = st.find(mp(-v[i].sc,-i));
        if(q!=st.end()) st.erase(q);
        st.insert(mp(-v[i].sc,p.sc));
        swap(v[i].sc,v[-p.sc].sc);
        st.erase(p);
    }
    if(cnt<=n-2) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 8832
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min([abs(h[j]-h[i])+dp[j] for j in range(max(0,i-k),i)])
print(dp[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    ll n,k;cin>>n>>k;
    vector<ll> h;
    rep(i,n){
        int p;cin>>p;
        h.push_back(p);
    }
    sort(h.begin(),h.end());
    ll ans=0;
    rep(i,n-k){
        ans+=h[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

ld dp[300][300][300];
bool done[300][300][300];
int n;


ld fdp(int a0,int a1,int a2)
{
	int a3=n-a0-a1-a2;
	if(a0<0 || a1<0 || a2<0 || a3<0)
		return 0;
	if(a0>n || a1>n || a2>n ||a3>n)
		return 0;
	if(a0==n)
		return 0;
	if(done[a0][a1][a2])
		return dp[a0][a1][a2];
	dp[a0][a1][a2]=(((ld)a1/n)*fdp(a0+1,a1-1,a2) + ((ld)a2/n)*fdp(a0,a1+1,a2-1) + ((ld)a3/n)*fdp(a0,a1,a2+1) + 1)/(1-(ld)a0/n);
	done[a0][a1][a2]=1;
	//cout<<a0<<' '<<a1<<'='<<dp[a0][a1][a2]<<endl;
	return dp[a0][a1][a2];
}

signed main()
{
	fio
	memset(done,0,sizeof(done));
	cin>>n;
	//cout<<fdp(2,1,0)<<endl;
	//return 0;
	int a1=0,a2=0;
	fo(i,n)
	{
		inp(x)
		if(x==1)
			a1++;
		else if(x==2)
			a2++;
	}
	cout<<fixed<<setprecision(10)<<fdp(0,a1,a2)<<'\n';
	printclock;
}

Measured memory_bytes: 446848
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  long long  A[100003]={};
  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
//  scanf("%lld", &A[0]);
//  A[0]=A[0]-1;
//  for(i=1;i<a;i++){
//    scanf("%lld", &A[i]);
//    if(A[i-1]<A[i]) A[i]=A[i]-1;
//    else if(A[i-1]>A[i]){
//      printf("No\n");
//      return 0;
//    }
//  }
      
  printf("%d\n", a*a*a);
 
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,K;
LL MOD=1e9+7;
LL C[200011];

LL calc(LL x){
	if(x<=0)return 0;
	LL ans=x*(x+1)/2;
	ans%=MOD;
	return ans;
}


int main(){
	cin>>N>>K;
	LL ans=0;
	for(int i=K;i<=N+1;i++){
		ans+=calc(N);
		ans%=MOD;
		//cout<<ans<<endl;
		ans+=(MOD-calc(N-i));
		//cout<<N-K<<" "<<calc(N-K)<<endl;
		ans%=MOD;
		//cout<<ans<<endl;
		ans+=(MOD-calc(i-1));
		ans%=MOD;
		//cout<<ans<<endl<<endl;
		ans+=1;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int N,e, cont;
	cin >> N;
	cont = N;
	e = 10;
	
	while(e != 0){
		if(cont % 2 == 0 && cont % N == 0){
			cout << cont << "\n";
			e = 0;
		}
		cont= cont + N;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   int a[7],b,c,d;
   for(int i=1;i<=6;i++){
    cin>>a[i];
   }
   cin>>b;
   for(int i=0;i<b;i++){
    cin>>c>>d;
   if(c==a[1]){
    if(d==a[2])cout<<a[3]<<endl;
    if(d==a[3])cout<<a[5]<<endl;
    if(d==a[5])cout<<a[4]<<endl;
    if(d==a[4])cout<<a[2]<<endl;
   }else if(c==a[2]){
    if(d==a[1])cout<<a[4]<<endl;
    if(d==a[4])cout<<a[6]<<endl;
    if(d==a[6])cout<<a[3]<<endl;
    if(d==a[3])cout<<a[1]<<endl;
   }else if(c==a[3]){
    if(d==a[1])cout<<a[2]<<endl;
    if(d==a[2])cout<<a[6]<<endl;
    if(d==a[6])cout<<a[5]<<endl;
    if(d==a[5])cout<<a[1]<<endl;
   }else if(c==a[4]){
    if(d==a[1])cout<<a[5]<<endl;
    if(d==a[5])cout<<a[6]<<endl;
    if(d==a[6])cout<<a[2]<<endl;
    if(d==a[2])cout<<a[1]<<endl;
   }else if(c==a[5]){
    if(d==a[1])cout<<a[3]<<endl;
    if(d==a[3])cout<<a[6]<<endl;
    if(d==a[6])cout<<a[4]<<endl;
    if(d==a[4])cout<<a[1]<<endl;
   }else if(c==a[6]){
    if(d==a[2])cout<<a[4]<<endl;
    if(d==a[4])cout<<a[5]<<endl;
    if(d==a[5])cout<<a[3]<<endl;
    if(d==a[3])cout<<a[2]<<endl;
   }
}
}


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

using namespace std;

int main()
{
  int n;
  int m;
  int l;
  long a[100][100]={0};
  long b[100][100]={0};
  long c[100][100]={0};
  int i;
  int j;
  int k;
  
  cin >> n >> m >>l;
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      cin >> a[i][j];
    }
  }
  
  for(i=0;i<m;i++)
  {
    for(j=0;j<l;j++)
    {
      cin >> b[i][j];
    }
  }
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<l;j++)
    {
      for(k=0;k<m;k++)
      {
        c[i][j]+=a[i][k]*b[k][j];
      }
    }
  }
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<l;j++)
    {
    cout << c[i][j];
    if(j!=(l-1))
      cout << " ";
    }
    cout << "\n";
  }
  
}

Measured memory_bytes: 1404
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;

int main()
{
  int n, k;
  cin >> n >> k;
  out(ceil((double)(n-1)/(k-1)));
  return 0;
}


Measured memory_bytes: 256
N, M = [int(n) for n in input().split()]
o = {}
for i in range(N):
    T = [int(n) for n in input().split()]
    K = T[0]
    A = T[1:]
    c = 0
    for j in range(K):
        c = o.setdefault(A[j], 0)
        c += 1
        o[A[j]] = c
ans = 0
for k,v in o.items():
    if v == N:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getPrimeNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static int getPrimeNumber(int array[]){
	  int total = 0;
	  for(int i = 0;i < array.length;++i){
		  boolean isPrime = true;
		  if(array[i] % 2 == 0 || array[i] == 1){
			  isPrime = false;
		  }
		  else{
			  for(int j = 3;j <= Math.sqrt(array[i]);j += 2){
			  //for(int j = 3;j < array[i];j += 2){
				if(array[i] % j == 0){
					isPrime = false;
					break;
				}
			}
		  }
		  if(isPrime || array[i] == 2)total++;
	  }
	  return total;
  }
}

Measured memory_bytes: 30676
package main

import (
    "fmt"
)


var button []int

func main() {
  var N int
  var a int
  var next  int = 0
  var count int = 1 

  fmt.Scan(&N)

  button = make([]int,N)

    for i := 0; i < N; i++ {
      fmt.Scan(&a)
      button[i] = a
    }

//    for i:= 0; i < N; i++ {
//      fmt.Printf("button[%d]=%d\n",i,button[i])
//    }


    for i := 0; i < N ; i++{
      //fmt.Println("i:",i)
      next = button[next]-1
      if next == 1 {
       break
      } else {
        count++
      }
    }

    if next == 1 {
      fmt.Println(count)
    } else {
      fmt.Println(-1)
    }
}


Measured memory_bytes: 5504
N, M = map(int, input().split())
a_list = [int(input()) for _ in range(M)]

mod = 10 ** 9 + 7

dp = [0] * (N + 3)
dp[0] = 1
not_use = [False] * (N + 3)
for a in a_list:
    not_use[a] = True

for i in range(N+1):
    not_u = not_use[i]
    if not_u:
        continue
    else:
        if i < N:
            dp[i + 1] += dp[i]
            dp[i + 1] %= mod
        if i < N - 1:
            dp[i + 2] += dp[i]
            dp[i + 2] %= mod

print(dp[N] % mod)


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

using vi=vector<int>;
using vvi=vector<vector<int>>;

int main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<min(a+b+1,c)+b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

const int MOD = 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	double n;
	int k;
	cin >> n >> k;
	double sum;
	sum = 0;
	for (int i = 1; i <= n; i++)
	{
		double x;
		x = i;
		double	p;
		p = 1.0 / n;
		while (x < k)
		{
			x *= 2;
			p /= 2;
		}
		sum += p;
	}
	cout << sum << endl;
}
// END

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


Measured memory_bytes: 256
#!/usr/bin/env python
import bisect
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    As = set([int(input()) for i in range(M)])
    BIG_NUM = 1000000007

    current_step = 0
    prev_prev_step = 1
    if 1 in As:
        prev_step = 0
    else:
        prev_step = 1
        current_step = 1

    for i in range(2, N+1):
        if i in As:
            current_step = 0
        else:
            current_step = (prev_step + prev_prev_step) % BIG_NUM
        prev_prev_step = prev_step
        prev_step = current_step

    print(current_step)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13544
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define L(__) (__ << 1)
#define R(__) (L(__)|1) 
#define LL long long
#define oo (1<<30)
#define N 300005
using namespace std;
int st1[N],top1,st2[N],top2;
int n,w,h,m,z[N],ans,A[4*N],add[4*N];
struct dot{
	int x,y;
	dot(int _x=0,int _y=0){ x=_x,y=_y;}
}a[N],b[N];
bool cmp(const dot &p,const dot &q){ return p.x<q.x||(p.x==q.x&&p.y<q.y);}
int map(int x){ return lower_bound(z+1,z+m+1,x)-z;}
void update(int t){ A[t]=max(A[L(t)],A[R(t)]);}
void build(int t,int l,int r)
{
	int mid=(l+r)>>1; add[t]=0;
	if(l==r){ A[t]=-z[l]; return ;}
	build(L(t),l,mid);
	build(R(t),mid+1,r);
	update(t);
}
void Add(int t,int d){ add[t]+=d,A[t]+=d;}
void push(int t)
{
	if(add[t]==0) return ;
	Add(L(t),add[t]);
	Add(R(t),add[t]);
	add[t]=0;
}
void modify(int t,int l,int r,int l1,int r1,int d)
{
	int mid=(l+r)>>1;
	if(l>r1||r<l1||l1>r1) return ;
	if(l>=l1&&r<=r1) return Add(t,d);
	push(t);
	modify(L(t),l,mid,l1,r1,d);
	modify(R(t),mid+1,r,l1,r1,d);
	update(t);
}
void solve(int n)
{
	int i,mi=(h>>1);
	for(i=1;i<=n;i++) a[i]=b[i];
	sort(a+1,a+n+1,cmp);
	if(a[n].x<w)
		a[++n]=dot(w,0);
	top1=top2=0;
	for(i=1;i<=n;i++) z[i]=a[i].x;
	m=n,z[++m]=0,z[++m]=w;
	sort(z+1,z+m+1);
	for(i=1;i<=n;i++)
		a[i].x=map(a[i].x);
	build(1,1,m);
	if(a[1].x>1)
		modify(1,1,m,1,1,h);
	a[0].x=1;
	for(i=1;i<=n;i++){
		if(a[i].y<=mi){
			modify(1,1,m,a[i].x,a[i].x,h);
			ans=max(ans,A[1]+z[a[i].x]);
			modify(1,1,m,a[st1[top1]].x,a[i].x-1,-a[i].y);
			while(top1&&a[st1[top1]].y<=a[i].y){
				modify(1,1,m,a[st1[top1-1]].x,a[st1[top1]].x-1,a[st1[top1]].y-a[i].y);
				top1--;
			  }
			st1[++top1]=i;
		  }
		else{
			modify(1,1,m,a[i].x,a[i].x,h);
			ans=max(ans,A[1]+z[a[i].x]);
			modify(1,1,m,a[st2[top2]].x,a[i].x-1,a[i].y-h);
			while(top2&&a[st2[top2]].y>=a[i].y){
				modify(1,1,m,a[st2[top2-1]].x,a[st2[top2]].x-1,a[i].y-a[st2[top2]].y);
				top2--;
			  }
			st2[++top2]=i;
		  }
	  }
}
int main()
{
	int i;
	scanf("%d %d %d",&w,&h,&n);
	for(i=1;i<=n;i++)
		scanf("%d %d",&b[i].x,&b[i].y);
	solve(n);
	for(i=1;i<=n;i++) swap(b[i].x,b[i].y);
	swap(w,h);
	solve(n);
	cout<<ans*2;
	return 0;
}

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

int main(){
  int N;
  ll a[100000];
  cin>>N;
  ll x[100000]={0};
  for (int i(0);i<N;i++)cin>>a[i];
  for (int i(0);i<N;i++){
    if (i%2==0) x[0]+=2*a[i];
    else x[0]-=2*a[i];
  }
  x[0]/=2;
  cout << x[0] << " ";
  for (int i(1);i<N-1;i++){
    x[i]=2*a[i-1]-x[i-1];
    cout << x[i] <<" ";
  }
  cout << 2*a[N-1]-x[0] << endl;
  return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
  int x[5],y[5],a=0,sum=0;
  for(int i=0;i<5;i++){
    scanf("%d",&x[i]);
    y[i]=x[i];
    if(y[i]%10!=0){
      y[i]/=10;
      y[i]+=1;
      y[i]*=10;
    }
    sum+=y[i];
  }
  for(int i=0;i<5;i++){
    if(y[i]-x[i]>a){
      a=y[i]-x[i];
    }
  }
  sum-=a;
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128