akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;

int r,c,q;
int r2,c2;
const int INF=2147483647;
vector<vector<int> > dc,dr;

int init(int k){
	int sz=1;
	while(sz<k)sz*=2;
	return sz;
}

void update(vector<int> &seg,int k,int a){
	k+=(seg.size()/2)-1;
	seg[k]=a;
	while(k>0){
		k=(k-1)/2;
		seg[k]=min(seg[k*2+1],seg[k*2+2]);
	}
}

int query(vector<int> &seg,int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return INF;
	if(a<=l && r<=b)return seg[k];
	else{
		int vl=query(seg,a,b,k*2+1,l,(l+r)/2);
		int vr=query(seg,a,b,k*2+2,(l+r)/2,r);
		return min(vl,vr);
	}
}

int main(void){
	while(1){
		scanf("%d%d%d",&r,&c,&q);
		if(r==0 && c==0 && q==0)break;
		dc.resize(r);
		dr.resize(c);
		c2=init(c)*2;
		r2=init(r)*2;
		for(int i=0;i<r;i++){
			dc[i].resize(c2);
			fill(dc[i].begin(),dc[i].end(),INF);
		}
		for(int i=0;i<c;i++){
			dr[i].resize(r2);
			fill(dr[i].begin(),dr[i].end(),INF);
		}
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				int a;
				scanf("%d",&a);
				update(dc[i],j,a);
				update(dr[j],i,a);
			}
		}
		for(int i=0;i<q;i++){
			int x,x2,y,y2;
			scanf("%d%d%d%d",&y,&x,&y2,&x2);
			int res=INF;
			if(y2-y<=x2-x){
				for(int i=y;i<=y2;i++){
					res=min(res,query(dc[i],x,x2+1,0,0,dc[i].size()/2));
				}
			}else{
				for(int i=x;i<=x2;i++){
					res=min(res,query(dr[i],y,y2+1,0,0,dr[i].size()/2));
				}
			}
			printf("%d\n",res);
		}
	}
    return 0;
}

Measured memory_bytes: 64008
import sys

# x = abs(int(input()))
# k = int(input())
# d = int(input())

array = list(map(int, input().strip().split()))
x = abs(array[0])
k = array[1]
d = array[2]
if (d == 0):
    amari = abs(x)

else:
    move_cnt = int(x / d)
    if (move_cnt <= k):
        k -= move_cnt
        amari = x - move_cnt * d

    else:
        amari = x - k * d
        k = 0

    if (k > 0):
        if (k % 2 == 1):
            if (amari > 0):
                amari -= d
            else:
                amari += d

print(abs(amari))

Measured memory_bytes: 9140
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,l;
    char s[101],t[101],temp;
    gets(s);
    gets(t);
    l=strlen(s);
    if(strcmp(s,t)==0)
    {
        printf("Yes\n");
        return 0;
    }
    for(i=1;i<l;i++)
    {
        temp=s[0];
        for(j=0;j<l-1;j++)
        {
            s[j]=s[j+1];
        }
        s[j]=temp;
        if(strcmp(s,t)==0)
        {
            printf("Yes\n");
            return 0;
        }
    }
     printf("No\n");
     return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
ll c[51][51];
 
void comb(int n) {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                c[i][j] = 1LL;
            } else {
                c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
            }
 
        }
    }
}
 
 
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    comb(n);
    ll v[n];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v, v + n);
    reverse(v, v + n);
    int maxValueCnt = 0;
    for (int i = 0; i < n; i++) {
        if (v[0] == v[i]) {
            maxValueCnt++;
        } else {
            break;
        }
    }
 
    if (maxValueCnt >= a) {
        int mn = min(maxValueCnt, b);
        ll ans = 0;
        for (int i = a; i <= mn; i++) {
            ans += c[maxValueCnt][i];
        }
        double meanValue = v[0];
        printf("%.10f\n",meanValue);
        printf("%lld\n", ans);
        return 0;
    }
 
    double meanValue = 0;
    for (int i = 0; i < a; i++) {
        meanValue += v[i];
    }
    meanValue /= a;
    ll minValueCnt = 0;
    ll idx;
    for (int i = n - 1; i >= 0; i--) {
        if (v[a - 1] == v[i]) {
            minValueCnt++;
            idx = i;
        }
    }
    printf("%.10f\n", meanValue);
    printf("%lld\n", c[minValueCnt][a - idx]);
 
 
 
    return 0;
}

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

const int MAX = 1e6+1;

void solve(){
    char str[3]; scanf("%s", &str);

    if(str[0] == str[1] && str[1] == str[2] && str[1] == 'R')
        printf("3\n");
    else if((str[0] == str[1] &&  str[0] == 'R')
            || (str[1] == str[2] && str[1] == 'R'))
        printf("2\n");
    else
        if(str[0] == 'R' || str[1] == 'R' || str[2] == 'R')
            printf("1\n");
        else
            printf("0\n");
}

int main()
{
    solve();
    return 0;
}


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

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

typedef long long int LLI;
typedef unsigned long long int LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<int> vi;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

LLI t[57];

