akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define _GLIBCXX_DEBUG
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    int K,S;cin >> K >> S;
    int count = 0;
    rep(i, K+1) {
        rep(j, K+1) {
            if(S - i - j < 0) continue;
            if(S - i - j <= K) count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<vector<bool> > matrixProduct(const vector<vector<bool> >& x, const vector<vector<bool> >& y)
{
    int n = x.size();
    vector<bitset<101> > bs1(n), bs2(n);
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            bs1[i][j] = x[i][j];
            bs2[j][i] = y[i][j];
        }
    }
    vector<vector<bool> > ret(n, vector<bool>(n, false));
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            ret[i][j] = (bs1[i] & bs2[j]).any();
        }
    }
    return ret;
}

vector<vector<bool> > matrixPower(const vector<vector<bool> >& x, int k)
{
    int n = x.size();
    vector<vector<bool> > y(n, vector<bool>(n, false));
    for(int i=0; i<n; ++i)
        y[i][i] = true;

    vector<vector<bool> > z = x;
    while(k > 0){
        if(k & 1)
            y = matrixProduct(y, z);
        z = matrixProduct(z, z);
        k >>= 1;
    }
    return y;
}


int main()
{
    for(;;){
        int n, m, z;
        cin >> n >> m >> z;
        if(n == 0)
            return 0;

        vector<vector<bool> > graph(n, vector<bool>(n, false));
        int size = 2*m+1;
        vector<int> curr(size);
        vector<int> prev(size);
        for(int i=0; i<m; ++i){
            int s, d;
            cin >> s >> d;
            graph[s-1][d-1] = graph[d-1][s-1] = true;
            curr[2*i+1] = s-1;
            prev[2*i+1] = d-1;
            curr[2*i+2] = d-1;
            prev[2*i+2] = s-1;
        }
        curr[0] = 0;
        prev[0] = -1;

        vector<vector<bool> > x(size, vector<bool>(size, false));
        for(int i=0; i<size; ++i){
            for(int j=0; j<size; ++j){
                if(graph[curr[i]][curr[j]] && curr[i] == prev[j] && prev[i] != curr[j])
                    x[i][j] = true;
            }
        }

        x = matrixPower(x, z);

        bool ok = false;
        for(int i=0; i<size; ++i){
            if(x[0][i] && curr[i] == n-1)
                ok = true;
        }

        if(ok)
            cout << "yes" << endl;
        else
             cout << "no" << endl;
    }
}

Measured memory_bytes: 920
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[100];
int main(){
	int n,cnt=0;scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	for (int i=0;i<n;i++){
		int minj=i;
		for (int j=i;j<n;j++) if (A[minj]>A[j]) minj=j;
		if (minj!=i){
			swap(A[i],A[minj]);
			cnt++;	
		}
	}
	for (int i=0;i<n;i++){
		printf("%d",A[i]);
		if (i==n-1) printf("\n");
		else printf(" ");
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int,int> pr;
#define N 1000002
signed main()
{
    SPEED;
  	int n;
  	cin>>n;
  	int l[n],h[n];
  	for(int i=0;i<n;++i)
    {
      cin>>l[i]>>h[i];
    }
    sort(l,l+n);
    sort(h,h+n);
  	if(n%2)
    {
      	cout<<h[n/2]-l[n/2]+1;
    }
  	else
    {
      cout<<h[n/2]+h[n/2-1]+1-l[n/2]-l[n/2-1];
    }
}
  

Measured memory_bytes: 6740
/******************************************
* AUTHOR : AMAN SAXENA *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

template <typename TYPE> void in(TYPE &x){cin>>x;}

void solve()
{
    ll n;
    cin >> n;
    string ans="";
    while(n>0)
    {
        n--;
        ans += 'a' + n%26;
        n/=26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // test();
    solve();
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN (100005);
#if !testing
	#define cerr if(0)cout
#endif

int32_t main() {
	IAMSPEED
	string s; cin >> s;
	sort(all(s));
	if (s=="abc") cout << "Yes";
	else cout << "No";
}


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

// utility
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))

#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define F first
#define S second

char s[11];

signed main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<long long> a(n);
    REP(i, n)
    cin >> a[i];

    long long num = 1;

    REP(i, n)
    if (a[i] == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    REP(i, n)
    {

        if (a[i] <= 1000000000000000000 / num)
        {
            num *= a[i];
        }
        else
        {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>
#include<stdlib.h>



struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)return u;
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  /* if(z->left==NIL || z->right ==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y.parent.left){
    y.parent.left=x;
  }
  else{
    y.parent.right=x;
  }
  if(y!=z){
  z->key=y->key;*/
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if (z->key < y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
  
  return;
}

void inorder(Node u){
  if(u->left!=NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL)  inorder(u->right);
  

}
void preorder(Node u){
printf(" %d",u->key);
if(u->left!=NIL) preorder(u->left);
if(u->right!=NIL)  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      
      }*/
  }

  return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18


void solve()
{
   int a;
   cin>>a;
   cout<<a+(a*a)+(a*a*a)<<endl;
}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //int t; cin>>t; while(t--) solve();
    solve();

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}

