akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> vi;

const int Z = 1e9+7;

int bexp(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return 1ll * a * bexp(a, x - 1) % Z;
    }
    int t = bexp(a, x / 2);
    return 1ll * t * t % Z;
}

int inv(int a) {
    return bexp(a, Z - 2);
}

void dfs1(vi e[], const vi &fac, const vi &ifac, int x, int p[], int sz[], int dp[]) {
    sz[x] = 0;
    dp[x] = 1;

    for (int y : e[x]) {
        if (y != p[x]) {
            p[y] = x;
            dfs1(e, fac, ifac, y, p, sz, dp);
            sz[x] += sz[y];
            dp[x] = 1ll * dp[x] * dp[y] % Z;
        }
    }

    dp[x] = 1ll * dp[x] * fac[sz[x]] % Z;
    for (int y : e[x]) {
        if (y != p[x]) {
            dp[x] = 1ll * dp[x] * ifac[sz[y]] % Z;
        }
    }

    sz[x]++;
}

void dfs2(vi e[], const vi &fac, const vi &ifac, int x, int p[], int sz[], int dp[], int dp2[]) {
    if (x == 0) {
        dp2[x] = 1;
    } else {
        dp2[x] = 1ll * dp[p[x]] * inv(dp[x]) % Z * ifac[sz[p[x]]-1] % Z * fac[sz[x]] % Z;
        dp2[x] = 1ll * dp2[x] * dp2[p[x]] % Z * fac[sz[0]-1-sz[x]] % Z * ifac[sz[0]-sz[p[x]]] % Z;
    }

    for (int y : e[x]) {
        if (y != p[x]) {
            dfs2(e, fac, ifac, y, p, sz, dp, dp2);
        }
    }
}

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

    int n;
    cin >> n;
    vi e[n];
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    vi fac(n), ifac(n);
    for (int i = 0; i < n; i++) {
        fac[i] = i == 0 ? 1 : 1ll * fac[i-1] * i % Z;
        ifac[i] = i == 0 ? 1 : 1ll * ifac[i-1] * inv(i) % Z;
    }

    int p[n], sz[n], dp[n];
    p[0] = -1;
    dfs1(e, fac, ifac, 0, p, sz, dp);

    int dp2[n];
    dfs2(e, fac, ifac, 0, p, sz, dp, dp2);

    for (int i = 0; i < n; i++) {
        cout << 1ll * dp[i] * dp2[i] % Z * fac[sz[0]-1] % Z * ifac[sz[i]-1] % Z * ifac[sz[0]-sz[i]] % Z << endl;
    }

    return 0;
}


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

