akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define PI 3.14159265358979
#define ll long long
using namespace std;

int Msquare_int(int x)
{
	return (ll)x* (ll)x% MOD_P;
}

int Mpower_int(int x, int e)
{
	if (e == 1) {
		return x;
	}
	if (e % 2) {
		return (int)((ll)(Msquare_int(Mpower_int(x, (e - 1) / 2))) * (ll)x % MOD_P);
	}
	return Msquare_int((Mpower_int(x, e / 2)) % MOD_P);
}

int inverse(int x, int y = MOD_P)
{
	return Mpower_int(x, y - 2);
}

ll permitation(int n)
{
	ll p = 1LL;
	for (ll i = 2LL; i <= n; i++) {
		p *= i;
		p %= MOD_P;
	}

	return p;
}

int main()
{
	int x, y;
	cin >> x >> y;

	if ((2 * y - x) % 3 || (2 * x - y) % 3 || (2 * y - x) < 0 || (2 * x - y) < 0) {
		printf("0");
	} else {
		int a = (2 * y - x) / 3;
		int b = (2 * x - y) / 3;
		ll pa = permitation(a);
		ll pb = permitation(b);
		ll ps = permitation(a + b);
		//printf("[%lld,%lld,%lld]\n", pa, pb, ps);
		ps *= (ll)inverse(pa);
		ps %= MOD_P;
		ps *= (ll)inverse(pb);
		ps %= MOD_P;
		printf("%lld", ps);
	}

	return 0;
}



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

