akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if A[i] <= B[i]:
        ans += A[i]
        B[i] -= A[i]
        A[i] = 0
        if A[i + 1] <= B[i]:
            ans += A[i + 1]
            B[i] -= A[i + 1]
            A[i + 1] = 0
        else:
            ans += B[i]
            A[i + 1] -= B[i]
    else:
        ans += B[i]
        B[i] = 0
        A[i] -= B[i]

print (ans)

Measured memory_bytes: 18624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc103_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();

            Array.Sort(input);

            int sum=0;
            for(int i=1; i<input.Length; i++){
                sum += Abs(input[i]-input[i-1]);
            }

            WriteLine(sum);
            //WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);
            //WriteLine($"答えは{input[0]+input[1]}");
        }
    }
}

Measured memory_bytes: 13396
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	cin >> N;
	long double ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> M;
		ans += (long double)1 / M;
	}
	cout << (long double)1 / ans << endl;
}

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

int main() {
  int N,D,X;
  cin >> N;
  cin >> D >> X;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  int cnt = X;
  for (int i=0; i<N; i++) {
    int C = D-1;
    cnt++;
    while (C>=A[i]) {
      C = C - A[i];
      cnt++;
    }
  }
  cout << cnt << endl;
  
}

Measured memory_bytes: 3608
def get_keta(N):
    ans = 1
    while True:
        if N // 10 != 0:
            ans += 1
            N //= 10
        if N // 10 == 0:
            break
    return ans

N = int(input())
ans = get_keta(N)

for a in range(1, int(N ** 0.5) + 1):
    if N % a != 0:
        continue
    b= N // a
    tmp = max(get_keta(a), get_keta(b))

    if ans > tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

void write(const string s,char cmax,int n) {
    if(n == 0) {
        cout << s << endl;
        return;
    }
    char c = 'a';
    while(c <= cmax) {
        if(c == cmax) write(s+c,cmax+1,n-1);
        else write(s+c,cmax,n-1);
        c += 1;
    }
}

int main() {
    int n;
    cin >> n;
    write("a",'b',n-1);
}

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

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    rep(i, n){
        if(i!=(k-1)){
            cout << s[i];
        }else{
            cout << (char)(s[i]-'A'+'a');
        }
    }
    cout << endl;
    return 0;
}

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

int main() {
  int a, b, c, x;
  cin >> a;
  b = a / 100;
  a = a % 100;
  c = a / 10;
  a = a % 10;
  x = a + b + c;
  cout << x << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    System.out.println(n * n * n);
  }
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define PB push_back
#define MP make_pair
#define F first
#define S second

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;
}