int main()
{
    string S;
    cin >> S;
    string ans = "WA";
    bool ok = true;
    if (S[0] == 'A')
    {
        int c = 0;
        if (S[1] < 'a')
            ok = false;
        for (int i = 2; i < S.size() - 1; i++)
        {
            if (c == 0 && S[i] == 'C')
                c++;
            else if (S[i] < 'a')
                ok = false;
        }
        if (S[S.size() - 1] < 'a')
            ok = false;
        if (c == 1 && ok)
            ans = "AC";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	B := sc.Next()

	count := 0
	for i := 0; i < len(B)/2; i++ {
		if B[i] != B[len(B)-1-i] {
			count++
		}
	}

	fmt.Println(count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (int) 1e9 + 7;

int main(){
    
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n,0);
    
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int b;
            cin >> b;
            a[b - 1]++;
        }
    }
    
    int ans = 0;
    
    rep(i,n) if(a[i] == 0) ans++;
    
    cout << ans << "\n";
    
    return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int a,b;
char c;
int main(){
    cin>>a>>b;
    while(a--){
        cin>>c;
        if(c<'0'||c>'9'){
            puts("No");
            return 0;
        }
    }
    cin>>c;
    if(c!='-'){
        puts("No");
        return 0;
    }
    while(b--){
        cin>>c;
        if(c<'0'||c>'9'){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
aI, aO, aT, aJ, aL, aS, aZ = map(int, raw_input().split())
ans = 0
for i in range(2):
    if aI>=i and aJ>=i and aL>=i:
        ans = max(ans, (aI-i)/2*2+aO+(aJ-i)/2*2+(aL-i)/2*2+3*i)
print ans


Measured memory_bytes: 2568
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
int d,g,c[N],p[N],ans=inf,vis[N];
void find(){
	int sum=0,ans1=0;
	for(int i=1;i<=d;i++){
		if(vis[i]){
			ans1+=c[i];
			sum+=p[i]+c[i]*100*i;
		}
	}
	if(sum>=g){
		ans=min(ans1,ans);return;
	}
	for(int i=d;i;i--){
		if(vis[i])continue;
		int t=c[i];
		while(t>1){
			t--;
			ans1++;
			sum+=100*i;
			if(sum>=g){
				ans=min(ans1,ans);
				return;
			}
		}
	}
}
void dfs(int x){
	if(x==d+1){find();return;}
	vis[x]=1;dfs(x+1);
	vis[x]=0;dfs(x+1);
}
int main(){
	in2(d,g);
	for(int i=1;i<=d;i++)in2(c[i],p[i]);
	dfs(1);
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int k,s;
	cin >> k >> s;
	int ans = 0;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= k;j++){
			if(s - i - j >= 0 && s - i - j <= k)ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  long long x,a=100;
  cin >> x;
  rep(i,4000){
    if(a>=x){
      cout << i << endl;
      break;
    }
    a += (a/100);
  }
}

Measured memory_bytes: 3632
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:23/05/2020
*/
// #include <boost/lexical_cast.hpp>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long 
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define tc(t) cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)
ll max(ll a,ll b){if(a>b)return a;else return b;} 
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll mod=1000000007;

unordered_map<ll,ll>cache;
ll a,b,c,d;

ll dp(ll n)
{
    
    if(n==0)
    return 0;
    if(n==1)
    return d;
    if(cache.find(n)!=cache.end())
    return cache[n];
    ll &ans=cache[n];
    ans=4e18;
    if(n<4e9)
    ans=min(ans,n*d);
    for(ll i=-10;i<=10;i++)
    {
        ll k=n+i;
        if(k<0)
        continue;
        if(k%2==0 and k/2<n)
        ans=min(ans,abs(i)*d+a+dp(k/2));
        if(k%3==0 and k/3<n)
        ans=min(ans,abs(i)*d+b+dp(k/3));
        if(k%5==0 and k/2<n)
        ans=min(ans,abs(i)*d+c+dp(k/5));
        if(k%6==0 and k/6<n)
        ans=min(ans,abs(i)*d+a+b+dp(k/6));
        if(k%10==0 and k/10<n)
        ans=min(ans,abs(i)*d+a+c+dp(k/10));
        if(k%15==0 and k/15<n)
        ans=min(ans,abs(i)*d+b+c+dp(k/15));
        
        
        
    }
    return ans;
    
}


bool test = 1;
void solve()
{
    ll n;
    cache.clear();
    cin>>n>>a>>b>>c>>d;
    cout<<dp(n)<<endl;
}










int main()
{
    fio;

    #ifndef ONLINE_JUDGE 
      freopen("input.txt", "r", stdin); 
      freopen("output.txt", "w", stdout); 
      // freopen("error.txt", "w", stderr); 
   #endif
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    char choco[h][w];
    rep(i,h) rep(j,w) cin >> choco[i][j];
    int ans = h*w;
    int matakitane = -1;
    rep(i,pow(2,h-1)){
        vector<int> vec;
        vec.push_back(0);
        int tmpans  = 0;
        rep(j,h-1) if(i&(1<<j)) vec.push_back(j+1),tmpans++;
        vec.push_back(h);
        int c[tmpans+1];
        rep(j,tmpans+1) c[j]=0;
        //Debug_Output_ALL(vec);
        //if(i==2) Debug_Output_ALL(vec);
        //if(i==2) cout << tmpans << endl;
        rep(j,w){
            int maxc = -1;
            for(int k = 1;k<vec.size();k++){
                for(int l = vec[k-1];l<vec[k];l++){
                    if(choco[l][j]=='1') c[k-1]++;
                }
            }
            rep(k,vec.size()-1) maxc = max(maxc,c[k]);
            //if(i==2) cout << maxc << " ";
            if(maxc>k){
                tmpans++;
                rep(k,vec.size()-1) c[k]=0;
                if(matakitane==j){
                    tmpans = INF_int;
                    //if(i==2) cout << "meu" << endl;
                    break;
                }
                matakitane = j;
                j--;
                //if(i==2) cout << j << endl;
            }
        }
        //if(i==2) cout << tmpans << endl;
        ans = min(ans,tmpans);
    }
    cout << ans << endl;
}

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

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    A+=B;
    C+=D;
    if(A>C){
        cout<<"Left"<<endl;
    }else if(A == C){
        cout<<"Balanced"<<endl;
    }else{
        cout<<"Right"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] c = S.toCharArray();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < c.length; i++) {
            sb.append('x');
        }
        System.out.println(sb);
    }

}

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

