akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long max = Math.max(a,b);
        long min = Math.min(a,b);
        HashSet<Long> maxl = getPrimeFactorization(max);
        HashSet<Long> minl = getPrimeFactorization(min);
        int prime = 1;
        for(long p : maxl){
            if(minl.contains(p)){
                prime++;
            }
        }
        System.out.println(prime);
    }
    
    static HashSet<Long> getPrimeFactorization(long x) {
        HashSet<Long> result = new HashSet<Long>();
        while (x >= 2L && x % 2L == 0) {
            result.add(2L);
            x /= 2;
        }
        long d = 3;
        long q = x / d;
        while (q >= d) {
            if (x % d == 0) {
                result.add(d);
                x = q;
            } else {
                d += 2;
            }
            q = x / d;
        }
        if(x != 1){
            result.add(x);   
        }
        return result;
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {
	int d;
	std::cin >> d;

	if (d == 25) {
		std::cout << "Christmas" << std::endl;
	}
	else if (d == 24) {
		std::cout << "Christmas Eve" << std::endl;
	}
	else if (d == 23) {
		std::cout << "Christmas Eve Eve" << std::endl;
	}
	else {
		std::cout << "Christmas Eve Eve Eve" << std::endl;
	}
}

Measured memory_bytes: 256
using System;

class C {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var n = int.Parse(line[0]);
        var x = int.Parse(line[1]);
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = 0L;
        for (int i = 1; i < n; ++i) {
            var delta = a[i - 1] + a[i] - x;
            if (0 < delta) {
                answer += delta;
                a[i] -= delta;
            }
            if (a[i] < 0) {
                a[i - 1] += a[i];
                a[i] = 0;
            }
        }
        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 25052
# 参考: https://qiita.com/y-tsutsu/items/aa7e8e809d6ac167d6a1

import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

# 多次元配列
# dp = [[0] * 3 for _ in range(5)]

# 入力を受け取る
n = int(input())

print((n - 2) * 180)


Measured memory_bytes: 3572
def find(A):
    increase = []
    for i in range(len(A)-1):
        if A[i] <= A[i+1]:
            increase += [1]
        else:
            increase += [0]
    increase += [0]
    
    val = 1000
    hold = 0
    for i in range(len(increase)):
        if i==0:
            if increase[i] == 1:
                hold = val//A[i]
                val -= A[i]*hold
        else:
            if increase[i] == 1:
                if increase[i-1] == 0:
                    hold = val//A[i]
                    val -= A[i]*hold 
            else:
                if increase[i-1] == 1:
                    val += A[i]*hold
                    hold = 0
    return val
N = input()
A = list(map(int,input().strip().split()))
print(find(A))

Measured memory_bytes: 62068
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    string s;
    cin >> s;
    s += '?';
    s += '?';
    int n = s.size();
    int pre_a = 0;
    int i = 0;
    ll ans = 0;
    while (i < n) {
        if (s[i] == '?') {
            break;
        }
        if (s[i] == 'A') {
            pre_a++;
            i++;
        }
        else {
            if (s[i] == 'C') {
                pre_a = 0;
                i++;
            }
            else {
                if (s[i + 1] == 'C') {
                    ans += pre_a;
                    i += 2;
                }
                else {
                    pre_a = 0;
                    i++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)


int A,B,C;
int main(){
    string S;
    cin >> S;
    int N = S.length();
    REP(i,N){
        char x = S[i];
        if(x == 'a') A++;
        else if(x == 'b') B++;
        else if(x == 'c') C++;
        else cout << "Error" << endl;
    }

    int diff_ab = abs(A-B);
    int diff_bc = abs(C-B);
    int diff_ca = abs(A-C);

    if(diff_ab > 1 || diff_bc > 1 || diff_ca > 1) {
        cout << "NO" << endl;
        return 0;
    }else{
        cout << "YES" << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 512
n=97
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i,j):
	for t in r(30):b(p:=j+t-1);a(j+t,n,j+t);[*map(b,r(j+t,j+29))];a(j+29,x,i+t,1);b(p);a(j+t,i+t,j+t)
p(3933)
a(0,1,n)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
for t in r(59):a(2,2,2);[(a(5+t-s,36+s,98),a(n,98,99,1),a(2,99,2))for s in r(t+1)if t-30<s<30]

Measured memory_bytes: 9180
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()
B=LIST()

total=sum(A)
for i in range(N):
    if A[i]>=B[i]:
        A[i]-=B[i]
    else:
        A[i+1]=max(0, A[i+1]-(B[i]-A[i]))
        A[i]=0

print(total-sum(A))


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

int main()
{
    int n,k;
    cin>>n;
    vector<vector<int> > activities(n,vector<int> (3));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>activities[i][j];
        }
    }
    vector<vector<int> > ans(n,vector<int> (3));
    ans[0][0]=activities[0][0];
    ans[0][1]=activities[0][1];
    ans[0][2]=activities[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            ans[i][j]=activities[i][j] + max(ans[i-1][(j+1)%3],ans[i-1][(j+2)%3]);
        }
    }
    int an=0;
    for(int i=0;i<3;i++)
    an = max(an,ans[n-1][i]);
    cout<<an;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];

  int seq0[100001] = {}, seq1[100001] = {};
  for (int i = 0; i < n; i += 2)
    ++seq0[v[i]];
  for (int i = 1; i < n; i += 2)
    ++seq1[v[i]];

  int i_0 = 0, i_1 = 0;
  for (int i = 1; i <= 100000; ++i) {
    if (seq0[i] > seq0[i_0])
      i_0 = i;
    if (seq1[i] > seq1[i_1])
      i_1 = i;
  }
  sort(seq0 + 1, seq0 + 100001, greater<int>()),
      sort(seq1 + 1, seq1 + 100001, greater<int>());

  if (i_0 != i_1)
    cout << n - seq0[1] - seq1[1] << endl;
  else
    cout << min(n - seq0[2] - seq1[1], n - seq0[1] - seq1[2]) << endl;
}


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

#define mp       make_pair
#define mt       make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,A;
vector<int> cards;
const int MAX_N = 51;
ll dp[MAX_N][MAX_N][MAX_N * MAX_N];
ll memo(int pos, int cnt, int sum){
  if (pos >= N){
    if (cnt == 0)return 0;
    if (sum % cnt != 0){
      return 0;
    }
    return (sum / cnt) == A ? 1 : 0;
  }
  ll &res = dp[pos][cnt][sum];
  if (res >= 0){
    return res;
  }
  res = 0;
  res += memo(pos + 1, cnt + 1, sum + cards[pos]);
  res += memo(pos + 1, cnt, sum);

  return res;
}
int main(){
  cin >> N >> A;
  cards.resize(N);
  for (auto &val : cards){
    cin >> val;
  }
  sort(cards.begin(), cards.end());
  memset(dp, -1, sizeof(dp));
  cout << memo(0, 0, 0) << endl;

}


Measured memory_bytes: 53120
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using namespace std;
long long f[100][10];
long long p[100][11];
long long d[10];
long long n;

long long calc() {
	long long ans = -1000000000;
	bool flag = false;
	long long int score = 0, count[100] = {};
	for (int i = 0; i<10; i++) {
		if (d[i] == 1) flag = true;
	}
	if (flag == true) {
		for (int i = 0; i<10; i++) {
			for (int j = 0; j<n; j++) {
				if (d[i] == 1 && f[j][i] == 1)  count[j]++;
			}
		}
		for (int i = 0; i<n; i++) {
			score += p[i][count[i]];
		}
		ans = max(ans, score);
	}
	return ans;
}
long long solve(long long depth) {
	if (depth == 10) {
		return calc();
	}
	long long l, r;
	d[depth] = 0;
	l = solve(depth + 1);
	d[depth] = 1;
	r = solve(depth + 1);
	return max(l, r);
}
int main() {
	cin >> n;
	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}
	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j <= 10; j++) {
			cin >> p[i][j];
		}
	}
	cout << solve(0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
static unsigned int inf = 1e9+7;
int main(){
    double n;
    cin >> n;
    int ans = pow(n, 3.0);
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    vector<long long> H(N);
    vector<bool> F(N,0);
    for(int i = 0; i < N; i++) cin >> H[i];
    bool flag = 0;
    for(int i = 1; i < N; i++){
        if(H[i-1] > H[i]){
            if(F[i-1] == 0){
                if(H[i-1]- H[i] == 1){
                    if(i == 1){
                        H[i-1]--;
                        F[i] = 1;
                    }else if(H[i-1] - H[i-2]>=1){
                        H[i-1]--;
                        F[i] = 1;
                    }/*
                    if(flag == 0){
                        H[i]++;
                        flag = 1;
                    }*/
                }else{
                    cout << "No\n";
                    return 0;
                }
            }else{
                cout << "No\n";
                return 0;
            }
        }else if(H[i-1] == H[i] && F[i-1] == 1){
            F[i] = 1;
        }
    }
    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 1024
/*
 * NoobM
 * File Name : A.cpp
 * Date : 17.05.2020 01:14:16 +06
 * Version : 1.0
 * 
 * Copyright 2020 Mehedi <imehedi357@gmail.com>
 * Shahjalal University of Science & Technology 
 * 
 * Geany 1.36
 * 
 */

#include <bits/stdc++.h>

#define rep(i, a, b) \
    for (int i = int(a); i < int(b); i++)
#define rr(i, b) \
    for (int i = 0; i < int(b); i++)
#define vina vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl

using namespace std;
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int ans = a + min(k - a, 0);
    k = max(k - a - b, 0);
    
    if(k) ans -= k;
    
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 3648
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI B(N-1), A(N, INF);
		REP(i, N-1) cin>>B[i];
		REP(i, N-1) {
			minUpdate(A[i], B[i]);
			minUpdate(A[i+1], B[i]);
		}
		ll ans=accumulate(ALL(A), 0LL);
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define STACK_SIZE 1000
#define MAX_LEN 1000

int stack[STACK_SIZE];
int stack_size = 0;


int pop()
{
	if (stack_size <= 0) return 0;
	return stack[--stack_size];
}


int push(int a)
{
	stack[stack_size++] = a;
}


int is_digit(char *s)
{

	if (*s == '+' || *s =='-') {
		s++;
		if (*s >= '0' && *s <= '9') return 1;
		return 0;
	}

	if (*s >= '0' && *s <= '9') return 1;
	return 0;
}


int get_number(char *s)
{
	int sign = 0, n = 0;
	

	if (*s == '+') {
		s++;
	} else if (*s == '-') {
		sign = 1;
		s++;
	}

	while (*s >= '0' && *s <= '9') {
		n = n * 10 + (*s - '0');
		s++;
	}

	if (sign) return -n;
	return n;
}


int calc_rpn(char *s)
{
	int a, b, n;
	

	while (*s) {

		if (is_digit(s)) {
			n = get_number(s);
			push(n);
			while (*s == '-' || *s == '+') {
				s++;
			}
			while (n) {
				n /= 10;
				s++;
			}
			

		} else {
			switch (*s) {
			case '+':
				a = pop();
				b = pop();
				push(b+a);
				break;
			case '-':
				a = pop();
				b = pop();
				push(b-a);
				break;
			case '*':
				a = pop();
				b = pop();
				push(b*a);
				break;
			case '/':
				a = pop();
				b = pop();
				if (a == 0) break;
				push(b/a);
				break;
			case '%':
				a = pop();
				b = pop();
				if (a == 0) break;
				push(b%a);
			}
			s++;
		}
	}
	return pop();
}

int main()
{
	char s[MAX_LEN];

	scanf("%[^\n]*s", s);
	printf("%d\n", calc_rpn(s));
return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c;
    cin>>a>>c>>b;
    bool ok;
    if(a<=c){
        if(a<=b && b<=c) ok=true;
        else ok=false;
    }
    if(a>=c){
        if(a>=b && b>=c) ok=true;
        else ok=false; 
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
 

Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int N, C, K;
    cin >> N >> C >> K;
    priority_queue<int, vector<int>, greater<int>> passengers;
    REP(i, N) {
        int a;
        cin >> a;
        passengers.push(a);
    }
    int bus = 0;
    int cnt = 0;
    int dep = passengers.top() + K;
    while (!passengers.empty()) {
        if (passengers.top() <= dep) {
            passengers.pop();
            cnt++;
            if (cnt == C) {
                bus++;
                cnt = 0;
                dep = passengers.top() + K;
            }
        } else {
            bus++;
            dep = passengers.top() + K;
            passengers.pop();
            cnt = 1;
        }
    }
    if (cnt) { bus++; }
    print(bus);
}


Measured memory_bytes: 892
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    Q = int(input())
    LR = [[int(i) for i in input().split()] for j in range(Q)]
    B = [10**9]*(H*W+1)
    pos = {A[i][j]: (i+1, j+1) for i in range(H) for j in range(W)}
    for i in range(1, H*W+1):
        cur_p = i
        if B[cur_p] < 10**9:
            continue
        B[cur_p] = 0
        y, x = pos[cur_p]
        while cur_p + D <= H*W:
            np = cur_p + D
            ny, nx = pos[np]
            power = abs(nx - x) + abs(ny - y)
            B[np] = B[cur_p] + power
            cur_p = np
            y, x = ny, nx

    for le, ri in LR:
        print(B[ri] - B[le])


if __name__ == '__main__':
    main()


Measured memory_bytes: 76124
N = int(input())
B = [int(x) for x in input().split()]

answer = 0

for i in range(len(B)):                                                                                                                                                                                     
    if i == 0:                                                                                                                                                                                              
        answer += B[i]                                                                                                                                                                                      
                                                                                                                                                                                                            
    else:                                                                                                                                                                                                   
        answer += min(B[i-1], B[i])                                                                                                                                                                         

answer += B[len(B)-1]
print(answer)

Measured memory_bytes: 3060
function main()
	N=parse(Int,readline())
	S=map(x->-parse(Int,x),split(readline()))
	sort!(S)
	T=[shift!(S)]
	for i=0:N-1
		sort!(T)
		A=Int[]
		id=1
		cnt=0
		for s=S
			if id<=1<<i&&T[id]<s
				push!(T,s)
				id+=1
			else
				push!(A,s)
			end
		end
		S=A
	end
	println(isempty(S)?"Yes":"No")
end
main()

Measured memory_bytes: 171076
//
//  main.cpp
//  048
//
//  Created by Coma on 2020/05/15.
//  Copyright © 2020 Coma. All rights reserved.
//

#include <iostream>
#include <cmath>

using namespace std;

long count(const long x, const long y);

int main(int argc, const char * argv[]) {
    long a, b, x;
    cin >> a >> b >> x;
    
    // bまでの整数でxで割り切れるものの個数
    long count1 = count(b, x);
    // a-1までの整数でxで割り切れるものの個数
    long count2 = count(a-1, x);
    
    // 求める個数はcount(b,x) - count(a-1,x)
    cout << count1 - count2 << endl;
    
    return 0;
}

long count(const long x, const long y)
{
    if(x >= 0)
    {
        return x / y + 1;
    }
    else
    {
        return 0;
    }
}


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

typedef pair<int, int> pii;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int> > road(N);
  for (int i = 0; i < M; i++)
  {
    int A, B;
    cin >> A >> B;
    road.at(A-1).push_back(B-1);
    road.at(B-1).push_back(A-1);
  }
  queue<int> que;
  vector<int> cave(N);
  vector<bool> checked(N);
  for (int i = 0; i < N; i++)
  {
    cave.at(i) = -1;
    checked.at(i) = false;
  }
  que.push(0);
  cave.at(0) = 0;
  while (!que.empty())
  {
    int now = que.front();
    que.pop();
    if (!checked.at(now))
    {
      for (auto x : road.at(now))
      {
        if (cave.at(x) == -1)
        {
          cave.at(x) = now;
          que.push(x);
        }
      }
    }
    checked.at(now) = true;
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) cout << cave.at(i)+1 << endl;
}


Measured memory_bytes: 10124
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char s1(char g1, char g2) { if (g1 == 'T' && g2 == 'T')return 'T'; return 'F'; }
char s2(char g1, char g2) { if (g1 == 'F' && g2 == 'F')return 'F'; return 'T'; }
char s3(char g1, char g2) { if (g1 == 'T' && g2 == 'F')return 'F'; return 'T'; }
char solve(string S) {
	int T = 0; string U = "";
	while (T < S.size() && S[T] == '-') { T++; U += "-"; }
	int depth = 0, minx = 99999;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '(')depth++;
		else if (S[i] == ')')depth--;
		else { minx = min(minx, depth); }
		if (depth == 1 && i >= T + 1 && i <= (int)S.size() - 2) {
			string R1 = S.substr(T + 1, i - T - 1);
			string R2 = S.substr(i + 1, S.size() - i - 2);
			if (S[i] == '*')return solve(U + s1(solve(R1), solve(R2)));
			if (S[i] == '+')return solve(U + s2(solve(R1), solve(R2)));
			if (S[i] == '>')return solve(U + s3(solve(R1.substr(0, R1.size() - 1)), solve(R2)));
		}
	}

	if (T % 2 == 1) { if (S[T] == 'T')S[T] = 'F'; else S[T] = 'T'; }
	return S[T];
}
int main() {
	while (true) {
		bool OK = true;
		string U, V1, V2; cin >> U; char R[3] = "FT"; if (U == "#")break;
		for (int i = 0; i < U.size(); i++) {
			if (U[i] == '=') { V1 = U.substr(0, i); V2 = U.substr(i + 1, U.size() - i - 1); }
		}
		for (int i = 0; i < (1 << 11); i++) {
			string Y1 = V1, Y2 = V2; int bit[11];
			for (int j = 0; j < 11; j++) { bit[j] = (i / (1 << j)) % 2; }
			for (int j = 0; j < Y1.size(); j++) {
				if (Y1[j] >= 'a' && Y1[j] <= 'k') { Y1[j] = R[bit[Y1[j] - 'a']]; }
			}
			for (int j = 0; j < Y2.size(); j++) {
				if (Y2[j] >= 'a' && Y2[j] <= 'k') { Y2[j] = R[bit[Y2[j] - 'a']]; }
			}
			if (solve(Y1) != solve(Y2)) {
				OK = false;
			}
		}
		if (OK == true)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

const int N = 100005;

int n, a[3][N], dp[3][N];

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[0][i] >> a[1][i] >> a[2][i];
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[0][i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i];
		dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + a[2][i];
	}
	cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
	return 0;
}


