akhauriyash/Code-Regression huggingface dataset:
N=int(input())
A=list(map(int, input().split()))
ans=0
right=0
SUM=0
xor=-1
for left in range(N):
    while right<N and ((SUM+A[right]==(xor^A[right])) or (xor==-1)):
        if xor==-1:
            xor=A[left]
        else:
            xor=xor^A[right]
        SUM+=A[right]
        right+=1
    ans+=right-left
    #print(SUM, xor)
  
    SUM-=A[left]
    xor=A[left]^xor

print(ans)

Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 2e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll fact[N];
ll ifact[N];

ll nCr(ll n, ll r) { return fact[n] * ifact[r] % mod * ifact[n - r] % mod; }

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

  fact[0] = ifact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = i * fact[i - 1] % mod;
    ifact[i] = power(fact[i], mod - 2, mod);
  }
  ll n;
  cin >> n;

  ll x[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> x[i];

  ll res = 0;
  ll multiplier = 1;

  for (ll i = 1; i < n; i++) {

    res += (x[i + 1] - x[i]) * multiplier % mod;
    if (res >= mod)
      res -= mod;

    multiplier += power(1 + i, mod - 2, mod);
    if (multiplier >= mod)
      multiplier -= mod;
    /*
    for (ll j = i; j < n; j++) {

      ll no = j - i;

      res += power(no + 1, mod - 2, mod) * (x[j + 1] - x[j]) % mod;
      if (res >= mod)
        res -= mod;
    }
     */
  }
  cout << res * fact[n - 1] % mod << en;

  return 0;
}

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

int main() {
int N;
string c;
cin >> N;
for(int i = 0;i < N;i++){
cin >> c;
if(c == "Y"){
cout << "Four";
break;
}
else if(i == N - 1){
cout << "Three";
}
}
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a,int b){int r,tmp;if(a < b){tmp = a;a = b;b = tmp;}r = a % b;while(r != 0){a = b;b = r;r = a % b;}return b;}

int main()
{
    int n,a[100000],i,j;

    scanf("%d",&n);
    for(i = 0;i < n;i++)scanf("%d",&a[i]);
    
    int r = a[0];
    for (i = 1; i < n; i++)
    {
        r = gcd(r,a[i]);
    }
    printf("%d",r);
}

Measured memory_bytes: 512
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[100010], b[100010], c[100010];
    rep(i,0,N) cin >> a[i] >> b[i] >> c[i];
    ll dp[100010][3] = {};
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    rep(i,1,N){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    print(max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}));
    


}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A>=13) cout << B << endl;
  else if(A<6) cout << 0 << endl;
  else cout << B/2 << endl;
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int p[n+5];
	int i;
	for( i = 1; i<=n; i++)
		cin>>p[i];
	int ans = 0;
	int f = 0;
	for( i =1; i<n; i++ )
	{
		if( i == p[i] )
		{
			if( i == n - 1 )
				f = 1;
			if( i + 1 == p[i+1] )
				i++;
			ans += 1;
		}
	}
	if( n == p[n] && f == 0 )
	{
		ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 640
require "matrix"

arr = Array.new
while line = gets
   a = line.split(",")
   a.map!{|j| j.to_i}
   if a[0] == 0 and a[1] == 0
      break
   end
   arr << a
end
d = 90
p = Vector[0, 0]
arr.each do |i|
   length, degree = i[0], i[1]
   r = 2 * (d / 360.0) * Math::PI
   p += length * Vector[Math.cos(r), Math.sin(r)]
   d -= degree
end
puts p[0].to_i
puts p[1].to_i

Measured memory_bytes: 6452
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010,P=1e9+7;
int n,k,ans,a[MAXN],b[MAXN],c[MAXN],fac[MAXN],inv[MAXN];
int qpow (int a,int b) {
	int res=1;
	while (b) {
		if (b&1) {res=(1ll*res*a)%P;}
		a=(1ll*a*a)%P,b>>=1;
	}
	return res;
}
void init () {
	fac[0]=inv[0]=1;
	for (int i=1;i<=MAXN-10;i++) {fac[i]=(1ll*fac[i-1]*i)%P;}
	inv[MAXN-10]=qpow(fac[MAXN-10],P-2);
	for (int i=MAXN-11;i>=1;i--) {inv[i]=(1ll*inv[i+1]*(i+1))%P;}
	return;
}
int ct (int n,int m) {return (n<m?0:(1ll*((1ll*fac[n]*inv[m])%P)*inv[n-m])%P);}
int main () {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) {scanf("%d",&a[i]);}
	sort(a+1,a+n+1);
	a[0]=a[n+1]=1e9+1;
	for (int i=1;i<=n;i++) {b[i]=i-1;c[i]=n-b[i]-1;}
	init();
	for (int i=1;i<=n;i++) {ans=((ans+(1ll*a[i]*ct(b[i],k-1))%P)%P+P)%P;}
	for (int i=1;i<=n;i++) {ans=((ans-(1ll*a[i]*ct(c[i],k-1))%P)%P+P)%P;}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
using namespace std;
#define int long long int
class segtree
{
	public :
	int n;
	vector<int> tree;
	segtree(int N)
	{
		n=N;
		tree.resize(4*n+1,0);
	}
	void build_tree(int arr[],int start,int end,int index)
	{
		if(start==end)
		{
			tree[index]=arr[start];
			return ;
		}
		else
		{
			int mid=(start+end)/2;
			build_tree(arr,start,mid,2*index);
			build_tree(arr,mid+1,end,2*index+1);
			tree[index]=max(tree[2*index],tree[2*index+1]);
		}
	}
	int max_query(int start,int end,int left,int right,int index)
	{
		if(left>end||start>right)
		  return 0;
		if(start>=left&&end<=right)
		   return tree[index];
		else
		{
			int mid=(start+end)/2;
		    int x=max_query(start,mid,left,right,2*index);
		    int y=max_query(mid+1,end,left,right,2*index+1);
		    return max(x,y);
		}
	}
	void update(int start,int end,int point,int index,int val)
	{
		if(point>end||point<start)
		   return ;
		if(start==end)
		{
			tree[index]=val;
			return ;
		}
		else
		{
			int mid=(start+end)/2;
			update(start,mid,point,2*index,val);
			update(mid+1,end,point,2*index+1,val);
			tree[index]=max(tree[2*index],tree[2*index+1]);
		}
	}
	int binary_search(int start,int end,int val)
	{
		if(start>end)
		  return -1;
		else
		{
			int mid=(start+end)/2;
			int val2=max_query(0,n-1,start,mid,1);
			if(val2>=val)
			{
				int x=mid;
				int y=binary_search(start,mid-1,val);
				if(y==-1)
				  return x;
				else
				  return y;
			}
			else
			  return binary_search(mid+1,end,val);
		}
	}
};
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	segtree seg(n);
	int j,arr[n];
	for(j=0;j<n;j++)
	  cin>>arr[j];
	seg.build_tree(arr,0,n-1,1);
	while(q--)
	{
		int query;
		cin>>query;
		if(query==1)
		{
			int point,val;
			cin>>point>>val;
			point--;
			seg.update(0,n-1,point,1,val);
		}
		else if(query==2)
		{
			int left,right;
			cin>>left>>right;
			left--;
			right--;
			int answer=seg.max_query(0,n-1,left,right,1);
			cout<<answer<<endl;
		}
		else
		{
			int point,val;
			cin>>point>>val;
			point--;
			int answer=seg.binary_search(point,n-1,val);
			answer++;
			if(answer==0)
			  answer=n+1;
			cout<<answer<<endl;
		}
	}
}


