akhauriyash/Code-Regression huggingface dataset:
//C
/*==========================================================*/
/*    Template ver 2017-0401    |   Created by AVM.Martin   */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<algorithm>
#include<cmath>

#include<cstring>
#include<string>
#include<cctype>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>

typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::vector<int> vi;

const int OO=(int)2e9;
const ll INF=(ll)4e18;
const double EPS=(double)1e-12;

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define INL(i,a,b) ((a<=i)&&(i<=b))
#define EXL(i,a,b) ((a< i)&&(i< b))
#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
using namespace std;

int n;
ll dat[200005];
ll res;

int main(){
	scanf("%d",&n);
	dat[0]=0;
	REP(i,1,n){
		scanf("%lld",dat+i);
		dat[i]+=dat[i-1];
	}
	res=INF;
	REP(i,1,n-1)res=min(res,abs(2*dat[i]-dat[n]));
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll p=a-b;
    if((k+1)%2==0) p*=-1;
    if(abs(p)>1000000000000000000) cout<<"Unfair";
    else cout<<p;
}

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

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

void solve(std::string S, std::string T, long long A, long long B,
           std::string U) {
  // solver code

  if (U == S) {
    A--;
  } else {
    B--;
  }

  cout << A << " " << B << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  std::string U;
  std::cin >> U;
  solve(S, T, A, B, U);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=50000;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

bool prime[10000001];
void fin()
{
    for(int i=2;i*i<=1000000;i++)
    {
        if(!prime[i])
        for(int j=i*i;j<=1000000;j+=i)
            prime[j]=true;
    }
}


void solve()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;
    ans+=n/(a+b);
    ans=ans*a;
    n=n%(a+b);
    ans+=min(n,a);
    cout<<ans;

}

int main(){
    boost;
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e5+7;
int T,n,m;
PII a[N], b[N];
int cnt[4];
bool cmp(PII a, PII b){
    if(a.se==b.se){
        return a.fi > b.fi;
    }
    return a.se > b.se;
}
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    int x;
    rep(i,0,N){
        a[i].fi = i, b[i].fi = i;
        a[i].se = 0, b[i].se = 0;
    }
    rep(i,1,n+1){
        scanf("%d", &x);
        if(i&1){
            a[x].se++;
        }
        else{
            b[x].se++;
        }
    }
    sort(a, a + N, cmp );
    sort(b, b + N, cmp );
    if(a[0].fi==b[0].fi){
        printf("%d\n", min(n - a[1].se - b[0].se, n - a[0].se - b[1].se));
    }
    else
        printf("%d\n", n - a[0].se - b[0].se);
    return 0;
}

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

