akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(list:[i64]));
    let (min, max) = {
        let mut list2 = list.clone();
        list2.sort();
        let len = list2.len();
        (list2[len / 2 - 1], list2[len / 2])
    };
    list.into_iter()
        .map(|x| (if x <= min { max } else { min }).to_string())
        .collect::<Vec<_>>()
        .join("\n")
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "4\n2 4 4 3" => "4\n3\n3\n4",
    test2: "2\n1 2" => "2\n1",
    test3: "6\n5 5 4 4 3 3" => "4\n4\n4\n4\n4\n4",
}


Measured memory_bytes: 19696
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
signed main(){
  string s;
  int k;
  cin>>k>>s;
  if(s.size()<=k)cout<<s<<endl;
  else{
    rep(i,k){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;
  }
}

Measured memory_bytes: 3608
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut s = vec![0i64; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + a[i];
    }

    let mut ans = 1i64 << 60;

    let mut p = 1;
    let mut r = 3;
    for q in 2..n - 1 {
        let mut P = s[p];
        let mut Q = s[q] - s[p];
        let mut R = s[r] - s[q];
        let mut S = s[n] - s[r];
        while p + 1 < q && (s[q] - s[p + 1] - s[p + 1]).abs() <= (Q - P).abs() {
            p += 1;
            P = s[p];
            Q = s[q] - s[p];
        }
        while r + 1 < n && (s[n] - s[r + 1] - s[r + 1] + s[q]).abs() <= (S - R).abs() {
            r += 1;
            R = s[r] - s[q];
            S = s[n] - s[r];
        }
        ans = min(ans, max(max(max(P, Q), R), S) - min(min(min(P, Q), R), S));
    }
    println!("{}", ans);
}


Measured memory_bytes: 6624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n, w;
	cin >> n >> w;
	struct ITEM {
		int v, w;
	} item[1001];
	for (int i = 1; i <= n; i++)
		cin >> item[i].v >> item[i].w;
	int dp[100 + 1][10000 + 1];
	fill_n(dp[0], 10000 + 1, 0);
	for (int i = 0; i <= n; i++)
		dp[i][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			if (item[i].w <= j) {
				dp[i][j] = max(dp[i-1][j], item[i].v + dp[i-1][j-item[i].w]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 5112
n=int(input())

ans_list=[]
a_max=int(n**(1/2))+1
for a in range(1,a_max):
    if n%a==0:
        
        b=n//a
        num_a=len(list(str(a)))
        num_b=len(list(str(b)))
        
        ans_list.append(max(num_a,num_b))
    
print(min(ans_list))
    


Measured memory_bytes: 9452
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;

int N, M;
/*
struct Edge {
    int to, cost;
};
vector<Edge> G[100001];
*/
int cnt[100001];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
        /*
        for(int j = 0; j <= G[a].size(); ++j){
            if(j == G[a].size()){
                G[a].push_back((Edge){b, 1});
            }
            else if(G[a][j].to == b){
                G[a][j].cost ++;
                break;
            }
        }
        for(int j = 0; j <= G[b].size(); ++j){
            if(j == G[b].size()){
                G[b].push_back((Edge){a, 1});
            }
            else if(G[b][j].to == a){
                G[b][j].cost ++;
                break;
            }
        }*/
    }
    bool check = true;
    for(int i = 1; i <= M; ++i){
        if(cnt[i] % 2 != 0){
            check = false;
        }
    }
    cout << (check ? "YES" : "NO") << endl;

    return 0;
}

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

int check(long P, vector<int> &W, int k) {
    int i = 0;  // 運べる荷物数
    for (int j = 0; j < k; j++) {  // j: トラック数
        long s = 0;
        while (s + W.at(i) <= P) {
            s += W.at(i);
            i++;
            if (i == W.size())
                return i;
        }
    }
    return i;
}

int solve(vector<int> &W, int k) {
    long left = 0;
    long right = 100000 * 10000; // max(n) * max(w) : 必ず1台にすべて積める
    long mid;

    while (left < right) {
        mid = (left + right) / 2;

        int v = check(mid, W, k); // 何個つめる？

        if (W.size() <= v) {
            right = mid;
        }
        else {
            left = mid + 1;
        }
    }
    return right;
}

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> W;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        W.push_back(tmp);
    }

    long ans = solve(W, k);
    cout << ans << endl;
}


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

KUKAN = [0] * N

for i in range(N):
    if i != N - 1:
        KUKAN[i] = A[i + 1] - A[i]
    else:
        KUKAN[N - 1] = K - A[N - 1] + A[0]

