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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll xorn(ll n) {
    if (n%4 == 0)
        return n;
    else if (n%4 == 1)
        return 1;
    else if (n%4 == 2)
        return n+1;
    else 
        return 0;
}

int main() {
    fast;
    ll a, b;
    cin >> a >> b;
    ll ans = xorn(b);
    ans = ans ^ xorn(a-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a, b = na()
n = int(str(a) + str(b))
print("Yes" if (n**0.5).is_integer() else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n;
int x[100000], y[100000];
char d[100000];
vector<double> ts;

double solve (double t) {
    double Mx = -inf, mx = inf, My = -inf, my = inf;
    rep(i,n) {
        double tx = x[i], ty = y[i];
        if (d[i] == 'U') ty += t;
        if (d[i] == 'D') ty -= t;
        if (d[i] == 'R') tx += t;
        if (d[i] == 'L') tx -= t;
        Mx = max(Mx, tx);
        mx = min(mx, tx);
        My = max(My, ty);
        my = min(my, ty);
    }
    return (Mx-mx) * (My-my);
}

int main() {
    cin >> n;
    rep(i,n) {
        cin >> x[i] >> y[i] >> d[i];
    }
    ts.push_back(0.0);
    int dx = -inf, ux = -inf, cx = -inf;
    //up
    rep(i,n) {
        if (d[i] == 'U') ux = max(ux, y[i]);
        else if (d[i] == 'D') dx = max(dx, y[i]);
        else cx = max(cx, y[i]);
    }
    if (dx != -inf && cx != -inf && dx >= cx) ts.push_back(dx-cx);
    if (cx != -inf && ux != -inf && cx >= ux) ts.push_back(cx-ux);
    if (dx != -inf && ux != -inf && dx >= ux) ts.push_back((dx-ux)/2.0);
    //down
    dx = inf; ux = inf; cx = inf;
    rep(i,n) {
        if (d[i] == 'U') ux = min(ux, y[i]);
        else if (d[i] == 'D') dx = min(dx, y[i]);
        else cx = min(cx, y[i]);
    }
    if (dx != -inf && cx != -inf && dx >= cx) ts.push_back(dx-cx);
    if (cx != -inf && ux != -inf && cx >= ux) ts.push_back(cx-ux);
    if (dx != -inf && ux != -inf && dx >= ux) ts.push_back((dx-ux)/2.0);
    //right
    dx = -inf; ux = -inf; cx = -inf;
    rep(i,n) {
        if (d[i] == 'R') ux = max(ux, x[i]);
        else if (d[i] == 'L') dx = max(dx, x[i]);
        else cx = max(cx, x[i]);
    }
    if (dx != -inf && cx != -inf && dx >= cx) ts.push_back(dx-cx);
    if (cx != -inf && ux != -inf && cx >= ux) ts.push_back(cx-ux);
    if (dx != -inf && ux != -inf && dx >= ux) ts.push_back((dx-ux)/2.0);
    //left
    dx = inf; ux = inf; cx = inf;
    rep(i,n) {
        if (d[i] == 'R') ux = min(ux, x[i]);
        else if (d[i] == 'L') dx = min(dx, x[i]);
        else cx = min(cx, x[i]);
    }
    if (dx != -inf && cx != -inf && dx >= cx) ts.push_back(dx-cx);
    if (cx != -inf && ux != -inf && cx >= ux) ts.push_back(cx-ux);
    if (dx != -inf && ux != -inf && dx >= ux) ts.push_back((dx-ux)/2.0);
    double ans = (double)linf;
    rep(i,ts.size()) {
        ans = min(ans, solve(ts[i]));
    }
    printf("%.10f\n", ans);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

    int n,k,s;
    cn n>>k>>s;

    for (int i = 0; i <k; ++i)
    {
        ct s<<" ";
    }

    if(s==1000000000)s=1;
    else s++;

    for (int i =k ; i <n; ++i)
    {
        ct s<<" ";
    }
    nl;









    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();

		if (A <= C && C <= B) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23892
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    char s[4001];
    scanf("%s", s);
    vector<int> red, green, blue;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            red.emplace_back(i);
        else if (s[i] == 'G')
            green.emplace_back(i);
        else
            blue.emplace_back(i);
    }
    vector<pair<int, int>> brown, syan, purple, brown2, syan2, purple2;
    for (int i = 0; i < red.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (red[i] < green[j])
                brown.emplace_back(make_pair(red[i], green[j]));
            else
                brown2.emplace_back(make_pair(green[j], red[i]));
        }
    }
    for (int i = 0; i < green.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (green[i] < blue[j])
                syan.emplace_back(make_pair(green[i], blue[j]));
            else
                syan.emplace_back(blue[j], green[i]);
        }
    }
    for (int i = 0; i < blue.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (blue[i] < red[j])
                purple.emplace_back(make_pair(blue[i], red[j]));
            else
                purple.emplace_back(make_pair(red[j], blue[i]));
        }
    }
    ll cnt = 0;
    for (int i = 0; i < brown.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (brown[i].second - brown[i].first != blue[j] - brown[i].second && brown[i].second < blue[j])
                cnt++;
        }
    }
    for (int i = 0; i < syan.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (syan[i].second - syan[i].first != red[j] - syan[i].second && syan[i].second < red[j])
            {
                cnt++;
            }
        }
    }
    for (int i = 0; i < purple.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (purple[i].second - purple[i].first != green[j] - purple[i].second && purple[i].second < green[j])
                cnt++;
        }
    }

    for (int i = 0; i < brown2.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (brown2[i].second - brown2[i].first != blue[j] - brown2[i].second && brown2[i].second < blue[j])
                cnt++;
        }
    }
    for (int i = 0; i < syan2.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (syan2[i].second - syan2[i].first != red[j] - syan2[i].second && syan2[i].second < red[j])
            {
                cnt++;
            }
        }
    }
    for (int i = 0; i < purple2.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (purple2[i].second - purple2[i].first != green[j] - purple2[i].second && purple2[i].second < green[j])
                cnt++;
        }
    }
    printf("%lld\n",cnt);
}


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

