akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<functional>
#include<stdio.h>
#include<string>
#include<string.h>
#define INF 2147483647
#define MP make_pair
using namespace std;

string start(int N){
	string st[9];
	st[0]="0";st[1]="1";st[2]="12";st[3]="123";st[4]="1234";
	st[5]="12345";st[6]="123456";st[7]="1234567";st[8]="12345678";
	return st[N];
}
int fact(int N){
	return (N==0)?1:N*fact(N-1);
}
string swapnumber(const string input,int a,int b){
	char str[9];
	char *pa,*pb;
	string before(input);
	strcpy(str,before.c_str());
	pa=strchr(str,'0'+a);pb=strchr(str,'0'+b);
	*pa='0'+b;*pb='0'+a;
	return str;
	//p=before.find(sa,0);pb=before.find(sb,0);
	
}
int main(void){
  int N;
  int c[8][8];
  map<string,int> node;//数列、コスト
  map<string,int>::iterator itr;
	priority_queue<pair<int,string>,vector<pair<int,string> >,greater<pair<int,string> > > edge;//コスト,数列
  int ans=0;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
    	scanf("%d",&c[i][j]);
    }
  }

  string startstr=start(N);
  node.insert(MP(start(N),0));
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
    	edge.push( MP(c[i][j],swapnumber(startstr,i+1,j+1)) );
    }
  }
  while(1){
	  pair<int,string> buf;
	  if(node.size()==fact(N)){
	  	break;
	  }
 	  while(1){
  		buf=edge.top();
	  	edge.pop();
	  	
  		if(node.count(buf.second)){//既に確定してたら
  			continue;
	  	}else{//初めてだったら
	  		break;
	  	}
	  }
	  node.insert(map<string,int>::value_type(buf.second,buf.first));
	  for(int i=0;i<N;i++){
    	for(int j=i+1;j<N;j++){
   			edge.push( MP( buf.first+c[i][j],swapnumber(buf.second,i+1,j+1) ) );
   		}
 	 	}
  }
	for (itr = node.begin(); itr != node.end(); itr++){
		// キーを出力
	//	cout << itr->first << " " << itr->second << endl;
		if((itr->second)>ans){
			ans=itr->second;
		}
	}
	printf("%d\n",ans);
	
  return 0;
}

Measured memory_bytes: 58168
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;
bool k[100001]={};
ll x[100001];
ll y[100001];
int main() {
	ll n;
	cin>>n;
	ll t=12;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ll b=n/i;
			for( ll j=1;j<11;++j){
				if(b/10==0){
					t=min(t,j);
					break;
				}
				b=b/10;
			}
		}
	}
		cout<<t<<endl;
	return 0;
}


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

int main() {
	int ans; cin >> ans; char op; int temp;
	while (1) {
		cin >> op >> temp;
		if (op == '+') ans = ans + temp;
		if (op == '-') ans = ans - temp;
		if (op == '*') ans = ans * temp;
		if (op == '/') ans = ans / temp;
		if (op == '=') break;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n,y;
  cin >> n >> y;
  int count = 0;
  bool flag = false;
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n-i;j++){
      int k = n-i-j;
      if(i*10000+j*5000+k*1000 == y){
        cout << i <<" "<< j <<" "<< k << endl;
        return 0;
      }
    }
  }
  cout << -1 <<" "<< -1 <<" "<< -1 << endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	int sum = 0;
	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[n - 1 - i]) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int n = scanner.nextInt();


        String valueString;
        String tani;
        double tmp = 0;
        int sum=0;
        

        for(int i=0;i<n;i++) {
        	valueString = scanner.next();
        	tani = scanner.next();
        	if(tani.equals("JPY")) {
        		sum += Integer.parseInt(valueString);
        	}else {
        		tmp += Double.parseDouble(valueString);
        	}
        }
        System.out.println((double)sum+(tmp*380000.0));

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 23252
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM
import Data.List

type Map = IM.IntMap Int

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

get :: Int -> Map -> Int
get key m = fromMaybe 0 $ IM.lookup key m

solve :: Int -> Int -> Map -> [Int]
solve k right m
  | left <= 0 = []
  | otherwise = get right m - get left m : solve k (right - 1) m
    where left = right - k + 1

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  hs <- sort <$> readIntLines
  let d = IM.fromList $ zip [1..] hs
  print . minimum $ solve k (length hs) d

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

void count(vector<int> &counter, map<int, unordered_set<int>> &d, int number) {
    int v = counter[number];
    for (auto child : d[number]) {
        counter[child] += v;
        d[child].erase(number);
        count(counter, d, child);
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    map<int, unordered_set<int>> d;
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        d[a].insert(b);
        d[b].insert(a);
    }
    vector<int> counter(N + 1);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        counter[p] += x;
    }
    count(counter, d, 1);
    cout << counter[1];
    for (int i = 2; i <= N; i++) cout << " " << counter[i];
    cout << endl;
}

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