Measured memory_bytes: 11140
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int n, k;
    cin >> n >> k;

    vector<ll> a(n);
    fo(i, n) cin >> a[i];

    for ( int i = k; i < n; i++ ) {
        if ( a[i - k] < a[i] ) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#define N 9
using namespace std;
void NP(int);
void check();
int flag;
pair<char,char> data[N],out[N];
bool used[N];
int main(){
  int T;
  cin >> T;
  for(int i=0;i<T;i++){
    for(int j=0;j<N;j++){
      cin >> data[j].first;
    }
    for(int j=0;j<N;j++){
      cin >> data[j].second;
    }
    flag=0;
    NP(0);
    if(flag==1) cout << 1 << endl;
    else cout << 0 << endl;
  }
  return 0;
}
void NP(int x){
  if(flag==1) return ;
  if(x<N){
    for(int i=0;i<N;i++){
      if(used[i]) continue;
      out[x]=data[i];
      used[i]=true;
      NP(x+1);
      used[i]=false;
    }
  }else{
    check();
  }
}
void check(){
  int flag1=0;
  for(int i=0;i<N;i+=3){
    if(out[i].second==out[i+1].second&&out[i+1].second==out[i+2].second){
      if(out[i].first==out[i+1].first-1&&out[i+1].first==out[i+2].first-1){
      }
      else if(out[i].first==out[i+1].first&&out[i+1].first==out[i+2].first){
      }
      else{
	flag1=1;
	break;
      }
    }else{
      flag1=1;
      break;
    }
  }
  if(flag1==0) flag=1;
}

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

public class Program {

        public static void Main(string[] args) {

            // 問題数N
            var n = int.Parse(Console.ReadLine());

            // 問題を解く時間T秒
            var tArray = Console.ReadLine().Split(' ');

            // M種類のドリンク
            var m = int.Parse(Console.ReadLine());

            // ドリンクを飲んだときの回答秒数
            List<string[]> list = new List<string[]>();

            for(int i = 0; i < m; i++) {

                list.Add(Console.ReadLine().Split());

            }

            // 回答秒数を格納する配列
            var outArray = new int[m];

            for(int i = 0; i < m; i++) {

                var sum = 0;

                for(int j = 1; j <= n; j++) {

                    if(j == int.Parse(list[i][0])) {

                        sum += int.Parse(list[i][1]);

                    } else {

                        sum += int.Parse(tArray[j - 1]);

                    }

                }

                outArray[i] = sum;

            }

            foreach(int i in outArray) {

                Console.WriteLine(i);

            }
            
        }

    }

Measured memory_bytes: 11220
public class Main {
	public static void main(String[] args) {
		    java.util.Scanner scanner = new java.util.Scanner(System.in);
                    String c1 = scanner.next();
                    String c2 = scanner.next(); 
                    if ((c1.charAt(0) == c2.charAt(2)) &&
                        (c1.charAt(1) == c2.charAt(1)) &&
                        (c1.charAt(2) == c2.charAt(0))) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
		 } 

}

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

ans = 1
mode = 0
prev = A[0]

for i in A:
    check = i - prev

    if check == 0:
        pass
    elif check > 0:
        if mode >= 0:
            mode = check
        else:
            ans += 1
            mode = 0
    else:
        # check < 0
        if mode <= 0:
            mode = check
        else:
            ans += 1
            mode = 0

    prev = i

print(ans)


Measured memory_bytes: 19984
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


double dp[3009][3009];
int n;
double arr[3009];



double solve(int idx, int num) {
	if(idx == n) {
		return (num > n - num) ? 1.0 : 0.0;  
	}
	if(dp[idx][num] != -1.0)
		return dp[idx][num];
	
	double ans = 0;
	ans += arr[idx] * solve(idx + 1, num + 1);
	ans += (1 - arr[idx]) * solve(idx + 1, num);

	return dp[idx][num] = ans;
}


int main() {
	cin>>n;

	for (int i = 0; i < 3009; ++i){
		for (int j = 0; j < 3009; ++j) {
			dp[i][j] = -1 * 1.0;
		}
	}

	for(int i = 0; i < n; i++)
		cin>>arr[i];
	
	printf("%.11f\n", solve(0, 0));
}

Measured memory_bytes: 71296
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int h,w;

int dist[100];
int d[100];
int c[500][500];
bool used[100];
const int INF=100000000;

//1頂点確定→その頂点から更新の繰返し
int main(){
cin>>h>>w;
rep(i,10)rep(j,10)cin>>c[i][j];

for(int to=0;to<10;to++){
	rep(i,10)dist[i]=INF;//各頂点への距離
	rep(i,10)used[i]=0;

	int now=to;
	dist[now]=0;


	while(true){
		int v=-1;
		for(int u=0;u<10;u++){
			if(!used[u]&&(v==-1||dist[u]<dist[v]))v=u;
		}

		if(v==-1)break;
		used[v]=1;
		for(int u=0;u<10;u++)dist[u]=min(dist[u],dist[v]+c[v][u]);
	}

	d[to]=dist[1];
	//rep(i,10)cout<<dist[i]<<" ";cout<<endl;
}

///rep(i,10)cout<<d[i]<<endl;

int ans=0,to;
rep(i,h){
	rep(j,w){
		cin>>to;
		if(to==-1)continue;
		ans+=d[to];
		//cout<<to<<" "<<d[to]<<endl;
	}
}

cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n, ans = 0;
  long long d;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
import sys
S = input()
K = int(input())
if len(S) == 1:
  print(S)
  sys.exit(0)
if K == 1:
  print(S[0])
  sys.exit(0) #
i = 0
while i<len(S):
  if S[i] == '1':
  	i += 1
  else:
    break
if i < len(S):
  keep = S[i]
else:
  keep = S[i-1]
if K <= i:
  print('1')
  sys.exit(0)
else:
  if S[0] != '1':
    print(S[0])
  else:
	  print(keep)

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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long
#define pil pair <int, ll>
#define pii pair <int, int>

using namespace std;

deque <int> b;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    int a;
    cin >> a;
    if (i % 2 == 0) b.push_back(a);
    else            b.push_front(a);
  }
  while (!b.empty()) {
    if (n % 2 == 1) {
      cout << b.back() << " ";
      b.pop_back();
    } else {
      cout << b.front() << " ";
      b.pop_front();
    }
  }

  return 0;
}



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