int main(){
	size_t k;
	cin >> k;
	string s;
	cin >> s;

	if(s.size()<=k){
		cout << s << endl;
	}
	else{
		REP(i,k){
			cout << s[i];
		}
		cout <<"..."<<endl;
	}
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int d = sc.nextInt();
    String ans = "Christmas";

    for (int i = d - 25; i < 0; i++) {
      ans += " Eve";
    }

    System.out.println(ans);

  }
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){ 
      a=b; 
      b=r; 
      r=a%b; 
    }
    return b;
}
int main(){
  int t;cin>>t;
  for(int i=0;i<t;i++){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    if(b>a){cout<<"No"<<endl;continue;}
    if(b>d){cout<<"No"<<endl;continue;}
    if(c>=b){cout<<"Yes"<<endl;continue;}
    ll g=gcd(d,b);
    if(b-g+(a%g)<=c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
def lcm(a,b):
    if a < b:
        a,b = b,a
    while a % b != 0:
        a,b = b,a%b
    return b

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += lcm(lcm(i,j),k)
print(ans)


Measured memory_bytes: 69180
n=int(input())
x=10**9+7
sa=[1,4,16]
sg=[1,4,15]
sc=[1,4,14]
st=[1,4,16]
for i in range(3,n):
    sa.append(sa[i-1]+sg[i-1]+sc[i-1]+st[i-1])
    sg.append(sa[i-1]+sg[i-1]+(sc[i-1]-sa[i-2]+sg[i-3])+st[i-1])
    sc.append((sa[i-1]-sg[i-2])+(sg[i-1]-sa[i-2]-sa[i-3]-sa[i-3])+(sc[i-1])+(st[i-1]-sa[i-3]))
    st.append(sa[i-1]+sg[i-1]+sc[i-1]+st[i-1])
n=n-1
print((sa[n]+sg[n]+sc[n]+st[n])%x)


Measured memory_bytes: 3064
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let a = read::<String>();
    let A: Vec<char> = a.chars().collect();
    let b = read::<String>();
    let B: Vec<char> = b.chars().collect();

    if A[0] == B[0] {
        println!("H");
    }else {
        println!("D");
    }
}

/*
AtCoder AtCoDeer
H H 1
H D 0
D H 0
D D 1
*/


Measured memory_bytes: 4352
n = int(input())
a_list = [i for i in list(map(int, input().split()))]

a_list.sort()
max_num = a_list.pop(-1)
margin = max_num
r = 0
for a in a_list:
    m = abs(max_num/2 - a)
    if margin >= m:

        margin = m
        r = a

print(str(max_num) + " " + str(r))

Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<vector<int>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }

    lint ret = inf;

    for (int i = 0; i < n; ++i) {

        vector<lint> nstot(n, 0);
        vector<lint> ns(n, 0);
        vector<int> depth(n, 0);
        {
            function<void(int, int)> dfs = [&](int c, int p) {
                for (auto &v : edges[c]) {
                    if (v == p)
                        continue;
                    depth[v] = depth[c] + 1;
                    dfs(v, c);
                    ns[c] += ns[v];
                    nstot[c] += nstot[v];
                }
                nstot[c] += ns[c];
                if (s[c] == '1')
                    ns[c]++;
            };
            dfs(i, -1);
        }

        if (nstot[i] % 2 == 1) {
            continue;
        }
        vector<lint> dp(n, inf);
        function<void(int, int)> dfs = [&](int c, int p) {
            dp[c] = nstot[c] % 2;
            for (auto &v : edges[c]) {
                if (v == p)
                    continue;
                dfs(v, c);
                dp[c] = max(dp[c], dp[v] + ns[v] - (nstot[c] - nstot[v] - ns[v]));
            }
            if (dp[c] < 0) {
                dp[c] = ((-dp[c]) % 2 == 0) ? 0 : 1;
            }
        };
        dfs(i, -1);
        if (dp[i] == 0) {
            ret = min(ret, nstot[i] / 2);
        }
    }
    if (ret == inf)
        cout << -1 << "\n";
    else
        cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
signed main(){
long long a,b,c;
long long k;
scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
long long i=0,ans=0;
if(k<=a){
  ans+=k;
  i++;
}else{
  ans+=a;
  k-=a;
}
if(k<=b&&i==0){
  i++;
}else{
  k-=b;
}
if(k<=c&&i==0){
  ans-=k;
}
printf("%d\n",ans);
return(0);
}

Measured memory_bytes: 1708
#include<stdio.h>
int main()
{
int x,y;
for(;;)
{
scanf("%d %d",&x,&y);
if(x != 0 | y != 0)
{
if(x < y)
{
printf("%d %d\n",x,y);
}
else
{
printf("%d %d\n",y,x);
}
}
else
{
break;
}
}
return 0;
}

Measured memory_bytes: 600
a,b,c,k = map(int,input().split())

ans = 0

if a <= k:
    ans += a
    k -= a
else:
    ans += k
    print(ans)
    exit()
if b <= k:
    k -= b
else:
    ans += k
    print(ans)
    exit()
if c <= k:
    ans -= c
    k -= c
else:
    ans -= k
    print(ans)
    exit()
print(ans)

Measured memory_bytes: 9208
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
uint64_t gcd(uint64_t a, uint64_t b);
uint64_t lcm(uint64_t a, uint64_t b);

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint64_t N;
  cin >> N;
  vector<uint64_t> a(N);
  ArrayInput(a);
  uint64_t current = 1;
  uint64_t i = 0;
  vector<uint64_t> res;
  while (i < N) {
    if (a[i] == current) {
      res.push_back(i);
      ++current;
    }
    ++i;
  }
  if (res.size() == 0) {
    cout << -1 << endl;
  } else {
    cout << N - res.size() << endl;
  }

  return 0;
}

uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

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

Measured memory_bytes: 3956
using System;

namespace ABC136
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int sum = 0;
            if (1 <= N && N <= 9)
            {
                Console.WriteLine(N);
            }

            sum += 9;

            if (10 <= N && N <= 99)
            {
                Console.WriteLine(sum);
            }

            if (100 <= N && N <= 999)
            {
                Console.WriteLine(sum + N - 100 + 1);
            }

            sum += (999 - 100 + 1);

            if (1000 <= N && N <= 9999)
            {
                Console.WriteLine(sum);
            }

            if (10000 <= N && N <= 99999)
            {
                Console.WriteLine(sum + N - 10000 + 1);
            }

            sum += (99999 - 10000 + 1);

            if (N == 100000)
            {
                Console.WriteLine(sum);
            }
        }
    }
}


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

int main() {
    ld x;
    std::cin >> x;
    
    ld now = 100;
    ll cnt = 0;
    
    
    while(true){
        cnt++;
        now = floor(now*1.01);
        if(now>=x){
            std::cout << cnt << std::endl;
            return 0;
        }
    }
}


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