print(str(sum(KUKAN) - max(KUKAN)))

Measured memory_bytes: 26420
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: Chars,
    }

    //tabで移動
    if n[0] == '7' || n[1] == '7' || n[2] == '7' {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2108
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        a: usize,
        b: usize,
        h: usize,
        m: usize,
    };
    let tpi = std::f64::consts::PI * 2.0;
    let a_theta: f64 = h as f64 * (tpi / 12.0) + m as f64 * (tpi / 12.0 / 60.0);
    let b_theta: f64 = m as f64 * (tpi / 60.0);
    let mut theta: f64 = (a_theta - b_theta).abs();
    if theta > std::f64::consts::PI {
        theta = tpi - theta;
    }

    let ans: f64 = ((a.pow(2) + b.pow(2)) as f64 - 2.0 * (a * b) as f64 * theta.cos()).sqrt();

    println!("{}", ans);
}


Measured memory_bytes: 2888
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;

int main(int argc, const char * argv[]) {
  long long n, m;
  cin >> n >> m;
  long long time = (n-m) * 100 + m * 1900;
  long long ans = time*pow(2,m);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const int N = 3;
    vector<vector<int>> v(N,vector<int>(N));
    vector<int> a(N), b(N,1000);
    REP(i,N) REP(j,N) cin >> v[i][j];
    REP(i,N) {
        a[i] = *min_element(ALL(v[i]));
        REP(j,N) v[i][j] -= a[i];
    }
    REP(i,N) {
        REP(j,N) b[i] = min(b[i],v[j][i]);
        REP(j,N) v[j][i] -= b[i];
    }

    bool ans = true;
    REP(i,N) REP(j,N) if (v[i][j] != 0) {
        ans = false; break;
    }

    ATYN(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
const int inf = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    while(1){
        int w,h;
        cin >> w >> h;
        if(w==0) break;

        vector<vector<char> > field(h+2, vector<char>(w+2, 'x'));
        vector<pair<int,int> > coord(11);
        int n=1;
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                cin >> field[i][j];
                if(field[i][j]=='o'){
                    field[i][j] = 'A';
                    coord[0] = make_pair(i,j);
                }
                if(field[i][j]=='*'){
                    field[i][j] = 'A'+n;
                    coord[n] = make_pair(i,j);
                    n++;
                }
            }
        }

        vector<vector<int> > adj(n, vector<int>(n, inf));
        for(int i=0; i<n; i++){
            queue<pair<int, pair<int,int> > > wait;
            vector<vector<bool> > used(h+2, vector<bool>(w+2, false));
            wait.push(make_pair(0, coord[i]));
            used[coord[i].first][coord[i].second] = true;
            adj[i][i] = 0;
            while(!wait.empty()){
                int y = wait.front().second.first;
                int x = wait.front().second.second;
                int step = wait.front().first;
                wait.pop();
                for(int d=0; d<4; d++){
                    int ny = y+dy[d];
                    int nx = x+dx[d];
                    if(field[ny][nx]!='x' && !used[ny][nx]){
                        used[ny][nx] = true;
                        wait.push(make_pair(step+1, make_pair(ny, nx)));
                        if(field[ny][nx]!='.'){
                            adj[i][field[ny][nx]-'A'] = adj[field[ny][nx]-'A'][i] = step+1;
                        }
                    }
                }
            }
        }

        bool fail = false;
        for(int i=0; i<n; i++){
            if(adj[0][i]==inf){
                fail = true;
                break;
            }
        }
        if(fail){
            cout << -1 << endl;
            continue;
        }
            
        for(int k=0; k<n; k++){
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
                }
            }
        }

        int ans = inf;
        vector<int> perm(n);
        for(int i=0; i<n; i++) perm[i]=i;
        do{
            int subans = 0;
            for(int i=0; i<n-1; i++){
                subans += adj[perm[i]][perm[i+1]];
            }
            ans = min(ans, subans);
        }while(next_permutation(perm.begin()+1, perm.end()));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3012
from operator import itemgetter 
def hms2s (t):
	l = t.split(":")
	return sum([0 if l[i] == "" else int(l[i]) * (60**(2-i)) for i in range(3)])
