akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){
    os << "(" << p.first << ","<< p.second <<")";
    return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

constexpr ll mod = 1e9+7;
int n,w,d;

void solve(){
    vector<pii> que;
    que.push_back(make_pair(w,d));
    rep(loop,n){
        int p,s;cin>>p>>s;
        p--;
        auto b=que[p];
        int width=b.first;
        int hight=b.second;
        int len[]={width,hight,width,hight};
        int sum=width+hight+width+hight;
//        cerr << "erase : " << b << endl;
        que.erase(que.begin()+p);
        s%=sum;
        if(width+hight<=s and  s<=width+hight+width) s=width-(s-width-hight);
        if(width+hight+width<=s and s<=width+hight+width+hight) s=width+hight-(s-width-hight-width);
        if(s<=width){
            pii u=make_pair(width-s,hight);
            pii v=make_pair(s,hight);
            que.push_back(min(u,v));
            que.push_back(max(u,v));
//            cerr << "push : " << u << " , " << v << endl;
        }else{
            s -= width;
            pii u=make_pair(width,s);
            pii v=make_pair(width,hight-s);
            que.push_back(min(u,v));
            que.push_back(max(u,v));
//            cerr << "push : " << u << " , " << v << endl;
        }
    }
    vector<int> s;
    for(auto p : que){
        s.push_back(p.first*p.second);
    }
    sort(all(s));
    for(int i=0;i<s.size()-1;i++){
        cout << s[i] << " ";
    }
    cout << s[s.size()-1] << endl;

}

int main(){
    while(cin>>n>>w>>d){
        if(n==0 and w==0 and d==0) break;
        solve();
    }
}

Measured memory_bytes: 3144
from bisect import bisect_left
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
x = 0

for i in range(n):
    for j in range(i+1, n):
        a = l[i] + l[j]
        x += max(bisect_left(l,a) - j - 1, 0)
print(x)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    int n;
    cin >> n;
    if(n) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=n;i>0;i--){
    string hina;
    cin>>hina;
    if(hina=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    else{
      if(i==1){
        cout<<"Three"<<endl;
      }
      else{
      }
    }
  }
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
int _w;

vector<string> v;

int main() {
	int a, b, c;
	_w = scanf( "%d%d%d", &a, &b, &c );
	for( int i = 0; i < a; ++i ) v.push_back("a");
	for( int i = 0; i < b; ++i ) v.push_back("b");
	for( int i = 0; i < c; ++i ) v.push_back("c");
	while( v.size() > 1 ) {
		sort(v.begin(), v.end());
		string s1 = v.front(), s2 = v.back();
		v.pop_back();
		reverse(v.begin(), v.end());
		v.pop_back();
		v.push_back(s1+s2);
	}
	cout << v.front() << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	A := ReadInts(N)
	sort.Ints(A)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + A[i]
	}

	// (x以上がいくつあるか、x以上の合計) を返す
	calc := func(x int) (int, int) {
		var count, total int
		for i := 0; i < N; i++ {
			k := sort.Search(len(A), func(j int) bool {
				return A[i]+A[j] >= x
			})
			count += N - k
			total += A[i]*(N-k) + s[N] - s[k]
		}
		return count, total
	}

	l, r := 0, int(2e5)+1
	for r-l > 1 {
		c := (l + r) / 2
		if count, _ := calc(c); count >= M {
			l = c
		} else {
			r = c
		}
	}
	count, total := calc(l)
	ans := total - (count-M)*l
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4372
#include <iostream>

int main(int, char **)
{
    int K, A, B, a;
    std::cin >> K >> A >> B;
    a = A % K;
    if ((a == 0) || ((B - A + a) >= K))
        std::cout << "OK";
    else
        std::cout << "NG";
}


Measured memory_bytes: 3056
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif
 
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}
 
template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

int n;
vector<int> a;
int e[MAX];

bool ok() {
	if (sum(all(a)) % (n*(n+1)/2) != 0) return false;
	int k = sum(all(a)) / (n*(n+1)/2);
	rep(i, n) {
		e[i] = a[(i+1)%n] - a[i] - k;
		if (e[i] == 0) continue;
		if (e[i] > 0) return false;
		if (abs(e[i]) % n != 0) return false;
	}
	return true;
}

void solve() {
	cin >> n;
	a.resize(n);
	rep(i, n) cin >> a[i];
	puts(ok() ? "YES" : "NO");
}