int dsum(int n) {
  int sm = 0;
  while (n>0) {
    sm += n%10;
    n /= 10;
  }
  return sm;
}
int main() {
  int n,a,b;cin>>n>>a>>b;
  int cnt=0,d;
  rep(i,n) {
    d = dsum(i+1);
    if (d >= a and d <= b) cnt+=i+1;
  }
  cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
#define bisect_left(vector,a) lower_bound(vector.begin(),vector.end(),a)
#define bisect_right(vector,a) upper_bound(vector.begin(),vector.end(),a)

bool lambda0( const vector<long long>& v1, const vector<long long>& v2 ) { return v1[0] < v2[0]; }
int main(void){
    int n,p;
    cin>>n;
    string town;
    vector< pair<pair<string,int>,int> >sp;
    for(int i=0  ;i<n  ;i++){
        cin>>town>>p;
        sp.push_back(pair<pair<string,int>,int>{{town,-p},i});
    }
    sort(sp.begin(),sp.begin()+n);
    for(int i=0  ;i<n  ;i++){
        cout<<sp[i].second+1<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,N) repi(i,0,(N))
#define repi(i,a,b) for (int i = (a); i < (b); ++ i)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)

#define all(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define t
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;
constexpr long long MOD = 1e9 + 7;
constexpr long long INF = 1LL << 60;
// UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1},
          dy[] = {1, 0, -1, 0};
template<class T = int> bool chmin(T& a, T b) { bool f = a > b; a = f ? b : a; return f;}
template<class T = int> bool chmax(T& a, T b) { bool f = a < b; a = f ? b : a; return f;}

template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){
  return s << "(" << p.first << ", " << p.second << ")";
}


signed main() { 
  ios();
  int a;
  cin >> a;
  string s;
  cin >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    MOD = 998244353

    S = []
    LR = []
    for i in range(K):
        l, r = map(int, input().split())
        LR.append((l, r))
    
    LR.sort()
    # for (l, r) in LR:
    #     for x in range(l, min(r+1, N)):
    #         S.append(x)

    a = [0] * N
    f = [0] * N
    f[0] = 1
    a[1] = -1

    for i in range(N):
        if i > 0:
            f[i] = (f[i-1] + a[i]) % MOD
        for (l, r) in LR:
            if i+l < N:
                a[i+l] = (a[i+l] + f[i]) % MOD
            if i+r+1 < N:
                a[i+r+1] = (a[i+r+1] - f[i]) % MOD
    # print(f)
    print(f[N-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 24608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ll long long
#define N 200010
using namespace std;
int n,m,cnt;
int fa[N],c[N][2],da[N],ed[N],nx[N],v[N];
ll ans;
struct node
{
	int s,c0,c1;
	node(int _s=0,int _c0=0,int _c1=0){s=_s,c0=_c0,c1=_c1;}
	bool operator <(node const &a)const
	{
		if((ll)c0*a.c1==(ll)c1*a.c0)return s<a.s;
		return (ll)c0*a.c1<(ll)c1*a.c0;
	}
};
priority_queue<node> d;
int ff(int a)
{
	if(da[a]==a)return a;
	return da[a]=ff(da[a]);
} 
int main()
{
	int i,s,a,b,k;
	node j;
	scanf("%d",&n);
	for(i=2;i<=n;i++)scanf("%d",&fa[i]);
	for(i=1;i<=n;i++)scanf("%d",&v[i]),c[i][v[i]]++,da[i]=ed[i]=i;
	for(i=2;i<=n;i++)d.push(node(i,c[i][0],c[i][1]));
	while(!d.empty())
	{
		j=d.top();d.pop();
		s=j.s;
		if(c[s][0]!=j.c0 || c[s][1]!=j.c1)continue;
		da[ff(s)]=k=ff(fa[s]);
		nx[ed[k]]=s;ed[k]=ed[s];c[k][0]+=c[s][0];c[k][1]+=c[s][1];
		if(k!=1)d.push(node(k,c[k][0],c[k][1]));
	}
	a=1;k=0;
	while(a)
	{
		if(v[a])k++;
		else ans+=k;
		a=nx[a];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;


int main(){
  string s;
  cin >> s;

  string a;
  a = s.substr(0,1);
  string b;
  b = s.substr(strlen(s.c_str())-1, 1);

  stringstream ss;
  ss << (strlen(s.c_str()) - 2);
  cout << a + ss.str() + b << endl;

  return 0;
}




Measured memory_bytes: 256
#include<iostream>

int main(){
  int n,x; std::cin >> n >> x;
  int ans = 1,crt = 0;
  for(int i = 0; i < n; ++i){
    int t; std::cin >> t;
    ans += ((crt += t) <= x);
  }
  std::cout << ans;
}

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

using namespace std;

vector<int> tpsort(const vector<vector<int>>& g) {
	int V = g.size();
	vector<int> indeg(V, 0);
	stack<int> S;

	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < g[i].size(); ++j) {
			++indeg[g[i][j]];
		}
	}
	for (int i = 0; i < V; ++i) {
		if (indeg[i] == 0) { S.push(i); }
	}

	vector<int> ret;
	while (S.size() > 0) {
		int u = S.top(); S.pop();
		ret.push_back(u);
		for (int i = 0; i < g[u].size(); ++i) {
			--indeg[g[u][i]];
			if (indeg[g[u][i]] == 0) {
				S.push(g[u][i]);
			}
		}
	}
	return ret;
}

pair<int, int> key(int a, int b) {
	if (a > b) { swap(a, b); }
	return { a, b };
}

int main() {
	int N;
	cin >> N;
	vector<vector<int>> a(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			cin >> a[i][j];
			--a[i][j];
		}
	}

	map< pair<int, int>, int > ids;
	int sz = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			ids[key(i, j)] = sz++;
		}
	}
	vector<vector<int>> g(sz);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j + 1 < N - 1; ++j) {
			int u = ids[key(i, a[i][j])];
			int v = ids[key(i, a[i][j + 1])];
			g[u].push_back(v);
		}
	}

	vector<int> d = tpsort(g);
	if (d.size() != sz) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> indeg(sz, 0);
	for (int i = 0; i < sz; ++i) {
		for (auto v : g[i]) {
			++indeg[v];
		}
	}

	deque<int> que;
	vector<int> cost(sz, -1);
	for (int i = 0; i < sz; ++i) {
		if (indeg[i] > 0) { continue; }
		que.push_back(i);
		cost[i] = 1;
	}

	while (!que.empty()) {
		int u = que.front(); que.pop_front();
		for (auto v : g[u]) {
			cost[v] = max(cost[v], cost[u] + 1);
			--indeg[v];
			if (indeg[v] == 0) { que.push_back(v); }
		}
	}
	cout << *max_element(cost.begin(), cost.end()) << endl;

	return 0;
}


