akhauriyash/Code-Regression huggingface dataset:
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	im := IntMap{}
	for i := 0; i < n; i++ {
		im.increment(getNextInt(scanner))
	}

	ans := "No"
	if n%3 == 0 {
		switch len(im) {
		case 1:
			if im.get(0) == n {
				ans = "Yes"
			}
		case 2:
			if im.get(0)*3 == n {
				ans = "Yes"
			}
		case 3:
			check := 0
			for v, c := range im {
				check ^= v
				if c*3 != n {
					fmt.Println("No")
					return
				}
			}
			if check == 0 {
				ans = "Yes"
			}
		}

	} else if len(im) == 1 && im.get(0) == n {
		ans = "Yes"
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}

func (m IntMap) increment(key int) {
	m[key] = m.get(key) + 1
}


Measured memory_bytes: 7168
import sys
import math
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

print(cmb(x + y, x, MOD))

Measured memory_bytes: 121856
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;

int n, m;
vector<int> ans;
vector<int> G[ARRAY_MAX];
bool visited[ARRAY_MAX];



void dfs(int now) {

	visited[now] = true;
	ans.push_back(now);

	for (int i = 0; i < G[now].size(); i++)
	{
		if (visited[G[now][i]] == false)
		{
			return dfs(G[now][i]);
		}
	}


}

int main() {


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

	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
		//1-index
	}

	dfs(1);
	reverse(ans.begin(), ans.end());
	ans.pop_back();
	dfs(1);

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 9720
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	vi L(N);
	rep(i, N) {
		cin >> L[i];
	}
	sort(L.begin(), L.end(), less<int>());
	ll ans = 0;
	rep(i, N - 2) {
		int k = i;
		rep(j, N - 1) {
			k = max(k, j + 1);
			if (j <= i)
				continue;
			while (1) {
				if (k >= N)
					break;
				if (L[i] + L[j] <= L[k])
					break;
				k++;
			}
			ans += k - j - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
six=[6**i for i in range(1,7)][::-1]
nine=[9**i for i in range(1,6)][::-1]
N=int(input())

ans=[]
def find(n,a):
    if n<6: ans.append(n+a)
    for s in six:
        if s<=n:
            find(n-s,a+1)
            break
    for s in nine:
        if s<=n:
            find(n-s,a+1)
            break
find(N,0)
print(min(ans))

Measured memory_bytes: 118876
a,b,c,x = 4.times.map { gets.to_i }
cnt = 0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      cnt += 1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end
puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

int mod = 1e9 + 7;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N;
    cin >> N;
    ll dp[N + 1][4][4][4];
    rep(i, 0, N + 1) rep(a, 0, 4) rep(b, 0, 4) rep(c, 0, 4) dp[i][a][b][c] = 0;
    dp[0][0][0][0] = 1;

    int T = 0, A = 1, C = 2, G = 3;
    rep(i, 0, N) {
        rep(a, 0, 4) {
            rep(b, 0, 4) {
                rep(c, 0, 4) {
                    rep(d, 0, 4) {
                        if(b == A and c == G and d == C) continue;
                        if(b == G and c == A and d == C) continue;
                        if(b == A and c == C and d == G) continue;
                        if(a == A and c == G and d == C) continue;
                        if(a == A and b == G and d == C) continue;

                        (dp[i + 1][b][c][d] += dp[i][a][b][c]) %= mod;
                    }
                }
            }
        }
    }

    int rsl = 0;
    rep(a, 0, 4) rep(b, 0, 4) rep(c, 0, 4) (rsl += dp[N][a][b][c]) %= mod;
    cout << rsl << endl;

}


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

int main() {
	string s,t;
	cin >> s >> t;
	int ans=0;
	for (int i=0;i < s.length()-t.length()+1;i++) {
		int cnt=0;
		for (int j=0;j < t.length();j++) {
			if (s[i+j] == t[j]){
				cnt++;
			}
		}
		ans = max(ans,cnt);
	}
	cout << t.length() - ans << endl;
	return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			List<string> resultList = new List<string> ();

			int n = int.Parse (Console.ReadLine ());
			for (int i=0; i<n; i++) {
				string a = Console.ReadLine ();
				string b = Console.ReadLine ();
				if (a.Length > 80 || b.Length > 80) {
					resultList.Add ("overflow");
				} else {
					resultList.Add (GetAdd (a, b));
				}
			}

			foreach(string s in resultList){
				Console.WriteLine (s);
			}

			Console.ReadKey ();

		}
		
		static string GetAdd(string a,string b){
			char[] aArray = a.ToCharArray ();
			char[] bArray = b.ToCharArray ();

			int maxDigit = 1;
			if (a.Length > b.Length) {
				maxDigit += a.Length;
			} else {
				maxDigit += b.Length;
			}

			string[] answerArray = new string[maxDigit];
			int aCount = a.Length - 1;
			int bCount = b.Length - 1;

			int flag = 0;
			for (int i=maxDigit-1; i>=0; i--) {
				if (aCount < 0 && bCount < 0) {
					answerArray [i] = flag.ToString();
				} else if (aCount < 0) {
					if (int.Parse(bArray [bCount].ToString()) + flag >= 10) {
						answerArray [i] = (int.Parse(bArray [bCount].ToString()) + flag - 10).ToString();
						flag = 1;
					} else {
						answerArray [i] = (int.Parse(bArray [bCount].ToString()) + flag).ToString();
						flag = 0;
					}
				} else if (bCount < 0) {
					if (int.Parse(aArray [aCount].ToString()) + flag >= 10) {
						answerArray [i] = (int.Parse(aArray [aCount].ToString()) + flag - 10).ToString();
						flag = 1;
					} else {
						answerArray [i] = (int.Parse(aArray [aCount].ToString()) + flag).ToString();
						flag = 0;
					}
				} else {
					if (int.Parse(aArray [aCount].ToString()) + int.Parse(bArray [bCount].ToString()) + flag >= 10) {
						answerArray [i] = (int.Parse(aArray [aCount].ToString()) + int.Parse(bArray [bCount].ToString()) + flag - 10).ToString();
						flag = 1;
					} else {
						answerArray [i] = (int.Parse(aArray [aCount].ToString()) + int.Parse(bArray [bCount].ToString()) + flag).ToString();
						flag = 0;
					}
				}

				aCount--;
				bCount--;
			}

			string answer = String.Join("",answerArray);
			if (answer.Substring (0, 1) == "0") {
				return answer.Substring (1);
			} else if (answer.Length > 80) {
				return "overflow";
			} else {
				return answer;
			}


		}
					
	}
	
}

