akhauriyash/Code-Regression huggingface dataset:
def main(lst):
    m_1, d_1, m_2, d_2 = lst[0], lst[1], lst[2], lst[3]

    before = False
    after = None

    lst_1 = [1, 3, 5, 7, 8, 10, 12]
    lst_2 = [2]
    lst_3 = [4, 6, 9, 11]

    if m_1 in lst_1:
        if d_1 == 31:
            before = True
            if m_2 == m_1 + 1 or m_2 == 1:
                if d_2 == 1:
                    after = True
        else:
            before = False
    elif m_1 in lst_2:
        if d_1 == 28:
            before = True
            if m_2 == 3:
                if d_2 == 1:
                    after = True
        else:
            before = False
    if m_1 in lst_3:
        if d_1 == 30:
            before = True
            if m_2 == m_1 + 1:
                if d_2 == 1:
                    after = True
        else:
            before = False

    if before == True and after == True:
        return 1
    else:
        return 0


if __name__ == '__main__':
    before = list(map(int, input().rstrip().split()))
    after = list(map(int, input().rstrip().split()))

    print(main(before + after))


Measured memory_bytes: 3064
def buffet(n, ali, bli, cli):

    ans = 0
    count = 10**5

    for i in range(n):
        ans += bli[ali[i]-1]

        if ali[i] == count+1:
            ans += cli[count-1]
        count = ali[i]
    return ans