int main()
{
//#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
//#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int x,a;
   cin>>x>>a;
   if(x<a)
   	cout<<0<<endl;
   else
   	cout<<10<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin >> n;
  vector<int> L(n+1);
  rep(i,n) cin >> L[i];
  L[n] = INF;
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i=0; i<=n-3; i++){
    for (int j=i+1; j<=n-2; j++){
      int limit_k = L[i] + L[j]; //一番長い棒がlimit_kよりも小さければOK
      auto itr = lower_bound(L.begin(), L.end(), limit_k);
      if (itr != L.end()){
        int idx = itr - L.begin();
        ans += max(0, idx-1-j);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
char z;

//inputします
void input() {
    cin >> z;
}

//ライブラリ置き場

//main
int main() {
    input();
    char ans = z + 1;
    cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
int tmp;
cin>>tmp;
int a=tmp/100;
int b=tmp%100;
  if(a && a<=12) 
    cout<<(b && b<=12?"AMBIGUOUS":"MMYY")<<endl;   
  else
	cout<<(b && b<=12?"YYMM":"NA")<<endl;
return 0;
}

Measured memory_bytes: 256
#include<map>
#include<deque>
#include<cstdio>

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

using namespace std;

typedef long long ll;

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

int h,w;

struct field{ char B[10][10]; };

ll hash(const field &F){
	ll res=0;
	rep(i,h) rep(j,w) res=res*1000000007+F.B[i][j];
	return res;
}

int main(){
	for(;scanf("%d%d",&h,&w),h;){
		char B0[10][11];
		rep(i,h) scanf("%s",B0[i]);

		int gx,gy;
		rep(i,h) rep(j,w) if(B0[i][j]=='E') gx=j, gy=i, B0[i][j]='.';

		field ini;
		rep(i,h) rep(j,w) ini.B[i][j]=B0[i][j];

		int ans=-1;
		map<ll,int> dp; dp[hash(ini)]=0;
		deque< pair<int,field> > Q; Q.push_back(make_pair(0,ini));
		while(!Q.empty()){
			int t=Q.front().first;
			field F=Q.front().second; Q.pop_front();

			int x,y;
			rep(i,h) rep(j,w) if(F.B[i][j]=='@') x=j, y=i;

			if(x==gx && y==gy){ ans=t; break; }

			// コンテナを押す
			rep(k,4){
				int xx=x+dx[k],yy=y+dy[k];
				if(F.B[yy][xx]=='c' && (F.B[yy+dy[k]][xx+dx[k]]=='.' || F.B[yy+dy[k]][xx+dx[k]]=='w')){
					field F2=F;
					F2.B[yy][xx]='.';
					while(F.B[yy+dy[k]][xx+dx[k]]=='.' || F.B[yy+dy[k]][xx+dx[k]]=='w'){
						yy+=dy[k];
						xx+=dx[k];
						if(F.B[yy][xx]=='w') break;
					}
					F2.B[yy][xx]=(F2.B[yy][xx]=='.'?'c':'.');
					ll h=hash(F2);
					if(dp.count(h)==0 || dp[h]>t){
						dp[h]=t;
						Q.push_front(make_pair(t,F2));
					}
				}
			}

			// 移動する
			rep(k,4){
				int xx=x+dx[k],yy=y+dy[k];
				if(F.B[yy][xx]=='.'){
					field F2=F;
					F2.B[y][x]='.';
					F2.B[yy][xx]='@';
					ll h=hash(F2);
					if(dp.count(h)==0 || dp[h]>t+1){
						dp[h]=t+1;
						Q.push_back(make_pair(t+1,F2));
					}
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 4568
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        100000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

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

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class CRepsept {
public:
    void solve(std::istream &in, std::ostream &out) {
        int k;
        in >> k;
        int ans = 7 % k;
        for (int i = 1; i < 1e7; ++i) {
            if (ans == 0) {
                out << i << endl;
                return;
            }
            ans = (ans * 10 + 7) % k;
        }
        out << -1 << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    CRepsept solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3652
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            string[] newline = Console.ReadLine().Split(' ');
            int l_max = int.Parse(newline[0]);
            int r_min = int.Parse(newline[1]);
            for (int i = 1; i < M; i++)
            {
                newline = Console.ReadLine().Split(' ');
                if (int.Parse(newline[0]) > l_max) l_max = int.Parse(newline[0]);
                if (int.Parse(newline[1]) < r_min) r_min = int.Parse(newline[1]);
            }
            if (r_min >= l_max) Console.WriteLine((r_min - l_max + 1).ToString());
            else Console.WriteLine("0");
        }
    }
}

Measured memory_bytes: 15188
#include <iostream>
using namespace std;
int square[1500][1500];
int h[1500];
int w[1500];
int lenh[1500001];
int lenw[1500001];
int sum,cnt,maxh,maxw,minlen,n,m;
int main(){
	while(1){
		cin >> n>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<1500001;i++){
			lenh[i]=lenw[i]=0;
		}


		for(int i=0;i<n;i++){
			cin>>h[i];
		}
		for(int i=0;i<m;i++){
			cin>>w[i];
		}
		sum=0;
		maxh=0;
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				sum+=h[j];
				lenh[sum]++;
			}
			if(maxh<sum)maxh=sum;
			sum=0;
		}

		sum=0;
		maxw=0;
		for(int i=0;i<m;i++){
			for(int j=i;j<m;j++){
				sum+=w[j];
				lenw[sum]++;
			}
			if(maxw<sum)maxw=sum;
			sum=0;
		}
		minlen=min(maxh,maxw);
		cnt=0;
		for(int i=0;i<=minlen;i++){
			cnt+=lenh[i]*lenw[i];
		}
		cout << cnt<<endl;
	}
}

Measured memory_bytes: 14804
n = int(input())
a = list(map(int,input().split()))

ans = [0 for i in range(n)]
for i in range(1,n):
    ans[i] = 2 * (a[i-1] - ans[i-1]//2)

s = a[n-1] - ans[n-1]//2

for i in range(n):
    if i%2 == 0:
        ans[i] += s
    else:
        ans[i] -= s
    ans[i] = str(ans[i])
print(" ".join(ans))

Measured memory_bytes: 84324
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int matrix(int n){
	switch(n){
	case 1:
		printf("  1\n");
		break;
	case 2:
		printf("  1  2\n");
		printf("  3  4\n");
		break;
	case 3:
		printf("  1  2  6\n");
		printf("  3  5  7\n");
		printf("  4  8  9\n");
		break;
	case 4:
		printf("  1  2  6  7\n");
		printf("  3  5  8 13\n");
		printf("  4  9 12 14\n");
		printf(" 10 11 15 16\n");
		break;
	case 5:
		printf("  1  2  6  7 15\n");
		printf("  3  5  8 14 16\n");
		printf("  4  9 13 17 22\n");
		printf(" 10 12 18 21 23\n");
		printf(" 11 19 20 24 25\n");
		break;
	case 6:
		printf("  1  2  6  7 15 16\n");
		printf("  3  5  8 14 17 26\n");
		printf("  4  9 13 18 25 27\n");
		printf(" 10 12 19 24 28 33\n");
		printf(" 11 20 23 29 32 34\n");
		printf(" 21 22 30 31 35 36\n");
		break;
	case 7:
		printf("  1  2  6  7 15 16 28\n");
		printf("  3  5  8 14 17 27 29\n");
		printf("  4  9 13 18 26 30 39\n");
		printf(" 10 12 19 25 31 38 40\n");
		printf(" 11 20 24 32 37 41 46\n");
		printf(" 21 23 33 36 42 45 47\n");
		printf(" 22 34 35 43 44 48 49\n");
		break;
	case 8:
		printf("  1  2  6  7 15 16 28 29\n");
		printf("  3  5  8 14 17 27 30 43\n");
		printf("  4  9 13 18 26 31 42 44\n");
		printf(" 10 12 19 25 32 41 45 54\n");
		printf(" 11 20 24 33 40 46 53 55\n");
		printf(" 21 23 34 39 47 52 56 61\n");
		printf(" 22 35 38 48 51 57 60 62\n");
		printf(" 36 37 49 50 58 59 63 64\n");
		break;
	case 9:
		printf("  1  2  6  7 15 16 28 29 45\n");
		printf("  3  5  8 14 17 27 30 44 46\n");
		printf("  4  9 13 18 26 31 43 47 60\n");
		printf(" 10 12 19 25 32 42 48 59 61\n");
		printf(" 11 20 24 33 41 49 58 62 71\n");
		printf(" 21 23 34 40 50 57 63 70 72\n");
		printf(" 22 35 39 51 56 64 69 73 78\n");
		printf(" 36 38 52 55 65 68 74 77 79\n");
		printf(" 37 53 54 66 67 75 76 80 81\n");
		break;
}
}

int main(){
	for(int i = 0;;i++){
		int n;
		cin>>n;
		if(!n)break;
		printf("Case %d:\n",i+1);
		matrix(n);
	}
	
  return 0;
}

Measured memory_bytes: 0
// Longest Path
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define times(t) int t; cin >> t; while(t--)
#define mod 1000000007

const int MAXN = 1e5 + 5;
vector<int> g[MAXN];
int dp[MAXN], vis[MAXN], N, M;

int dfs(int u) {
	if(vis[u]) return dp[u];
	vis[u] = 1;
	int best = 0;
	for(auto v : g[u]) {
		best = max(best, dfs(v)+1);
	}
	return dp[u] = best;
}

void solve() {
	cin >> N >> M;
	for(int i=1; i<=M; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
	}
	int best = 0;
	for(int i=1; i<=N; i++)
		best = max(best, dfs(i));
	cout << best << endl;
	return;
}

int main() {
	IOS;
	// #ifndef ONLINE_JUDGE
	// freopen("C:/Gen code/CompProg/input.txt", "r", stdin);
	// freopen("C:/Gen code/CompProg/output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

Measured memory_bytes: 11892
N = int(input())
e = [0] * (N + 1)

for i in range(2, N + 1):
    K = i
    for j in range(2, i + 1):
        while K % j == 0:
            e[j] += 1
            K //= j


def calc(m):
    return len(list(filter(lambda x: x >= m - 1, e)))


print(calc(75) + calc(25) * (calc(3) - 1) + calc(15) * (calc(5) - 1) + calc(5) * (calc(5) - 1) * (calc(3) - 2) // 2)


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

int main() {
  int n;
  cin >> n;
  
  int cnt=0;
  bool flag=false;
  
  for(int i=0; i<n; i++){
    int a, b;
    cin >> a >> b;
    
    if(a==b)
      cnt++;
    else
      cnt=0;
    
    if(cnt>=3){
      flag=true;
      break;
    }
  }
  
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{	rtn
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

int n, arr[N];
int r0[N], r1[N];


int go(int x)
{
	int cnt = 0;
	while (x)
	{
		int y = __builtin_popcount(x);
		x = x % y;
		cnt++;
	}
	return cnt;
}
void solve()
{

	cin >> n;
	string str; cin >> str;
	lop(i, 0, n) arr[i] = (str[i] - '0');
	int cnt = 0;
	lop(i, 0, n) cnt += arr[i];
	if (cnt == 0)
	{
		lop(i, 0, n) cout << 1 << endl;
		return;
	}


	int p = 1, s1 = 0, s2 = 0;
	int m1 = cnt + 1, m2 = cnt - 1;
	int p2 = 1;

	// bug(m1, m2);
	rlop(i, n - 1, 0)
	{
		// bug(s1, p, p2);
		if ( arr[i] )s1 = (s1 +   p) % (m1);
		p = (p * 2) % m1;
		if (m2 > 0)
		{
			s2 = (s2 + arr[i] * p2) % (m2);
			p2 = (p2 * 2) % m2;
		}
	}

	// bug(m1, m2);
	// cout << s1 << " " << s2 << endl;
	// return;


	p = 1;
	rlop(i, n - 1, 0)
	{
		if ( arr[i] == 0 )
		{
			int nsum = (s1 + p) % m1;
			// if (!i) bug(nsum, p);
			r0[i] = go(nsum) + 1;
		}
		p = (p * 2) % m1;
	}


	p = 1;
	rlop(i, n - 1, 0)
	{
		if (!m2) break;
		if (arr[i])
		{
			int nsum = (s2 - p + m2) % m2;
			r1[i] = go(nsum) + 1;
		}
		p = (2 * p) % m2;
	}

	lop(i, 0, n)
	{
		if (arr[i]) cout << r1[i] << endl;
		else cout << r0[i] << endl;
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















Measured memory_bytes: 8468
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int h, w;
	cin >> h >> w;

	vector<vector<int>> m(h, vector<int>(w));
	vector<string> s(h);
	for (int i = 0; i < h; i++)
	{
		cin >> s.at(i);

		for (int j = 0; j < w; j++)
		{
			string c = s.at(i).substr(j, 1);
			if (c == "#")
			{
				if (j > 0)
				{
					if (i > 0)
					{
						m.at(i - 1).at(j - 1)++;
					}
					if (i < h - 1)
					{
						m.at(i + 1).at(j - 1)++;
					}
					m.at(i).at(j - 1)++;
				}
				if (j < w - 1)
				{
					if (i > 0)
					{
						m.at(i - 1).at(j + 1)++;
					}
					if (i < h - 1)
					{
						m.at(i + 1).at(j + 1)++;
					}
					m.at(i).at(j + 1)++;
				}
				if (i > 0)
				{
					m.at(i - 1).at(j)++;
				}
				if (i < h - 1)
				{
					m.at(i + 1).at(j)++;
				}
			}
		}
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (s.at(i).substr(j, 1) == "#")
			{
				cout << "#";
			}
			else
			{
				cout << m.at(i).at(j);
			}
		}

		cout << endl;
	}
}

Measured memory_bytes: 256
import itertools
x=list(input())

for lst in itertools.product(['+','-'],repeat=3):
  sum=int(x[0])
  for i in range(3):
    if lst[i]=='+':
      sum+=int(x[i+1])
    else:
      sum-=int(x[i+1])
  if sum==7:
    print(x[0]+lst[0]+x[1]+lst[1]+x[2]+lst[2]+x[3]+'=7')
    break

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> a(3);rep(i,3)cin>>a[i];
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[1]!=a[2])cout<<"Yes";
    else if(a[0]!=a[1]&&a[1]==a[2])cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll dp[1001000][2];

int main() {

	string s;
	cin >> s;
	int n = s.size();

	dp[0][0] = 0;
	dp[0][1] = 1;

	rep(i, n) {
		if (s[i] == '1') {
			dp[i + 1][0] = 3 * dp[i][0] + dp[i][1];
			dp[i + 1][1] = 2 * dp[i][1];
		}
		else {
			dp[i + 1][0] = 3 * dp[i][0];
			dp[i + 1][1] = dp[i][1];
		}
		dp[i + 1][0] %= MOD;
		dp[i + 1][1] %= MOD;
	}

	cout << (dp[n][0] + dp[n][1]) % MOD << endl;

}

Measured memory_bytes: 5312
N, M = map(int, input().split())
a = list(map(int, input().split()))
A = sorted(a, reverse=True)

Total = 0
for i in range(N):
    Total += A[i]

ch = 0
for j in range(M):
    if A[j] < Total/(4*M):
        ch += 1
    else:
        continue
        
if ch > 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(A, reverse=True)
maxA1 = maxA[0]
maxA2 = maxA[1]

for i in range(N):
  if A[i] == maxA1:
    print(maxA2)
  else:
    print(maxA1)
    

Measured memory_bytes: 14112
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	_ = nextInt()
	s := nextStr()

	ok := true

	for i := 0; i < len(s); i++ {
		if i == a {
			if s[i] != '-' {
				ok = false
				break
			}
		} else {
			if (s[i] < '0') || (s[i] > '9') {
				ok = false
				break
			}
		}

	}

	if ok == true {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK and str[i] != "a"):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK > 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	else:
		changeNum = changeNum
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

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

int main(){
	int t;string s;
	while(cin>>t>>s,t!=0||s!="0"){
		int Max=-1,id;
		int c=0;
		rep(i,1<<(s.size()-1)){
			int sum=0,cnt=0;
			rep(j,s.size()){
				cnt=cnt*10+s[j]-'0';
				if(i>>j&1){
					sum+=cnt;cnt=0;
				}
			}
			sum+=cnt;
			if(sum<=t){
				if(sum==Max){
					c++;
				}
				if(sum>Max){
					c=1;
					Max=sum;
					id=i;
				}
			}
		}
		if(Max==-1){
			puts("error");
			continue;
		}
		if(c!=1){
			puts("rejected");
			continue;
		}
		cout<<Max<<" ";
		rep(i,s.size()){
			cout<<s[i];
			if(id>>i&1)cout<<" ";
		}
		cout<<endl;
	}
}

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

int main(){
  int N,M; cin>>N>>M;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  sort(T.begin(),T.end());
  vector<int> Q(N-M+1);
  for(int i=0;i<N-M+1;i++){
    Q[i]=T[i+M-1]-T[i];
  }
  sort(Q.begin(),Q.end());
  cout<<Q[0]<<endl;
}

Measured memory_bytes: 1024
using namespace std;
#include<string.h>
#include <sstream>
typedef long long int ll;
typedef long double ld;
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <map>
//#define N 4
#include <stack>
#include <unordered_set>
#include <math.h>
#include <cstring>
#include <bitset>
#include <numeric>
#include <set>
#include <sstream>
#include <list>
#include <queue>
#define PI 3.14159265358979323846264338327950
#define mp make_pair
#define inf 1e9
//#define M 1000000007
#define M 10000000
#define N 100000

int main() {

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

	int x, y;
	cin >> x >> y;

	int b = (y - 2 * x) / 2;
	int a = x - b;

//	cout << a << " " << b << endl;
//	if (a > 0 && b > 0) {
//		cout << "Yes" << endl;
//	} else {
//		cout << "No" << endl;
//	}

	if (a >= 0 && b >= 0) {
		if ((a + b == x) && (2 * a + 4 * b) == y) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		cout << "No" << endl;
	}

//	if (a == 0 && b != 0) {
//		cout << "Yes" << endl;
//	} else if (b == 0 && a != 0) {
//		cout << "Yes" << endl;
//	} else if (b == 0 && a == 0) {
//		cout << "Yes" << endl;
//	} else if (a > 0 && b > 0) {
//		cout << "Yes" << endl;
//	} else {
//		cout << "No" << endl;
//	}
}



Measured memory_bytes: 3536
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<assert.h>
//#include<time.h>
#include<math.h>
//#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;

bool isdigit(char c) {return c>='0' && c<='9';}
int qread()
{
    char c;int s=0,f=1;while (!isdigit(c=getchar())) f=(c=='-'?-1:1);
    do s=s*10+c-'0'; while (isdigit(c=getchar())); return s*f;
}

int n;
#define maxn 300011
#define LL long long
int a[maxn],b[maxn],c[maxn];
struct BIT
{
	LL a[maxn],n;
	void clear(int m) {n=m;memset(a,0,sizeof(a));}
	void add(int x,int v) {for (;x<=n;x+=x&-x) a[x]+=v;}
	LL query(int x) {LL ans=0;for (;x;x-=x&-x) ans+=a[x];return ans;}
}t,tt;
int lisan[maxn],li=0;
int main()
{
	n=qread();
	for (int i=1;i<=n;i++) a[i]=qread(),lisan[++li]=a[i];
	for (int i=1;i<=n;i++) b[i]=qread(),lisan[++li]=b[i];
	for (int i=1;i<=n;i++) c[i]=qread(),lisan[++li]=c[i];
	int m=n*3;
	t.clear(m);tt.clear(m);
	sort(lisan+1,lisan+1+m);
	for (int i=1;i<=n;i++) a[i]=lower_bound(lisan+1,lisan+1+m,a[i])-lisan,t.add(a[i],1);
	for (int i=1;i<=n;i++)
	{
		b[i]=lower_bound(lisan+1,lisan+1+m,b[i])-lisan;
		tt.add(b[i],t.query(b[i]-1));
	}
	LL ans=0;
//	for (int i=1;i<=n;i++) cout<<tt.query(i)<<' ';cout<<endl;
	for (int i=1;i<=n;i++)
	{
		c[i]=lower_bound(lisan+1,lisan+1+m,c[i])-lisan;
		ans+=tt.query(c[i]-1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  for(I c=9;c>0;c--){
    if (n % c == 0){
      n = n / c;
      if (n < 10){
        Yes;
        return 0;
      }else{
        No;
        return 0;
      }
    }else{
    }
  }
  No;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int H, W, N, Sx, Sy, pl, pr;
string S, T;


int main() {
	cin >> H >> W >> N >> Sx >> Sy >> S >> T;
	pl = 1;
	pr = W;
	for (int i = N - 1; i >= 0; --i) {
		if (T[i] == 'L') {
			++pr;
		}
		if (T[i] == 'R') {
			--pl;
		}
		pl = max(pl, 1);
		pr = min(pr, W);
		if (S[i] == 'L') {
			++pl;
		}
		if (S[i] == 'R') {
			--pr;
		}
		pl = max(pl, 1);
		pr = min(pr, W);
		if (pl > pr) {
			puts("NO");
			return 0;
		}
	}
	if (pl <= Sy&&Sy <= pr) {
		pl = 1;
		pr = H;
		for (int i = N - 1; i >= 0; --i) {
			if (T[i] == 'U') {
				++pr;
			}
			if (T[i] == 'D') {
				--pl;
			}
			pl = max(pl, 1);
			pr = min(pr, H);
			if (S[i] == 'U') {
				++pl;
			}
			if (S[i] == 'D') {
				--pr;
			}
			pl = max(pl, 1);
			pr = min(pr, H);
			if (pl > pr) {
				puts("NO");
				return 0;
			}
		}
		if (pl <= Sx&&Sx <= pr) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 776
import numpy as np

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

B = []
for i in range(1, len(A)):
    B.append(A[i] - A[i-1])

B.append(K - A[-1] + A[0])

max_dist = np.max(B)

print(K - max_dist)

Measured memory_bytes: 44380
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int h[110];

int main()
{
    int n;  cin >> n;
    for(int i = 0;i<n;i++)  cin >> h[i];
    int Ans =0 ;
    for(int i = 0;i<n;i++){
        bool ok = true;
        for(int j = i;j>=0;j--)  ok&=h[i]>=h[j];
        if(ok)  Ans++;
    }
    cout << Ans;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int INF = 1001001001;
const int MAX_N = 1000;
const int MAX_M = 5050;
int P[MAX_N + 10];
int X[MAX_N + 10];
int y[MAX_N + 10];
int dp[MAX_N + 10][MAX_M + 10];

vector<int> g[MAX_N + 10];

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  P[0] = -1;
  for (int i = 1; i < N; i++) { 
    P[i] = nextInt() - 1;
    g[P[i]].push_back(i);
  }
  REP(i, N) X[i] = nextInt();

  bool possible = true;
  for (int v = N - 1; v >= 0; v--) {
    REP(i, g[v].size() + 1) REP(j, MAX_M) dp[i][j] = INF;
    dp[0][0] = 0;
    int d = 0;
    for (int u : g[v]) {
      for (int j = X[v]; j >= 0; j--) if (dp[d][j] < INF) {
        if (j + X[u] <= X[v]) chmin(dp[d+1][j + X[u]], dp[d][j] + y[u]);
        if (j + y[u] <= X[v]) chmin(dp[d+1][j + y[u]], dp[d][j] + X[u]);
      }
      d++;
    }

    int mi = INF;
    for (int j = X[v]; j >= 0; j--) {
      chmin(mi, dp[d][j]);
    }
    if (mi >= INF) {
      possible = false;
      break;
    }
    y[v] = mi;

  }
  cout << (possible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 20096
class UnionFind:
    def __init__(self, size):
        self.__data = [-1 for _ in range(size)]
    def find(self, x):
        if self.__data[x] < 0:
            return x
        else:
            self.__data[x] = self.find(self.__data[x])
            return self.__data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.__data[y] < self.__data[x]:
                x, y = y, x
            self.__data[x] += self.__data[y]
            self.__data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.__data[self.find(x)]
    def get_data(self):
        return [a if a >= 0 else i for i, a in enumerate(self.__data)]

N, K, L = [int(i) for i in input().split()]

uf1 = UnionFind(N)
for _ in range(K):
    p, q = [int(i) - 1 for i in input().split()]
    uf1.union(p, q)

uf2 = UnionFind(N)
for _ in range(L):
    r, s = [int(i) - 1 for i in input().split()]
    uf2.union(r, s)

for i in range(N):
    uf1.find(i)
    uf2.find(i)

from collections import Counter
Z = [(a, b) for a, b in zip(uf1.get_data(), uf2.get_data())]
C = Counter(Z)
print(*[C[z] for z in Z])


Measured memory_bytes: 53044
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const s = inputLines[0];
	const t = inputLines[1];

	var result = 0;

	for (var i = 0; i < s.length; i++) {
		if (s.substr(i, 1) != t.substr(i, 1)) {
			result += 1;
		}
	}

	console.log(result);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 33028
import math
import sys
A, B = map(int, input().split())

Xmin = math.ceil(A / 0.08)
Xmax = (A + 1) / 0.08
Ymin = math.ceil(B / 0.1)
Ymax = (B + 1) / 0.1

if (Xmin > Ymin):
    if (Xmin < Ymax):
        print(Xmin)
        sys.exit(0)
else:
    if (Ymin < Xmax):
        print(Ymin)
        sys.exit(0)
print("-1")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n,T;
  int t[200001];
  
  cin>>n>>T;

  long long ans=0;
  
  cin>>t[0];

  for(int i=1;i<n;i++){
    cin>>t[i];

    ans+=min(T,t[i]-t[i-1]);

  }
  ans+=T;

  cout<<ans<<endl;

  
  
  
  return 0;

}


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

using namespace std;

using LL = long long;
using PII = pair<int, int>;
using ll = long long;
using DBL = double;
using VI = vector<int>;
using VD = vector<DBL>;
using VVI = vector<VI>;
using VVD = vector<VD>;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)
#define SZ(a) ((int)((a).size()))
#define ALL(x) (x).begin(), (x).end()
#define SET(a,v) memset((a), (v), sizeof(a))
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

//#define trace(...) {__f(#__VA_ARGS__, __VA_ARGS__);}
//template<typename Arg> void __f(const char* name, Arg&& arg) {
//  cerr << name << " = " << arg << std::endl;
//} template <typename Arg1, typename... Args>
//void __f(const char* names, Arg1&& arg1, Args&&... args) {
//  const char* comma = strchr(names + 1, ',');
//  cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...); }
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; // OST: find_by_order, order_of_key
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//#pragma GCC optimize("Ofast")
//optimize("unroll-loops")
//target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
///*** RNGS ***/
//SEED=chrono::steady_clock::now().time_since_epoch().count();
//// or high_resolution_clock
//mt19937 rng(SEED); /*or*/ random_device rd; mt19937 rng(rd());
//uniform_int_distribution<> dis(MIN, MAX);// usage: dis(rng)
//struct chash {int operator()(int x) const {return x^SEED;}};
//gp_hash_table<int,int,chash>m;//use cc if very less updates
///*** FAST IO ***/
//inline int scan(){ bool y=0; int x=0; char c=getchar_unlocked();
//while(c<'0'||c>'9'){ if(c=='-')y=1; c=getchar_unlocked();}
//while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar_unlocked();}
//return y?-x:x; }

const int MAXN = 200010;
int h[MAXN], a[MAXN];
long long tree[4*MAXN];

void upd(int x, int l, int r, int p, long long v) {
    if(l == r) {
        assert(l == p);
        tree[x] = max(tree[x], v);
        return;
    }
    int m = ((l+r)/2);
    if(p <= m) upd((2*x), l, m, p, v);
    else upd((2*x+1), 1+m, r, p, v);
    tree[x] = max(tree[2*x], tree[2*x+1]);
}

long long query(int x, int l, int r, int p, int q) {
    if(r < p or q < l) return 0;
    if(p<=l and r<=q) return tree[x];
    int m = ((l+r)/2);
    return max(query((x<<1), l, m, p, q), query((x<<1)+1, 1+m, r, p, q));
}

int main() {
    #ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
//    freopen("sample.out", "w", stdout);
    #else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #endif
    int n;
    cin >> n;
    for(int i=1; i<=n; ++i) {
        cin >> h[i];
    }
    for(int i=1; i<=n; ++i) {
        cin >> a[i];
    }
    for(int i=1; i<=n; ++i) {
        upd(1, 1, n, h[i], a[i] + query(1, 1, n, 1, h[i]-1));
    }
    cout << query(1, 1, n, 1, n) << endl;
	return 0;
}


Measured memory_bytes: 9288
import java.util.Scanner;

public class Main {

	public static int f(long a, long b) {
		int digit = 0;
		
		if(a < 0 && b < 0)return -1;
		
		long tmp = (long)Math.max(a, b);
		
		while(tmp > 0) {
			tmp /= 10;
			++digit;
		}
		
		return digit;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n;
		n = sc.nextLong();
		sc.close();
		
		int min = 100;
		for(int i = 1; i <= (int)Math.sqrt(n); ++i) {
			if(n % i == 0) {
				min = Math.min(min,  f((n / (long)i), (long)i));
			}
		}
		System.out.println(min);
	}

}


Measured memory_bytes: 22868
n = gets.to_i
hash = {}
n.times do
  name = gets[0]
  if %w(M A R C H).include?(name)
    if hash[name].nil?
      hash[name] = 1
    else
      hash[name] += 1
    end
  end
end

if hash.length < 3
  puts 0
else
  march = %w(M A R C H)
  count = 0
  march.combination(3).to_a.each do |combi|
    if hash[combi[0]].nil? || hash[combi[1]].nil? || hash[combi[2]].nil?
      next
    else
      count += hash[combi[0]] * hash[combi[1]] * hash[combi[2]]
    end
  end
  puts count
end


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    if (s[s.length()-1]=='s')
    {
    	cout<<s+"es"<<endl;
	}
	else
	{
		cout<<s+"s"<<endl;
	}
}

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

int main() {
	string s;
	int k;
	cin >> s >> k;
	for (int i = 0; i < k - 1; i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << s[k - 1] << endl;
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List

main = do
    _ <- getLine
    (a:b:_) <- map read . words <$> getLine
    c <- readLn
    toppings <- map read . lines <$> getContents
    print $ solve a b c toppings

solve :: Int -> Int -> Int -> [Int] -> Int
solve basePrice toppingPrice baseCalories =
    maximum . map (uncurry div)
        . scanl (\(cc,cp) t -> (t+cc,cp+toppingPrice)) (baseCalories,basePrice)
        . sortBy (flip compare)

Measured memory_bytes: 4104
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int t,r;
  cin >> t >> r;
  
  vector<vector<int>>road(r,vector<int>(2,0));
  
  for(int i=0;i<r;i++){
    cin >> road[i][0];
    cin >> road[i][1];
  }

  vector<int>town(t+1,0);
  
  for(int i=0;i<r;i++){
    town[road[i][0]]++;
    town[road[i][1]]++;
  }
  
  for(int i=1;i<t+1;i++){
    cout << town[i] << endl;
  }
  
  return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h.begin(), h.end());
    if(n <= k){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for(int i = 0; i < n - k; i++) ans += h[i];
    cout << ans << endl;
}

Measured memory_bytes: 4744
L=[]
for i in range(5):
	L.append(int(input()))
S=[]
for i in range (4):
	for j in range(i+1,5):
		S.append(abs(L[i]-L[j]))
K=int(input())
if max(S)<=K:
	print("Yay!")
else:
	print(":(")

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3656
package main
import "fmt"
const mod int64 = 1000000007
func main() {
  var n,i,x,y,p,k,d int64
  k = 1
  fmt.Scan(&n)
  fmt.Scan(&x)
  for i=1;i<n;i++ {
    fmt.Scan(&y)
    p = (p+inv(i))%mod
    d = (d+((y-x)*p)%mod)%mod
    k = (k*i)%mod
    x = y
  }
  fmt.Println((k*d)%mod)
}
func inv(n int64) int64 {
  var a,b,c,x int64 = n%mod,mod,0,1
  for b != 0 { a,b,c,x = b,a%b,x-(a/b)*c,c }
  return (x%mod+mod)%mod
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using ll = long long; //10^19 < 9223372036854775807
#define REP(i,n) for(ll i=0;i<ll(n);i++)

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

    ll X;
    set<ll> A;
    REP (i, N) {
        cin >> X;
        A.insert(X);
    }

    if (A.size() == N) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 12952
N = int(input())
A = [0, 0, 0]
bool = 0
for i in range(3):
  A[i] = N % 10
  N = (N - A[i])/10
  if A[i] == 7:
    print('Yes')
    bool = 1
    break
if bool == 0:
    print('No')

Measured memory_bytes: 9240
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<set>
using namespace std;

int main() {
	set<int>s;
	int a;
	int b, d;
	scanf("%d", &a);
	for (int c = 0; c < a; c++) {
		scanf("%d%d", &b, &d);
		s.insert(b * 60 + d);
	}
	scanf("%d", &a);
	for (int c = 0; c < a; c++) {
		scanf("%d%d", &b, &d);
		s.insert(b * 60 + d);
	}
	int x = 0;
	for (auto y = s.begin(); y != s.end(); x++, y++) {
		if (x)printf(" ");
		printf("%d:%.2d",*y/60,*y%60);
	}
	puts("");
}

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

using namespace std;

int main(){
    int a,b,theta;
    cin >> a >> b >> theta;
    double S,L,h;
    double pi = acos(-1);
    S = 0.5*a*b*sin(pi*theta/180);
    double c = sqrt(a*a + b*b -2*a*b*cos(pi*theta/180));
    L = a + b + c ;
    h = b * sin(pi*theta/180);

    printf("%f\n",S);
    printf("%f\n",L);
    printf("%f\n",h);

    return 0;   
}



Measured memory_bytes: 3348
#include <stdio.h>

int main() {
	int N, M;
	scanf("%d %d\n", &N, &M);
	int* L = new int[M];
	int* R = new int[M];

	for (int i = 0; i < M; i++) {
		scanf("%d %d", &L[i], &R[i]);
	}
	int maxL = 0, minR = 100000;

	for (int i = 0; i < M; i++) {
		if (maxL < L[i])maxL = L[i];
		if (minR > R[i])minR = R[i];
	}
	if (maxL <= minR) {
		printf("%d", minR - maxL + 1);
	}
	else {
		printf("0");
	}
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> arr(n);
    F0R(i,n)
        cin >> arr[i];
    int best=0;
    int curr=0;
    FOR(i,1,n)
    { 
        if(arr[i]<=arr[i-1])
            curr++;
        else
        {
            best=max(best,curr);
            curr=0;
        }
    }
    best=max(curr,best);
    cout << best;

    return 0;
}


Measured memory_bytes: 640