int main(){

    ll n;

    cin >> n;

    vector<ll> p(n);

    rep(i,n){
        cin >> p[i];
    }

    ll ans=0;
    ll t;

    if(p[0]==1){
        t=p[0];
        p[0]=p[1];
        p[1]=t;
        ans++;
    }

    for(int i=1;i<n-1;i++){
        if(p[i]==i+1){
            if(p[i+1]!=i+1){
                t=p[i];
                p[i]=p[i+1];
                p[i+1]=t;
                ans++;
            }
        }
    }

    if(p[n-1]==n){
        t=p[n-1];
        p[n-1]=p[n-2];
        p[n-1]=t;
        ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

struct Matrix
{
  int row;
  int column;
  int multiple_time;

  Matrix():
    row(0), column(0), multiple_time(0)
  {}

  Matrix(int r, int c, int m):
    row(r), column(c), multiple_time(m)
  {}
};

Matrix multiple(Matrix mat1, Matrix mat2)
{
  return Matrix(mat1.row,
                mat2.column,
                mat1.multiple_time + mat2.multiple_time + mat1.row * mat1.column * mat2.column);
}

Matrix matrices[100];
Matrix multiplication[100][100];

Matrix minimum_multiple_time(int i, int j)
{
  if (i == j)
    return matrices[i];

  Matrix min = multiple(multiplication[i][i], multiplication[i + 1][j]);

  for (int k = 1; k < j - i; ++k)
  {
    Matrix cur_matrix = multiple(multiplication[i][i + k], multiplication[i + k + 1][j]);
    if (min.multiple_time > cur_matrix.multiple_time)
      min = cur_matrix;
  }

  return min;
}

int main()
{
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i)
    scanf("%d%d", &matrices[i].row, &matrices[i].column);

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; i + j < n; ++j)
    {
      multiplication[j][i + j] = minimum_multiple_time(j, i + j);
    }
  }

  printf("%d\n", multiplication[0][n - 1].multiple_time);

  return 0;
}


Measured memory_bytes: 2860
//Auuthor:Avdhoot
//Editor:Geany
//Favourite:One Piece
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int x;
	cin>>x;
	if(x==0){cout<<1 <<"\n";}
	else{cout<<0 <<"\n";}
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
using namespace std;

typedef long long ll;

int grid[1005][1005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	string temp;
	queue <pair<pair<int,int>,int> > que;
	memset(grid,0,sizeof(grid));
	for (int i = 1; i <= h; ++i)
	{
		cin>>temp;
		for (int j = 1; j <= w; ++j)
		{
			if (temp[j-1]=='#') {
				grid[i][j]=0;
				que.push(make_pair(make_pair(i,j),0));
			}
			else grid[i][j]=1;
		}
	}
	int ans=0,i,j,level;
	while (!que.empty()) {
		i = que.front().first.first;
		j = que.front().first.second;
		level = que.front().second;
		que.pop();
		if (grid[i][j-1]) que.push(make_pair(make_pair(i,j-1),level+1));
		if (grid[i][j+1]) que.push(make_pair(make_pair(i,j+1),level+1));
		if (grid[i-1][j]) que.push(make_pair(make_pair(i-1,j),level+1));
		if (grid[i+1][j]) que.push(make_pair(make_pair(i+1,j),level+1));
		grid[i][j-1]=0;
		grid[i][j+1]=0;
		grid[i-1][j]=0;
		grid[i+1][j]=0;
	}
	cout<<level<<endl;
}





Measured memory_bytes: 16272
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int sam[] = new int[A];
        int sam2 = 0;
        int sam3 = 0;

	  for(int i= 0;i<A;i++){
        sam[i] = sc.nextInt();
      }
	  for(int i= 0;i<A;i++){
        sam2 = sam[i]-sc.nextInt();
        if(sam2>0){
          sam3 += sam2;
        }
      }
      
		System.out.print(sam3);

    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;

void Fast_Read_Out()
{
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
}

void Random()
{
	unsigned int seed;
	asm("rdtsc" : "=A" (seed));
	srand(seed);        
}

unsigned int Time()
{
	 unsigned int time = clock() / 1000.00;
	 return time;
}

const int inf = int(1e9) + 123;

int a[101], cnt;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif 
	Random();
	Fast_Read_Out();
	int n, x;
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++) if(x >= a[i]) x -= a[i], cnt++;
	if(x > 0 && cnt == n) cout << cnt - 1;
	else cout << cnt << endl; 
	#ifdef JUDGE
//		cout << Time() << endl;
	#endif
}
// Easy Peasy Lemon Squeezy                                                            Sometimes it's the very people who no one imagines anything of who do the things no one can imagine.

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29