public class Main {
	static String s;
	static long x;
	
	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		s = br.readLine();
		x = 0;
		
		for(int i=0; i<= s.length(); i++) f(i, 0, s);
		System.out.println(x);
	}
	
	static void f(int plus, long sum, String str){
		if(plus != 0){
			for(int i=1; i<str.length()-plus+1; i++){
				f(plus-1, Long.parseLong(str.substring(0, i))+sum, str.substring(i, str.length()));
			}
		}else{
			x += sum + Long.parseLong(str);
		}
	}
}


Measured memory_bytes: 8788
#include <bits/stdc++.h>
#define ll long long int    
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const ll MOD = 1e9 + 7, N = 1e5 + 3;

int main(){
    ll x, n;
    cin >> x >> n;
    if(n == 0)
        cout << x;
    else{
        ll a[n];
        for(int i = 0; i < n; ++i)
            cin >> a[i];
        sort(a, a+n);
        ll ans = 0, d = 0, ans1 = 0;
        for(int i = x; i >= 0; --i){
            for(int j = 0; j < n; ++j){
                if(a[j] == i){
                    ++d;
                    break;
                }
            }
            if(d == 0){
                ans = i;
                break;
            }
            d = 0;
        }
        d = 0;
        for(int i = x; i < 1e5; ++i){
            for(int j = 0; j < n; ++j){
                if(a[j] == i){
                    ++d;
                    break;
                }
            }
            if(d == 0){
                ans1 = i;
                break;
            }
            d = 0;
        }
        if(abs(ans - x) > abs(ans1 - x))
            cout << ans1;
        else
            cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);

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

    vector<long long> x(n);

    long long sum = 0;

    for(long long i = 0; i < n; i++){
        if(i % 2 == 0){
            sum += 2*a[i];
        }
        else{
            sum -= 2*a[i];
        }
    }

    x[0] = sum/2;

    for(long long i = 1; i < n; i++){
        x[i] = 2*a[i-1] - x[i-1];
    }

    for(long long i = 0; i < n; i++){
        printf("%lld ", x[i]);
    }
    printf("\n");
    return 0;

}

Measured memory_bytes: 2944
#include<cstdio>

int N,Last;
long long Ans;

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        int x;
        scanf("%d",&x);
        if(x<Last)
            Ans+=x,Last=x%2;
        else
            Ans+=Last+(x-Last)/2,Last=(x-Last)%2;
    }
    printf("%lld",Ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;

struct node{
	int key;
	node *right,*left,*parent;
};

node *root,*nil,*z;

void preorder(node *id){
	if(id == nil)return;
	cout << " " << id->key;
	preorder(id->left);
	preorder(id->right);
}

void inorder(node *id){
	if(id == nil)return;
	inorder(id->left);
	cout << " " << id->key;
	inorder(id->right);
}

void print(){
	inorder(root);
	cout << endl;
	preorder(root);
	cout << endl;
}

void insert(int k){
	node *p = nil;
	node *r = root;
	node *z = (node *)malloc(sizeof(node));
	z->key = k;
	z->left = nil;
	z->right = nil;
	while(r != nil){
		p = r;
		if(z->key < r->key){
			r = r->left;
		}else{
			r = r->right;
		}
	}
	z->parent = p;
	if(p == nil){
		root = z;
	}else if(z->key < p->key){
		p->left = z;
	}else{
		p->right = z;
	}
}

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string order;
		int key;
		cin >> order;
		if(order == "print"){
			print();
		}else if(order == "insert"){
			cin >> key;
			insert(key);
		}
	}
}