Measured memory_bytes: 68560
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

multiset<int>st;

int i,j,m,n,p,k,L[N],R[N];

char s[N],c[N]; 

pair<int,int> A[N];

int work(int x,int y,int t)
{
		if (x>=t)
		{
				return 2*y+x+x-t;
		}
		if (y>=n-t)
		{
				return 2*x+y+y-(n-t);
		}
		return min(t+2*y,2*x+(n-t));
}

int main()
{
		scanf("%s",c+1); 
		scanf("%s",s+1);
		n=strlen(c+1);
		for (i=1;i<=n;++i) if (s[i]=='1') break;
		if (i>n)
		{
			for (i=1;i<=n;++i) if (c[i]=='1') break;
			if (i<=n) printf("-1\n");
			else puts("0"); 
		}
		else 
		{
			int ans=(int)1e9;
			for (i=1;i<=n;++i)
			{
					for (j=0;j<=n;++j) if (s[(i-j-1+n)%n+1]=='1') break;
					L[i]=j;
					for (j=0;j<=n;++j) if (s[(i+j-1)%n+1]=='1') break;
					R[i]=j; 
			}
			//workL
			int LL,RR;
			for (j=0;j<=n;++j)
			{
					int tot=0;
					for (i=1;i<=n;++i) if (s[(i-j-1+n)%n+1]!=c[i]) A[++tot]=mk(L[i],R[i]);
					sort(A+1,A+tot+1);
					for (i=1;i<=tot;++i) st.insert(A[i].se);
					LL=1;
					for (i=0;i<=n;++i)
					{
							while (LL<=tot&&A[LL].fi<=i)
							st.erase(st.lower_bound(A[LL].se)),++LL;
							if (st.begin()==st.end()) RR=0;
							else RR=*--st.end();
							ans=min(ans,tot+work(i,RR,j));
					}
			}
			for (j=0;j<=n;++j)
			{
					int tot=0;
					for (i=1;i<=n;++i) if (s[(i+j-1)%n+1]!=c[i]) A[++tot]=mk(L[i],R[i]);
					sort(A+1,A+tot+1);
					for (i=1;i<=tot;++i) st.insert(A[i].se);
					LL=1;
					for (i=0;i<=n;++i)
					{
							while (LL<=tot&&A[LL].fi<=i)
							st.erase(st.lower_bound(A[LL].se)),++LL;
							if (st.begin()==st.end()) RR=0;
							else RR=*--st.end();
							ans=min(ans,tot+work(RR,i,j));
					}
			}
			printf("%d\n",ans);
		}
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int main() {
	int N; cin >> N;
	int size = 1 << N;

	vector<int>* v = new vector<int>[N];
	for (int i = 0; i < N; i++) {
		v[i].resize(size);
	}
	string S; cin >> S;
	vector<int> input(size);
	for (int i = 0; i < size; i++) {
		cin >> input[i];
	}
	int s = size;
	for (int n = 0; n < N; n++) {
		if (n == 0) {
			for (int i = 0; i < size; i += 2) {
				int j = i + 1;
				int x = input[i], y = input[j];
				if (x > y) { int c = x; x = y; y = c; }
				int c = y - x;
				if (S[c - 1] == '0') {
					v[0][i / 2] = x;
				}
				else {
					v[0][i / 2] = y;
				}
			}
			for (int i = 1; i < size; i += 2) {
				int j = (i + 1) % size;
				int x = input[i], y = input[j];
				if (x > y) { int c = x; x = y; y = c; }
				int c = y - x;
				if (S[c - 1] == '0') {
					v[0][i / 2 + size / 2] = x;
				}
				else {
					v[0][i / 2 + size / 2] = y;
				}
			}
		}
		else {
			s /= 2;
			for (int i0 = 0; i0 < size; i0 += s) {
				for (int i = i0; i < i0 + s; i+=2) {
					int j = i + 1;
					int x = v[n-1][i], y = v[n-1][j];
					if (x > y) { int c = x; x = y; y = c; }
					int c = y - x;
					if (S[c - 1] == '0') {
						v[n][i0 + (i - i0) / 2] = x;
					}
					else {
						v[n][i0 + (i - i0) / 2] = y;
					}
				}
				for (int i = i0 + 1; i < i0 + s; i += 2) {
					int j = i + 1;
					if (j == i0 + s) { j = i0; }
					int x = v[n - 1][i], y = v[n - 1][j];
					if (x > y) { int c = x; x = y; y = c; }
					int c = y - x;
					if (S[c - 1] == '0') {
						v[n][i0 + (i - i0) / 2 + s / 2] = x;
					}
					else {
						v[n][i0 + (i - i0) / 2 + s / 2] = y;
					}
				}
			}
		}
	}
	for (int i = 0; i < size; i++) {
		int k = i;
		int anchor = 0;
		int s = size;
		for (int n = 0; n < N; n++) {
			s /= 2;
			if (k & 1) {
				anchor += s;
			}
			k /= 2;
		}
		cout << v[N - 1][anchor] << endl;
	}

	return 0;
}


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

using namespace std;

#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 1e5 + 5;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

void findNumberOfDigits(long n, int base)
{
    int dig = (int)(floor( log(n) / log(base)) + 1);
    cout << dig;
}
int32_t main()
{
    int n;
    cin >> n;
    int base;
    cin >> base;

    findNumberOfDigits(n, base);
    return 0;
}



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

struct edge {
    int to;
    int cost;
};
using P = pair<int, int>;
vector<vector<edge>> G;
vector<int> d;
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M, a, b;
    cin >> N >> M;
    G.resize(N);
    d.resize(N);

    rep(i, M) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back({b, 1});
        G[b].push_back({a, 1});
    }

    dijkstra(0);
    if (d[N - 1] == 2)
        cout << "POSSIBLE";
    else
        cout << "IMPOSSIBLE";
    cout << endl;

    return 0;
}