int main(){
int n;
set<int> lis;

cin >>n;
int d[n];
for(int i=0;i<n;i++){
cin >>d[i];
lis.insert(d[i]);
}


cout << (int)lis.size();


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long mypow(long long a, long long b) {
  if (b == 0) {
	  return 1LL;
	}
  if (b % 2 == 1) {
	  return (a * mypow(a, b - 1)) % mod;
	}
  long long c = mypow(a, b / 2);
  return (c * c) % mod;
}

int main() {
  int n;
  cin >> n;
  vector <int> d(n);
  int M = 0;
  for (int i = 0; i < n; i++) {
	  cin >> d[i];
	  M = max(d[i], M);
	}
  if (d[0] != 0) {
	  cout << 0 << endl;
	  return 0;
	}
  vector <int> cnt(M + 1, 0);
  for (int i = 0; i < n; i++) {
	  cnt[d[i]]++;
	}
  if (cnt[0] > 1) {
	  cout << 0 << endl;
	  return 0;
	}
  long long ans = 1;
  for (int i = 1; i <= M; i++) {
	  ans = (ans * mypow(cnt[i - 1], cnt[i])) % mod;
	}
  cout << ans << endl;
  return 0;
}


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

int main () {
  string s, t, ans = "Yes";
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i]!=t[i]) {
      ans ="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
set<pair<int, int>> x;
int main() {
  int n;
  cin >> n;
  if (n & 1)
    cout << n / 2 << endl;
  else
    cout << n / 2 - 1 << endl;
}

Measured memory_bytes: 3572
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007;




void main() {
    int n;
    scan(n);
    auto p = readln.split.to!(int[]);
    p[] -= 1;

    int c;

    foreach (i ; 0 .. n) {
        if (i != p[i]) c++;
    }

    writeln(c <= 2 ? "YES" : "NO");
}


















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 62)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

inline int calc(int b, int c)
{
    int mb = b*b - 4*c;
    if(mb < 0) return 0;

    int sqt = sqrtl(mb);
    if(sqt * sqt != mb) return 0;

    int r1 = -b + sqt, r2 = -b - sqt, ret = 0;

    if(r1 % 2 == 0 && r1 / 2 > 0) ret++;
    if(r2 % 2 == 0 && r2 / 2 > 0) ret++;

    return ret;
}

int main()
{
    ll n;
    cin >> n;

    for1(i, n) {

        ll ans = 0;
        for(int x = 1; x*x <= i; x++) {

            int sqx = x*x;

            for(int y = 1; y*y <= i; y++) {
                int tot = sqx + y*y + x*y;
                if(tot > i) break;

                int k = x+y, c = i - tot;

                ans += calc(k, -c);

                //if(calc(k, -c) > 0) cout << x << " " << y << " " << k << endl;
            }
        }

        pf("%lld\n", ans);
    }

    return 0;
}


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

