akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
long long max(long long a ,long long b){
  if(a>b)return a;
  else return b;
}
int main(){
  int n; cin>>n;
  long long a[110000];
  long long b[110000];
  for(int i=0;i<n+1;i++)
  cin >> a[i];
  for(int i=0;i<n;i++)
  cin>>b[i];
  long long sum = 0;

  for(int i=0;i<n;i++){
    if(a[i]>=b[i]) sum+=b[i];
    else{
      sum+=a[i];
      b[i]-=a[i];
      sum+=min(b[i],a[i+1]);
      a[i+1]=max(a[i+1]-b[i],0);
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 1792
program abc161d
      implicit none
!参考有
      integer::k
      integer::i,j,m,n
      integer::Kazu(10,0:9),Sowa(0:10)
      integer::check  !check;counter

         read *,k

         Kazu(1,:)=1
         do i=2,10
            do j=0,9
               if (j==0) then
                  Kazu(i,j)=Kazu(i-1,j)+Kazu(i-1,j+1)
               else if (j==9) then
                  Kazu(i,j)=Kazu(i-1,j-1)+Kazu(i-1,j)
               else
                  Kazu(i,j)=Kazu(i-1,j-1)+Kazu(i-1,j)+Kazu(i-1,j+1)
               end if
            end do
         end do

         Sowa(0)=0
         do j=1,10
            Sowa(j)=sum(Kazu(j,:))-Kazu(j,0)
         end do

         do j=1,9
            Sowa(j+1)=Sowa(j+1)+Sowa(j)
         end do

         do m=1,10
            if (k<=Sowa(m)) then  !何桁か確定
               check=Sowa(m-1)    !確定した直前までの通し番号を記憶
               do n=1,9
                  if (check+Kazu(m,n)>=k) then  !最高位の確定
                     write(*,'(I0)',advance='no') n
                     call solve(k-check,m-1,n)  !(探索する直前までのカウント&
                                                ! ,前桁,確定した数字)
                     stop
                  end if
                  check=check+Kazu(m,n)
               end do
            end if
         end do

      contains
      recursive subroutine solve(k1,mae,fix)
         implicit none
         integer::k1,mae,fix
         integer::l,check1

            if (mae==0) then
               write(*,*) ''
               return
            end if

            check1=0
            do l=max(0,fix-1),min(9,fix+1)
               if ((check1+Kazu(mae,l))>=k1) then
                  write(*,'(I0)',advance='no') l
                  call solve(k1-check1,mae-1,l)
                  stop
               end if
               check1=check1+Kazu(mae,l)
            end do
            stop

      end subroutine solve

   end program abc161d

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

int main(){
	int n[1000000]={0};
	int a;
	
	n[0]=1;
	n[1]=1;
	for(int i=2;i<1000000;i++){
		for(int j=2;i*j<1000000&&n[i]!=1;j++){
			n[i*j]=1;
		}
	}
	
	while(cin>>a){
		for(int i=a-1;;i--){
			if(n[i]==0){
				cout << i;
				break;
			}
		}
		cout << " ";
		for(int i=a+1;;i++){
			if(n[i]==0){
				cout << i;
				break;
			}
		}
		cout << endl;
	}
	return 0;
}

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

const int Maxn = 505;

int n, m, q;
int dp[Maxn][Maxn];

int main()
{
	scanf("%d %d %d", &n, &m, &q);
	while (m--) {
		int l, r; scanf("%d %d", &l, &r);
		dp[l][r]++;
	}
	for (int l = 1; l <= n; l++)
		for (int i = 1; i + l <= n; i++) {
			int j = i + l;
			dp[i][j] += dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
		}
	while (q--) {
		int l, r; scanf("%d %d", &l, &r);
		printf("%d\n", dp[l][r]);
	}
	return 0;
}

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

bool Fanc(int key){
	int t[9],top=0;
	while(key){
		t[top]=key%10;
		top++;
		key/=10;
	}
	bool ok=true;
	for(int i=1;i<top;i++){
		if(t[i-1]!=t[i]+1)ok=false;
	}
	return ok;

}

int main(){
	int n,k[1000],ans=-1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k[i];
		for(int j=0;j<i;j++){
			if(Fanc(k[i]*k[j])){
				ans=max(ans,k[i]*k[j]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int solve(int a, int b, int c, int k){
    int sum = 0;
    for(int i=0; i<a; i++){
        if(k<=0){return sum;}
        sum += 1;
        k--;
    }
    for(int i=0; i<b; i++){
        if(k<=0){return sum;}
        k--;
    }
    for(int i=0; i<c; i++){
        if(k<=0){return sum;}
        sum += -1;
        k--;
    }
    return sum;
}

int main(){
    int A, B, C, K;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> K;
    cout << solve(A, B, C, K) << endl;
}

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

#define pb push_back
#define fr first
#define sc second
#define ll long long

using namespace std;

const int N = 1e4 + 7;
const int mod = 1e9 + 7;

int dp[107][2], dp2[107][2];

int ad(int x)
{
	return ((x + mod) % mod);
}

main()
{
	string s;
	int m, n;
	
	cin >> s >> m;
	
	n = s.size();
	dp2[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		memset(dp, 0, sizeof(dp));
		for (int j = 0; j < m; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				dp[(j + k) % m][1] += dp2[j][1];
				dp[(j + k) % m][1] %= mod;
			}
			for (int k = 0; k < int(s[i] - '0'); k++)
			{
				dp[(j + k) % m][1] += dp2[j][0];
				dp[(j + k) % m][1] %= mod;
			}
			dp[((j + int(s[i] - '0')) % m)][0] += dp2[j][0];
			dp[((j + int(s[i] - '0')) % m)][0] %= mod;
		}
		for (int j = 0; j < m; j++)
			dp2[j][0] = dp[j][0], dp2[j][1] = dp[j][1];
	}
	cout << ad((dp[0][0] + dp[0][1]) - 1) << endl;
}
/*
 * I will solve it in two way
	/					\
   /					 \
 Memory optimization    Time optimization
*/


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n > 0){
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double A = 2.0*(x2 - x1);
			double B = 2.0*(y2 - y1);
			double C = (x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
			double A2 = 2.0*(x3 - x1);
			double B2 = 2.0*(y3 - y1);
			double C2 = (x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);
			double px = (B*C2-B2*C)/(A*B2-A2*B);
			double py = (C*A2-C2*A)/(A*B2-A2*B);
			double exe = Math.hypot(px-x1,py-y1);
			System.out.printf("%.3f %.3f %.3f",round(px),round(py),round(exe));
			System.out.println();
			n--;
		}
	}
	static double round(double d){
		d = Math.round(d*1000);
		d = d/1000;
		return d;
	}
}

Measured memory_bytes: 20780
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main(void)
{
    int N;cin>>N;
    std::vector<ll> A;
    for(int i=0; i<N;i++){
      ll a; cin>>a; A.push_back(a);
    }
    ll ans = gcd(A[0], A[1]);
    for(int i=2; i<N;i++){
      ans = gcd(ans, A[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int n;
    scanf("%d", &n);
    long long a[n];

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

    long long mini = 10000000000;
    long long acm = 0;
    for (int i = 0; i < n - 1; i++) {
        acm += a[i];
        mini = min(mini, abs(sum - 2 * acm));
        //cout << abs(sum - 2 * acm) << endl;
    }

    cout << mini << endl;
}

Measured memory_bytes: 5296
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

long long gcd(long long N, long long M){
    while (true){
        if (min(N,M)==0){
            return max(N,M);
        }else if (N>M){
            N%=M;
        }else{
            M%=N;
        }
    }
}

long long lcm(long long N, long long M){
    return N*M/gcd(N,M);
}

void get_inverse(vector<long long> &inv){
    inv[0]=inv[1]=1;
    for(int i=2; i<(int)inv.size(); i++){
        inv[i]=(MOD+(-(MOD/i)*inv[MOD%i])%MOD)%MOD;
    }
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}


vector<long long> prime_number(int N){
    vector<long long> primes(0);
    vector<int> tmp(N+1,1);
    tmp[0]=tmp[1]=0;
    for(int i=2; i<=N; i++){
        if(tmp[i]==1){
            primes.push_back(i);
        }
        for(long long j= (long long) i*i; j<=N; j+=i){
            tmp[j]=0;
        }
    }
    return primes;
}

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

    vector<long long> A(N,0);
    for(auto &a: A){
        cin >> a;
    }

    vector<long long> inv(1000001,0);
    get_inverse(inv);

    vector<long long> prime = prime_number(1000);
    vector<long long> cnt((int)prime.size(), 0);
    for(int i=0; i<N; i++){
        vector<long long> tmp((int)prime.size(), 0);
        long long a=A[i];
        for(int j=0; j<(int)prime.size(); j++){
            while(a%prime[j]==0){
                a/=prime[j];
                tmp[j]++;
                //cout << a << endl;
            }
        }
        if(a>1){
            prime.push_back(a);
            cnt.push_back(1);
            tmp.push_back(1);
        }
        for(int j=0; j<(int)cnt.size(); j++){
            cnt[j]=max(tmp[j],cnt[j]);
        }
    }

    //cout << (int)prime.size() << endl;
    //cout_vec(cnt);
    long long lcm_=1;
    for(int i=0; i<(int)prime.size(); i++){
        while(cnt[i]>0){
            lcm_=(lcm_*prime[i])%MOD;
            cnt[i]--;
        }
    }

    //cout << lcm_ << endl;
    long long ans=0;
    for(int i=0; i<N; i++){
        ans=(ans+lcm_*inv[A[i]]%MOD)%MOD;
    }

    cout << ans << endl;

}

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

int main() {
  int A, B, M;
  int mina = 1e9+9, minb = 1e9+9;
  cin >> A >> B >> M;
  vector<int> a(A);
  for (int i{}; i < A; ++i) {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
  vector<int> b(B);
  for (int i{}; i < B; ++i) {
    cin >> b[i];
    minb = min(minb, b[i]);
  }

  int ans{mina + minb};
  for (int i{}; i < M; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    --x, --y;
    int tmp = a[x] + b[y] - c;
    ans = min(ans, tmp);
  }

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


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  D2(x)       { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  all(x)      (x).begin(), (x).end()
#define  mem(a)      memset(a , 0 ,sizeof a)
#define  deb(x)      cout << #x << " - " << x << "\n";
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcount(x)
#define  deb2(x,y)   cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
 
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

void solve(){
    int n; cin>> n;
    // vi v(n);
    // rep(i,0,n) cin >> v[i];
    if(n>=30) cout << "Yes";
    else cout << "No";
}
 
int main() {
    IOS;
    // int t; cin >> t;
    int t=1; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3612
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);
        int[] a = new int[n + 1];
        for (int i = 0; i < k; i++)
        {
            int d = int.Parse(Console.ReadLine());

            input = Console.ReadLine().Split(' ');
            for (int j = 0; j < d; j++)
            {
                a[int.Parse(input[j])]++;
            }
        }

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

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 27664
import sys
input = sys.stdin.readline
from itertools import product

H, W = map(int, input().split())
maps = [['.']*(W+2)] + [(['.'] + list(input()) + ['.']) for _ in range(H)] + [['.']*(W+2)]
dxy = ((0, -1), (0, 1), (-1, 0), (1, 0))

for i, j in product(range(1, H+1), range(1, W+1)):
    if maps[i][j] == '#':
        for k, l in dxy:
            if maps[i+k][j+l] == '#':
                break
        else:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3064
void main(){
	string s = _scan!string();
	switch(s){
		case "SUN": writeln(7); break;
		case "MON": writeln(6); break;
		case "TUE": writeln(5); break;
		case "WED": writeln(4); break;
		case "THU": writeln(3); break;
		case "FRI": writeln(2); break;
		case "SAT": writeln(1); break;
		default: break;
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2616
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    string s; cin >> s;
    int count = 0;
    vector<int> A(0);
    
    int countR = 0;
    FOR(i, a, c){
        if(s[i] == '#'){
            countR++;
        }
        else countR = 0;

        if(countR >= 2){
            cout << "No" << endl;
            return 0;
        }
    }
    countR = 0;
    FOR(i, b, d){
        if(s[i] == '#'){
            countR++;
        }
        else countR = 0;

        if(countR >= 2){
            cout << "No" << endl;
            return 0;
        }
    }
    FOR(i, b - 2, d + 2) {
        if(s[i] == '.'){
            count++;
        }
        else{
            A.push_back(count);
            count = 0;
        }
    }
    whole(sort, A, greater<>());
    if(c < d) cout << "Yes" << endl;
    else{
        if(A[0] >= 3) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 772
function main(input) {
  let args = input.split(/\s/);
  let result = 0;
  for (let i = 0;i <= args[0];i++) {
    let sum = 0;
    for (let j = 0;j < ((i + '').length);j++) {
      sum += ((i + '')[j]) * 1;
    }
    if (sum >= args[1] && sum <= args[2]) {
      result += i;
    }
  }
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32820
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int N=2e5+20,inf=0x3f3f3f3f,M=1e5+2;
int n,x;
map<int,int> mp;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&x),mp[x]++,mp[x+1]++,mp[x-1]++;
	int ans=0;
	for(int i=-1;i<=M;i++)
		ans=max(mp[i],ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll MAX = 1e6;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll res=1e18;
    rep3(i,1,sqrt(n)+1){
        if(n%i==0){
            chmin(res,i+n/i);
        }
    }
    cout<<res-2<<endl;
}


Measured memory_bytes: 256
def main():
    INF = 10**9
    n,k = map(int,input().split())
    P = [0] + list(map(int,input().split()))
    C = [0] + list(map(int,input().split()))

    scores = [0]*n

    for s in range(1,n+1):
        start = s
        dp = [-INF]*(n+1)
        dp[0] = 0
        for i in range(n):
            p = P[s]
            dp[i+1] = dp[i] + C[p]
            
            if start == p:
                break
            s = p
        if k <= i+1:
            scores[start-1] = max(dp[1:k+1])
        elif dp[i+1]<=0:
            scores[start-1] = max(dp[1:])
        else:
            r = k%(i+1)
            q = k//(i+1)
            if r>0:
                scores[start-1] = max(max(dp[1:r+1])+dp[i+1]*q, max(dp[1:]))
            else:
                scores[start-1] = dp[i+1]*(q-1)+max(dp[1:])

    print(max(scores))
main()

Measured memory_bytes: 76920
#include <iostream>

using namespace std;

int main(void){
    int a,b;
    cin >> a >> b; cin.ignore();
    if (a < b) {
        cout << "a < b" << endl;
    } else if(a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;

namespace AtCoder
{
    public class Solver
    {
        private readonly IInputReader _inputReader;
        private readonly IOutputWriter _outputWriter;

        public Solver(IInputReader inputReader, IOutputWriter outputWriter)
        {
            _inputReader = inputReader;
            _outputWriter = outputWriter;
        }

        public void Solve()
        {
            var numbers = _inputReader.ReadLine().ToIntArray().ToList();
            var n = numbers[0];
            var l = numbers[1];
            var words = new List<string>();
            for (int i = 0; i < n; i++)
            {
                var s = _inputReader.ReadLine();
                words.Add(s);
            }

            var text = string.Join("", words.OrderBy(s => s).ToArray());

            _outputWriter.WriteLine(text);
        }
    }


    internal class Program
    {
        static void Main(string[] args)
        {
            var reader = new ConsoleInputReader();
            var writer = new ConsoleOutputWriter();
            new Solver(reader, writer).Solve();
        }
    }

    public interface IInputReader
    {
        string ReadLine();
    }

    public interface IOutputWriter
    {
        void WriteLine(string output);
    }

    internal class ConsoleInputReader : IInputReader
    {
        public string ReadLine() => Console.ReadLine();
    }

    internal class ConsoleOutputWriter : IOutputWriter
    {
        public void WriteLine(string output) => Console.WriteLine(output);
    }

    public static class StringExtensions
    {
        public static char ToChar(this string text) => text[0];
        public static int ToInt(this string text) => int.Parse(text);
        public static int[] ToIntArray(this string text) => text.Split(' ').Select(txt => txt.ToInt()).ToArray();
        public static long ToLong(this string text) => long.Parse(text);
        public static long[] ToLongArray(this string text) => text.Split(' ').Select(txt => txt.ToLong()).ToArray();
    }
}

Measured memory_bytes: 28688
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def manhattan(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


n = I()

points = set()
hmin = 10 ** 9
wmin = 10 ** 9
hmax = -(10 ** 9)
wmax = -(10 ** 9)
for _ in range(n):
    x, y = MI()
    points.add((x, y))
    hmin = min(hmin, y)
    hmax = max(hmax, y)
    wmin = min(wmin, x)
    wmax = max(wmax, x)

max_dist = manhattan((wmin, hmin), (wmax, hmax))
hs = max_dist
ms = max_dist
mu = max_dist
hu = max_dist
for p in points:
    hs = min(hs, manhattan((wmin, hmin), p))
    ms = min(ms, manhattan((wmax, hmin), p))
    mu = min(mu, manhattan((wmax, hmax), p))
    hu = min(hu, manhattan((wmin, hmax), p))

print(max_dist - min(hs + mu, hu + ms))


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


int solve(long long int start, long long int target, vector<long long int>& a_sum){
  int left = start;
  int right = a_sum.size() - 1;
  while(right - left > 1){
    int middle = (left + right) / 2;
    long long int value = a_sum[middle] - a_sum[start];
    if(value <= target){ left = middle; }
    else{ right = middle; }
  }
  return left;
}



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

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

  vector<long long int> a_sum(2 * n + 2);
  a_sum[0] = 0;
  for(int i = 0; i < (int)a_sum.size() - 1; i++){
    a_sum[i + 1] = a_sum[i] + a[i % n];
  }


  long long int ans = 0;
  for(int i = 0; i < n; i++){
    int firs = i;
    int seco = solve(firs, total_a / 3, a_sum);
    int thir = solve(seco, (total_a - (a_sum[seco] - a_sum[firs])) / 2, a_sum);
    ans = max(ans, min(a_sum[seco] - a_sum[firs], min(a_sum[thir] - a_sum[seco], a_sum[firs + n] - a_sum[thir])));
    ++thir;
    ans = max(ans, min(a_sum[seco] - a_sum[firs], min(a_sum[thir] - a_sum[seco], a_sum[firs + n] - a_sum[thir])));

    
    ++seco;
    thir = solve(seco, (total_a - (a_sum[seco] - a_sum[firs])) / 2, a_sum);
    ans = max(ans, min(a_sum[seco] - a_sum[firs], min(a_sum[thir] - a_sum[seco], a_sum[firs + n] - a_sum[thir])));
    ++thir;
    ans = max(ans, min(a_sum[seco] - a_sum[firs], min(a_sum[thir] - a_sum[seco], a_sum[firs + n] - a_sum[thir])));
  }


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

Measured memory_bytes: 5196
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 0) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, K;
  std::string S;
  std::cin >> N >> S >> K;

  std::string ans;
  for (auto c : S) {
    ans += c == S[K-1] ? c : '*';
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


struct DSU {
	vector<int> v;
	int n;
	
	DSU( int n ) : n(n){
		v.resize(n);
		iota(v.begin(), v.end(), 0);
	}
	
	// xのグループを求める
	int find(int x){
		if ( x == v[x] )
			return x;
		v[x] = find(v[x]);
		return v[x];
	}
	
	// xとyが同じグループか?
	bool same( int x, int y ){
		return find(x) == find(y);
	}
	
	// xとyを同じグループにする。xの方を親にする
	void unify( int x, int y ){
		x = find(x);
		y = find(y);
		if ( x != y ){
			v[y] = x;
		}
	}
};



ll n, q;

vector<int> a;

int main(){
	cin >> n;
	
	map<int,int> m;
	a.resize(n);
	ll sum = 0;
	for ( int i = 0; i < n; i++ ){
		cin >> a[i];
		m[a[i]]++;
		sum += a[i];
	}
	
	cin >> q;
	for ( int i = 0; i < q; i++ ){
		int b, c;
		cin >> b >> c;
		
		if ( m.count(b) ){
			sum += m[b] * ( c - b );
			m[c] += m[b];
			m.erase(b);
		}
		cout << sum << endl;
	}
	return 0;
}




Measured memory_bytes: 6688
#![allow(clippy::needless_range_loop)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct Bits(usize);

impl Bits {
    fn at(&self, index: usize) -> bool {
        self.0 & 1 << index > 0
    }
}

macro_rules! n_bits_range {
    ($bits:expr) => {
        (0..(1 << $bits)).map(Bits)
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        c: [chars; h]
    }
    let ans = n_bits_range!(h + w)
        .map(|bits| {
            (0..w)
                .map(|x| {
                    (0..h)
                        .filter(|y| bits.at(x) && bits.at(y + w) && c[*y][x] == '#')
                        .count()
                })
                .sum::<usize>()
        })
        .filter(|x| x == &k)
        .count();
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

void disp_stone(vector<vector<char> > s, int H, int W){
	cerr << endl;
	rep (i, H){
		rep (j, W){
			cerr << s[i][j];
		} // end rep
		cerr << endl;
	} // end rep
}

// 落ちきった状態を作り出す
vector<vector<char> > all_fall(vector<vector<char> > s, int H, int W){
	vector<vector<char> > t = s;
//	disp_stone(t, H, W);
	while(true){
		bool update = false;
		for (int i = 0; i < H-1; ++i){
			for (int j = 0; j < W; ++j){
				if (t[i][j] != '0' && t[i+1][j] == '0'){
					swap(t[i][j], t[i+1][j]);
					update |= true;
					break;
				} // end if
			} // end for
			if (update) break;
		} // end for
		if (!update) break;
	} // end while
//	disp_stone(t, H, W);
	
	return t;
}

// 消滅する状態を作り出す
int disappearing(vector<vector<char> > &s, int H, int W, int K){
	int score = 0;
	for (int i = 0; i < H; ++i){
		int left = 0, right = 0;
		while(right < W){
			while (s[i][left] == s[i][right]){
				++right;
			} // end while
			if (right - 1 - left + 1 >= K){
				score += (right - 1 - left + 1)*(int)(s[i][left] - '0');
				for (int j = left; j < right; ++j){
					s[i][j] = '0';
				} // end for
			} // end if
			left = right;
		} // end while
	} // end for
	
	return score;
}

int smulate(vector<vector<char> > s, int H, int W, int K){

	vector<vector<char> > t;
	int score = 0;
	for(int i = 0;; ++i){
		bool update = false;
		t = all_fall(s, H, W);
		if (t == s) break;
		score += (1<<i) * disappearing(t, H, W, K);
		s = t;		
	} // end for
	
	return score;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char> > stones(H, vector<char>(W, 0));
	rep (i, H){
		rep (j, W){
			cin >> stones[i][j];
		} // end rep
	} // end rep

	int res = 0;
	rep (i, H){
		rep (j, W){
			vector<vector<char> > s = stones;
			s[i][j] = '0';
			int curr = smulate(s, H, W, K);
			res = max(res, curr);
		} // end rep
	} // end rep

	cout << res << endl;

	return 0;
}

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

int main() {
  
  string S; cin >> S; string title = "keyence";
  
  int N = S.size(), M = title.size(); bool flag = false;
  
  for (int i = 0; i < M + 1; i++) {
    
    string leftSide = S.substr(0, i);
    string rightSide = S.substr(N - M + i, M - i);
    
    if (leftSide + rightSide == title) flag = true;
    
  }
  
  if (flag) cout << "YES" << endl;
  
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
int n, ans;
int main(void) {
    scanf("%d", &n);
    if (n < 10) {
        ans = n;
    } else {
        ans = n % 10;
    }
    if (ans == 3) {
        printf("bon\n");
    } else if (ans == 0 || ans == 1 || ans == 6 || ans == 8) {
        printf("pon\n");
    } else {
        printf("hon\n");
    }
}

Measured memory_bytes: 1664
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  string s;
  cin >> N;
  cin >> s;
  if(N>=3200){
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        int a, b, d, rect=0, dia=0;
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            String[] s = sc.next().split(",");
            a = Integer.parseInt(s[0]);
            b = Integer.parseInt(s[1]);
            d = Integer.parseInt(s[2]);
            
            if(a * a + b * b == d * d)
                rect++;
            if(a == b)
                dia++;
        }
        System.out.println(rect);
        System.out.println(dia);
    }
 

}

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

int main(){
    int x, y;
    cin >> x >> y;
    int shokin = 0;
    if(x == 1)
        shokin += 300000;
    else if(x == 2)
        shokin += 200000;
    else if(x == 3)
        shokin += 100000;

    if(y == 1)
        shokin += 300000;
    else if(y == 2)
        shokin += 200000;
    else if(y == 3)
        shokin += 100000;
        
    if(x == 1 && y == 1)
        shokin+=400000;

    cout << shokin << endl;
    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
a=[]
1.upto(n){|i|x=gets.split;a<<[i,x[0],x[1].to_i]}
puts a.sort{|a,b|(a[1]<=>b[1]).nonzero?||(b[2]<=>a[2])}.map{|x|x[0]}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int l; cin >> l;
    int n = 20;
    for (int i = 19; !(l & (1 << i)); --i, --n);

    auto g = vec<vector<pair<int, int>>>(n);
    FOR(i, 0, n - 1) {
        g[i].emplace_back(i + 1, 0);
        g[i].emplace_back(i + 1, 1 << i);
    }
    int m = (n - 1) * 2, b = (1 << (n - 1));
    rFOR(i, 0, n - 1)if (l & (1 << i)) {
        g[i].emplace_back(n - 1, b);
        b += (1 << i);
        ++m;
    }

    cout << g.size() << " " << m << "\n";
    FOR(i, 0, n)each(j, g[i]) {
        cout << i + 1 << " " << j.first + 1 << " " << j.second << "\n";
    }
}

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

int main(){
	int n;
	cin>>n;
	int *A=new int[n];
	for(int i=0;i<n;++i)cin>>A[i];
	int q,k,sum=0;
    cin>>q;
    for(int i=0;i<q;++i){
    	cin>>k;
    	if(*((upper_bound(A,A+n,k))-1)==k)sum++;
    }
    cout<<sum<<endl;
	return 0;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

int N, K, *A;

int max(int a, int b){
	return a >= b ? a : b;
}

int only_one_dig_sum(int d, int b){
	int i, ans = 0;
	for(i = 0; i < N; i++){
		ans += ((b << d) ^ (A[i] & ((int)1 << d)));
	}
	return ans;
}

int solve_sub(int d){
	if(d < 0){
		return 0;
	}
	else{
		return max(only_one_dig_sum(d, 0), only_one_dig_sum(d, 1)) + solve_sub(d - 1);
	}
}

int solve(int d){
	if(d < 0){
		return 0;
	}
	else if((((int)1 << d) & K) == 0){
		return only_one_dig_sum(d, 0) + solve(d - 1);
	}
	else{
		return max(only_one_dig_sum(d, 1) + solve(d - 1), only_one_dig_sum(d, 0) + solve_sub(d - 1));
	}
}

signed main(){
	int i;
	scanf("%lld%lld", &N, &K);
	A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	printf("%lld\n", solve(50));
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void bfs(vector<vector<int>> &gr, vector<bool> &chk, vector<int> &deg, vector<int> &ans, int i){
  queue<int> q;
  q.push(i);
  chk.at(i) = true;
  while(!q.empty()){
    int now = q.front(); q.pop();
    ans.push_back(now);
    for(auto nx : gr.at(now)){
      deg.at(nx)--;
      if(deg.at(nx) == 0 && chk.at(nx) == false){
        chk.at(nx) = true;
        q.push(nx);
      }
    }
  }
}

int main(){
  int v, e;
  cin >> v >> e;
  vector<int> deg(v, 0);
  vector<vector<int>> gr(v, vector<int>());
  rep(i, e){
    int s, t;
    cin >> s >> t;
    gr.at(s).push_back(t);
    gr.at(t).push_back(s);
    deg.at(t)++;
  }
  vector<bool> chk(v, false);
  vector<int> ans;
  rep(i, v){
    if(deg.at(i) == 0 && chk.at(i) == false){
      bfs(gr, chk, deg, ans, i);
    }
  }

  for(int i : ans){
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 4188
#include <stdio.h>

int a,b;
int main(){
    scanf("%d %d", &a, &b);
      if(a < b){
    	printf("a < b\n");
	} else if(a > b){
		printf("a > b\n");
	} else  {
		printf("a == b\n");
	}
    return 0;
}


Measured memory_bytes: 2088
A, B, C, D = map(int, input())

r = A + B + C + D
if r == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
    exit()
while True:
    if A + B + C - D == 7:
        print('{}+{}+{}-{}=7'.format(A, B, C, D))
        exit()
    elif A + B - C - D == 7:
        print('{}+{}-{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B - C - D == 7:
        print('{}-{}-{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B + C - D == 7:
        print('{}-{}+{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B - C + D == 7:
        print('{}-{}-{}+{}=7'.format(A, B, C, D))
        exit()
    elif A + B - C + D == 7:
        print('{}+{}-{}+{}=7'.format(A, B, C, D))
        exit()
    elif A - B + C + D == 7:
        print('{}-{}+{}+{}=7'.format(A, B, C, D))
        exit()
    exit()

Measured memory_bytes: 3064
sx, sy, tx, ty = gets.split.map(&:to_i)
w = tx - sx
h = ty - sy

first_go = "R" * w + "U" * h
first_back = "L" * w + "D" * h
second_go = "D" + "R" * (w+1) + "U" * (h+1) + "L"
second_back = "U" + "L" * (w+1) + "D" * (h+1) + "R"

puts first_go + first_back + second_go + second_back


Measured memory_bytes: 1916
N=int(input())
plus=[input() for i in range(N)]
M=int(input())
minus=[input() for i in range(M)]
S=list(set(plus+minus))
ans=[]
for i in S:
    point=0
    point=plus.count(i)-minus.count(i)
    ans.append(point)
money=max(ans)
if money>0:
    print(money)
else:
    print(0)
    

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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


void Main(){
    int N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    string S; cin >> S;

    VL v;
    RREP(i,N){
        for(auto x : v) chmin(A[i], A[i]^x);
        if(A[i]){
            if(S[i] == '1'){
                cout << 1 << en;
                return;
            }
            v.push_back(A[i]);
        }
    }
    cout << 0 << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int k, q;
    cin >> k >> q;
    lint d[k];
    cins(d, d + k);
    for(int i = 0; i < q; i++){
        lint n, x, m;
        cin >> n >> x >> m;
        x %= m;
        n--;
        lint last = x;
        for(int j = 0; j < k; j++){
            lint d2 = d[j] % m;
            if(!d2){
                d2 = m;
            }
            last += d2 * (n / k);
            if(j < n % k){
                last += d2;
            }
        }
        //cout << last << endl;
        cout << n - last / m << endl;
    }
}


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

int main() {
  int N, A;
  cin >> N >> A;

  if (N % 500 != 0) {
    if (A < 500) {
      if (N % 500 > A) {
        cout << "No" << endl;
      }else{
        cout << "Yes" << endl;
      }
    }else{
      cout << "Yes" << endl;
    }
  }else{
    cout << "Yes" << endl;
  }
}


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

s = []
for i in range(n):
    a,b = map(int,input().split())
    temp = (b,a)
    s.append(temp)
s.sort()

now = 0
for i in range(n):
    now += s[i][1]
    if now > s[i][0]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 29444
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    normal, throw = map(int, input().split())
    a.append(normal)
    b.append(throw)
a.sort(reverse=True)
b.sort(reverse=True)

count = 0

def check():
    if h <= 0:
        print(count)
        exit()

nage = [x for x in b if x > a[0]]
for v in nage:
    h -= v
    count += 1
    check()

print((h + a[0] - 1) // a[0] + count)




Measured memory_bytes: 12056
def solve():
  N, W = map(int, input().split())

  dp = [0]  * (W + 1)
  items = []
  for i in range(N):
    w, v = map(int, input().split())
    items.append((w, v))

  for w, v in items:  
    for wk in range(W, w - 1, -1):
      tv = dp[wk - w] + v
      if tv > dp[wk]:
        dp[wk] = tv
  res = max(dp)
  print(res)

if __name__ == "__main__":
  solve()


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

map<int, vector<int>> tree;
map<int, set<int> > used;
map<int, pair<int, int>> sides;
map<pair<int, int>, int> ans;
int maxNum;

void dfs(int key, int exceptKey, int exceptNum) {
  int num = 1;
  for (auto l: tree[key]) {
      if (l == exceptKey) continue;
      
      while (used[key].count(num)!=0 || exceptNum==num) {
        num++;
      }
      used[key].insert(num);
      used[l].insert(num);
      int a = key;
      int b = l;
      if (a>b) swap(a,b);
      ans[{a,b}] = num;
      maxNum = max(maxNum, num);
      dfs(l, key, num);
  }
  return;
}

int main(){
  int N;
  cin >> N;
  
  for (int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    sides[i]={a,b};
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  maxNum = 0;
  dfs(1, 0, 0);
  
  cout << maxNum << endl;
  for (int i = 0; i < N-1; i++) {
    cout << ans[sides[i]] << endl;
  }
  
  return 0;
}

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

int main() {
	int a[3];
	rep(i,3) cin >> a[i];
	if(a[0] + a[1] + a[2] >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}


Measured memory_bytes: 256