akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {

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

  int cnt = 0;
  int tmp = 0;
  for(int i=1; i<n; i++){
    if( tmp == 0 && a[i-1] < a[i] ){
      tmp = 1;
    } else if( tmp == 0 && a[i-1] > a[i] ){
      tmp = -1;
    }else if( tmp == 1 && a[i-1] > a[i] ){
      tmp = 0;
      cnt++;
    }else if( tmp == -1 && a[i-1] < a[i] ){
      tmp = 0;
      cnt++;
    }
  }
  cout << cnt + 1 << endl;


  return 0;
}

//


Measured memory_bytes: 640
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;

void main()
{
    auto S = readln.strip;
    if(S[0]==S[$-1]){
        writeln(S.length%2==0?"First":"Second");
    }else{
        writeln(S.length%2==1?"First":"Second");
    }
}


Measured memory_bytes: 2556
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template<class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();
void naive();

void outputinput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	//naive();
	//outputinput();
	return 0;
}

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

int K;

void input() {
	cin >> K;
}

void daminput() {
}

void solve() {
	for (int k = 0; k < K; k++) {
		cout << "ACL";
	}
	cout << "\n";
}

void naive() {
}

void outputinput() {
}


Measured memory_bytes: 3072
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort(key = lambda x:x[0])
can = 0
money = 0
i = 0
while can < M:
    if can + A[i][1] <= M:
        can += A[i][1]
        money += A[i][0] * A[i][1]
    else:
        money += A[i][0] * (M - can)
        can = M
    i += 1

print(money)
    

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

	int n;
    cin>>n;

    ll lcm = 1;

    for(int i =0;i<n;i++){
        ll x;
        cin>>x;

        lcm = lcm/(__gcd(x,lcm));
        lcm = lcm*x;
    }

    cout<<lcm<<endl;


}


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

int main(){
    int n,count=0;cin>>n;vector<int> p(n);
    for(int i=0;i<n;i++) cin>>p.at(i);
    for(int i=1;i<n-1;i++){
        if((p.at(i)>p.at(i-1)&&p.at(i+1)>p.at(i))||(p.at(i)<p.at(i-1)&&p.at(i)>p.at(i+1))) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map(String::toInt)

    for (i in 10..1000) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            println(i)
            return
        }
    }
    println(-1)
}


Measured memory_bytes: 38304
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
typedef long long ll;

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    bool like[10];
    for (int i = 0; i < 10; i++) like[i] = true;
    for (int i = 0; i < K; i++){
	int n;
	cin >> n;
	like[n] = false;
    }

    for (int i = N; i < 100000; i++){
	int n = i;
	bool can = true;
	while (n > 0){
	    int x = n%10;
	    if (!like[x]) can = false;
	    n /= 10;
	}
	if (can){
	    cout << i << endl;
	    break;
	}
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);
        int D = int.Parse(input[3]);
        long counter = 1;
        while (A > 0 && C > 0) {
            if (counter % 2 == 0) { A = A - D;  }
            else { C = C - B;  }
            counter++;
            
        }
        if (A <= 0) { Console.WriteLine("No"); }
        else { Console.WriteLine("Yes"); }
    }
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if(L == R) {
    cout << "Balanced" << endl;
  }
  else {
    cout  << "Right" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N, K;
vector<ll> A;
vector<ll> F;

bool solve(ll L){
    ll k = 0;
    REP(i,N){
        k += max(A[i] - L / F[i], 0LL);
    }

    if(k <= K)
        return true;
    else
        return false;
}

int main(){
    cin >> N >> K;

    A.resize(N);
    F.resize(N);
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N){
        cin >> F[i];
    }

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll left = -1;
    ll right = 1e18;
    //ll right = 25;
    while(right - left > 1){
        ll mid = (left + right) / 2;
        bool valid = solve(mid);
        if(valid){
            right = mid;
        }
        else{
            left = mid;
        }
    }

    ll ans = right;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll a;
	cin >> a;
	cout << a+a*a+a*a*a << endl;
}

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