Measured memory_bytes: 2560
program main
  
  implicit none
  character(6) :: s
  
  read(*,*) s
  
  if( s(3:3) == s(4:4) ) then  
    if( s(5:5) == s(6:6) ) then  
      print*, "Yes"
    else
      print*, "No"
    endif
  else
    print*, "No"
  endif
end program main


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<utility>
#include<string>
#include<map>
#include<unordered_map>
#include<queue>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}

int main(){
    int n;
    cin >> n;
    vector<Pi> p(n);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }

    sort(p.begin(), p.end()); //締め切りでソート
    ll deadline = p.back().first;
    ll time = 0;
    for(int i = 0; i < n; i++){
        if(time+p[i].second > p[i].first){
            cout << "No" << endl;
            return 0;
        }
        time += p[i].second;
    }

    cout << "Yes" << endl; 
    return 0;
}


Measured memory_bytes: 4816
import Data.Int (Int64)

judge :: Integral a => a -> [a] -> Bool
judge n xs = m == 0 && all f ys
    where
        (k, m) = sum xs `divMod` (n * (n + 1) `div` 2)
        ds = diff $ last xs : xs
        ys = fmap (k -) ds
        f x = x >= 0 && mod x n == 0

diff :: Num a => [a] -> [a]
diff xs = zipWith (-) (tail xs) (init xs)