int main() {
  string s,t;
  cin >> s >> t;
  for(int i=0; i<s.length(); i++){
    if(s.at(i) != t.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> edge;
typedef pair<int,edge> qdata;
int main(){
    double x1,x2,x3,y1,y2,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double S = abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;
    double a = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    double b = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    double c = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    double m = max(a,max(b,c));
    double sum = a+b+c;
    double ans = 2.0*m*S/(m*sum+4.0*S);
    printf("%.12lf\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  rep(i, m) cin >> p[i].first >> p[i].second;

  sort(p.begin(), p.end());
  
  int ans = 0;
  vector<bool> used(n, false);
  pair<int, int> res = {0, 0};
  rep(i, m) {
    if (used[p[i].first]) continue;
    used[p[i].first] = true;
    if (p[i].first >= res.second) {
      ans++;
      res = p[i];
    }
    else {
      res.first = p[i].first;
      res.second = min(res.second, p[i].second);
    }
  }

  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 1024
N,K=map(int,input().split())
D=list(map(int,input().split()))
number=[i for i in range(10) if i not in D]

for i in range(N,N*10):
    c=0
    for j in str(i):
        if int(j) not in number:
            c=1
            break
    if c==0:
        print(i)
        break

Measured memory_bytes: 40668
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <functional>

using namespace std;

const int dx[] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int A[9];
int dp[10001];
int rd[10001];
int m;

int f(int n) {
    if(n < 0) return -1e9;
    if(n == 0) return 0;
    if(dp[n] != -1) return dp[n];
    int mx = -1e9;
    for(int j = m - 1; j >= 0; --j)
        if(mx < f(n - dx[A[j] - 1]) + 1) {
            mx = f(n - dx[A[j] - 1]) + 1;
            rd[n] = A[j];
            
        }

    return dp[n] = mx;
}

int main() {
    int n; cin >> n >> m;
    for(int i = 0; i < m; ++i)
        cin >> A[i];
    sort(A, A + m);
    
    memset(dp, -1, sizeof dp);
    
    f(n);
    while(n > 0) {
        cout << rd[n];
        n -= dx[rd[n] - 1];
    }
    
    return 0;
}

Measured memory_bytes: 384
N = int(input())
x,l = [],[]
for _ in range(N):
  t1,t2 = list(map(int, input().split()))
  x.append(t1)
  l.append(t2)

width = []
for i in range(N):
  width.append([x[i]-l[i],x[i]+l[i]])

width = sorted(width, key=lambda x: x[1])
res = N
for i in range(1, N):
  if width[i-1][1] > width[i][0]:
    width[i][1] = width[i-1][1]
    res -= 1

print(res)


Measured memory_bytes: 29988
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
def sumOfArithmeticSequence(a, b):
    return (a + b) * (b - a + 1) // 2

def solve(N, K):
    ret = ModInt(0)
    for i in range(K, N + 2):
       ret += sumOfArithmeticSequence(N - i + 1, N) - sumOfArithmeticSequence(0, i - 1) + 1
    return ret


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))

Measured memory_bytes: 68252
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	string s;
	cin>>n>>m>>s;
	int pos=n;
	vector<int> ans;
	while(pos!=0)
	{
		for(int i=m;i>=0;i--)
		{
			if(i==0)
			{
				ans.push_back(-1);
				pos=0;
				break;
			}
			if(pos-i<0) continue;
			if(s[pos-i]=='0')
			{
				ans.push_back(i);
				pos-=i;
				break;
			}
		}
	}
	if(ans.back()==-1) cout<<-1<<endl;
	else
	{
		for(vector<int>::reverse_iterator it=ans.rbegin();it!=ans.rend();it++) cout<<*it<<' ';
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1096
N = input()

if N[-1] == "2" or N[-1] == "4" or N[-1] == "5" or N[-1] == "7" or N[-1] == "9":
    print("hon")
elif N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
    print("pon")
else:
    print("bon")



Measured memory_bytes: 8972
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N=2e5+10,M=(1<<19)+10,mod=924844033;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],hd[N],tot=1;
void adde(int x,int y)
{
	++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;
}
int sz[N];
void dfs(int x,int ffa)
{
	sz[x]=1;
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(y==ffa) continue;
		dfs(y,x),sz[x]+=sz[y];
	}
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,LL b,int mod){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}
int ginv(int a,int mod){return fpow(a,mod-2,mod);}
int rdr[M],W[20],iW[20];
void ntt(int *a,int n,bool op)
{
	int l=0,x,y;
	while(1<<l<n) ++l;
	for(int i=0;i<n;++i)
	{
		rdr[i]=(rdr[i>>1]>>1)|((i&1)<<(l-1));
		if(i<rdr[i]) swap(a[i],a[rdr[i]]);
	}
	for(int i=1,p=0;i<n;i<<=1,++p)
	{
		int ww=op?W[p]:iW[p];
		for(int j=0;j<n;j+=i<<1)
			for(int k=0,w=1;k<i;++k,w=1ll*w*ww%mod)
				x=a[j+k],y=1ll*a[j+k+i]*w%mod,a[j+k]=(x+y)%mod,a[j+k+i]=(x-y+mod)%mod;
	}
	if(!op) for(int i=0,w=ginv(n,mod);i<n;++i) a[i]=1ll*a[i]*w%mod;
}
int p1[M],p2[M];
void MUL(int *a,int n,int *b,int m)
{
	int len=1;
	while(len<=n+m) len<<=1;
	memcpy(p1,a,sizeof(int)*n),memcpy(p2,b,sizeof(int)*m);
	ntt(p1,len,1),ntt(p2,len,1);
	for(int i=0;i<len;++i) p1[i]=1ll*p1[i]*p2[i]%mod;
	ntt(p1,len,0);
	memcpy(a,p1,sizeof(int)*n);
	memset(p1,0,sizeof(int)*len),memset(p2,0,sizeof(int)*len);
}
int n,k,cn[N],fac[N],iac[N],an[N],aa[N],bb[N];
int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}

int main()
{
	for(int i=1,p=0;p<20;i<<=1,++p)
		W[p]=fpow(5,(mod-1)/(i<<1),mod),iW[p]=ginv(W[p],mod);
	fac[0]=1;
	for(int i=1;i<=N-10;++i) fac[i]=1ll*fac[i-1]*i%mod;
	iac[N-10]=ginv(fac[N-10],mod);
	for(int i=N-10;i;--i) iac[i-1]=1ll*iac[i]*i%mod;
	n=rd();
	for(int i=1;i<n;++i) adde(rd(),rd());
	dfs(1,0);
	for(int i=2;i<=n;++i) ++cn[sz[i]];
	for(int i=1;i<=n;++i) an[i]=1ll*C(n,i)*n%mod;
	for(int i=0;i<=n;++i) aa[n-i]=1ll*cn[i]*fac[i]%mod;
	for(int i=0;i<=n;++i) bb[i]=iac[i];
	MUL(aa,n+1,bb,n+1);
	for(int i=1;i<=n;++i) ad(an[i],mod-1ll*aa[n-i]*iac[i]%mod);
	for(int i=0;i<=n;++i) aa[n-i]=1ll*cn[n-i]*fac[i]%mod;
	for(int i=0;i<=n;++i) bb[i]=iac[i];
	MUL(aa,n+1,bb,n+1);
	for(int i=1;i<=n;++i) ad(an[i],mod-1ll*aa[n-i]*iac[i]%mod);
	for(int i=1;i<=n;++i) printf("%d\n",an[i]);
    return 0;
}


Measured memory_bytes: 25728
#include<stdio.h>
int main(){
  int n,m,i,j,k,u,o;
  int h[2000],r[2000],p[4000];
  while(1){
    h[0]=-1;
    r[0]=-1;
    p[0]=0;
    
    scanf("%d",&n);
    if(n==0){break;}
    for(i=1;i<=n;i++){
      scanf("%d %d",&h[i],&r[i]);
    }

    scanf("%d",&m);
    for(j=i;j<=n+m;j++){  
      scanf("%d %d",&h[j],&r[j]);
    }
    
    /*hツづーsort*/
    for(i=1;i<n+m;i++){
      for(j=i+1;j<=n+m;j++){
	if(h[i]>h[j]){
	  u=h[i];
	  h[i]=h[j];
	  h[j]=u;
	  o=r[i];
	  r[i]=r[j];
	  r[j]=o;   
	}
      }
    }
 
    /*LIS*/
    for(i=1;i<=n+m;i++){
      p[i]=0;
      for(j=i-1;j>=0;j--){
	if(h[i]>h[j]&&r[i]>r[j] && p[i]<=p[j])
	  {
	    p[i]=p[j]+1;     
	  }
      }
    }
    
    k=0;
    for(i=1;i<=n+m;i++){
      if(k<p[i]){
	k=p[i];
      }
    }
    printf("%d\n",k);
    
  }
  
  return 0;
}

Measured memory_bytes: 0
A, B = sorted([int(i) for i in input().split()])

res = 1
for i in range(2, int(B**0.5)+1):
    if B % i == 0:
        if A % i == 0:
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    break
            else:
                res += 1
        t = B // i
        if t != i and A % t == 0:
            for j in range(2, int(t**0.5)+1):
                if t % j == 0:
                    break
            else:
                res += 1

print(res if res > 1 else (1 if (A == B == 1) or A != B else 2))


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s1,s2;
	cin>>s1>>s2;
	rep(i,0,s1.size()) if(s1[i]!=s2[i])
	{
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 3652
import Control.Monad (replicateM)

f :: [Integer] -> Integer -> Maybe Integer
f (a:as) i
  | a > i     = Nothing
  | otherwise = case as of
                  []     -> Just 0
                  (b:as) -> case compare (a + 1) b of
                              LT -> Nothing
                              EQ -> fmap (+ 1) (f (b:as) (i + 1))
                              GT -> fmap (+ b) (f (b:as) (i + 1))

main = do
  n <- readLn :: IO Int
  a <- map read <$> replicateM n getLine :: IO [Integer]
  print $ case f a 0 of
            Just i  -> i
            Nothing -> -1

Measured memory_bytes: 94716
N,M = map(int,input().split())
a,b = map(int,input().split())
for i in range(M-1):
    c,d = map(int,input().split())
    a = max(a,c)
    b = min(b,d)
if b>=a:
	print(b-a+1)
else:
  print(0)

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

S = []
for i in range (N):
    S.append(input())

ab_count = 0
bottom_a = 0
top_b = 0
ba = 0
for s in S:
    if s[-1] == 'A' and s[0] == 'B':
        ba += 1
    else:
        if s[-1] == 'A':
            bottom_a += 1
        if s[0] == 'B':
            top_b += 1
    for i in range(1,len(s)):
        if s[i-1] == 'A' and s[i] == 'B':
            ab_count += 1
if ba > 0:
    if bottom_a > 0:
        bottom_a -= 1
        ab_count += 1
    if top_b > 0:
        top_b -=  1
        ab_count += 1
ans = max(ba - 1, 0) + min(bottom_a, top_b) + ab_count
print(ans)

Measured memory_bytes: 3700
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] arr = s.split("");
		long bcount = 0;
		long count = 0;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i].equals("B")) {
				bcount++;
			} else {
				count = count + bcount;
			}
		}
		System.out.println(count);
	}
}

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

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

    int flag = 0;
    if(A == B) flag += 1;
    if(A == C) flag += 1;
    if(C == B) flag += 1;

    if(flag == 1){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}


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

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		static bool t[1000][1440];
		int bless[1000]={},enter[1000]={},last[1000]={};

		int pre=-1;
		rep(k,n+1){
			int date,id;
			if(k<n){
				int mon,day,hh,mm;
				scanf("%d%*c%d %d%*c%d %*c %d",&mon,&day,&hh,&mm,&id);
				date=31*mon+day;

				if(enter[id]==0){
					enter[id]=60*hh+mm;
				}
				else{
					for(int j=enter[id];j<60*hh+mm;j++) t[id][j]=true;
					enter[id]=0;
				}
			}
			else date=7777777;

			if(pre!=date){
				rep(i,1000) if(last[i]==pre) rep(j,1440) if(t[i][j] && t[0][j]) bless[i]++;
				rep(i,1000) if(last[i]==pre) rep(j,1440) t[i][j]=false;
			}
			last[id]=pre=date;
		}

		printf("%d\n",*max_element(bless+1,bless+1000));
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, a, b;std::cin >> n >> a >> b;
  if(abs(a-b)%2==0){
    std::cout << abs(a-b)/2 << '\n';
    return 0;
  }
  ll ans = 1000000000000000001;
  // case left
  ll tmp_a = 1;
  ll tmp_b = b - a;
  ans = min(ans, a + (tmp_b-tmp_a)/2);
  //std::cout << tmp_b << " " << tmp_a << '\n';
  // case right
  tmp_b = n;
  tmp_a = a + (n-b+1);
  ans = min(ans, n - b + 1 +  (tmp_b-tmp_a)/2);
  //std::cout << tmp_b << " " << tmp_a << '\n';

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<pair<ll, ll>> vec;
    rep(i, 1, n+1) {
        ll a;
        cin >> a;
        vec.emplace_back(a, i);
    }
    sort(vec.begin(), vec.end());
    rep(i, 0, n) {
        cout << vec[i].second << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2544
N = int(input())
j = 0
for i  in range(1,N + 1):
    if i % 3 == 0 and i % 5 == 0:
        pass #print('FizzBuzz')
    elif i % 3 == 0:
        pass #print('Fizz')
    elif i % 5 == 0:
        pass #print('Buzz')
    else:
        # print(i)
        j = j + i

print(j)

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,L;cin >> N >> L;
    vector<int> a(N);rep(i,N)cin >> a[i];

    bool ok = false;
    int num = -1;
    rep(i,N-1){
        if(a[i]+a[i+1] >= L){
            num = i;
            ok = true;
            break;
        }
    }

    if(!ok){
        cout << "Impossible" << endl;
    }
    else{
        cout << "Possible" << endl;
        rep(i,num)cout << i+1 << endl;
        for(int i = N-1;i >= num + 2;i--)cout << i << endl;
        cout << num + 1 << endl;
    }
}


Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
    public static void main(String[] args) throws IOException
    {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        Integer[] abc =
            Arrays.stream(reader.readLine().split(" ")).map(x -> Integer.parseInt(x)).toArray(Integer[]::new);

        if (abc[2] <= abc[0] + abc[1])
        {
            System.out.println(abc[2] + abc[1]);
        }
        else
        {
            System.out.println(abc[0] + 2 * abc[1] + 1);
        }
    }
}