while 1:
	n = int(raw_input())
	if n == 0:
		break
	time_table = []
	for i in range(n):
		t = raw_input().split(" ")
		time_table.append([hms2s(t[0]),1])
		time_table.append([hms2s(t[1]),0])
	time_table.sort(key=itemgetter(0,1))
	max_num = 0
	move_num = 0
	for t in time_table:
		if t[1]:
			move_num += 1
			max_num = max(max_num, move_num)
		else:
			move_num -= 1
	print max_num

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int n;cin>>n;
  i_i ab[n+10];
  int a,b;
  REP(i,n) {
    cin>>a>>b;
    ab[i] = make_pair(b,a);
  }
  sort(ab,ab+n);

  ll time=0;
  REP(i,n) {
    time+=ab[i].second;
    // pr(ab[i].second,ab[i].first,time);
    if(time > ab[i].first) {
      pr("No");
      return 0;
    }
  }
  pr("Yes");
  return 0;
}


Measured memory_bytes: 1792
import math
a,b,h,m = map(int, input().split())
w = abs((30*h+0.5*m - 6*m))
if w > 180:
  w = 360 - w
A = a
B = b
A *= a
B *= b
l = round(A + B - 2*a*b*math.cos(math.radians(w)),11)
print(l**0.5)

Measured memory_bytes: 9488
a,b = map(int, input().split())
count=0
num_list = list(map(int, input().split()))
max=[0]*a
flag=[0]*a

for i in range(b):
    c,d = map(int, input().split())
    if num_list[c-1]<num_list[d-1]:
        max[d-1]=num_list[d-1]
        max[c-1]=0
        flag[c-1]+=1
    elif num_list[c-1]>num_list[d-1]:
        max[c-1]=num_list[c-1]
        max[d-1]=0
        flag[d-1]+=1
    elif num_list[c-1]==num_list[d-1]:
        flag[c-1]+=1
        flag[d-1]+=1
    #print(max)
    #print(flag)
for i in range(a):
    #if max[i]==num_list[i]:
    #    count+=1
    if flag[i]==0:
        count+=1
print(count)

Measured memory_bytes: 20160
#include <iostream>
using namespace std;
int main()
{
  int n, m;
  cin >> n >> m;

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

  int c[m], d[m];
  for (int ci = 0; ci < m; ci++) {
    cin >> c[ci] >> d[ci];
  }

  for (int si = 0; si < n; si++) {
    int min = 1e9, min_index;
    for (int ci = 0; ci < m; ci++) {
      int distance = abs(a[si]-c[ci]) + abs(b[si]-d[ci]);
      if (distance < min) {
	min = distance;
	min_index = ci + 1;
      }
    }
    cout << min_index << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
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; }

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> G(N);
  REP(i, M) {
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  bool flag = false;
  REP(i, G[0].size()) {
    REP(j, G[G[0][i]].size()) {
      if (G[G[0][i]][j] == N - 1) flag = true;
    }
  }
  if (flag) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  
  return 0;
}

Measured memory_bytes: 12016
#include<bits/stdc++.h>
#define MAXN 200005
#define LL long long
using namespace std;

int N;
int M0 = 2e9, M1 = -1;
int A0,A1,B0,B1,id0,id1;
int t0,t1;

struct Node{
	int x,y;
	Node(int x=0, int y=0):x(x), y(y){}
	
	bool operator < (const Node& n1) const{
		return x < n1.x;
	}
} n[MAXN];

LL solve0(){
	if(id0==id1) return 1e18;
	A0 = M0;
	A1 = M1;
	
	int py0[MAXN], py1[MAXN], fy0[MAXN], fy1[MAXN];
	py0[0] = fy0[N+1] = 1e9;
	py1[0] = fy1[N+1] = 0;
	int x,y;
	for(int i=1;i<=N;i++){
		x = n[i].x; y = n[i].y;
		py0[i] = min(py0[i-1], y);
		py1[i] = max(py1[i-1], y);
	}
	for(int i=N;i>=1;i--){
		x = n[i].x; y = n[i].y;
		fy0[i] = min(fy0[i+1], y);
		fy1[i] = max(fy1[i+1], y);
	}
	
	int ans = 1e9;
	for(int i=1;i<N;i++){
		ans = min(ans, max(n[N].x, py1[i]) - min(n[i+1].x, py0[i]));
	}	
	
	return (LL)ans*(A1-A0);
}

LL solve1(){
	A1 = M1;
	B0 = M0;
	A0 = t0;
	B1 = t1;

	int x,y;
	for(int i=1;i<=N;i++){
		if(i==id0 || i==id1) continue;
		x = n[i].x; y = n[i].y;
		
		B1 = max(B1, min(x, y));
		A0 = min(A0, max(x, y));
	}
	return (LL)(A1-A0)*(B1-B0);
}

int main(){
	ios::sync_with_stdio(0);
	
	cin>>N;
	
	int x,y;
	for(int i=1;i<=N;i++){
		cin>>x>>y;
		n[i].x = min(x, y);
		n[i].y = max(x, y);
	}
	sort(n+1, n+1+N);
	
	
	for(int i=1;i<=N;i++){
		x = n[i].x; y = n[i].y;
		
		if(M0 > min(x, y)){
			id0 = i;
			M0 = min(x, y);
		}
		if(M1 < max(x, y)){
			id1 = i;
			M1 = max(x, y);
		}
	}
	
	if(n[id0].x == M0) t0 = n[id0].y;
	else t0 = n[id0].x;
	if(n[id1].x == M1) t1 = n[id1].y;
	else t1 = n[id1].x;
	//cout<<t0<<" "<<t1<<endl;
	cout<<min(solve0(), solve1())<<endl;
	return 0;
}

/*
2
1 2
3 4
*/

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    map<ll,ll> mp;
    rep(i,n){
        cin >> a[i];
        if(mp.find(a[i])!=mp.end()) mp[a[i]]++;
        else mp[a[i]]=1;
    }
    ll ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans+=(itr->second)*(itr->second-1)/2;
    }
    rep(i,n){
        ll ans1=ans;
        ans1-=mp[a[i]]*(mp[a[i]]-1)/2;
        ans1+=(mp[a[i]]-1)*(mp[a[i]]-2)/2;
        cout << ans1 << endl;
    }
}