main :: IO ()
main = do
    n <- readLn :: IO Int64
    xs <- fmap read . words <$> getLine :: IO [Int64]
    putStrLn $ if judge n xs then "YES" else "NO"


Measured memory_bytes: 33148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,sum = 0;
    cin >> n;
    rep1(i, n){
        if(i % 5 != 0 && i % 3 != 0)sum += i;
    }
    pf(sum);
    return 0;
}



Measured memory_bytes: 3632
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

//use text_io::*;

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut s = s.split_whitespace();

    let n: usize = s.next().unwrap().parse().unwrap();
    let w: usize = s.next().unwrap().parse().unwrap();

    let mut products = Vec::with_capacity(n);
    for _ in 0..n {
        let v: usize = s.next().unwrap().parse().unwrap();
        let w: usize = s.next().unwrap().parse().unwrap();

        products.push((v, w));
    }

    let mut dp = vec![vec![0; w + 1]; n+1];

    for i in (0..n).rev() {
        for j in 0..(w+1) {
            if j >= products[i].1 {
                dp[i][j] = std::cmp::max((dp[i + 1][j - products[i].1] + products[i].0),(dp[i + 1][j]));
            } else {
                dp[i][j] = dp[i + 1][j];
            }
        }
    }

    println!("{}", dp[0][w]);
}