Measured memory_bytes: 28628
//                                  _                 ______   ______   ______   ______
//                                 | |               |  __  | |  __  | |  __  | |____  |
//   __ _   ____    _____    _  _  | |____           | |__| | | |__| | | |__| |      | |
//  / _` | |  __| /  __  |  / _` | |  __  |          |____  | |____  | |____  |      | |
// | (_| | | |    | |  | | | (_| | | |__| |  ______   ____| |  ____| |  ____| |      | |
//  \__,_| |_|    |_|  |_|  \__,_| |______| |______| |______| |______| |______|      |_|

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

bool comp(const pair<int, int> &a, const pair<int, int> &b){
  return (a.first > b.second);
}

int main(){

  FAST();
  //Code goes past here:
    ll x;
    cin>>x;
    ll ans = 0;
    ans += x/500 * 1000;
    x %= 500;

    ans += x/5 *5;
    cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

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

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

// 二項係数計算
long long 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 gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
int n;
int bit[100010];
void add(int v, int x) {

	while (v <= n)
	{
		bit[v] += x;
		v += v & -v;
	}
}

ll sum(int v) {
	ll r = 0;
	while (v > 0)
	{
		r += bit[v];
		v -= v & -v;
	}
	return r;
}

void solv() {
	int x;
	cin >> x;
	cout << x * x * x << endl;

}


int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3092
n,m = map(int,input().split())
num = [1]*n
red = [False]*n
red[0] = True

for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    if red[x]:
        red[y] = True
        if num[x] == 1:
            red[x] = False
    num[x] -= 1
    num[y] += 1
    
print(red.count(True))   

Measured memory_bytes: 4596
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long sum = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextLong();
      sum += a[i];
    }
    long min = Long.MAX_VALUE;
    long y = 0;
    for(int i = 0; i < n-1; i++){
      sum -= a[i];
      y += a[i];
      if(Math.abs(sum-y) < min){
        min = Math.abs(sum-y);
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 64648
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
def solve():
    N = int(input())

    numss = [[0]*(10) for _ in range(10)]
    for A in range(1, N+1):
        ss = str(A)
        numss[int(ss[-1])][int(ss[0])] += 1

    ans = 0
    for A in range(1, N+1):
        ss = str(A)
        ans += numss[int(ss[0])][int(ss[-1])]

    print(ans)

solve()


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

long long l, r;
vector<int> v;

long long solve();

int main() {
  cin >> l >> r;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  if(r - l + 1 >= 2019) return 0;
  int ans = 2018;
  for(long long i = l; i <= r; ++i) v.push_back(i % 2019);
  sort(v.begin(), v.end());
  for(int i = 0; i < v.size(); ++i)
    for(int j = i + 1; j < v.size(); ++j)
      ans = min(ans, v[i] * v[j] % 2019);
  return ans;
}

Measured memory_bytes: 256
from collections import deque
X = input()
S = deque()
for e in X:
    S.append(e)
Q = int(input())
flip = 0
for i in range(Q):
    query = input()
    if query == str(1):
        flip += 1
    else:
        f = int(query[2])
        c = query[-1]
        if f == 1:
            if flip%2 == 1:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if flip%2 == 1:
                S.appendleft(c)
            else:
                S.append(c)
S = "".join(S)
if flip%2 == 1:
    print(S[::-1])
else:
    print(S)

Measured memory_bytes: 8684
#include<bits/stdc++.h>
const int MAXN=1e6+17;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

int a[MAXN];
map<long long, int> m;
void mainp()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    
    m[0]=1;
    long long temp=0ll, ans=0ll;
    for(int i=0; i<n; i++)
    {
        temp+=a[i];
        //cout<<temp<<" "<<m[temp]<<endl;
        ans+=m[temp];
        m[temp]++;
    }
    
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mainp();
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, m, k;
    cin >> n >> m;
    vector<vector<int> > s(m);
    vector<int> p(m);
    for(int i = 0; i < m ; i++){
        cin >> k;
        s[i].resize(k);
        for(int j = 0; j < k; j++){
            cin >> s[i][j];
            --s[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }

    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        int k = 1;
        for(int j = 0; j < m; j++){
            int x = 0;
            for(int l : s[j]){
                if((i >> l) & 1) x++;
            }
            if(x % 2 != p[j]) k = 0;
        }
        if(k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;

    int ans = 0;
    FOR(i, 1, N + 1) {
        if (i % 2 == 0) continue;
        int cnt = 0;
        FOR(j, 1, i + 1) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << '\n';

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	long long sum = 0;
	for(int i=0; i<s.size(); i++){
		char t = s[i];
		int num = t - '0';
		sum += num;
	}
	if(sum%9==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3728
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from collections import deque

def main():
	n=II()
	G=[[] for _ in range(n+1)]
	
	for _ in range(n-1):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)
	#print(G)
	
	Q=deque()
	Q.append([1,0])
	l=0
	v=0
	sumi=set()
	
	while Q:
		#print(Q)
		now,d=Q.popleft()
		sumi.add(now)
		if d>l:
			v=now
			l=d
		for i in G[now]:
			if i not in sumi:
				Q.append([i,d+1])
	#print(v,l)
	
	Q=deque()
	Q.append([v,0])
	l=0
	sumi=set()
	while Q:
		#print(Q)
		now,d=Q.popleft()
		sumi.add(now)
		if d>l:
			l=d
		for i in G[now]:
			if i not in sumi:
				Q.append([i,d+1])
	#print(l)
	
	if l%3==1:
		print("Second")
	else:
		print("First")

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	









if __name__ == "__main__":
	main()


Measured memory_bytes: 166152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            long n = Long.parseLong(strArr[0]);
            long a = Long.parseLong(strArr[1]);
            long b = Long.parseLong(strArr[2]);
            long ans = (b - a) * (n - 2) + 1;
            if (ans > 0) {
                System.out.println(ans);
            } else {
                System.out.println(0);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 21844
N = int(input())
a = N // 1000
N %= 1000
b = N //100
N %= 100
c = N // 10
N %= 10
d = N
if a == b and b == c:
  print("Yes")
elif b == c and c == d:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()




using Graph = vector<vector<int>>;

// 探索
vector<bool> seen, finished;

// サイクル復元のための情報
int pos = -1; // サイクル中に含まれる頂点 pos
stack<int> hist; // 訪問履歴

void dfs(const Graph &G, int v, int p) {
    seen[v] = true;
    hist.push(v);
    for (auto nv : G[v]) {
        //if (nv == p) continue; // 逆流を禁止する

        // 完全終了した頂点はスルー
        if (finished[nv]) continue;

        // サイクルを検出
        if (seen[nv] && !finished[nv]) {
            pos = nv;
            return;
        }

        // 再帰的に探索
        dfs(G, nv, v);

        // サイクル検出したならば真っ直ぐに抜けていく
        if (pos != -1) return;
    }
    hist.pop();
    finished[v] = true;
}




int main() {
    // 頂点数 (サイクルを一つ含むグラフなので辺数は N で確定)
    ll k;
    int N; cin >> N>>k;

    int a[N];
    rep(i,N){
        cin>>a[i];
        a[i]--;
    } 

    Graph G(N);
    for (int i = 0; i < N; ++i) {
        G[i].push_back(a[i]);
    }

    // 探索
    seen.assign(N, false), finished.assign(N, false);
    pos = -1;
    dfs(G, 0, -1);

    // サイクルを復元
    set<int> cycle;
    while (!hist.empty()) {
        int t = hist.top();
        cycle.insert(t);
        hist.pop();
        if (t == pos) break;
    }
    //cout<<cycle.size()<<endl;
    int cnt=1;
    int x=0;
    while(1){
        int y=a[x];
        if (cycle.count(x) && cycle.count(y)){
            break;
        }
        if (cycle.count(x)==0 && cycle.count(y)){
            break;
        }
        cnt++;
        x=y;
    }
    ll jy=cnt+cycle.size()-1;
    //cout<<cnt<<" "<<cycle.size<<endl;
    vector<int> ans;

    int num=jy;
    x=0;
    rep(i,jy){
        x=a[x];
        if(i>=cnt-1) ans.push_back(x);
    }

    if(k<=jy){
        x=0;
        while(k>0){
            x=a[x];
            k--;
        }
        cout<<x+1<<endl;
    }
    else{
        k-=jy+1;
        k%=ans.size();
        cout<<ans[k]+1<<endl;
    }
}



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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int n,m;



int main(){

  cin >> n >> m;
  vector<int>L(m),R(m);
  for(int i= 0; i < m; i++)cin >> L[i] >> R[i];

  int a = 0;
  int b = INTMAX;

  for(int i = 0; i < m; i++){
    if(a < L[i]) a = L[i];
    if(R[i]< b) b = R[i];
  }
  int ans = max(b-a+1, 0);
  cout << ans<< endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Integer>[] edges = new List[N];
		for (int i = 0; i < N; i++) {
			edges[i] = new LinkedList<>();
		}
		for (int i = 0; i < M; i++) {
			edges[sc.nextInt() - 1].add(sc.nextInt() - 1);
		}
		int s = sc.nextInt() - 1;
		int t = sc.nextInt() - 1;
		int[][] dp = new int[N][3];
		for (int i = 0; i < N; i++) {
			Arrays.fill(dp[i], 1 << 25);
		}
		dp[s][0] = 0;
		Queue<int[]> Q = new LinkedList<>();
		Q.add(new int[] {s, 0});
		while (!Q.isEmpty()) {
			int u = Q.peek()[0];
			int d = Q.poll()[1];
			if (u == t && d == 0) {
				System.out.println(dp[u][d]/3);
				return;
			}
			for (int v: edges[u]) {
				if (dp[v][(d + 1) % 3] > dp[u][d] + 1) {
					dp[v][(d + 1) % 3] = dp[u][d] + 1;
					Q.add(new int[] {v, (d + 1) % 3});
				}
			}
		}
		System.out.println(-1);
	}
}

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

def func(s, cnt):
    if int(s)>N:
        return cnt
    else:
        b=list(s)
        if '7' in b and '5' in b and '3' in b:
            cnt += 1
        for t in "753":
            cnt = func(s+t, cnt)
        return cnt
    
print(func("0", 0))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  int top = 0;
  int low = 1000;
  rep(i,n){
    int temp;
    cin >> temp;
    top = max(top, temp);
    low = min(low, temp);
  }
  cout << top - low << endl;
  return 0;
}

Measured memory_bytes: 256
def main()
  x, seq_num = gets.split.map(&:to_i)

  ps = gets&.split&.map(&:to_i) || []

  i = 0
  while true do
    return x - i unless ps.include? x - i
    return x + i unless ps.include? x + i
    i += 1
  end
end

print main

Measured memory_bytes: 14364
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		char a=sc.next().charAt(0);
		char b=sc.next().charAt(0);
		System.out.println(a==b?"H":"D");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


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

int main(void) {
	int N, X;
	vector<int> M;
	const int INF = (int)1e9;

	cin >> N >> X;
	M.resize(N);
	int min_m = INF;
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> M[i];
		sum += M[i];
		min_m = min(M[i], min_m);
	}
	
	int ans = N + (X - sum) / min_m;
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    for (int i = 1; i <= 9; ++i) {
        if(n%i!=0)continue;
        else if(n/i<=9){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=1
count=2
i=1
while i<N:
    if count==0:
        break
    if a[i]==a[i-1]:
        ans*=a[i]
        count-=1
        i+=2
    else:
        i+=1    
if count==0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 14252
import math
x=int(input())

b=0
while True:
    p,m=b, -b
    xp, xm = x+p**5, x+m**5
    flag=False
    for i in range(math.ceil(abs(xp)**0.2)+1):
        if i**5 - p**5 == x:
            ans=[i,p]
            flag=True
            break
        if (-1*i)**5 - p**5 == x:
            ans=[-1*i,p]
            flag=True
            break
    for i in range(math.ceil(abs(xm)**0.2)+1):
        if i**5 - m**5 == x:
            ans=[i,m]
            flag=True
            break
        if (-1*i)**5 - m**5 == x:
            ans=[-1*i,m]
            flag=True
            break
    if flag:
        break
    b+=1

print(" ".join(list(map(str,ans))))

Measured memory_bytes: 9440
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#define SF scanf
#define PF printf
#define MAXN 300010
using namespace std;
typedef long long ll;
int n;
ll L,ans,x[MAXN],t[MAXN];
pair<int,int> s[MAXN];
stack<int> q[2];
bool del[MAXN];
int main(){
	//freopen("datax.in","r",stdin);
	//freopen("data.out","w",stdout);
	SF("%d%lld",&n,&L);
	for(int i=0;i<n;i++)
		SF("%lld",&x[i]);
	for(int i=0;i<n;i++){
		SF("%lld",&t[i]);
		ans+=(t[i]/(2ll*L))*2ll*L;
		t[i]%=(2ll*L);
	}
	//PF("[%lld]",ans);
	bool flag=0;
	for(int i=0;i<n;i++){
		if(t[i]!=0){
			flag=1;
			if(t[i]<=2ll*(L-x[i]))
				s[i].first=0;
			else
				s[i].first=1;
			if(t[i]<=2ll*x[i])
				s[i].second=0;
			else
				s[i].second=1;
		}
		else{
			s[i].first=s[i].second=1;
		}
	}
	for(int i=0;i<n;i++)
		if(s[i].first==1&&s[i].second==1){
			del[i]=1;
			if(t[i]!=0)
				ans+=2ll*L; 
			//PF("********(%lld %lld)******",t[i],x[i]);
		}
	for(int i=0;i<n-1;i++){
		if(del[i]==1)
			continue;
		if(s[i].first==0&&s[i].second==1){
			if(!q[1].empty()){
				del[q[1].top()]=1;
				del[i]=1;
				q[1].pop();
				ans+=2ll*L;
			}
			else if(!q[0].empty()){
				del[q[0].top()]=1;
				del[i]=1;
				q[0].pop();
				ans+=2ll*L;
			}
		}
		else if(s[i].second==0){
			q[s[i].first].push(i);
		}
	}
	while(!q[1].empty())
		q[1].pop();
	while(!q[0].empty())
		q[0].pop();
	//PF("{%lld}",ans);
	for(int i=0;i<n-1;i++){
		if(del[i]==1||(s[i].first==0&&s[i].second==1))
			continue;
		if(s[i].first==0){
			if(!q[1].empty()){
				del[i]=1;
				del[q[1].top()]=1;
				q[1].pop();
				ans+=2ll*L;
			}
			else if(!q[0].empty()){
				del[i]=1;
				del[q[0].top()]=1;
				q[0].pop();
				ans+=2ll*L;
			}
			else
				q[0].push(i);
		}
		else
			q[1].push(i);
	}
	if(s[n-1].first==0&&del[n-1]==0){
		for(int i=0;i<n-1;i++)
			if(del[i]==0&&s[i].second==0){
				del[i]=1;
				del[n-1]=1;
				ans+=2ll*L;
				break;
			}
	}
	/*for(int i=0;i<n;i++)
		PF("[%d %d %d]\n",s[i].first,s[i].second,del[i]);
	PF("{%lld}",ans);*/
	ll res=0,sum=0;
	for(int i=0;i<n;i++)
		if(del[i]==0)
			sum++;
	if(del[n-1]==0){
		if(s[n-1].first==1&&s[n-1].second==0)
			res=sum+1;
		else
			res=sum;
	}
	if(del[n-1]==1)
		res=sum+1;
	ans+=res*2ll*L;
	PF("%lld",ans);
} 

Measured memory_bytes: 8652
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

int a[100010], b[100010], f[200010];

ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;
}

signed main(void)
{
  int n;
	cin >> n;
	vector<PII> v;
	REP(i, n) cin >> a[i], v.PB({a[i], 0});
	REP(i, n) cin >> b[i], v.PB({b[i], 1});
	sort(ALL(v));

	f[0] = 1;
	FOR(i, 1, 2*n+1) (f[i] = f[i-1] * i) %= MOD;

	VI v2;
	int cnt = 1;
	FOR(i, 1, v.size()) {
		if(v[i].second == v[i-1].second) cnt++;
		else {
			v2.PB(cnt);
			cnt = 1;
		}
	}
	v2.PB(cnt);

	// for(int i: v2) cout << i << " "; cout << endl;

	bool turn = true;
	int ret = 1; cnt = 0;
	for(int i: v2) {
		if(turn) {
			cnt += i;
		} else {
			if(cnt >= i) {
				// C(cnt, i) * i!
				(ret *= combi(cnt, i) * f[i] % MOD) %= MOD;
				cnt -= i;
			} else {
				(ret *= f[cnt]) %= MOD;
				cnt = i-cnt;
				turn = !turn;
			}
		}
		// cout << turn << " " << ret << " " << cnt << endl;
		turn = !turn;
	}
	cout << ret % MOD << endl;

	return 0;
}


Measured memory_bytes: 19692
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

typedef vector<pair<long long int,long long int>> DP;

DP connect(const DP&l, const DP&r) {
	DP k(l.size()+r.size()-1,make_pair(1e18,1e18));
	for (int i = 0; i < l.size(); ++i) {
		for (int j = 0; j < r.size(); ++j) {
			auto x = make_pair(l[i].first + r[j].first, l[i].second + r[j].second);

			k[i + j] = min(k[i + j], x);

		}
	}
	return k;
}
DP dfs(const int now, const int from,
	const vector<vector<int>>&edges,vector<int>&overs) {

	long long int over_num=overs[now];
	DP v(2);
	v[0]=make_pair(over_num,0);
	v[1]=make_pair(over_num-1,0);

	vector<vector<pair<long long int,long long int>>>ps;
	for (auto e : edges[now]) {
		if(e==from)continue;
		ps.push_back(dfs(e,now,edges,overs));
	}
	sort(ps.begin(), ps.end(), [](const vector < pair<long long int, long long int>>&l, const vector<pair<long long int, long long int>>&r) {
		return l.size()<r.size();
	});
	for (auto p : ps) {
		v=connect(v,p);
	}
	for (auto &k : v) {
		k.second+=abs(k.first);
	}
	return v;
}
int main() {
	int N;cin>>N;
	vector<int>nums;
	{
		for (int i = 0; i < N; ++i) {
			int a;cin>>a;
			nums.push_back(a);
		}
		long long int sum=accumulate(nums.begin(),nums.end(),0ll);
		for (auto &n : nums) {
			n-=sum/N;
		}
	}
	vector<vector<int>>edges(N);
	for (int i = 0; i < N - 1; ++i) {
		int a,b;cin>>a>>b;a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	DP ans=dfs(0,-1,edges,nums);
	for (int i = 0; i < ans.size(); ++i) {
		if(ans[i].first==0)cout<<ans[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 4264
n,m=map(int, input().split())
abl=[list(map(int, input().split())) for _ in range(n)]
cd=[list(map(int, input().split())) for _ in range(m)]

for ab in abl:
    dis=10**18
    num=0
    for i in range(m):
        x2,y2=cd[i]
        if dis>abs(ab[0]-x2)+abs(ab[1]-y2):
            dis=abs(ab[0]-x2)+abs(ab[1]-y2)
            num=i
    print(num+1)


Measured memory_bytes: 8988
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
inline int roundup(int a, int b) { return (((a + (b -1)) / b)); }
using namespace std;

signed main(void) {
    int x;
    cin >> x;
    (x == 0)? cout << 1:cout << 0;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
string s;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='C'){
            for(int j=i;j<s.size();j++){
                if(s[j]=='F') {
                    cout<<"Yes"<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i, j
  integer, allocatable :: a(:)
  read(*, *) n
  allocate(a(n))
  read(*, *) (a(i), i = 1, n)
  j = 1
  do i = 1, n
    j = a(j)
    if (j == 2) then
      write(*, "(i0)") i
      stop 0
    end if
  end do
  write(*, "(i0)") -1
end program main



Measured memory_bytes: 1152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
      n: usize,
      r: usize,
    );
    match n {
        1 ... 10 => println!("{}", r + 100*(10 - n)),
        _ => println!("{}", r)
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
int n;
string s;
int main(){
    cin >> n >> s;
    s = "!" + s;
    int j = n , ans = 0;
    for (int i = 1; i <= n; i++){
        if (s[i] == 'W'){
            while (s[j] != 'R' && i < j) j--;
            if (i < j) {
                swap(s[i],s[j]);
                ans++;
            }
        }
        if (i >= j) break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3388