Measured memory_bytes: 15080
def make_fib(n):
    if n == 0 or n == 1: return 1
    if F[n] != -1: return F[n]
    else:
        F[n] = make_fib(n-1)+make_fib(n-2)
        return(F[n])

def fibonacci(n):
    if n == 0 or n == 1: return 1
    else: return(fibonacci(n-1)+fibonacci(n-2))

n = int(input())
F = [-1 for i in range(50)]
F[0] = F[1] = 1   #n=0 t0 1 pre-registered
print(make_fib(n))




Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<ll,int>
#define F first
#define S second
#define ld long double
int const M=1e6+10,M2=1e3+10,mod=1e9+7,inf=1e9+10;
string x;
int dp[M][2];
void upd(int last)
{
	//cout<<last<<endl;
	if(x[(int)x.size()-1]!='0')
		dp[(int)x.size()-1][0]=1,dp[(int)x.size()-1][1]=1;
	else dp[(int)x.size()-1][0]=0,dp[(int)x.size()-1][1]=0;
	for(int j=last;j>=0;j--)
	{
		if(x[j]=='0')
		{
			dp[j][0]=dp[j+1][0];
			dp[j][1]=dp[j+1][0];
			continue;
		}
		if(x[j+1]=='0')
		{
			dp[j][0]=dp[j+1][1]+1;
			dp[j][1]=dp[j+1][1]+1;
			continue;
		}
		//if(last==0)cout<<x[j];
		if(x[j]>x[j+1])dp[j][0]=dp[j+1][1],dp[j][1]=dp[j+1][1];
		else if(x[j]==x[j+1])dp[j][0]=dp[j+1][0]+1,dp[j][1]=dp[j+1][1];
		else {
			//cout<<last<<" "<<dp[j+1][0]<<endl;
			dp[j][0]=dp[j+1][0]+1,dp[j][1]=dp[j+1][0]+1;
		}
		//if(last==0)cout<<dp[j][0]<<endl;
	}
}
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>x;
	reverse(x.begin(),x.end());
	for(int j=0;j<4;j++)x+='0';
	upd((int)x.size()-2);
	int ans=0;
	int t=x.size();
	for(int j=1;j<=t;j++)
	{
		int ind;
		for(int k=0;k<x.size();k++)
		{
			if(x[k]=='9')x[k]='0';
			else {
				x[k]=char(x[k]+1);
				ind=k;
				break;
			}
		}
		//cout<<x<<" "<<ind<<" "<<dp[1][0]<<endl;
		upd(ind);
		if(dp[0][0]<=j)return cout<<j,0;
	}
}

