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


int main(){
    ll n;
    cin >> n;
    string ans;
    while(n){
        n--;
        ans.push_back((char)('a'+n%26));
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  int count=0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) ;
    if((i+1)%2==1 && A.at(i) %2==1)
      count++;
  }
  cout<<count<<endl;
   
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

int j;
char s[101],g[2] = {'C','F'};
int main(){
	gets(s);
	for(int i = 0;i < strlen(s);i++){
		if(s[i] == g[j])
			j++;
		if(j == 2){
			printf("Yes\n");
			return 0;
		}	
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int month,day;

  int sum,day_w;
  int month_y[12]={31,29,31,30,31,30,31,31,30,31,30,31};

  int i;

  while(1) {

    scanf("%d %d",&month,&day);

    if(month==0 || day==0) break;

    sum=0;

    for(i=0;i<month-1;i++) {

      sum+=month_y[i];

    }

    sum+=day;

    day_w=sum%7;

    switch(day_w) {

    case 0:
      printf("Wednesday\n");
      break;

    case 1:
      printf("Thursday\n");
      break;

    case 2:
      printf("Friday\n");
      break;

    case 3:
      printf("Saturday\n");
      break;

    case 4:
      printf("Sunday\n");
      break;

    case 5:
      printf("Monday\n");
      break;

    case 6:
      printf("Tuesday\n");
      break;

    }

  }

  return 0;

}
      

Measured memory_bytes: 0
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

type Request struct {
	Start int
	End int
}
 
type Requests []Request
 
func (r Requests) Remove(i int) {
	if i == len(r)-1 {
		r = r[:i]
	} else {
		r = append(r[:i], r[i+1:]...)
	}
}
 
func (r Requests) Len() int{
	return len(r)
}
 
func (r Requests) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}
 
type ByStart struct {
	Requests
}
 
func (b ByStart) Less(i, j int) bool {
	return b.Requests[i].Start < b.Requests[j].Start
}
 
type ByEnd struct {
	Requests
}
 
func (b ByEnd) Less(i, j int) bool {
	return b.Requests[i].End < b.Requests[j].End
}

func main() {
	// sc.Buffer(buf, 1000000009)
	var N, M, ans int 
	fmt.Scan(&N, &M)
	requests := make(Requests, M)
	ans = 1
	for i:=0; i<M; i++ {
		ab := scanIntSplit(2)
		requests[i] = Request{Start : ab[0], End : ab[1]}
	}
	be := ByEnd{requests}
	sort.Sort(be)
	end := be.Requests[0].End
	for i:=1; i<len(be.Requests); i++ {
		req := be.Requests[i]
		if req.Start >= end {
			end = req.End
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 1e9+7
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 1000000007;
const int N = 1e5+5, M = N;
//=========================================

char a[1005][1005];
int dp[1005][1005];
int H, W;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> H >> W;
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j)
            cin >> a[i][j];
    }

    memset(dp, 0, sizeof(dp));
    dp[1][1] = 1;

    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            if((i == 1 && j == 1) || (a[i][j] == '#')) continue;
            dp[i][j] += (dp[i][j - 1] + dp[i - 1][j]) % mod;
            dp[i][j] %= mod;
        }
    }

    cout << dp[H][W] << endl;
    return 0;
}


Measured memory_bytes: 9088
#include <stdio.h>
int main(void){
    int N, i, cnt;
    int A[1000];
    
    scanf("%d", &N);
    cnt = 1;
    
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
        //printf("%d\n", A[i]);
    }
    
    
    
    for(i = 0; i < N; i++){
        if(A[i]%2 == 0){
            if(!(A[i]%3 == 0 || A[i]%5 == 0)){
                cnt = cnt - 1;
                //printf("  %d\n", cnt);
            }
        }
    }
    
    if(cnt <= 0){
        printf("DENIED");
    }else{
        printf("APPROVED");
    }
    
}


Measured memory_bytes: 1740
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()

def solve():
    if S == 'AAA' or S == 'BBB':
        return 'No'
    return 'Yes'

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3952
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define for0(i,n) for (int i=0; i<n; i++)
#define forr(i,n) for (int i=n-1; i>=0; i--)
#define fori(i,a,b) for (int i=a; i<=b; i++)
#define iter(c,x) for(x::iterator it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define size(x) (int)(x).size()
#define read(x) int x; scanf("%d",&x);
#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<size(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 999999999;
const long long INFL = 99999999999999999LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll A[500005], cur_dist[500005], min_unreach[500005];