Measured memory_bytes: 13116
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int h,w;
int c[26];
main()
{
	cin>>h>>w;
	string s;
	for(int i=0;i<h;i++)
	{
		cin>>s;
		for(int j=0;j<w;j++)
		{
			c[s[j]-'a']++;
		}
	}
	int cnt1=0,cnt2=0;
	for(int i=0;i<26;i++)
	{
		if(c[i]%2)cnt1++;
		c[i]-=c[i]%2;
		if(c[i]%4==2)cnt2++;
	}
	int ans1=h*w%2,ans2=h%2*(w/2)+w%2*(h/2);
	if(cnt1!=ans1||cnt2>ans2||(ans2-cnt2)%2)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var L = int.Parse(line[1]);
            var r = int.Parse(line[2]);
            if (n == 0 && L == 0 && r == 0) break;
            var a = new int[n];
            for (int i = 0; i < n; i++) a[i] =  int.Parse(Console.ReadLine().Trim());
            var ans = getAns(a, n, L, r);
            Console.WriteLine(ans);
        }
    }
    static int getAns (int [] a, int n,    int L , int r)
    {
        var count = 0;
        for (int i = L; i <= r; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i % a[j] == 0)
                    if ((j + 1) % 2 == 1) { count++; goto next; }
                    else goto next;
            }
            if (n % 2 == 0) count++;
            next:;
        }
        return count;
    }
}