Measured memory_bytes: 9116
use std::ascii::AsciiExt;
fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf);
    let nk = buf.split_whitespace().map(|x|x.parse().unwrap()).collect::<Vec<usize>>();
    let k = nk[1];
    buf.clear();
    let _ = std::io::stdin().read_line(&mut buf);
    print!("{}", buf.chars().take(k-1).collect::<String>());
    print!("{}", buf.chars().nth(k-1).unwrap().to_ascii_lowercase());
    print!("{}", buf.chars().skip(k).collect::<String>());
    println!();
}


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

struct Node {
	int s, e, m;
	//covers s,e;
	ll sum;
	ll maxi;
	Node *l, *r;
	
	Node(int a, int b) {
		s = a;
		e = b;
		sum = 0;
		maxi = 0;
		if (s != e) {
			m = (s+e)/2;
			l = new Node(s,m);
			r = new Node(m+1,e);
		}
		else {
			l = NULL;
			r = NULL;
		}
	}


	void add(int i, ll x) {
		if (s == e) {
			sum += x;
			maxi = sum;
            return;
		}
		if (i <= m) {
			l->add(i,x);
		}
		else if (i > m) {
			r->add(i,x);
		}
		else assert(false);
		sum = l->sum + r->sum;
		maxi = max(l->maxi,r->maxi);
	}

	ll getmaxi(int st, int en) {
		if (st <= s && e <= en) {
			return maxi;
		}
		ll ret = 0;
		if (st <= m) {
			ret = max(ret,l->getmaxi(st,en));
		}
		if (en > m) {
			ret = max(ret,r->getmaxi(st,en));
		}
		return ret;
	}	
};