int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	int n, m; scanf("%d%d", &n, &m);
	vector<vector<int>>p(n, vector<int>(n));
	rep(i, n)rep(j, n)scanf("%d", &p[i][j]);
	rep(i, m) {
		int a; scanf("%d", &a);
		if (a == 0) {
			int r, c, s, t; scanf("%d%d%d%d", &r, &c, &s, &t); r--; c--;
			rep(i, t / 90) {
				vector<vector<int>>u = p;
				rep(i, s)rep(j, s)u[i + r][j + c] = p[s - j - 1 + r][i + c];
				p = u;
			}
		}
		if (a == 1) {
			int r, c, s; scanf("%d%d%d", &r, &c, &s); r--; c--;
			rep(i, s)rep(j, s)p[r + i][c + j] = !p[r + i][c + j];
		}
		if (a == 2) {
			int r; scanf("%d", &r); r--;
			rotate(p[r].begin(), p[r].begin() + 1, p[r].end());
		}
		if (a == 3) {
			int r; scanf("%d", &r); r--;
			rotate(p[r].rbegin(), p[r].rbegin() + 1, p[r].rend());
		}
		if (a == 4) {
			int r, c; scanf("%d%d", &r, &c); r--; c--;
			queue<P>que; que.push(P(r, c));
			int b = p[r][c]; p[r][c] = !p[r][c];
			while (!que.empty()) {
				P a = que.front(); que.pop();
				rep(i, 4) {
					int nx = a.first + dx[i], ny = a.second + dy[i];
					if (0 <= nx&&nx < n && 0 <= ny&&ny < n&&p[nx][ny] == b) {
						p[nx][ny] = !p[nx][ny]; que.push(P(nx, ny));
					}
				}
			}
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (j)printf(" ");
			printf("%d", p[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3292
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))


double GaussElimination(vector<vector<double> > matrix) {
  const int n = matrix.size();
  double ret = 1.0;
  for (int x = 0; x < n; x++) {
    int pivot = x;
    for (int i = x + 1; i < n; i++) {
      if (fabs(matrix[i][x]) - fabs(matrix[pivot][x]) > EPS) {
        pivot = i;
      }
    }
    swap(matrix[x], matrix[pivot]);
    if (fabs(matrix[x][x]) < EPS) { return 0.0; }
    for (int y = 0; y < n; y++) {
      if (y == x) { continue; }
      double ratio = -matrix[y][x] /  matrix[x][x];
      matrix[y][x] = 0.0;
      for (int i = x + 1; i < n; i++) {
        matrix[y][i] += matrix[x][i] * ratio;
      }
    }
  }
  return ret;
}

typedef int Weight;
struct Edge {
  int src;
  int dest;
  Weight weight;
  Edge(int src, int dest, Weight weight) : src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    if (weight != rhs.weight) { return weight > rhs.weight; }
    if (src != rhs.src) { return src < rhs.src; }
    return dest < rhs.dest;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<double> Array;
typedef vector<Array> Matrix;

void PrintMatrix(const Matrix &matrix) {
  for (int y = 0; y < (int)matrix.size(); y++) {
    for (int x = 0; x < (int)matrix[y].size(); x++) {
      printf("%f ", matrix[y][x]);
    }
    puts("");
  }
}

const int ITER_CNT = 10;
bool Sunny(const Graph &g) {
  const int n = g.size();
  REP(iter, ITER_CNT) {
    Matrix tutte(n, Array(n, 0));
    REP(from, n) {
      FORIT(it, g[from]) {
        int to = it->dest;
        if (to <= from) { continue; }
        if (from != 0) {
          double r = (double)(rand() + 1) / RAND_MAX;
          tutte[from][to] = r;
          tutte[to][from] = -r;
        } else {
          double r1 = (double)(rand() + 1) / RAND_MAX;
          double r2 = (double)(rand() + 1) / RAND_MAX;
          tutte[from][to] = r1;
          tutte[to][from] = -r2;
        }
      }
    }
    if (GaussElimination(tutte) != 0.0) { return true; }
  }
  return false;
}

int n, m;
int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    Graph g(n);
    REP(i, m) {
      int f, t;
      scanf("%d %d", &f, &t);
      f--; t--;
      g[f].push_back(Edge(f, t, 0));
      g[t].push_back(Edge(t, f, 0));
    }
    if (Sunny(g)) {
      puts("Yes");
    } else {
      puts("No");
    }
  }
}

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

int main(){
  int N;
  cin >> N;
  vector <int> a(N);
  rep(i, N){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  rep(i,N-1){
    if(a[i] == a[i+1]){
      cout << "NO" << endl;
      return 0;
    }
    else {
      continue;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 1024
Public Class Compiler
    Const M As Integer = 1000000007
    Shared Sub Main()
        Dim nk As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        Dim n As Integer = nk(0)    ' 頂点の数
        Dim k As Integer = nk(1)    ' 色の数
        Dim x(0 To n - 1) As Integer
        For i As Integer = 0 To n - 2
            Dim ab() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
            x(ab(0) - 1) += 1
            x(ab(1) - 1) += 1
        Next
        Dim output As Long = Npr(k, x(0) + 1)
        For i As Integer = 1 To n - 1
            output = (output * Npr(k - 2, x(i) - 1)) Mod M
        Next
        Console.WriteLine(output.ToString())
    End Sub
    
    Shared Function Npr(n As Integer, r As Integer) As Long
        If n < r Then Return 0
        Dim result As Long = 1
        For i As Integer = 0 To r - 1
            result = (result * (n - i)) Mod M
        Next
        Return result
    End Function
End Class

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

int h, r;

int main() {
	cin >> h >> r;
	
	if (h < -r) { cout << -1 << endl; }
	else if (h == -r) { cout << 0 << endl; }
	else { cout << 1 << endl; }
	return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll ans = 1e12;
int dp[101010];

int solve(int N) {
    if (N == 0) {
        //cout << "A" << endl;
        return dp[N] = 0;
    }
    else if (N < 0) return 1e8;
    int& res = dp[N];
    if (res != 1e8) return res;
    int tmp1 = 1e8, tmp2 = 1e8;
    for (int i=0; i<10; ++i) {
        tmp1 = min(tmp1, solve(N-(int)pow(6,i))+1);
        tmp2 = min(tmp2, solve(N-(int)pow(9,i))+1);
    }
    res = min(tmp1, tmp2);
    return res;
}

int main() {
    int n;
    cin >> n;
    fill(dp, dp+n+1, 1e8);
    cout << solve(n) << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int nm[30], pr[30][N];
char lx[N];

void fail() {
  puts("-1");
  exit(0);
}

int lower(int x) {
  return x & (-x);
}

int tr[N];
void upd(int x, int k) {
  for(; x < N; x += lower(x))
    tr[x] += k;
}

int get(int x) {
  int ans = 0;
  for(; x; x -= lower(x))
    ans += tr[x];
  return ans;
}

int vs[N];
int main() {
  scanf("%s", lx + 1);
  int n = strlen(lx + 1);
  for(int i = 1; i <= n; ++i) {
    upd(i, 1);
    int pos = lx[i] - 'a';
    pr[pos][++pr[pos][0]] = i;
  }
  int be = 0;
  for(int i = 0; i < 26; ++i) {
    if(pr[i][0] & 1) {
      if(be) fail();
      be = i + 1;
    }
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(vs[i]) continue;
    int pos = lx[i] - 'a', r = pr[pos][pr[pos][0]--];
    if(i == r) {
      ans += (get(n) - get(i)) / 2;
    } else {
      ans += get(n) - get(r);
    }
    vs[i] = vs[r] = 1;
    upd(i, -1), upd(r, -1);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 22528
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

template<typename T>
class hashmap64 {
	std::vector<std::pair<uint64, T>> map;
	uint64 mask, count, temp;
	uint64 hash64(uint64 key) {
		key = ~key;
		key ^= key << 13;
		key ^= key >> 19;
		return key ^ (key << 17);
	}
public:
	hashmap64() :map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
		mask = 8191; count = 0;
	}
	hashmap64(size_t s) {
		s |= s << 1;
		s |= s >> 2;
		s |= s >> 4;
		s |= s >> 8;
		s |= s >> 16;
		s |= s >> 32;
		mask = s;
		count = 0;
		map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
	}
	T &operator[](uint64 suf) {
		temp = mask&hash64(suf);
		while (map[temp].first != suf) {
			temp = mask&(temp + 1);
		}
		return map[temp].second;
	}
	void insert(uint64 key, const T &value) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				map[temp].second = value;
				return;
			}
			temp = mask&(temp + 1);
		}
		map[temp] = std::make_pair(key, value);
		++count;
		if ((count << 1) > mask) {
			std::pair<uint64, T> mkey;
			mask = mask << 1 | 1;
			map.resize(mask + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
			for (uint64 t = 0;t <= mask >> 1;++t) {
				if (~map[t].first) {
					mkey = map[t];
					map[t].first = ~static_cast<std::uint_fast64_t>(0);
					temp = mask&hash64(mkey.first);
					while (~map[temp].first) {
						temp = mask&(temp + 1);
					}
					map[temp] = mkey;
				}
			}
		}
		return;
	}
	bool find(uint64 key) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				return true;
			}
			temp = mask&(temp + 1);
		}
		return false;
	}
	bool empty(void) {
		return !count;
	}
	size_t size(void) {
		return count;
	}
};

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	hashmap64<uint32> map(7);
	uint32 n;
	std::cin >> n;
	int64 a, sum = 1e15;
	uint32 ans = 0;
	map.insert(sum, 0);
	rep(i, 0, n) {
		std::cin >> a;
		sum += a;
		if (map.find(sum)) {
			ans = std::max(ans, i + 1 - map[sum]);
		}
		else {
			map.insert(sum, i + 1);
		}
	}
	std::cout << ans << "\n";
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ok=1,ng=1;
    for (int i=0;i<N;++i){
        int A; cin >> A;
        ok*=3; ng*=(A&1?1:2);
    }
    cout << ok-ng << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];
int Ans[200100];

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

  memset(Ans, -1, sizeof(Ans));
  
  vector<pair<int, pair<int, int> > > T;
  
  for (int i = 0; i < N; i++) {
    int s, t, x; cin >> s >> t >> x;
    T.push_back(make_pair(x, Pi(s-x, t-x)));
  }
  auto comparator1 = [](const pair<int, Pi> &l ,const pair<int, Pi> &r) {
                       return l.first < r.first;
                     };

  sort(T.begin(), T.end(), comparator1);

  auto comparator = [](const Pi &l, const Pi &r) { 
                      return l.second < r.second;
                    };
  
  set<Pi, decltype(comparator)> P(comparator);
  
  for (int i = 0; i < Q; i++) {
    int x; cin >> x;
    P.insert(Pi(i, x));
  }

  // for (auto x: P) {
  //   cout << x.first << " " << x.second << endl;
  // }

  for (int i = 0; i < N; i++) {
    int id = T[i].first;
    Pi range = T[i].second;
    auto leftitr = P.lower_bound(Pi(-1, range.first));
    auto rightitr = P.upper_bound(Pi(-1, range.second-1));

    //cout << "id: " << id << " range: " << range.first << " <= x < " << range.second << endl;
    for (auto it = leftitr; it != rightitr; it++) {
      // cout  << (*it).first <<  " "<<(*it).second << endl;
      Ans[(*it).first] = id;
    }

    P.erase(leftitr, rightitr);

    // cout << "h" << endl;
    // for (auto x: P) {
    //   cout << x.first << " " << x.second << endl;
    // }
    // cout << "e" << endl;
  }



  for (int i = 0; i < Q; i++) {
    cout << Ans[i] << endl;
  }
}


Measured memory_bytes: 14320
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct p1 {
	int idx, x, y;
};
bool operator<(const p1& r1, const p1& r2) {
	if (r1.y != r2.y) return r1.y < r2.y;
	return r1.x < r2.x;
}
struct edge {
	int to; long long cost; int type;
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
int H, W, N;
int main() {
	cin >> W >> H >> N;
	vector<p1> p(N);
	for (int i = 0; i < N; i++) cin >> p[i].x >> p[i].y, p[i].x--, p[i].y--, p[i].idx = i;
	p.push_back(p1{ N, W - 1, H - 1 }); N++;
	vector<vector<p1> > ex(W), ey(H);
	for (int i = 0; i < N; i++) {
		ex[p[i].x].push_back(p[i]);
		ey[p[i].y].push_back(p[i]);
	}
	for (int i = 0; i < W; i++) sort(ex[i].begin(), ex[i].end());
	for (int i = 0; i < H; i++) sort(ey[i].begin(), ey[i].end());
	vector<vector<edge> > G(N);
	for (int i = 0; i < W; i++) {
		for (int j = 1; j < ex[i].size(); j++) {
			int d = ex[i][j].y - ex[i][j - 1].y;
			G[ex[i][j - 1].idx].push_back(edge{ ex[i][j].idx, d, 0 });
			G[ex[i][j].idx].push_back(edge{ ex[i][j - 1].idx, d, 0 });
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 1; j < ey[i].size(); j++) {
			int d = ey[i][j].x - ey[i][j - 1].x;
			G[ey[i][j - 1].idx].push_back(edge{ ey[i][j].idx, d, 1 });
			G[ey[i][j].idx].push_back(edge{ ey[i][j - 1].idx, d, 1 });
		}
	}
	priority_queue<edge> que;
	vector<vector<long long> > dist(N, vector<long long>(2, 1LL << 60));
	if (ex[0].size()) {
		que.push(edge{ ex[0][0].idx, ex[0][0].y, 0 });
		dist[ex[0][0].idx][0] = ex[0][0].y;
	}
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			long long d = dist[u.to][u.type];
			if (e.type == 0) d += abs(p[u.to].y - p[e.to].y);
			else d += abs(p[u.to].x - p[e.to].x);
			if (u.type != e.type) d++;
			if (dist[e.to][e.type] > d) {
				dist[e.to][e.type] = d;
				que.push(edge{ e.to, -d, e.type });
			}
		}
	}
	long long ret = min(dist[N - 1][0], dist[N - 1][1]);
	if (ret == (1LL << 60)) cout << -1 << endl;
	else cout << ret << endl;
	return 0;
}