int main(){
	//ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n;
	//cout << "asa" << endl;
	cin >> n;
	int m[1000001]={};
	bool b=false;
	int count=0;
	
	while(1){
		m[n]++;
		count++;
		//cout << n << endl;
		REP(i,1000001){
			if(m[i]==2){
				cout << count << endl;
				b=true;
			}
		}
		if(n%2==0) n/=2;
		else n=(n*3)+1;
		if(b) break;
	}
/////////////////////////////////////////////
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool allsame(string x)
{
      set<char> s1;
      for(int i=0;i<x.size();i++)
      s1.insert(x[i]);
      
      if(s1.size()==1)
      return true;
      
      return false;
}
int main()
{
       int n;
       cin>>n;
       
       if(allsame(to_string(n)))
       cout<<n<<endl;
       else
       {
             string ans;
             for(int i=n;i<=999;i++)
             {
                   if(allsame(to_string(i)))
                   {
                         ans=to_string(i);
                         break;
                   }
             }
             cout<<ans<<endl;
       }
}

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

int main(){

	int A[3][3];

	int mark = 1000;

	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			scanf("%d",&A[i][j]);
		}
	}

	int N;

	scanf("%d",&N);	

	int b[N];

	for(int i=0; i<N; i++){
		scanf("%d",&b[i]);
	}

	for(int k =0; k<N; k++){
		for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
				// printf("A[%d][%d] = %d\n",i,j,A[i][j]);
				if(A[i][j] == b[k]){
					A[i][j] = mark;
					break;
				}
			}
		}
	}

	for(int i=0; i<3; i++){
		if(A[i][0] == mark && A[i][1] == mark && A[i][2] == mark){
			printf("Yes\n");
			return 0;
		}
	}

	for(int i=0; i<3; i++){
		if(A[0][i] == mark && A[1][i] == mark && A[2][i] == mark){
			printf("Yes\n");
			return 0;
		}
	}

	if(A[0][0] == mark && A[1][1] == mark && A[2][2] == mark){
		printf("Yes\n");
		return 0;
	}

	if(A[0][2] == mark && A[1][1] == mark && A[2][0] == mark){
		printf("Yes\n");
		return 0;
	}

	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<string.h>

int main(void) {
	char str[10];
	scanf("%s\n", str);
	if (strcmp(str, "ABC") == 0) {
		printf("ARC\n");
	}
	else {
		printf("ABC\n");
	}
	return 0;

}

Measured memory_bytes: 3764
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
sum_num=sum(a)
cnt=Counter(a)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    sum_num+=(c-b)*cnt[b]
    print(sum_num)
    cnt[c]+=cnt[b]
    cnt[b]=0

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

using namespace std;

# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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 unsigned long long int ullint;

#define M_DEBUG if (1)