int main()
{
    #ifdef DEBUG
    freopen("C.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    read(n);
    read(init_dist);
    for0(i,n) {
        read(x);
        A[i] = x;
    }

    cur_dist[0] = init_dist;
    for (int i=1; i<n; i++) {
        cur_dist[i] = min(cur_dist[i-1], fabs(cur_dist[i-1]-A[i-1]));
    }
    printa(cur_dist,n+1)

    min_unreach[n] = 1;
    //min_unreach[n-1] = A[n-1] == 1 ? 2 : 1;
    for (int i=n-1; i>=0; i--) {
        min_unreach[i] = A[i] >= 2*min_unreach[i+1] ? min_unreach[i+1] : min_unreach[i+1]+A[i];
    }
    printa(min_unreach,n+1)

    read(q);
    for0(i,q) {
        read(idx);
        idx--;
        if (cur_dist[idx] >= min_unreach[idx+1]) {
            cout<<"YES"<<endl;
        }
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    ll k, a, b;
    cin >> k >> a >> b;

    if (b - a <= 2) {
        cout << k + 1 << "\n";
    }
    else {
        ll ans = a;
        k -= a - 1;
        ans += k / 2 * (b - a) + k % 2;
        cout << ans << "\n";
    }

    return 0;
}

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

int N,K;
ll ans;
int main(){
    cin>>N>>K;
    for(int i=K+1;i<=N;i++){
        ans+=N/i*(i-K)+max(N%i-K+1,0);
    }
    if(K==0)ans-=N;
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 256
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = MAP()

tree = UnionFind(N)
friends = [[] for _ in range(N)]

for _ in range(M):
	A, B = MAP()
	tree.union(A-1, B-1)
	friends[A-1].append(B-1)
	friends[B-1].append(A-1)

blocks = [[] for _ in range(N)]

for _ in range(K):
	C, D = MAP()
	blocks[C-1].append(D-1)
	blocks[D-1].append(C-1)

for i in range(N):
	blocks_cnt = sum([tree.same(i, j) for j in blocks[i]])
	print(tree.size(i) - len(friends[i]) - 1 - blocks_cnt, end=" ")
print()


Measured memory_bytes: 46548
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,h,hp,c;
    cin>>n>>hp;
    c=hp;
    for(ll i=1;i<n;i++){
        cin>>h;
        if(h>hp) c+=h-hp;
        hp=h;
    }
    cout<<c<<endl;
    return 0;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s;cin>>s;
  if(s[s.size()-1]=='3'){
    puts("bon");
  }else if (s[s.size()-1]=='0'||s[s.size()-1]=='1'||s[s.size()-1]=='6'||s[s.size()-1]=='8') {
    puts("pon");
  }else{
  puts("hon")    ;
  }
  
  return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n, K, Res, D[101000];
vector<int>E[101000];
void DFS(int a, int dep){
    int i;
    D[a] = 0;
    for(i=0;i<E[a].size();i++){
        DFS(E[a][i], dep+1);
        D[a] = max(D[E[a][i]]+1, D[a]);
    }
    if(D[a] >= K-1 && dep>1){
        D[a] = -1;
        Res++;
    }
}
int main(){
    int i, a;
    scanf("%d%d",&n,&K);
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        if(i==1){
            if(a!=1)Res++;
            continue;
        }
        E[a].push_back(i);
    }
    DFS(1,0);
    printf("%d\n",Res);
}


Measured memory_bytes: 12416
n = int(input())
m = list(map(int, input().split()))
ms = sorted(m)
m_mid = ms[len(ms) // 2]
m_1mid = ms[len(ms) // 2 - 1]
if m_mid == m_1mid:
    print(0)
else:
    print(m_mid - m_1mid)


Measured memory_bytes: 14428
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#define range(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
int m[110][110];
int p[110];

int matrixChainMultiplication() {
  rep1(i, n) m[i][i] = 0;

  range(l, 2, n) {
    rep1(i, n - l + 1) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      range(k, i, j - 1) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }
  return m[1][n];
}

int main() {
  cin >> n;
  rep1(i, n) {
    cin >> p[i - 1] >> p[i];
  }
  cout << matrixChainMultiplication() << endl;
  return 0;
}



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

int main() {
    int N, M, a, b;
    cin >> N >> M;
    vector<int> c(N, 0);
    rep(i, M) {
        cin >> a >> b;
        c[a - 1]++;
        c[b - 1]++;
    }
    string ans = "YES\n";
    rep(i, N) {
        if (c[i] % 2) ans = "NO\n";
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n,m;
	while (cin >> n >> m && n&&m) {
		vector<int> a(n);
		int maxv = 0;
		for (int i = 0; i < n; ++i) cin >> a[i];
		sort(a.begin(), a.end());
		for (int i = 0; i < n - 1; ++i) {
			for (int j = i + 1; j < n; ++j) {
				if (a[i] + a[j] <= m) maxv = max(maxv, a[i] + a[j]);
				else break;
			}
		}
		if (maxv) cout << maxv << endl;
		else cout << "NONE" << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <utility>

struct UnionFind {
	std::vector<int> par;
	std::vector<int> size;

	UnionFind(int n) : par(n), size(n, 1) {
		for (int i = 0; i < n; ++i)
			par[i] = i;
	}

	int root(int x) {
		return (par[x] == x ? x : par[x] = root(par[x]));
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y)
			return;

		size[x] += size[y];
		par[y] = x;
	}

	bool isSame(int x, int y) {
		return root(x) == root(y);
	}

	int getSize(int x) {
		return size[root(x)];
	}
};

int main() {
	int n, m, k;
	std::cin >> n >> m >> k;

	std::vector<std::pair<int, int>> ff(m);
	UnionFind uf(n);

	for (auto&& p : ff) {
		std::cin >> p.first >> p.second;
		--p.first, --p.second;

		uf.unite(p.first, p.second);
	}

	std::vector<int> cands(n);
	for (int i = 0; i < n; ++i)
		cands[i] = uf.getSize(i) - 1;

	for (auto&& p : ff)
		if (uf.isSame(p.first, p.second))
			--cands[p.first], --cands[p.second];

	for (int i = 0; i < k; ++i) {
		int c, d;
		std::cin >> c >> d;
		--c, --d;

		if (uf.isSame(c, d))
			--cands[c], --cands[d];
	}

	std::cout << cands[0];
	for (int i = 1; i < n; ++i)
		std::cout << ' ' << cands[i];

	std::cout << std::endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
vector< pair<ll,ll> > adj[N];
ll vis[N],dist[N],n,m;
void dfs(ll u,ll d)
{
    if(vis[u]==1)
	{
        if(dist[u]!=d)
		{
            cout<<"No";
            exit(0);
        }
        return;
    }
    vis[u]=1;
    dist[u]=d;
    for(auto node:adj[u])
		dfs(node.first,d+node.second);
}
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0;i<m;i++)
	{
        ll x,y,d;
		cin>>x>>y>>d;
        adj[x].push_back({y,d});
        adj[y].push_back({x,-d});
    }
    for(ll i=1;i<=n;i++)
		if(!vis[i])
			dfs(i,0);
    cout<<"Yes";
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(3*N);
    for(int i = 0; i < 3 * N; ++i) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    long long int ans = 0;
    for(int i = 1; i <= 2 * N - 1; i += 2) {
        ans += a.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    ll ans=0;
    int k,s;cin >>k>>s;
    for (int x = 0; x <=k; ++x) {
        for (int y = 0; y <=k; ++y) {
            int z=s-x-y;
            if(0<=z and z<=k)ans++;
        }
    }
    cout <<ans <<endl;
}


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

struct Node
{
    int key;
    Node *parent,*left,*right;
};
Node *root,*NIL;

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

Node* Find(Node *u,int k)
{
    while(u!=NIL&&k!=u->key)
    {
        if(k<u->key)u=u->left;
        else u=u->right;
    }
    return u;
}

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

void treeDelete(Node *z)
{
    Node *y;
    Node *x;

    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;
    }
    free(y);
}

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

    z=(Node*)malloc(sizeof(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;
        }
    }
}
void inorder(Node *u)
{
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

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

int main()
{
    int n,i,x;
    string com;

    scanf("%d",&n);

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

 	return 0;
}



Measured memory_bytes: 22000
N = int(input())
A = list(map(int, input().split()))
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

gcd_L = [A[0]]
gcd_R = [A[N - 1]]

for i in range(1, N):
    new_gcd_l = gcd(gcd_L[-1], A[i])
    gcd_L.append(new_gcd_l)
    new_gcd_r = gcd(gcd_R[-1], A[N - i - 1])
    gcd_R.append(new_gcd_r)
    
best = gcd_L[N - 1]
for i in range(N):
    if i > 0:
        if i == N - 1:
            a = gcd_L[i - 1]
            if best < a:
                best = a
        else:
            l = gcd_L[i - 1]
            r = gcd_R[N - 2 - i]
            gcd_without_i = gcd(l, r)
            if gcd_without_i > best:
                best = gcd_without_i
    else:
        a = gcd_R[N - 2]
        if a > best:
            best = a

print(best)
    

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

int main () {
	
	long long n, k;
	cin >> n >> k;
	long long x = n / k;
	
	long long ans = min (abs(n - (k * x)), abs(n - (k * (x+1))));
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}



int  H,W,ans,N,A,B,num,T[27],S[27];
string s,t,tt,ss;


int main() {
	cin >> s >> t;
	num = 0;
	for (int j = 'z'; j >= 'a';j--) {
		num++;
		for (int i = 0; i < t.size(); i++) {
			if (t[i] == j) {
				tt += j;
			}
		}
	}
	num = 0;
	for (int j = 'a'; j <= 'z'; j++) {
		num++;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == j) {
				ss += j;

			}
		}
	}


	for (int i = 0; i < max(s.size(), t.size()); i++) {
		if (ss[i] > tt[i]) {
			cout << "No" << endl;
			return 0;
		}
		if (ss[i] < tt[i]) {
			cout << "Yes" << endl;
			return 0;
		}

	}

	if (s.size() >= t.size()) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}


	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
int main(){
    ll h, n, a, check=0;
    cin >> h >> n;
    for(ll i=0;i<n;i++){
        cin >> a;
        check += a;
    }
    if(check<h){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int d,t,s;cin >> d >> t >> s;
    if(d > t*s)puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
#define ll long long int
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for(ll i=0;i<x;i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k"<<endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int main() {
	ll A, B;
	cin >> A >> B;
	cout << lcm(A, B);
}

Measured memory_bytes: 384
N = int(input())
prev_t = 0
now = [0] * 2
for i in range(N):
	t,x,y = map(int,input().split(" "))

	dis = abs(x-now[0]) + abs(y-now[1])
	if (t - prev_t - dis)%2 == 0 and (dis <= t-prev_t):
		now = [x,y]
		prev_t = t
	else:
		print("No")
		exit(0)

print("Yes")




Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll b_pow(ll x,ll n){return n ? n==1 ? x: b_pow(x,n>>1)*b_pow(x,(n>>1)+(n&1)) : 1;}
 
int main(){
    ll z;
    while(cin >> z && z){
        ll ans = 0;
        for(ll x = 1 ; x*x*x <= z*z*z ; x++){
            ll y = pow(z*z*z-x*x*x,1.0/3);
            if(y!=0)ans = max(ans,x*x*x+y*y*y);
        }
        cout << z*z*z-ans << endl;
    }
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxn 1000000000+7


map<int,int>a;
int main()
{
	int n;
	long long ans=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		a[i]=i+1;
	}
	for(int i=2;i<=n;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			while(a[j]%i==0)
			{
				a[j]/=i;
				cnt++;
			}
		}
		ans=(ans*(cnt+1))%1000000007;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    int n;
    cin >> n;
    int a[n];
   	map<int, set<int>> m;
   	bool ok = 0;
   	for(int i = 0; i < n; ++ i){
   		cin >> a[i];
   		m[a[i]].insert(i);
   		ok |= a[i] == 1;
   	}
   	if(!ok){
   		cout << -1 << endl;
   		exit(0);
   	}


   	int idx = *m[1].begin();
   	int cur = 2;
   	while(1){
   		if(m.find(cur) != m.end()){
   			auto zz = m[cur].upper_bound(idx);
   			if(zz != m[cur].end()){
   				idx = *zz;
   				++ cur;
   			}
   			else{
   				break;
   			}
   		}
   		else{
   			break;
   		}
   	}
   	// dbg(cur);
   	cout << n - cur + 1;

    return 0;
}

/*

*/

Measured memory_bytes: 32536
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DCaracalVsMonster {
    ll getCount(ll hp) {
        if (hp == 1) return 1;
        else return 2 * getCount(hp/2) + 1;
    }
public:
    void solve(std::istream& in, std::ostream& out) {
        ll H;
        in >> H;
        out << getCount(H) << "\n";
    }
};


signed main() {
    DCaracalVsMonster solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
/**
 *      ABC 108 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 21:00:08
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int K; cin >> K;
    int even = K / 2; int odd = K - even;

    cout << even * odd << endl;


    return 0;
}


Measured memory_bytes: 892
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

   
int main(){
	int N;
	cin >> N;
	int cnt[100000+1]={};
	vector<int> a(N);
	for(int i = 0; i<N;i++){
		cin >> a[i];
	}
	
	for(int i = 0; i<N;i++){
		cnt[a[i]-1]++;
		cnt[a[i]]++;
		cnt[a[i]+1]++;
	}
	int ans = 0;
	for(int i = 0; i< 100000+1;i++){
		ans = max(cnt[i],ans);
	}
	cout << ans <<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main(){
    int N,K,x,sum=0;
    cin >> N;
    cin >> K;
    for(int i=0;i<N;i++){
            cin >> x;
            if(x<K-x)   sum+=x;
            else    sum+=(K-x);
    }
    cout << sum*2 << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
if n == 0:
  print(0)
  exit(0)
for k in range(100):
    if -2*pow(4,k) +2 < 3*n < pow(4,k) - 1:
        break
l = 2*k

delta = n - (-2*(pow(2,l)-1)//3)

var = delta ^ (2*(pow(2,l)-1)//3)

ans = ''
while var > 0:
    if var&1:
        ans ='1'+ans
    else:
        ans ='0'+ans
    var = var >> 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll a,b,k;
  cin>>a>>b>>k;
  for(ll i=a;i<=min(b,a+k-1);i++){
    cout<<i<<"\n";
  }
  for(ll i=max(b-k+1,a+k);i<=b;i++){
    cout<<i<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void dfs(vector<vector<int>> &g, vector<bool> &used, int v, vector<int> &ans) {
    used[v] = true;
    for(int nv: g[v]) {
        if(!used[nv])  {
            dfs(g, used, nv, ans);
        }
    }
    ans.push_back(v);
}
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    vector<vector<int>> from(n);
    vector<int> ind(n,0);
    rep(i,n-1+m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        from[b].push_back(a);
        ind[b]++;
    }
    vector<bool> used(n, false);
    vector<int> topo_sort(0);
    //dfs
    /*
    rep(v,n) {
        if(!used[v]) dfs(to, used, v, topo_sort);
    }
    reverse(topo_sort.begin(), topo_sort.end());
    */
    //bfs
    queue<int> q;
    rep(i,n) if(ind[i] == 0) q.emplace(i);
    while(!q.empty()) {
        int now = q.front();
        topo_sort.push_back(now);
        q.pop();
        for(auto e: to[now]) {
            ind[e]--;
            if(ind[e] == 0) {
                q.emplace(e);
            }
        }
    }

    vector<int> inv_topo(n);
    rep(i,n) {
        inv_topo[topo_sort[i]] = i;
    }
    rep(i,n) {
        if(from[i].size() == 0) {
            cout << 0 << endl;
            continue;
        }
        int ans = from[i][0];
        for(int v :from[i]) {
            if(inv_topo[v] > inv_topo[ans]) {
                ans = v;
            }
        }
        cout << ans+1 << endl;
    }
}


Measured memory_bytes: 13052
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
 ll k ;cin>>k ;
 ll now=7 ;
 ll ans=1 ;
 if(k%2==0 || k%5==0) cout<<-1<<endl ;
 else{
   rep(i,k+5){
     if(now%k==0){
       break ;
     }

    now = (now%k)*10+7 ;
    ans++ ;
   }
   cout<<ans<<endl ;
 }
   return 0 ;
 }



Measured memory_bytes: 3620
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> arr(n+1);
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    unordered_map<ll, ll> v;
    ll t = 0, curr = 1;
    while (v.find(curr) == v.end()) {
        if (k == t) {
            cout << curr << "\n";
            return 0;
        }
        v[curr] = t++;
        curr = arr[curr];
    }

    ll l = t - v.find(curr)->second;
    k -= t;
    k = k%l;
    while (k--) {
        curr = arr[curr];
    }

    cout << curr << "\n";
}



Measured memory_bytes: 11200
#include<iostream>
#include <cmath>
#include <iomanip>

using namespace std;

typedef struct point{
    double x,y;
}Point,Vector;

typedef struct line{
    Point x;
    Vector k;
}Line;

//点积
double dot(Vector x,Vector y){
    return x.x*y.x+x.y*y.y;
}

//叉积
double cross(Vector x,Vector y){
    return x.x*y.y-x.y*y.x;
}

double getlen(Vector x){
    return sqrt(dot(x,x));
}

Vector getV(Point x,Point y){
    Vector v;
    v.x=y.x-x.x;
    v.y=y.y-x.y;
    return v;
}
//点在直线的投影
Point Projection(Line x,Point y){
    Point answ;
    answ = x.x;

    double len = dot(x.k,getV(x.x,y));
    len/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    Vector temp  = x.k;
    temp.x /=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    temp.y/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    answ.x+=temp.x*len;
    answ.y+=temp.y*len;
    return answ;
}
//点与直线的对称点
Point Reflection(Line x,Point y){
    Point half = Projection(x,y);
    Point answ;
    answ.x=y.x+2*(half.x-y.x);
    answ.y=y.y+2*(half.y-y.y);
    return answ;
}

int main(){
    Point p0,p1;
    cin>>p0.x>>p0.y>>p1.x>>p1.y;
    Vector v1=getV(p0,p1);
    int t;
    cin>>t;
    Vector v2;
    while(t--){
        cin>>p1.x>>p1.y;
        v2=getV(p0,p1);
        double temp = cross(v1,v2);
        if(temp==0){
            if(dot(v1,v2)<0){
                cout<<"ONLINE_BACK"<<endl;
            }
            else if(getlen(v1)>=getlen(v2)){
                cout<<"ON_SEGMENT"<<endl;
            }
            else cout<<"ONLINE_FRONT"<<endl;
        }
        else if(temp<0){
            cout<<"CLOCKWISE"<<endl;
        }
        else cout<<"COUNTER_CLOCKWISE"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}
 
/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
 
//#define int ll
//#define int long long
 
signed main()
{
  int kind; cin >> kind;//2-n-100
  int cap; cin >> cap;//allm-x-1e5
  int gram;//1-m-1000
  int cnt = kind;
  
  vi Gram(0);
  REP(i, kind){
    cin >> gram;
    Gram.PB(gram);
  }
  
  for(const auto& g: Gram)
   cap = cap - g;
  
  int ming = *min_element(ALL(Gram)) ;
  
  while(cap >= ming){cap = cap-ming;++cnt;}
  
  
  cout << cnt;
  return 0;
}

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

using namespace std;

const int V = (int) 1e5;
const int E = (int) 1e5;
int nv, ne;
vector<int> adj[V + 1];
int mark[V + 1];
vector<int> topo_order;
int dp[V + 1];

void DFSTopoSort(int u) {
    if (mark[u] == 2) return;
    assert(mark[u] != 1); // back edge => not DAG
    mark[u] = 1;
    for (int& v : adj[u]) {
        DFSTopoSort(v);
    }
    mark[u] = 2;
    topo_order.push_back(u);
}

void TopoSort() {
    fill(mark, mark + nv + 1, 0);
    for (int u = 1; u <= nv; u++) {
        DFSTopoSort(u);
    }
    reverse(topo_order.begin(), topo_order.end());
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> nv >> ne;

    for (int i = 0; i < ne; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    TopoSort();

    // dp[i]: longest directed path ends that the ith vertex (according to topo-order)
    int ans = 0;

    fill(dp, dp + nv + 1, 0);
    for (int i = 0; i < nv; i++) {
        int u = topo_order[i];
        for (int& v: adj[u]) {
            dp[v] = max(dp[v], dp[u] + 1);
            ans = max(ans, dp[v]);
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 9080
package main
import (
  "fmt"
)
func main() {
  var n, x int
  fmt.Scan(&n, &x)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  result := 0
  prevNum := 0
  for _, a := range as {
    num := a + prevNum - x
    if 0 < num {
      result += num
      prevNum = x - prevNum
      continue
    }
    prevNum = a
  }
  fmt.Println(result)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    long long n;
    cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
        return 0;
    }
    
    long long ans=0,fives=10;
    while(fives<=n){
        ans+=n/fives;
        fives*=5;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int N = 2010, mod = 1e9 + 7;
int dp[N * 2][N * 2], G[N][N], frac[N * 4], inv[N * 4];
typedef long long LL;
inline int Pow(int x, int y) {
	int res = 1;
	for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
	return res;
}
inline int C(int n, int r) {
	return (LL)frac[n] * inv[r] % mod * inv[n - r] % mod;
}
int main() {
	int n, res = 0; scanf("%d", &n), frac[0] = 1;
	for (int i = 1; i <= 8000; i++) frac[i] = (LL)frac[i - 1] * i % mod, inv[i] = Pow(frac[i], mod - 2);
	for (int i = 1, a, b; i <= n; i++) 
		scanf("%d%d", &a, &b), G[a][b]++, dp[2001 - a][2001 - b]++, res = (res - C(a * 2 + b * 2, a * 2) + mod) % mod;
	for (int i = -2000; i <= 2000; i++)
		for (int j = -2000; j <= 2000; j++) {
			dp[i + 2001][j + 2001] = (dp[i + 2001][j + 2001] + dp[i + 2001][j + 2000] + dp[i + 2000][j + 2001]) % mod;
			if (i >= 0 && j >= 0 && G[i][j]) res = (res + (LL)G[i][j] * dp[i + 2001][j + 2001]) % mod;
		}
	printf("%d\n", (LL)res * inv[2] % mod);
}

Measured memory_bytes: 78976
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    int s,w;
    cin >> s >> w;
    if (s>w)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "unsafe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string w;
  cin >> w;
  
  bool ans = true;
  for (int i = 0; i < w.size(); i++) {
    if(count(w.begin(), w.end(), w.at(i)) % 2 != 0) {
      ans = false;
      break;
    }
  }
  
  if(ans) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" << endl;
  }
}
 

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
typedef long long ll;


int main(){

    while(true){
        ll n,m;
        cin>>n>>m;
        if(n==0&&m==0)break;
        
        ll h,g,s;
        ll t=m-n;
        s=t/1000;
        t=t%1000;
        g=t/500;
        t=t%500;
        h=t/100;
        
        cout<<h<<" "<<g<<" "<<s<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define int long long

signed main(){
    int n; cin >> n;
    vector<string> S(n);
    for(int i=0; i<n; ++i) cin >> S[i];
    int C[26];
    for(int c='a'; c<='z'; ++c){
        int count = 1<<20;
        for(int i=0; i<n; ++i){
            int tmp = 0;
            for(int j=0; j<S[i].size(); ++j){
                if(S[i][j]==c){
                    //cout << "kiteru?";
                    tmp++;
                }
            }
            count = min(count, tmp);
        }
        //cout << count << endl;
        C[c-'a'] = count;
    }
    //for(int i=0; i<26; ++i) cout << C[i] << endl;
    vector<char> res;
    for(int i=0; i<26; ++i){
        for(int j=0; j<C[i]; ++j){
            res.push_back(static_cast<char>(i+'a'));
        }
    } 
    for(int i=0; i<res.size(); ++i) cout << res[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  cin>>n;
  for(int i=0;i<3;i++){
    if(n[i]=='7'){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 5e5 + 10;
const int mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) 
        fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) {
	return binpow(a, mod - 2);
}

ll A(ll n, ll m) {
	return fac[n] * inv(fac[n - m]) % mod;
}

ll C(ll n, ll m) {
    return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}

int main() {
	init();
	int n, m; cin >> n >> m;
	ll sum = 0;
	for (int i = 0; i <= n; i++) {
		ll now = C(n, i) * A(m - i, n - i) % mod;
		if (i % 2 == 0) sum = (sum + now) % mod;
		else sum = (sum - now + mod) % mod;
	}
	cout << A(m, n) * sum % mod << "\n";
}

Measured memory_bytes: 7516
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
pattern = [[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans = []
for i in pattern:
    if A + B*i[0] + C*i[1] + D*i[2] == 7:
        for j in range(3):
            if i[j] == 1:
                ans.append("+")
            else:
                ans.append("-")
        print(str(A)+ans[0]+str(B)+ans[1]+str(C)+ans[2]+str(D)+"=7")
        exit()


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;++i){
        int sum=0;
        for(char c='a'; c<='z'; c++){
            bool left=false, right=false;
            for(int j=0;j<i;++j){
                if(s[j]==c)left=true;
            }
            for(int j=i;j<n;j++){
                if(s[j]==c)right =true;
            }
            if(left && right){
              sum++;
            }
        }
        if(ans<sum) ans=sum;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608