int32_t main()
{
	LLI x; scanf("%lld", &x);
	int sz = 50;
	printf("%d\n", sz);
	LLI dod = x / sz;
	LLI r = x % sz;
	int ind = 0;
	for(int i = 0; i < sz; ++i)
		t[i] = sz - 1 + dod + (i < r ? sz - r : 0);
	for(int i = r; i < sz; ++i)
		t[i] -= r;
	for(int i = 0; i < sz; ++i)
		printf("%lld ", t[i]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsze 555
#define endl '\n'
#define sz(v) v.size()
#define flush fflush(stdout)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

int main(){
    fast;
    ll a,b;
    cin>>a>>b;
    if(a>12)    cout<<b;
    else if(a<=12 && a>=6)  cout<<b/2;
    else    cout<<0;    
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string st;
    cin >> st;
    vector<int> b;
    vector<int> arr(st.size(),0);
    FOR(i,1,st.size())
    {
        if(st[i-1]=='R' && st[i]=='L')
            b.pb(i);
    }
    int ind=0;
    F0R(i,st.size())
    {
        if(i==0 || st[i]!='R' || st[i-1]!='L')
        {
            if((b[ind]-i)%2)
                arr[b[ind]-1]++;
            else
                arr[b[ind]]++;
        }
        else
        {
            ind++;
            if((b[ind]-i)%2)
                arr[b[ind]-1]++;
            else
                arr[b[ind]]++;
        }
    }
    F0R(i,arr.size())
        cout << arr[i] << " ";

    return 0;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	int A = max(H, W);

	cout << (N + A - 1) / A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

//ll chk[55];
//ll num[55];
//ll num2[55];
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<long long int> pq;   //big at front
//stack<int> stk;
//vector<pair<ll,ll>> vint;
//vector<ll> vtime;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;

ll gcd(ll,ll);

int main()
{
    //double ans=0.0,half;
    //float f,g,h;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    //string s,s1;
    //char now,pre,c;
    cin>>n>>a1;
    for(i=1;i<n;i++)
    {
        cin>>a;
        a1=gcd(a1,a);
    }
    cout<<a1;
    return 0;
}

ll gcd(ll m,ll n)
{
    if(n==0) return m;
    return gcd(n,m%n);
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    String T = scanner.next();
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    String U = scanner.next();
    
    if(S.equals(U)){
      a--;
    }else{
      b--;
    }
    System.out.println(a + " " + b);
    
  }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
string arrstr;
int memoL[MAXN];
int n;
int dfsL(int idx){
	//cerr<<idx<<endl;
	//cerr<<arrstr[idx-1]<<endl;
	if(idx<=0)return -1;
	if(arrstr[idx]=='R'){dfsL(idx-1);
	return -1;
	}
	if(arrstr[idx-1]=='R'){
		dfsL(idx-2);
		return memoL[idx]=0;}
	else return memoL[idx]=dfsL(idx-1)+1;
}
int memoR[MAXN];
int dfsR(int idx){
	if(idx>=n-1)return -1;
	if(arrstr[idx]=='L'){
		dfsR(idx+1);
		return -1;
	}
	if(arrstr[idx+1]=='L'){
		dfsR(idx+2);
		
		return memoR[idx]=0;}
	else {
		
		return memoR[idx]=dfsR(idx+1)+1;}
}
int main(){
	cin>>arrstr;
	n=(int)arrstr.size();
	memset(memoL,-1,sizeof(memoL));
	
	dfsL(n-1);
	//cerr<<"endL"<<endl;
	memset(memoR,-1,sizeof(memoR));
	dfsR(0);
	int res[n];
	memset(res,0,sizeof(res));
	
	
	for(int i=0;i<n;i++){
		//cerr<<i<<endl;
		if(memoL[i]!=-1){
			if(memoL[i]%2==0){
				res[i-memoL[i]]++;
			}else res[i-memoL[i]-1]++;
		}else if(memoR[i]!=-1){
			if(memoR[i]%2==0){
				res[i+memoR[i]]++;
			}else res[i+memoR[i]+1]++;
		}else assert(0);
	}
	for(int i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<res[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 6144
class Node:
    def __init__(self, key, pri):
        self.key = key
        self.pri = pri
        self.left  = None
        self.right = None


def rRotate(t):
    s       = t.left
    t.left  = s.right
    s.right = t

    return s


def lRotate(t):
    s       = t.right
    t.right = s.left
    s.left  = t

    return s


def insert(t, key, pri):
    if t == None: return Node(key, pri)

    if key == t.key: return t

    if key < t.key:
        t.left = insert(t.left , key, pri)
        if t.pri < t.left.pri : t = rRotate(t)

    else:
        t.right = insert(t.right, key, pri)
        if t.pri < t.right.pri: t = lRotate(t)

    return t


def delete(t, key):
    if   t == None:
        return None
    if   key < t.key:
        t.left  = delete(t.left , key)
    elif key > t.key:
        t.right = delete(t.right, key)
    else:
        return _delete(t, key)
    return t


def _delete(t, key):
    if t.left == None and t.right == None:
        return None
    elif t.left  == None:
        t = lRotate(t)
    elif t.right == None:
        t = rRotate(t)
    else:
        if t.left.pri > t.right.pri:
            t = rRotate(t)
        else:
            t = lRotate(t)
    return delete(t, key)


def find(t, key):
    if(t == None): return False
    if(t.key == key): return True
    if(t.key >  key): return find(t.left , key)
    else            : return find(t.right, key)

def preorder(t):
    if(t == None): return

    print('', t.key, end='')
    preorder(t.left )
    preorder(t.right)


def inorder(t):
    if(t == None): return

    inorder(t.left )
    print('', t.key, end='')
    inorder(t.right)


if __name__ == '__main__':
    n = int(input())
    top = None

    for _ in range(n):
        strs = input().split()

        op  = strs[0]
        if op != 'print':
            key = int(strs[1])
            if op == 'insert':
                pri = int(strs[2])

        if op == 'insert': top = insert(top, key, pri)
        if op == 'delete': top = delete(top, key)
        if op == 'find'  :
            if find(top, key): print('yes')
            else           : print('no' )
        if op == 'print' :
            inorder(top)
            print()
            preorder(top)
            print()



Measured memory_bytes: 52328
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
// int a[N];
int main(){
    int a,b;
    cin >> a >> b;
    for(int i=1;i<=10000;++i){
        if(i*8/100 == a && i/10 == b){
            cout << i<<'\n';
            return 0;
        }
        // cout << i*8/100 << ' ' << i/10 << '\n';
    }
    cout <<"-1\n";




    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


vector<P> bomb;
vector<P> edge[220000];
Int onecnt[220000];
vector<Int> ans;
bool come[110000];

void dfs(Int x){
    come[x] = true;
    onecnt[x] += bomb[x].second;
    for(auto p:edge[x]){
        Int to =p.first;
        Int ind =p.second;
        if(come[to])continue;
        dfs(to);
        onecnt[x] += onecnt[to];
        if(onecnt[to] % 2)ans.push_back(ind);
    }
//    cout << x << ": " << onecnt[x] << endl;
}



int main(){
    Int n, m;
    cin >> n >> m;
    for(Int i = 0;i < n;i++){
        Int a, b;
        cin >> a >> b;
        bomb.emplace_back(a, b);
    }
    bomb.push_back(P(LINF, 0));
    n++;
    sort(bomb.begin(), bomb.end());
    for(Int i = n-1;i > 0;i--){
        bomb[i].second ^= bomb[i-1].second;
    }

    for(Int i = 0;i < m;i++){
        Int l, r;
        cin >> l >> r;
        Int lind = lower_bound(bomb.begin(), bomb.end(), P(l, 0)) - bomb.begin();
        Int rind = upper_bound(bomb.begin(), bomb.end(), P(r, 1)) - bomb.begin();
        edge[lind].push_back(P(rind, i));
        edge[rind].push_back(P(lind, i));
//        cout << lind << " " << rind << endl;
    }

    for(Int i = 0;i < n;i++){
        if(come[i])continue;
        dfs(i);
        if(onecnt[i] % 2){
            cout << -1 << endl;
            return 0;
        }
    }

    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for(Int c:ans){
        cout << c+1 << " ";
    }cout << endl;
    
    return 0;
}

Measured memory_bytes: 24048
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  ll N;
  cin >> N;
  ll T, A;
  cin >> T >> A;
  N--;
  while (N > 0) {
    ll t, a;
    cin >> t >> a;
    N--;
    T = max(T, t), A = max(A, a);
    if (T % t != 0) {
      T += t - T % t;
    }
    if (A % a != 0) {
      A += a - A % a;
    }
    if (t == a) {
      T = max(A, T);
      A = max(A, T);
      continue;
    }
    if (t < a) {
      ll tmp = T / t * a;
      if (A <= tmp) {
        A = tmp;
      } else {
        tmp = A / a * t;
        T = tmp;
      }
    } else {
      ll tmp = A / a * t;
      if (T <= tmp) {
        T = tmp;
      } else {
        tmp = T / t * a;
        A = tmp;
      }
    }
   // cout << "         " << T << " " << A << endl;
  }
  cout << T + A << endl;
}

Measured memory_bytes: 3628
<?php

$N = trim(fgets(STDIN));
$S = trim(fgets(STDIN));
$S_ar = str_split($S);
$count = 0;
for($i=0; $i<$N; $i++){
    if($S_ar[$i] != 'A') continue;
    if(!isset($S_ar[$i+1]) || $S_ar[$i+1] != 'B') continue;
    if(!isset($S_ar[$i+2]) || $S_ar[$i+2] != 'C') continue;
    $count++;
}
echo $count;

?>

Measured memory_bytes: 4604
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String t=sc.next();
    final char[] S=s.toCharArray();
    final char[] T=t.toCharArray();
    int counter=0;
    for(int i=0;i<3;i++){
      if(S[i]==T[i]){
        counter++;
      }
    }
    System.out.println(counter);
  }
}

Measured memory_bytes: 22484
<?php  
list($n, $k) = explode(' ', trim(fgets(STDIN))); 
$s = trim(fgets(STDIN));  
$split = str_split($s);
foreach($split as $index => &$char){
if($index == $k - 1){
 $char = strtolower($char);
}
}
  printf(implode('', $split));

?>

Measured memory_bytes: 4728
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
cur = 0
cnt = [0 for _ in range(n+1)]
fill_cur = 0
ans = []
residual = []
for i in range(n*n):
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		fill_cur = max(fill_cur, cur)
		if cur == n:
			break
	elif fill_cur < n:
		while cnt[s[fill_cur][1]] == s[fill_cur][1]-1:
			fill_cur += 1
			if fill_cur == n:
				if not residual:
					print("No")
					sys.exit()
				ans.append(residual.pop())
				break
		else:
			fill_cur = max(fill_cur, cur)
			ans.append(s[fill_cur][1])
			cnt[s[fill_cur][1]] += 1
	elif not residual:
		print("No")
		sys.exit()
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

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

long long i,j,n,m,k;

/*int main(){
    int x, ans = INT_MAX;
    bool ok = false;
    cin >> n >> m >> x;
    long long c[n][m];
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> c[i][j];
        }
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> c[i][j];
        }
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){

        }
    }
}*/

int main() {
    long long a, b, c, ans = 0;
    cin >> a >> b >> c >> k;
    if(a >= k) cout << k << endl;
    else if(k >= a && k <= a+b) cout << a << endl;
    else cout << a-(k-a-b) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pInt pair<int, int>

struct asc {
	bool operator() (const pInt &x, const pInt &y) const {
		return x.second > y.second;
	}
};

priority_queue <pInt, vector<pInt>, asc> pq;
int dijkstra(int *cost, int terminal, int n, vector<vector<int> > vc) {
	while(!pq.empty()) {
		pInt p = pq.top();
		pq.pop();
		rep(i,n) {
			if(vc[p.first][i] != -1) {
				int total = p.second + vc[p.first][i];
				if(total < cost[i]) {
					pq.push(make_pair(i,total));
					cost[i] = total;
				}
			}
		}
	}
	return cost[terminal];
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int> > vc(n); 
	rep(i,n) {
		vector<int> va(n);
		vc[i] = va;
		rep(j,n) {
			vc[i][j] = -1;
		}
	}
	rep(i,m) {
		int s, t, c1, c2;
		scanf("%d,%d,%d,%d", &s, &t, &c1, &c2);
		vc[--s][--t] = c1;
		vc[t][s] = c2;
	}
	int s, g, a, b;
	scanf("%d,%d,%d,%d", &s, &g, &a, &b);
	--s, --g;
	int cost[20] = {};

	rep(i,n) {
		if(i==s)cost[i] = 0;
		else cost[i] = INT_MAX;
	}
	pq.push(make_pair(s,0));
	int ret = 0;
	ret += dijkstra(cost, g, n, vc);

	rep(i,n) {
		if(i==g)cost[i] = 0;
		else cost[i] = INT_MAX;
	}
	pq.push(make_pair(g,0));
	ret += dijkstra(cost, s, n, vc);

	cout << a - b - ret << endl;
	return 0;
}

Measured memory_bytes: 1260
#include <stdio.h>

int main(void){
  double n, t, x1, x2, count=0;
  int i;

  scanf("%lf %lf", &n, &t);
  scanf("%lf", &x1);

  for(i=0;i<n-1;i++){
    x2=x1;
    scanf("%lf", &x1);
    if(x1-x2>=t)
    count+=t;
    else
    count+=x1-x2;
  }
  count+=t;
  printf("%d\n", (int)count);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

class Main {
    public static void main(String[] args) throws Exception {
        Map<Integer, Long> G = new HashMap<Integer, Long>();
        Map<Integer, Integer> V = new HashMap<Integer, Integer>();
        final Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Pair[] d = new Pair[N+1];
        int[] n = new int[N+1];
        long[] m = new long[N+1];
        int i = 0, flag = 0;
        for(i = 1 ; i <= N ; i++){
            G.put(i, sc.nextLong());
            n[i] = 1;
        }
        G = G.entrySet().stream()
        .sorted(Entry.<Integer, Long>comparingByValue().reversed())
        .collect(Collectors.toMap(Entry::getKey,Entry::getValue,(e1, e2)->e1,LinkedHashMap::new));
        i = 1;
        for (int key : G.keySet()){
            d[i] = new Pair(key, G.get(key));
            i++;
        }
        for(i = 1 ; i < N ; i++){
            flag = 0;
            for(int j = i+1 ; j <= N ; j++){
                if(d[i].b-(long)N+(long)(2*n[i]) == d[j].b){
                    n[j] += n[i];
                    m[j] += n[i]+m[i];
                    V.put(d[i].a, d[j].a);
                    flag = 1;
                    break;
                }
            }
            if(flag == 0){
                System.out.println("-1");
                System.exit(0);
            }
        }
        if(m[N]!=d[N].b){
            System.out.println("-1");
            System.exit(0);
        }
        for (Integer key : V.keySet()) {
            System.out.println(key + " " + V.get(key));
        }
    }

    static class Pair implements Comparable<Pair> {
        int a;
        long b;
        Pair(int a,long b) {
            this.a = a;
            this.b = b;
        }    
        @Override
        public int compareTo(Pair o) {
            return Long.compare(a, o.b);
        }
    }
}

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

int main()
{
    int n = 5;
    vector<int> A(n, 0);
    for( auto&& a : A)
        cin >> a;
    int k = 0;
    cin >> k;
    bool flag = true;

    for (int i = 0; i< n; ++i){
        for (int j = i + 1; j < n; ++j){
            if( A[j] - A[i] > k){
                flag = false;
            }
        }
    }

    if (flag){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

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

  vector<int> w(110);
  vector<int> v(110);
  rep(i,N){
    cin >> w.at(i)>> v.at(i);
  }


  vector<vector<ll>> dp(110,vector<ll>(100010,0));

  for(int i = 0;i < N;i++){
    for(int sumw = 0;sumw <= W;sumw++){
      if(sumw >= w[i]){
        dp[i+1][sumw] = max(dp[i+1][sumw],dp[i][sumw-w[i]]+v[i]);
      }
      dp[i+1][sumw] = max(dp[i+1][sumw],dp[i][sumw]);
    }
  }
  cout << dp[N][W] << endl;

}


Measured memory_bytes: 87296
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    cin>>n;
    bool p[1001];
    REP(i,1001)p[i]=true;
    p[0]=p[1]=false;
    for(int i=2;i<=n;i++){
        if(p[i]){
            for(int j=i*2;j<=n;j+=i){
                p[j]=false;
            }
        }
    }
    long long cnt[1001];
    memset(cnt,0,sizeof(cnt));
    for(int i=2;i<=n;i++){
        if(!p[i])continue;
        for(int j=i;j<=n;j+=i){
            int jj=j;
            while(jj%i==0){
                cnt[i]++;
                jj/=i;
            }
        }
    }
    long long ans=1;
    long long mod=1e9+7;
    for(int i=2;i<=n;i++){
        if(!p[i])continue;
        ans=(ans*(cnt[i]+1))%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind
{
    vector<int> par, rank;
    UnionFind(int n) : par(n), rank(n)
    {
        for (int i = 0; i < n; ++i)
            par[i] = i;
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x), ry = root(y);
        if (rx == ry)
            return;
        if (rank[ry] > rank[rx])
            par[rx] = ry;
        else
            par[ry] = rx;
        if (rank[rx] == rank[ry])
            rank[rx]++;
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
};

vector<ll> fac, inv, finv;

void initcom()
{
    fac = inv = finv = vector<ll>(1e6);
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (ll i = 2; i < 1e6; ++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;
    }
}

ll com(int n, int k)
{
    if (n < 0 || k < 0)
        return 0;
    if (n < k)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll x, ll y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}
ll mopow(ll a, ll x, ll mod)
{
    ll res = 1;
    while (x > 0)
    {
        if (x & 1)
            res = res * a % mod;
        a = a * a % mod;
        x >>= 1;
    }
    return res;
}

int main(){
    ll n,k;cin>>n>>k;
    vector<vector<int>> next(60,vector<int>(n));
    for(int i=0;i<n;++i) cin>>next[0][i],--next[0][i];
    for(int d=0;d+1<60;++d){
        for(int i=0;i<n;++i){
            next[d+1][i]=next[d][next[d][i]];
        }
    }
    int v=0;
    for(int d=0;d<60;++d){
        if(k&(1LL<<d)) v=next[d][v];
    }
    cout<<v+1<<endl;
    return 0;
}

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

#define int long long
typedef pair<int,int> PII;

signed main(){
	int n,a,b;
	cin>>n>>a>>b;

	if(n<a+b){
		cout<< min(a,b)<<' '<<a+b-n<<endl;
	}else
		cout<<min(a,b)<<' '<<0<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

char s[222];
int n;
bool lc[222],rc[222];
int dp[222][222][2];

int f(int l,int r,int flag){
  if(l+1==r)return s[l]-'0'; // num
  if(dp[l][r][flag]!=-INF-1)return dp[l][r][flag];

  int res=flag?INF:-INF;
  repl(i,l,r){
    if(s[i]!='+'&&s[i]!='-')continue;
    if((lc[i]&&i-2>=l)||(rc[i]&&i+2<r))continue;
    int op=s[i]=='+'?+1:-1;
    int lnum=f(l,i,flag),rnum=f(i+1,r,op==+1?flag:1-flag);
    if(!flag)maxch(res,lnum+op*rnum);
    else minch(res,lnum+op*rnum);
  }
  return dp[l][r][flag]=res;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>s;
  n=strlen(s);
  rep(i,222)rep(j,222)rep(k,2)dp[i][j][k]=-INF-1;
  rep(i,n){
    if(i-2>=0&&(s[i]=='+'||s[i]=='-')&&s[i-2]=='(')lc[i]=true;
    if(i+2<n&&(s[i]=='+'||s[i]=='-')&&s[i+2]==')')rc[i]=true;
  }
  rep(i,n){
    if(s[i]=='('||s[i]==')')s[i]=0;
  }
  rep(i,n){
    if(s[i]!=0)continue;
    repl(j,i,n){
      if(s[j]==0)continue;
      s[i]=s[j];
      lc[i]=lc[j];
      rc[i]=rc[j];
      s[j]=0;
      break;
    }
  }
  n=strlen(s);
  cout<<f(0,n,0)<<endl;
	return 0;
}

Measured memory_bytes: 3548
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

beats = list()
count = 0
for i in range(n):
    beat = min(Bs[i], As[i])
    count += beat
    Bs[i] -= beat
    As[i] -= beat

    beat = min(Bs[i], As[i + 1])
    count += beat
    Bs[i] -= beat
    As[i + 1] -= beat

    # print(As)
    # print(Bs)
    
print(count)
# print(beats)

# if As[n] > Bs[n - 1]:
#     beat = Bs[n - 1]
# else:
#     beat = As[n]


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class BinaryIndexTree
{
public:
    BinaryIndexTree(int n)
        : mN(n)
    {
        mPow = 1;
        while (mPow < n)
            mPow <<= 1;
        node.resize(n + 1);
        REP(i, n + 1)
        {
            node[i] = 0;
        }
    }
    ~BinaryIndexTree()
    {
        node.resize(0);
    }

    //! 1-index get
    ll sum(int index)
    {
        ll sum = 0;
        for (int i = index; i > 0; i -= i & (-i))
            sum += node[i];
        return sum;
    }

    //! 1-index add
    void add(int index, ll value)
    {
        for (int i = index; i <= mN; i += i & (-i))
            node[i] += value;
    }

    int lowerBound(ll value)
    {
        if (value <= 0)
            return 0;
        int x = 0;
        for (int k = mPow; k > 0; k >>= 1)
        {
            if (x + k <= mN && node[x + k] < value)
            {
                value -= node[x + k];
                x += k;
            }
        }
        return x + 1;
    }

private:
    vector<ll> node;
    ll mN;
    ll mPow;
};

ll R, C, N;
struct Line
{
    pll a;
    pll b;
};

ll length(pll g)
{
    //! (0,0)からの距離
    if (g.second == 0)
        return g.first;
    if (g.first == R)
        return R + g.second;
    if (g.second == C)
        return R + C + (R - g.first);
    return R + C + R + (C - g.second);
}

bool onEdge(pll g)
{
    if (g.first == 0 || g.first == R)
        return true;
    if (g.second == 0 || g.second == C)
        return true;
    return false;
}

int main()
{
    cin >> R >> C >> N;
    vector<Line> L;
    vector<ll> S;
    REP(i, N)
    {
        pll a, b;
        cin >> a.first >> a.second >> b.first >> b.second;
        if (!onEdge(a) || !onEdge(b))
            continue;
        Line l;
        ll la = length(a), lb = length(b);
        if (la < lb)
        {
            l.a = a;
            l.b = b;
        }
        else
        {
            l.a = b;
            l.b = a;
        }
        L.push_back(l);
        S.push_back(la);
        S.push_back(lb);
    }
    sort(L.begin(), L.end(), [](Line a, Line b) { return length(a.a) < length(b.a); });

    BinaryIndexTree bit(S.size());
    sort(S.begin(), S.end());
    bool f = true;
    REP(i, L.size())
    {
        ll la = length(L[i].a);
        ll lb = length(L[i].b);
        int ia = lower_bound(S.begin(), S.end(), la) - S.begin();
        int ib = lower_bound(S.begin(), S.end(), lb) - S.begin();
        int num = bit.sum(ib) - bit.sum(ia);
        //cout<<bit.sum(ib)<<" "<<bit.sum(ia)<<endl;
        if (num > 0)
            f = false;
        bit.add(ib, 1);
    }
    if (f)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 8432
#include<stdio.h>

int main()
{
    int S,h,m,s;
    int rest;
    scanf("%d",&S);
    h=S/3600;
    rest=S-h*3600;
    m=rest/60;
    rest=rest-m*60;
    s=rest;
    printf("%d:%d:%d\n",h ,m ,s);
    return 0;
}


Measured memory_bytes: 2768
#include <iostream>
#include <bits/stdc++.h>
#define scan(n)      scanf("%I64d",&n);
#define scan2(a,b)   scanf("%I64d%I64d",&a,&b);
#define scan3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c);
#define sc(n)        scanf("%c",&n);
#define sf(n)        scanf("%lf",&n);
#define ss(n)        scanf("%s",n);
#define forall(i,a,b)for(long long int i=a;i<b;i++)
#define all(a)       a.begin(), a.end()
#define pb           push_back
#define mp           make_pair
#define FAST_IO      ios_base::sync_with_stdio(false); cin.tie(NULL);
#define minimum(a)   *min_element(a.begin(),a.end())
#define maximum(a)   *max_element(a.begin(), a.end())
#define display(a)   for(auto i : a) cout<<i<<" ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<ll> scanVector(ll n, vector<ll> &v)
{
  ll temp;
  for(ll i = 0; i < n ; i++)
  {
     cin>>temp;
     v.pb(temp);
  }
  return v;
}

int main() {
    FAST_IO
    ll t;
    //cin>>t;
    t = 1;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<double> p;
        double temp;
        for(ll i = 0; i < n ; i++)
        {
            cin>>temp;
            p.push_back(temp);
        }
        vector<double> q;
        for(ll i = 0; i < p.size(); i++)
        {
            q.push_back(1-p[i]);
        }
        double dp[n+1][n+1];
        dp[1][0] = q[0];
        for(ll i = 0; i <= n ; i++)
        {
            for(ll j = 0; j <= n ; j++)
            {
                if(i == 0)
                {
                    if(i == 0 && j == 0) dp[i][j] = 1;
                    else dp[i][j] = 0;
                }
                else if(j == 0)
                {
                    dp[i][j] = (double)dp[i-1][j] * (double)q[i-1];
                }
                else
                {
                    dp[i][j] = ((double)q[i-1]*((double)dp[i-1][j])) + ((double)p[i-1] * ((double)dp[i-1][j-1]));    
                }
            }
        }
        // for(ll i = 0; i <= n ; i++)
        // {
        //     for(ll j = 0; j <=n ; j++)
        //     {
        //         cout<<dp[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        double res = 0;
        for(ll i = float((double)n/2)+1; i <= n ; i++)
        {
            res += dp[n][i];
        }
        cout<<std::setprecision(10)<< res<<endl;
    }
    return 0;
}

Measured memory_bytes: 70656
/* ***********************************************
Author        :yang12138
Created Time  :2017/11/12 23:55:28
File Name     :E.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int V=205;
const ll INF=1e13;

struct Edge{
	int to,rev;
	ll cap;
	Edge(){}
	Edge(int to,ll cap,int rev){
		this->to=to;
		this->cap=cap;
		this->rev=rev;
	}
};
vector<Edge>G[V];
int iter[V],level[V];

void add_edge(int u,int v,ll w){
	G[u].push_back(Edge(v,w,(int)G[v].size()));
	G[v].push_back(Edge(u,0,(int)G[u].size()-1));
}

queue<int>que;
void bfs(int s){
	mem(level,-1);
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<(int)G[v].size();i++){
			Edge& e=G[v][i];
			if(level[e.to]<0 && e.cap>0) level[e.to]=level[v]+1,que.push(e.to);
		}
	}
}

ll dfs(int s,int t,ll f){
	if(s==t) return f;

	for(int& i=iter[s];i<(int)G[s].size();i++){
		Edge& e=G[s][i];
		if(level[s]<level[e.to] && e.cap>0){
			ll d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d,G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s,int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		mem(iter,0);
		while(1){
			ll f=dfs(s,t,INF);
			if(f==0LL) break;
			flow+=f;
		}
	}
}

void solve(){
	int n;
	cin>>n;
	int s=0,t=n+1;
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll x;
		cin>>x;
		if(x<0) add_edge(s,i,-x);
		else add_edge(i,t,x),ans+=x;
		for(int j=2*i;j<=n;j+=i) add_edge(i,j,INF);
	}
	cout<<ans-max_flow(s,t)<<endl;
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


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

int main(){
    int n, m, x;
    int custo1 = 0, custo2 = 0;
    cin >> n >> m >> x;
    int square[m+1];
    int rua[n];
    for(int i = 1; i<=m; i++){
        cin>>square[i];
        rua[square[i]] = 1;
    }
    for(int i = x; i<n; i++){
        if (rua[i]==1 and i!=x){
            custo1++;
        }
    }
    for(int i = x; i>0; i--){
        if  (rua[i]==1 and i!=x){
            custo2++;
        }

    }
    cout << min(custo1, custo2);
}


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

bool includeNum(int fig, std::vector<int> S){
	int left = 0;
	int right = S.size();
	int center;

	while(right>left){
		center = (right+left)/2;
		if(S[center]<fig){
			left = center + 1;
		}else if(S[center]>fig){
			right = center;
		}else{
			return true;
		}
	}

	return false;
}

int main(int argc, char const *argv[]){

	int N,fig;
	int cnt = 0;

	std::vector<int> S;
	std::cin >> N;
	for (int i = 0; i < N; ++i){
		std::cin >> fig;
		S.push_back(fig);
	}
	std::cin >> N;
	for (int i = 0; i < N; ++i){
		std::cin >> fig;
		if(includeNum(fig,S)) cnt++;
	}

	std::cout << cnt << std::endl;
	return 0;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  int M;
  cin >> M;

  int sum = 0;
  for ( int i = 0; i < N; i++ ) {
    int a;
    cin >> a;
    sum += a;    
  }

  int ans = 0;
  for ( int i = 0; i < M; i++ ) {
    int b;
    cin >> b;
    ans += b*sum;
  }

  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i=0; i<(int)c; i++)
long long kougeki(long long);
long long kougeki(long long t){
	if (t==1){
		return 1;
	}
	else{
		return kougeki(t/2)*2+1;
	}
}
int main() {
	long long h,a;

	cin >>h;

	a=kougeki(h);
	cout <<a<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll n;
bool f=false;
V Log;
VV graph;
ll NG1;
ll NG2;
V have;
void dfs(ll now,ll prev){
    if(now==n-1){
        Log.push_back(now);
        f=true;
        return;
    }
    for(auto i:graph[now]){
        if(i==prev){
            continue;
        }
        dfs(i,now);
        if(f){
            Log.push_back(now);
            return;
        }
    }
}
void dfs2(ll now,ll prev){
    have[now]=true;
    for(auto i:graph[now]){
        if((now==NG1&&i==NG2)||(now==NG2&&i==NG1)){
            continue;
        }
        if(i==prev){
            continue;
        }
        dfs2(i,now);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    graph.resize(n);
    have.resize(n,false);
    rep(i,n-1){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    dfs(0,-1);
    reverse(all(Log));
    ll k=Log.size();
    k=(k-1)/2;
    NG1=Log[k];
    NG2=Log[k+1];
    dfs2(0,-1);
    ll res=0;
    for(auto i:have){
        if(i){
            res++;
        }
    }
    if(res*2<=n){
        cout<<"Snuke"<<endl;
    }else{
        cout<<"Fennec"<<endl;
    }
    return 0;
}


Measured memory_bytes: 12408
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    set<int> s;
    for(int i=1;i<n;++i){
      s.insert((i*i)%n);
    }
    vector<int> v(s.size());
    int p=0;
    for(set<int>::iterator it=s.begin();it!=s.end();++it)v[p++]=*it;
    vector<int> hist((n-1)/2+1);
    for(int i=0;i<v.size();++i){
      for(int j=v.size()-1;j>i;--j){
        int d=v[i]-v[j];
        //cerr<<v[i]<<" "<<v[j]<<endl;
        d=(d<0)?d+n:d;
        d=(d>(n-1)/2)?n-d:d;
        ++hist[d];
      }
    }
    for(int i=1;i<=(n-1)/2;++i){
      cout<<hist[i]*2<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1472
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


int n;
string s;

int powmod(int a, int b, int c = MOD){
    int ans = 1;
    while(b){
        if(b&1){
            ans = (ans*a)%c;
        }
        a = (a*a)%c;
        b >>= 1;
    }
    return ans;
}

int getmod(int mo){
    int cur = 1;
    int ans = 0;
    if(mo == 0)
        return 0;
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            ans += cur;
            ans %= mo;
        }
        cur = cur * 2;
        cur %= mo;
    }
    return ans;
}

int play(int x){
    int v = 1;
    while(x != 0){
        v++;
        int b = __builtin_popcountl(x);
        x = x % b;
    }
    return v;
}

void solve(){
    cin>>n;
    cin>>s;
    reverse(all(s));
    int sb = 0;
    For(i, 0, sz(s)){
        if(s[i]=='1')
            sb++;
    }
    if(sb == 0){
        For(i, 0, n){
            cout<<1<<"\n";
        }
        return;
    }
    int m1 = getmod(sb-1);
    int m2 = getmod(sb+1);

    vector<int> ans;

    For(i, 0, n){
        if(s[i]=='1'){
            int b = sb - 1;
            if(b == 0){
                ans.pb(0);
                continue;
            }
            int x = b - powmod(2, i, b);
            int cur = (m1 + x) % b;
            ans.pb(play(cur));
        }
        else{
            int b = sb + 1;
            int x = powmod(2, i, b);
            int cur = (m2 + x) % b;
            ans.pb(play(cur));
        }
    }
    reverse(all(ans));
    for(int v: ans){
        cout<<v<<"\n";
    }
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 5508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NMX = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M, X) = (NMX[0], NMX[1], NMX[2]);

        var C = new int[N];
        var A = new int[N][];

        for (int i = 0; i < N; i++)
        {   
            var CA = ReadLine().Split(' ').Select(s => int.Parse(s));
            C[i] = CA.First();
            A[i] = CA.Skip(1).ToArray();
        }

        var minCost = int.MaxValue;

        for (int pattern = 0; pattern < (1 << N); pattern++)
        {
            var cost = 0;
            var a = new int[M];

            for (int i = 0; i < N; i++)
            {
                if (((pattern >> i) & 1) == 1)
                {
                    cost += C[i];

                    for (int j = 0; j < M; j++)
                    {
                        a[j] += A[i][j];
                    }
                }
            }

            var clear = true;
            for (int j = 0; j < M; j++)
            {
                if (a[j] < X)
                {
                    clear = false;
                }
            }

            if (clear)
            {
                minCost = Math.Min(minCost, cost);
            }
        }

        var ans = (minCost == int.MaxValue) ? -1 : minCost;

        WriteLine(ans);
    }
}


Measured memory_bytes: 28600
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,x,a[maxn],F;

int main()
{
	n=read(); x=read(); rep(i,1,n) a[i]=read(); sort(a+1,a+n+1);
	ll tmp=0;
	rep(i,1,n)
	{
		tmp+=a[i];
		if(tmp==x) {F=1; cout<<i<<endl; break;}
		else if(tmp>x) {F=1; cout<<i-1<<endl; break;}
	}
	if(!F) cout<<n-1<<endl;
	return 0;
}

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

int main(){
  string w,T;
  int a=0;
  
  cin>>w;
  
  while(1){
    cin>>T;

    int b=T.size();

    for(int i=0;i<b;i++){
      if(T!="END_OF_TEXT") T[i]=tolower(T[i]);
    }
    
    if(w==T) a++;
    if(T=="END_OF_TEXT") break;
  }
  cout<<a<<endl;
  return 0;
  
}



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

bool isInteger(double num) {
    if(floor(num) == ceil(num)) return true;
    else return false;
}

double distance(int y[], int z[], int d) {
    double dx[d];
    double dist = 0;
    for(int i = 0; i < d; i++) {
        dx[i] = y[i] - z[i];
        dist += dx[i] * dx[i];
    }
    dist = sqrt(dist);
    return dist;
}

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];

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

    int count = 0;
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            double dist;
            dist = distance(x[i], x[j], d);
            if(isInteger(dist)) count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256