using namespace std;
const int N=2e5+5;
#define ll long long
bool can(ll n,ll k)
{
    if(k==1) return 0;
    while(n%k==0) n/=k;
    n%=k;
    return n==1;
}
void Div(ll n,vector<ll>&a)
{
    for(ll i=1;i*i<=n;i++)
        if(n%i==0)
        {
            a.push_back(i);
            a.push_back(n/i);
        }
}
vector<ll> solve(ll n,vector<ll>a)
{
    vector<ll>ret;
    for(auto k:a)
        if(can(n,k))
            ret.push_back(k);

    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    vector<ll>a;
    Div(n,a);
    Div(n-1,a);
    sort(a.begin(),a.end());
    a.resize(unique(a.begin(),a.end())-a.begin());
    cout<<solve(n,a).size()<<endl;
    return 0;
}


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

using namespace std;



int main(){
    int X;
    cin >> X;
    vector<int> A(X+1, 0);
    A[0] = 1;
    for(int i=100;i<106;i++){
        for(int j=1;j<X+1;j++){
            if(j >= i) A[j] += A[j-i];
        }
    }
    cout << !!A[X] << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9 + 7;

int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<vector<ll> > dp(n+1,vector<ll>(k+1,0) );
    dp[0][k] = 1;
    for(int i=0;i<n;i++){
	ll sum = 0;
	for(int j=0;j<=a[i];j++){
	    sum += dp[i][k-j];
	    sum %= mod;
	    dp[i+1][k-j] = sum;
	}
	for(int j=a[i]+1;j<=k;j++){
	    sum += dp[i][k-j];
	    sum -= dp[i][k-(j-a[i]-1)];
	    sum += mod;
	    sum %= mod;
	    dp[i+1][k-j] = sum;
	}
    }
    cout<<dp[n][0]<<endl;
 //   for(int i=0;i<=n;i++){
//	for(int j=0;j<=k;j++)cout<<dp[i][j]<<' ';
//	cout<<endl;
  //  }

    return 0;
}