Measured memory_bytes: 26612
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/26 21:01:50 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	s, w;
	cin >> s >> w;

	if (w >= s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}
// END

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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<int, int> pii;
#define ff first
#define ss second

int main(){
    int n;
    cin>>n;
    lli i,j,l;
    lli a[n][n];
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    lli dp[1<<n]={0};

    for(i=0;i<(1<<n);i++){
        //dp[i] = sum(i);
        lli s=0;
        vector<lli> v;
        for(j=0;j<n;j++){
            if(i&(1<<j)) v.push_back(j);
        }
        for(j=0;j<v.size();j++){
            for(l=j+1;l<v.size();l++){
                s = s + a[v[j]][v[l]];
            }
        }
        dp[i] = s;

        for(j=i;j>0; j = (j-1)&i){
            dp[i] = max(dp[i] , dp[j] + dp[j^i]);
        }
    }
    cout<<dp[(1<<n) - 1]<<endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < n; i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

int main(){
    int n;
    cin >> n;
    
    while(1){
        if(n-1000>=0){
            n-=1000;
        }
        else{
            if(n==0) break;
            else{
                n=1000-n;
                break;
            }
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0;i < m;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> dist(n, -1);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int node = q.front();
        q.pop();
        for (int i = 0;i < g[node].size();i++){
            int next = g[node][i];
            if (dist[next] == -1){
                dist[next] = node;
                q.push(next);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1;i < n;i++){
        cout << dist[i] + 1 << endl;
    }
}

Measured memory_bytes: 10132
N, Q = map(int, input().split())

N -= 2 # 枠を取り除いたサイズに直す

#ここから33行目まで準備。Binary indexed tree(BIT)というデータ構造を使う。

BIT = [[0 for i in range(N+1)] for _ in range(2)] #BITを2つ用意
# BITでできること。
#  1, 要素の更新をO(logn)で行う
#  2, 累積和をO(logn)で求める。
# 　※ 両方ともそれなりに早くできるのがメリット。
#     普通の配列だと、1と2がそれぞれO(1),O(n)かかる。
#     一方、累積和で記録した配列だと、1と2がO(n)とO(1)かかる。
# 原理は例えばhttp://hos.ac/slides/20140319_bit.pdf参照。(これと別にsegment treeも載ってますが、同じような考え方です。)

# 以下、実装用の関数。以下のWeb記事から引用させていただきました。
# https://juppy.hatenablog.com/entry/2018/11/17/%E8%9F%BB%E6%9C%AC_python_Binary_Indexed_Tree_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0

n = N # (直すのサボりました、ごめんなさい)

def BIT_query(idx,BIT):# 1, BITのidx番目までの要素の和を求める。
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x,BIT):# 2, BITのidx番目の要素に、xを足す。
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return
# なお、配列番号idxが1から始まることに注意。(BITの0番目には0を入れておき、「0番目までの和」としておいたほうが都合が良い。)

# 以下、本処理。
# お約束: たて座標を「右から左へ」、よこ座標を「下から上へ」カウントする。(いつもと反対なので注意)
#        座標は1からスタートさせる
#        2つのBITが表す累積和には、それぞれよこ、たて座標における「たて刺し」、「よこ刺し」が刺さる深さ（がNからどれだけ減ったか、負数）を格納する。
#        (もととなる配列の要素ではなく、累積和で表すことに注意。)

now = N * N # 現在の黒玉の数。
max_x = [0, 0] # それぞれ、これまでに刺さった「たて刺し」のうちの最大のよこ座標と、これまでに刺さった「よこ刺し」のうちの最大のたて座標を記録。最初は0とする。
for _ in range(Q):
  # 51行目まで整形作業
  s, x = map(int, input().split())
  # s=0が「たて刺し」、s=1が「よこ刺し」を表すようにする
  s -= 1 
  # 最初に両端を削った分の調整（スタートを0にしているわけではないので注意）
  x -= 1
  # いつもと逆向きに数える
  x = N+1 - x
  
  #どこまで刺さるか
  depth = N + BIT_query(x, BIT[s]) 
  now -= depth #刺さった分だけ、黒玉を減らす
  
  if x > max_x[s]: # 深さの更新処理。今までに刺さったものよりも大きい座標の場合のみ。
    BIT_update(N-depth+1, max_x[s] - x, BIT[1-s]) 
    # 反対側のBITを更新する。今刺さった深さの地点N-depth+1に、max_x[s]-xを足す。累積和なので、N-depth+1より大きい座標すべてにおいて深さが更新される。
    max_x[s] = x
    
print(now)   

# 追記：
#  刺さる深さを普通の配列で持つと、毎回O(N)回更新するためTLEするかと思い、BITを使いました。

#  しかし57行目にあるように、更新が必要なのはそれまでよりも大きい座標のところに「刺し」が入る時のみです。
#  ここで、これまでの「刺し」の最大座標よりも小さい座標に刺さる「刺し」の深さは、それ以降変化することはありません。
#  また、最大座標よりも大きい座標での「刺し」の深さは、全て同じ値になり、その値１つを記録しておけば十分です。

#  このため、普通の配列に「刺し」の最大座標よりも小さい座標についての深さを記録しておき、
#  「刺し」の最大座標よりも大きい部分については一括して１つの値で管理しておけば、
#   BITなしでも上記の目的が果たせます。

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=8;
char grid[mxn][mxn];
int row[mxn],col[mxn];
int h,w,k;

int calc(int x, int y){
	int res = 0;
	for(int i=0;i<h;i++){
		if(x>>i&1)continue;
		for(int j=0; j<w; j++){
			if(y>>j&1)continue;
			res += grid[i][j]=='#';
		}
	} 
	return res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> h >> w >> k;
	int t=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> grid[i][j];
			if(grid[i][j]=='#'){
				row[i]++;
				col[j]++;
				t++;
			}
		}
	}
	int left = t-k;
	int ans = 0;
	for(int i=0; i<(1<<h); i++){
		for(int j=0; j<(1<<w); j++){
			if(calc(i,j)==k)ans++;
		}
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3644
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        int cnt = inpt[1];

        long[] list = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();

        long totalMinus = 0;
        long totalPlus = 0;

        long totalMinusMin = 0;
        long totalPlusMin = 0;

        long totalAll = 0;

        for(int i=0; i<list.Length; i++) {
            if(list[i]>0) {
                totalPlus+=list[i];
                totalAll+=list[i];
            }
            if(list[i]<0) {
                totalMinus+=list[i];
            }
            if(i>=cnt) {
                if(list[i-cnt]>0) {
                    totalPlus-=list[i-cnt];
                }
                if(list[i-cnt]<0) {
                    totalMinus-=list[i-cnt];
                }
            }
            if(i==cnt-1) {
                totalMinusMin = totalMinus;
                totalPlusMin = totalPlus;
            }
            if(i>=cnt-1) {
                if(Math.Abs(totalMinusMin) > Math.Abs(totalMinus)) {
                    totalMinusMin = totalMinus;
                }
                if(totalPlusMin > totalPlus) {
                    totalPlusMin = totalPlus;
                }
            }
        }
        totalAll = Math.Max(totalAll + totalMinusMin, totalAll - totalPlusMin);
        Console.WriteLine(totalAll);
    }

    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"


10 5
5 -4 -5 -8 -4 7 2 -4 0 7




";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }

    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 19408
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, long long D, std::vector<std::vector<long long>> X){
  ll cnt = 0;
  rep(i,N-1) REP(j,i+1,N){
    double x = 0.0;
    rep(k,D) x += double(X[i][k]-X[j][k]) * double(X[i][k]-X[j][k]);
    double sq = sqrt(x);
    if(abs(double(ll(sq))-sq)<double(1e-10)) cnt++;
    dump(i,j,x,sq*sq,x);
  }
  cout << cnt << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < D ; j++){
      scanf("%lld",&X[i][j]);
    }
  }
  solve(N, D, std::move(X));
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int n;
	double t,a;
	scanf("%d%lf%lf",&n,&t,&a);
	double ans = (1e100);
	int ord;
	for(int i = 1;i <= n;i++){
		double x;
		scanf("%lf",&x);
		if(abs(t - 0.006 * x - a) < ans) ans = abs(t - 0.006 * x - a),ord = i;
	}
	printf("%d",ord);
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