Measured memory_bytes: 15936
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
    ios_base::sync_with_stdio(false);
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    int w;
    cin >> w;
    for (int i = 0; i < s.size(); i += w) cout << s[i];
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

#define MOD (int)(1e9 + 7)
#define MAXN 55

int n;
ll k;
struct matrix {
    int a[MAXN][MAXN];

    void read() {
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) scanf("%i", &a[i][j]);
    }

    void diag() {
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) a[i][j] = (i == j) ? 1 : 0;
    }

    int sum() {
        ll t = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                t += a[i][j];
                //printf("%10i  ", a[i][j]);
            }
            //printf("\n");
        }

        return t % MOD;
    }
} one;

matrix operator*(const matrix &a, const matrix &b) {
    matrix tmp;

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j) {
            ll t = 0;
            for(int z = 0; z < n; ++z) 
                t = (t + (ll)a.a[i][z]*b.a[z][j]) % MOD;
            tmp.a[i][j] = t;
        }

    return tmp;
}

matrix power(matrix one, ll k) {
    matrix r;
    r.diag();

    while (k) {
        if (k & 1) r = r * one;
        one = one * one;
        k = k >> 1;
    }

    return r;
}

int main() {
    scanf("%i%lld", &n, &k);
    one.read();

    one = power(one, k);

    printf("%i\n", one.sum());
    return 0;
}

