akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
 
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;
 
    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }
 
    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }
 
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
 
    return ret;
}
const string YES = "YES";
const string NO = "NO";


int main(){
    vector<ll> A(3);
    cin >> A[0] >> A[1] >> A[2];
    SORT(A);
    if(A[0] == 5 && A[1] == 5 && A[2] == 7){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[100001][3];//最後にjを選んだ時の最大値

int main(){
  int n;
  int last=0;

  cin >> n;
  for(int i=0;i<n;i++){
    int a, b, c;
    cin >> a >> b >> c;
    dp[i+1][0]=max(dp[i][1],dp[i][2])+a;
    dp[i+1][1]=max(dp[i][0],dp[i][2])+b;
    dp[i+1][2]=max(dp[i][0],dp[i][1])+c;
  }

  cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <queue>
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int N, M, Q, a[200009], b[200009], r[200009], f[200009], dist[200009], ret[200009]; vector<int> g[200009], gt[200009]; bool vis[100009];
int main() {
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &a[i], &b[i]), a[i]--, b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	fill(f, f + M, -1);
	for (int i = 0; i < Q; i++) scanf("%d", &r[i]), r[i]--, f[r[i]] = i;
	queue<int> que1; que1.push(0);
	fill(dist, dist + N, -1); dist[0] = 0;
	while (!que1.empty()) {
		int u = que1.front(); que1.pop();
		for (int i : g[u]) {
			if (dist[i] == -1) {
				dist[i] = dist[u] + 1;
				que1.push(i);
			}
		}
	}
	for (int i = 0; i < M; i++) {
		if (dist[a[i]] == dist[b[i]]) continue;
		if (dist[a[i]] > dist[b[i]]) swap(a[i], b[i]);
		if (f[i] == -1) gt[a[i]].push_back(b[i]);
	}
	int cnt = N - 1;
	vector<bool> vis(N); vis[0] = true;
	queue<int> que2; que2.push(0);
	while (!que2.empty()) {
		int u = que2.front(); que2.pop();
		for (int i : gt[u]) {
			if (!vis[i]) {
				vis[i] = true; cnt--;
				que2.push(i);
			}
		}
	}
	for (int i = Q - 1; i >= 0; i--) {
		ret[i] = cnt;
		if (dist[a[r[i]]] == dist[b[r[i]]]) continue;
		if (dist[a[r[i]]] > dist[b[r[i]]]) swap(a[r[i]], b[r[i]]);
		gt[a[r[i]]].push_back(b[r[i]]);
		if (vis[a[r[i]]] && !vis[b[r[i]]]) {
			vis[b[r[i]]] = true; cnt--;
			queue<int> que; que.push(b[r[i]]);
			while (!que.empty()) {
				int u = que.front(); que.pop();
				for (int j : gt[u]) {
					if (!vis[j]) {
						vis[j] = true, cnt--;
						que.push(j);
					}
				}
			}
		}
	}
	for (int i = 0; i < Q; i++) printf("%d\n", ret[i]);
	return 0;
}

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

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

    vector<int> t(n);
    int sum_t = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        t.at(i) = x;
        sum_t += x;
    }

    int m;
    cin >> m;

    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        int a, x;
        cin >> a >> x;
        p.at(i) = x - t.at(--a);
    }

    for (int i = 0; i < m; i++)
        cout << (sum_t + p.at(i)) << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <iomanip>

using namespace std;

const int limit = 160;

void Print(const string &s)
{
    int st, end;

    for (int i = 0; i < s.size(); i++) {  // 始点
        for (int k = 1; i + k < s.size() / 2; k++) {  // 数字幅
            bool flag = true;
            string tmp = s.substr(i, k);
            st = i + k;

            while (st + k < s.size()) {
                if (s.substr(st, k) != tmp) {
                    flag = false;
                    break;
                }
                st += k;
            }

            if (flag) {
                cout << s.substr(0, i) << tmp << endl;
                for (int l = 0; l < i; l++)
                    putchar(' ');
                for (int l = 0; l < tmp.size(); l++)
                    putchar('^');
                putchar('\n');

                return ;
            }
        }
    }
}