typedef long long ll;

#define N 100010

int n,m,q;
char S[N];

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}


int main()
{
	scanf("%s",S+1);
	int len=(int)strlen(S+1);
	int Ans=0;
	for(int i=2;i<=len;i++)
	{
		if(S[i]==S[i-1])
			continue;
		Ans++;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 384
s = int(input())
a = [s]
for i in range(1000000):
    if a[i] % 2:
        a.append(3 * a[i] + 1)
    else:
        a.append(a[i] // 2)

    if len(set(a)) != len(a):
        print(i + 2)
        break


Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 2147483647
#define Max 100000
#define NTL -1
#define min(a,b) ((a>b)?b:a)
  int a[Max];
void find(int s,int t){
    int mm=N;
    for(int k=s;k<=t;k++){
      if(a[k]<mm){
        mm=a[k];
      }
    }
    printf("%d\n",mm);
}
int main(){
  int n,i,j,q;
  int ord,x,y;

  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    a[i]=N;
  }
  while(q--){
    scanf("%d%d%d",&ord,&x,&y);
    if(ord==0){
      a[x]=y;
    }else{
      find(x,y);
    }
  }
  return 0;
}


Measured memory_bytes: 2172
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define x first
#define y second
namespace WoHaoLajIA__x_x_
{
	typedef long long ll;
	typedef std::pair<ll,ll> pii;
	const int N=100100;
	ll ans[N],q[N],cnt[N];
	std::queue<pii> dl;
	int n,m,dn;
	void initialize()
	{
		int tmp;
		scanf("%d%d",&n,&m);
		dn=n,q[tmp=1]=n;
		for(ll x;m--;)
		{
			scanf("%lld",&x);
			while(tmp && x<=q[tmp])tmp--;
			q[++tmp]=x;
		}
		n=q[1],m=tmp;
	}
	void solve()
	{
		initialize();
		cnt[m]=1;
		for(int i=m;i;i--)
		{
			if(cnt[i])dl.push(pii(q[i],cnt[i]));

			for(pii p;!dl.empty();)
			{
				p=dl.front();dl.pop();
				if(p.x<=n){ans[p.x]+=p.y;continue;}
				int x=std::lower_bound(q+1,q+m+1,p.x)-q-1;

				cnt[x]+=(p.x/q[x])*p.y;

				if(p.x%q[x])dl.push(pii(p.x%q[x],p.y));
			}
		}



		for(int i=n;i;i--)ans[i-1]+=ans[i];
		for(int i=1;i<=dn;i++)
			printf("%lld\n",ans[i]);
		printf("\n");
	}
}
int main()
{
	WoHaoLajIA__x_x_::solve();
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using P = std::pair<int, int>;
using ll = long long ;
template<class T> inline void chmax(T& a, T b) {if(a < b) a = b; }
template<class T> inline void chmin(T& a, T b) {if(a > b) a = b; }

int main(){
	int N;
	std::cin >> N;
	std::vector<char> col(N);
	rep(i, N){
		std::cin >> col[i];
	}

	int l = 0, r = N-1;
	int res = 0;
	while(l < r){
		if(col[l] == 'W' && col[r] == 'R'){
			l++;
			r--;
			res++;
		}else{
			if(col[l] == 'R') l++;
			if(col[r] == 'W') r--;
		}
	}
	std::cout << res << std::endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    int mx=0;
    int s=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        s+=x;
        mx=max(mx,x);
    }
    s-=mx;
    cout<<s+mx/2<<"\n";
    return 0;
}


Measured memory_bytes: 256
// atcoder/aising2020/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  map<lli, lli> m;
  for (lli x = 1; x <= 100; ++x) {
    for (lli y = 1; y <= 100; ++y) {
      for (lli z = 1; z <= 100; ++z) {
        lli n = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
        ++m[n];
      }
    }
  }

  lli n;
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) {
      cout << m[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6016
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;


//xを素因数分解する
//例えば60 = 5*3*2*2 であれば[(5,1),(3,1),(2,2)]を返す
vector<pair<LL,LL>> factorial(LL x){
	vector<pair<LL,LL>> ret;
	for(LL i=2;i*i<=x;i++){
		if(x%i==0){
			LL counter = 0;
			while(1){
				if(x%i!=0) break;
				x /= i;
				counter++;
			}
			ret.push_back(make_pair(i,counter));
		}
	}
	if(x!=1) ret.push_back(make_pair(x,1));
	return ret;
}

LL N;

LL ans = 0;

void solve(){
	//数値1~iまでの和をaccum[i]とおく
	//ただしaccum[0] = 0
	vector<LL> accum(100,0);
	for(int i=1;i<100;i++) accum[i] = accum[i-1] + i;

	vector<pair<LL,LL>> divisor = factorial(N);
	for(int i=0;i<divisor.size();i++){
		LL prime = divisor[i].first;
		LL num = divisor[i].second;

		LL n = int(upper_bound(accum.begin(),accum.end(),num)-accum.begin()) - 1LL;
		ans += n;
	}
}

int main(){
    cin >> N;

    solve();
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n;
  cin>>n;
  int mi=0;
  bool zero=false;
  int mina=INF;
  int sum=0;
  rep(i,n){
    int a;
    cin>>a;
    mi+=(a<0);
    mina=min(mina,abs(a));
    zero|=(a==0);
    sum+=abs(a);
  }

 
  if(mi%2&&!zero){
    cout<<sum-2*mina<<endl;
  }else{
    cout<<sum<<endl;
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<LL,LL> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=2e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL dp[110000];
vector<P> v1;

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		v1.push_back(make_pair(a+b,a-b));
	}
	sort(v1.begin(),v1.end());
	for(i=0;i<n;i++){
		auto itr=upper_bound(v1.begin(),v1.end(),make_pair(v1[i].second,MAX));
		a=distance(v1.begin(),itr);
		dp[i+1]=max(dp[i],dp[a]+1);
	}
	cout<<dp[n]<<endl;
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,z=0,k,n;

cin>>n;
db ans=0;
pll a[n];
rep(i,0,n,1)	cin>>a[i].ff>>a[i].ss;
sort(a,a+n);
 do {  
        z++;	db y=0;
        rep(i,0,n-1,1){
        	y+=sqrt(( a[i].ff- a[i+1].ff)*( a[i].ff- a[i+1].ff)+( a[i].ss- a[i+1].ss)*( a[i].ss- a[i+1].ss));
        }
        // ce(y)
        ans+=y;
        // ce(ans)
    } while(next_permutation(a,a+n));  

// ce(z)
cout_p(ans/z, 7);
}


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

int main(){
	int n;
	int ans=100000;
	cin>>n;
	for(int i=0;i<n;++i){
		ans=ans*1.05;
		if(ans%1000>0) ans=ans-ans%1000+1000;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  
  vector<string> words(N);
  cin >> words.at(0);
  for(int i = 1; i < N; ++i)
  {
    string word;
    cin >> word;
    if(words.at(i - 1)[words.at(i - 1).length() - 1] == word[0] &&
       count(words.begin(), words.end(), word) == 0)
    {
      words.at(i) = word;
    }
    else
    {
      cout << "No" << endl;
      return 0;
    }   
  }
  
  cout << "Yes" << endl;
  return 0;
}    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,a,mx,d,d1;

    cin>>k>>n;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
    if(i==0){
        d=abs(v[i]-v[n-1]);
        d1=abs(v[i]-0)+abs(k-v[i+1]);
        mx=min(d,d1);
    }
    else if(i==n-1)
    {
        d=abs(v[i]-k)+abs(0-v[i-1]);
        d1=abs(v[i]-v[0]);
        d=min(d,d1);
        mx=min(d,mx);
    }
    else{
        d=abs(v[i]-k)+abs(0-v[i-1]);
        d1=abs(v[i]-0)+abs(k-v[i+1]);
        d=min(d,d1);
        mx=min(d,mx);
    }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 1528
// AtCoder :: Beginner Contest 177 :: B - Substring 
// https://atcoder.jp/contests/abc177/tasks/abc177_b

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string S, T;
    getline(cin, S);
    getline(cin, T);
    int soln{numeric_limits<int>::max()};
    // For the substring of S[i, j] how many changes must be made?
    for (size_t i{0}, j{T.size()-1}; j < S.size(); i++, j++) {
        int changes{0};
        for (size_t k{i}, l{0}; k <= j; ++k, ++l) {
            if (S[k] != T[l]) {
                changes++;
            }
        }
        soln = min(changes, soln);
    }
    cout << soln << "\n";
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3652
long gcd(long a,long b){
  if(b==0) return a;
  return gcd(b,a%b);
}

long lcm(long a, long b){
  return (a*b)/gcd(a,b);
} 
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  long a,b; cin>>a>>b;
  cout<<lcm(a,b)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
#define N 200000 + 5
 
int n, A[N], F[N];
LL k, l, r;
 
bool Check(LL x)
{
	LL t = 0;
	for (int i = 1; i <= n; i ++)
	{
		t += max(0LL, A[i] - x / F[i]);
		if (t > k)
			return false;
	}
	return true;
}
 
int main()
{
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i ++)
		scanf("%d", A + i);
	for (int i = 1; i <= n; i ++)
		scanf("%d", F + i);
	sort(A + 1, A + n + 1);
	sort(F + 1, F + n + 1);
	reverse(F + 1, F + n + 1);
	for (int i = 1; i <= n; i ++)
		r = max(r, 1LL * A[i] * F[i]);
	
   LL ans=r;
  	while (l <= r)
	{
		LL mid = l + r >> 1;
		if (Check(mid))
        {
         	 r = mid-1;
        	ans=min(ans,mid);
        }
		else l = mid+1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(void)
{
	int A, B,wa=0;
	scanf("%d", &A); scanf("%d", &B);
	for (int i = 0; i < 2; i++) {
		if (A > B) {
			wa += A;
			A--;
		}
		else {
			wa += B;
			B--;
		}
	}
	printf("%d", wa);
	return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){

    int N = 0;
    int a[11];

    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    
    vector<int> v(begin(a),a+N);
    sort(v.begin(),v.end());

    int sum = 0;
    int Longest = v[N-1];
    for(int i=0;i<N-1;i++){
        sum += v[i];//if(v[i] != Longest)
    }

    if(sum > Longest){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100000],b[100000],c[100000],dp[100000][3];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
		dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

template <class T> struct Dijkstra {

    struct Edge{
        int to;
        T cost;
        Edge(int _to, T _cost) : to(_to), cost(_cost) {}
    };
    
    const T INF = numeric_limits<T>::max() / 2;
    vector< vector< Edge > > G;
    vector< T > d;
    Dijkstra (int n) : G(n), d(n) {}

    void add_directed_edge(int a, int b, T c) {
        G[a].push_back(Edge(b,c));
    }
    
    void add_undirected_edge(int a, int b, T c) {
        G[a].push_back(Edge(b,c));
        G[b].push_back(Edge(a,c));
    }

    void init(int s) {
        priority_queue< pair<T,int>,vector< pair<T,int> >, greater< pair<T,int> > > que;
        fill(d.begin(), d.end(), INF);
        d[s] = 0;
        que.push(make_pair(0,s));
        while (!que.empty()){
            pair<T,int> p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); i++) {
                Edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
    
    T dist(int a) {
        return d[a];
    }
    
}; 

int N,M;
vector<int> p,q,c;
vector<int> G[100010];
map< pair<int,int>, int> newv;
Dijkstra<int> inst(500010);

int main() {

    cin >> N >> M;
    p.resize(M);
    q.resize(M);
    c.resize(M);
    REP(i,M) cin >> p[i] >> q[i] >> c[i];

    REP(i,N) {
        newv[make_pair(i + 1, i + 1)] = 0;
    }

    REP(i,M) c[i] += 200000;

    REP(i,M) {
        newv[make_pair(p[i],c[i])] = 0;
        newv[make_pair(q[i],c[i])] = 0;
        G[p[i]].push_back(c[i]);
        G[q[i]].push_back(c[i]);
    }

    int cnt = 0;
    for (auto itr = newv.begin(); itr != newv.end(); itr++) {
        itr -> second = cnt++;
    }

    int start = -1, end = -1;
    for (int i = 1; i <= N; i++) {
        REP(j,G[i].size()) {
            int a = newv[make_pair(i,i)];
            int b = newv[make_pair(i,G[i][j])];
            inst.add_undirected_edge(a,b,1);
        }
    }

    REP(i,M) {
        int a = newv[make_pair(p[i],c[i])];
        int b = newv[make_pair(q[i],c[i])];
        inst.add_undirected_edge(a,b,0);
    }

    int from = newv[make_pair(1,1)];
    int to = newv[make_pair(N,N)];

    inst.init(from);
    int ans = inst.dist(to);

    if (ans == inst.INF) {
        cout << -1 << endl;
    } else {
        cout << ans / 2 << endl;
    }

    return 0;
}




Measured memory_bytes: 72824
import sys
sys.setrecursionlimit(10**6)
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
memo=[-1]*N
def rec(x):
  if memo[x]>=0:
    return memo[x]
  res=0
  if not G[x]:
    memo[x]=0
    return 0
  for y in G[x]:
    res=max(rec(y),res)
  memo[x]=res+1
  return memo[x]
for i in range(N):
  rec(i)
print(max(memo))

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



int Rank[1000005];
int Tmp[1000005];
int kc,len;

bool compare_sa(int i,int j){
  if(Rank[i]!=Rank[j])return Rank[i]<Rank[j];
  else{
    int ri=i+kc<=len?Rank[i+kc]:-1;
    int rj=j+kc<=len?Rank[j+kc]:-1;
    return ri<rj;
  }
}

void construct_sa(char* S,int *sa){
  len=strlen(S);
  for(int i=0;i<=len;i++){
    sa[i]=i;
    Rank[i]=i<len?S[i]:-1;
  }
  for(kc=1;kc<=len;kc*=2){
    sort(sa,sa+len+1,compare_sa);
    Tmp[sa[0]]=0;
    for(int i=1;i<=len;i++){
      Tmp[sa[i]]=Tmp[sa[i-1]]+compare_sa(sa[i-1],sa[i]);
    }
    for(int i=0;i<=len;i++)Rank[i]=Tmp[i];
  }
}


int n,m;
char str[1000005];
char t[1000005];
int sa[1000005];

int main(){
  scanf("%s",str);
  n=strlen(str);
  construct_sa(str,sa);
  scanf("%d",&m);
  while(m--){
    scanf("%s",t);
    int k=strlen(t);
    int l=0,r=n+1,m;
    while(l+1<r){
      m=(l+r)/2;
      if(strncmp(str+sa[m],t,k)<=0)l=m;
      else r=m;
    }
    printf("%d\n",(strncmp(str+sa[l],t,k)==0));
  }
  return 0;
}

Measured memory_bytes: 14900
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  int n;
  scanf("%d",&n);
  int sm=0; 
  vector<int>ans;
  for(int i=1;sm+i<=n;i++){
    ans.push_back(i);
    sm+=i;
  }
  int rem=n-sm;
  for(int i=0;i<rem;i++){
    ans[int(ans.size())-1-i]++;
  }
  for(int x:ans){
    printf("%d\n",x);
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll max = 1e5;
    ll cnt[max+1];
    cnt[0] = 0;
    cnt[1] = 1;
    for(int i = 2; i <= n; i++){
        ll tmp_min = cnt[i-1] + 1;
        int idx = 1;
        rep1(k,6){
            idx *= 6;
            if(i - idx < 0) break;
            ll tmp_cnt = cnt[i-idx] + 1;
            tmp_min = min(tmp_cnt,tmp_min);
        }
        idx = 1;
        rep1(k,5){
            idx *= 9;
            if(i - idx < 0) break;
            ll tmp_cnt = cnt[i-idx] + 1;
            tmp_min = min(tmp_cnt,tmp_min);
        }
        cnt[i] = tmp_min;
    }

    cout << cnt[n] <<endl;
    return 0;
}

Measured memory_bytes: 3748
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():
    a, b = LI()
    if (a + b) % 2 == 0:
        print((a+b)//2)
    else:
        print("IMPOSSIBLE")

main()



Measured memory_bytes: 6472
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PP;

int N, T[101], M, P[101], X[101];
int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> T[i];
	}
	cin >> M;
	REP(i, 0, M) {
		cin >> P[i] >> X[i];
	}
	int sum = 0;
	REP(i, 0, N) {
		sum += T[i];
	}
	REP(i, 0, M) {
		cout << sum - (T[P[i] - 1] - X[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int  M = 1e9+7;
int a[22][22];
int n;
ll dp[21][(1<<21)-1];
ll solve(int i,ll bitmask)
{
  //cout<<i<<" "<<bitmask<<endl;
  if(i==n) return 1;
  if(dp[i][bitmask]!=-1) return dp[i][bitmask];
  ll ans = 0;
  for(int j=0;j<n;j++)
  {
    if(a[i][n-j-1] == 1 && bitmask&(1<<j))
    {
      ans = (ans+solve(i+1,bitmask-(1<<j)))%M;
    }
  }
  dp[i][bitmask] = ans;
  return ans;
}
int main() {
  for(int i=0;i<21;i++)
  {
    for(int j=0;j<(1<<21)-1;j++)
    {
      dp[i][j]=-1;
    }
  }
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  cout<<solve(0,(1<<n)-1);
  return 0;
}

Measured memory_bytes: 347688
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    
    int cnt = 0;
    for(int i=1; i<=n; i+=2){
        int d = 0;
        for(int j=1; j<=i; j++){
            if(i % j == 0) d++;
        }
        if(d == 8) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int i = 0, j = n-1;
  int ans = 0;
  while (i < j) {
      if (s[i] == 'W' && s[j] == 'R') {
          s[i] = 'R';
          s[j] = 'W';
          ans++;
          i++;
          j--;
      }
      else if (s[i] == 'W' && s[j] == 'W') j--;
      else if (s[i] == 'R' && s[j] == 'R') i++;
      else if (s[i] == 'R' && s[j] == 'W') {
          i++;
          j--;
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3724
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
A = [-a for a in A]

A.sort()

from heapq import *

ans = -A[0]

q = A[:2][:]
heapify(q)
q[0] = q[-1]

for a in A[2:]:
    ans += -q[0]
    t1 = heappop(q)
    t1 = max(t1, a)
    heappush(q, t1)
    heappush(q, a)
print(ans)

Measured memory_bytes: 31396
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)

Measured memory_bytes: 32476
#include <bits/stdc++.h>
using namespace std;
string s,t;
long a[5000][5000];
void lcs()
{
    for(long i=0;i<5000;i++)
        for(long j=0;j<5000;j++)
            a[i][j]=0;
    //s.insert(0,1,' ');
    //t.insert(0,1,' ');
    for(long i=1;i<=s.size();i++)
        for(long j=1;j<=t.size();j++)
    {
        if(s[i-1]==t[j-1]) a[i][j]=a[i-1][j-1]+1;
        if(s[i-1]!=t[j-1]) a[i][j]=max(a[i-1][j],a[i][j-1]);
    }
    
    string kq;
    long n=s.size(),m=t.size();
    while(n>0 && m>0)
    {
        if(s[n-1]==t[m-1])
        {
            kq.push_back(s[n-1]);
            --n;
            --m;
        }
         else if(a[n][m-1] > a[n - 1][m]) -- m;
        else -- n;
    }
    reverse(kq.begin(),kq.end());
    cout<<kq;
}
int main()
{
   cin>>s>>t;
   lcs();
}


Measured memory_bytes: 195584
def main():
    N, K = map(int, input().split())
    mod = 10**9 + 7
    ans1 = (N + 2 - K) % mod
    ans2 = ((N + 1) * (N + 1) * (N + 2) // 2 - (N + 1) * K  * (K - 1) // 2) % mod
    ans3 = ((N + 1) * (N + 2) * (2 * N + 3) // 6 - (K - 1) * K * (2 * K - 1) // 6) % mod
    ans = (ans1 + ans2 - ans3) % mod
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
N=int(input())
onetwofour=[0,0,0]
ans="No"
for i in [int(j) for j in input().split()]:
    if i%4==0:
        onetwofour[2]+=1
    elif i%2==0:
        onetwofour[1]+=1
    else:
        onetwofour[0]+=1
if onetwofour[2]>=onetwofour[0]:
    ans="Yes"
elif onetwofour[1]==0 and onetwofour[2]==onetwofour[0]-1:
    ans="Yes"
print(ans)

Measured memory_bytes: 14252
N = int(input())

sosuu = []
for i in range(2, N + 1):
    flag = True
    for s in sosuu:
        if i % s == 0:
            flag = False
            break
    if flag:
        sosuu.append(i)

disolvers = [[], []]
for i in range(2, N + 1):
    ret = [0] * len(sosuu)
    t = i
    while t > 1:
        for i, s in enumerate(sosuu):
            if t % s == 0:
                t = t // s
                ret[i] += 1
                break
    disolvers.append(ret)

# 約数の数
# Nを素因数分解したときに、 n1 ** p1 * n2 ** p2 .... ni * pi とすると
# (p1 + 1) * (p2 + 1) * ... * (pi + 1) となる
# ここで 約数個数75 を分解すると 5, 5, 3
# つまり、数字M　は
#   素数1 ** 4 * 素数2 ** 4 * 素数3 ** 2
#   素数1 ** 24 * 素数2 ** 2
#   素数1 ** 14 * 素数3 ** 4
#   素数1 ** 75
# のいずれかで表せる必要がある

# 9! を素因数分解すると、 2**7, 3**4, 5 ** 1, 7 ** 1
#  > 上記の (4, 4, 2) を満たせない。
# 10! は、 2**8, 3**4, 5 ** 2, 7 ** 1
#  > (4, 4, 2) を満たすパターンが存在する  (2**4, 3**4, 5**2)

d_count = [0] * len(sosuu)
for i in range(2, N + 1):
    di = disolvers[i]
    for i, d in enumerate(di):
        d_count[i] += d

created_numbers = []
def count_numbers(depth, pow_count, used_idx, curr):
    if depth == len(pow_count):
        di = disolvers[N]
        t = 1
        for i in range(len(pow_count) - 1, -1, -1):
            idx = curr[i]
            t = t * (sosuu[idx] ** pow_count[i])
        if t in created_numbers:
            return 0
        created_numbers.append(t)
        return 1
    num = pow_count[depth]
    ret = 0
    for i in range(len(d_count)):
        n = d_count[i]
        if n >= num and i not in used_idx:
            u2 = used_idx + [i]
            ret += count_numbers(depth + 1, pow_count, u2, curr + [i])
    return ret

total = 0
total += count_numbers(0, [4, 4, 2], [], [])
total += count_numbers(0, [24, 2], [], [])
total += count_numbers(0, [14, 4], [], [])
total += count_numbers(0, [74], [], [])

print(total)

Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
#include <tuple>
#include <cmath>
#include <chrono>
#include <map>

using namespace std;

using ll = long long;

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    reverse(s.begin(), s.end());
    
    int b = count(s.begin(), s.end(), '#');
    
    vector<int> c(n + 1);
    
    for (int i = 0; i < n; i++) {
        c[i + 1] = c[i] + (s[i] == '#');   
    }
    
    int ans = n;
    
    for (int i = 0; i <= n; i++) {
        ans = min(ans, i - c[i] + b - c[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1404
s = input()
from collections import Counter
x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()
for i in range(len(s)-1,-1,-1):
    cnt[total] += 1
    total = total + int(s[i])*x
    total %= mod
    ans += cnt[total]
    x = x*10%2019
print(ans)

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;


void solve_test()
{
    ll n, x, m;
    cin >> n >> x >> m;
    if(m == 1)
    {
        cout << 0;
        return;
    }
    ll pos[m+1];
    for(int i=0; i<=m; i++)
    {
        pos[i] = -1;
    }
    ll val = x;
    ll ans = 0;
    ll period = 1;
    ll sum[m+1];
    ll st = n;
    memset(sum, 0, sizeof(sum));
    ll diff = 0;
    for(ll i=0; i<min(n, m); i++)
    {
        if(pos[val] != -1)
        {
            period = i - pos[val];
            st = pos[val];
            diff = sum[i-1];
            if(st > 0)
            {
                diff -= sum[st-1];
            }
            break;
        }
        sum[i] += val;
        pos[val] = i;
        val = (val*val) % m;
        if(i)
        {
            sum[i] += sum[i-1];
        }
    }

//    for(ll i=0; i<min(n, m); i++)
//    {
//        cout << sum[i] << " ";
//    }
//    cout << "\n";
//    what_is(st);
    if(st > 0)
        ans += sum[st-1];
    if (st != n)
    {
        ll q = (n - st) / period;
        ll r = (n - st) % period;
        what_is(ans);

        ans += q * diff;
//        what_is(st);
//        what_is(val);
//        what_is(period);
//        what_is(diff);
//        what_is(q);
//        what_is(r);
        for(ll i=0; i<r; i++)
        {
            ans += val;
            val = (val * val) % m;
        }
    }

    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 5188
#include <cstdio>
#include <algorithm>
using namespace std;

struct Point
{
    double x,y;
    Point(){}
    Point(double _x,double _y)
    {
        x = _x;
        y = _y;
    }
    Point operator -(const Point& b)const
    {
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point& b)const
    {
        return x*b.y-y*b.x;
    }
};

Point pl[30000],pr[30000];
int cnt[30000];
int n,m,w,h,s;

int calc(int a)
{
    if (a < 0)  return 0;
    return ((pl[a].y+pr[a].y)*w);
}

int main()
{
    while (scanf("%d",&n),n)
    {
        scanf("%d%d%d%d",&m,&w,&h,&s);
        for (int i = 0;i < m;i++)
        {
            scanf("%lf%lf",&pl[i].y,&pr[i].y);
            pl[i].x = 0;
            pr[i].x = w;
            cnt[i] = 0;
        }
        for (int i = 0;i < n;i++)
        {
            Point p;
            scanf("%lf%lf",&p.x,&p.y);
            int l,r,mid;
            l = 0,r = m-1;
            while (l < r)
            {
                mid = l+r>>1;
                if ((p-pl[mid])*(pr[mid]-pl[mid]) > 0)
                    r = mid;
                else
                    l = mid+1;
            }
            cnt[l]++;
            //printf("l = %d\n",l);
        }
        int pre = -1,res = 0,tot = 0;
        for (int i = 0;i < m;i++)
        {
            tot += cnt[i];
            while (calc(i)-calc(pre) > (w*h-s)*2)
            {
                tot -= cnt[pre+1];
                pre++;
            }
            //printf("%d %d %d\n",i,pre,tot);
            res = max(res,tot);
        }
        printf("%d\n",n-res);
    }
    return 0;
}

Measured memory_bytes: 2120
#include <iostream>

using namespace std;

//global variances
long long N,Q,K;
int arr[100000];
//prototype
void input();

int main()
{
    input();
    
    if(K > Q)
    {
        for(int i = 0; i < N; ++i)
        {
            cout << "Yes" << endl;
        }
    }
    else
    {
        for(int i = 0; i < N; ++i)
        {
            if(arr[i] > 0) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    
    
    return 0;
}

void input()
{
    cin >> N >> K >> Q;
    for (int i = 0; i < N; ++i)
    {
        arr[i] = K-Q;
    }
    
    int tmp;
    for (int i = 0; i < Q; ++i)
    {
        cin >> tmp;
        ++arr[tmp-1];
    }
}

Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A;
  int B;
  rd(A);
  rd(B);
  wt_L(6-A-B);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// {
//   int A, B;
//   rd(A,B);
//   wt(6-A-B);
// }


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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayLong();
            var N = input[0];
            var A = input[1];
            var B = input[2];
            var AB = A + B;
            var ans = 0L;
            if (N % AB == 0) ans = A * (N / AB);
            else
            {
                var rem = N % AB;
                ans += A * (N / AB);
                if (rem >= A) ans += A;
                else ans += rem;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a,b;
	long long int ct=0;
	cin>>a>>b;
	int c[a];
	forr(i,0,b)
	{
		cin>>c[i];
		ct+=c[i];
	}
	if(ct>a)
		cout<<-1;
	else
		cout<<a-ct;
	
	return 0;	
}

Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<29) - 1;

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

    int N, M, S, G1, G2;
    while(cin >> N >> M >> S >> G1 >> G2, N|M|S|G1|G2){
        S--; G1--; G2--;
        vector<vector<int>> G(N, vector<int>(N, INF));
        for(int i=0; i<N; i++)
            G[i][i] = 0;
        while(M--){
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            b1--; b2--;
            G[b1][b2] = c;
        }
        
        for(int k=0; k<N; k++)
            for(int i=0; i<N; i++)
                for(int j=0; j<N; j++)
                    G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
        
        int ans = INF;
        for(int i=0; i<N; i++){
            ans = min(ans, G[S][i] + G[i][G1] + G[i][G2]);
        }
        cout << ans << endl;
    }
    
    
    return 0;
}

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

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

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[i] / 2;
        a[i] %= 2;
        if(i + 1 < n){
            ans += a[i] && a[i + 1];
            a[i + 1] -= a[i] && a[i + 1];
        }
    }
    cout << ans << "\n";
}

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

int main() {
  string a,b;cin>>a>>b;
  int c=a.size(),d=b.size();
  if(c-d==1){
    rep(i,d)cout<<a[i]<<b[i];
    cout<<a[c-1]<<endl;
  }
  else {
    rep(i,c)cout<<a[i]<<b[i];
    cout<<endl;
  }
}

Measured memory_bytes: 3600