using namespace std;

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

    vector<int> p(0), e(0);
    for (long long i = 2, j = n; ; i++) {
        if (j % i == 0) {
            p.push_back(i);
            e.push_back(0);
            while (j % i == 0) {
                e[e.size() - 1]++;
                j /= i;
            }
        }

        if (j == 1) {
            break;
        } else if (i * i > j) {
            p.push_back(j);
            e.push_back(1);
            break;
        }
    }

    long long res = 0;
    for (int i = 0; i < static_cast<int>(e.size()); i++) {
        for (int j = 1; ; j++) {
            if ((j + 1) * (j + 2) / 2 > e[i]) {
                res += j;
                break;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3628
N=int(input())
h=list(map(int, input().split()))

dp=[0]
highjump=0
jump=0

dp.append(abs(h[1]-h[0]))

for i in range(2,N):
    highjump=abs(h[i]-h[i-2])
    jump=abs(h[i]-h[i-1])
    dp.append(min(dp[i-2]+highjump,dp[i-1]+jump))

print(dp[N-1])

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

int main(){
  int c[3][3];
  rep(i,3)rep(j,3)cin>>c[i][j];
  int cross=0,all=0;
  rep(i,3)cross+=c[i][i];
  rep(i,3)rep(j,3)all+=c[i][j];
  
  if(3*cross==all)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N, min = 10000, sum = 0;
    cin >> N;
    vector<int> W(N), S(N);
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        sum += W[i];
        S[i] = W[i] + (i > 0 ? S[i-1] : 0);
    }
    for (int T = 0; T < N; T++) {
        int t = abs(2 * S[T] - sum);
        if (t < min) min = t;
    }
    cout << min << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

using namespace std;
using ll = long long;

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 2;

bool is_prime(int n)
{
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

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

    int n;
    cin >> n;
    int ans = 0;
    REP(i, n)
    {
        int a;
        cin >> a;
        ans += is_prime(a);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}



int main() {
    ll N;
    cin >> N;
    ll s[MAX*2]={};
    ll i;
    
    for(i=1; i<=N; i++) {
        ll t;
        cin >> t;
        s[i]=s[i-1]+t;
    }
    
    ll ans=INF;
    ll l=1, r=3;
    for(i=2; i<=N-2; i++) {
        while(abs(s[l]-(s[i]-s[l]))>abs(s[l+1]-(s[i]-s[l+1]))) l++;
        while (abs(s[N]-s[r]-s[r]+s[i])>abs(s[N]-s[r+1]-s[r+1]+s[i])) r++;
        
        ll ma=max(s[l], max(s[i]-s[l], max(s[r]-s[i], s[N]-s[r])));
        ll mi=min(s[l], min(s[i]-s[l], min(s[r]-s[i], s[N]-s[r])));
        
        chmin(ans, abs(ma-mi));
    }
    
    pt(ans);
    
}


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

int main(){
  int a,b,c,x;
  int count=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x)count++;
      }
    }
  }
  cout<<count<<endl;
}
        

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;
const ll mod = 1e9 + 7;

int n, m, a, b;
ll fact[1000010], ifact[1000010];

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

void init()
{
    fact[0] = 1;
    for (int i = 1; i <= 1e6; ++i)
    {
        fact[i] = fact[i - 1] * i % mod;
    }
    ifact[1000000] = power(fact[1000000], mod - 2);
    for (int i = 999999; i >= 0; --i)
    {
        ifact[i] = ifact[i + 1] * (i + 1) % mod;
    }
}