/******************************************************************************
	Main
******************************************************************************/
int main()
{
	lint n = 0, k = 0;
	cin >> n >> k;
	assert(n >= 0 && n <= pow(10, 18));	
	assert(k >= 1 && n <= pow(10, 18));
	
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}

	lint x = (n > k)? n % k: k - n;
	while (x < n) {
		n = x;
		x = (n - k > 0)? n - k: -(n - k);
	}
	cout << n << endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  HW := NextIntVec()
  H := HW[0]
  W := HW[1]
  A := make([]string, H)
  C := make([]int, 26)
  for i := range A {
    A[i] = NextLine()
    for j := 0; j < W; j++ {
      C[int(A[i][j]) - 97] += 1
    }
  }
  W1 := (H % 2) * (W % 2)
  W2 := (H / 2) * (W % 2) + (H % 2) * (W / 2)
  W4 := (H / 2) * (W / 2)
  for i := 0; i < 26; i++ {
    k4 := C[i] / 4
    if W4 < k4 { k4 = W4 }
    W4 -= k4
    C[i] -= 4 * k4
    k2 := C[i] / 2
    if W2 < k2 { k2 = W2 }
    W2 -= k2
    C[i] -= 2 * k2
    k1 := C[i]
    if W1 < k1 { k1 = W1 }
    W1 -= k1
    C[i] -= k1
  }
  ans := "Yes"
  if W4 > 0 || W2 > 0 || W1 > 0 { ans = "No" }
  Write(ans)
  Output()
}

Measured memory_bytes: 640
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    a = kwargs["a"]
    b = kwargs["b"]
    c = kwargs["c"]
    d = kwargs["d"]

    res = 'No'

    while True:
        if res == 'No':
            c -= b
            res = 'Yes'

            if c <= 0:
                break
        else:
            a -= d
            res = 'No'

            if a <= 0:
                break

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["a"], kwargs["b"], kwargs["c"], kwargs["d"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31168
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	LL a, b;
	cin >> a >> b;
	if (a == 1 or b == 1) cout << 1 << endl;
	else cout << (a * b + 1) / 2 << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<iomanip>
#include<cassert>
#include<functional>
typedef long long ll;

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

	int input;
	int waru;
	int divisor_counter;
	int ans_counter = 0;

	std::cin >> input;

	for (int i = 1; i <= input; i++){
		if (i % 2 == 0){//偶数のとき飛ばす
			continue;
		}
		waru = 1;//初期化
		divisor_counter = 0;//初期化
		while (waru <= i){
			if (i % waru == 0){//割り切れるとき
				divisor_counter++;
			}
			waru++;
		}

		if (divisor_counter == 8){//約数が8個のとき
			ans_counter++;
		}
	}

	std::cout << ans_counter << '\n';

	return 0;
}

Measured memory_bytes: 256
a, v = map(int,input().split())
b, w = map(int,input().split())
t = int(input())

if a > b:
    v = -v
    if w > 0:
        w = -w
if a < b and  w < 0:
    w = -w



A = t * v + a
B = t * w + b

if A > B:
    if  a < b:
        print("YES")
    else:
        print("NO")
elif A == B:
    print("YES")
elif A < B :
    if a < b:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 9124
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not x==y: # 根が同じでない場合のみ併合する
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x] # 要素数を併合
                self.par[x] = y # 根を付け替えている
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
        
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) 

def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    from collections import defaultdict,deque
    G = defaultdict(list)
    D = []
    for i in range(N-1):
        a, b = map(int,input().split())
        D.append([a,b])
        G[a].append(b)
        G[b].append(a)
    
    que = deque()
    que.append(1)
    visited = {}
    oya = [-1]*(10**5+1)
    while que != deque():
        v = que.pop()
        visited[v] = 1
        if v == N:
            break
        else:
            for i in G[v]:
                if not i in visited:
                    oya[i] = v
                    que.append(i)
    now = N
    path = []
    while now != -1:
        path.append(now)
        now = oya[now]
    path = path[::-1]
    #print(path)
    L = len(path)
    if L%2==0:
        d1,d2 = path[L//2-1],path[L//2]
    else:
        d1,d2 = path[L//2],path[L//2+1]
    G2 = UnionFind(N)
    
    for i in D:
        a,b = i
        if not {a,b} == {d1,d2}:
            G2.union(a,b)
    one = -G2.par[G2.find(1)]
    enu = -G2.par[G2.find(N)]
    
    if one>enu:
        print("Fennec")
    else:
        print("Snuke")
    

main()

Measured memory_bytes: 50208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
		if(S.length() + 1 == T.length()) {
			
			String TS = T.substring(0,S.length());
			if(TS.equals (S)) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
			
		}else {
			System.out.println("No");
		}

}
}