Measured memory_bytes: 256
//AT2703
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;
inline ll read() {
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MAXN=2005,INF=1e9;
char tmp[MAXN];
int n,a[MAXN],b[MAXN],q[MAXN],G[MAXN],R[MAXN],L[MAXN];
bool cmp(int x,int y) {return R[x]<R[y];}
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);/*syn加速*/
	cin>>(tmp+1); n=strlen(tmp+1);
	int f1=0,f2=0;
	for(int i=1;i<=n;++i) a[i]=tmp[i]-'0',f1+=a[i];
	cin>>(tmp+1);
	for(int i=1;i<=n;++i) b[i]=tmp[i]-'0',f2+=b[i];
	if(f1&&!f2){cout<<-1<<endl;return 0;}
	for(int i=1;i<=n;++i) L[i]=R[i]=INF;
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)if(b[j])L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
	int ans=INF;
	for(int i=1;i<=n;++i) {
		int ct=0,k=i;
		for(int j=1;j<=n;++j) {
			if(a[k]!=b[j]) q[++ct]=k;
			k=k%n+1;
		}
		sort(q+1,q+ct+1,cmp);
		G[ct+1]=-INF;
		for(int j=ct;j>=1;--j)G[j]=max(G[j+1],L[q[j]]);
		G[ct+1]=0;
		k=n+1;
		for(int j=0;j<=ct;++j) {
			ans=min(ans,(R[q[j]]+max((i-k+n)%n,G[j+1]))*2-(i-k+n)%n+ct);
			ans=min(ans,(G[j+1]+max((k-i+n)%n,R[q[j]]))*2-(k-i+n)%n+ct);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    long long n; cin >> n;

    n++;

    int digit = 0;
    int temp = 0;
    int temp2 = 1;
    while(n != 0){
        temp = n % 10;
        n /= 10;
        digit++;
        if(temp != 0){
            temp2 = 0;
        }
    }


    cout << temp + (digit-1) * 9 + temp2 - 1<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int l[11],v1,v2;
  for(;~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2);)
    {
      for(int i=1;i<10;i++)
	  l[i]+=l[i-1];
      double num;
      int ans;
      // if(v1<v2)
	num=l[9]*(v1/((double)v1+v2));
      //      else
      //	num=l[9]*(v2/((double)v1+v2));
      for(int i=0;i<10;i++)
	{
	  if(l[i]>=num)
	    {
	      //  cout<<"l="<<l[i]<<"num="<<num<<endl;
	      ans=i+1;
	      break;
	    }
	}
	cout<<ans<<endl;
      //      cout<<l[9]<<endl;
    }
}