vector<ll> yaksuu(ll N) {
    vector<ll> vec;
    for (ll i = 1;i*i <= N;i++) {
        if (N%i == 0) {
            vec.push_back(i);
            vec.push_back(N/i);
        }
    }
    return vec; 
}


// 桁数を数える
long long keta(long long a) {
    long long res = 0;
    while (a) {
        ++res;
        a /= 10;
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> vec;
    vec = yaksuu(N);
    ll ans = INF;
    //cout << vec.size() << endl;
    for (ll i = 0;i<vec.size() - 1;i++) {
        ll k = max(keta(vec.at(i)),keta(vec.at(i+1)));
        ans = min(ans,k);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
K = int(input())
hist = set()

INF = 10**8

w = 0
pows = 1
for i in range(INF):
  w += 7 * pows
  pows = pows * 10 % K
  w %= K
  if w == 0:
    print(i+1)
    break
  else:
    if w in hist:
      print(-1)
      break
    else:
      hist.add(w)
      
#print(hist)


Measured memory_bytes: 77656
def main():
    # from math import gcd

    def gcd(a, b):
        return a if b == 0 else gcd(b, a % b)

    A, B, K = map(int, input().split())

    g = gcd(A, B)
    rt = int(pow(g, 0.5))

    divisors = set()
    for d in range(1, rt + 1):
        if g % d == 0:
            divisors.add(d)
            divisors.add(g // d)

    ans = sorted(divisors, reverse=True)[K - 1]
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3064
import math
N,M,K = map(int,input().split())
list = [0 for i in range(N*M+1)]
i = 0
while i <= M:
    k=0
    list[N*i]=1
    while k < N:
        list[N*i+(M-2*i)*k]=1
        k+=1
    i+=1
j = 0
while j <= N:
    l = 0
    list[M*j]=1
    while l < M:
        list[M*j+(N-2*j)*l]=1
        l+=1
    j+=1
if list[K] ==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 16840
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

bool possible(set<int> s, int b, int k){
    //set<int> s;
    //s.insert(a);
    IFOR(i, 1, k){
        set<int> s2;
        for(int n: s) s2.insert(n % i);
        for(int n2: s2) s.insert(n2);
    }
    if(s.count(b) > 0){
        return true;
    }else{
        return false;
    }
}

signed main(){

    int N; cin >> N;
    vec a(N); readvec(a);
    vec b(N); readvec(b);

    vector<bool> ok(N, false);
    vector<set<int>> s(N);

    REP(i, N) if(a[i] == b[i]) ok[i] = true;

    REP(i, N) s[i].insert(a[i]);
    REP(i, N){
        if(!possible(s[i], b[i], 51)){
            cout << -1;
            return 0;
        }
    }

    int ans = 0;
    IFOR(k, 1, 51){
        bool f = false;
        REP(i, N){
            if(ok[i]) continue;
            if(!possible(s[i], b[i], k)){
                f = true;
                break;
            }
        }

        if(f){
            ans += (1LL << k);
            REP(i, N){
                if(ok[i]) continue;
                set<int> s2;
                for(int n: s[i]) s2.insert(n % k);
                for(int n2: s2) s[i].insert(n2);
                if(s[i].count(b[i]) > 0) ok[i] = true;
            }
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
const ll INF=1e18 + 5;
ll p=1000000007;
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);   
    // freopen("output.txt", "w", stdout);
    // #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n;cin>>n;
    ll dp[1<<n];
    ll a[n][n];
    rep(i,n)rep(j,n)cin>>a[i][j];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<(1<<n);i++){
        int x=__builtin_popcount(i);
        for(int j=0;j<n;j++){
            if(i&(1<<j))continue;
            if(a[x][j])
            dp[i|(1<<j)]+=dp[i];
            dp[i|(1<<j)]%=p;
        }
    }
    cout<<dp[(1<<n)-1];
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  vector<int> table(50000,1);
  table[0] = table[1] = 0;
  for(int i=2; i*i<50000; i++)
    if(table[i])
      for(int j=i*2; j<50000; j+=i)
        table[j] = 0;
  vector<int> pr;
  REP(i,50000)
    if(table[i])
      pr.push_back(i);
  int n;
  while(cin>>n,n) {
    int ans=0;
    for(int i=0; pr[i]<=n/2; i++) {
      if (table[n-pr[i]]) ans++;
    }
    cout << ans << endl;
  }
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a;
	string s;
	cin >> a >> s;
	if(a >= 3200){
		cout << s;
	} else {
		cout << "red";
	}
}

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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

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; }


// 1. calculate the accumulation of sum for 2017-like numbers
// 2. answer each query with O(1) time complexity

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

int main(){
    int Q;
    cin >> Q;
    
    // 1. calculate the accumulation of sum for 2017-like numbers
    
    const int range = pow(10, 5)+2;
    
    // S[r] : sum of 2017-like numbers between 0 and r
    vector<int> S(range,0);
    for(int i = 1; i <= 100000; i++){
        
        S[i] += S[i-1];
        if (i % 2 == 1 && isPrime(i) && isPrime((i+1)/ 2)) S[i] += 1;
    }

    rep(i, Q){
        int l, r;
        cin >> l >> r;
        
        cout << S[r] - S[l-1] << endl;
    }
    
}

Measured memory_bytes: 1024
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const int d=62;

int n;

ll tab[nax];
char wcz[nax];
int kto[nax];

ll mac[d];

void dorz(ll v)
{
	for (int i=d-1; i>=0; i--)
		if (v&(1LL<<i))
			v^=mac[i];
	if (!v)
		return;
	int x=d-1;
	while(!(v&(1LL<<x)))
		x--;
	mac[x]=v;
	for (int i=0; i<d; i++)
		if (i!=x && (mac[i]&(1LL<<x)))
			mac[i]^=v;
}

int czy(ll v)
{
	for (int i=d-1; i>=0; i--)
		if (v&(1LL<<i))
			v^=mac[i];
	return (!v);
}

void test()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%lld", &tab[i]);
	scanf("%s", wcz+1);
	for (int i=1; i<=n; i++)
		kto[i]=wcz[i]-'0';
	for (int i=0; i<d; i++)
		mac[i]=0;
	for (int i=n; i; i--)
	{
		if (kto[i]==0)
		{
			dorz(tab[i]);
		}
		else
		{
			if (!czy(tab[i]))
			{
				printf("1\n");
				return;
			}
		}
	}
	printf("0\n");
}

int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
		test();
	return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k;
  cin >> k;
  ll cnt = 9;
  queue<ll> q;
  vl lun;
  lun.push_back(0);
  rep2(i, 1, 10) {
    q.push(i);
    lun.push_back(i);
  }
  while(cnt < k) {
    ll x = q.front();
    q.pop();
    ll d = x % 10;
    if(d != 0) {
      ll n = x * 10 + d - 1;
      q.push(n);
      lun.push_back(n);
    }
    ll m = x * 10 + d;
    q.push(m);
    lun.push_back(m);
    if(d != 9) {
      ll n = x * 10 + d + 1;
      q.push(n);
      lun.push_back(n);
    }
    cnt += 2;
    if(d != 0 && d != 9) cnt++;
  }
  cout << lun[k] << endl;
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int N;  cin >> N;
  vector<int> ans;
  if(N == 0){
    cout << 0 << endl;
    return 0;
  }

  while(N){
	if(N % 2){	ans.push_back(1); N -= 1;}
    else		ans.push_back(0);
    
    N /= -2;
  }
  
  for(int i = ans.size() - 1; 0 <= i ; i--)
    cout << ans[i];
  
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
/*
Author: Fuadul Hasan(fuadul202@gmail.com)
BSMRSTU,Gopalganj
*/

#include <set>
#include <map>
#include <list>
#include <queue>
#include <ctime>
#include <deque>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <chrono>
#include <random>
#include <cassert>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <fstream>
#include <climits>
#include <stdio.h>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
//#include<bits/stdc++.h>
using namespace std;
 
int         cinn()              {int x; scanf("%d", &x); return x;}
long long   scll()              {long long x; scanf("%lld", &x); return x;}
double      scd()               {double x; scanf("%lf", &x); return x;}
void        coutt(int x)        {printf("%d ", x);}
 
#define  scll                   scll()
#define  gcd(a,b)               __gcd(a,b)
#define  lcm(a,b)               (a*b)/gcd(a,b)
#define  PI                     acos(-1.0)
#define  vi                     std::vector<int>
#define  vll                    std::vector<ll>
#define  vit                    vector<int> :: iterator
#define  sit                    set<int> :: iterator
#define  mpsi                   std::map<string, int>
#define  pb                     push_back
#define  ll                     long long int
#define  ld                     long double
#define  ull                    unsigned long long int
#define  min3(a,b,c)            min(a,min(b,c))
#define  min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define  max3(a,b,c)            max(a,max(b,c))
#define  max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define  nl                     printf("\n");
#define  no                     printf("No");
#define  yes                    printf("Yes");
#define  F                      first
#define  S                      second

typedef pair<int,int> ii;
typedef std::vector<ii> vii;
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 1e6 + 5;
const int nn           = 4e5 + 5;



int solve()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			if(a[i]%3==0) continue;
			else if(a[i]%5==0) continue;
			else {
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

int main()
{
    int test = 1, tc = 0;
    //scanf("%d", &test);
   // (void)getchar();
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll gcd(ll a, ll b)
{
    if (a > b)
        std::swap(a, b);

    while (true)
    {
        auto m = b % a;
        if (m == 0)
            return a;
        b = a;
        a = m;
    }
}

int main()
{
    using namespace std;

    int a, p;
    cin >> a >> p;

    auto sum = a * 3 + p;
    
    cout << sum / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int dp[1001][1001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  vector<string> xs(q), ys(q);
  for (int i = 0; i < q; i++) {
    cin >> xs[i] >> ys[i];
  }

  for (int i = 0; i < q; i++) {
    fill(dp[0], dp[1001], 0);
    string x = xs[i], y = ys[i];
    for (int j = 0; j < x.size(); j++) {
      for (int k = 0; k < y.size(); k++) {
        if (x[j] == y[k]) {
          dp[j + 1][k + 1] = dp[j][k] + 1;
        } else {
          dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
        }
      }
    }

    cout << dp[x.size()][y.size()] << endl;
    ;
  }
  return 0;
}


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

int main(){
    string S;
    cin >> S;
    int a = S.size();
    char R = 'R';
    char L = 'L';
    int A[a];
    int res[a];

    for(int i = 0; i < a; i++){
        res[i] = 0;
        A[i] = 0;
    }
    
    for(int i = 0; i < a-1; i++){
        if(S[i] == R & S[i+1] == L){
            A[i] = 1;
            A[i+1] = 1;
        }
    }

    for(int i = 0; i < a;){
        if(S[i] == R){
            int j = 0;
            while(A[i+j] == 0){
                j++;
            }
            if(j % 2 == 0){
                res[i+j] += (j/2)+1;
                res[i+j+1] += j/2;
            }
            else{
                res[i+j] += (j+1)/2;
                res[i+j+1] += (j+1)/2;
            }
            i += j+1;
        }

        else if(S[i] == L){
            i++;
        }
    }

    for(int i = a-1; i >= 0;){
        if(S[i] == L){
            int j = 0;
            while(A[i-j] == 0){
                j++;
            }
            if(j % 2 == 0){
                res[i-j] += (j/2)+1;
                res[i-j-1] += j/2;
            }
            else{
                res[i-j]+= (j+1)/2;
                res[i-j-1] += (j+1)/2;
            }
            i -= j+1;
        }
        else if(S[i] == R){
            i--;
        }
    }

    for(int i = 0; i < a; i++){
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 1408