Measured memory_bytes: 26940
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  int N,count=0;
  cin >> N;
  int A[N],B[N];

  for(int i=1;i<N+1;i++){
    cin >> A[i];
    B[A[i]] = i;
  }
  
  for(int i=1;i<N+1;i++){
  cout << B[i] << " " ;
  }
  cout << endl;
}


Measured memory_bytes: 1536
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
  int n, ans = 0; cin >> n;
  map <int, int> ms;
  for(int i = 1; i <= n; i++) {
     int x; cin >> x;
     ans += ms[(x-i)];
     ms[-x-i]++;
  }
  cout << ans << '\n';
}   

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}    


Measured memory_bytes: 26360
while True:
    a, op, b = input().split()   
    a =int(a)                   
    b = int(b)                   


    if op=="?": 
        break
    else:    
            if op=="+":
                print(a+b)
            elif op=="-":
                print(a-b)
            elif op=="*":
                print(a*b)
            elif op=="/":
                print(a//b)


Measured memory_bytes: 5596
#include<iostream>
#include<set>
#include<vector>
using namespace std;
#define ll long long

class P {
public:
  ll L, R, C;
  P(ll _L, ll _R, ll _C): L(_L),R(_R),C(_C) {}
};

struct cmp_L { bool operator()(const P x, const P y) const { return x.L < y.L; } } Cmp_L;
struct cmp_R { bool operator()(const P x, const P y) const { return x.R < y.R; } } Cmp_R;
struct cmp_C { bool operator()(const P x, const P y) const { return x.C < y.C; } } Cmp_C;

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

  multiset<P, cmp_L> Plist;
  multiset<P, cmp_C> Qlist;
  for(ll m=0; m<M; ++m) {
    ll L, R, C;
    cin >> L >> R >> C;
    P p(L,R,C);
    Plist.insert(p);
  }

  ll i=1;
  vector<ll> D(N+1);
  D[1]=0;

  while(i<N){
    {
      auto ip = Plist.begin();
      for(; ip!=Plist.end() && (ip->L)<=i; ++ip){
        P q(*ip);
        q.C += D[q.L];
        Qlist.insert(q);
      }
      Plist.erase(Plist.begin(), ip);
    }

    for(auto itr = Qlist.begin(); itr!=Qlist.end(); ++itr){
      if(itr->R>i) break;
      Qlist.erase(itr);
    }

    if(Qlist.size()==0){ cout << -1 << endl; return 0; }
    
    auto qq = Qlist.begin();
    for(ll r=i+1; r<qq->R+1; ++r){
      D[r] = qq->C;
    }
    i = qq->R;
  }

  cout << D[N]<<endl;

  return 0;
}


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

const int N = 2e4 + 10;

int p[N], a[N], b[N];

int main(){
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&p[i]);
	for (int i = 1; i <= n; i++){
		a[i] = i * n;
		b[i] = (n - i + 1) * n;
	} 
	for (int i = 1; i <= n; i++) b[p[i]] -= n - i;
	for (int i = 1; i <= n; i++){
		printf("%d", a[i]);
		if (i < n) printf(" ");
		else printf("\n");
	}
	for (int i = 1; i <= n; i++){
		printf("%d", b[i]);
		if (i < n) printf(" ");
		else printf("\n");
	}
	return 0;
}

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