ll nCk(int n, int k)
{
    return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    cin >> n >> m >> a >> b;
    ll ans = nCk(n + m - 2, n - 1);
    for1(i, b)
    {
        ll cur = nCk(n - a + i - 2, i - 1);
        cur *= nCk(m - i + a - 1, a - 1);
        cur %= mod;
        ans = ans - cur + mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}


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

def CountingSort(A,k):
    C = [0 for x in range(k+1)]
    B = [0 for x in range(N)]

    for j in range(N):
        C[A[j]] += 1

    for i in range(k):
        C[i+1] += C[i]

    for j in reversed(range(N)):
        B[C[A[j]]-1] = A[j]
        C[A[j]] -= 1

    return B

B = CountingSort(A,max(A))

for i in range(N):
    if i != N-1:
        print(B[i], end=" ")
    elif i == N-1:
        print(B[N-1])



Measured memory_bytes: 224416
int main(void){
    int i,a;
    int Num;
    int l;
    
    scanf("%d",&Num);
    
    for(i=1;i<=Num;i++){
        if(i%3==0){
            printf(" %d",i);
            continue;
        }
        a=i;
        while(a!=0){
            if(a%10==3){
                printf(" %d",i);
                break;
            }
            a /= 10;
        }
    }
    printf("\n");
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin >> a>>b>>c;
int five=0;
int seven=0;
if(a==5){
five++;
}
else if(a==7){
seven++;
}
if(b==5){
five++;
}
else if(b==7){
seven++;
}
if(c==5){
five++;
}
else if(c==7){
seven++;
}
if(five==2&&seven==1)
cout << "YES ";
else
cout <<"NO";
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int h[200],n,a[200];
void doo()
{
    for(int i=0; i<n; i++)
        if(h[i]>0)
            h[i]--;
}
int main()
{
    int ans=0,ma=1999;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&h[i]);
        ma=min(ma,h[i]);
    }
    for(int i=0;i<n;i++) h[i]-=ma;
    ans=ma;
    while(1){
        int po=0;
        for(int i=0;i<n;i++){
            if(h[i]>0) a[po++]=i;
        }
        if(po==0) break;
        int k=0;
        for(int i=1;i<po;i++){
            if((a[i]-a[i-1])>1){
                k++;
            }
        }
        doo();
        ans+=(k+1);
    }
    printf("%d\n",ans);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+2;
vector<int>p(N);
vector<int>ed(N);
vector<int>v(N);

void build()
{
    for(int i=0; i<N; ++i)
    {
        p[i]=i;
        ed[i]=0;
        v[i]=1;
    }
}
int find_parent(int v)
{
    if(v==p[v])
        return v;
    return p[v]=find_parent(p[v]);
}
bool union_set(int a, int b)
{
    a=find_parent(a);
    b=find_parent(b);
    if(a!=b)
    {
        if(rand()&1)
        {
            swap(a, b);
        }
        if(ed[a]+ed[b]+1>v[a]+v[b])
        {
            return 0; 
        }
        ed[a]+=ed[b]+1;
        v[a]+=v[b];
        p[b]=a;
    }
    else 
    {
        if(ed[a]+1>v[a])
            return 0;
        ed[a]++;
    }
    return 1;
}

int32_t main()
{
    int n, h, w;
    cin>>n>>h>>w;
    srand(time(NULL));

    vector<pair<int,pair<int,int>>>a(n);
    for(int i=0; i<n; ++i)
    {
        cin>>a[i].second.first>>a[i].second.second>>a[i].first;
    }
    sort(a.begin(), a.end());
    int ans=0;
    build();
    for(int i=n-1; i>=0; --i)
    {
        if(union_set(a[i].second.first, a[i].second.second+h))
            ans+=a[i].first;
    }
    cout<<ans;
}

Measured memory_bytes: 7552
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, ans = 0; cin >> n;

    vector<long long> a(n);

    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    for(long long i = 1; i < n; i++){
        if(a[i - 1] > a[i]){
            ans += (a[i - 1] - a[i]);
            a[i] = a[i - 1];
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    bool bo=false;
    if(n>=2100) bo=true;
    if(100<=n){
        int a=n%100,b=n/100;
        if(a<=b*5) bo=true;
    }
    cout<<bo;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,ans,fa[N],sum[N];

inline int Find(int x)
{
    if(x==fa[x]) return x;
    return fa[x]=Find(fa[x]);
}

inline void Union(int x,int y)
{
    x=Find(x),y=Find(y);
    if(x!=y)
    {
    	fa[y]=x;
		sum[x]+=sum[y];
	}
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) 
    {
    	fa[i]=i;
    	sum[i]=1;
	}
        
    while(m--)
	{
        int a,b;
        cin>>a>>b;
        Union(a,b);
    }
    for(int i=1;i<=n;i++) 
	 if(Find(i)==i) 
	  ans=max(ans,sum[i]);
    
	cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 5452
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

int main() {
	int n;
	int a[1000];

	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	int tmp;

	for (int i = 0; i < n / 2; i++) {
		tmp = a[i];
		a[i] = a[(n - 1) - i];
		a[(n - 1) - i] = tmp;
	}
	for (int i = 0; i < n; i++) {
		if (i < n - 1)
			std::cout << a[i] << " ";
		else
			std::cout << a[i];
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3052
/*---> 04 April 2020 <--- > 01:28:41 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n,k;
	cin>>k>>n;
	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int mx=k-a.back()+a[0];
	for(int i=1;i<n;i++){
		mx=max(mx,a[i]-a[i-1]);
	}
	cout<<k-mx<<"\n";
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
void primes(int n, int a)
{
	vector<int> x(n+1,true);
	x[0] = x[1] = false;

	int m = sqrt(n);

	for (int i = 2; i <= m; ++i)
	{
		if(x[i])
		{
			for (int j =  i * i; j <= n; j+=i)
			{
				x[j] = false;
			}
		}
	}

	if(x[a]) cout << a;
	else primes(n,a+1);
}

int main() {

	int z;
	cin >> z;
	primes(1000005,z);
	
	return 0;
}

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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()

#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d\n",n)
#define SL(n) scanf("%lld",&n)
#define PL(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
typedef long long int 	LL;
typedef long double 	LD;
typedef pair<int,int>   II;
typedef vector<int>     VI;
const int MOD = 1e9 + 7;
const int N = 100011;


int main() {
    int n;
    SI(n);
    PI(24 + 23 - n + 1);
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	cnt := make([]int, 100001)
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		cnt[a] += b
	}

	for i := 0; i <= 100000; i++ {
		if k <= cnt[i] {
			fmt.Println(i)
			return
		}
		k -= cnt[i]
	}
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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



int main(){fastio
    ll n;cin>>n;
    vector<ll>a(n);rep(i,0,n-1)cin>>a[i];
    SORT(a);
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            ll bnd=a[i]+a[j];
            ll ad=POSL(a,bnd)-1-j;
            ans+=ad;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
#define test() int t; cin>>t; while(t--)
#define ll long long int

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int k;
	cin >> k;
	ll a = 7 % k;
	for (int i = 1; i < 1e7; i++) {
		if (a == 0) {
			cout << i << endl;
			return 0;
		}
		a = ((a * 10) + 7) % k;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3600
import sys
S = input()
S = S[::-1]
N = len(S)
words = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != N:
    flag = 1
    for word in words:
        if S[i:i+len(word)] == word:
            flag = 0
            i += len(word)
    if flag:
        print('NO')
        sys.exit()
print('YES')

Measured memory_bytes: 3188
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    boolean res = true;
    char[] a = s.toCharArray();
    for(int i = 0; i < a.length; ++i) {
      if((i & 1) == 0) {
        if(a[i] != 'h') res = false;
      } else {
        if(a[i] != 'i') res = false;
      }
    }
    if(a.length % 2 != 0) res = false;
    if(res) System.out.println("Yes");
    else System.out.println("No");
  }
}


Measured memory_bytes: 21844
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 100007;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;


int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt" , "w", stdout);


    int n;
    cin >> n;
    VI A(n);
    FOR(i,0,n)
        cin >> A[i];
    int res = 0;
    FOR(i,1,n)
        if (A[i] == A[i - 1])
        {
            ++ res;
            A[i] = -1;
        }
        cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> Pair;
 
const int INF = 0x3fffffff;
int N;
char S[200001];
int type[200001];
int dp[200001];
int nxt[200001];
queue<int> qs[200001];
vector<int> es[200001];
map<int, vector<int>> belong;
 
int main() {
  scanf("%s", S);
  N = strlen(S);
  
  type[0] = 0;
  belong[0].emplace_back(0);
  int bit = 0;
  for (int i=0; i<N; i++) {
    es[i].reserve(26);
    bit ^= (1 << int(S[i]-'a'));
    belong[bit].emplace_back(i+1);
    type[i+1] = bit;
  }
 
  for (auto &itr : belong) {
    auto &v = itr.second;
    if (v.empty()) continue;
    for (int i=0; i<v.size()-1; i++) {
      nxt[v[i]] = v[i+1];
    }

    for (int j=0; j<26; j++) {
      int t = itr.first ^ (1<<j);
      auto &vec = belong[t];
      auto itr = upper_bound(vec.begin(), vec.end(), v.front());
      if (itr == vec.end()) continue;
      for (int g : v) {
        while (itr != vec.end() && *itr < g) itr++;
        if (itr == vec.end()) break;
        es[g].emplace_back(*itr);
      }
    }
  }
 
  fill(dp, dp+N+1, INF);
  dp[0] = 0;
  qs[0].push(0);
  for (int i=0; i<N; i++) {
    while (!qs[i].empty()) {
      int v = qs[i].front(); qs[i].pop();
      if (v == N) continue;
      //assert(dp[v] == i);
 
      if (nxt[v] != -1) {
        int u = nxt[v];
        if (dp[u] > dp[v]) {
          dp[u] = dp[v];
          qs[i].push(u);
        }
      }
 
      for (int u : es[v]) {
        if (dp[u] > dp[v]+1) {
          dp[u] = dp[v]+1;
          qs[i+1].push(u);
        }
      }
    }
  }
 
  if (!dp[N]) dp[N]++;
  printf("%d\n", dp[N]);
}


Measured memory_bytes: 509056
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var set = new HashSet<int> { io.I, io.I, io.I };

        io.Write(set.Count);
    }
}

Measured memory_bytes: 13280
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

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

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	int X, Y, Z;
	cin >> X >> Y >> Z;

	int ans = 0;
	int total = Z;
	while (total + Y + Z <= X) {
		ans++;
		total += (Y + Z);
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int x=0,y=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='c'){
      cout << "No" << endl;
    }
    else if(s[i]=='b'){
      if(x<a+b&&y<b){
        x++;
        y++;
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      if(x<a+b){
        x++;
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
  }
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)2e5+111;
ll const LG=(ll)log2(N)+1;



void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        cin>>n;
        vll a(N);
        ll sum=0;
        for(i=0;i<n;i++){
                cin>>x;
                a[x]++;
                sum+=x;
        }
        cin>>m;
        while(m--){
                cin>>x>>y;
                ll tt=sum-a[x]*x + a[x]*y;
                a[y]+=a[x];
                a[x]=0;
                sum=tt;
                cout<<sum<<endl;
        }
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 4776
import std.stdio, std.range, std.conv, std.string, std.array, std.functional, std.math, std.regex, std.range, std.traits, std.ascii, std.container;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;
import std.typecons; 

void scanLine(TList...)(ref TList list)
{
    auto elem = readln().split;
    foreach(i, T; TList)
    {
        list[i] = elem[i].to!T;
    }
}
T[] scanArray(T=long)()
{
    return readln.split.to!(T[]);
}
T scanElem(T=long)()
{
    string res;
    char[1] bIn = ' ';
    while(isWhite(bIn[0]))
    {
        stdin.rawRead(bIn);
    }
    while(!isWhite(bIn[0]))
    {
        res ~= bIn[0];
        stdin.rawRead(bIn);
    }
    return res.to!T;
}

struct N{
    long x;
    long y;
    long z;
}

void main()
{
    auto X = scanElem();
    auto Y = scanElem();
    auto Z = scanElem();
    auto K = scanElem();

    auto aList = scanArray().sort!"a>b";
    auto bList = scanArray().sort!"a>b";
    auto cList = scanArray().sort!"a>b";

    long sum(N n)
    {
        return aList[n.x] + bList[n.y] + cList[n.z];
    }

    auto heap = BinaryHeap!(Array!N, (a,b)=>sum(a)<sum(b))();
    heap.insert(N(0,0,0));
    bool[N] used;
    used[N(0,0,0)] = true;
    foreach(i; 0..K)
    {
        auto top = heap.front; heap.popFront;
        writeln(sum(top));
        
        auto xQueue = N(top.x+1, top.y, top.z);
        auto yQueue = N(top.x, top.y+1, top.z);
        auto zQueue = N(top.x, top.y, top.z+1);
        if(top.x+1 < X && (xQueue !in used))
        {
            heap.insert(xQueue);
            used[xQueue] = true;
        }
        if(top.y+1 < Y && (yQueue !in used))
        {
            heap.insert(yQueue);
            used[yQueue] = true;
        }
        if(top.z+1 < Z && (zQueue !in used))
        {
            heap.insert(zQueue);
            used[zQueue] = true;
        }
    }
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define rep(I,n) for (int I = 0; I < (n); ++I)
using namespace std;
typedef long long ll;
 
int main() {
    
    string s;
     cin>>s;
    int n = s.length();
    
    
    for(int i =0; i<n; i=i+2){
        cout << s[i];
        
    }
    
    
    
    
    
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = inf;
    if(x*y>=0&&y-x>0){
        ans = min(inf, y-x);
    }
    if(x*y>=0&&y-x<0){
        ans = min(abs((-y)+x)+2, ans);
    }
    if(x*y <=0){
        ans = min(abs(x+y)+1, ans);
    }
    cout << ans << endl;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>d(n);
	for(auto&i:d)cin>>i;
	sort(d.begin(),d.end());
	int ans=1;
	for(int i=0;i<n-1;++i){
		if(d.at(i)<d.at(i+1))++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
from sys import exit
from collections import defaultdict
H,W,N = [int(n) for n in input().split()]
Sr,Sc = [int(n) for n in input().split()]
#上に
Dout = H-Sr + 1
#下に
Uout = Sr
#右に落とすのに必要な歩数
Rout = W - Sc + 1
#左に
Lout = Sc
# print(Uout, Dout,Rout, Lout)
S = str(input())
T = str(input())
ptrC = defaultdict(int)
ptrA = defaultdict(int)
for s,t in zip(S,T):
    ptrC[s]+=1
    ptrA[t]+=1
# print(ptrC,ptrA)
# if ptrC["R"] - ptrA["L"] >= Rout or ptrC["L"] - ptrA["R"] >= Lout or ptrC["D"] - ptrA["U"] >= Dout or ptrC["U"] - ptrA["D"] >= Uout:
#     print("NO")
#     exit()
def check(outcnt, C, A, lim, B):
    backed = 0
    for s,t in zip(S,T):
        if s == B and outcnt == lim -1 and backed > 0:
            outcnt -= 1
            backed -= 1
        if( s == C ):
            outcnt -= 1
        if( outcnt == 0 ):
            print("NO")
            exit()
        if( t == A and outcnt < lim ):
            outcnt += 1
            backed += 1

check(Rout, "R", "L", W, "L")
check(Lout, "L", "R", W, "R")
check(Uout, "U", "D", H, "D")
check(Dout, "D", "U", H, "U")
print("YES")


Measured memory_bytes: 4044
//https://atcoder.jp/contests/agc026/tasks/agc026_d
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>

int f[100][101][101][2]; // [h,l,r,alt]

int constexpr MOD=1000000007;
int constexpr INV2=(MOD+1)/2;

int pow2(int exp){
	assert(exp>=0);
	int base=2,ans=1;
	while(true){
		if(exp&1)ans=ans*(int64_t)base%MOD;
		exp>>=1;if(exp==0)return ans;
		base=base*(int64_t)base%MOD;
	}
}

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;
	std::vector<int> a(n);for(int& x:a)std::cin>>x;

	auto vals=a;std::sort(begin(vals),end(vals));
	vals.erase(std::unique(begin(vals),end(vals)),end(vals));
	for(int& x:vals)x-=1;

	for(int hi=vals.size();hi--;){
		int const h=vals[hi];
		f[hi][n][n][0]=0;
		f[hi][n][n][1]=1;
		for(int l=n;l--;){
			f[hi][l][l][0]=0;
			f[hi][l][l][1]=1;

			int min_lr=a[l];
			if(min_lr<=h)
				continue;

			int hp=-1; // any index with height == h+1, or -1
			if(a[l]==h+1)hp=l;

			f[hi][l][l+1][0]=0;
			f[hi][l][l+1][1]=pow2(a[l]-h);

			for(int r=l+2;r<=n;++r){
				min_lr=std::min(min_lr,a[r-1]);
				if(min_lr<=h)
					continue;

				if(a[r-1]==h+1)hp=r-1;

				if(hp>=0){
					assert(f[hi][hp][hp+1][1]==2);
					if(hp!=l&&hp!=r-1)
						f[hi][l][r][1]=f[hi][l][hp][1]*(int64_t)f[hi][hp+1][r][1]
							%MOD*INV2%MOD;
					else
						f[hi][l][r][1]=f[hi][l][hp][1]*(int64_t)f[hi][hp+1][r][1]
							%MOD;

					assert(f[hi][hp][hp+1][0]==0);
					f[hi][l][r][0]=
						(
							2LL
							*
							(f[hi][l][hp][0]+f[hi][l][hp][1])
							*
							(f[hi][hp+1][r][0]+f[hi][hp+1][r][1])
							+MOD-f[hi][l][r][1]
						)%MOD;

				}else{
					assert(hi!=vals.size()-1);
					int const nexthi=hi+1;
					int const nexth=vals[nexthi];
					f[hi][l][r][0]=f[nexthi][l][r][0];
					f[hi][l][r][1]=f[nexthi][l][r][1]*(int64_t)pow2(nexth-h)%MOD;
				}
			}
		}
	}

	int h0=vals[0];
	std::cout<<(f[0][0][n][0]+f[0][0][n][1]*(int64_t)pow2(h0))%MOD<<'\n';
}


/*

given config A:
| ........... |
n of way to fill the row below (assume rect.)
1 (just flip the last col) if any 2 cons. id
2 (flip or keep) if alternate

consider top down

f[l,r,h,0|1] = num of way to fill [l..r[ with h first lay cut of (alternative?)
(assume all are > h)
1: must alternate
0: must not alternate

ans = sum f[0,n,0,all]

BASE CASE

let f[x,x,_,1] = 1 // len <= 1 : alternative
let f[x,x,_,0] = 0
let f[x,x+1,_,0] = 0
let f[x,x+1,h,1] = 2^(h[x]-h) (h[x]-h>0)


f[l,r,h,0] = f[l,r,h+1,0] if valid
f[l,r,h,1] = 2*f[l,r,h+1,1] if valid

if f[l,r,h+1,_] is not valid
then there is i in [l..r[ such that h[i]==h
consider f[l,i], f[i,i+1] and f[i+1,r]
f[l,r,h,1] = f[l,i,h,1] * f[i,r,h,1] / 2
f[l,r,h,0] = 
f[l,i,h,sum] * f[i,i+1,h,sum] * f[i+1,r,h,sum] - f[l,r,h,1]

*/

Measured memory_bytes: 8192
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict
from bisect import bisect_right

s = ns()
t = ns()

ok = True

sset = set(list(s))
for ti in t:
    if ti not in sset:
        ok = False
        break

if not ok:
    print(-1)

else:
    n = len(s)

    charidx = defaultdict(list)

    for i, si in enumerate(s):
        charidx[si].append(i)
    for i, si in enumerate(s):
        charidx[si].append(n+i)

    ks = charidx.keys()

    move = [{ki: -1 for ki in ks} for _ in range(n)]

    for i, si in enumerate(s):
        for ki in ks:
            idxlist = charidx[ki]
            nexidx = bisect_right(idxlist, i)
            move[i][ki] = (idxlist[nexidx] - i) % (n+1)

    cur = s.index(t[:1])
    ans = cur
    for ti in t[1:]:
        nex = move[cur][ti]
        ans += nex
        cur = (cur + nex) % n

    print(ans+1)


Measured memory_bytes: 378916
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
long long s[100];
long long p[100];
long long Burger(int n,long long x){//nを下からx枚
    long long res=0;
    if(x>0){
        if(n==0){res=1;}
        else if(x==s[n]){res=p[n];}
        else if(x==1){res=0;}
        else if(x<=s[n-1]+1){res=Burger(n-1,x-1);}
        else if(x==s[n-1]+2){res=1+Burger(n-1,x-1);}
        else{res=1+p[n-1]+Burger(n-1,x-s[n-1]-2);}
    }
    return res;
}
int main()
{ 
    int n;
    long long x;
    cin>>n>>x;
    s[0]=1;
    p[0]=1;
    for(int i=1;i<n+1;i++){
        s[i]=2*s[i-1]+3;
        p[i]=2*p[i-1]+1;
    }
    cout<<Burger(n,x)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<stack>
#include<string>
using namespace std;
int main(){
	string t;
	int tmp,ans=0,t1,t2;
	stack<int>sta;
	
	while(cin>>t){
		
		if(t[0]=='-'||t[0]=='+'||t[0]=='*'){
			t2=sta.top();
			sta.pop();
			t1=sta.top();
			sta.pop();
			if(t[0]=='-')sta.push(t1-t2);
			if(t[0]=='+')sta.push(t1+t2);
			if(t[0]=='*')sta.push(t1*t2);
		}

		else{
			stringstream ss(t);
			ss>>tmp;
			sta.push(tmp);
		}
	
	}
	cout<<sta.top()<<endl;
		sta.pop();
	return 0;
}

Measured memory_bytes: 1228
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1000");
            //ABC
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2000");
            //ARC
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int x = int.Parse(InputList[0]);

        Console.WriteLine(x < 1200 ? "ABC" : "ARC");
    }
}


Measured memory_bytes: 2776
//list index out of range エラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)


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

  cout << 2*M_PI*N;
}



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

int main(){

int a, b, cnt, dnt;
  cin >> a >> b;
  
bool aa = true;
bool bb = true;
int n = 0;
cnt = 0;
dnt = 0;  
  
 while(bb){
 if((b / 10 == 0) && (b % 10 == 0)) bb = false;
 else{
   n += (b % 10) * pow(10, cnt);
   cnt++;
   b /= 10;
 }
 }

 while(aa){
 if((a / 10 == 0) && (a % 10 == 0)) aa = false;
 else{
   n += (a % 10) * pow(10, cnt);
   cnt++;
   a /= 10;
 }
 }

int hantei = (int)sqrt((double)n);
  
  if(hantei * hantei == n) cout << "Yes" << endl;
  else cout << "No" << endl;

return 0;
  
}

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

int main() {
 int a,b,c;
  cin>>a>>b>>c;
  bool flag=false;
  if(a==b&&a!=c) flag=true;
  if(b==c&&a!=b) flag=true;
  if(c==a&&a!=b) flag=true;
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

int
main(int argc, char **argv)
{
    int n,r;
    cin >> n >> r;

    if(n > 10)
        cout << r << endl;
    else
        cout << r + (100 * (10 - n)) << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	//入力が素数の場合はn-1を出力するのでn-1で初期化
	res := n - 1

	//入力が塁上より低い間ループする
	for i := 1; i*i <= n; i++ {
		//iで割り切れない場合
		if n%i != 0 {
			continue
		}
		//iで割り切れた場合
		v := i - 1 + (n / i) - 1
		if v < res {
			res = v
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
string N;
int num[1000005];
int dp[1000005][2];

int solve(int idx, int carry){
    if (idx < 0) return carry;
    if (dp[idx][carry] != -1) return dp[idx][carry];
    if (num[idx] == 9 && carry == 1) return dp[idx][carry] = solve(idx-1,1);
    return dp[idx][carry] = min(solve(idx-1,0)+num[idx]+carry, solve(idx-1,1) + (10 - (num[idx] + carry)));
}

int main() {
    cin >> N;
    int s = N.length();
    for (int i=s-1; i>=0; i--){
        num[s-1-i] = N[i]-'0';
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(s, 0) << endl;
    return 0;
}


Measured memory_bytes: 59908
import sys
sys.setrecursionlimit(10**7)
n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

def unite(a, b):
    root_a = find_root(a)
    parent[a] = root_a
    root_b = find_root(b)
    parent[b] = root_b
    if root_a != root_b:
        parent[root_b] = root_a

def find_root(a):
    ls = []
    while parent[a] != a:
        ls.append(a)
        a = parent[a]
    for l in ls:
        parent[l] = a
    return a


for i in range(m):
    x, y, z = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    unite(x, y)

_set = set()
for i in range(n):
    _set.add(find_root(i))
print(len(_set))

Measured memory_bytes: 52128
import math
import sys
from collections import defaultdict
from itertools import product, permutations, combinations

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


N = int(input())
if N % 2:
    print(0)
    exit()
else:
    N //= 2

ans = 0
while N > 0:
    N //= 5
    ans += N
print(ans)



Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    int sa=a*12.4;
    for(int i=0;i<100;i++){
        if((int)((sa+i)*0.08)==a&&(int)((sa+i)*0.1)==b){
            cout<<sa+i;
            return 0;
        }
    }
    cout<<"-1";
    return 0;
}


Measured memory_bytes: 256
//AC

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	int a,b,c; cin>>a>>b>>c;
	int ans = 3;
	if(a == b && b== c) ans = 1;
	else if(a == b) ans--;
	else if(a == c) ans--;
	else if(b == c) ans--;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256