const int maxn = 2e5+5;
int N, h[maxn], a[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    Node *root = new Node(0,N);
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ll r = a[i] + root->getmaxi(0,h[i]-1);            
        root->add(h[i],r);
        ans = max(ans,r);
    }
    cout << ans << '\n';


    return 0;
}



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

typedef long long ll;

int main()
{
    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    ll ans = 0;

    if (a >= k)
    {
        cout << k << endl;
        return 0;
    }
    else
    {
        ans += a;
        k -= a;
    }

    if (b >= k)
    {
        cout << a << endl;
        return 0;
    }
    else
    {
        k -= b;
    }

    cout << ans - k << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n, k;
    cin >> n >> k;
    vector<long long> teleport(n,0);
    for (long long i = 0; i < n; i++) {
        long long a;
        cin >> a;
        teleport[i] = a;
    }
    int i = teleport[0];
    vector<bool> visited(n,false);
    visited[0] = true;
    k--;
    int cycle = 0;
    int start = 0;
    while (k > 0 && start != i) {
        if (visited[i-1]) {
            if (start == 0) {
                start = i;
            } else {
                cycle++;
            }
        }
        visited[i-1] = true;
        i = teleport[i-1];
        k--;
    }
    if (k > 0) {
        k = k % (cycle + 1);
    }
    while (k > 0) {
        i = teleport[i-1];
        k--;
    }
    cout << i;
}


Measured memory_bytes: 4752
import math

n, k = map(int, input().split())

total = 0
for i in range(n, 0, -1):
    
    cnt = 0
    temp = i
    while temp < k:
        temp *= 2
        cnt += 1
    
    power = math.pow(2, -cnt) / n
    total += power
    #print(i, cnt, power)

print(total)


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
	//リング状の文字列
	string s;

	//作りたい文字列
	string p;

	string str2;

	//文字列入力
	cin >> s;
	cin >> p;

	//リング状の文字列を連結
	str2 = s + s;

	if( strstr(str2.c_str(), p.c_str()) != NULL)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}




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