void input(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int dfs(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnMoneyCnt)
{
  const vector<int> cnvnMoney{10000, 5000, 1000};

  if (nTrgSu == 0 && nTrgKin == 0) return  1;
  if (nTrgKin <  0)                return -1;
  if (nPos == rvnMoneyCnt.size())  return  0;

  if (nPos == rvnMoneyCnt.size() - 1)
  {
    rvnMoneyCnt[nPos] = nTrgSu;
    return dfs(nPos + 1, 0, nTrgKin - cnvnMoney[nPos] * nTrgSu, rvnMoneyCnt);
  }
  else
    for (int i = 0; i <= nTrgSu; i++)
    {
      rvnMoneyCnt[nPos] = i;
      for (int i = nPos + 1; i < rvnMoneyCnt.size(); i++)
        rvnMoneyCnt[i] = 0;

      int nReslt = dfs(nPos + 1, nTrgSu - i, nTrgKin - cnvnMoney[nPos] * i, rvnMoneyCnt);
      if      (nReslt ==  1)  return 1;
      else if (nReslt == -1)  break;
    }

  return 0;
}

void searchCntl(int nTrgSu, int nTrgKin)
{
  vector<int> vnMoneyCnt(3);

  if ( dfs(0, nTrgSu, nTrgKin, vnMoneyCnt) )
  {
    for (int i = 0; i < vnMoneyCnt.size(); i++)
    {
      if ( i )  cout << " ";
      cout << vnMoneyCnt[i];
    }
    cout << endl;
  }
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  input(nTrgSu, nTrgKin);
  searchCntl(nTrgSu, nTrgKin);

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);

template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<T, T> > > & G){     
  using Pa = pair<T, T>;
  vector<T> D(100010,LINF);//----------------
  priority_queue<Pa,vector<Pa>,greater<Pa> > q;
  D[s]=0;
  q.emplace(D[s],s);//最短距離、ゴール頂点番号

  while(!q.empty()){
    T spath=q.top().first;
    int v=q.top().second;
    q.pop();

    if(D[v]<spath) continue;
    for(auto& e:G[v]){
      int u=e.first;//頂点番号
      T c=e.second;//最短距離
      if(D[u]>D[v]+c){
        D[u]=D[v]+c;
        q.emplace(D[u],u);
      }
    }
  }
  return D;
}

signed main(){
    ll nv,ne;cin>>nv>>ne;
    ll s,g;cin>>s>>g;
    s--;g--;

    vector<vector<PL>> ea(nv,vector<PL>(0)),eb(nv,vector<PL>(0));
    vector<ll> ans(nv,LINF);

    rep(i,0,ne){
        ll u,v,a,b;cin>>u>>v>>a>>b;
        u--;v--;
        ea[u].pb({v,a});
        ea[v].pb({u,a});
        eb[u].pb({v,b});
        eb[v].pb({u,b});
    }

    rep(i,0,nv){
        ea[i].pb({i,0});
        eb[i].pb({i,0});
    }

    vector<ll> froms=dijkstra(s,ea),fromg=dijkstra(g,eb);
    ans[nv-1]=froms[nv-1]+fromg[nv-1];
    for(int i=nv-2;0<=i;i--)
    {
        ans[i]=min(ans[i+1],froms[i]+fromg[i]);
    }

    rep(i,0,nv){
        cout<<(ll)1e15-ans[i]<<endl;
    }
}

Measured memory_bytes: 26112
INF = float('inf')
N = int(input())
h = list(map(int, input().split()))

dp = [INF for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    cost1 = dp[i-1] + abs(h[i] - h[i-1])
    cost2 = dp[i-2] + abs(h[i] - h[i-2])
    dp[i] = min(cost1, cost2)

print(dp[N-1])


Measured memory_bytes: 13928
import numpy as np

N = int(input())
P = map(float, input().split())

dp = np.zeros(N+1, dtype=float)
dp[0] = 1

for p in P:
  ndp = dp*(1-p)
  ndp[1:] += dp[:-1]*p
  dp = ndp

print(np.sum(dp[N//2+1:]))

Measured memory_bytes: 14540
import math
N,M = map(int,input().split())
if abs(N-M) > 1:
    print(0)
    exit()

fac = 1
num = 10**9 + 7
for i in range(1,N+1):
    fac *= i
    if fac > num:
        fac %= num

fac2 = 1
for i in range(1,M+1):
    fac2 *= i
    if fac2 > num:
        fac2 %= num

if N == M:
    print(fac**2*2%num)
else:
    print(fac*fac2%num)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}


ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
vector<vector<ll>>to, cost;
ll dist[101010];
bool flag[101010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll a, b;
	cin >> a >> b;
	ll ans = (3 * a + b) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  int depth;
  struct node *parent;
  struct node *left;
  struct node *right;
};
typedef struct node *Node;
int degree(Node);

void calcDepth(Node T,int p){
  T->depth = p;
  if(T->right!=NULL) calcDepth(T->right,p+1);
  if(T->left!=NULL) calcDepth(T->left,p+1);
}

int height(Node T){
  int kr=0,kl=0;
    if(T->right!=NULL) kr=height(T->right)+1;
  if(T->left!=NULL) kl=height(T->left)+1;
  if(kr>=kl) return kr;
  else return kl;
}

int main(){
  struct node T[25];
  int n;
  int i;
  int id,leftid,rightid;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NULL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&leftid,&rightid);
    T[id].key=id;
    if(leftid>=0){
      T[id].left=&T[leftid];
    T[leftid].parent=&T[id];
    }
    else T[id].left=NULL;
    if(rightid>=0){
      T[id].right=&T[rightid];
    T[rightid].parent=&T[id];
    }
    else T[id].right=NULL;
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NULL) calcDepth(&T[i],0);
    }
  
  for(i=0;i<n;i++){
    printf("node %d: ",T[i].key);
     if(T[i].parent==NULL) printf("parent = -1, ");
       else printf("parent = %d, ",T[i].parent->key);
   printf("sibling = ");
    if(T[i].parent==NULL || T[i].parent->left==NULL || T[i].parent->right==NULL) printf("-1, ");
     else if(T[i].parent->left->key==T[i].key) printf("%d, ",T[i].parent->right->key);
    else printf("%d, ",T[i].parent->left->key);
    printf("degree = %d, ",degree(&T[i]));
    printf("depth = %d, ",T[i].depth);
     printf("height = %d, ",height(&T[i]));
    if(T[i].parent==NULL) printf("root");
     else if(T[i].right==NULL && T[i].left==NULL) printf("leaf");
     else printf("internal node");
    printf("\n");
  }
  return 0;
  }