signed main() {
	cout << fixed << setprecision(20);
	while(true) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = n%10;
    
    if(ans==2 || ans==4 || ans==5 || ans==7 || ans==9){
      System.out.println("hon");
    }else if(ans==0 || ans==1 || ans==6 || ans==8){
      System.out.println("pon");
    }else{
      System.out.println("bon");
    }
    
  }  
}

Measured memory_bytes: 35600
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
sum=0
cnt=0
for i in range(N):
    A=list(map(int,input().split()))
    for j in range(M):
        sum+=A[j]*B[j]
    if sum + C > 0:
        cnt+=1
    sum=0
print(cnt)


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

int main() {
    long A, B, C, K;
    cin >> A >> B >> C >> K;

    long ans = 0;
    if(A>K){
        ans = K;
    } else if (A+B>=K) {
        ans = A;
    } else {
        ans = A - (K - (A + B));
    }

    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
 
int a[100000];
 
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	ll cnt = 0;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += a[i];
		if (a[i] == 0) {
			cnt += sum / 2;
			sum = 0;
		}
	}
	cnt += sum / 2;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, p, w, g, y;
  p=0, w=0, g=0, y=0;
  cin >>N;
  for (int i=0; i<N; i++){
    string S;
    cin >> S;
    if (S=="P"){
      p++;
    }
    else if (S=="W"){
      w++;
    }
    else if (S=="G"){
      g++;
    }
    else if (S=="Y"){
      y++;
    }
  }
  int m;
  m=0;
  if (p) {
    m++;
  }
  if (w) {
    m++;
  }
  if (g) {
    m++;
  }
  if (y) {
    m++;
  }
  if (m==3) {
    cout <<"Three" <<endl;
  }
  else if (m==4){
    cout <<"Four" <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char S[6];
  	scanf("%s",S);
  
  if(S[2] == S[3]){
    if(S[4] == S[5]){
      printf("Yes");
    }else{
      printf("No");
    }
  }else{
    printf("No");
  }
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d %d", $n, $m);
for( $i=0; $i<$n; $i++ )
{
  $user = explode( " ",  trim(fgets(STDIN)) );
  array_shift($user);
  $userList[] = $user;
}

$countList = array_fill(1, $m, 0);
foreach( $userList as $user )
{
  foreach( $user as $kind )
  {$countList[$kind] += 1; }
}
$count = array_count_values($countList);
echo isset($count[$n]) ? $count[$n] : 0;

Measured memory_bytes: 4604
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int n, k, c, cnt, ans=1, a[200005];
set<int> st;
int main() {
	int i;
	cin >> n >> k;
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=0; i<n-1; i++) {
		if(a[i] < a[i+1]) c++;
		else c = 0;
		if(c == k-1) cnt++;
	}
	for(i=0; i<k; i++) st.insert(a[i]);
	for(; i<n; i++) {
		st.erase(a[i-k]);
		if(a[i-k] > *st.begin() || a[i] < *st.rbegin()) ans++;
		st.insert(a[i]);
	}
	cout << ans - max(0, cnt-1);
	return 0;
}

Measured memory_bytes: 10368
a,b = map(int,input().split())

if a * b <= 0:
  print("Zero")
else:
  if a > 0:
    print("Positive")
  else:
    cnt = b - a + 1
    
    if cnt % 2 == 0:
      print("Positive")
    else:
      print("Negative")



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

int main() {
    double a, b;
    double C;
    scanf("%lf %lf %lf", &a, &b, &C);

    double c;
  	double pi = 3.14159265;
    c = sqrt(a*a + b*b - 2*a*b*cos(C*pi/180));

    double L = a + b + c;
    double l = L/2;
    double S = sqrt(l*(l-a)*(l-b)*(l-c));
    double h = S*2/a;

    printf("%.8f %.8f %.8f\n", S, L, h);
}


Measured memory_bytes: 3304
N = int(input())
A = list(map(int, input().split()))
 
M = 10**6 + 1
 
cnt = [0] * M
 
for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for b in range(a, M, a):
        cnt[b] += 1
 
ans = 0
for a in A:
    if cnt[a] == 1:ans += 1
 
print(ans)

Measured memory_bytes: 32232
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String s = sc.next();

      int cnt = 0;
      for(int i = 0; i < s.length(); i++) {
        if(s.charAt(i) != 'A') continue;
        if(i + 2 < s.length() && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C') {
          cnt++;
          i += 2;
        }
      }
      System.out.println(cnt);
  }
}


Measured memory_bytes: 22096
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

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