Measured memory_bytes: 12160
#!/usr/bin/env python3
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
cnt = Counter(a)
s = sum(a)
for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)


Measured memory_bytes: 24012
#include<iostream>
using namespace std;
int main(){
    int x=1;
    int i=1;
    
    for (i=1;x!=0;i++){
       
         cin >>x;
        if (x==0)  break;
        cout << "Case"<<" "<<i<<":"<<" "<<x<<endl;
        
    }
    return 0;
}


Measured memory_bytes: 3004
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt(), b = sc.nextInt(), ret = 0;
			if(a == 0) break;
			for(int i = 1; i < a; i++) {
				if(i == 2) ret += 29;
				else if(i == 4 || i == 6 || i == 9 || i == 11) ret += 30;
				else ret += 31;
			}
			ret = (ret + b) % 7;
			if(ret == 0) System.out.println("Wednesday");
			if(ret == 1) System.out.println("Thursday");
			if(ret == 2) System.out.println("Friday");
			if(ret == 3) System.out.println("Saturday");
			if(ret == 4) System.out.println("Sunday");
			if(ret == 5) System.out.println("Monday");
			if(ret == 6) System.out.println("Tuesday");
		}
	}
}

Measured memory_bytes: 25944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i,a,b;
    int n;
    long long int r,d,x;
    string s;
    int u, v, w;
    cin >>r>>d>>x;
    long long int ans=0;
    ans=x;
    for (i=0;i<10;i++){
        ans=ans*r-d;
        std::cout << ans << std::endl;
  }
 //   for (i=0;i<n;i++){
  //      std::cin >> u>>v>>w;
//        if (w%2==0)ans[v-1]=ans[u-1];
 //       else if(ans[u-1]==0)ans[v-1]=1;
  //      else ans[v-1]=0;
//    }
 //   for(i=0;i<n;i++)
// if (a>=13) ans=b;
// else if(a>5)ans=b/2;
    //std::cout << ans << std::endl;
   
}


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

