akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
int n, m, s[3005][3005], fac[3005], inv[3005], mul2[3005];
int ksm(int a, int b, int mod)
{
    int s = 1;
    while (b)
    {
        if (b & 1)
        {
            s = s * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return s;
}
void init()
{
    s[0][0] = 1;
    for (int i = 1; i <= 3001; i++)
    {
        for (int j = 1; j <= 3001; j++)
        {
            s[i][j] = (s[i - 1][j - 1] + j * s[i - 1][j] % m) % m;
        }
    }
    fac[0] = mul2[0] = 1;
    for (int i = 1; i <= 3001; i++)
    {
        fac[i] = fac[i - 1] * i % m;
    }
    inv[3001] = ksm(fac[3001], m - 2, m);
    for (int i = 3000; i >= 0; i--)
    {
        inv[i] = inv[i + 1] * (i + 1) % m;
    }
    for (int i = 1; i <= 3001; i++)
    {
        mul2[i] = mul2[i - 1] * 2 % (m - 1);
    }
}
#undef int
int main(int argc, char const *argv[])
{
    #define int long long
    scanf("%lld%lld", &n, &m);
    init();
    int ans = 0, f = -1, tmp;
    for (int i = 0; i <= n; i++)
    {
        f *= -1;
        tmp = 0;
        for (int k = 0; k <= i; k++)
        {
            tmp = (tmp + s[i + 1][k + 1] * ksm(2LL, ((n - i) * k + mul2[n - i]) % (m - 1), m) % m) % m;
        }
        ans = (ans + f * fac[n] * inv[i] % m * inv[n - i] % m * tmp % m) % m;
    }
    printf("%lld", (ans + m) % m);
    return 0;
}

Measured memory_bytes: 74356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gg(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}

int main()
{
     io;
    int T=1;
    //T=gg();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       ll d,t,s;
       cin>>d>>t>>s;
       if(s*t>=d)cout<<"Yes";
       else cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;



int main(){
   string s,t;
   cin >> s >> t;
   cout << t << s << endl;
   
   
   return 0;
}

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

/* -------------------------------- Template -------------------------------- */

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> T inf() { assert(false); }
template<> constexpr int inf<int>() { return 1e9; }
template<> constexpr ll inf<ll>() { return 1e18; }
template<> constexpr ld inf<ld>() { return 1e30; }

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int main() {
  string str;
  cin >> str;
  int n = str.size();
  vector<ll> se;
  REP(bit,1<<(n-1)) {
    ll num = 0, s = 0;
    REP(i,n) {
      s = s * 10 + (int)(str[i] - '0');
      if (((bit >> i) & 1) || i == n - 1) {
        num += s;
        s = 0;
      }
    }
    se.push_back(num);
  }
  ll res = 0;
  for (ll i: se) res += i;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h, w;
    scanf("%d %d", &h, &w);
    int n;
    scanf("%d", &n);
    int i;
    int a[10004];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int j, k;
    k = 0;
    int ans[102][102];
    for (i = 0; i < h; i++)
    {
        if (i % 2 == 0)
        {
            for (j = 0; j < w; j++)
            {
                ans[i][j] = k + 1;
                a[k]--;
                if (a[k] == 0)
                    k++;
            }
        }
        else
        {
            for (j = w - 1; j >= 0; j--)
            {
                ans[i][j] = k + 1;
                a[k]--;
                if (a[k] == 0)
                    k++;
            }
        }
    }
    for (i = 0; i < h; i++)
    {
        printf("%d", ans[i][0]);
        for (j = 1; j < w; j++)
            printf(" %d", ans[i][j]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl
typedef long long ll;
using namespace std;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	int n;
	cin >> n >> a;
	cout << n - a + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

   long long ans = 0;
   for(int i=1; i<=N; ++i){
      if(!(i%3==0 || i%5==0)) ans += i;
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 3548
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
char s[N];int a[N],n,x,m,res;
int main(){
	scanf("%d%d",&x,&n);
	fp(i,1,n)scanf("%d",&a[i]);
	a[n+1]=a[1]+x,res=x;
	fp(i,1,n)cmin(res,x-(a[i+1]-a[i]));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1024
def ds n
  res = 0
  while n>0
    res += n%10
    n /= 10
  end
  res
end

n = gets.to_i
ans = [ds(n)]
n = n.to_s

t = 0
while n.size!=0
  t += n[0].to_i
  ans << t-1+ds(10**(n.size-1)-1)
  n = n[1..-1]
end

p ans.max


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) if(a<b)a=b
#define LL long long
const int N=1e5+5;

int n,m;
int w[N],v[N];
LL dp[N],ans;

int main()
{
	
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",w+i,v+i);
	for(int i=1;i<=n;i++)
	for(int j=m-w[i];j>=0;j--)
		chmax(dp[j+w[i]],dp[j]+v[i]);
	for(int i=1;i<=m;i++)
		chmax(ans,dp[i]);
	printf("%lld\n",ans);
	
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=998244353; //1000000007
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	char str[200005];
	scanf("%s",str);
	int n=strlen(str);
	for(int i=0;i<n;i++)if(str[i]=='?')str[i]='D';
	printf("%s",str);
}


Measured memory_bytes: 4020
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int year, month, day;
    char left, right;
    cin >> year >> left >> month >> right >> day;

    if(month <= 4) cout << "Heisei" << endl;
    else cout << "TBD" << endl;

    return 0;
}


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

int main(){
 int n,k;cin >> n >> k;
 vector<int> flag(n,0);
 rep(i,n){
   int a;
   cin >> a;
   flag[a-1]++;
 }
 sort(flag.begin(),flag.end());
 int sum=n;
 for(int i=n-1;i>=n-k;i--)sum-=flag[i];

 cout << sum << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 512345;

class{
public:
	int a[N] = {};
	void add(int i, int x){
		while(i < N){
			a[i] += x;
			i += i&-i;
		}
	}
	int sum(int i){
		int x = 0;
		while(i){
			x += a[i];
			i -= i&-i;
		}
		return x;
	}
} bt;
int c[N], b[N] = {};
vpii qs[N];
int ans[N];

int main(){
	int n, q; scanf("%d%d", &n, &q);
	FOR(i, 1, n+1) scanf("%d", c+i);
	REP(i, q){
		int s, t; scanf("%d%d", &s, &t);
		qs[t].EB(s, i);
	}
	FOR(j, 1, n+1){
		if(b[c[j]]) bt.add(b[c[j]], 1);
		b[c[j]] = j;
		for(auto [i, h] : qs[j])
			ans[h] = (j-i+1) - (bt.sum(j) - bt.sum(i-1));
	}
	REP(i, q) printf("%d\n", ans[i]);
}


Measured memory_bytes: 32868
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c||b+c==a||c+a==b)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

vll into_binary(ll a) {
  vll v(60, 0);
  ll b = pow(2, 59);
  for (ll i = 0; i < 60; i++) {
    if (a >= b) {
      v[i]++;
      a -= b;
      if (a == 0) break;
    }
    b /= 2;
  }
  return v;
}

int main() {
  ll n, p = 1000000007;
  cin >> n;

  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];

  vector<vll> base(n, vll(60));
  for (ll i = 0; i < n; i++) base[i] = into_binary(a[i]);

  vll ans(60);
  for (ll i = 0; i < 60; i++) {
    ll x = 0, y = 0;
    for (ll j = 0; j < n; j++) {
      if (base[j][i] == 0) x++;
      else y++;
    }
    ans[i] = x * y % p;
  }

  ll ans_10 = 0, b = pow(2, 59);
  for (ll i = 0; i < 60; i++) {
    ans_10 += (ans[i] % p) * (b % p) % p;
    ans_10 %= p;
    b /= 2;
  }

  cout << ans_10 << endl;
}

Measured memory_bytes: 154880
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
vector<pll > da;
ll dp[100005][105];
ll try1(ll w, ll i, ll n)
{
	if(dp[w][i]!=-1)
		return dp[w][i];

	if(w<=0 || i>=n)
		return 0;

	if(w-da[i].first>=0)
	{
		dp[w][i] =  max(da[i].second+try1(w-da[i].first,i+1,n),try1(w,i+1,n));
		return dp[w][i];
	}
	return 0;

}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i,n,W;
	ll j;
	ll w,v;

	for(i=0;i<100005;i++)
		for(j=0;j<105;j++)
			dp[i][j]=-1;

	cin>>n>>W;
	for(i=0;i<n;i++)
	{
		cin>>w>>v;
		da.pb(mp(w,v));
	}
	sort(da.begin(),da.end());
	cout<<try1(W,0,n)<<endl;
	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	string s,t;cin>>s>>t;
	int a,b;cin>>a>>b;
	string u;cin>>u;
	if(u==t) b--;
	if(u==s) a--;
	cout << a << " " << b;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

int d,n,a,b;

int main(){
    while(cin>>d>>n){
        a = n;
        b = 1;
        while(d--) {
            a *= 100;
            b *= 100;
        }

        if(n==100)
            printf("%d\n",a+b);
        else
            printf("%d\n",a);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,K;
    int i;
    scanf("%d%d",&N,&K);

    int h[N];
    int count=0;

    for(i=0;i<N;i++){
        scanf("%d",&h[i]);
        if(K<=h[i]){
            count++;
        }
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

#define N 100001

int Partition(int A[],int p,int r);

int main(){
  int A[N];
  int n,i,q;

  scanf("%d", &n);

  for(i = 0; i < n ; i++) scanf("%d",&A[i]);

  q = Partition(A,0,n-1);

  for(i = 0 ; i < n ; i++){
    if(i == q){
      printf("[%d] ",A[i]);
    } else if(i != n-1) {
      printf("%d ", A[i]);
    }
    else printf("%d",A[i]);
  }
  printf("\n");

  return 0;
}

int Partition(int A[],int p,int r) {
  int i,j,x,y,z;

  x = A[r];
  i = p-1;

  for(j = p ; j < r ; j++) {
    if(A[j] <= x) {
      i += 1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }

  z = A[i+1];
  A[i+1] = A[r];
  A[r] = z;

  return i+1;
}

Measured memory_bytes: 992
S = list(input())
N = len(S)
T = [S[i] for i in range(N)]
c1 = 0

for i in range(1,N):
  if T[i] == T[i-1]:
    if T[i-1] == '0':
      T[i] = '1'
      c1 += 1 
    else:
      T[i]= '0'
      c1 += 1

if  S[0] == '0':
  S[0] = '1'
else:
  S[0] = '0'
c2 = 1
for i in range(1,N):
  if S[i] == S[i-1]:
    if S[i-1] == '0':
      S[i] = '1'
      c2 += 1 
    else:
      S[i]= '0'
      c2 += 1

print(min(c1,c2))

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint A(N); cin >> A;

	int cnt = 0;
	for (int i = 0; i < N; i += 2) {
		if (A[i]&1) cnt++;
	}
	cout << cnt << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3656
n, a, b, c, d = map(int, input().split())
s = input()
if "##" in s[min(a,b):max(c,d)]:
    print("No")
    exit()
if c < d:
    print("Yes")
else:
    if "..." in s[b-2:d+1]:
        print("Yes")
    else:
        print("No")

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

int main(){    
    int n, a[100000];
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];

    map<int,int> mp;
    mp[a[0]] = 1;
    for(int i=1;i<n;i++){
        auto it = mp.lower_bound(a[i]);
        if(it != mp.begin()){
            --it;
            (it->second)--;
            if(it->second == 0) mp.erase(it);
        }
        mp[a[i]]++;
    }

    int ans = 0;
    for(auto m : mp) ans += m.second;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int INF = 1e9;
const int A = 1000005;
int main(){
    int n;cin>>n;
    vector<int> a(n);
    vector<int> dd(A,0);
    rep(i,n){cin>>a[i];dd[a[i]]++;}
    int sai=0;

    bool pairwise = true;
    for (int i = 2;i < A;i++){
        int cnt = 0;
        for(int j = i;j<A;j += i){
            cnt += dd[j];
        }
        if(cnt > 1){
            pairwise = false;
        }
        
    }
    if(pairwise){
            cout<<"pairwise coprime"<<endl;
            return 0;
        }
    rep(i,n){
        sai = __gcd(sai,a[i]);
        
    }
    if(sai==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;

    return 0;
}

Measured memory_bytes: 11092
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        long X = cin.nextLong();

        long A = N - X;
        long B = X;
        if (A > B) swap(ref A, ref B);
        Console.WriteLine(N + dfs(A, B));
    }

    //swap
    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    } 

    long dfs(long a, long b)
    {
        long ans = (a / b) * 2 * b;
        if (a % b == 0) return ans - b;
        else return ans + dfs(b, a % b);
    }

}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

    public long nextLong()
    {
        return long.Parse(next());
    }

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

    public double nextDouble()
    {
        return double.Parse(next());
    }


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


Measured memory_bytes: 13140
// Palindromic Number
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;


int main()
{
  int A, B, count=0;
  cin >> A >> B;

  for(int i = A; i <= B; i++){
    string front, back;
    front = std::to_string(i);
    back = std::to_string(i);
    std::reverse(back.begin(), back.end());
  
    if(front == back){
      count++;
    }
  }

  cout << count << endl;
  
  return 0;
}


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

int main()
{
    int n, x;
    int a[200005] = {};
    cin >> n;

    for (int i = 1; i < n; ++i)
    {
        cin >> x;
        ++a[x - 1];
    }
    for (int i = 0; i < n; ++i)
    {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 4416
#include <stdio.h>
const int MAX_V = 10000; // 100???????????????????f???????¢\????°???¬?????
int prime[MAX_V+1];
int main() {
	int k,i,max,min,n; // 1????????f???????C0????????f????????????????????¢
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2???????£????f????????????°??????¨
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0; // ???f??????2???{???????£????{?????????f????????????????????¢
			}
		}
	}
	while(scanf("%d",&n)){
		if(n == 0)break;
		max = 0; min = 0;
		for(i = n;i > 0;i--){
			if(prime[i] && prime[i-2]){
				max = i;
				min = max -2;
				//printf("%d %d\n",i-2,i);
				break;
			}
		}
		printf("%d %d\n",min,max);
	}
	return 0;
}

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


int dp[1001][1001];

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

    int n,m; cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(3)); rep(i,n) rep(j,3) cin >> a[i][j];
    ll ans = 0LL;
    for(int bit = 0; bit < 8; ++bit){
        sort(a.begin(), a.end(), [&](vector<ll> a, vector<ll> b){
            ll a1 = 0LL, b1 = 0LL;
            rep(i,3){
                if(bit & (1 << i)){
                    a1 += a[i];
                    b1 += b[i];
                }else{
                    a1 -= a[i];
                    b1 -= b[i];
                }
            }
            return a1 < b1;
        });
        ll tmp[3]; rep(i,3) tmp[i] = 0LL;
        rep(i,m) rep(j,3){
            if(bit & (1 << j)) tmp[j] += a[i][j];
            else tmp[j] -= a[i][j];
        }
        ll ret = 0LL;
        rep(i,3) ret += abs(tmp[i]);
        ans = max(ans, ret);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
/**
 * Created by hiramekun at 20:07 on 2019-08-27.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vl a(x), b(y), c(z);
    cin >> a;
    cin >> b;
    cin >> c;

    vl ab;
    rep(i, x) rep(j, y) ab.eb(a[i] + b[j]);
    sort(all(ab), greater<>());
    sort(all(c), greater<>());

    
    vl ans;
    rep(i, min(k, x * y)) rep(j, min(k, z)) ans.eb(ab[i] + c[j]);
    sort(all(ans), greater<>());
    rep(i, k) cout << ans[i] << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



Measured memory_bytes: 43368
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  string S;
  cin >> N >> S;
  ll ans = 1e10;
  vector<ll> wa(N + 1);
  wa[0] = 0;
  for (int i = 1; i <= N; i++) {
    wa[i] = wa[i - 1];
    if (S[i - 1] == '.') wa[i]++;
  }
  for (int i = 1; i <= N; i++) {
    ll l = wa[i];
    ll r = wa[N] - wa[i];
    ans = min(ans, (i - l) + (r));
  }
  ans = min(min(wa[N],ans), N - wa[N]);
  cout << ans << endl;
}

Measured memory_bytes: 5240
class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    dice = dice(1, 2, 3)
    order = list(input())
    for v in order:
        dice.roll(v)
    print(dice.dice[dice.t-1])


Measured memory_bytes: 5604
n = int(input())
w = list(input() for i in range(n))
s = True

for i in range(len(w)-1):
  if w[i][-1]!=w[i+1][0]:
    s = False
    break

ws = set(w)
if s and len(ws)==len(w):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
import sys

def solve():
    input = sys.stdin.readline
    X, N = map(int, input().split())
    P = [int(p) for p in input().split()]
    Num = [True] * 102
    for p in P: Num[p] = False
    minDiff = 10000000000
    ans = 0
    for i, t in enumerate(Num):
        if t == True and abs(X - i) < minDiff:
            ans = i
            minDiff = abs(X - i)
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9204
import sys
lines = [line.strip() for line in sys.stdin]
cards = lines[0]
m = int(lines[1])
lines_index = 2
while m > 0:
    line = lines[lines_index]
    if line == '-':
        break
    h = int(line)
    cards = cards[h:] + cards[:h]
    m -= 1
    if m == 0:
        print (cards)
        lines_index += 1
        cards = lines[lines_index]
        if cards == '-':
            break
        lines_index += 1
        m = int(lines[lines_index])
    lines_index += 1

Measured memory_bytes: 7756
N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

require 'pp'
def debug obj
  # PP.pp obj, STDERR
end
debug [N,K]
debug A
sum = 0
sumA = A.map{|a| sum += a }
bt_list = []

(0..(N)).to_a.combination(2) do |l,r|
  bt_list.push(((sumA[r] || 0) - sumA[l]).abs)
end

bt_list.sort!.reverse!
debug bt_list

r = 0

max = sumA.last

maxlog = Math.log2(max).to_i
bt_list_size = bt_list.size
maxlog.downto(0) do |i|
  count = 0
  ra = r + (1 << i)
  nbt_list = []
  bt_list.each do |bt|
    if ra == ( ra & bt )
      count += 1
      nbt_list.push(bt)
    end
  end
  if count >= K
    r = ra
    bt_list = nbt_list
  end
end

puts r

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

int main(int argc, char const *argv[])
{
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;

  int answer = 0;
  for (int i = 0; i < N; ++i)
  {
    bool ab = A[i] == B[i];
    bool bc = B[i] == C[i];
    bool ca = C[i] == A[i];
    int matched = ab + bc + ca;
    if (matched == 1)
      answer++;
    else if (matched == 0)
      answer += 2;
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int x , y , z , k;
    cin>>x>>y>>z>>k;
    ll a[x], b[y], c[z];
    for(int i = 0; i < x; i++){
        cin>>a[i];
    }
    for(int i = 0; i < y; i++){
        cin>>b[i];
    }
    for(int i = 0; i < z; i++){
        cin>>c[i];
    }
    sort(a , a + x , greater<ll>());
    sort(b , b + y , greater<ll>());
    sort(c , c + z , greater<ll>());
    vector<ll> ans;
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            for(int l = 0; l < z; l++){
                if((i + 1)*(j + 1)*(l + 1) <= k){
                    ll sum = a[i] + b[j] + c[l];
                    ans.pb(sum);
                }else{
                    break;
                }
            }
        }
    }
    sort(all(ans) , greater<ll>());
    for(auto it : ans){
        if(k == 0){
            break;
        }
        cout<<it<<"\n";
        k--;
    }

    
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, x;
    cin >> n;
    
    for (int i=sqrt(n); i>0; i--) {
        if (n%i == 0) {
            x = i;
            break;
        }
    }
    
    cout << (x-1) + ((n/x)-1);
    
    return 0;
}


Measured memory_bytes: 384
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


def main():
    x, y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        exit()
    i = (2 * x - y) // 3
    j = (2 * y - x) // 3
    print(comb_mod(i + j, i, MOD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
inputs = STDIN.map(&:chomp).map(&:to_i)

$coins = []

def calc_cost(input)
  (1000 - input)
end

def refund(cost)
  [500, 100, 50, 10, 5, 1].each { | coin |
    if cost >= coin
      $coins << coin
      cost -= coin
      return refund(cost)
    end
  }
  if cost == 0
   ans = $coins.count
   $coins = []
   return ans
  end
  'something wrong'
end

inputs.each { |input|
  puts refund(1000 - input.to_i) if input > 0
}


Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

ll cost(vector<pair<ll, ll>> a)
{
   ll N = a.size();
   for (auto &p : a)
      p.first = min(p.first, N);
   vector<vector<ll>> v(N + 1);
   for (auto &p : a)
      v[p.first].push_back(p.second);

   priority_queue<ll> pq;
   ll res = 0;

   for (int i = N; i > 0; i--)
   {
      for (auto k : v[i])
         pq.push(k);

      if (pq.empty())
         continue;
      res += pq.top();
      pq.pop();
   }
   return res;
}

int main()
{
   int t;
   cin >> t;
   while (t--)
   {
      int N;
      cin >> N;
      vector<pair<ll, ll>> left, right;

      ll ans = 0;

      for (int i = 0; i < N; i++)
      {
         ll k, l, r, m;
         cin >> k >> l >> r;
         ans += min(l, r);
         if (l > r)
            left.emplace_back(k, l - r);
         if (r > l)
            right.emplace_back(N - k, r - l);
      }
      ans += cost(left);
      ans += cost(right);
      cout << ans << "\n";
   }
}

Measured memory_bytes: 14056
#include <stdio.h>
#include <math.h>

double square(int l, int m, int N)
{
	return l*m*sin(N * M_PI / 180) / 2;
}

double length(int l, int m, int N)
{
	return sqrt(l*l + m*m - 2 * l*m*cos(N*M_PI / 180))+l+m;
}

double height(int l, int m, int N)
{
	return m*sin(N*M_PI / 180);
}

int main(void)
{
	int a, b, C;

	scanf("%d %d %d", &a, &b, &C);

	printf("%lf\n%lf\n%lf\n", square(a, b, C), length(a, b, C), height(a, b, C));

	return 0;
}

Measured memory_bytes: 684
class UnionFind:
    def __init__(self, sz: int):
        self._par: list[int] = [-1] * sz

    def root(self, a: int):
        if self._par[a] < 0:
            return a
        self._par[a] = self.root(self._par[a])
        return self._par[a]
    
    def size(self, a: int):
        return -self._par[self.root(a)]
    
    def unite(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a != b:
            if self.size(a) < self.size(b):
                a, b = b, a
            self._par[a] += self._par[b]
            self._par[b] = a
    
if __name__ == '__main__':
    N, M = map(int, input().split())
    uf = UnionFind(N + 1)
    for i in range(M):
        a, b = map(int, input().split())
        uf.unite(a, b)
    ans = 1
    for i in range(1, N + 1):
        ans = max(ans, uf.size(i))
    print(ans)

Measured memory_bytes: 14632
N = int(input())
ary = [int(_) for _ in input().split()]


def insertion_sort(ary, verbose=True):

    for i in range(1, N):

        if verbose:
            print(' '.join([str(_) for _ in ary]))

        v = ary[i]
        j = i - 1

        while j >= 0 and ary[j] > v:
            ary[j + 1] = ary[j]
            j -= 1

        ary[j + 1] = v

    print(' '.join([str(_) for _ in ary]))


insertion_sort(ary)



Measured memory_bytes: 5608
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long n;

long dbg_print = 0;

ll calc( const char* str, long n0, const char* str0, long n1, const char* str1 )
{
    if ( dbg_print ) {
        printf("(%s)(%s)(%s) ", str, str0, str1);
    }

    ll dp[20][20]={0};

    long i,j;
    for(i=0; i<=n0; i++) {
        for(j=0; j<=n1; j++) {
            if(i==0 && j==0) {
                dp[i][j] = 1;
            }
            else {
                if(i>0 && str[i+j-1]==str0[i-1]) {
                    dp[i][j] += dp[i-1][j];
                }
                if(j>0 && str[i+j-1]==str1[j-1]) {
                    dp[i][j] += dp[i][j-1];
                }
            }
        }
    }
    if ( dbg_print ) {
        printf("%lld\n", dp[n0][n1]);
    }

    return dp[n0][n1];
}

int main(int argc, char* argv[])
{
    scanf("%ld", &n);

    char str[40]={0};
    scanf("%s", str);

    {
        char str0[20]={0};
        char str1[20]={0};
        strncpy( str0, str+0, n);
        sort( str0+0, str0+n );
        strncpy( str1, str+n, n);
        sort( str1+0, str1+n );
        if( strcmp( str0, str1 ) != 0 ) {
            printf("0\n");
            return 0;        
        }
    }

    char strrev[40]={0};
    long i;
    for(i=0; i<n; i++) {
        strrev[i] = str[2*n-1-i];
    }

    ll ans = 0;

    char str0[40]={0};
    char str1[40]={0};
    long bit, k;
    for(bit=0; bit<(1<<n); bit++) {
        long cnt0=0, cnt1=0;
        for(k=0; k<n; k++) {
            if(bit & (1<<k)) {
                str0[cnt0]=str[k];
                cnt0++;
            }
            else {
                str1[cnt1]=str[k];
                cnt1++;
            }
        }
        str0[cnt0]=0;
        str1[cnt1]=0;

        ans += calc( strrev, cnt0, str0, cnt1, str1 );
    }

    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 128
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) fill_n(x, sizeof(x)/sizeof(x[0]), y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scf(x) scanf("%f", &x)
#define scd(x) scanf("%lf", &x)
#define scld(x) scanf("%Lf", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	string s;
	cin >> s;
	string tmp[2];
	for (int i = 0; i < s.size(); ++i) {
		tmp[0].pb((i % 2) + '0');
		tmp[1].pb(((i + 1) % 2) + '0');
	}
	int cnt[2];
	RESET(cnt);
	for (int i = 0; i < s.size(); ++i) {
		cnt[0] += tmp[0][i] != s[i];
		cnt[1] += tmp[1][i] != s[i];
	}
	printf("%d\n", min(cnt[0], cnt[1]));
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#define MAX_N 100000
#define INF 1000000000
using namespace std;

int a[MAX_N];
int dp[MAX_N];

int search(int key, int n) {
  int left = 0;
  int right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (dp[mid] < key) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  return left;
}

void solve(int n) {
  dp[0] = a[0];
  int length = 1;
  for (int i = 1; i < n; i++) {
    if (dp[length - 1] < a[i]) {
      dp[length++] = a[i];
    } else {
      int index = search(a[i], length);
      dp[index] = a[i];
    }
  }
  cout << length << endl;
}

void init() {
  for (int i = 0; i < MAX_N; i++) {
    dp[i] = INF;
  }
}

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

  init();
  solve(n);
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5, MAXB = 20;

int nxt[MAXN][MAXB];
int v[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n + 2){
		if (i <= n){
			scanf("%d", &v[i]);
		} else {
			v[i] = (1 << MAXB) - 1;
		}
		REP(j, 0, MAXB){
			if (v[i] & (1 << j)){
				nxt[i][j] = i;
			}
		}
	}
	for(int i = n + 2; i > 0; i--){
		REP(j, 0, MAXB){
			if (!nxt[i][j]){
				nxt[i][j] = nxt[i + 1][j];
			}
		}
	}
	ll ans = 0ll;
	REPN(i, 1, n){
		int r = n + 1;
		REP(j, 0, MAXB){
			r = min(r, nxt[nxt[i][j] + 1][j]);
		}
		ans += (r - i);
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,k,ans=0;
	cin>>n>>k;
	vector<int> a(100000000);
	n=n-k;
	ans++;
	for(int i=0;0<n;i++){
		n=n-k+1;
		ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 390912
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
G = [[] for _ in range(n)]
A = LI()
for i in range(n - 1):
    G[A[i] - 1] += [i - 1]

for j in range(n):
    print(len(G[j]))


Measured memory_bytes: 117904
package main

import (
        "fmt"
)

type Pair struct {
        Start int
        End int
}

func main() {
        var n, k int
        var s string
        fmt.Scanf("%d %d", &n, &k)
        fmt.Scanf("%s", &s)
        var pairs []Pair
        var idx, last int
        last = 1
        for i:=0; i < n; i++ {
                if last == 1 && int(s[i])-int('0') == 0 {
                        idx = i
                } else if last == 0 && int(s[i])-int('0') == 1 {
                        var p Pair
                        p.Start = idx
                        p.End = i
                        pairs = append(pairs, p)
                }
                last = int(s[i])-int('0')
        }
        if last == 0 {
                        var p Pair
                        p.Start = idx
                        p.End = n - 1
                        pairs = append(pairs, p)
        }
        /*
        for _,p := range pairs {
                fmt.Printf("%d %d\n", p.Start, p.End)
        }*/

        if k > len(pairs) {
                fmt.Println(n)
        } else {
                var start, end, ml, l int
                for i := 0; i + k - 1 < len(pairs); i++ {
                        if i == 0 {
                                start = 0
                        } else {
                                start = pairs[i-1].End
                        }
                        if i + k - 1 == len(pairs) - 1 {
                                end = len(s)
                        } else {
                                end = pairs[i+k].Start
                        }
                        l = end - start
                        //fmt.Printf("start=%d, end=%d, length=%d\n", start, end, l)
                        if ml < l {
                                ml = l
                        }
                }
                fmt.Println(ml)
        }
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N, K;
	cin >> N >> K;
	cout << (N - K + 1) << endl;
	return 0;
}



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

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

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

vector<ll> prime_enum(int n) {
  vector<bool> is_prime(n + 1, true);
  is_prime[0] = is_prime[1] = false;
  vector<ll> res;
  for (int i = 2; i <= n; i++) {
    if (!is_prime[i]) continue;
    res.push_back(i);
    for (int j = 2 * i; j <= n; j += i) {
      is_prime[j] = false;
    }
  }
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  auto mp = prime_factor(g);
  cout << 1 + mp.size() << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7; 
vector<int> adj[200005];
bool vis[200005];
int dfs(int node){
	int c=1;
	vis[node]=true;
	for(auto i:adj[node]){
		if(!vis[i])
		c+=dfs(i);
	}
	return c;
}
int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	memset(vis, false, sizeof(vis));
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
		ans=max(ans,dfs(i));
		}
	}
	cout<<ans;
}

Measured memory_bytes: 24076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define debug(x) cout<<#x<<"="<<x<<endl;

using namespace std;

int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);	
	printf("%d",a^b^c);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

int a,b,c;

int main(){
    cin>>a>>b>>c;
    bool flag=false;
    int ans;
    for(int i=1;i<=b;i++){
            if((i*a)%b==c){
            flag=true;
            break;
        }
    }
    if(flag) cout<<"YES"<<"\n";
    else cout<<"NO"<<"\n";
    return 0;
}

Measured memory_bytes: 3584