int main( void ) {
  string S;
  cin >> S;
  int l = S.size();
  int h = l/2;
  int answer = h;
  if ( l == 1 ) {
    if ( S[0] == '(' || S[0] == ')' ) answer = 1;
  } else {
    if ( l % 2 == 1 && ( S[h] == '(' || S[h] == ')' ) ) answer++;
    for ( int i = 0; i < h; i++ ) {
      if ( S[i] == '(' && S[l-i-1] == ')' ) answer--;
      if ( S[i] == ')' && S[l-i-1] == '(' ) answer--;
      if ( ( S[i] == 'w' || S[i] == 'i' ) && S[i] == S[l-i-1] ) answer--;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 0
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{

  int n, m;
  cin >> n >> m;
  int k[n + 10];
  int count[40];

  rep(i,40) count[i] = n;

  int x;
  rep(i,n){
    cin >> k[i];
    rep(j,k[i]){
      cin>>x;
      count[x]--;
    }
  }
  int ans = 0;
  for (int i = 1; i < 40; i++){
    if(count[i]==0)ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a, b, c, d;
signed main() {
    cin >> a >> b >> c >> d;
    if(c * b <= 0 && c * a <= 0 && b * d <= 0 && a * d <= 0) {
		if(a * b * c * d == 0) {
	        puts("0");
		}
		else if(a > 0) {
			cout << a * d;
		}
		else {
			cout << b * c;
		}
    }
    else {
        cout << max(max(a * c, a * d), max(b * c, b * d));
    }
    return 0;
}

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

int main() {
	int n, num; cin >> n; 
	vector<string> vec(n);
	vector<int> vec_alpha(n - 1);
	vector<int> vec_beta(0);
	for (int i = 0; i < n; i++) cin >> vec[i];
	for (int i = 0; i < n; i++) {
		num = 0;
		for (int j = 0; j < n; j++)
			if (i != j) { vec_alpha[num] = stoi(vec[i] + vec[j]); num++; }
		sort(vec_alpha.begin(), vec_alpha.end());
		vec_beta.push_back(vec_alpha[0]);
		vec_beta.push_back(vec_alpha[1]);
		vec_beta.push_back(vec_alpha[2]);
	}
	sort(vec_beta.begin(), vec_beta.end());
	cout << vec_beta[2] << endl;
	return 0;
}


Measured memory_bytes: 3496
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g[100][100],h,j,i,z,x,c,flg=0;
	scanf("%d %d",&a,&s);
	scanf("%d",&d);
	c=0;
	z=0;
	x=0;
	for(i=0;i<d;i++){
		scanf("%d",&f);
		c++;
		for(j=0;j<f;j++){
	//		printf("%d %d\n",x,z);
			g[x][z]=c;
			if(flg==0){
				z++;
				if(z==s){
					flg=1;
					x++;
				}
			}
			if(flg==1){
				z--;
				if(z==-1){
					z++;
					flg=0;
					x++;
				}
			}
		}
	}
	for(i=0;i<a;i++){
		for(j=0;j<s;j++){
			printf("%d",g[i][j]);
			if(j!=s-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] result = new int[m];
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(sc.next());
			for (int j = 0; j < k; j++) {
				result[Integer.parseInt(sc.next()) - 1]++;
			}
		}
		int ans = 0;
		for (int i = 0; i < result.length; i++) {
			if (result[i] == n) {
				ans++;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21844
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n_ = 2 * 10**6 + 5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod

def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod


inv26 = modinv(26, mod)


def solve():
    k = ni()
    s = ns()
    n = len(s)
    ans = 0
    v = 1
    u = pow(26, k, mod)
    for i in range(n, n+k+1):
        ans = (ans + nCr(i-1, n-1) * v * u) % mod
        u = u * inv26 % mod
        v = v * 25 % mod
    print(ans)
    return

solve()


Measured memory_bytes: 106944
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
    }
    return res;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(100000);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i]]++;
  }

  if (N % 2 == 0) {
    for(int j = 0; j < N; j++) {
      if (j % 2 == 0 && cnt[j] != 0) {
        cout << 0 << endl;
        return 0;
      } else if (j % 2 == 1 && cnt[j] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    if (cnt[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    for(int j = 1; j < N; j++) {
      if (j % 2 == 0 && cnt[j] != 2) {
        cout << 0 << endl;
        return 0;
      } else if (j % 2 == 1 && cnt[j] != 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << mod_pow(2, (N / 2), 1000000007) << endl;
  return 0;
}

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

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;

	int mini = 1;
	while(n--)
	{
		if (mini >= k) mini += k;
		else mini *= 2;
	}

	cout << mini << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*Lower_Rating*/
/*Comb*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;

#define LL long long
#define DB double
#define MOD 924844033
#define MAXN 4000
#define Pr pair<DB,int>
#define X first
#define Y second
#define INF 20000000000000000LL
#define mem(x,p) memset(x,p,sizeof(x))
#define P(x) ((x+1)*x/2)

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}

int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return 1LL*a*b%MOD;}
int fst_pow(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=mul(res,a);
        a=mul(a,a);
        b>>=1;
    }return res;
}

int n,k,istp[MAXN+5],cnt,fac[MAXN+5];
int f[MAXN+5][MAXN+5][2];
int ans;

int main()
{
    n=read(),k=read();
    fac[0]=1;
    for(int i=1;i<=n;i++)
    fac[i]=mul(fac[i-1],i);
    for(int i=1;i<=k;i++){
        istp[cnt+1]=1,cnt+=(n+k-i)/k;
        istp[cnt+1]=1,cnt+=(n+k-i)/k;
    }
    f[0][0][0]=1;
    for(int i=1;i<=(n*2);i++)
        for(int j=0;j<=i;j++){
            f[i][j][0]=add(f[i][j][0],add(f[i-1][j][0],f[i-1][j][1]));
            if(!istp[i]&&j)f[i][j][1]=add(f[i][j][1],f[i-1][j-1][0]);
        }
    for(int i=0;i<=n;i++){
        int s=add(f[n*2][i][0],f[n*2][i][1]);
        if(i&1)ans=dec(ans,mul(s,fac[n-i]));
        else ans=add(ans,mul(s,fac[n-i]));
    }
    printf("%d",ans);
}


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

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}

int main(void){
	int n=in(),m=in(),i,j,c,t[100]={},g[100][100]={},a[100]={};
	for(i=0;i<m;i++){
		t[i]=in();
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			g[i][j]=in();
		}
	}
	for(i=0;i<m;i++){
		c=0;
		for(j=0;j<n;j++){
			if(t[i]==g[i][j]){
				a[j]++;
			}
			else{
				c++;
			}
		}
		a[t[i]-1]+=c;
	}
	for(i=0;i<n;i++){
		print(a[i]);
	}
	return 0;
}

Measured memory_bytes: 644
package main

import (
	"fmt"
	"strconv"
)

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

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

	s := strconv.Itoa(n)
	c, _ := strconv.Atoi(string(s[0]))
	for i := 1; i < len(s); i++ {
		if s[i] != '9' {
			fmt.Println(c - 1 + (len(s)-1)*9)
			return
		}
	}
	fmt.Println(c + (len(s)-1)*9)
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    ll A, B, N;
    cin >> A >> B >> N;
    N = min(N, B - 1);
    ll ans = (A / B) * N + (A % B * N) / B;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N;
  cin >> N;
  vector<long long int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  vector<long long int> B(N);
  for(int i=0;i<N;i++){
    B[i]=A[i];
  }
  sort(B.begin(),B.end());
  long long int x=B[N-1];
  for(int i=0;i<N;i++){
    if(A[i]!=x){
      cout << x << endl;
    }
    else{
      cout << B[N-2] << endl;
    }
  }
}

Measured memory_bytes: 4736
M, D = map(int, input().split())

ans = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        today = str(d)
        if len(today) > 1 and int(today[0]) > 1 and int(today[1]) > 1 and int(today[0])*int(today[1]) == m:
            ans += 1

print(ans)

Measured memory_bytes: 3064