int main() {
  int s1, s2, s3, a;
  cin >> a;
  s1 = a/100;
  s2 = (a-s1*100)/10;
  s3 = a-s1*100-s2*10;
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
char grid[MAXN][MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif
    int A, B, W, H;
    cin>>H>>W>>A>>B;

    for(int i = 0; i < B; i++){
        for(int j = 0; j < A; j++){
            grid[i][j] = '0';
        }
        for(int j = A; j < W; j++){
            grid[i][j] = '1';
        }
    }
    for(int i = B; i < H; i++){
        for(int j = 0; j < A; j++){
            grid[i][j] = '1';
        }
        for(int j = A; j < W; j++){
            grid[i][j] = '0';
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout<<grid[i][j];
        }
        cout<<endl;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<queue>
#include <string.h>
#include <algorithm>

using namespace std;

int main(){
  int H,A;
  cin>>H>>A;
  int cnt=0;
  while(H>0){
    cnt++;
    H-=A;
  }
  cout<<cnt<<"\n";
}

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


int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> point(n+1);
    rep(i,q) {
        int a;
        cin >> a;
        point[a]++;
    }

    for(int i = 1; i <= n; i++) {
        if (k - q + point[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3764
def main():
    import itertools
    N, M, X = map(int, input().split())
    #c_list = []
    #a_list = []
    dict = {}
    c_dict = {}
    a_dict = {}
    count = 0
    count_list = []
    for i in range(1,N+1) :
        count = count + 1
        count_list.append(count)
        A_list = [A for A in input().split()]
        A_list = list(map(int, A_list))
        #c_list.append(A_list[0])
        #a_list.append(A_list[1:])
        dict[A_list[0]] = A_list[1:]
        c_dict[count] = A_list[0]
        a_dict[count] = A_list[1:]

    comb_lists = []
    for i in range(1, len(count_list)+1) :
        for comb_list in itertools.combinations(count_list, i) :
            comb_lists.append(list(comb_list))
    #print("comb_lists = %s" % comb_lists)
    result = -1
    for key_list in comb_lists :
        ans = 0
        t = [0] * M
        #print("key_list = %s" % key_list)
        for key in key_list :
            ans = ans + c_dict[key]
            #print("dict = %s" % c_dict[key])
            for j in range(M) :
                t[j] = t[j] + a_dict[key][j]
        #print("t = %s" % t)
        if all(x >= X for x in t) :
            if result == -1 :
                result = ans
            else :
                result = min(result, ans)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int N;  cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    rep(i, N) cin >> S[i] >> P[i];

    set<string> st;
    vector<pair<int, int>> P_;
    rep(i, N) {
        st.insert(S[i]);
        P_.push_back(make_pair(P[i], i));
    }
    sort(all(P_));
    reverse(all(P_));

        for (auto itr = st.begin(); itr != st.end(); itr++) {
            rep(j, P_.size()) {
                rep(i, N) {
                if (S[i] == *itr && P[i] == P_[j].first) {
                    print(P_[j].second+1);
                }
                }
            }
        }
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    main(chunk.trim());
});

function main(chunk){
    var lines = chunk.split("\n");
    for(var n=0;n<lines.length-1;){
        var H = Number(lines[n].split(" ")[0]);
        var W = Number(lines[n].split(" ")[1]);
        var map = [];
        n++;
        for(var i=0;i<H;i++){
            map[i] = lines[n].split("");
            n++;
        }
        console.log(calc(map,0,0));
    }
}
function calc(map,h,w){
    if(map[h][w] == "."){
        return w + " "+ h;
    }
    if(map[h][w] == "1"){
        return "LOOP";
    }
    switch(map[h][w]){
    case '>':
        map[h][w] = "1";
        return calc(map,h,w+1);
    case '<':
        map[h][w] = "1";
        return calc(map,h,w-1);
    case 'v':
        map[h][w] = "1";
        return calc(map,h+1,w);
    case '^':
        map[h][w] = "1";
        return calc(map,h-1,w);
    }
}

Measured memory_bytes: 17036
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

unsigned euclidean_gcd(unsigned a, unsigned b) {
	while(1) {
		if(a<b) swap(a,b);
		if(!b) break;
		a%=b;
	}
	return a;
}

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

	int N;
	int i,j,k;
	int tmp;
	ll answer=0;
	ll counter=0;
	vector<int> given;

	cin >> N;

	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			for(k=1;k<=N;k++){
				answer+=euclidean_gcd(euclidean_gcd(i,j),k);
				//cout << answer << endl;
			}
		}
	}

	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




int fac[310000];

int inv(int x){
  if(x==1) return 1;
  return (M-M/x)*inv(M%x)%M;
}


int comb(int n,int k){
  int x=(fac[k]*fac[n-k])%M;
  return (fac[n]*inv(x))%M;
}

int fac_init(int n){
  fac[0]=1;
  FOR(i,1,n+1){
    fac[i]=fac[i-1]*i;
    fac[i]%=M;
  }
}


ll power(ll x,ll k){
  ll ret=1;
  while(k>0){
    if(k&1) (ret*=x) %= M;
    (x*=x) %= M;
    k >>= 1;
  }
  return ret;
}


int n,a,b,c;
int ans1,ans2=1;

main(){
  cin>>n>>a>>b>>c;
  fac_init(2*n);

  FOR(m,n,2*n){
    int aa=a*power(a+b,M-2);
    int bb=b*power(a+b,M-2);
    aa%=M;
    bb%=M;
    int res=comb(m-1,n-1)*m;
    res%=M;
    int res1=(power(aa,n)*power(bb,m-n))%M;
    res1+=(power(bb,n)*power(aa,m-n))%M;
    res1%=M;
    res*=res1;
    res%=M;
    res*=100;
    res%=M;
    res*=power(100-c,M-2);
    res%=M;
    ans1+=res;
    ans1%=M;
    //cout<<ans1<<endl;
  }


  cout<<ans1<<endl;

}


Measured memory_bytes: 1792
/*input
6
4
7
9
0
0
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_.pop();
    return_
}

fn main() {
    let mut x: f64;
    let mut h: f64;
    loop {
        x = read_line().parse().unwrap();
        h = read_line().parse().unwrap();
        if x == 0f64 && h == 0f64 {
            break;
        } else {
            println!(
                "{:.6}",
                x * x + 2.0 * x * (h * h + (x / 2.0) * (x / 2.0)).sqrt()
            );
        }
    }
}

//184.192455



Measured memory_bytes: 5056
l=[]
ind=["a","b","c"]
for i in range(3):
  l.append([i for i in input()])
next=l[0][0]
now=0  
while True:
  if not l[now]:
    print(ind[now].upper())
    break
  next=l[now][0]
  l[now].pop(0)
  now=ind.index(next)  

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

ll bpow(ll x, ll p, ll mod) {
	if (p == 0)
		return 1;
	if (p % 2)
		return (bpow(x, p - 1, mod) * x) % mod;
	else {
		ll b = bpow(x, p / 2, mod);
		return (b * b) % mod;
	}
}

ll pop_cnt(ll a) {
	ll res = 0;
	while (a) {
		if ((a & 1) == 1)
			res++;
		a >>= 1;
	}
	return res;
}

ll triv(ll a) {
	ll res = 0;
	while (a) {
		a = a % pop_cnt(a);
		res++;
	}
	return res;
}

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int cnt1 = 0;
	for (int i = 0; i < n; i++)
		if (s[i] == '1')
			cnt1++;

	if (cnt1 <= 1) {
		ll res2 = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '1') {
				res2 += bpow(2, (n - i - 1), cnt1 + 1);
				res2 %= (cnt1 + 1);
			}
		}
		for (int i = 0; i < n; i++) {
			ll add, cur, ans = 1;
			if (s[i] == '1') {
				ans = 0;
			}
			else {
				add = bpow(2, (n - i - 1), cnt1 + 1);
				cur = (res2 + add + cnt1 + 1) % (cnt1 + 1);
				ans += triv(cur);
			}
			cout << ans << '\n';
		}
	}
	else {
		ll res1 = 0, res2 = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '1') {
				res1 += bpow(2, (n - i - 1), cnt1 - 1);
				res2 += bpow(2, (n - i - 1), cnt1 + 1);
				res1 %= (cnt1 - 1);
				res2 %= (cnt1 + 1);
			}
		}
		for (int i = 0; i < n; i++) {
			ll add, cur, ans = 1;
			if (s[i] == '1') {
				add = bpow(2, (n - i - 1), cnt1 - 1);
				cur = (res1 - add + cnt1 - 1) % (cnt1 - 1);
			}
			else {
				add = bpow(2, (n - i - 1), cnt1 + 1);
				cur = (res2 + add + cnt1 + 1) % (cnt1 + 1);
			}
			ans += triv(cur);
			cout << ans << '\n';
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3780
#include <stdio.h>
#include <string.h>

int main(){
	int a = 0;
	int i;
	char moji[3];
	int b = 1;
	char m = '0' + b;
	if(scanf("%s",moji)==1){
		for(i=0;i < sizeof(moji);i++){
			if(moji[i] == m)a++;
		}
	}
	printf("%d",a);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n)cin >> a[i];
    b = a;
    if(prev_permutation(all(b)))
        rep(i,n)cout << b[i] << ((i < n-1)?" ":"\n");
    rep(i,n)cout << a[i] << ((i < n-1)?" ":"\n");
    if(next_permutation(all(a)))
        rep(i,n)cout << a[i] << ((i < n-1)?" ":"\n");
    
    return 0;
}


Measured memory_bytes: 3164
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	dp := make([]mint, n+1)
	dp[0] = 1
	ll := make([]int, k)
	rr := make([]int, k)
	for i := 0; i < k; i++ {
		ll[i] = getNextInt(scanner)
		rr[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < k; j++ {
			if i+ll[j] < n+1 {
				dp[i+ll[j]].AddAs(dp[i])
			}
			if i+rr[j]+1 < n+1 {
				dp[i+rr[j]+1].SubAs(dp[i])
			}
		}
		if i > 0 {
			dp[i+1].AddAs(dp[i])
		}
	}
	fmt.Fprintln(writer, dp[n-1])
}

type mint int64

func (mt mint) Mod() mint {
	m := mint(998244353)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) Inv() mint {
	return mt.Pow(mint(0).Sub(2))
}
func (mt mint) Pow(n mint) mint {
	p := mint(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(mt)
		}
		mt.MulAs(mt)
		n >>= 1
	}
	return p
}
func (mt mint) Add(x mint) mint {
	return (mt + x).Mod()
}
func (mt mint) Sub(x mint) mint {
	return (mt - x).Mod()
}
func (mt mint) Mul(x mint) mint {
	return (mt * x).Mod()
}
func (mt mint) Div(x mint) mint {
	return mt.Mul(x.Inv())
}
func (mt *mint) AddAs(x mint) *mint {
	*mt = mt.Add(x)
	return mt
}
func (mt *mint) SubAs(x mint) *mint {
	*mt = mt.Sub(x)
	return mt
}
func (mt *mint) MulAs(x mint) *mint {
	*mt = mt.Mul(x)
	return mt
}
func (mt *mint) DivAs(x mint) *mint {
	*mt = mt.Div(x)
	return mt
}


Measured memory_bytes: 3468
import sys

PRIMES=[]
SIEVES=[]
def sieve(max_number):
    numbers = range(1, max_number + 2, 2)
    mroot = int(max_number ** 0.5)+1
    half = len(numbers)
    numbers[0]=0
    for i in range(0, half):
        x = numbers[i]
        if x > mroot: break
        if x and i + x < half:
            numbers[i + x: half: x]=[0] * ((half - 1 - i - x) / x + 1)
    return numbers
def prime(n):
    global SIEVES
    if SIEVES==[]: SIEVES=sieve(n)
    primes =[2] + filter(None, SIEVES[:n/2])
    return primes
PRIMES=prime(105000)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print sum(PRIMES[:n])

Measured memory_bytes: 8264
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        System.out.println(solve(H, N, A, B));
    }

    private static int solve(int H, int N, int[] A, int[] B) {
        int dp[] = new int[H+1];

        dp[0] = 0;
        dp[1] = B[0];
        for (int j=2; j<=H; j++) {
            if (j <= A[0]) {
                dp[j] = B[0];
            } else {
                dp[j] = B[0] * (j/A[0]);
                dp[j] += j%A[0] == 0 ? 0 : B[0];
            }
        }

        for (int i=1; i<N; i++) {
            for (int j = 1; j <= H; j++) {
                if (j < A[i]) {
                    dp[j] = Math.min(dp[j], B[i]);
                } else {
                    dp[j] = Math.min(dp[j], dp[j - A[i]] + B[i]);
                }
            }
        }

        return dp[H];
    }
}

Measured memory_bytes: 27496
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  int ans = n;
  rep(i, n-1) {
    if (s[i] != s[i+1]) chmin(ans, max(i+1, n-i-1));
  }

  cout << ans << endl;
  return 0;
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

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

int main() {
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	long long s;
	cin >> s;
	const int inf = 1e9;
	cout << "0 0 " << inf << " " << 1 << " " << (s + inf - 1) / inf * inf - s << " " << (s + inf - 1) / inf << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d){
        cout << "Yes" << endl;
        return 0;
    }else if(abs(a-b)<=d&&abs(b-c)<=d){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

void solve() {
    int N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    string S;
    cin >> S;
    
    vector<lint> base;
    for (int i = N - 1; i >= 0; --i) {
        lint x = A[i];
        for (auto b : base) {
            x = min(x, x ^ b);
        }
        if (x) {
            if (S[i] == '0') {
                base.push_back(x);
                sort(base.rbegin(), base.rend());
            } else {
                cout << 1 << "\n";
                return;
            }
        }
    }
    cout << 0 << "\n";
}

int main() {
    int T;
    cin >> T;
    rep(i, T) solve();
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>

int gcd(int max, int min) {
  if (max % min) {
    return gcd(min, max % min);

  } else {
    return min;
  }
}

int main() {
  int x, y;

  scanf("%d %d", &x, &y);
  if (x >= y) {
    printf("%d\n", gcd(x, y));

  } else {
    printf("%d\n", gcd(y, x));
  }

  return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define INF 1ll << 60
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, ll>> WGraph;
#define int ll
vector<int> dijkstra(int v, WGraph &g, int r)
{
    vector<int> cost(v, INF);
    cost[r] = 0;
    priority_queue<pair<int, int>> pq;

    pq.push({0, r});

    while (!pq.empty())
    {
        //cerr << "-------------------------------" << endl;
        auto t = pq.top();
        pq.pop();
        //cerr << t.second << "," << t.first << endl;
        if (cost[t.second] < -t.first)
        {
            continue;
        }
        for (auto x : g[t.second])
        {
            if (cost[x.first] > cost[t.second] + g[t.second][x.first])
            {
                cost[x.first] = cost[t.second] + g[t.second][x.first];
                //cerr << "update cost[" << x.first << "] with " << cost[x.first] << endl;
                pq.push({-cost[x.first], x.first});
            }
        }
    }
    return cost;
}

signed main()
{
    int n, m;
    cin >> n >> m;
    int l[m], r[m], c[m];
    rep(i, m)
    {
        cin >> l[i] >> r[i] >> c[i];
        l[i]--;
        r[i]--;
    }
    WGraph g;

    vector<int> p;
    map<int, bool> mp;
    rep(i, m)
    {
        if (g[l[i]][r[i]] == 0)
        {
            g[l[i]][r[i]] = INF;
            g[r[i]][l[i]] = INF;
        }
        g[l[i]][r[i]] = min(c[i], g[l[i]][r[i]]);
        g[r[i]][l[i]] = min(c[i], g[r[i]][l[i]]);
        if (mp[l[i]] == false)
        {
            p.push_back(l[i]);
            mp[l[i]] = true;
        }
        if (mp[r[i]] == false)
        {
            p.push_back(r[i]);
            mp[r[i]] = true;
        }
    }
    sort(ALL(p));
    rep(i, 1, m)
    {
        g[i][i - 1] = 0;
    }
    auto cost = dijkstra(n, g, 0);
    if (cost[n - 1] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << cost[n - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 38260
let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f
let n = read int
let as' = reads int
let bs' = reads int
let cs' = reads int

let mutable acc = 0
for i = 0 to (n-1) do
    acc <- acc + bs'.[as'.[i]-1]
    if i <> (n-1) && as'.[i+1]-as'.[i] = 1 then
        acc <- acc + cs'.[as'.[i]-1]
printfn "%d" acc

Measured memory_bytes: 14044
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	ll k; cin >> k;
	vector<vector<ll>> dp(11, vector<ll>(10));
	rip(i,10,0) dp[0][i] = 1;
	rip(i,10,0){
		rip(j,10,0){
			dp[i+1][j] = dp[i][j];
			if(j != 0) dp[i+1][j] += dp[i][j-1];
			if(j != 9) dp[i+1][j] += dp[i][j+1];
		}
	}
	ll ans = 0;
	ll id = 0, now = k;
	bool ju= false;
	rip(i,11,0){
		rip(j,10,1){
			if(now > dp[i][j]){
				now-=dp[i][j];
			}
			else{
				ans = j;
				id = i;
				ju = true;
				break;
			}
		}
		if(ju) break;
	}
	// cout << ans << endl;
	// vdeb(dp);
	while(id){
		id--;
		int d = ans%10;
		// cout << d << endl;
		if(ans%10 > 0){
			if(now <= dp[id][d-1]){
				ans = 10*ans + d-1;
			}
			else if(now <= dp[id][d-1] + dp[id][d]){
				now -= dp[id][d-1];
				ans = 10*ans + d;
			}
			else{
				now -= dp[id][d-1] + dp[id][d];
				ans = 10*ans + d + 1;
			}
		}
		else{
			if(now <= dp[id][d]){
				ans = 10*ans + d;
			}
			else{
				now -= dp[id][d];
				ans = 10*ans + d+1;
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;


int main(){
	long long N,K;
	scanf("%lld %lld",&N,&K);

	if(2*N < K){
        printf("0\n");
	}
	else{
        if(K % 2 == 1){
            printf("%lld\n",(long long)pow((N/K),3));
        }
        else{
        printf("%lld\n",(long long)pow((N/K),3) + (long long)pow((N-K/2)/K + 1,3));
        }
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    map<string,int> ma;
    for(int i = 0;i < N;i++) {
        string S;
        cin >> S;
        ma[S]++;
    }
    int ret = 0;
    for(auto x:ma) {
        ret = max(ret,x.second);
    }
    for(auto x:ma) {
        if(x.second == ret){
            cout << x.first << endl;
        }
    }
}

Measured memory_bytes: 25216