Measured memory_bytes: 5736
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(int i = 0; i <N; i++)
using namespace std;


const int MOD = pow(10,9)+7;
const int MAX = 2047483647;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}




int main() {

    double T;
    double X;
    cin >> T;
    cin >> X;
    
    cout << T/X << endl;

    return 0;
}










Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
	ll x, y,a;
	int sum=0;
	cin >> x >> y;
	a = x;
	while (a <= y)
	{
		sum++; a *= 2;
	}
	cout << sum << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//Meri hr baat bs yaad hai tumhari , mera apna koi kissa nhi!!
#include<iostream>
#include<vector>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define fat 998244353 
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
ll n , m ;
vector<ll> adj[N];
bool vis[N];
ll dp[N];


void dfs(ll ind)
{
    vis[ind]=1;
    for(ll i = 0 ; i < adj[ind].size() ; i++)
    {
        if(!vis[adj[ind][i]])
        {
            dfs(adj[ind][i]);
        }
        dp[ind] = max(dp[ind],1+dp[adj[ind][i]]);
    }
    
}


int main()

{
    cin>>n>>m;
    for(ll i = 0 ; i < m ; i++)
    {
        ll x , y ;
        cin>>x>>y;
        adj[x].push_back(y);
    }

    for(ll i = 1 ; i <=n ; i++)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    ll ans = 0;
    for(ll i = 0 ; i <= n ;i++)
    {
        ans = max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 32256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long double ld;

int main(){
    ld a,b;
    long long ans;
    cin >> a >> b;
    ans = floor(a*b);
    cout << setprecision(18) << ans << endl;
    //cout << (long long)a*b << endl;
    return 0;
}

Measured memory_bytes: 3732
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number, one, five, ten, value;
    boolean flag = true;
    number = Integer.parseInt(sc.next());
    value = Integer.parseInt(sc.next());
    for(ten = 0; ten <= number; ten++) {
      for(five = 0; five <= number - ten; five++) {
        one = number - ten - five;
        if(one * 1000 + five * 5000 + ten * 10000 == value) {
          flag = false;
          System.out.println(ten + " " + five + " " + one);
          return;
        }
      }
    }
    if(flag) System.out.println("-1 -1 -1");
  }
}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;
int main()
{
    long int n;
    cin >> n;

    long int a[n];

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

    long int ans = 0;
    long int counter = 1;

    for (int i = 0; i < n; i++)
    {
        if (a[i] == counter)
        {
            counter = counter + 1;
        }else
        {
            ans = ans +1;
        }
    }

    if (ans == n)
    {
        ans = -1;
    }


    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 1792
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

long N,M;
long A[100000],B[100000];

long ans[100000];

//引用元
//http://drken1215.hatenablog.com/entry/2019/03/03/224600
struct UnionFind {
    vector<long> parent;
    
    UnionFind(long n) : parent(n, -1) { }
    void init(long n) { parent.assign(n, -1); }
    
    //xの属している木の根っこを返す
    long root(long x) {
        if (parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);//経路圧縮
    }
    
    long size(long x) {return -parent[root(x)];}
    bool is_same_tree(long x,long y) {return root(x)==root(y);}
    
    bool merge(long x,long y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);//xの親の方がyの親より小さくなるようにする
        parent[x] += parent[y];
        parent[y] = x;//yの親をxとする
        return true;
    }
};