int k;
ll ans;
int main(){
    cin >> k;
    rep(a, 1, k+1) rep(b, 1, k+1) rep(c, 1, k+1){
        ans += gcd(gcd(a, b), c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    def sort_for(s):
        cc = [c for c in s]
        cc.sort()
        s = "".join(cc)
        return s

    def sort_rev(t):
        cc = [c for c in t]
        cc.sort(reverse=True)
        t = "".join(cc)
        return t

    s = input()
    t = input()
    s = sort_for(s)
    t = sort_rev(t)
    st = [s, t]
    st.sort()
    if st[0] == s and s != t:
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 3064
def dw19A():
    N = int(input())
    a = list(map(int, input().split()))
    avea = sum(a) / N
    mina = 1000000000000
    ans = 0
    for i in range(N):
        if mina > abs(a[i] - avea):
            ans = i
            mina = abs(a[i] - avea)
    print(ans)
dw19A()

Measured memory_bytes: 3060
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1e5 + 10;
vector < int > g[maxN];
ll a[maxN];
void dfs(int v, int p) {
    vector < ll > in_leaves;
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        in_leaves.emplace_back(a[to]);
    }
    sort(in_leaves.begin(), in_leaves.end());
    if (in_leaves.empty()) return;
    if (in_leaves.size() == 1) {
        if (in_leaves[0] != a[v]) {
            cout << "NO\n";
            exit(0);
        }
    }
//    cout << " HI " << v << endl;
    ll our_val = a[v];
    ll c = 0;
    for (ll& it : in_leaves) {
        c += it;
    }
    sort(in_leaves.begin(), in_leaves.end());
    ll s_l = c - our_val;
    ll s_f = our_val - s_l;
    if (s_l < 0 || s_f < 0) {
        cout << "NO\n";
        exit(0);
    }
    if (c - in_leaves.back() < s_l) {
        cout << "NO\n";
        exit(0);
    }
    a[v] = s_f;

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if (n == 2) {
        if (a[1] != a[2]) cout << "NO\n";
        else cout << "YES\n";
        return 0;
    }
    int root = 1;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    for (int i = 1; i <= n; i++) {
        if (g[i].size() != 1) root = i;
    }
    dfs(root, -1);
    if (a[root] == 0) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 19736
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &p : a) cin >> p;
  int q;
  cin >> q;
  while (q--) {
    int b, e;
    cin >> b >> e;
    reverse(a.begin() + b, a.begin() + e);
  }
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3084
o = input()
e = input()
password = ''

while True:
    if len(o)>0:
        password += o[0:1]
        o = o[1:]
    else:
        print(password)
        break
    if len(e)>0:
        password += e[0:1]
        e = e[1:]
    else:
        print(password)
        break

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
int main(void){
    ll N, M, X, A[105], c=0;
    scanf("%lld %lld %lld", &N, &M, &X);
    rep(i, 0, M) scanf("%lld", A+i);
    qsort(A, M, sizeof(ll), cmp);
    rep(i, 0, M){
        if(A[i]<X) c++;
    }
    printf("%lld\n", min(c, M-c));
    return 0;
}
int cmp(const void *a, const void *b){
    return *(int *)a - *(int *)b;//昇順ソート
}


Measured memory_bytes: 128
#include <stdio.h>

int main(int argc, char** argv)
{
	int j, k, max_i, H, W, a[10000];

	int i = 0;
	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
			break;
		}
		a[i * 2] = H;
		a[i * 2 + 1] = W;
		i++;
	}
	max_i = i;

	for (i = 0; i < max_i; i++) {
		for (j = 0; j < a[i * 2]; j++) {
			for (k = 0; k < a[i * 2 + 1]; k++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 580
n, q  = map(int, input().split())
l = list(input())
bef = ""
now = 0
stack = []

for i in range(n):
  if l[i] == "C" and (bef == "A"):
    now += 1
  stack.append(now)
  bef = l[i]
  
for _ in range(q):
  fr, to = map(int, input().split())
  print(stack[to-1] - stack[fr-1])

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

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

    for (int i = 0; i < s.size(); i++){
        int x = s[i] - 'A';
        x = (x + n) % 26;
        s[i] = x + 'A';
    }
    cout << s << endl;
    return 0;
}

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

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

int main(){
    long long H,W,Q,M=0,cnt=0,max=0,sum=0;
    cin >> H;
    while(true){
        cnt++;
        M += H;
        M = M % 360;
        if(M==0)break;
    }
    cout << cnt <<endl;
}


Measured memory_bytes: 3612
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
const ll maxn = 1e6 + 10;
//const double pi = acos(-1.0);
 
char s[10]; 
int main(void)
{
	scanf("%s",s);
	int len = strlen(s);
	int tp=0;
	for(int i=0;i<len;i++)
	{
		tp = s[i] - '0';
		if(tp==7)break;
	}
	if(tp==7){
		printf("Yes\n");
	//	printf("%s contains 7 as its last digit.\n",s);	
	}
	else 
	{
		printf("No\n");
	//	printf("%s doesdoes not contain the digit 7.\n",s);
	}
	return 0;
} 

Measured memory_bytes: 3164
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))

c = []
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

Measured memory_bytes: 7012
#include <stdio.h>
int main(void)
{
	int n, k, i = 0, sum = 1;
	
	scanf("%d %d", &n, &k);
	
	while(sum <= n){
		sum = sum * k;
		i++;
	}
	
	printf("%d", i);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	long long n,m;
	cin>>n>>m;
	long long ans=0;
	long long get=max(n,m);
	long long ok=min(n,m);
	ans+=get;
	get--;
	if(get>ok){ans+=get;}
	else{ans+=ok;}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<ll> X(N);
    REP(i, 0, N) cin >> X[i];

    int L; cin >> L;
    int k = 1; while ((1 << k) < N) k++;
    int next[k][N] = {};
    REP(i, 0, N) {
        int idx = upper_bound(ALL(X), X[i] + L) - X.begin() - 1;
        next[0][i] = idx;
        // cout << X[idx] << endl;
    }
    REP(i, 0, k - 1) {
        REP(j, 0, N) {
            if (next[i][j] < 0) {
                next[i + 1][j] = -1;
            } else {
                next[i + 1][j] = next[i][next[i][j]];
            }
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        int a, b; cin >> a >> b; a--; b--;
        if (a > b) swap(a, b);
        
        int ans = 0;
        for (int i = k - 1; i >= 0; i--) {
            if (next[i][a] < b) {
                ans += (1 << i);
                a = next[i][a];
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}

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

int yakusuu(int A){
  int count=0;
  for(int i=1;i<sqrt(A)+1;i++){
    if(A%i==0){
      count++;
      if(A/i!=i){
        count++;
      }
    }
  }
  return count;
}
  
int main(){
  int N,count=0;
  cin >> N;
  for(int i=0;i<N;i+=2){
    if(yakusuu(i+1)==8){
      count++;
    }
  }
  cout << count << endl;
}

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

const int MAXN = 1e6+7;
int dp[MAXN];
//LL prefix[MAXN], suffix[MAXN];
int f[MAXN];

int N, now;
string X;
void solve(char c) {
    int mod;
    if (c=='1') {
        if (now==0) return;
        mod = now-1;
    } else {
        if (now==N) return;
        mod = now+1;
    }

    if (mod == 0) {
        assert(c=='1');
        for (int i = 1; i <= N; i++) {
            if (X[i-1]=='1') {
                f[i] = 0;
            }
        }
        return;
    }

//    cout << c << " mod " << mod << endl;

    int total = 0;
    for (int i = N, pw = 1; i > 0; i--, pw = (pw+pw)%mod) {
        if (X[i-1]=='1') total = (total+pw)%mod;
    }

    for (int i = N, pw = 1; i > 0; i--, pw = (pw+pw)%mod) {
        if (X[i-1]!=c) continue;
        int tmp = total;
        if (c=='1') tmp = (tmp+mod-pw)%mod;
        else tmp = (tmp+pw)%mod;
        f[i] = dp[tmp]+1;
    }
}

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

    for (int i = 1; i < MAXN; i++) {
        dp[i] = dp[i%__builtin_popcount(i)]+1;
    }

    cin >> N >> X;
    now = 0;
    for (char c : X) now += c=='1';

    solve('0');
    solve('1');

    for (int i = 1; i <= N; i++) cout << f[i] << "\n";



    return 0;
}


Measured memory_bytes: 8440
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    int N,M; cin>>N>>M;
    vector<vector<int> > G(N,vector<int>());
    vector<int> indeg(N);
    for(int i=0;i<M;i++){
        int x,y; cin>>x>>y;
        x--; y--;
        G[x].push_back(y);
        indeg[y]++;
    }

    queue<int> Q;
    for(int i=0;i<N;i++) if(indeg[i]==0){
        Q.push(i);
    }

    vector<int> dp(N);
    while(!Q.empty()){
        int v=Q.front();
        Q.pop();
        for(int u:G[v]){
            indeg[u]--;
            if(indeg[u]==0){
                dp[u]=dp[v]+1;
                Q.push(u);
            }
        }
    }

    int ans=0;
    for(int i=0;i<N;i++) ans=max(ans,dp[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main()
{
    unsigned int n;
    unsigned long int a[100001];
    unsigned long long int s = 1;
    int t=0;
    cin>>n;
    for(unsigned int i=0;i<n;i++)
        {
            cin>>a[i];
            
            if(a[i]>1000000000000000000/s)
               t=1;
               else 
               s*=a[i];
               if(a[i]==0)
                 { cout<<0;
                   return 0;
                 }
                 
             
        }
   if(t==1)
    cout<<-1;
    else
    cout<<s;
    return 0;
}

Measured memory_bytes: 4376
# Dice I

class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h


d = input().rstrip().split()
dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5])

command = list(input().rstrip())
# print(command)

for i, a in enumerate(command):
    if a == 'N':
        dice1.north()
    elif a == 'S':
        dice1.south()
    elif a == 'E':
        dice1.east()
    elif a == 'W':
        dice1.west()
print(dice1.top())



Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<int> C(N);
	rep(i, N)cin >> C[i];
	SORT(C);
	REVERSE(C);
	C[0] /= 2;
	int sum = 0;
	rep(i, N)sum += C[i];
	cout << sum << endl;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ' ';  } return os;  }

void print(int num, ...) {
  va_list valist;
  va_start(valist, num);
  for (int i = 0; i < num; i++) {
    if (i!=0) cout << ' ';
    cout << va_arg(valist, ll);
  }
  cout << endl;
  va_end(valist);
}

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> S(h);
  loop(i,0,h) cin >> S[i];
  ll acc[h+1][w+1];
  loop(i,0,h+1) acc[i][0] = 0;
  loop(i,0,w+1) acc[0][i] = 0;
  loop(y,1,h+1) {
    loop(x,1,w+1) {
      acc[y][x] = acc[y-1][x] + acc[y][x-1] - acc[y-1][x-1] + (S[y-1][x-1]-'0');
    }
  }

  ll ans = 100000000000000000;
  for (int T=0; T<1<<(h-1); T++) {
    ll y_cut = __builtin_popcount(T);
    bool ok = true;
    int g = 0;
    vector<int> id(h);
    loop(y,0,h) {
      id[y] = g;
      if (T>>y&1) g++;
    }
    g++;
    vector<ll> acc(g, 0); // 各グループごとのホワイトチョコ数.
    ll x_cut = 0;
    loop(x,0,w) {
      bool over = false;
      loop(y,0,h) {
        acc[id[y]] += S[y][x]-'0';
        over |= acc[id[y]]>k;
      }
      if (over) {
        x_cut++;
        loop(i,0,g) acc[i] = 0;
        loop(y,0,h) {
          acc[id[y]] += S[y][x]-'0';
          if (acc[id[y]]>k) ok = false; // 切っても足りない.
        }
      }
    }

    if (!ok) continue;
    // print(2, y_cut, x_cut);
    ans = min(ans, y_cut+x_cut);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>
#include <cstring>
#define MN 201000

int a[MN], cnt[MN], n, k;

int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= k; i++)
	{
		for(int j = 1; j <= n; j++)
			cnt[std::max(0, j - a[j])]++, cnt[std::min(n, j + a[j]) + 1]--;
		bool ok = 1;
		for(int j = 1; j <= n; j++)
		{
			cnt[j] += cnt[j - 1];
			if(cnt[j] < n) ok = 0;
		}
		memcpy(a, cnt, sizeof(cnt));
		memset(cnt, 0, sizeof(cnt));
		if(ok) break;
	}
	for(int i = 1; i <= n; i++) printf("%d ", a[i]); puts("");
}

Measured memory_bytes: 5336
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T = sorted(T)

S = []
for i in range(N):
    S.append(T[i] + K)
ans = 0
bus = 0
count = 0
for i in range(N):
    if T[i] <= bus and count < C:
        count += 1
    else:
        bus = S[i]
        count = 1
        ans += 1
print(ans)


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

int main () {
    int N; cin >> N;
    vector<float> v(N);
    for (int i = 0; i < N; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end(), greater<float>());
    for (int i = N; i >= 2; i--) {
        float x;
        x = (v.at(i - 2) + v.at(i - 1)) / 2.0;
        v.pop_back();
        v.pop_back();
        v.push_back(x);
    }
    cout << v.at(0) << endl;

}

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

using namespace std;

int main() {
	int S; 
	cin >> S;
	int L = S / 100;
	int R = S% 100;

	if (1 <= L && L <= 12) {
		if (1 <= R && R <= 12)
			cout << "AMBIGUOUS" << endl;
		else 
			cout << "MMYY" << endl;
	}
	else {
		if (1 <= R && R <= 12)
			cout << "YYMM" << endl;
		else 
			cout << "NA" << endl;
	}
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  vector<ll> v;
  for (int i = 1; i <= 9; i++) {
    v.emplace_back(i);
  }
  for (int i = 0;; i++) {
    ll x = v[i];
    if (x % 10 != 0) v.emplace_back(10 * x + x % 10 - 1);
    v.emplace_back(10 * x + x % 10);
    if (x % 10 != 9) v.emplace_back(10 * x + x % 10 + 1);
    if ((int)v.size() >= k) {
      cout << v[k - 1] << '\n';
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 4280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1<<31
#define MAX 100005
#define PI 2*acos(0.0)
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

ll a[MAX], suf[MAX], pre[MAX], mx = 0;
map<ll,int>mp;
vector<int>v;

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

    int n;
    sf(n);

    for(int i = 1; i <= n; i++)
    {
        sfl(a[i]);
        if(i==1)
            pre[i] = a[i];
        else
            pre[i] = __gcd(a[i], pre[i-1]);
    }
    suf[n] = a[n];
    for(int i = n-1; i >= 1; i--)
    {
        suf[i] = __gcd(a[i], suf[i+1]);
    }

    for(int i = 1; i <= n; i++)
    {
        mx = max(mx, __gcd(pre[i-1], suf[i+1]));
    }

    pf(mx);

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
bool interval(vector<pair<int,int> > mvs, int sz, int p){
	int l = 1, r = sz;
	while(!mvs.empty()){
		int dx, id; tie(dx, id) = mvs.back(); mvs.pop_back();
		if(id == 0){
			if(dx == -1) l++;
			else r--;
		} else {
			if(dx == -1) r = min(r + 1, sz);
			else l = max(l - 1, 1);
		}
		if(l > r) return false;
	}
	return l <= p && p <= r;
}
int main(){
	int h, w, n; cin >> h >> w >> n;
	int sr, sc; cin >> sr >> sc;
	string s, t; cin >> s >> t;
	vector<pair<int,int> > uph, upw;
	for(int i = 0; i < n; i++){
		int id = 0;
		for(int rot = 0; rot < 2; rot++, id ^= 1){
			if(s[i] == 'U') uph.push_back({-1,id});
			else if(s[i] == 'D') uph.push_back({1,id});
			else if(s[i] == 'L') upw.push_back({-1,id});
			else if(s[i] == 'R') upw.push_back({1,id});
			swap(s, t);
		}
	}
	if(interval(uph, h, sr) && interval(upw, w, sc)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



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

#define ll long long
const int mxN = 2e5;
map<ll, ll> mp;

int main()
{
    ll n, a[mxN], ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        ans += mp[i - a[i]];
        mp[i + a[i]]++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 27872
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second

#define MM INT_MAX/5
#define MIM INT_MIN/2

int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

#define MAX (int)1e5+1

queue<int> tops;
queue<int> q;
vector<vector<int>> adj;
int inDegree[MAX];
bool visited[MAX];
int N, E;

void topsort(int v) {
	if (visited[v])
		return;
	for (int x : adj[v])
		topsort(x);
	tops.push(v);
}

int DP[MAX];

int main()
{
	cin >> N >> E;
	adj.assign(N + 1, {});
	int from, to;
	for (int i = 0; i < E; i++)
	{
		cin >> from >> to;
		adj[from].pb(to);
		inDegree[to]++;
	}
	for (int i = 1; i <= N; i++)
		if (inDegree[i] == 0)
			q.push(i);
	while (!q.empty())
	{
		int a = q.front();
		q.pop();
		tops.push(a);
		//remove a from the DAG so to update inDegree
		for (int i : adj[a])
		{
			DP[i] = max(DP[i], DP[a] + 1);
			if (--inDegree[i] == 0)
				q.push(i);
		}
	}
	int ans = INT_MIN;
	for (int i = 0; i <= N; i++)
		ans = max(ans, DP[i]);
	cout << ans;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
using namespace std;
vpii d;
vvi dp(1005,vi(5000,-1));
int ans;
int rec(int x,int tar,int val){
    if(tar==val){
        return 0;
    }
    if(x>=d.size()){
        return 1000000000;
    }
    if(dp[x][val]!=-1){
        return dp[x][val];
    }
    dp[x][val]=min(rec(x+1,tar,(val|d[x].S))+d[x].F,rec(x+1,tar,val));
    return dp[x][val];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
 
    while(t--){
       int n,m;
       cin>>n>>m;
       int tar=0;
       for(int i=0;i<n;i++){
            tar=(tar|(1<<i));
       } 
       //cout<<tar<<endl;
       int x,y,z;
       for(int i=0;i<m;i++){
            cin>>x>>y;
            int uu=0;
            for(int j=0;j<y;j++){
                cin>>z;z--;
                uu=(uu|(1<<z));
            }
            d.push_back(mp(x,uu));
       }
       int u=rec(0,tar,0);
       if(u>=1000000000){
            u=-1;
       }
       cout<<u<<endl;
    }
    return 0;
} 

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

int x,y,z;
void input()
{
    cin>>x>>y>>z;
}

void solve()
{
    cout<<z<<" "<<x<<" "<<y<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3612
from statistics import mean, median,variance,stdev
N = int(input())
a = list(map(int,input().split()))
b = mean(a)
for i in range(N):
  a[i] = abs(a[i]-b)
  if a[i]==0:
    print(i)
    exit(0)
b = min(a)
for i in range(N):
  if a[i]==b:
    print(i)
    break

Measured memory_bytes: 5788
N=int(input())
A=[0]+list(map(int,input().split()))+[0]

X=0
for i in range(1,N+2):
    X+=abs(A[i]-A[i-1])
    
S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=X-(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1])
print("\n".join(map(str,S[1:])))


Measured memory_bytes: 91352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	ll n,k;
	cin >> n >> k;
	ll ans = 0;
	if(k%2==0) {
		ll a = n/k;
		ll b = n/(k/2) - a;
		ans = a*a*a+b*b*b;
		cout << ans << endl;
		return 0;
	}
	if(k%2 == 1) {
		ll c = n/k;
		ans = c*c*c;
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 256
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/

#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define fo(x,y) for(int x = 1 ; x <= y ; ++x)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;

typedef long long ll;
typedef unsigned int uint;
const int nmax = 200005;
const ll linf = LLONG_MAX;
const int mod = 1e9+7;
const int inf = INT_MAX;

ll n, k, a[nmax];

int main(){
    cin >> n >> k;
    fo(i,n){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    ll sum = 0;
    fo(i,n-k){
        sum += a[i];
    }
    cout << sum << '\n';

}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        int k=Integer.parseInt(sc.next());
        int res=0;
        for(int i=0; i<n; i++){
            if(Integer.parseInt(sc.next())>=k){
                res++;
            }
        }
        System.out.println(res);
        sc.close();
    }
}

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

void GratestCommonDevisor(int* input){
    int temp;
    if(input[0] < input[1]){
        temp = input[0];
        input[0] = input[1];
        input[1] = temp;
    }

    //cout << "debug1: "<< input[0] << " " << input[1] << endl;

    while(input[1] > 0){
        temp = input[0];
        input[0] = input[1];
        input[1] = temp % input[1];
        //cout << input[0] << " " << input[1] << endl;
    }

    //cout << "debug2: "<< input[0] << " " << input[1] << endl;
    return;
}

int main(){

    int input[2];

    cin >> input[0];
    cin >> input[1];

    //cout << "input: "<< input[0] << " " << input[1] << endl;

    GratestCommonDevisor(input);

    cout << input[0] << endl;

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int D;

int main(){
	
	cin>>D;
	
	if( D == 25 ) puts("Christmas");
	if( D == 24 ) puts("Christmas Eve");
	if( D == 23 ) puts("Christmas Eve Eve");
	if( D == 22 ) puts("Christmas Eve Eve Eve");
	
}


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

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

int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i] /= 2;
    }
    ll l = a[0];
    rep(i,n){
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,n){
        if ((l/a[i]) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m/l + 1)/2 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int r = 0;
    int l = 0;
    REP(i,n) CMAX(r,a[i]);
    while(r - l > 1){
        int cnt = 0;
        int m = (r + l) / 2;
        REP(i,n){
            if(a[i] % m == 0)
                cnt += a[i] / m - 1;
            else cnt += a[i] / m;
        }
        if(cnt > k)
            l = m;
        else r = m;
    }
    println(r);
    return 0;
}

Measured memory_bytes: 4052
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;

struct edge {
    int to, cost;
};

vector<int> G[1000000];
int c[200000];

int dp[11][200000];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < 11; i++) {
        fill(dp[i], dp[i] + N, -1);
    }
    for (int i = 0; i < Q; i++) {
        int v, d;
        cin >> v >> d >> c[i];
        dp[d][v - 1] = i;
    }
    for (int i = 10; i >= 1; i--) {
        for (int j = 0; j < N; j++) {
            if (dp[i][j] != -1) {
                dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
                int len = G[j].size();
                for (int k = 0; k < len; k++) {
                    dp[i - 1][G[j][k]] = max(dp[i - 1][G[j][k]], dp[i][j]);
                }
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (dp[0][i] == -1) {
            cout << 0 << endl;
        } else {
            cout << c[dp[0][i]] << endl;
        }
    }
}


Measured memory_bytes: 36088
from math import ceil, log

class SegmentTree(object):
    __slots__ = ["elem_size", "tree", "default", "op"]

    def __init__(self, a: list, default: int, op):
        real_size = len(a)
        self.elem_size = elem_size = 1 << ceil(log(real_size, 2))
        self.tree = tree = [default] * (elem_size * 2)
        tree[elem_size:elem_size + real_size] = a
        self.default = default
        self.op = op

        for i in range(elem_size - 1, 0, -1):
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])

    def get(self, x: int, y: int) -> int:  # [x, y)
        l, r = x + self.elem_size, y + self.elem_size
        tree, result, op = self.tree, self.default, self.op
        while l < r:
            if l & 1:
                result = op(tree[l], result)
                l += 1
            if r & 1:
                r -= 1
                result = op(tree[r], result)
            l, r = l >> 1, r >> 1

        return result

    def set(self, i: int, value: int) -> None:
        k = self.elem_size + i
        self.tree[k] = value
        self.__update(k)

    def __update(self, i: int) -> None:
        op, tree = self.op, self.tree
        while i > 1:
            i >>= 1
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])

    def bisect_left(self, x: int, y: int, op):  # [x, y)
        l = x
        r = y + 1
        while l + 1 != r:
            mid = (l + r) // 2
            if op(seg.get(l, mid)):
                r = mid
            else:
                l = mid
        return r


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

seg = SegmentTree(A, 0, max)

for i in range(Q):
    t, a, b = map(int, input().split())
    if t == 1:
        seg.set(a-1, b)
    elif t == 2:
        print(seg.get(a-1, b))
    else:
        print(seg.bisect_left(a-1, N, lambda x: x >= b))


Measured memory_bytes: 103568
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	ll a;
	cin>>a;
	for(ll i=1;i<=a;i++){
		double x =i*1.08;
		ll k =x;
		if(k==a){
			cout<<i<<endl;
			return 0;
		}
	}

	cout<<":(";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int X[N];
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int result = INT_MAX;
  for (int i = 0; i <= N-K; i++) {
    int l = X[i];
    int r = X[i+K-1];
    result = min(result, min(abs(l)+abs(r-l),abs(r)+abs(r-l)));
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n, a[100010], c, ans=999999999;
    pair<int, int> cnt[100010], cnto[100010];
    memset(cnt, 0, sizeof(cnt));
    memset(cnto, 0, sizeof(cnto));
    cin>>n;
    for (int i=0; i<n; i++) { cin>>a[i]; cnt[a[i]].first++; }
    for (int i=0; i<100005; i++) if (cnt[i].first!=0) c++;
    if (c==1) { cout<<n/2<<endl; return 0; }
    memset(cnt, 0, sizeof(cnt));
    for (int i=0; i<100005; i++) { cnt[i].second=i; cnto[i].second=i; }
    for (int i=0; i<n; i++)
    {
        if (i%2==0) cnt[a[i]].first++;
        else cnto[a[i]].first++;
    }
    sort(cnt, cnt+100005); reverse(cnt, cnt+100005);
    sort(cnto, cnto+100005); reverse(cnto, cnto+100005);
    for (int i=0; i<100005; i++)
    {
        bool ok=false;
        for (int j=0; j<100005 && !ok; j++)
        {
            if (cnt[i].second!=cnto[j].second)
            {
                ans=min(ans, n-cnt[i].first-cnto[j].first);
                ok=true;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2176