Measured memory_bytes: 59704
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t A, B, C, D, E, sum = 0;
  cin >> A >> B >> C >> D;
  A -= 1;
    E = __gcd(C, D);
    sum += B - (B / C) - (B / D) + (B / (C * D / E));
    sum -= A - (A / C) - (A / D) + (A / (C * D / E));
    cout << sum << endl;
}

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

using namespace std;

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

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

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

ll A[100005];
ll L[100005];
ll R[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }
    memset(L, 0, sizeof(L));
    memset(R, 0, sizeof(R));
    ll ans = 0;
    {
        ll s = 0;
        REP(i, N) {
            L[i] = s;
            s += std::max(0LL, A[i]);
        }
    }
    {
        ll s = 0;
        for (ll i = N - 1; i >= 0; --i) {
            s += std::max(0LL, A[i]);
            R[i] = s;
        }
    }

    {
        ll s = 0;
        REP(i, K) {
            s += A[i];
        }
        REP(i, N) {
            if (i + K > N)
                break;
            ans = std::max(L[i] + R[i + K] + std::max(0LL, s), ans);
            s += A[i + K] - A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main(){
    int n,m;
    cin >> n >> m;
    REP(i,m){
      int x;
      cin >>x;
      n -= x;
    }
    cout << max(-1,n) << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>

int main(){
	int n;
	std::string str;

	std::cin >> n;
	std::getline(std::cin, str);

	for (int i = 0; i < n; ++i){

		std::getline(std::cin, str);

		while(str.find("Hoshino") != std::string::npos){

			str.replace(str.find("Hoshino"), 7, "Hoshina");

		}

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

	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
#define vi vector<int>
#define ll long long
#define ld long double
#define vvi vector<vi>
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector<vll>
#define vvld vector<vld>
#define MOD 1000000007
#define endL << '\n'
#define ii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define endL << '\n'
#define vii vector<ii>
#define pb push_back

/*
ll powmod(ll x, ll y, ll mod){
	ll res = 1;
	while (y > 0){
		if (y%2) res = (res*x) % mod;
		x = (x*x) % mod;
		y /= 2;
	}
	return res;
}
*/

/*const int N = 1000000;
int lp[N+1];
vector<ll> pr;

void sieve(){
	for (int i=2; i<=N; ++i) {
	    if (lp[i] == 0) {
	        lp[i] = i;
	        pr.push_back (i);
	    }
	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
	        lp[i * pr[j]] = pr[j];
	}
}*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1; //cin >> t;
	while(t--){

		int n; cin >> n;
		vll a(n); for (int i = 0; i < n; i++) cin >> a[i];
		vector<vector<pll>> dp(n, vector<pll>(n, mp(-1, -1)));
		for (int i = 0; i < n; i++) dp[i][i] = mp(a[i], 0);
		for (int i = 0; i < n-1; i++) dp[i][i+1] = mp(min(a[i], a[i+1]), max(a[i], a[i+1]));
		int j;
		for (int len = 3; len <= n; len++){
			for (int i = 0; i < n; i++){
				j = i + len - 1;
				if (j >= n) break;
				if (len % 2 == 1){
					if (a[i] + dp[i+1][j].fi > a[j] + dp[i][j-1].fi){
						dp[i][j] = mp(a[i] + dp[i+1][j].fi, dp[i+1][j].se);
					}
					else dp[i][j] = mp(a[j] + dp[i][j-1].fi, dp[i][j-1].se);
				}
				else {
					if (a[i] + dp[i+1][j].se > a[j] + dp[i][j-1].se){
						dp[i][j] = mp(dp[i+1][j].fi, a[i] + dp[i+1][j].se);
					}
					else dp[i][j] = mp(dp[i][j-1].fi, a[j] + dp[i][j-1].se);
				}
			}
		}
		ll ans = dp[0][n-1].fi - dp[0][n-1].se;
		if (n % 2 == 0) ans *= -1;
		cout << ans;
	}
}

Measured memory_bytes: 141056
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll solve();
bool possible(ll,int);
int N;
ll S[200010];
int main()
{
    ll ANS;
    scanf("%d",&N);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d",&S[i]);
        if(i > 0)S[i] += S[i - 1];
    }
    for(int i = N + 1; i <= 2 * N; i++)
    {
        S[i] = S[N] + S[i - N];
    }
    ANS = solve();
    printf("%lld\n",ANS);
    return 0;
}
ll solve()
{
    ll l = 1,r = S[N] + 1;
    while(r - l > 0)
    {
        ll m = (r + l) / 2;
        bool up1 = 0,up2 = 0;
        for(int i = 0; i < N; i++)
        {
            up1 = up1 | possible(m,i);
            up2 = up2 | possible(m + 1,i);
        }
        if(up1 && !up2)return m;
        if(up1)l = m + 1;
        else r = m;
    }
    return l;
}
bool possible(ll O,int C)
{
    ll M = O;
    for(int i = 0; i < 3; i++)
    {
        if(M > S[C + N] - S[C])return false;
        ll l = C + 1,r = C + N + 1;
        while(r - l > 0)
        {
            ll m = (r + l) / 2;
            if((S[m] - S[C] > M && S[m - 1] - S[C] < M) || S[m] - S[C] == M)
            {
                M = S[m] - S[C] + O;
                break;
            }
            if(S[m] - S[C] > M)r = m;
            else l = m + 1;
        }
    }
    return true;
}

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    ll n, s;

    std::cin >> n >> s;

    constexpr ll MAX = 1e6, INF = 1e12;

    ll ans = INF;

    if (n == s)
        ans = n + 1;
    else if (n > s)
    {
        ll dif = n - s;
        ll x = 1;
        while (x * x <= dif)
        {
            if (dif % x == 0)
            {
                if (x <= s && s - x <= dif / x)
                    ans = std::min(dif / x + 1, ans);
            }
            ++x;
        }
    }

    for (ll i = MAX; i >= 2; --i)
    {
        ll x = n, res = 0;
        while (x > 0)
        {
            res += x % i;
            x /= i;
        }
        if (res == s)
            ans = i;
    }

    std::cout << ((ans == INF) ? -1 : ans) << std::endl;

    return 0;
}

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

using namespace std;

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

typedef long long ll;

struct FenwickTree{
	vector<ll> data;
	FenwickTree(int n):data(n+1){}
	void AddRange(int i,int x){
		for(;i;i-=i&-i)
			data[i]+=x;
	}
	void AddRange(int i,int j,int x){
		AddRange(i,-x);
		AddRange(j,x);
	}
	int Get(int i){
		ll res=0;
		for(i++;i<data.size();i+=i&-i)
			res+=data[i];
		return res;
	}
};



int main()
{
	for(int n,k,m;cin>>n>>k>>m,n|k|m;){
		FenwickTree ft(n);
		rep(i,n) ft.AddRange(i,n,1);
		
		int p=m-1; ft.AddRange(p,n,-1);
		for(int rest=n-1;rest>1;rest--){
			int x=(ft.Get(p)+k-1)%rest+1;
			int lo=0,hi=n;
			while(lo<hi){
				int mi=(lo+hi)/2;
				if(ft.Get(mi)>=x)
					hi=mi;
				else
					lo=mi+1;
			}
			p=lo;
			ft.AddRange(p,n,-1);
		}
		
		rep(i,n) if(ft.Get(i)==1){
			cout<<i+1<<endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	int h[100000]={};
	for (int i = 0; i < n; i++)
		scanf("%d", &h[i]);
	int max=h[0];
	for (int i = 1; i < n; i++) {
		if(max>h[i]+1){
			printf("No\n");
			return 0;
		}
		if(max<h[i])
			max=h[i];
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(x+r>W){
        printf("No\n");
    }else if(x-r<0){
        printf("No\n");
    }else if(y+r>H){
        printf("No\n");
    }else if(y-r<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
return 0;
}

Measured memory_bytes: 584