void solve(){
	UnionFind uf(N+1);
	ans[M-1] = N*(N-1)/2;
	for(int i=M-1;i>=1;i--){
		if(uf.is_same_tree(A[i],B[i])){
			ans[i-1] = ans[i];
			continue;
		}
		ans[i-1] = ans[i] - ((long)uf.size(A[i]))*((long)uf.size(B[i]));
		uf.merge(A[i],B[i]);
	}
}
 
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++)cin >> A[i] >> B[i];
 
	solve();

	for(int i=0;i<M;i++)cout << ans[i] << endl;
	return 0;
}


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

int main() {
  int a, b, c, d, e, ans;
  cin >> a >> b >> c >> d >> e;
  if (a < 0) {
    a *= -1;
    ans = c * a + d + e * b;
  } else {
    ans = e * (b - a);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3084
#include <stdio.h>
int gcd(int a,int b){
    int r;
    if(a<b){
        int 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,x;
    scanf("%d%d",&n,&x);
    int a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=abs(x-a[i]);
    }
    if(n==1){
        printf("%d",abs(x-a[0]));
        return 0;
    }
    int p=gcd(b[0],b[1]);
    for(int i=2;i<n;i++){
        p=gcd(p,b[i]);
    }
    printf("%d",p);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

	for(int i=2; i<1000000; i++){
		if(n[i]==0){ continue; }
		if(n[i]==1){
			for(int j=i*2; j<1000000; j+=i){ n[j]=0;	}
		}
	}

	int num;
	int count;
	while(cin >> num){
		count = 0;
		for(int i=2; i<=num; i++){
			count += n[i];
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 3968
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, K = mi()
    D = set(mi())
    while True:
        if set(map(int, str(N))) & D:
            N += 1
        else:
            print(N)
            return
if __name__ == '__main__':
    main()

Measured memory_bytes: 73224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int x = scanner.nextInt();
        int cnt=0;

        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++) {
               for(int k=0; k<=c; k++) {
                   if(((500*i)+(100*j)+(50*k)) == x) {
                       cnt++;
                   }
               }
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 27088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int a, b;
    cin >> a >> b;
    REP(i, 100000){
        double c = i;
        if (int(floor(c * 0.08) == a &&int(floor(c * 0.1) == b))){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[100005][13];
int main(void){
	ll MOD=1000000007;
	ll k=10;
	int a;
	string s;
	cin>>s;
	if(s[s.size()-1]=='?'){
		for(int i=0;i<=9;i++){
			ans[s.size()-1][i]=1;
		}
	}else{
		a=s[s.size()-1]-48;
		ans[s.size()-1][a]=1;
	}
	for(int i=1;i<s.size();i++){
		if(s[s.size()-i-1]=='?'){
			for(int j=0;j<=12;j++){
				for(int l=0;l<=9;l++){
					int J=(j-k*l+1300)%13;
					ans[s.size()-i-1][j]=(ans[s.size()-i-1][j]+ans[s.size()-i][J])%MOD;
				}
			}
		}else{
			a=s[s.size()-i-1]-48;
			for(int j=0;j<=12;j++){
				int J=(j-k*a+1300)%13;
				ans[s.size()-i-1][j]=(ans[s.size()-i-1][j]+ans[s.size()-i][J])%MOD;
			}
		}
		/*for(int j=0;j<13;j++){
			cout<<ans[s.size()-i-1][j]<<" ";
		}*/
		k=k*10%13;
		//cout<<endl;
	}
	cout<<ans[0][5]%MOD<<endl;
    
}


Measured memory_bytes: 10624
#include <stdio.h>

int main(void){
    int m,f,r;

    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1) break;
        if(m==-1||f==-1) printf("F\n");
        else{
            int total=m+f;
            if(total>=80) printf("A\n");
            else if(total>=65) printf("B\n");
            else if(total>=50) printf("C\n");
            else if(total>=30){
                if(r>=50) printf("C\n");
                else printf("D\n");
            }else printf("F\n");
        }
        getchar();
    }

    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> C(N);
    for(int i=0; i<N; ++i) cin >> C[i];
    C.erase(unique(begin(C), end(C)), end(C));

    const long long MOD = 1000000007;
    map<int, long long> sum;
    sum[C[0]] = 1;
    for(int i=1; i<C.size(); ++i) {
        sum[C[i]] = (sum[C[i]] + sum[C[i - 1]]) % MOD;
    }
    cout << sum[*rbegin(C)] << endl;
}

Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		long a = scanner.nextLong();
		long b = scanner.nextLong();

		long ans = 0;
		if(a + b > 0){
			long big = n/(a+b);
			long small = n%(a+b);
			long ss = Math.min(small, a);


			ans = big*a + ss;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    vector<ll>a(n+1),b(n);
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];

    ll sum=0;
    rep(i,n){
        sum+=min(a[i],b[i]);
        b[i]-=min(a[i],b[i]);
        sum+=min(a[i+1],b[i]);
        a[i+1]-=min(a[i+1],b[i]);
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> p(N);
	for (Int i = 0; i < N; i++) {
		cin >> p[i];
	}

	Int ans = 0;
	Int cnt = 0;

	for (Int i = 0; i < N; i++) {
		if (p[i] == i+1) {
			cnt++;
		}
		else {
			ans += (cnt + 1) / 2;
			cnt = 0;
		}
	}

	if (cnt)ans += (cnt + 1) / 2;

	cout << ans << "\n";
}

Measured memory_bytes: 1024
f = readlines
N = f[0].to_i
a = f[1].split(" ").map(&:to_i)
b = f[2].split(" ").map(&:to_i)
b.push(0)
i = N
ans = 0

while i > 0
  if a[i] > b[i]
    ans += b[i]
    a[i] -= b[i]
  else
    ans += a[i]
    a[i] = 0
  end
  m = a[i] - b[i-1]
  
  if m >= 0
    ans += b[i-1]
    b[i-1] = 0
  else 
    ans += a[i]
    b[i-1] -= a[i]
  end
  i -= 1
end

if a[i] > b[i]
  ans += b[i]
else
  ans += a[i]
end

puts ans


Measured memory_bytes: 15500
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	LLONG N, A, B;
	get(N, A, B);

	LLONG ans = 0;
	LLONG diff = tp_abs(A - B);
	if (diff % 2 == 0) {
		ans = diff / 2LL;
	}
	else {
		LLONG big = std::max(A, B);
		LLONG sml = std::min(A, B);

		ans = (big - sml) / 2 + sml;

		ans = std::min(ans, (N - big + 1) + (N - (sml + N - big + 1)) / 2);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3664
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
set<int> seti;
int main(){
    std::ios::sync_with_stdio(false);
    int n,i,val;
    cin>>n;
    if(n/10==9 || n%10==9){

    	cout<<"Yes"<<endl;
    }
    else
    	cout<<"No"<<endl;
    return 0;  
    
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	String S = sc.next();
	String s[] = S.split("");
	String T = sc.next();
	String t[] = T.split("");

	int count = 0;
	for (int i = 0; i < 3; i++) {
	    if (s[i].equals(t[i]))
		count++;
	}

	System.out.println(count);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one
}

int main() {

    double r = inp1;

    cout << fixed << setprecision(7) << r * 2.0 * acos(-1) << endl;

    return 0;
}


Measured memory_bytes: 3784
/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int mod = 1e9+7;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}
const int N = 2e3+5;

int32_t main(){
   
   speed_cubing
   
   int n,d;
   cin>>n>>d;

   int cnt = 0;

   for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      int temp = x*x+y*y;
      if(temp<=d*d)
        cnt++;
   }

   cout<<cnt;

   return 0;
}

Measured memory_bytes: 3648
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

class EnumerableBits {
  int N;
	vector<bool> bits;
	long long b, max_b;
public:
	EnumerableBits(int N) {
	  this->N = N;
		this->max_b = (1 << N) - 1;
		reset();
	}

  // ビット列を0に戻す
	void reset() {
		bits = vector<bool>(N, 0);
		b = 0;
	}

  // ビット列の桁数を返す
	int size() {
		return N;
	}

  // ビットが1である個数を返す
	int count() {
		return accumulate(bits.begin(), bits.end(), 0);
	}

  // ビット列を1進める
	bool next() {
		if (b == max_b) {
			return false;
		}

		b++;
		for (int i = 0; i < N; i++) {
			bits[i] = b >> i & 1;
		}

		return true;
	}

  // ビット列のvectorを返す
	vector<bool> get_bits() {
		return bits;
	}

  // ビット列のvectorへの参照を返す（変更しない場合はこちらが高速）
	vector<bool>& get_bits_ref() {
		return bits;
	}

	// ビットが1であるインデックスのvectorを返す
	vector<int> get_indices() {
		vector<int> indices;
		for (int i=0; i<bits.size(); i++) {
			if (bits[i]) {
				indices.push_back(i);
			}
		}

		return indices;
	}
};

int C[12];
int A[12][12];
int understand[12];

int main() {
	int N, M, X;
	cin >> N >> M >> X;

	for (int i=0; i<N; i++) {
		cin >> C[i];
		for (int j=0; j<M; j++) {
			cin >> A[i][j];
		}
	}

	EnumerableBits enum_bits(12);

	int min_cost = INF;
	do {
		vector<int> indices = enum_bits.get_indices();
		int cost = 0;
		for (int i=0; i<M; i++) {
			understand[i] = 0;
		}

		for (int i : indices) {
			cost += C[i];
			for (int j=0; j<M; j++) {
				understand[j] += A[i][j];
			}
		}

		bool ok = true;
		for (int j=0; j<M; j++) {
			if (understand[j] < X) {
				ok = false;
				break;
			}
		}

		if (ok) {
			min_cost = min(min_cost, cost);
		}
	} while (enum_bits.next());

	int ans;
	if (min_cost == INF) {
		ans = -1;
	} else {
		ans = min_cost;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

const int n_max = 8;
int N, M;
int Graph[n_max][n_max];
bool is_visited[n_max];

int dfs(int cur_v) {
    bool all_visited = true;
    for (int i = 0; i < N; i++) {
        if (is_visited[i] == false) {
            all_visited = false;
            break;
        }
    }
    if (all_visited) { return 1; }
    int ret = 0;

    for (int i = 0; i < N; i++) {
        if (Graph[cur_v][i] == 0) { continue; }
        if (is_visited[i]) { continue; }

        is_visited[i] = true;
        ret += dfs(i);
        is_visited[i] = false;
    }
    return ret;
}

int main() {
    int a, b;

    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        Graph[a-1][b-1] = Graph[b-1][a-1] = 1;
    }
    for (int i = 0; i < N; i++) {
        is_visited[i] = false;
    }
    is_visited[0] = true;

    cout << dfs(0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,a[maxn],u,v,arr[maxn],arr2[maxn],ans[maxn];
vector<int> adj[maxn],LIS;

void dfs(int u, int x){
	if(lower_bound(all(LIS),a[u])==LIS.end()){
		arr[u]=-1;
		LIS.pb(a[u]);
	}
	else{
		arr[u]=lower_bound(all(LIS),a[u])-LIS.begin();
		arr2[u]=LIS[arr[u]];
		LIS[arr[u]]=a[u];
	}
	ans[u]=sz(LIS);
	rep(sz(adj[u])){
		int v=adj[u][i];
		if(v!=x) dfs(v,u);
	}
	if(arr[u]==-1) LIS.pop_back();
	else LIS[arr[u]]=arr2[u];
}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i];
	rep(n-1){
		cin >> u >> v;
		u--,v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(0,-1);
	rep(n) print1(ans[i]);
	return 0;
}

Measured memory_bytes: 29300
#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;    // 許容誤差。問題によって変える
typedef complex<double> P;  // Point
#define X real()
#define Y imag()
namespace std{
    bool operator < (const P a, const P b){
        return a.X != b.X ? a.X <b.X : a.Y < b.Y;
    }
    P operator+(const P p1, const P p2) { return P(p1.X + p2.X, p1.Y + p2.Y); }
    P operator-(const P p1, const P p2) { return P(p1.X - p2.X, p1.Y - p2.Y); }
    P operator*(const P p, double k) { return P(p.X * k, p.Y * k); }
    P operator/(const P p, double k) { return P(p.X / k, p.Y / k); }
}
//外積cross(a,b) = |a||b|sinθ=a1b2+a2b1
double cross(const P& a, const P& b) {
  return (conj(a)*b).Y;
}
//内積dot(a,b) = |a||b|cosθ=a1b1+a2b2
double dot(const P& a, const P& b) {
  return (conj(a)*b).X;
}

//位置関係判定(線分abを軸にcがどちら側にあるか)
int ccw(P a, P b, P c){
    b -= a;
    c -= a; //aからの向きを考える
    if (cross(b, c) > EPS)
        return +1; //clockwise
    else if (cross(b, c) < -EPS)
        return -1; //counter clockwise
    else if (dot(b, c) < -EPS)
        return +2; //c-a-b
    else if (norm(b) < norm(c))
        return -2; //a-b-c
    else return 0;    //他
}

int main(){
    double x0,y0,x1,y1;
    cin>>x0>>y0>>x1>>y1;
    P p0 = P(x0, y0), p1 = P(x1, y1);
    int q;
    cin >> q;
    for (int i = 0; i < q;i++){
        double x2,y2;
        cin>>x2>>y2;
        int pos=ccw(p0,p1,P(x2,y2));
        if(pos==-1) cout << "CLOCKWISE" << endl;
        else if(pos==1) cout << "COUNTER_CLOCKWISE" << endl;
        else if(pos==2) cout << "ONLINE_BACK" << endl;
        else if(pos==-2) cout << "ONLINE_FRONT" << endl;
        else  cout << "ON_SEGMENT" << endl;
    }
    return 0;
}



Measured memory_bytes: 3232
/****************************
*  Developer : joshi08
*  Date  :  14-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;

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

	lli n,i,j,k,cnt=0;
	cin>>n;
	
	vector<lli> a;
	vector<lli> hash(1000005,0);
	for(i=0;i<n;i++)
	{
		cin>>k;
		a.push_back(k);
		hash[k]++;
	}
	
	sort(a.begin(),a.end());
	
	for(i=0;i<=a.size()-1;i++)
	{
		if(hash[a[i]]==1)
		{
			cnt++;
			
		}
		if(hash[a[i]]>=1)
		{
			for(j=a[i];j<=a[a.size()-1];j+=a[i])
			{
				hash[j] = 0;
			}
		}
	}
	
	cout<<cnt;
	
	

    return 0;
}



Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << "\n"

ll power(ll a, ll b,ll MOD){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int ans(int x) {
	int c = 0;
	while (x > 0) {
		x = x % __builtin_popcount(x);
		c++;
	}
	return c;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#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
	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0;
	for (int i = n - 1; i >= 0; i--) {
		if(s[i]=='1')
			x++;

	}
	int r1,r2,r3;
	r1=r2=r3=0;
	int y=max(x-1,1);
	for (int i = 0;i<n; i++) {
		if(s[i]=='0'){
			r1=(2*r1)%x;
			r2=(2*r2)%(x+1);
			r3=(2*r3)%y;
		}
		else{
			r1=(2*r1+1)%x;
			r2=(2*r2+1)%(x+1);
			r3=(2*r3+1)%y;
		}
	}
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			cout<<ans((r2+(power(2,n-i-1,x+1)))%(x+1))+1<<"\n";
		}
		else{
		    if(x==1)
		        cout<<0<<"\n";
		    else
			    cout<<ans((r3-(power(2,n-i-1,x-1))+(x-1))%(x-1))+1<<"\n";
		}
	}
}


Measured memory_bytes: 3752
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*n
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)


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

int main(){
  int a,b,c;
  cin >>a >>b >>c;
  if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
    cout << "YES" << endl;
  else cout << "NO" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
struct Tree {
    Tree *l, *r;
};
 
Tree *tree[2];
 
Tree* make_node()
{
    Tree *t = new Tree;
    t->l = t->r = NULL;
    return t;
}
 
void init()
{    
    tree[0] = make_node();
    tree[1] = make_node();
}
  
bool search_left_node(int &cur, string &s)
{
    int p = 0;
    for (int i = cur; i >= 1; i--) {
        if (s[i] == ')') {
            p++;
        } else if (s[i] == '(') {
            p--;
        }
        if (s[i] == ',' && p == 1) {
            cur = i;
            return 1;
        }
        if (p < 0) return 0;
    }
    return 0;
}
 
bool search_right_node(int &cur, string &s)
{
    int p = 0;
    for (int i = cur; i < (int)s.size()-1; i++) {
        if (s[i] == '(') {
            p++;
        } else if (s[i] == ')') {
            p--;
        }
        if (s[i] == ',' && p == 1) {
            cur = i;
            return 1;
        }
        if (p < 0) return 0;
    }
    return 0;
}
 
void add_left(Tree *t)
{
    t->l = make_node();
}
 
void add_right(Tree *t)
{
    t->r = make_node();
}
 
void dfs(int cur, string &s, Tree *t)
{
    int L = cur - 1, R = cur + 1;
    if (search_left_node(L, s)) {        
        add_left(t);
        dfs(L, s, t->l);
    }
    if (search_right_node(R, s)) {
        add_right(t);
        dfs(R, s, t->r);
    }
}
  
string make_i_tree(Tree *t1, Tree *t2)
{
    string l, r;
    if (t1->l != NULL && t2->l != NULL) {
        l = make_i_tree(t1->l, t2->l);
    } 
        
    if (t1->r != NULL && t2->r != NULL) {
        r = make_i_tree(t1->r, t2->r);
    }
    return "(" + l + "," + r + ")";
}

string make_u_tree(Tree *t1, Tree *t2)
{
    string l, r;
    if (t1->l != NULL || t2->l != NULL) {
        if (t1->l == NULL) add_left(t1);
        if (t2->l == NULL) add_left(t2);
        l = make_u_tree(t1->l, t2->l);
    } 
        
    if (t1->r != NULL || t2->r != NULL) {
        if (t1->r == NULL) add_right(t1);
        if (t2->r == NULL) add_right(t2);
        r = make_u_tree(t1->r, t2->r);
    }
    return "(" + l + "," + r + ")";
}

int get_root(string &s)
{
    int depth = 0;
    for (int i = 1; i < (int)s.size(); i++) {
        if (s[i] == '(') depth++;
        else if (s[i] == ')') depth--;
        if (depth == 0 && s[i] == ',') {
            return i;
        }
    }
    return -1;
}

void solve(char order, string &a, string &b)
{
    int cur_a = get_root(a), cur_b = get_root(b);   
    init();
    
    dfs(cur_a, a, tree[0]);
    dfs(cur_b, b, tree[1]);
    
    if (order == 'i') {
        cout << make_i_tree(tree[0], tree[1]) << endl;
    } else {
        cout << make_u_tree(tree[0], tree[1]) << endl;
    }
}
 
int main()
{
    char order;
    string a, b;
    while (cin >> order >> a >> b) {
        solve(order, a, b);
    }
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int x = n / 100;
	int y = n % 100;

	// cout << x << endl;
	// cout << y << endl;

	bool can_month1 = (1 <= x && x <= 12);
	bool can_month2 = (1 <= y && y <= 12);

	string ans = "NA";
	if (can_month1 && can_month2) {
		ans = "AMBIGUOUS";
	} else if (can_month1) {
		ans = "MMYY";
	} else if (can_month2) {
		ans = "YYMM";
	}

	cout << ans << endl;

	return 0;
}


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

/*ll powmod(ll x,ll y){     //指数乗の計算　MODありver
  ll ans=1;
  rep(i,y){
    ans=ans*x%mod;
  }
  return ans;
}*/

int main()
{
  int N;
  cin>>N;
  int D[N][2];
  rep(i,N){
    int a,b;
    cin >> a>>b;
    D[i][0]=a;
    D[i][1]=b;
  }
  int cnt=0;
  rep(i,N){
    if(D[i][0]==D[i][1]){
      cnt++;
      if(cnt==3) break;
    }else cnt=0;
  }
  if(cnt==3) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 3644
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var HWK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var H = HWK[0]; var W = HWK[1]; var K = HWK[2];
            var map = new bool[H, W];

            for (int h = 0; h < H; h++)
            {
                var read = Console.ReadLine();
                for (int w = 0; w < W; w++) map[h, w] = read[w] == '#';
            }

            var result = 0;
            for (int hlines = 0; hlines < (1 << H); hlines++)
            {
                for (int wlines = 0; wlines < (1 << W); wlines++)
                {
                    var copyMap = new bool[H, W];
                    Array.Copy(map, copyMap, map.Length);
                    for (int delH = 0; delH < H; delH++)
                    {
                        if ((hlines & (1 << delH)) > 0)
                        {
                            for (int w = 0; w < W; w++)
                            {
                                copyMap[delH, w] = false;
                            }
                        }
                    }
                    for (int delW = 0; delW < W; delW++)
                    {
                        if ((wlines & (1 << delW)) > 0)
                        {
                            for (int h = 0; h < H; h++)
                            {
                                copyMap[h, delW] = false;
                            }
                        }
                    }

                    var count = 0;
                    for (int h = 0; h < H; h++)
                    {
                        for (int w = 0; w < W; w++)
                        {
                            if (copyMap[h, w]) count++;
                        }
                    }
                    if (count == K) result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27808
#include<iostream>

using namespace std;
const int MAX_P = 100, MAX_D = 10;
int D, G, p[MAX_P], c[MAX_D], sump[MAX_D], ans = 1000;
bool b[MAX_D];

void judge(int sum, int num)
{
  int j;
  for(int i = 0; i < D; i++){
    if(b[i] == false){
      j = i;
    }
  }
  for(int i = 0; i < p[j] - 1; i++){
    sum += 100 * (j + 1);
    num++;
    if(sum >= G) break;
  }
  if(sum >= G && ans >= num) ans = num;
}

void bfs(int i, int sum, int num)
{
  if(i == D){
    if(sum >= G){
      if(ans >= num) ans = num;
    }else{
      judge(sum, num);
    }
    return;
  }

  b[i] = true;
  bfs(i + 1, sum + sump[i], num + p[i]);

  b[i] = false;
  bfs(i + 1, sum, num);
  return;
}

int main()
{
  cin >> D;
  cin >> G;

  for(int i = 0; i < D; i++){
    cin >> p[i];
    cin >> c[i];
   }
  for(int i = 0; i < D; i++){
    sump[i] = 100 * (i + 1) * p[i] + c[i];
  }

  bfs(0, 0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256