def main():
    n = int(input())
    ali = list(map(int, input().split()))
    bli = list(map(int, input().split()))
    cli = list(map(int, input().split()))
    print(buffet(n, ali, bli, cli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    int N,M; cin >> N >> M;
    vector<ll> a(N);
    priority_queue<ll> pq;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        pq.push(a[i]);
    }
    for (int i = 0; i < M; i++){
        ll top = pq.top();
        pq.pop();
        pq.push(top/2);
    }
    ll ans = 0;
    while(pq.size()){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

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

int main(){

	int a, b, c, d;

	cin >> a >> b >> c;

	if (a >= b){
		d = a; a = b; b = d;
	}
	if (c <= a){
		d = c; c = a; a = d;
	}
	if (c >= a && c <= b){
		d = b; b = c; c = d;
	}


	cout << a << " " << b << " " << c << endl;



	return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int N, M, K;

struct edge
{
  int to, cost;
  edge(int t, int c)
  {
    to = t; cost = c;
  }
};

typedef pair<int, int> P;
vector<edge> edges[10000];
int d[3000];

int dijkstra(vector<int> sts)
{
  priority_queue<P, vector<P>, greater<P> > queue;
  for(auto st : sts)
  {
    d[st] = 0;
    queue.push(make_pair(0, st));
  }
  while(!queue.empty())
  {
    auto p = queue.top(); queue.pop();
    int v = p.second;
    if(d[v] < p.first)
      continue;
    for(auto e : edges[v])
    {
      if(d[e.to] > d[v] + e.cost)
      {
        d[e.to] = d[v] + e.cost;
        queue.push(make_pair(d[e.to], e.to));
      }
    }
  }
}

int main()
{
  fill(d, d + 3000, 1000000000);
  scanf("%d%d%d", &N, &M, &K);
  for(int i = 0; i < M; i++)
  {
    int a, b, l;
    scanf("%d%d%d", &a, &b, &l);
    a--; b--;
    edges[a].push_back(edge(b, l));
    edges[b].push_back(edge(a, l));
  }

  vector<int> sts;
  for(int i = 0; i < K; i++)
  {
    int a;
    scanf("%d", &a);
    sts.push_back(--a);
  }
  dijkstra(sts);
  int ans = 0;
  for(int v = 0; v < N; v++)
    for(auto e : edges[v])
      ans = max(ans, (int)((d[v] + d[e.to] + e.cost) / 2.0 + 0.5));
  printf("%d\n", ans);
}

Measured memory_bytes: 4204
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin>>N;
  set<int> st;
  rep(i,N){
    int d; cin>>d;
    st.insert(d);
  }
  cout<< st.size()<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main() {
  int a, b;
  int x;
  cin >> a >> b;
  x = (a + b) / 2;
  if( (a + b) % 2 == 0)
    cout << x << endl;
  else
    cout << x + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vector<pii> a(n);
	rep(i,n){
		int x;
		cin>>x;
		a[i]=make_pair(x,i+1);
	}
	sort(all(a));
	
	rep(i,n){
		cout<<a[i].second<<endl;
	}
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
  ll res = 1ll << 62;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ll xs = x[i], xt = x[j];
      if (xs > xt) swap(xs, xt);
      vector<ll> ny;
      for (int k = 0; k < N; k++) {
        if (xs <= x[k] && x[k] <= xt) {
          ny.push_back(y[k]);
        }
      }
      sort(ny.begin(), ny.end());
      for (int k = 0; k + K - 1 < ny.size(); k++) {
        res = min(res, (xt - xs) * (ny[k + K - 1] - ny[k]));
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int continueCount = 1;
	map<int, int> mp;

	for (int i = 1; i < s.length(); ++i) {
		if (s[i] != s[i - 1] && s[i] == 'L') {
			mp[i] += continueCount / 2;
			mp[i - 1] += continueCount / 2 + continueCount % 2;
			continueCount = 0;
		}
		else if(s[i] == 'R'){
			++continueCount;
		}
	}

	continueCount = 1;
	for (int i = s.length() - 2; i >= 0; --i) {
		if (s[i] != s[i + 1] && s[i] == 'R') {
			mp[i] += continueCount / 2;
			mp[i + 1] += continueCount / 2 + continueCount % 2;
			continueCount = 0;
		}
		else if (s[i] == 'L') {
			++continueCount;
		}
	}

	for (int i = 0; i < s.length(); ++i) {
		cout << mp[i] << " ";
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 5248
#124c
S = str(input())
#################01234567
ans_b_start = 0 #01010101…
ans_w_start = 0 #10101010…

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            ans_w_start+=1
        if S[i]=="1":
            ans_b_start+=1
    if i%2==1:
        if S[i]=="0":
            ans_b_start+=1
        if S[i]=="1":
            ans_w_start+=1
        
if ans_w_start > ans_b_start:
    print(ans_b_start)
else:
    print(ans_w_start)

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

using namespace std;

vector < int > with[100005];
int used[100005];
int res = 0;

void dfs(int v, int p) {
	used[v] = 1;
	if (p == -1) res++;
	for (int i = 0; i < with[v].size(); i++)
		if (!used[with[v][i]]) dfs(with[v][i], v);
}

int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin>>n>>m;	
	int l, r, z;
	for (int i = 0; i < m; i++) {
		cin>>l>>r>>z;
		with[l].push_back(r);
		with[r].push_back(l);		
	}
	for (int i = 1; i <= n; i++)
		if (!used[i]) dfs(i, -1);
	cout<<res;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	int A[2][N];
	rep(i, 0, 2) rep(j, 0, N) cin >> A[i][j];

	int res[2][N];
	memset(res, 0, sizeof(res));
	res[0][0] = A[0][0];
	rep(i, 1, N) {
		res[0][i] = res[0][i - 1] + A[0][i];
	}

	res[1][0] = res[0][0] + A[1][0];
	rep(i, 1, N) {
		res[1][i] = max(res[0][i], res[1][i -1]) + A[1][i];
	}

	cout << res[1][N - 1] << endl;




}


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

int main()
{
	int n,k;
	cin>>n>>k;
	int x,y;
	for(int i=0;i<k;i++)
	{
		cin>>x>>y;
		x=min(x,n-x+1);
		y=min(y,n-y+1);
		cout<<(min(x,y)%3?min(x,y)%3:3)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int n;
int a[101010];

int main() {
  cin >> n;
  rep(i, 0, n) { cin >> a[i]; }
  sort(a, a + n);
  int ai = a[n - 1];

  int mid;
  if (ai % 2 == 0) {
    mid = ai / 2;
  } else {
    mid = (ai + 1) / 2;
  }

  auto lb = lower_bound(a, a + n, mid);
  int up = *lb;

  if (lb > a) {
    --lb;
  }
  int low = *lb;

  int aj;
  if (ai % 2 == 0) {
    if (abs(up - mid) < abs(low - mid)) {
      aj = up;
    } else {
      aj = low;
    }
  } else {
    if (abs(up - mid) < abs(low - (mid - 1))) {
      aj = up;
    } else {
      aj = low;
    }
  }

  cout << ai << " " << aj << endl;
}


Measured memory_bytes: 640
mod = 10**9+7
N = int(input())
x = list(map(int,input().split()))

ans = 0
for j in range(1,N-1):
    ans += x[j]*j*pow(j+1,mod-2,mod)
    ans %= mod
for i in range(N-2):
    ans += x[i]*(-N+i+2)*pow(N-i-1,mod-2,mod)
    ans %= mod
for i in range(N-1):
    ans += (x[N-1]-x[i])*pow(N-1-i,mod-2,mod)
    ans %= mod

for i in range(1,N):
    ans *= i
    ans %= mod

print(ans)

Measured memory_bytes: 85160
#include <stdio.h>

int main(void){
	long long n,m,d;
	scanf("%lld%lld%lld",&n,&m,&d);
	double ans;
	long long  temp = n*n;
	if(d==0)ans = n * (m-1);
	if(d!=0){
		ans = (n-d) * 2 * (double)(m-1);
	}
	ans /= (double)temp;
	printf("%.10lf",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <list>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<ll> pqil;
typedef priority_queue<iil> pqiil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef pair<iil, ll> iiil;
typedef vector<pair<pair<int,int>,int> > viii;
typedef vector<pair<pair<ll,ll>,ll> > viiil;
typedef vector<vl> vvl;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 2000000000

ll MOD = 1000000007;

void solve() {
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll ans = b * d;
    
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, a * c);
    
    cout << ans << endl;
    
}

void querySolve() {
    int t;
    cin >> t;
    for (int i = 0 ; i < t ; i++) {
        solve();
    }
}

int main() {
    solve();
    //querySolve();
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;	//using vi = vector<int>;
typedef vector<vector<int>> vvi;

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

vvi memo(1000, vector<int>(1000));

int main()
{
	int n;
	cin >> n;
	cout << 3 * n*n << endl;

	return 0;
}


Measured memory_bytes: 4224
#include<iostream>

using namespace std;

int main(){
 
  int a,b,c;
  
  cin >> a >> b >> c;
  
  int cnt = 0;
  
  if(a==5 || a ==7){
   cnt += a;
  }
  if(b==5 || b ==7){
   cnt += b;
  }
  if(c==5 || c ==7){
   cnt += c;
  }
  
  if(cnt == 17){
    cout << "YES" <<endl;
  }else{
  	cout <<"NO"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# CGL_7_F: Circles - Tangent to a Circle

from math import asin, atan2, cos, sin, sqrt


def tangent_point(circle, point):
    cx, cy, cr = circle
    x, y = point

    p = (cx-x)**2 + (cy-y)**2
    q = cr**2
    r = sqrt(p - q)

    t0 = atan2(cy-y, cx-x)
    t1 = asin(cr/sqrt(p))

    return [(x + r*cos(t0+t1), y + r*sin(t0+t1)),
            (x + r*cos(t0-t1), y + r*sin(t0-t1))]


def run():
    x, y = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]

    ps = tangent_point(c, (x, y))

    p1, p2 = ps
    if p1 > p2:
        p1, p2 = p2, p1

    print("{:.10f} {:.10f}".format(*p1))
    print("{:.10f} {:.10f}".format(*p2))


if __name__ == '__main__':
    run()



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

 int main(){
 int N;
 double ans = 0.0, A;
 cin >> N;
 for(int i = 1; i <= N; ++i){
 cin >> A;
 ans += 1.0 / A;
 }
 ans = 1.0 / ans;
 cout << setprecision(16) << ans << endl;
 }


Measured memory_bytes: 256
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int a, b; cin >> a >> b;
  b *= 2;
  cout << max(a - b, 0) << "\n";
}


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

typedef long long ll;

class set{
  class node{
  public:
    int val;
    node *left, *right;
  };

public:
  set(){
    root = NULL;
  }
  void insert(int n){
    root = nodeInsert(root, n);
  }

  bool find(int n){
    return nodeFind(root, n);
  }

  void remove(int n){
    nodeRemove(root, n);
  }
  void printBST(){
    printInorder(root);
    cout << endl;
    printPreorder(root);
    cout << endl;
  }
private:
  node *root;
  node* nodeInsert(node* p, int n){
    if(p==NULL){
      node* q = new node;
      q->val = n;
      q->left = q->right = NULL;
      return q;
    }
    else{
      if(n < p->val){
        p->left = nodeInsert(p->left, n);
      }
      else{
        p->right = nodeInsert(p->right, n);
      }
      return p;
    }
  }
  bool nodeFind(node* p, int n){
    if(p==NULL) return false;
    else if(n==p->val) return true;
    else if(n < p->val) return nodeFind(p->left, n);
    else  return nodeFind(p->right, n);
  }
  node* nodeRemove(node* p, int n){
    if(p==NULL) return NULL;

    if(n < p->val) {
      p->left = nodeRemove(p->left, n);
      return p;
    }
    if(n > p->val) {
      p->right = nodeRemove(p->right, n);
      return p;
    }

    //n == p->val
    if(p->left == NULL){
      return p->right;
    }
    if(p->right == NULL){
      return p->left;
    }
    else{
      int m = min(p->right);
      p->right = nodeRemove(p->right, m);
      p->val = m;
      return p;
    }
  }

  int min(node* p){
    if(p->left == NULL){
      return p->val;
    }
    else{
      return min(p->left);
    }
  }

  void printInorder(node* p){
    if(p==NULL) return;

    if(p->left!=NULL) printInorder(p->left);
    cout << " " << p->val;
    if(p->right!=NULL) printInorder(p->right);
  }

  void printPreorder(node* p){
    if(p==NULL) return;

    cout << " " << p->val;
    if(p->left!=NULL) printPreorder(p->left);
    if(p->right!=NULL) printPreorder(p->right);
  }
};

int main(){
  set s;

  int n; cin >> n;

  string op; ll num;
  for(int i=0; i<n; i++){
    cin >> op;
    if(op[0]=='i') {
      cin >> num;
      s.insert(num);
    }
    if(op[0]=='f') {
      cin >> num;
      cout << ((s.find(num)? "yes": "no")) << endl;
    }
    if(op[0]=='d'){
      cin >> num;
      s.remove(num);
    }
    if(op[0]=='p'){
      s.printBST();
    }
  }

  return 0;
}



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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    string n;
    cin >> n;
    if ((n[0] == n[1] && n[1] == n[2] ) || (n[1] == n[2] && n[2] == n[3])) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    String s=sc.nextLine();
    String t=sc.nextLine();
    int n=s.length();
    int m=t.length();
    int dp[][]=new int[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
      for(int j=0;j<=m;j++)
      {
        if(i==0 || j==0)
        dp[i][j]=0;
        else
        {
          if(s.charAt(i-1)==t.charAt(j-1))
          dp[i][j]=dp[i-1][j-1]+1;
          else
          dp[i][j]=
            Math.max(dp[i][j-1],dp[i-1][j]);
        }
      }
    }
    int i=n,j=m;
    String ans="";
    while(i!=0 && j!=0)
    {
      if(s.charAt(i-1)==t.charAt(j-1))
      {
        ans+=s.charAt(i-1);
        i--;
        j--;
      }
      else
      {
        if(dp[i][j-1]>dp[i-1][j])
        j--;
        else
        i--;
      }
    }
    String rev="";
    for(int k=ans.length()-1;k>=0;k--)
    rev+=ans.charAt(k);
    System.out.println(rev);
  }
}
    

Measured memory_bytes: 88396
// https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  sort(all(as));

  ll res = 0;

  auto calc = [&](bool first_smaller) -> ll {
    VL comps(N);

    rep(i, N) {
      ll c = i == 0 || i == N - 1 ? 1 : 2;
      if ((i % 2 == 0) == first_smaller) c *= -1;
      comps[i] = c;
    }

    sort(all(comps));

    ll _res = 0;

    rep(i, N) { _res += comps[i] * as[i]; }

    return _res;
  };

  chmax(res, calc(true));
  chmax(res, calc(false));

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 1792
//InTheNameOfGod
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
const int maxn = 1e5+5;
int n,a[maxn],f,s,w;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    rep(i,0,n)
    {
        int x,y,t;
        cin>>t>>x>>y;
        int df1=t-w,df2=abs(x-f)+abs(y-f);
        if(df2>df1)
        {
            cout<<"No";
            return 0;
        }
        if(df2<df1&&(df1-df2)%2)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<cassert>
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MRE assert(0)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int>PP;
int a[200006], b[200006];
int L[200006], R[200006];
int imos[200005];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n)cin >> a[i];
	rep(i, n)b[a[i]]++;
	rep(i, n + 1)L[i] = R[i] = -inf;
	rep(i, n) {
		if (b[i + 1]) {
			L[i + 1] = i + 2 - b[i + 1];
			R[i + 1] = i + 1;
		}
	}
	int cnt1 = 0,cnt2=0;
	rep(i, n + 1) {
		if (b[i]) {
			if (L[i] < 1)cnt1 += 1 - L[i];
			imos[max(1ll, L[i])]++;
			imos[R[i] + 1]--;
		}
	}
	rep(j, n + 1)imos[j + 1] += imos[j];
	rep(j, n + 1) {
		if (imos[j])cnt2 += imos[j] - 1;
	}

	rep(i, m) {
		int x, y; cin >> x >> y;
		int F = a[x - 1];
		b[F]--;
		b[y]++;
		a[x - 1] = y;

		if (F == y) {
			cout << cnt1 + cnt2 << endl;
		}
		else {
			imos[L[F]]--;
			if (L[F] < 1)cnt1--;
			else if (imos[L[F]])cnt2--;
			L[F]++;
			if (L[F] > R[F]) {
				L[F] = R[F] = -inf;
			}

			if (b[y] == 1) {
				L[y] = R[y] = y;
				imos[y]++;
				if (imos[y] > 1)cnt2++;
			}
			else if (L[y] <= 1) {
				cnt1++;
				L[y]--;
			}
			else {
				L[y]--;
				if (imos[L[y]])cnt2++;
				imos[L[y]]++;
			}
			cout << cnt1 + cnt2 << endl;
		}
	}
}

Measured memory_bytes: 9216
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, A[10];

int rec(int i, bool f) {
	if (i == N) return f ? 1 : 0;
	int res = 0;
	for_(x,A[i]-1,A[i]+2) res += rec(i+1, f | (x % 2 == 0));
	return res;
}

int main() {
	cin >> N;
	for_(i,0,N) cin >> A[i];
	cout << rec(0, false) << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,j,k,n,p[55],a[55];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> p[i];
    p[i]--;
    a[i]=p[i];
  }
  for(i=0;i<n;i++){
    for(j=i;j<n;j++){
      swap(a[i],a[j]);
      int res=0;
      for(k=0;k<n;k++){
        if(k!=a[k]){
          res=1;
        }
      }
      if(res==0){
        cout << "YES" << endl;
        return 0;
      }
      for(k=0;k<n;k++){
        a[k]=p[k];
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include "stdio.h"
#include <iostream>
using namespace std;

/** Problem0055 : Sequence **/
int main()
{
	double input, sum, old;
	
	while (cin >> input) {
		sum = input;
		old = input;
		for (int i=2; i<=10; i++) {
			if (i%2==0) {
				sum+=old*2;
				old=old*2;
			} else {
				sum+=old/3;
				old=old/3;
			}
		}
		printf("%.8lf\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(){
	int i, j;
	int r, c;
	int data[101][101] = {0};

	scanf("%d %d", &r, &c);

	for(i=0; i<r; i++) {
		for(j=0; j<c; j++) {
			scanf("%d", &data[i][j]);
			data[i][c] += data[i][j];
			data[r][c] += data[i][j];
		}
	}

	for(j=0; j<c; j++) {
		for(i=0; i<r; i++) {
			data[r][j] += data[i][j];
		}
	}

	for(i=0; i<r+1; i++) {
		for(j=0; j<c+1; j++) {
			printf("%d", data[i][j]);
			if(j==c) printf("\n");
			else printf(" ");
		}
	}

	return 0;
}

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

using namespace std;

int edge[100][100];
int size[100];
bool used[100];

int rec(int idx){

  int ret = 1;
  for(int i = 0; i < size[idx]; i++){
    if(!used[edge[idx][i]]){
      used[edge[idx][i]] = true;
      ret = max( ret, rec(edge[idx][i]) + 1);
      used[edge[idx][i]] = false;
    }
  }
  return ret;
}

int main(){
  int N;
  while(cin >> N, N){
    fill_n( size, 100, 0);
    fill_n( used, 100, false);
    for(int i = 0; i < N; i++){
      int a, b;
      cin >> a >> b;
      a--, b--;
      edge[a][size[a]++] = b;
      edge[b][size[b]++] = a;
    }
    int ret = 0;
    for(int i = 0; i < 100; i++){
      used[i] = true;
      ret = max( ret, rec(i));
      used[i] = false;
    }
    cout << ret << endl;
  }
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

const int MOD = 998244353;

int main() {
    string s; cin >> s;
    int N = s.length();
    int M = 0;
    vector<int> dp(N * 2 + 1);
    dp[0] = 1;
    rep(t, N * 2) {
        if (t < N) {
            vector<int> _dp(N * 2 + 1);
            int db = s[t] - '0';
            rep(b, N * 2 + 1) if (dp[b])
                _dp[b + db] = dp[b];
            dp = _dp;
            M += 2;
        }
        {
            vector<int> _dp(N * 2 + 1);
            rep(b, N * 2 + 1) if (dp[b]) {
                int r = M - b;
                if (r) _dp[b] = (_dp[b] + dp[b]) % MOD;
                if (b) _dp[b - 1] = (_dp[b - 1] + dp[b]) % MOD;
            }
            dp = _dp;
            M--;
        }
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if ( size < 1 ) return;
  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if ( key < A[i] ) return;
  A[i] = key;
  while ( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){
  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
}

main(){
  int key;
  char com[20];
  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( strcmp(com, "extract") == 0  ){
      printf("%d\n", extract());
    } else break;
  }
  
  return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 100
#define MAX_M 1000

ll d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
	rep(k, 0, V) rep(i, 0, V) rep(j, 0, V) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
}

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

	rep(i, 0, V) rep(j, 0, V) {
		if(i == j) d[i][j] = 0;
		else d[i][j] = INF;
	}

	ll a[M], b[M], c[M];
	rep(i, 0, M) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
		d[b[i]][a[i]] = min(d[a[i]][b[i]], c[i]);
	}

	warshall_floyd();
	int rsl = M;
	rep(i, 0, M) {
		bool flag = false;
		rep(j, 0, V) {
			if(d[j][a[i]] + c[i] == d[j][b[i]]) flag = true;
		}
		if(flag) rsl--;
	}

	cout << rsl << endl;

}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[200008], b[200008], ite;

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){cin >> a[i];}
	if(n%2 == 0){
		ite = n/2+1;
		for(ll i = 1; i <= n; i++){
			b[ite] = a[i];
			ite += (i%2 == 0)? i : -i;
		}
	}
	else{
		ite = n/2+1;
		for(ll i = 1; i <= n; i++){
			b[ite] = a[i];
			ite += (i%2 == 0)? -i : i;
		}
	}
	
	for(ll i = 1; i <= n; i++){cout << b[i] << " ";}
	cout << endl;
	return 0;
}

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

const int maxn = 100005;
int bit[maxn];

void update(int i, int x) {
  while (i <= maxn)
    bit[i] += x, i += i & -i;
}

int query(int x) {
  int ans = 0;
  while (x)
    ans += bit[x], x -= x & -x;
  return ans;
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      update(x, y);
    } else {
      cout << (query(y) - query(x - 1)) << endl;
    }
  }
}


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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }
        
    UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
            
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
        
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  vector<int> a(4);
  cin>>a[0]>>a[1]>>a[2]>>a[3];
  sort(all(a));
  bool b=0;
 if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)
   b=1;
  YESNO(b);
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
// cf IO: I64d
// atcoder IO: ｌｌｄ
const int Maxn=100005;
vector<int> G[Maxn];
bool vis[Maxn];
int dep[Maxn];
int siz[Maxn];
int p[Maxn];
void dfs(int x,int d){
	dep[x]=d;
	vis[x]=true;
	siz[x]=1;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i];
		if (vis[v]) continue;
		dfs(v,d+1);
		siz[x]+=siz[v];
		p[v]=x;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for (int i=0;i<n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1,0);
	int x=n;
	for (int i=0;i<(dep[n]-1)/2;i++){
		x=p[x];
	}
	if (siz[x]>=n-siz[x]){
		printf("Snuke\n");
	}
	else{
		printf("Fennec\n");
	}
	return 0;
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  int ans = 0;
  int pos = 0;
  while (pos < n) {
    if (ans == 0) {
      pos = pos + k;
    } else {
      pos = pos + k - 1;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long com[51][51] = {};

//降順
int des(const void *a, const void *b)
{
  return *(long *)b - *(long *)a;
}

void com_init() {
  for (int i=0; i<=50; i++)
    com[i][0] = 1;
  for (int i=1; i<=50; i++) {
    for (int j=1; j<=i; j++) {
      com[i][j] = com[i-1][j] + com[i-1][j-1];
    }
  }
  return ;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  long v[N];
  double sum = 0.0;
  int ca = 0, ct = 0;
  for (int i=0; i<N; i++)
    cin >> v[i];
  sort(v, v+N);
  reverse(v, v+N);
  for (int i=0; i<A; i++) {
    sum += v[i];
    if (v[i] == v[A-1])
      ca++;
  }
  printf("%.6lf\n", sum/A);
  for (int i=0; i<N; i++)
    if (v[i] == v[A-1])
      ct++;
  long ans = 0;
  com_init();
  if (ca == A)
    for (int i=A; i<=B; i++)
      ans += com[ct][i];
  else
    ans += com[ct][ca];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define bitoff(val,pos) val & ~(1<<pos)
#define biton(val,pos) val | (1<<pos)
#define bittgl(val,pos) val ^ (1<<pos)
#define bitchk(val,pos) (bool)(val & (1<<pos))
#define odevn(val,pos) (bool)(val & (1<<pos))
#define bitcnt(val) __builtin_popcount(val)
ll ar[1000000],br[1000000],vis[1000009],cm[1000009],ck,n,r,sum,k,sm;
string st;
vector<ll>vec;
vector<ll>vec2[200009];
queue<ll>qq;
stack<ll>stk;
map<string,ll>mp;map<ll,ll>mp1;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll min1=9999999999;
    ll i,j,e,d,t,s=0;
    double dd,vv,gg;
    cin >> n;
    ck=0;
    i=1;
    k=0;
    while(1)
    {
        if(i==1 && k==0)
        {
            k=1;
        }
        else{
        i=i*2;}
        //cout << i << endl;
        n=n/2;
        ck+=i;
        if(n==0){
            break;
        }
    }
   // ck=ck*2;
    cout << ck << endl;
}



Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c = 0;
	string x,y;
	cin >> x >> y;
	a = x.size();
	b = y.size();
	if(a > b)
		cout << "GREATER" << endl;
	else if(a < b)
		cout << "LESS" << endl;
	else if(a == b){
		for(int i = 0; i < a; i++){
			if(x[i] == y[i]){
				continue;
			}
			else if(x[i] < y[i]){
				c = -1;
				break;
			}
			else if(x[i] > y[i]){
				c = 1;
				break;
			}
		}
		if(c == 0)
			cout << "EQUAL" << endl;
		else if(c == 1)
			cout << "GREATER" << endl;
		else if(c == -1)
			cout << "LESS" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a, b;
	int c = 0;
	cin >> a >> b;
	c = a - (2 * b);
	if (c < 0)
	{
		c = 0;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
def main():
    mod = 1000000007
    n, k = (int(x) for x in input().split())
    l = (i for i in range(n + 1))  # おまけの小さい部分，でも大事

    # 累積和を計算しておく，前からと後ろから。
    former = 0
    acm = tuple((former:= former + i) for i in range(n + 1))
    former = 0
    acm_rev = tuple((former:= former + i) for i in range(n, -1, -1))

    ans = 0
    # 選ぶ数の数で分ける。でかい部分は無視して，
    # 最小値と最大値が分かれば取りうる値も分かる。
    for j in range(k-1, n + 1):
        ans += acm_rev[j] - acm[j] + 1
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 30164
#include<bits/stdc++.h>
using namespace std;
long long a,b,n,x,ans,t;
int main(){
    cin>>n>>x;
    cin>>a;
    if(a>x) ans+=a-x,a=x;
    for(int i=2;i<=n;i++)
    {
    	cin>>b;
    	if(a+b>x)t=a+b-x,ans+=t,
    	b=b>=t?b-t:0;
    	a=b;
    	
    }
    cout<<ans;

	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    ll H;
    cin >> H;

    ll ans = 0;
    ll cur = 1;
    while(H > 0) {
        ans += cur;
        cur *= 2;
        H /= 2;
    }
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 256
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
li.sort()
lin = list(accumulate(li))
if lin[-1] %10 != 0:
    print(lin[-1])
    exit()
else:
    for i in li:
        if i % 10 == 0:
            continue
        print(lin[-1]-i)
        exit()
print(0)


Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = []
start = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            start.append([i, j])
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
while start:
    check = deepcopy(dist)
    q = [start.pop()]
    check[q[0][0]][q[0][1]] = True
    q[0] = tuple(q[0])
    cnt = -1
    while q:
        cnt += 1
        qq = []
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans = max(ans, cnt)
else:
    print(ans)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> w(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
    w[i] += w[i - 1];
  }
  const long long infty = 4e18;
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, infty));
  vector<vector<int>> md(n + 1, vector<int>(n + 1));
  for (int l = 0; l + 1 <= n; l++) {
    int r = l + 1;
    dp[l][r] = 0;
    md[l][r] = l;
  }
  for (int d = 2; d <= n; d++) {
    for (int l = 0; l + d <= n; l++) {
      int r = l + d;
      for (int m = md[l][r - 1]; m <= md[l + 1][r]; m++) {
        long long tmp = dp[l][m] + dp[m][r] + w[r] - w[l];
        if (tmp < dp[l][r]) {
          dp[l][r] = tmp;
          md[l][r] = m;
        }
      }
    }
  }
  cout << dp[0][n] << '\n';
  return 0;
}


Measured memory_bytes: 190804