int main()
{
    int p, q;

    while (cin >> p >> q) {
        string s;
        int quotient, surplus;
        bool flag = false;

        for (int i = 0; i < limit; i++) {
            p *= 10;
            quotient = p / q;
            surplus  = p % q;

            s.push_back(quotient + '0');
            if (surplus == 0) {
                flag = true;
                break;
            }

            p = surplus;
        }
        if (flag)
            cout << s << endl;
        else
            Print(s);
    }

    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int search(const vll& a, const int K, vector<short int>& dp){
  if(dp[K]>=0) return dp[K];
  bool flag1=false;
  bool flag2=true;
  for(ll num : a){
    if(num <= K){
      flag1=true;

      int tmp = search(a, K-num, dp);
      if(tmp%2==0 && tmp>=0){
        flag2 = false;
        return dp[K] = tmp+1;
      }
    }
  }
  if(!flag1 || flag2){
    return dp[K] = 0;
  }
  return dp[K] = -1;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;
  vll a(N);
  rep(i, 0, N){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  vector<short int> dp(K+1, -1);

  if(search(a, K, dp)%2==1) printf("First\n");
  else printf("Second\n");

  return 0;
}

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

int main() {
    long long N, ans;
    cin >> N;
    vector<long long> A(N, 0);
    bool flag = false;

    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    ans = A[0];
    for(int i = 1; i < N; i++){
        ans = ans * A[i];
        if(ans < 0){
            cout << "-1" << endl;
            return 0;
        }
    }
    if(ans > 0 && ans <= 1000000000000000000){
        cout << ans << endl;
    }else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
struct edge{
    int v; // 次の頂点.
    int w; // 距離.
};
int dist[MAX]; // 距離を保存

// グラフを幅優先探索する.
// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param G: グラフ.
// @param s: グラフの探索開始頂点.
// @return: 特に無し.
void bfs(vector<vector<edge> > &G, int s){
    
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. 訪問済みフラグ設定.
    // ※スタート地点は, 距離ゼロを指定.
    dist[s] = 0;
    
    // 3. 探索地点 s をキュー q に追加.
    q.push(s);
    while(!q.empty()){
        
        // 4. キューから取り出す.
        int u = q.front();
        q.pop();
        
        // 5. 取り出した要素を処理.
        for(auto &e : G[u]){
            // 6. 訪問済であれば, 処理をスキップ.
            if(dist[e.v] > 0)              continue;
            if(dist[e.v] == 0 && e.v != s) dist[e.v] = dist[u] + e.w, q.push(e.v);
        }
    }
    return;
}

int main() {
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    vector<vector<edge> > graph(N);
    for(int i = 0; i < N - 1; i++){
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        edge e1, e2;
        // u -> v
        e1.v = v, e1.w = w;
        graph[u].push_back(e1);
        // v -> u
        e2.v = u, e2.w = w;
        graph[v].push_back(e2);
    }
    
    // 2. 頂点を一つ固定して, そこから各頂点への距離を保存.
    // -> 頂点 0 から 最も遠い頂点 u を 選択.
    memset(dist, 0, sizeof(dist));
    bfs(graph, 0);
    int u = 0, d = 0;
    for(int i = 0; i < N; i++) if(d < dist[i]) u = i, d = dist[i];
    
    // 3. 頂点 u から 各頂点への距離を保存.
    // -> 頂点 u から 最も遠い距離 を 探索.
    memset(dist, 0, sizeof(dist));
    bfs(graph, u);
    d = 0;
    for(int i = 0; i < N; i++) if(d < dist[i]) d = dist[i];

    // 4. 出力 ～ 後処理.
    printf("%d\n", d);
    return 0;
    
}


Measured memory_bytes: 9760
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<int>());
  return (ret);
}

signed main(){
  int n,k;cin>>n>>k;
  int a[510];rep(i,n)cin>>a[i];
  int sum = 0;rep(i,n)sum += a[i];
  vector<int> d = divisor(sum);
  rep(i,d.size()){
    int diff[501];int dsum = 0;
    rep(j,n){
      double aa = a[j], dd = d[i];
      diff[j] = (int)(dd*ceil(aa/dd) - aa);
      dsum += diff[j];
    }
    sort(diff, diff+n);
    //cout << d[i] << endl;
    //rep(i,n)cout << diff[i] << " ";
   // cout << endl;
    //cout << n-dsum/d[i] << endl;
    int ans = 0;
    rep(j,n-dsum/d[i]){
      ans += diff[j];
    }
    if(ans <= k){
      cout << d[i] << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}
use std::collections::VecDeque;
fn main() {
    let n = read::<usize>();
    let mut v = VecDeque::new();

    for _i in 0..n {
        let a = read_vec::<i64>();
        match a[0] {
            0 => {
                if a[1] == 0 {
                    v.push_front(a[2])
                } else {
                    v.push_back(a[2])
                }
            }
            1 => println!("{}", v[a[1] as usize]),
            _ => {
                if a[1] == 0 {
                    v.pop_front().unwrap();
                } else {
                    v.pop_back().unwrap();
                }
            }
        }
    }
}



Measured memory_bytes: 9964
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int A,n;
    scanf("%d%d",&A,&n);
    for(int i=1;i<=n;i++){
        int k;scanf("%d",&k);
        if(A>0) A-=k;
    }
    if(A<=0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  double a, b, x;
  cin >> a >> b >> x;
  if (a * b / 2 < x / a)
  {
    double y = 2 * b - (2 * x / a / a);
    double rad = atan2(y, a);
    double ans = rad * 180 / acos(-1);
    printf("%.10lf\n", ans);
  }
  else
  {
    double y = 2 * x / a / b;
    double rad = atan2(b, y);
    double ans = rad * 180 / acos(-1);
    printf("%.10f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
suuretu=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
ans=suuretu[K-1]
print(ans)

Measured memory_bytes: 3060
_, k = (map(int, input().split()))
n = [int(i) for i in list(input())]
rem = n[0]
s = [1]
for i in range(1, len(n)):
    if n[i] == rem:
        s[-1] += 1
    else:
        s.append(1)
        rem = n[i]

imax = 0
sum_ = 0
r = 0
if n[0] == 0:
    s.insert(0, 0)

for l in range(len(s)):
    sum_ += s[l]
    if l % 2 == 1 and l - r > k * 2:
        r += 2
        sum_ -= s[r-2] + s[r-1]
    if sum_ > imax:
        imax = sum_

print(imax)

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

using ll=long long; 

void solve(){
	int n;cin>>n;
	vector<int>a(n);
	for(int i=0; i<n; i++)cin>>a[i];
	int ans=0;
	for(int i=1; i<n; i++){
		if(a[i]==a[i-1]){
			int cnt=2;
			i+=1;
			while(i<n&&a[i]==a[i-1]){
				i+=1;
				cnt+=1;
			}
			ans+=cnt/2;
		}
	}
	cout<<ans<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main(){

  int i,j,k=0,F,n;
  int A[N];

  scanf("%d",&n);

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

  for(j=1 ; j<n ; j++){
    if(A[j]<A[j-1]){
      F=A[j];
      A[j]=A[j-1];
      A[j-1]=F;
      j=0;
      k++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (double i = (a); i < (b); i++)
typedef long long ll;

int main (void)
{
    boost::multiprecision::cpp_int a, b, ans;
    cin >> a >> b;
    ans = a + b;
    cout << ans << endl;
}


Measured memory_bytes: 3424
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod1e7(ll a){
  return (a % 1000000007);
}

ll mod1e9(ll a){
  return (a % 1000000009);
}

ll mod998(ll a){
  return (a % 998244353);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

vector<ll> fac(200001);
void factorial(){
  fac[0] = 1; 
  for(ll i=1; i < 200001; i++){
    fac[i] = mod998(fac[i-1]*i);
  }
}
    
ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return mod998(fac[n]/fac[r]/fac[n-r]);
}

int main(){
  ll n,m; cin >> n >> m; ll accnt = 0; ll wacnt = 0;
  vl acwa(n);
  
  rep(i,m){
    ll x; string s; cin >> x >> s;
    
    if(s == "WA"){
      if(acwa[x-1] != -1) acwa[x-1]++;
    }
    else{
      if(acwa[x-1] != -1){
        wacnt += acwa[x-1];
        acwa[x-1] = -1;
        accnt++;
      }
    }
  }
  
  cout << accnt << ' ' << wacnt << endl;
  
  
}

Measured memory_bytes: 5616
int main(int argc, const char * argv[])
{
    int depth,width,i,j;
    
    while(1){
        scanf("%d %d",&depth,&width);
        
        if(depth==0 && width==0){
            break;
        }
        
        for(i = 0;depth > i;i+=1){
            
            for(j = 0;width > j;j+=1){
                if((i+j)%2==0){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            
            printf("\n");
            
        }
        printf("\n");
    }
    
    return 0;
}

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

using LL = long long;
using LD = long double;
 
LL mod = 10e9+7;

int main()
{
	LL n, m;
	cin >> n >> m;

	vector<LL> a(n);
	LL tot = 0;
	for (auto &e : a) {
		cin >> e;
		tot += e;
	}

	LL cnt = 0;

	for (LL i = 0; i < n; ++i) {
		if (4*m*a[i] >= tot) {
			cnt++;
		}
	}

	if (cnt >= m) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}



}

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

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

using namespace std;
using lint=long long;

inline int popcount(long long x){
	x-=(x>>1)&0x5555555555555555LL;
	x=(x&0x3333333333333333LL)+((x>>2)&0x3333333333333333LL);
	x=(x+(x>>4))&0x0f0f0f0f0f0f0f0fLL;
	x=(x*0x0101010101010101LL)>>56;
	return x;
}

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

weighted_graph<int> T;

pair<bool,lint> dfs(int u,int p,int g){
	if(u==g){
		return {true,0};
	}

	for(auto e:T[u]) if(e.to!=p) {
		auto tmp=dfs(e.to,u,g);
		if(tmp.first){
			return {true,(1LL<<e.wt)|tmp.second};
		}
	}
	return {false,0};
}

int main(){
	int n; scanf("%d",&n);
	T.resize(n);
	rep(i,n-1){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		T[u].emplace_back(v,i);
		T[v].emplace_back(u,i);
	}

	int m; scanf("%d",&m);
	lint E[20];
	rep(i,m){
		int a,b; scanf("%d%d",&a,&b); a--; b--;
		E[i]=dfs(a,-1,b).second;
	}

	lint ans=0;
	rep(S,1<<m){
		lint white=0;
		rep(i,m) if(S>>i&1) white|=E[i];
		int e=popcount(white);
		ans+=(popcount(S)%2==0?1:-1)*(1LL<<(n-1-e));
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



  
int main(){
    double l;
    cin >> l;
    double x = l/3;
    cout.precision(17);
    cout << x*x*x;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	ll n,x,i;
	cin >> x >> n;
	map<ll,ll>mp;
	rep(i,n)
	{
		ll m;
		cin >> m;
		mp[m]++;
	} 
	ll dis=0LL;
	pair<ll,ll>p,q;
	for(i=x; ;i++)
	{
		if(mp.count(i))
		{
			dis++;
		}
		else
		{
			p.first=i;
			//cout << i << " " << dis << endl;
			p.second=dis;
			break;
		}
	}
	dis=0LL;
	for(i=x; ;i--)
	{
		if(mp.count(i))
		{
			dis++;
		}
		else
		{
			//cout << i << " " << dis << endl;
			q.first=i;
			q.second=dis;
			break;
		}
	}
	if(p.second<q.second)
	{
		cout << p.first;
	}
	else if(q.second<p.second)
	{
		cout << q.first;
	}
	else
	{
		cout << min(p.first,q.first);
	}
	return 0;
}


Measured memory_bytes: 3592
n, m, l = gets.split(" ").map(&:to_i)
a = Array.new(n).map { Array.new(m) }
b = Array.new(m).map { Array.new(l) }
c = Array.new(n, 0).map { Array.new(l, 0) }

for i in 0..(n - 1)
  a[i] = gets.split(" ").map(&:to_i)
end

for i in 0..(m - 1)
  b[i] = gets.split(" ").map(&:to_i)
end

for i in 0..(n - 1)
  for j in 0..(l - 1)
    for k in 0..(m - 1)
      c[i][j] += a[i][k] * b[k][j]
    end
  end
end

for i in 0..(n - 1)
  puts c[i].to_s.gsub(/[\[\,\]]/, "")
end

Measured memory_bytes: 6368
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define endl '\n'
#define MAX 100002
#define pii pair<int, int>
#define pll pair<long long, long long>


typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vec;

int main(){
    fast_cin();
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(true){
        if(a<=0 or c<=0)
            break;
        c-=b;
        if(a<=0 or c<=0 )
            break;
        a-=d;

    }
    //cout<<a<<" "<<c;
    if(a>c)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, K = LI()
    S = SI()

    wakareme = []
    current_koufuku = 0
    for i in range(N-1):
        if S[i] != S[i+1]:
            wakareme.append(i)
        else:
            current_koufuku += 1

    if 2*K < len(wakareme):
        print(current_koufuku + 2 * K)  # K 回の操作すべてで幸福を+2できる。
        return
    else:
        print(N-1)  # 末端以外の人すべてを幸福にできる。
        return


main()

Measured memory_bytes: 7116
#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--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  multiset<int> ms;
  REP(i,n){
    auto itr = ms.lower_bound(a[i]);
    if(itr!=ms.begin()) ms.erase(--itr);
    ms.insert(a[i]);
  }
  cout << ms.size() << endl;
  return 0;
}

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

using namespace std;
const int _max = 2e6 + 10;
const int mod = 1e9 + 7;
typedef unsigned long long ll;


int main(){
    int n;
    int one=0,two=0,three=0,four=0;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="AC"){
            one++;
        }
        if(s=="WA"){
            two++;
        }
        if(s=="TLE"){
            three++;
        }
        if(s=="RE"){
            four++;
        }
    }
    printf("AC x %d\n",one);
    printf("WA x %d\n",two);
    printf("TLE x %d\n",three);
    printf("RE x %d",four);
    return 0;
}

Measured memory_bytes: 3720
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        char s[] = sc.next().toCharArray();
        char t[] = sc.next().toCharArray();
        boolean resolve = false;

        int slen = s.length;
        int tlen = t.length;
        for (int i = slen - tlen; i >= 0; i--) {
            if (check(Arrays.copyOfRange(s, i, i + tlen), t)) {
                for (int j = 0; j < tlen; j++) {
                    s[i + j] = t[j];
                }
                resolve = true;
                break;
            }
        }

        System.out.println(resolve ? new String(s).replace('?', 'a') : "UNRESTORABLE");
    }

    private boolean check(char s[], char t[]) {
        for (int i = 0; i < s.length; i++) {
            if (s[i] != '?' && s[i] != t[i]) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            new Main().main(sc);
        } catch (Exception e) {
            throw e;
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int mod = 1e9 + 7;
int ans = 0;
int vis[100005], dis[100005], in[100005];

int32_t main(){
	int n;
	cin>>n;
	double p[n+1];
	double dp[n+1];
	for(int i=1;i<=n;i++){
		cin>>p[i];
		dp[i] = 0;
	}
	dp[0] = 1;
	for(int lim = 1; lim <= n; lim ++){//specifies upto which coin are we considering
		for(int coin = n; coin >=0 ; coin--){//coin number of heads upto lim
			dp[coin] = p[lim] * dp[coin-1] + (1 - p[lim]) * dp[coin];
		}
	}
	double ans = 0;
	for(int h = 0; h <= n; h++){
		int t = n - h;
		if(h>t){
			ans += dp[h];
		}
	}
	cout<<setprecision(10)<<ans;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 1000005
#define pi 3.14159265358979323846

using namespace std;

ll mod = 1e9+7;

ll power(ll n, ll m)
{
    ll ans =1;
    for(ll i=1; i<=n; i++){
        ans*=m;
        ans%=mod;
    }
    return ans;
}


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

      ll ans =power(n,10)-power(n,9)-power(n,9)+power(n,8);
      while(ans<0)ans+=mod;
      cout<<ans<<endl;


}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;

const int inf = numeric_limits<int>::max();


int main(){   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int counter = 0;
    while(a>0 && c>0){
        if(counter%2==0){
            c-=b;
        }
        else{
            a-=d;
        }
        counter++;
    }
    if(a>0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

}

















Measured memory_bytes: 3544
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
#define Maxn 45
int rel[Maxn][Maxn];
ll dp[Maxn][Maxn][Maxn];
char ch[Maxn];

ll dfs(ll l,ll r,ll m){
	if(~dp[l][r][m])return dp[l][r][m];
	if(l==r)return dp[l][r][m]=1;
	if(l==m||r==m)return dp[l][r][m]=0;
	ll res=0;
	for(int i=l;i<m;++i)
	    for(int q=m+1;q<=r;++q){
	    	ll tmp1=0;
	    	for(int p=i;p<m;++p)tmp1+=dfs(l,p,i)*dfs(p+1,q-1,m);
	    	ll tmp2=0;
	    	for(int j=q;j<=r;++j)
			    if(rel[i][j])tmp2+=dfs(q,r,j);
			res+=tmp1*tmp2;
		}
	return dp[l][r][m]=res;
}

int main(){
	scanf("%d",&n);
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=2*n;++i){
		scanf("%s",ch+1);
		for(int j=1;j<=2*n;++j)rel[i][j]=ch[j]-'0';
	}
	ll Ans=0;
	for(int i=2;i<=n*2;++i)
	    if(rel[1][i]){
	    	ll now=dfs(2,2*n,i);
	    	Ans+=now;
	    }
	printf("%lld\n",Ans);
	return 0;
} 

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {
	bool flag = true;
	int a,b;
	string s;

	cin >> a >> b;
	cin >> s;

	if (s.size() != a + b + 1 || a < 1 || b > 5) {
		flag = false;
	}
	else {
		if (s[a] == '-') {
			for (int i = 0;i < a + b + 1;i++) {
				if (i != a) {
					if (s[i] - '0' >= 0 && s[i] - '0' <= 9) {
					}
					else {
						flag = false;
					}
				}
			}
		}
		else {
			flag = false;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  cout << (b-a)*(b-a+1)/2 - b << endl;
  return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    ll C[2][2019];
    memset(C, 0, sizeof(C));
    int f = 0;

    ll ans = 0;
    REP(i, S.size()) {
        f ^= 1;

        int s = S[i] - '0';
        REP(j, 2019) {
            C[f][(j * 10 + s) % 2019] = C[f^1][j];
        }

        C[f][s] += 1;

        ans += C[f][0];
    }

    cout << ans << endl;
    
}


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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    cin>>n;
    vector<int> arr(n);
    double sum = 0;
    for(int i = 0; i < n; i++) {
    	int x;
    	cin>>x;
    	arr[i] = x;
    	sum += x;
    }
    double avg = round(sum / n);
    int ans = 0;
    for(int i : arr) {
    	ans += (i - (int)avg) * (i - (int)avg);
    }
    cout<<ans;

	return 0;		
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int n,ans=0,max=0;
  cin>>n;
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I') {
      ans++;
      if(ans>max) max=ans;
    }else ans--;
  }
  cout<<max<<endl;
  return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string S; cin >> S;
  cout<<700+count(all(S),'o')*100<<endl;
  

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>

#define rep(i,n) for(int (i)=0;i < (n);(i)++)
#define ll long long
#define INF 9223372036854775807

using namespace std;

// input
int n;
int a[1001];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool flag = true;
  cin >> n;
  rep(i,n) {
	int num;
	cin >> num;

	if(num % 2 == 0 && (num % 3 != 0 && num % 5 != 0)) flag = false;
  }
  if(flag) {
	cout << "APPROVED" << endl;
  } else {
	cout << "DENIED" << endl;
  }
}



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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

ll n,a,b;
vector<ll> h;

bool calc(ll m){
  ll c = 0;
  rep(i,n){
    if(h[i] - b * m > 0)
      c += (h[i] - b * m + a - b - 1) / (a - b);
    }
  if(c <= m) return true;
  else return false;
}

int main(){
  cin >> n >> a >> b;
  h.resize(n); rep(i,n) cin >> h[i];

  ll l = 0, r = 1e9 / b, m;

  while(l + 1 < r){
    m = (l + r) / 2;
    if(calc(m)) r = m;
    else l = m;
  }
  
  if(calc(r)) cout << r << endl;
  else cout << r + 1 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define dec(i,j,k) for(int i=j;i>=k;i--)
#define edge(u) for(re int i=head[u];i;i=e[i].nxt)
#define pb push_back
#define mp make_pair
#define In inline
#define fi first
#define se second
#define db double
#define ui unsigned int
#define ull unsigned long long 
using namespace std; 
const int N=205;
inline ll read(){
	ll x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int t,n;
ll a[N],s1[65];
char s[N];
void insert(ll x){
	dec(i,59,0){
		if(x&(1LL<<i)){
			if(!s1[i]){
				s1[i]=x;
				return;
			} 
			else x^=s1[i];
		}
	}
}
bool find(ll x){
	ll res=0;
	dec(i,59,0){
		if((x&(1LL<<i))!=(res&(1LL<<i))) res^=s1[i];
	}
	return res==x;
}
int main(){ 
	t=read();
	while(t--){
		int ans=0;
		memset(s1,0,sizeof(s1));
		n=read();
		inc(i,1,n) a[i]=read();
		scanf("%s",s+1);
		dec(i,n,1){
			if(s[i]=='0') insert(a[i]);
			else if(!find(a[i])) ans=1;
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3760
N=int(input())
from collections import defaultdict,deque
B=[tuple(map(int,input().split())) for i in range(N-1)]
branch=defaultdict(set)
for a,b in B:
    branch[a-1]|={b-1}
    branch[b-1]|={a-1}
C=list(map(int,input().split()))
cnt=[len(branch[i]) for i in range(N)]
M=0
start=-1
for i in range(N):
    if M<len(branch[i]):
        M=len(branch[i])
        start=i
C.sort(reverse=True)
idx=0
ans=[0]*N
check=deque([start])
while len(check)>0:
    now=check.popleft()
    ans[now]=C[idx]
    idx+=1
    nex=[(i,len(branch[i])) for i in branch[now] if ans[i]==0]
    nex.sort(key=lambda x:x[1],reverse=True)
    check+=deque([i[0] for i in nex])
res=0
for a,b in B:
    res+=min(ans[a-1],ans[b-1])
print(res)
print(" ".join(list(map(str,ans))))

Measured memory_bytes: 9508
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  ll A,B,K; cin>>A>>B>>K;

  ll tk=A, ao=B;
  ll k = K;
  
  if (tk<=k) {
    k-=tk;
    tk=0;
  } else {
    tk-=k;
    cout << tk << " " << ao << endl;
    return 0;
  }

  if (ao<=k) {
    k-=ao;
    ao=0;
  } else {
    ao-=k;
    cout << tk << " " << ao << endl;
    return 0;
  }

  cout << tk << " " << ao << endl;

  return 0;
}


Measured memory_bytes: 256
import collections

def is_even(n):
    return n % 2 == 0


def is_odd(n):
    return not is_even(n)


def solve(n, a):
    counter = collections.Counter(a)

    evens = 0
    odds = 0
    for item in counter.items():
        k, v = item
        if is_odd(v):
            odds += 1
        else:
            evens += 1

    if is_even(evens):
        return odds + evens
    else:
        return odds + (evens - 1)


def get_args():
    N = int(input())
    A = list(map(int, input().split()))
    return N, A


if __name__ == '__main__':
    n, a = get_args()
    res = solve(n, a)
    print(res)


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

int main () {

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int direct_x = x2 - x1, direct_y = y2 - y1;

    int vertical_x = -1 * direct_y, vertical_y = direct_x;

    int x3 = x2 + vertical_x, x4 = x1 + vertical_x;
    int y3 = y2 + vertical_y, y4 = y1 + vertical_y;
    
    cout << x3 << " " << y3 <<  " " << x4 <<  " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var a int
	con.Scan(&a)
	con.Println(a + a*a + a*a*a)
	return nil
}


Measured memory_bytes: 1844
#include<iostream>
#include<bits/stdc++.h>
#include<map>
#include<iterator>
#include<string>
#include<string.h>
#include<math.h>
#include<vector>
#define ll long long int
#define mod 1000000007
using namespace std;

vector<int> fun(vector<int>&vec)
{
    vec.push_back(90);
    return vec;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int n,p=0,t;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    for(int i=0; i<n; i++)
    {
        t =i;
        for(int j=t+1; j<n; j++)
        {
            p=p+(arr[i]*arr[j]);
        }
    }
    cout<<p<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int x;
    cin >> x;
    int ans;
    while(true) {
        ans = 0;
        rrep(i, x) {
            if(x % i == 0) {
                ans++;
            }
            if(ans > 2) break;
        }
        if(ans == 2) {
            cout << x << endl;
            return 0;
        }
        x++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int A, B, C;
  cin>>A>>B>>C;
  vector<int> number={A, B, C};
  sort(number.begin(), number.end());
  int X=number[2]-number[0]; //最大値、最小値分引く
  int Y=number[1]-number[0]; //2番目
  int Z=0;
  int count=X-Y;
  if(Y%2==1){
      Y++;
      count++;
    }
  count=count+Y/2;
  cout<<count<<endl;
}

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

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	ll x;
	in x;
	out x* x* x en;
}



Measured memory_bytes: 3084
N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
rank = [0] * N
parent = [i for i in range(N)]


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

num = 0
for i in range(N):
    num += same(i, P[i])

print(num)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
 
#define MAXN 200010
using namespace std;
int sub[MAXN];
int N;
int main()
{
	cin>>N;
    for(int i = 1; i <= N; ++i)
    	sub[i] = 0;
    for(int i =2; i <= N; ++i)
    {
    	int tmp;
        cin>>tmp;
        sub[tmp]++;
    }
    for(int i = 1; i <= N; ++i)
    	cout<<sub[i]<<endl;
    return 0;
 
}

Measured memory_bytes: 4360
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();

    if n >= 1000 {
        println!("ABD")
    } else {
        println!("ABC")
    }
}


Measured memory_bytes: 4352
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int x, y;
	int a[] = { -1,0,2,0,1,0,1,0,0,1,0,1,0 };
	std::cin >> x >> y;
	if (a[x] == a[y]) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256