Measured memory_bytes: 1208
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

	if (A == B && B != C || A == C && C != B || A != B && B == C) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN]; int t[MAXN], f[MAXN];
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	int tot = 0, cnt[2] = {0, 0}; ll ans = 0;
	for (int i = 1; i <= n; i++)
		tot += s[i] == '0';
	for (int i = 1; i <= n; i++)
		if (s[i] == '0') cnt[0]++;
		else {
			if (s[i + 1] == '1') {
				ans += tot + 1, i++;
				cnt[1] += 2;
			} else {
				cnt[1] += 1;
				ans += i % 2;
				ans += tot - cnt[0];
				if (i % 2) ans += cnt[0] / 2;
				else ans += (cnt[0] + 1) / 2;
			}
		}
	for (int i = 1; i <= cnt[1] - 1; i++)
		ans += (i + 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3948
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {

    let n:Vec<char> = read::<String>().chars().collect();

    if n.contains(&'7') {
        println!("Yes");
    }else{
        println!("No");
    }
    
}


Measured memory_bytes: 2100
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main(void)
{
   int w,a,b;

   cin >> w >> a >> b;
   
   if (a <= b && b <= a + w) {
       cout << 0 << endl;
   }
   else if (a < b) {
       cout << b - (a + w) << endl;
   }
   else {
       cout << a - (b + w) << endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
/*
 * author  : anaksoleh
 * 29 sep 2019
 */
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int total;
    if(N%2 == 0)total = N / 2;
    else total = (N/2) + 1;

    cout << ((double)total) / N << '\n';
    return 0;

}


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

int u[108000];
int done[108000];
int dig[108000];
int cnt;

void ng(){
  cout << -1 << endl;
  exit(0);
}

int r(int x){
  if(x == u[x])return x;
  return u[x] = r(u[x]);
}

void unite(int x, int y){
  x = r(x);
  y = r(y);
  if(x != y)u[x] = y;
}

int n;

int main(){
  cin >> n;
  for(int i = 0;i < 108000;i++)u[i] = i;
  vector<int> a(n+1), b(n+1), c, d;
  a[n] = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    a[n] ^= a[i];
  }
  b[n] = 0;
  for(int i = 0;i < n;i++){
    cin >> b[i];
    b[n] ^= b[i];
  }
  
  c = a;
  d = b;
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  if(c != d){
    ng();
  }

  c.erase(unique(c.begin(), c.end()), c.end());

  for(int i = 0;i <= n;i++){
    a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
    b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
  }
  

  for(int i = 0;i <= n;i++){
    if(a[i] == b[i])continue;
    unite(a[i], b[i]);
    dig[a[i]]++;
    cnt++;
  }
  for(int i = 0;i <= n;i++){
    if(a[i] == b[i])continue;
    if(done[r(a[i])])continue;
    done[r(a[i])] = true;
    cnt++;
  }
  if(a[n] != b[n])cnt -= 2;
  else if(dig[a[n]] > 0)cnt--;
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n, k;
  cin >> n >> k;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  vector<vector<FiniteField>> dp1 = Make2DVector<FiniteField>(n + 1, k + 1, 0);
  // Cumulative sum.
  vector<vector<FiniteField>> dp2 = Make2DVector<FiniteField>(n + 1, k + 1, 0);
  dp1[0][k] = 1;
  dp2[0][k] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      int max_j = min(j + xs[i - 1], k);
      dp1[i][j] += dp2[i - 1][max_j];
      if (j > 0) dp1[i][j] -= dp2[i - 1][j - 1];
    }
    dp2[i][0] = dp1[i][0];
    for (int j = 1; j <= k; j++) dp2[i][j] = dp2[i][j - 1] + dp1[i][j];
  }
  cout << dp1[n][0].Value() << endl;
}


