akhauriyash/Code-Regression huggingface dataset:
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 

const ll MOD = 1e9 + 7;
string C[4] = { "A","G","C","T" };
int N;
//ll ans = 0;
vector<map<string, ll>> dp;
ll dfs(int n, int i, string res) {
    if (n>=2) {
        string s = { res[n - 2], res[n - 1], res[n] };
        if (s == "AGC" || s == "GAC" || s == "ACG") {
            return 0;
        }
    }
    if (n>=3) {
        string s = { res[n-3], res[n - 2], res[n - 1], res[n] };
        if ((s[0] == 'A' && s[2] == 'G' && s[3]=='C') ||
            (s[0] == 'A' && s[1] == 'G' && s[3]=='C')) {
            return 0;
        }
    }


    if (n >= N-1) {
        //ans += 1;
        //ans %= MOD;
        return 1;
    }

    if (n>=2) {
        string s = { res[n - 2], res[n - 1], res[n] };
        if (dp[n].count(s) > 0) return dp[n][s];
    }

    ll ret = 0;
    for(int j=0; j<4; j++) {
        ret += dfs(n + 1, j, res+C[j]);
        ret %= MOD;
    }

    if (n>=2) {
        string s = { res[n - 2], res[n - 1], res[n] };
        dp[n][s] = ret;
    }

    return ret;
}

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

    cin >> N;
    
    ll ans = 0;
    dp = vector<map<string,ll>>(N+2);
    for(int i=0; i<4; i++) {
        ans += dfs(0, i, C[i]);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int max(int x, int y)
{
    if (x >= y) return x;
    else return y;
}

int min(int x, int y)
{
    if (x <= y) return x;
    else return y;
}

int main()
{
    int n, t, a, h[1000];
    scanf("%d", &n);
    scanf("%d%d", &t, &a);
    int i;
    for (i=0; i<n; i++)
    {
        scanf("%d", &h[i]);
    }
    int dtmin = 1e9;
    int ans = 0;
    for (i=0; i<n; i++)
    {
        int dt = abs(t*1000 - h[i]*6 - a*1000);
        if (dt < dtmin) {
            dtmin = dt;
            ans = i + 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

template<typename T>
constexpr std::vector<std::pair<T, T>> primeFactorization(T number) noexcept {
	std::vector<std::pair<T, T>> primeFactors;
	T quotient = number;
	for (T i = 2; i * i <= quotient; ++i) {
		if (quotient % i == 0) {
			T prime = i, power = 1;

			quotient /= i;
			while (quotient % i == 0) {
				++power;
				quotient /= i;
			}

			primeFactors.push_back(std::pair<T, T>(prime, power));
		}
	}
	if (quotient != 1) primeFactors.push_back(std::pair<T, T>(quotient, 1));

	return primeFactors;
}

template<typename T>
constexpr int countDivisor(std::vector<std::pair<T, T>> primeFactors) noexcept {
	int counter = 1;
	for (int i = 0; i < primeFactors.size(); ++i) {
		counter *= (primeFactors[i].second + 1);
	}

	return counter;
}

template<typename T>
constexpr std::vector<T> findDivisor(T number) noexcept {
	std::vector<std::pair<T, T>> primeFactors = primeFactorization(number);

	std::vector<T> divisor(countDivisor(primeFactors));
	divisor[0] = 1;

	int counter = 1;
	for (int i = 0; i < primeFactors.size(); ++i) {
		int currentSize = counter;
		for (int j = 1; j <= primeFactors[i].second; ++j) {
			T x = 1;
			for (int k = 0; k < j; ++k) {
				x *= primeFactors[i].first;
			}

			for (int k = 0; k < currentSize; ++k) {
				divisor[counter + k] = divisor[k] * x;
			}
			counter += currentSize;
		}
	}
	sort(divisor.begin(), divisor.end());

	return divisor;
}

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

	ll x;
	cin >> x;

	vector<ll> divisor = findDivisor(x);
	rep(i, divisor.size()) {
		ll a, b;
		llREP(j, 1, 1e3) {
			a = j;
			b = a - divisor[i];
			if (a*a*a*a*a - b * b*b*b*b == x) {
				cout << a << " " << b << "\n";
				return 0;
			}
		}
	}


	return 0;
}



Measured memory_bytes: 3656
s = str(input())
ans = ['YYMM','MMYY','AMBIGUOUS','NA']
#print(s[:2],s[-2:])
if (0==int(s[:2]) or 13<=int(s[:2])) and (0==int(s[-2:]) or 13<=int(s[-2:])):
    print(ans[3])
if 0<int(s[:2])<=12 and 0<int(s[-2:])<=12:
    print(ans[2])
elif 0<int(s[:2])<=12:
    print(ans[1])
elif 0<int(s[-2:])<=12:
    print(ans[0])

    

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

int main(){
    while(1){
        int H,W;
        cin>>H>>W;
        if(H==0 && W==0) break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
N = int(input())
A = list(map(int,input().split()))

ans1 = c = 0
for i,a in enumerate(A):
    if i%2==0:
        if c+a > 0:
            c += a
        else:
            d = 1-(c+a)
            ans1 += d
            c = 1
    else:
        if c+a < 0:
            c += a
        else:
            d = c+a+1
            ans1 += d
            c = -1

ans2 = c = 0
for i,a in enumerate(A):
    if i%2:
        if c+a > 0:
            c += a
        else:
            d = 1-(c+a)
            ans2 += d
            c = 1
    else:
        if c+a < 0:
            c += a
        else:
            d = c+a+1
            ans2 += d
            c = -1

print(min(ans1, ans2))

Measured memory_bytes: 20144
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
const long long  INF=1e17;
long long dist[maxn];
#define ll long long
bool vis[maxn];
struct node
{
    int v,c;
    node(int _v=0,int _c=0):v(_v),c(_c){}
    bool operator <(const node &r) const
    {
        return c>r.c;
    }
};
struct edge
{
    ll v,cost;
    edge(ll _v=0,ll _cost=0):v(_v),cost(_cost){}
};
vector<edge>str[maxn];
void dijk(int n,int start)
{
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++) dist[i]=INF;
    priority_queue<node>q;
    while(!q.empty())
    {
        q.pop();
    }
    dist[start]=0;
    q.push(node(start,0));
    node tmp;
    while(!q.empty())
    {
        tmp=q.top();
        q.pop();
        int u=tmp.v;
        if(vis[u]) continue;
        vis[u]=true;
        for(int i=0;i<str[u].size();i++){
            int v=str[tmp.v][i].v;
            ll cost=str[u][i].cost;
            if(!vis[v]&&dist[v]>dist[u]+cost)
            {
                dist[v]=dist[u]+cost;
                q.push(node(v,dist[v]));
            }
        }
    }
}
void add(int u,int v,int w)
{
    str[u].push_back(edge(v,w));
}
int main()
{
    int n;
    scanf("%d",&n);
    int a,b,c;
    for(int i=0;i<n-1;i++){
        scanf("%d%d%d",&a,&b,&c);
        add(b,a,c);
        add(a,b,c);
    }
    int k,q;
    scanf("%d%d",&k,&q);
    dijk(n,q);
    for(int i=1;i<=k;i++){
        scanf("%d%d",&a,&b);
        printf("%lld\n",dist[a]+dist[b]);
    }
    return 0;
}


Measured memory_bytes: 10112
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[1010];

int main()
{
    #ifdef waltz
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n;scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans=1000000000;
    for (int x=-100;x<=100;x++)
    {
        int s=0;
        for (int i=1;i<=n;i++) s=s+(x-a[i])*(x-a[i]);
        ans=min(ans,s);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
ll MOD = 10e9 + 7;

int main() {
    int p,q,r;
    cin >> p >> q >> r;
    int m = min(p+q, p+r);
    m = min(m, q+r);
    OUT(m);
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
 
INF = 1001001001
 
def resolve():
  n = int(input())
  p = list(map(int, input().split()))
  q = list(map(int, input().split()))
  arr = []
  for i in range(1, n+1):
    arr.append(i)
 
  x = itertools.permutations(arr, n)
 
  a = 0
  b = 0
  for i, y in enumerate(x):
    if (p == list(y)):
      a = i + 1
    if (q == list(y)):
      b = i + 1
 
  print(abs(a - b))
resolve()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
long long a[200010];
int main(){
      long long n,m,i,ans=0;
      cin>>n;
      for(i=1;i<=n;i++){
      	scanf("%lld",&a[i]);
      	a[i]-=i;
      }
      sort(a+1,a+n+1);
      m=a[(n-1)/2+1];
      for(i=1;i<=n;i++)
        ans+=abs(m-a[i]);
      cout<<ans<<endl;
	  return 0;
}


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

const int N = 205;

int n, a[N];
vector<int> res;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = n - 1; i >= 0; --i) {
		int pos = -1;
		for (int j = 0; j < n; ++j) {
			if (a[j] == i) pos = j;
		}
		for (int j = 0; j <= pos; ++j) res.push_back(1);
		for (int j = pos + 1; j < n; ++j) {
			if (a[j] < a[j - 1]) {
				res.push_back(n - 1), swap(a[j], a[j - 1]);
			}
			res.push_back(1);
		}
		// for (int j = 0; j < n; ++j) cout << a[j] << ' '; cout << '\n';
	}
	cout << res.size() << '\n';
	for (auto i : res) cout << i << '\n';
}

Measured memory_bytes: 764
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(x) for x in input().split()]

d = [0] * (10**5)

for i in range(n):
    d[a[i]] += 1

ans = 1

for j in range(1, n-1):
    ans = max(ans, d[j-1] + d[j] + d[j+1])

print(ans)

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

typedef long long ll;

#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

ll a[100010];
ll s1[100010];
ll s2[100010];

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

    ll ans1 = 0,ans2 = 0;
    //ll a[n];
    REP(i,n) cin >> a[i];
    //ll s1[n] = {0};
    //ll s2[n] = {0};
    s1[0] = a[0];
    s2[0] = a[0];

    if(s1[0] <= 0){
        ans1 += 1 - s1[0];
        s1[0] = 1;
    }
    for(int i = 1;i < n;i++){
        if(i%2){
            if(-s1[i-1] > a[i]) s1[i] = s1[i-1] + a[i];
            else{
                s1[i] = -1;
                ans1 += s1[i-1] + a[i] + 1; 
            }
        }else{
            if(-s1[i-1] < a[i]) s1[i] = s1[i-1] + a[i];
            else{
                s1[i] = 1;
                ans1 += -(s1[i-1] + a[i]) + 1; 
            }
        }
    }

    if(s2[0] >= 0){
        ans2 += 1 + s2[0];
        s2[0] = -1;
    }
    for(int i = 1;i < n;i++){
        if(i%2 == 0){
            if(-s2[i-1] > a[i]) s2[i] = s2[i-1] + a[i];
            else{
                s2[i] = -1;
                ans2 += s2[i-1] + a[i] + 1; 
            }
        }else{
            if(-s2[i-1] < a[i]) s2[i] = s2[i-1] + a[i];
            else{
                s2[i] = 1;
                ans2 += -(s2[i-1] + a[i]) + 1; 
            }
        }
    }

    int ans = min(ans1,ans2);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2560
from math import sqrt

N, D = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(N)]

def get_dist(x1, x2):
    return sqrt(sum([(y-z)**2 for y, z in zip(x1, x2)]))

cnt = 0
for i in range(N-1):
    X_i = C[i]
    for X_j in C[i+1:]:
        d = get_dist(X_i, X_j)
        if d.is_integer():
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>

/*
	ax + by = c
	dx + ey = f

	ax = c - by
	x = (c - by) / a

	dx = f - ey
	x = (f - ey) / d

	(c - by) / a = (f - ey) / d
	d(c - by) = a(f - ey)
	dc - bdy = af - aey
	aey - bdy = af - dc
	y(ae - bd) = af - dc
	y = (af - dc) / (ae - bd)
*/

int main() {
	double a, b, c, d, e, f, x, y;
	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
		y = (a * f - d * c) / (a * e - b * d);
//		x = (f - e * y) / d + 0.0001;
		x = (c - b * y) / a + 0.0001;

//		if (x > (double)-0.001 && x <= (double)0) x = 0;
//		if (y > (double)-0.001 && y <= (double)0) y = 0;

		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
//#define int long long
const int INF = 1 << 30;

signed main(){

  int D; cin >> D;
  vector<int> C(26);
  for(int i = 0; i < 26; i++){
    cin >> C[i];
  }

  vector<vector<int>> S(D, vector<int>(26));
  for(int i = 0; i < D; i++){
    for(int j = 0; j < 26; j++){
      cin >> S[i][j];
    }
  }

  random_device seed_gen;
  mt19937_64 rnd(seed_gen());
  uniform_int_distribution<int> dist_T(1, 26);

  int score = -INF;
  vector<int> ans(D);
  clock_t start = clock();
  while(true){
    int res = 0;
    vector<int> L(26, 0);
    vector<int> dp(D);
    for(int i = 0; i < D; i++){
      int T = dist_T(rnd);
      res += S[i][T-1];
      L[T-1] = i;
      for(int j = 0; j < 26; j++){
        res -= C[j] * (i - L[j]);
      }
      dp[i] = T;
    }
    if(score < res){
      score = res;
      ans = dp;
    }

    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    if(time >= 1950) break;
    //cout << dp << " " << res << endl;
  }

  for(int p : ans){
    cout << p << endl;
  }

  return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int r, d, x_2000;
	cin >> r >> d >> x_2000;
	vector<int> a(10);
	a[0] = x_2000*r - d;
	for (int i = 1; i <= 9; i++) {
		a[i] = a[i - 1] * r - d;
	}
	rep(i, 10) cout << a[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    
    int r, c;
    cin >> r >> c;
    vector<vector<char>> grid(r, vector<char>(c));
    vector<vector<ll>> cnt(r, vector<ll>(c, 0));

    for(int i=0; i<r; ++i) {
        for(int j=0; j<c; ++j) {
            cin >> grid[i][j];
        }
    }

    cnt[0][0] = 1;
    for(int i=1; i<c; ++i) {
        if(grid[0][i] == '.') {
            cnt[0][i] = cnt[0][i-1];
        }
        else {
            cnt[0][i] = 0;
        }
    }
    for(int i=1; i<r; ++i) {
        if(grid[i][0] == '.') {
            cnt[i][0] = cnt[i-1][0];
        }
        else {
            cnt[i][0] = 0;
        }
    }

    for(int i=1; i<r; ++i) {
        for(int j=1; j<c; ++j) { 
            if(grid[i][j] == '.') {
                cnt[i][j] = (cnt[i-1][j] + cnt[i][j-1])%mod;
                if(cnt[i][j] < 0) {
                    cnt[i][j] += mod;
                }
            }
        }
    }
    cout << cnt[r-1][c-1]%mod << "\n";
	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long a, sum = 0, seihu = 1, ans = 0, count = 0;
  vector<long> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  for(int i = 0; i < N; i++) {
    if(sum + data.at(i) >= 0 && seihu == 1) {
      count += abs(-1 - sum - data.at(i));
      sum = -1;
      seihu = 0;
      continue;
    } else if(seihu == 1 && sum + data.at(i) < 0) {
      sum += data.at(i);
      seihu = 0;
      continue;
    }
    if(sum + data.at(i) <= 0 && seihu == 0) {
      count += abs(1 - sum - data.at(i));
      sum = 1;
      seihu = 1;
      continue;
    } else if(seihu == 0 && sum + data.at(i) > 0) {
      sum += data.at(i);
      seihu = 1;
      continue;
    }
  }
  ans = count;
  seihu = 0;
  count = 0;
  sum = 0;
  for(int i = 0; i < N; i++) {
    if(sum + data.at(i) >= 0 && seihu == 1) {
      count += abs(-1 - sum - data.at(i));
      sum = -1;
      seihu = 0;
      continue;
    } else if(seihu == 1 && sum + data.at(i) < 0) {
      sum += data.at(i);
      seihu = 0;
      continue;
    }
    if(sum + data.at(i) <= 0 && seihu == 0) {
      count += abs(1 - sum - data.at(i));
      sum = 1;
      seihu = 1;
      continue;
    } else if(seihu == 0 && sum + data.at(i) > 0) {
      sum += data.at(i);
      seihu = 1;
      continue;
    }
  }
  ans = min(ans, count);
  cout << ans << endl;
  return 0;
}

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

int N, height[MAXN + 3], beauty[MAXN + 3];
LL dp[MAXN + 3], tree[4 * MAXN + 3], answer;

LL query(int node, int l, int r, int a, int b) {
    if (r < a || l > b)
        return 0;

    if (l >= a && r <= b)
        return tree[node];

    int m = (l + r)/2;
    LL lft = query(2 * node, l, m, a, b);
    LL rght = query(2 * node + 1, m + 1, r, a, b);

    return max(lft, rght);
}

void update(int node, int l, int r, int idx, LL val) {
    if (l == r) {
        tree[node] = max(tree[node], val);
        return;
    }

    int m = (l + r)/2;
    if (idx <= m)
        update(2 * node, l, m, idx, val);
    else
        update(2 * node + 1, m + 1, r, idx, val);

    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> height[i];

    for (int i = 1; i <= N; i++)
        cin >> beauty[i];

    memset(tree, 0, sizeof(tree));

    dp[1] = beauty[1];
    update(1, 1, MAXN, height[1], dp[1]);

    answer = dp[1];
    for (int i = 2; i <= N; i++) {
        dp[i] = query(1, 1, MAXN, 1, height[i] - 1) + beauty[i];
        answer = max(answer, dp[i]);

        update(1, 1, MAXN, height[i], dp[i]);
    }

    cout << answer << endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dc(int v){
	int cnt=0;
	while(v>0){
		v/=10;
		cnt++;
	}
	return cnt;
}

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

int main(void){
	int s;
	scanf("%d",&s);
	int l=1,r=0;
	int sum=0;
	ll ans=0;
	while(1){
		while(sum<s){
			r++;
			sum+=dc(r);
		}
		if(dc(r)==dc(l))break;
		if(sum==s)ans++;
		sum-=dc(l);
		l++;
	}
	ll ten_pow=1;
	for(int i=1;i<dc(l);i++){
		ten_pow=ten_pow*10LL%MOD;
	}
	for(int i=dc(l);i<=s;i++){
		ll diff=s%i;
		if(diff==0){
			ll need=s/i;
			ans+=(ll)ten_pow*9LL-need+1LL;
			ans+=MOD;
			ans%=MOD;
		}
		ten_pow=ten_pow*10LL%MOD;
		if(diff==0)diff=i;
		//printf("%d s-%lld\n",i,ans);
		if(diff*(i+1)>=s)continue;
		ll st=(s-(diff)*(i+1))/i;
		ans+=(st-1LL)/(i+1LL)+1LL;
		ans%=MOD;
		//printf("%d a-%lld\n",i,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    public class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if(s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 25824
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

std::string a,b;

int main() {
	std::cin>>a>>b;
	int len1=a.length(),len2=b.length();
	if(len1!=len2-1) {
		puts("No");
		return 0;
	}
	for(int i=0;i<len1;++i) {
		if(a[i]!=b[i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	ss := strings.Split(s, "")
	st := strings.Split(t, "")

	sort.Strings(ss)
	sort.Strings(st)
	reverse(st)

	js := strings.Join(ss, "")
	jt := strings.Join(st, "")

	if js < jt {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func reverse(s []string) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}


Measured memory_bytes: 640
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    936 Hours of Solitude
    Quarantine_Day : 39
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 90

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

    string x, y; cin>>x>>y;

    SORT(x); SORT(y); REV(y);

    cout<<(x < y?"Yes\n":"No\n");

    return 0;
}


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

 
int main() {

    int64_t n,k;
    cin>>n>>k;


    vector<int64_t> A(n);
    for(int i=0;i<n;i++){
        cin>>A.at(i);
        A.at(i)--; // 0～にする。
    } 


    vector<int64_t> visit(n);
    int64_t next=0;
    int64_t loop_length=1;
    bool loop_flg=false;
    for(int i=0;i<n;i++){
//        cout<<next<<" ";
        visit.at(next) = i+1;
        next = A.at(next);

        if(visit.at(next) != 0){
            loop_length = i+1 - visit.at(next)+1;
            loop_flg=true;
            break;
        }
    }

    int64_t index;
    if(k>n)
        index = (k-visit.at(next))%loop_length;
    else{
        index=k-1;
        next=0;
    }
//    cout<<"loop_length="<<loop_length<<endl;
//    cout<<"index="<<index<<endl;
    for(int i=0;i<index;i++){
        next = A.at(next);
    }

//    cout<<endl;
    cout<<++A.at(next)<<endl;

 	return 0;
}


Measured memory_bytes: 6412
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;

//#define __DBG__


void solve(void){
  
  int a,b;
  
  cin >> a >> b;
  
  if(a>9 || b>9){
    cout << "-1" << endl;
    return;
  }
  
  cout << a*b << endl;

  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
#include <iomanip>  
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c < 22)cout << "win" << endl;
	else cout << "bust" << endl;


}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  if(s.length() == 2) cout << s << endl;
  else {
    string ans="";
    ans.push_back(s[2]);
    ans.push_back(s[1]);
    ans.push_back(s[0]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int x[100];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> x[i];
	
	int ans = 1e+18;
	for (i = -1000; i <= 1000; i++) {
		int cst = 0;
		rep(j, n) {
			cst += (i - x[j]) * (i - x[j]);
		}
		ans = min(ans, cst);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

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

  int s = 0;

  for (int i = 1; i <= n; i++){
    int r = 0;
    int j = i;
    while(j > 0){
      j /= 10;
      r++;
    }
    if (r % 2 == 1)
      s++;
  }


  cout << s << endl;


  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n);++i)
using namespace std;
typedef long long ll;

/*ll gcd(ll x,ll y){
    if (y==0)
        return x;
    return gcd(y, x % y);
}*/

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i){
        if (n%i) continue;
        res.emplace_back(i, 0);
        while(n%i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main(){
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A, B);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}

int main() {
	ll x, ans;
	cin >> x;
	ans = (x / 11 + 1)*2;
	if (x % 11 <= 6)
		ans--;
  if(x%11==0)
    ans=x*2/11;
  cout<<ans<<endl;
}


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

class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] alphabet = new int[26];
		char a = 'a';

		while(true){
			String str = br.readLine();
			if(str == null)
				break;
			for(int i=0; i<str.length(); i++){
				if(Character.isUnicodeIdentifierStart(str.charAt(i))){
					int num = Character.toLowerCase(str.charAt(i)) - 'a';
					alphabet[num]++;
				}
			}
		}

		for(int i=0; i<alphabet.length; i++){
			System.out.println(a++ + " : " + alphabet[i]);
		}
	}

}

Measured memory_bytes: 16872
import math
a, b, c, x, y = map(int,input().split(' '))
x=2*x
y=2*y

minp=0
# a,c
tmp=c*y+max(math.ceil((x-y)/2),0)*a
minp =tmp
# b,c
tmp=c*x+max(math.ceil((y-x)/2),0)*b
if minp > tmp:
    minp=tmp

# c
tmp=c*max(x,y)
if minp > tmp:
    minp=tmp
# a, b
tmp=a*math.ceil(x/2)+b*math.ceil(y/2)
if minp > tmp:
    minp=tmp

print(minp)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int k;
    ll max_ = 2, min_ = 2;
    cin >> k;
    vector<ll> a(k);
    rep(k){
        cin >> a[i];
    }
    a.push_back((ll)(INT_MAX/2-1));

    for(int i=k-1;i>=0;i--){
        min_ = (min_ + a[i] - 1LL) / a[i] * a[i];
    }

    ll tmp = min_;
    rep(k){
        tmp = tmp / a[i] * a[i];
    }
    if(tmp != 2){
        cout << -1 << endl;
        return 0;
    }

    for(int i=k-1;i>=0;i--){
        max_ = (max_ + a[i] - 1LL) / a[i] * a[i] + a[i] - 1;
        if(i == 0) break;
        max_ = max_ / a[i-1] * a[i-1];
    }

    tmp = max_;
    rep(k){
        tmp = tmp / a[i] * a[i];
    }
    if(tmp != 2){
        cout << -1 << endl;
        return 0;
    }

    cout << min_ << " " << max_ << endl;
    return 0;
}


Measured memory_bytes: 1792
n,k,s=map(int,input().split())
if k==n:
    x=[s]*n
    print(" ".join(map(str,x)))
elif k==0:
    if s<10**9:
        x=[s+1]*n
    else:
        x=[1]*n
    print(" ".join(map(str,x)))
else:
    if s<10**9:
        x=[s]*k
        y=[s+1]*(n-k)
    else:
        x=[s]*k
        y=[1]*(n-k)
    z=" ".join(map(str,x))+" "+" ".join(map(str,y))
    print(z)


Measured memory_bytes: 12068
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] an = new int[n];
        for(int i=0; i<n; i++){
            an[i] = Integer.parseInt(sc.next());
        }
        int queri = Integer.parseInt(sc.next());
        int target = 0;
        int sum=0, bit=0;
        for(int i=0; i<queri; i++){
            target = Integer.parseInt(sc.next());
            for(bit=0; bit < (1<<n); bit++){
                sum=0;
                for(int j=0; j<n; j++){
                    if((bit&(1<<j)) > 0){
                        sum += an[j];
                    }
                }
                if(sum == target){
                    System.out.println("yes");
                    break;
                }
            }
            if(bit == (1<<n)) System.out.println("no");
        }
    }
}


Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define ll long long
#define rsz resize
#define mod 1000000007
vector<vector<int> >v(1010);
int main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   bool flag=true;
   for(int i=0;;++i)
   {
       if(a<=0 && c>0)
       {
           flag=false;
           break;
       }
        if(c<=0 && a>0)
       break;
       if(i%2==0)
       {
           c-=b;
       }
       else
       a-=d;
   }
   if(flag)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;

int main(void) {
  string s,fo="",ba=""; //aはs前の文字列を反転したもの、bはs後ろの文字列
  int q;
  cin>>s>>q;
  bool r=false;
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1) r=!r;
    else{
      int f;
      string c,d;
      cin>>f>>c;
      d=c,reverse(d.begin(),d.end());
      if(f==1){
        if(r) ba+=d;
        else fo+=d;
      }
      else{
        if(r) fo+=c;
        else ba+=c;
      }
    }
  }
  
  string ans;
  if(r){
      reverse(s.begin(),s.end());
      reverse(ba.begin(),ba.end());
      ans=ba+s+fo;
  }
  else{
      reverse(fo.begin(),fo.end());
      ans=fo+s+ba;
  }
  
  int k=ans.size();
  for(int i=0;i<k;i++) cout<<ans[i];
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 1348
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int N, K;
	cin >> N >> K;
	if ((N + 1) / 2 >= K) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val S = next()
    val N = S.length
    val MOD = 1000000007L
    val dp = Array(N + 1) { LongArray(3 + 1) }
    for (i in (0 .. N).reversed()) {
        for (j in (0 .. 3).reversed()) {
            if (i == N) {
                dp[i][j] = if (j == 3) 1 else 0
            } else {
                dp[i][j] = dp[i + 1][j] * (if (S[i] == '?') 3 else 1)
                if (j < 3 && (S[i] == '?' || S[i] == "ABC"[j])) {
                    dp[i][j] += dp[i + 1][j + 1]
                }
                dp[i][j] %= MOD
            }
        }
    }
    println(dp[0][0])
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }





Measured memory_bytes: 40972
package main

import (
	"fmt"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var n int
	fmt.Scan(&n)
	var s float64
	for i := 0; i < n; i++ {
		var t float64
		fmt.Scan(&t)
		s += 1.0 / t
	}
	fmt.Println(1.0 / s)
}


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

int main() {
  string S;
  cin >> S;
  int suma=0,sumb=0;
  for(int i=0;i<S.length();i++){
    if(i%2==0){
      if(S[i]=='0')suma++;
      else sumb++;
    }
    else{
      if(S[i]=='0')sumb++;
      else suma++;
    }
  }
  cout << min(suma,sumb);
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
long long n, m, a[200000], b[200000], c[200000], p[200000], x[200000];
int main() {
	cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d", &p[i]); }
	for (int i = 1; i <= n - 1; i++) { scanf("%d%d%d", &a[i], &b[i], &c[i]); }
	for (int i = 0; i < m - 1; i++) { int a = p[i], b = p[i + 1]; if (a > b)swap(a, b); x[a]++; x[b]--; }
	for (int i = 1; i <= n; i++)x[i] += x[i - 1];
	long long sum = 0; for (int i = 1; i <= n - 1; i++) { sum += min(a[i] * x[i], b[i] * x[i] + c[i]); }
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 7072
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;


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

    string S;
    cin >> S;

    queue<int> startIndexes;
    stack<int> endIndexes;

    int happyHumans = 0;
    int happyHumansLimit = N-1;
    //初期状態読込
    for (int i = 1; i < N ; i++){
        
        if (S[i-1] == S[i]){
            happyHumans++;
        } else if(S[0] != S[N-1] && i == N-1){
            //操作候補
            startIndexes.push(i);
            endIndexes.push(i);
        } else {
            //操作候補
            startIndexes.push(i);
            endIndexes.push(i);
        }
    }


    //操作
    bool isFirstSkip = false;
    while( K > 0 && happyHumans < happyHumansLimit && !(startIndexes.empty())){

        int startIndex = startIndexes.front();
        startIndexes.pop();
        int endIndex = endIndexes.top();
        endIndexes.pop();

        if (endIndex == N-1) {
            //1つしかカウントアップしないため、あとに回す
            isFirstSkip = true;
            continue;
        }

        if(startIndex < endIndex){
            happyHumans += 2;
            K--;
            continue;
        }
        if(startIndex = endIndex){
            happyHumans += 2;
            K--;
            break;
        }
        if(startIndex > endIndex){
            break;
        }
    }

    if ( K > 0 && isFirstSkip && happyHumans < happyHumansLimit) {
        happyHumans ++;
    }

    cout << min(happyHumans,happyHumansLimit) << endl;
    return 0;
}

Measured memory_bytes: 1152
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

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

const int N=100000+10;
const int mod=1e9+7;

int n,m,cnt,top;
int a[N],b[N],S[N];
pair<int,int> p[N];
int f[N];

inline int cmp(pair<int,int> a,pair<int,int> b) {
    if (a.first!=b.first) return a.first<b.first;
    else return a.second>b.second;
}

int c[N];
inline int lowbit(int x) { return x&-x; }
inline int query(int x) { int res=0;
    for (;x;x-=lowbit(x)) res=(res+c[x])%mod;
    return res;
}
inline void add(int x,int y) {
    for (;x<=top;x+=lowbit(x)) c[x]=(c[x]+y)%mod;
}

int main() {
    n=read(),m=read();
    for (re int i=1;i<=n;++i) a[i]=read();
    for (re int i=1;i<=m;++i) b[i]=read();
    for (re int i=1;i<=n;++i) {
        if (a[i]<=b[1]||a[i]>=b[m]) continue;
        int x=lower_bound(b+1,b+m+1,a[i])-b;
        if (b[x]==a[i]) continue;
        p[++cnt]=make_pair(a[i]-b[x-1],b[x]-a[i]);
        S[++top]=b[x]-a[i];
    }
    sort(S+1,S+top+1); top=unique(S+1,S+top+1)-S-1;
    for (re int i=1;i<=cnt;++i)
        p[i].second=lower_bound(S+1,S+top+1,p[i].second)-S;
    sort(p+1,p+cnt+1,cmp); cnt=unique(p+1,p+cnt+1)-p-1;
    f[0]=1;
    for (re int i=1;i<=cnt;++i)
        f[i]=query(p[i].second-1)+1,add(p[i].second,f[i]);
    int ans=0;
    for (re int i=0;i<=cnt;++i) ans=(ans+f[i])%mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#define N 105
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	int a[N], b[N];
	int n, m, x, y, mx = -1000, mn = 1000;
	cin >> n >> m >> x >> y;
	for(int i = 1; i <= n; i++)  {
		cin >> a[i];
		if(a[i] > mx) mx = a[i];
	}
		
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
		if(mn > b[i]) mn = b[i];
	}
	for(int i = mx+1; i <= mn; i++) {
		if(i <= y && i > x) {
			cout << "No War\n";
			return 0;
		}
	}
	cout << "War\n";
	return 0;
}

Measured memory_bytes: 256
s =input()

even = ["L", "U", "D"]
odd  = ["R", "U", "D"]
cnt = 1
result = "Yes"

for i in s:

    if cnt % 2 == 0:
        
        if not(i in even):
            result = "No"
            break
    else:
        if not(i in odd):
            result = "No"
            break
    cnt += 1
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
    int n, m;
    cin >> n >> m;
    int foods[m];

    for(int i = 0; i < m; i++){
        foods[i] = 0;
    }

    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int num;
            cin >> num;
            foods[num-1] += 1;
        }
    }
    
    int res = 0;
    for(int i = 0; i < m; i++){
        if(foods[i] == n){
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main()
{
  int m;
  cin>>m;
  for(;m--;)
    {
      map<string,bool> hash;
      string s;
      cin>>s;
      hash[s]=true;
      for(int i=1;i<s.size();i++)
	{
	  string ss[4];
	  ss[2]=ss[0]=s.substr(0,i);
	  ss[3]=ss[1]=s.substr(i,s.size()-i+1);
	  reverse(ss[2].begin(),ss[2].end());
	  reverse(ss[3].begin(),ss[3].end());
	  
	  for(int i=0;i<4;i++)
	    for(int j=0;j<4;j++)
	      { 
		if(i!=j && 
		   !(i==0 && j==2) &&
		   !(i==2 && j==0) &&
		   !(i==1 && j==3) &&
		   !(i==3 && j==1))
		  hash[ss[i]+ss[j]]=true;
	      }
	}
      
      //      for(map<string,bool>::iterator it=hash.begin();it !=hash.end();it++)
	//	cout<<it->first<<endl;
      cout<<hash.size()<<endl;
    }
}

Measured memory_bytes: 1300
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#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 all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long int ll;

int main(){
  int n;  cin >> n;
  vector<int> map(100);
  int ans=0;
  rep(i, 0, n)  cin >> map[i];
  sort(map.begin(), map.begin()+n);
  rep(i, 0, n-1){
    ans += abs(map[i+1]-map[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

class UnionFind {
public:
  vector <ll> par;
  vector <ll> siz;
  UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  ll root(ll x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    UnionFind uf(N);
    rep(i,M) {
        int x,y; cin >> x >> y;
        uf.merge(x,y);
    }
    if (2*(N-M-1) > N) {
        cout << "Impossible" << endl;
        return 0;
    }
    if (M==N-1) {
        cout << 0 << endl;
        return 0;
    }
    map<int, ll> dic;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i,N) {
        int k = uf.root(i);
        if (!dic.count(k)) dic.emplace(k,A[i]);
        else {
            if (dic[k] > A[i]) {
                pq.emplace(dic[k]);
                dic[k] = A[i];
            } else pq.emplace(A[i]);
        }
    }

    ll ans = 0;
    for (auto i : dic) ans += i.second;
    rep(i,N-M-2) {
        ans += pq.top(); pq.pop();
    } 

    cout << ans << endl;

}

Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

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

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}


int main() {
  int a, b, c, k, ans = 0; cin >> a >> b >> c >> k;
  
  if (a <= k) ans = a;
  else ans = k;
  
  if (k-a-b >= 0) ans -= k-a-b;
  
  cout << ans << endl;

}

Measured memory_bytes: 3640