int degree(Node T){
  int d=0;
  if(T->left!=NULL) d++;
  if(T->right!=NULL) d++;
  return d;
}



Measured memory_bytes: 2104
N = int(input())
A = list(map(int, input().split()))
import collections

count = 0

count_dict = collections.defaultdict(int)

for idx, a in enumerate(A):
    count_dict[idx-a] += 1

for idx, a in enumerate(A):
    if idx+a in count_dict:
        count += count_dict[idx+a]
        continue
    # for i in range(idx+a+1, N):
    #     if a + A[i] == i - idx:
    #         count += 1
    #         count_dict[idx+a+1] += 1
# print(count_dict)

print(count)

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

#define ll long long
#define pb push_back
#define f first
#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>

using namespace std;

const int maxn = 132675;
const int INF = (int)1e9;

ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;

ll x[maxn],y[maxn],x2[maxn],y2[maxn];

bool m;

vector <int> v;

void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}

string s, ans;

ll pref;

//vector <int> g[maxn],d[maxn];

ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/

map <char, bool> mp;

char ch;

int main()
{
	cin >> a >> c >> d >> l;
	if(a <= c){
		cout << a * d;
		return 0;
	}
	cout << c * d + (a - c) * l;
	gg;
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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



int main(){
  string s; cin >> s; ll x = s.size();
  
  deque<char> arraychar;
  
  rep(i,x){
    if(s[i] == '0') arraychar.push_back('0');
    else if(s[i] == '1') arraychar.push_back('1');
    
    else if(s[i] == 'B' && !arraychar.empty()){
      arraychar.pop_back();
    }
  }
  
  while(!arraychar.empty()){
    cout << arraychar.front();
    arraychar.pop_front();
  }
  
  cout << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    int ans;
    if(N%2){
        int mx = B[N/2], mn = A[N/2];
        ans = mx-mn+1;
    }else{
        int mx = B[N/2-1] + B[N/2];
        int mn = A[N/2-1] + A[N/2];
        ans = mx-mn+1; 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4788
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int a, p;
    cin >> a >> p;
    cout << ((a * 3) + p) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[101];
	int charCount = 0, hugCount = 0;
	int i = 0;

	scanf("%s", s);

	/* 文字列の文字数を数える */
	charCount = strlen(s);

	/* 対称の位置にある文字同士を比較するので、ループは文字数の半分の回数 */
	for (i = 0; i < charCount / 2; i++)
	{
		/* 対称の位置にある文字が異なるとき、文字を変える必要がある */
		if (s[i] != s[charCount - 1 - i])
		{
			hugCount++;
		}
	}

	printf("%d\n", hugCount);

	return 0;
}

Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int D[2001];
int E[4001], ne[4001], he[2001];
void dfs(int v, int d) {
	D[v] = d;
	for (int to = he[v]; to; to = ne[to]) {
		if (D[E[to]] < 0) dfs(E[to], d + 1);
	}
}
int d, k;
int dfs2(int v, int prev) {
	int ret = 1;
	d++;
	for (int to = he[v]; to; to = ne[to]) {
		if (E[to] != prev && d <= k) ret += dfs2(E[to], v);
	}
	d--;
	return ret;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	N = getint();
	K = getint();
	k = K / 2;
	int tmp = 1;
	int jisuu[2001] = {};
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[tmp] = b;
		ne[tmp] = he[a];
		he[a] = tmp++;
		E[tmp] = a;
		ne[tmp] = he[b];
		he[b] = tmp++;
		jisuu[a]++;
		jisuu[b]++;
	}

	if (K == 1) {
		printf("%d\n", N - 2);
		return 0;
	}

	rep1(j, N) D[j] = -1;
	dfs(1, 0);
	int saidai = 0;
	int doko, doko2;
	rep1(i, N) if (saidai < D[i]) {
		saidai = D[i];
		doko = i;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko, 0);
	saidai = 0;
	bool muri[2001] = {};
	rep1(i, N) {
		if (saidai < D[i]) {
			saidai = D[i];
			doko2 = i;
		}
		if (D[i] < k) {
			muri[i] = 1;
		}
	}
	if (saidai <= K) {
		printf("0\n");
		return 0;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko2, 0);
	rep1(i, N) {
		if (D[i] < k) muri[i] = 1;
		if (jisuu[i] == 1) muri[i] = 1;
	}

	if (K % 2 == 0) {
		int kotae = N;
		rep1(i, N) {
			if (!muri[i]) {
				int kazu = dfs2(i, -1);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}
	else {
		int kotae = N;
		rep1(z, N - 1) {
			int i = E[z * 2];
			int j = E[z * 2 - 1];
			if (!muri[i] && !muri[j]) {
				int kazu = dfs2(i, j) + dfs2(j, i);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

#define MAX 0
#define MIN 1

signed main(){

	string l;
	cin>>l;

	lli dp[2][100100]={0};

	dp[MAX][0]=2;
	dp[MIN][0]=1;

	for(lli i=1;i<l.size();i++){
		if(DEBUG)cout<<"i="<<i<<endl;
		if(l.at(i)=='0'){
			dp[MAX][i]=dp[MAX][i-1];
			dp[MIN][i]=dp[MIN][i-1]*3;
			dp[MIN][i]%=MOD;
		}
		else{
			dp[MAX][i]=dp[MAX][i-1]*2%MOD;
			dp[MIN][i]+=dp[MIN][i-1]*3;
			dp[MIN][i]%=MOD;
			dp[MIN][i]+=dp[MAX][i-1];
			dp[MIN][i]%=MOD;
		}
		if(DEBUG)cout<<"dpMAX="<<dp[MAX][i]<<" dpMIN="<<dp[MIN][i]<<endl;
	}

	cout<<(dp[MAX][l.size()-1]+dp[MIN][l.size()-1])%MOD<<endl;

	return 0;
}

Measured memory_bytes: 2048
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N - 2):
    if (P[i + 1] < P[i] and P[i + 1] > P[i + 2]) or (P[i + 1] > P[i] and P[i + 1] < P[i + 2]):
        res += 1
print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<vector<char>> a(H);
  std::set<int> row;
  std::set<int> col;
  rep(i, H)
  {
    a[i].resize(W);
    bool white = true;
    rep(j, W)
    {
      cin >> a[i][j];
      if (a[i][j] != '.')
      {
        white = false;
      }
    }
    if (white)
      row.insert(i);
  }

  rep(j, W)
  {
    bool white = true;
    rep(i, H)
    {
      if (a[i][j] != '.')
      {
        white = false;
      }
    }

    if (white)
      col.insert(j);
  }

  rep(i, H)
  {
    if (row.find(i) != row.end())
    {
      continue;
    }
    rep(j, W)
    {
      if (col.find(j) != col.end())
      {
        continue;
      }
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pie (3.141592653589)
using namespace std;

const int N = 2e5 + 10;

long long mul(long long a, long long b)
{
	return (a * b) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	long long n;
	cin >> n;
	long long sol = 1;
	long long no = 2;
	long long both = 1;
	for(int i = 1; i <= n; i++)
	{
		sol = mul(sol, 10);
		no = mul(no, 9);
		both = mul(both, 8);
	}
	sol = sol - no + both;
	while(sol < 0)
		sol += mod;
	cout << sol << "\n";
	
	return 0;
}


Measured memory_bytes: 3644
#![allow(unused)]

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let avec: Vec<i64> = (0..n).map(|_| sc.get()).collect();
    let edges: Vec<(usize, usize)> =
        (0..(n - 1)).map(|_| (sc.get(), sc.get())).collect();

    let mut g = vec![vec![]; n];
    for (u, v) in edges {
        g[u - 1].push(v - 1);
        g[v - 1].push(u - 1);
    }

    let mut lens = vec![0; n];
    let mut dp = vec![];
    let mut visited = vec![false; n];
    let mut frontiers = vec![vec![0]];
    let mut rollback = vec![];

    while !frontiers.is_empty() {
        if let Some(u) = frontiers.last_mut().unwrap().pop() {
            if !visited[u] {
                visited[u] = true;
                frontiers.push(g[u].clone());

                let i = dp.binary_search(&avec[u]).unwrap_or_else(|i| i);
                if i >= dp.len() {
                    dp.push(std::i64::MAX);
                }
                rollback.push((i, dp[i]));
                dp[i] = avec[u];
                lens[u] = dp.len();
            }
        } else {
            frontiers.pop();
            if !frontiers.is_empty() {
                let (i, val) = rollback.pop().unwrap();
                if val == std::i64::MAX {
                    dp.pop();
                } else {
                    dp[i] = val;
                }
            }
        }
    }

    for u in 0..n {
        println!("{}", lens[u]);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        if let Some(t) = self.iter.next() {
            return t.parse().ok().expect("Parse error")
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get()
    }

    fn gets<T: std::iter::FromIterator<char>>(&mut self) -> T {
        use std::io::Read;
        assert_eq!(self.iter.next(), None);
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|&c| c.is_whitespace())
            .take_while(|&c| !c.is_whitespace())
            .collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}



Measured memory_bytes: 32348
package main

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

var (
	sc = bufio.NewReader(os.Stdin)
)

func main() {
	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}

	s := 0
	cur := A[0]
	for i := 1; i < N; i++ {
		if A[i] > cur {
			cur = A[i]
			continue
		}
		s += cur - A[i]
	}
	fmt.Println(s)
}

func abs(a int) int         { return int(math.Abs(float64(a))) }
func scan(a ...interface{}) { _, err := fmt.Fscan(sc, a...); pnc(err) }
func scanStr() (s string)   { scan(&s); return }
func scanInt() int          { i, err := strconv.Atoi(scanStr()); pnc(err); return i }
func scanFloat() float64    { f, err := strconv.ParseFloat(scanStr(), 64); pnc(err); return f }
func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 6292
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,h,da=0;
string st;
int main()
{
    cin>>n;
    cin>>st;
    for(int i=0;i<st.size();i++)
    {
        if(st[i]=='I')h++;
        else h--;
        if(h>da)da=h;
    }
    cout<<da<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)

int main(){
    string Sp,T;
    bool flag;
    vector<string> S;
    cin >> Sp >> T;
    rep(i,0,Sp.size()-T.size()+1){
        flag = true;
        rep(j,0,T.size()){
            if(Sp[i+j] !='?' &&  Sp[i+j] != T[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            string tmpS = Sp;
            for(int j=0;j<T.size();j++) tmpS[i+j] = T[j];
            S.push_back(tmpS);
        } 
    } 
    if(S.size()!=0){
        rep(i,0,S.size()){rep(j,0,S[i].size()) if(S[i][j]=='?') S[i][j]='a';} 
        sort(S.begin(),S.end());
        cout << S[0] << endl;
    }
    else cout << "UNRESTORABLE" << endl;
}

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

using namespace std;

int main() {

	#ifndef ONLINE_JUDGE
	#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int a, b, c;
	cin >> a >> b >> c;

	if ((a + b + c - 7) / 2 == 5) cout << "YES";
	else cout << "NO";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll t=ceil(1.0*x/d);

    if(t>k)
    {
        cout<<(x-k*d);
    }
    else
    {
        if((k-t)%2==0)
        {
            ;
        }
        else
        {
            t--;

        }
        cout<<(abs(x-t*d));
    }
    return 0;
}


Measured memory_bytes: 3744