Measured memory_bytes: 80256
using System;
using System.Diagnostics.CodeAnalysis;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt();
            int A = cin.NextInt();
            int B = cin.NextInt();
            int ans = 0;

            for(int i = 1; i <= N; i++)
            {
                string x = i.ToString();
                int sum = 0;

                for (int j = 0; j < x.Length; j++)
                {
                    sum += Convert.ToInt32(x[j].ToString() );
                    if(j==(x.Length - 1))
                    {
                        if (A <= sum && sum <= B)
                        {
                            ans += i;
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



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

int main() {
    int N;
    cin >> N;
    int Xi[4];
    for (int i = 3; i >= 0; i--) {
        Xi[i] = N % 10;
        N /= 10;
    }
    for (int i = 0; i < 8; i++) {
        int t = Xi[0];
        for (int j = 1; j < 4; j++) {
            int p = 1 << (j - 1);
            if ((i & p) > 0) {
                t += Xi[j];
            } else {
                t -= Xi[j];
            }
        }
        if (t == 7) {
            string s = to_string(Xi[0]);
            for (int j = 1; j < 4; j++) {
                int p = 1 << (j - 1);
                s += ((i & p) > 0) ? "+" : "-";
                s += to_string(Xi[j]);
            }
            s += "=7";
            cout << s << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    for (int i = 0; i < v.size(); ++i)
      os << v[i] << " ";
    os << '\n';
  }
  return os;
}

signed main() {
    int n;
    cin >> n;
    int arr[n][2];
    int i;
    for(i=0;i<n;i++)
        cin >> arr[i][0] >> arr[i][1];
    int ok = 0;
    for(i=0;i<n-2;i++)
    {
        if(arr[i][0] == arr[i][1] && arr[i+1][0] == arr[i+1][1] && arr[i+2][0] == arr[i+2][1])
            ok = 1;
    }
    if(ok)
        cout << "Yes\n";
    else
        cout << "No\n";
}

Measured memory_bytes: 3624
n = int(input())
A = list(map(int, input().split(' ')))
c = 0

for i in range(n - 1):
    minv = A[i]
    minv_idx = i
    for k in range(i + 1, n):
        if minv > A[k]:
            minv = A[k]
            minv_idx = k
    if i != minv_idx:
        A[i], A[minv_idx] = minv, A[i]
        c += 1

print(*A)
print(c)



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

int main(){
    string s, t;
    cin >> s >> t;
    int a[26] = {}, b[26] = {};
    for(int i = 0; i < s.size(); ++ i){
        a[s[i] - 'a']++;
        b[t[i] - 'a']++;
    }
    sort(a, a + 26);
    sort(b, b + 26);

    for(int i = 0; i < 26; ++ i){
        if(a[i] != b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
import itertools
import math
import fractions
import functools

s = input()
t = input()
ok = True
if len(s) + 1 == len(t):
    for i in range(len(s)):
        if s[i] != t[i]:
            ok = False
    if ok:
        print("Yes")
        quit()
print("No")

Measured memory_bytes: 72780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N ;

  cin >> N ;

  vector<int> A(N);

  for(int i=0;i<N;i++) cin >> A.at(i);//入力終了
  
  map<int,int> s;

  for(int i=0;i<N;i++){
    if(!s.count(A.at(i))) s[A.at(i)]=1;
    else s[A.at(i)]++;
  }

  int ans=0;

  for(pair<int,int> p : s){
    int key = p.first;
    int value = p.second;
    if(key<value) ans+=value-key;
    else if(key>value) ans+=value;
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 5120
while true do
  s=STDIN.gets
  h=s.split[0].to_i
  w=s.split[1].to_i
  break if (h==0 && w==0)

  h.times {|x|
    w.times {|y|
      printf "#" if ((x+y) % 2) == 0
      printf "." if ((x+y) % 2) == 1
    }
    printf("\n")
  }
  printf("\n")
end

Measured memory_bytes: 8764
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
  int N;
  string S;

  cin >> N >> S;

  vector<int> vec;
  vec.push_back(0);

  for(int i = 0; i < N; i++) {
    vec.push_back((S[i] == 'I') ? vec[i] + 1 : vec[i] - 1);
  }
  cout << *std::max_element(vec.begin(), vec.end()) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
using namespace std;

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


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

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

list<int> Prime(int num) {
	list<int>P;
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (j*j > i) {
				break;
			}
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if (j*j > i + 2) {
				break;
			}
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	P.push_front(3);
	P.push_front(2);
	return P;
}

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

	cin >> N;
	vector<int>c(N + 1);
	vector<int>s(N + 1);
	vector<int>d(N + 1);
	for (int i = 1; i < N; i++) {
		cin >> c[i] >> s[i] >> d[i];
	}
	for (int i = 1; i <= N; i++) {
		int ans = 0;
		for (int j = i; j < N; j++) {
			ans = max(ans, s[j]);
			if ((ans-s[j]) % d[j]) {
				ans += d[j];
				ans -= (ans - s[j]) % d[j];
			}
			ans += c[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s, t;
    int a, b;
    cin >> a >> b;
    rep(i,a)s += '0'+b;
    rep(i,b)t += '0'+a;
    cout << min(s, t) << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split(" "))
mod = 10 ** 9 + 7
ans = 0
for k in range(K, N + 2):
    ans += (k * (2 * N + 1 - k) // 2) - (k * (k - 1) // 2) + 1
    ans %= mod
print(ans)

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

int main(void)
{
  char S[101];
  int N;
  
  scanf( "%d", &N );
  scanf( "%s", S );
  
  if( (N%2) == 0 )
  {
    if( strncmp( &S[0], &S[N/2], N/2 ) == 0 )
    {
      puts( "Yes" );
      return 0;
    }
  }
  
  puts( "No" );
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<string, int> P;

bool pairCompare(const P &firstElof, const P &secondElof)
{
    return firstElof.second > secondElof.second;
}
bool pairCompare2(const P &firstElof,const P &secondElof){

    if(firstElof.first<secondElof.first) {
        return firstElof.first < secondElof.first;
    }
    else if(firstElof.first==secondElof.first){
        return firstElof.second > secondElof.second;
    }
    else
        return firstElof.first > secondElof.first;
}
typedef long long ll;

int main(void)
{
    string s;
    cin >> s;
    ll n = s.size();
    ll i = 0;
    ll cnt = 0;
    ll cnt_a = 0;
    ll cnt_bc = 0;
    while (i < n - 1)
    { // cerr<<i<<endl;

        if (s[i] == 'A')
        {
            cnt_a++;
        }
        else
        {
            cnt_a = 0;
        }

        if (s.substr(i, 3) == "ABC")
        {
            cnt += cnt_a;
            s[i] = 'B', s[i + 1] = 'C', s[i + 2] = 'A';
            i += 2;
            cnt_a--;
            //cerr<<"AC"<<endl;
        }
        else
        {
            i++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  long long ans = 1e10;
  if (H % 3 == 0)
    ans = 0;
  else
    ans = min(ans, (long long)W);
  if (W % 3 == 0)
    ans = 0;
  else
    ans = min(ans, (long long)H);
  for (int i = 0; i < H; i++)
  {
    long long a = (long long)i * W, b = (long long)(H - i) * (W / 2), c = (long long)(H - i) * ((W + 1) / 2);
    ans = min(ans, max({a, b, c}) - min({a, b, c}));
  }
  for (int i = 0; i < W; i++)
  {
    long long a = (long long)i * H, b = (long long)(W - i) * (H / 2), c = (long long)(W - i) * ((H + 1) / 2);
    ans = min(ans, max({a, b, c}) - min({a, b, c}));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    long N,A,B;
    cin >> N >> A >> B;
    if(N <= 1 && A != B)  cout << 0 << endl;
    else if(A > B) cout << 0 << endl;
    else cout << ((N-1)*B + A) - ((N-1)*A + B) + 1 << endl;
    return 0;
}   

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	cout<<count(all(s),'1');
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	vi a;
	for(int i=2;i<=55555;i++) if(i%5==1){
		bool B=1;
		for(int j=2;j*j<=i;j++) if(i%j==0) B=0;
		if(B) a.push_back(i);
	}
	for(int i=0;i<n;i++) cout<<a[i]<<" \n"[i==n-1];
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using Um = unordered_map<char,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;


#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> S(1LL<<N,0);
    for(ll i=0;i<(1LL<<N);++i)cin>>S[i];
    sort(S.rbegin(), S.rend());
    unordered_multiset<ll> selected;
    multiset<ll> notyet;
    selected.insert(S[0]);
    for(ll i=1;i<(1LL<<N);++i){
        notyet.insert(S[i]);
    }
    //for(auto p: selected)cout<<p<<" ";cout<<endl;
    for(ll i=0;i<N;++i){
        unordered_multiset<ll> select;
        for(auto p: selected){
            auto x=notyet.lower_bound(p);
            if(x==notyet.begin()){
                prt("No");
                return 0;
            }
            --x;
            select.insert(*x);
            notyet.erase(x);
        }
        for(auto p: select){
            selected.insert(p);
        }
        //for(auto p: selected)cout<<p<<" ";cout<<endl;
    }
    prt("Yes");

    return 0;
}



Measured memory_bytes: 26920
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3 ;
    if(a1+a2+a3 >= 22){
        cout << "bust" << endl;
        return 0;
    }else{
        cout << "win" << endl;
    }
        
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$c = null;
while ($n--) {
	fscanf(STDIN, "%s", $w);
	if ($c && $w[0] != $c || isset($f[$w])) exit('No');
	$c = substr($w, -1);
	$f[$w] = 1;
}
echo 'Yes';

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  vector<int> check(26);
  
  
  for(int i=0;i<S.size();i++){
    char x='a';
    for(int j=0;j<26;j++){
      if(S[i]==x+j){
        check[j]=1;
      }
    }
  }
  
  for(int i=0;i<26;i++){
    if(check[i]==0){
      cout<<(char)(i+'a')<<endl;
      return 0;
    }
  }
  
  cout<<"None"<<endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;
 
//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;
 
//少数点表示
//cout << std::fixed << std::setprecision(14) << 値
 
int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    
    double d,t,s;
    cin >> d >> t >> s;
    if(d/s>t) cout << "No" <<endl;
    else cout << "Yes" <<endl;
    
    
    return 0;
    
}

Measured memory_bytes: 3672
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <math.h>
#include <numeric>
#include <assert.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <queue>
#include <random>
#include <chrono>
#include <limits.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define endl "\n"
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST_multiset;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const ll inf = 1e9 + 69;
const ld pi = 3.14159265358979323L;
const ld eps = 1e-15;

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
int setIO_count = 0;
void setIO(string s = ""){
	if(!setIO_count){
		unsyncIO();
		setIO_count = 1;
	}
	if(s.size()){ //output only
		setIn(s + ".in");
		setOut(s + ".out");
	}
}

#define gc getchar//_unlocked //can't for window server
#define pc putchar//_unlocked //can't for window server
ll inp(){
	char c = gc(); bool neg = false;
	for(; c < '0'||'9' < c; c = gc())
		if(c == '-') neg=true;
	ll rs = c - '0'; c = gc();
	for(; '0' <= c && c <= '9'; c = gc())
		rs = (rs << 1) + (rs << 3) + (c - '0');
	if(neg) rs = -rs;
	return rs;
}
void pri(ll _n){
	ll N = _n, rev, count = 0;
	bool neg = false;
	if(N < 0){
		N = -N; neg = true;
	}
	rev = N;
	if(N == 0) {pc('0'); return;}
	if(neg) pc('-');
	while(rev % 10 == 0) {count ++; rev /= 10;}
	rev = 0;
	while(N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
	while(rev != 0) {pc(rev % 10 + '0'); rev /= 10;}
	while(count --) pc('0');
}

const ll mod = 1e9 + 7;
const int N = 2 * 100 * 1000 + 5;

int main(){
	setIO("");

	int n; cin >> n;
	vector<pair<int, int> > v(n);
	for(int i = 0; i < n; i ++)
		cin >> v[i].first >> v[i].second;
	int a = 0;
	for(int i = 2; i < n; i ++){
		if(v[i].first == v[i].second && v[i - 1].first == v[i - 1].second && v[i - 2].first == v[i - 2].second)
			a = 1;
	}
	if(a) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>

using namespace std;

#define DIM 100004

int V[DIM];

int sgn(int nr) {
    if(nr < 0) {
        return -1;
    }

    return 1;
}

int main() {
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE

    int N;
    cin >> N;

    for(int i = 1; i <= N; ++i) {
        cin >> V[i];
        if(V[i] == V[i - 1]) {
            N--;
            i--;
        }
    }

    int ans = 1;
    for(int i = 3; i <= N; ++i) {
        if(sgn(V[i] - V[i - 1]) * sgn(V[i - 1] - V[i - 2]) < 0) {
            ++ans;
            i++;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 640
n = int(input())
a = [int(input()) for i in range(n)]

m = max(a)
count = a.count(m)

if count != 1:
    for i in range(n):
        print(m)

else:
    switch = 0
    for i in range(n-1):
        if a[i] == m:
            a.remove(m)
            m2max = max(a)
            print(m2max)
            a.append(m)
            switch = 1
        else:
            print(m)
    
    if switch == 1:
        print(m)
    else:
        a.remove(m)
        m2max = max(a)
        print(m2max)

Measured memory_bytes: 12532
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> w(N); rep(i, 0, N) { cin >> w[i]; }
	auto f=[&](int P) {
		int i(0);
		rep(k, 0, K) {
			int sum(0);
			while (i<N&&sum + w[i] <= P)sum += w[i++];
			if (i == N)return true;
		}
		return false;
	};
	int l = 0, r = 100000 * 10000;
	// (l,r]
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (f(mid))r = mid;
		else l = mid;
		dump(l, r);
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3232
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int N;
	int A[1000];
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	for (int i = 0;i < N;i++) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j]>v) {
			A[j + 1] = A[j];
			j--;
			A[j + 1] = v;
		}
		for (int i = 0;i < N-1;i++) {
			cout << A[i] << ' ' ;
		}
		cout << A[N-1];
		cout << endl;

	}

}

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

int main() {
  int n; cin >> n;
  int ans = 0;
  long long a[n]; for(int i = 0; i < n; i++) cin >> a[i];
  while(true) {
    for(int i = 0; i < n; i++) {
      if(a[i] % 2 == 0) a[i] /= 2;
      else {
        cout << ans << endl;
        return 0;
      }
    }
    ++ans;
  }
}


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

using namespace std;

int main() {
    using ll = long long;
    
    ll n;
    cin >> n;
    
    vector<ll> a(5);
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    
    ll k = *min_element(a.begin(), a.end());
    
    cout << (n + k - 1) / k + 4 << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    adj = []
    for i in range(N):
        adj.append(S())

    def bfs(v):
        group = [-1] * N
        q = deque([(v, 0)])
        group[v] = 0
        while q:
            cur_v, gid = q.popleft()
            for next_v in range(N):
                if adj[cur_v][next_v] == '0':
                    continue
                if group[next_v] != -1:
                    if abs(group[cur_v] - group[next_v]) > 1:
                        return -1
                    if group[cur_v] == group[next_v]:
                        return -1
                    else:
                        continue
                group[next_v] = gid + 1
                q.append((next_v, gid+1))
        return max(group) + 1

    ans = -1
    for i in range(N):
        ans = max(ans, bfs(i))

    print(ans)

main()



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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  int W;
  scanf("%d",&W);
  int H;
  scanf("%d",&H);
  int N;
  scanf("%d",&N);
  int xl=0, xr=W;
  int yb=0, yt=H;
  for(int i = 0 ; i < N ; i++){
    int x,y,a; cin>>x>>y>>a;
    switch(a) {
      case 1:
        xl = max(xl,x);
        break;
      case 2:
        xr = min(xr,x);
        break;
      case 3:
        yb = max(yb,y);
        break;
      case 4:
        yt = min(yt,y);
        break;
    }
  }
  if (xl>=xr||yb>=yt) cout << 0 << endl;
  else cout << (xr-xl)*(yt-yb) << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
N = int(input())
f = 0
a = 0
b = 1
c = 1
for i in range(N):
  a2, b2, c2 = map(int, input().split())
  dis = abs(b2 - b) + abs(c2 - c)
  dis_t = a2 - a
  if dis > dis_t or (dis_t - dis) % 2 == 1:
    f = 1
    break
  a = a2
  b = b2
  c = c2
if f == 1:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 74264
#include <stdio.h>
int main(void){
    while(1){
    int n;
    scanf("%d",&n); 
    if(n==0) break;
    int p,d1,d2;
        scanf("%d %d %d",&p,&d1,&d2);
        int max_num=p,max=d1+d2;
    for(int i=1;i<n;i++){
        int p,d1,d2,x=0,y=0;
        scanf("%d %d %d",&p,&d1,&d2);
        if(max<d1+d2) {
            x=max; max=d1+d2; y=max_num; max_num=p;
        }
    }
    printf("%d %d\n",max_num,max);
    }
   return 0;
}




Measured memory_bytes: 2112
#include <iostream>
#include <queue>
#include <fstream>
#include <stack>
#include <cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int    inf = 100100100;


const int    dx[4] = { 0, 1, 0, -1 };
const int    dy[4] = { 1, 0, -1, 0 };

struct POINT {
    int lx;
    int ly;
    int rx;
    int ry;
};

bool u[55][55][55][55] = {};
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
//    ifstream in("in.txt");
//    cin.rdbuf(in.rdbuf());
    int  w, h;
    char ML[55][55], MR[55][55];
    int slx,sly,srx,sry;
    while (cin >> w >> h, w) {
        memset(u,0,sizeof(u));
        memset(ML,0,sizeof(ML));
        memset(MR,0,sizeof(MR));

        rep(y, h) {
            string sml,smr;
            cin >> sml >> smr;
            sml.copy(ML[y],sml.size()+1);
            smr.copy(MR[y],smr.size()+1);

        }
        rep(y, h) rep(x,w){
                if(ML[y][x] == 'L') ML[y][x] = '.',slx = x,sly = y;
                if(MR[y][x] == 'R') MR[y][x] = '.',srx = x,sry = y;
            }
        stack<POINT> st;
        st.push(POINT{slx, sly, srx, sry});

        bool flag = false;
        while (!st.empty()) {
            POINT p = st.top();
            st.pop();

            rep(i, 4) {
                int nlx = p.lx + dx[i];
                int nly = p.ly + dy[i];
                int nrx = p.rx + dx[(i + 2) % 4];
                int nry = p.ry + dy[i];
                bool left_do = true;
                bool right_do = true;
                if (nlx < 0 || w <= nlx) left_do = false;
                if (nly < 0 || h <= nly) left_do = false;
                if (ML[nly][nlx] == '#') left_do = false;
                if (nrx < 0 || w <= nrx) right_do = false;
                if (nry < 0 || h <= nry) right_do = false;
                if (MR[nry][nrx] == '#') right_do = false;
                if (ML[nly][nlx] == '%' && MR[nry][nrx] == '%') {
                    flag = true;
                    while (!st.empty()) st.pop();
                    break;
                } else if (ML[nly][nlx] == '%' || MR[nry][nrx] == '%') {
                    continue;
                }
                if (!left_do && !right_do) continue;
                if (!left_do) nlx = p.lx, nly = p.ly;
                if (!right_do) nrx = p.rx, nry = p.ry;
                if(!u[nlx][nly][nrx][nry]) {
                    u[nlx][nly][nrx][nry] = true;
                    st.push(POINT{nlx, nly, nrx, nry});
                }
            }

        }
        if (flag)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 30160
#BFSやなたぶん BFSって再帰呼び出しいるのかい？いやいらんだろう？

K = int(input())
runrun_num = 0

def bfs(s_list):
    global K,runrun_num
    new_s_list = []
    for s in s_list:
        new_int_min = int(s[-1])-1
        if s[-1]=='0':
            new_int_min = 0
        new_int_max = int(s[-1])+1
        if s[-1]=='9':
            new_int_max = 9
        for i in range(new_int_min,new_int_max+1):
            new_s = s+str(i)
            runrun_num+=1
            if K == runrun_num+9:
                print(new_s)
                return None
            else:
                new_s_list.append(new_s)
    bfs(new_s_list)

inp = [str(i) for i in range(1,10)]
if 1<=K and K<=9:
    print(K)
else:
    bfs(inp)


Measured memory_bytes: 10200
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n)
        cin >> a[i];

    ll seg1 = 0, seg2 = accumulate(a.begin(), a.end(), 0LL);
    ll minx = 1e18;
    REP(i, n-1){
        seg1 += a[i];
        seg2 -= a[i];
        minx = min(minx, abs(seg1 - seg2));
    }
    cout << minx << endl;
    return 0;
}

Measured memory_bytes: 1792
from itertools import accumulate
import sys
input = sys.stdin.readline

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P = accumulate(sorted(P, reverse=True))
for i, pi in enumerate(P):
    if pi + sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, m, d;
    cin >> n >> m >> d;

    cout << fixed << setprecision(12) << (double) (d == 0 ? n : 2*(n - d)) * (m - 1) / (n * n) << endl;

}


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

struct MapHeader {
	int w;
	int h;
};

MapHeader read_header() {
	std::string line;
	std::getline(std::cin, line);
	std::istringstream line_stream(line);
	MapHeader result;
	line_stream >> result.w >> result.h;
	return result;
}

struct SearchContext {
	MapHeader header;
	std::vector<bool> map;
	size_t count;

	SearchContext(MapHeader header)
		: header(header),
		count(0)
	{
		map.reserve(header.w * header.h);
	}

	size_t index(int x, int y) {
		return (size_t)header.w * y + x;
	}
};

void search(SearchContext& context, int x, int y) {
	if (x < 0 || x >= context.header.w || y < 0 || y >= context.header.h) return;

	size_t index = context.index(x, y);
	if (context.map[index]) return;

	context.map[index] = true;
	context.count++;
	
	search(context, x + 1, y);
	search(context, x - 1, y);
	search(context, x, y + 1);
	search(context, x, y - 1);
}

int main()
{
	while (true) {
		MapHeader header = read_header();
		if (header.w == 0 && header.h == 0) break;

		SearchContext context(header);
		int start_x, start_y;

		std::string line;
		line.reserve(header.w + 2);

		for (int y = 0; y < header.h; y++) {
			line.clear();
			std::getline(std::cin, line);

			for (int x = 0; x < header.w; x++) {
				switch (line[x]) {
				case '.':
					context.map.push_back(false);
					break;
				case '#':
					context.map.push_back(true);
					break;
				case '@':
					start_x = x;
					start_y = y;
					context.map.push_back(false);
					break;
				}
			}
		}

		search(context, start_x, start_y);
		std::cout << context.count << std::endl;
	}

    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(A, N - N / (A + B) * (A + B)) << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

if K == 0:
    print(N**2)
    exit()

ans = 0
for b in range(K+1, N+1):
    ans += (N//b)*(b-K)
    ans += max(0, N-((N//b)*b+K)+1)
    # print(b, ans)
print(ans)


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

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

L = sum(A)

ac = 0
for i in range(N):
  ac += A[i]
  if(ac >= L/2):
    key = i
    break

cost = 0
if(L%2 == 1):
  A[key] -= 1
  L -= 1
  cost = 1

ac = 0
for i in range(N):
  ac += A[i]
  if(ac >= int(L/2)):
    key = i
    break

if(ac == int(L/2)):
  print(cost)
else:
  right = ac - int(L/2)
  left = int(L/2) - (ac-A[key])
  cost += min(right, left)*2
  print(cost)


Measured memory_bytes: 26060