Measured memory_bytes: 159088
#include <iostream>
int main(void)
{
    int a, b, c, d;
    std::cin >> a >> b >> c;
    d = a - b;
    if (d - c < 0)
    {
        std::cout << c - d << std::endl;
    }
    else
    {
        std::cout << 0 << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  char a, b;
  std::cin >> a >> b;
  if (a == 'H') std::cout << (b == 'H' ? "H\n" : "D\n");
  else std::cout << (b == 'H' ? "D\n" : "H\n");
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

using namespace std;

int main(){
	char s[100010]; scanf("%s", s);
	int l = strlen(s), p = 0;
	for(int i = 0; i < l; i++) if(s[i] == 'p') p++;
	printf("%d\n", l / 2 - p);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int x = 0, min = 0, max = 0;

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

    for (int i = 0; i < N; i++) {
        if (A[i] < A[min]) {
            min = i;
        } else if(A[max] < A[i]) {
            max = i;
        }
    }
    x += A[max] - A[min] - 1;
    for (int i = A[min]; 0 < i; i--) {
        x++;
    }
    for (int i = B[max]; 0 <= i; i--) {
        x++;
    }

    printf("%d\n", x);
    return 0;
}

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

using namespace std;

int main() {
	long long int H, W;
	cin >> H >> W;
	vector<string>D( H );
	for( size_t i = 0; i < H; i++ ) {
		cin >> D[i];
	}
	for( size_t i = 0; i < H; i++ ) {
		for( size_t j = 0; j < W; j++ ) {
			if( D[i][j] == '#' ) {
				for( size_t k = i + 1; k < H; k++ ) {
					for( size_t l = 0; l < j; l++ ) {
						if( D[k][l] == '#' ) {
							cout << "Impossible" << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "Possible" << endl;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans = 0;
	for (int i = 1; i <= 5; i++)
	{
		int x;
		cin >> x;
		if( x == 0 ) ans = i;
	}
	cout << ans << '\n'; 
	return 0;
}


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

int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<string> vec(N);
  int X = 60;
  for(int i=0; i<N; i++){
    int64_t x;
    cin >> x;
    stringstream ss;
    ss << bitset<60>(x);
    string S = ss.str();
    vec.at(i) = S;
  }
  stringstream ss;
  ss << bitset<60>(K);
  string k = ss.str();
  
  vector<int64_t> one(X,0);
  for(int i=0; i<N; i++){
    for(int j=0; j<X; j++){
      if(vec.at(i).at(j) == '1'){
        one.at(j)++;
      }
    }
  }
  vector<int64_t> pow2(X,1);
  for(int i=X-1; i>0; i--){
    pow2.at(i-1) = pow2.at(i)*2;
  }
  
  int64_t dp[X+1][2];
  for(int i=0; i<X+1; i++){
    for(int j=0; j<2; j++){
      dp[i][j] = 0;
    }
  }
  
  bool start = false;
  
  for(int i=0; i<X; i++){
    if(!start){
      if(k.at(i) == '1'){
        start = true;
        dp[i+1][0] = pow2.at(i)*(N-one.at(i));
        dp[i+1][1] = pow2.at(i)*one.at(i);
      }
      continue;
    }
    int64_t x = k.at(i) - '0';
    for(int j=0; j<2; j++){
      for(int k=0; k<2; k++){
        int64_t ni = i+1;
        int64_t nj = j;
        int64_t nx = pow2.at(i)*one.at(i); 
        if(j == 0 && k < x){
          nj++;
        }
        if(nj == 0 && x < k){
          continue;
        }
        if(k == 1){
          nx = pow2.at(i)*(N-one.at(i));
        }
        dp[ni][nj] = max(dp[ni][nj], dp[i][j] + nx);
      }
    }
  }
  
  /*for(int i=0; i<X+1; i++){
    for(int j=0; j<2; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  
  int64_t ans = max(dp[X][0], dp[X][1]);
  
  for(int i=0; i<X; i++){
    if(k.at(i) == '1'){
      break;
    }
    ans += one.at(i)*pow2.at(i);
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  const ll mod = 1e9;
  ll s;
  cin >> s;
  ll x3 = ( mod + mod - s % mod) % mod;
  ll y3 = (x3 + s) / mod;
  cout << "0 0 1 " << mod << ' ' << y3 << ' ' << x3 << '\n';
  return 0;

}


Measured memory_bytes: 256