akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

signed main() {
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w + 1);
    for (int t = 0; t < n; t++) {
        int a, b;
        cin >> a >> b;
        for (int j = w - a; j >= 0; j--) {
            dp[j + a] = max(dp[j + a], dp[j] + b);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= w; i++) 
        ans = max(ans, dp[i]);
    cout << ans << "\n";
    return false;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w,a[505][505]={};
	cin>>h>>w;
	FORQ(i,1,h){
		FORQ(j,1,w){
			cin>>a[i][j];
		}
	}
	queue<pair<int,int>> q;
	map<pair<int,int>,int> mp;
	queue<pair<pair<int,int>,pair<int,int>>> ans;
	FORQ(i,1,h){
		FOR(j,1,w){
			if(a[i][j]%2==1){
				a[i][j]--;a[i][j+1]++;
				ans.push(MP(MP(i,j),MP(i,j+1)));
			}
		}
		if(a[i][w]%2==1&&i!=h){
			a[i][w]--;a[i+1][w]++;
			ans.push(MP(MP(i,w),MP(i+1,w)));
		}
	}
	cout<<ans.size()<<endl;
	while(ans.size()){
		pair<pair<int,int>,pair<int,int>> tpl=ans.front();
		ans.pop();
		cout<<tpl.ST.ST<<" "<<tpl.ST.ND<<" "<<tpl.ND.ST<<" "<<tpl.ND.ND<<endl;
	}
    return 0;
}


Measured memory_bytes: 5120
s = input()
state = 0
for i in range(len(s)):
    if state == 0:
        if s[i] == "C":
            state = 1
    if state == 1:
        if s[i] == "F":
            state = 2
if state == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
#define fr first
#define val second
#define N 100000000
#define fo(i,m,n) for(int i=m;i<n;i++)
#define M 7
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
using ul=unsigned long long;
using pii=pair<int,int>;
using vvi=vector<vector<int>>;
using vi=vector<int>;
using pll=pair<ll,ll>;
using vsi=vector<set<int>>;
using vll=vector<ll>;

ll power(ll a,ll n){
    ll j=0;
    ll x=1;
    while(1ll<<j<=n){
        if(1ll<<j&n)
            x=(x*a)%mod;

        a=a*a%mod;
        j++;
    }

    return x;
}

int gcd(int a,int b){
    if(b==0)
        return a;
    else
        return gcd(b,a%b);

}

int lb(vi &a,int x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;
    while(l<=r){
        int mid=(l+r)/2;
        if(x>=a[mid]){
            l=mid+1;
            ind=mid;
        }
        else
            r=mid-1;

    }

    return ind+1;

}

int up(vll &a,ll x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;

    while(l<=r){
        int mid=(l+r)/2;

        if(a[mid]>x){
            l=mid+1;
            ind=mid;
        }
        else
            r=mid-1;

    }

    return ind;
}

ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;

}

ll min(ll a, ll b){
    if(a>b)
        return b;
    else
        return a;

}
template<typename T>
void pra(T a[],int n){
    fo(i,0,n)
            cout<<a[i]<<' ';
    cout<<endl;

}

ifstream input;
ofstream output;
int t;
const ll inf=1e16;
int cs;
int tcs;
void build(vll &F,int ind,int tl,int tr,vll &st){

    if(tl==tr)
        st[ind]=F[tl];
    else{
        int mid=(tl+tr)/2;
        build(F,2*ind+1,tl,mid,st);
        build(F,2*ind+2,mid+1,tr,st);
        st[ind]=min(st[2*ind+1],st[2*ind+2]);
    }

}

void update(int j,ll nv,int ind,int tl,int tr,vll &st){

    if(j<tl||j>tr)
        return;
    else if(tl==tr)
        st[ind]=nv;
    else{
        int mid=(tl+tr)/2;
        update(j,nv,2*ind+1,tl,mid,st);
        update(j,nv,2*ind+2,mid+1,tr,st);
        st[ind]=min(st[2*ind+1],st[2*ind+2]);
    }

}


ll query(int ind,int tl,int tr,int l,int r,vll &st){
    int mid=(tl+tr)/2;
    if(r<tl||l>tr)
        return inf;
    else if(tl==l&&tr==r)
        return st[ind];
    else
        return min(query(2*ind+1,tl,mid,l,min(mid,r),st),query(2*ind+2,mid+1,tr,max(mid+1,l),r,st));

}

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

    if(x>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3624
//#pragma GCC optimize("O2")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 2e5 + 55;
const int mod = 1e9 + 7;
int n, a[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int ans = 1;
	for(int i = 1; i < n; i++) {
		if(a[i]<a[i-1]) ans++;
		else a[i] = a[i-1];
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int n ,m ,i ,j ,in ,out ,tmp ,cnt=0 ,most=0;
  scanf( "%d" ,&n );
  scanf( "%d" ,&m );
  most = m;
  for( i=0 ; i<n ; i++ ){
    scanf( "%d %d" ,&in ,&out );
    m += in;
    m -= out;
    if( m > most ){
      most = m;
    }
    if( m < 0 ){
      cnt++;
    }
  }
  
  if( cnt == 0 ){
    printf( "%d\n" ,most );
  }
    
  else{
    printf( "0\n" );   
  }
  
  return 0;

}

Measured memory_bytes: 596
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,m;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(n);in(m);
	for(int i=1;i<=max(n,m);i++)
	cout<<min(n,m); 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cmath>

using namespace std;

string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

char encode(char a,int k){
	int b;
	if(isupper(a))b=a-'A';
	else b=a-'a'+26;
	if(b-k>=0)return str[b-k];
	return str[52-abs(b-k)];
}

int main(void){
	
	int n;
	while(cin >> n,n){
		vector<int>k(n);
		for(int i=0;i<n;i++){
			cin >> k[i];
		}
		string s;
		cin >> s;
		for(int i=0;i<s.size();i++)s[i]=encode(s[i],k[i%n]);
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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



int main(){
    int n, m;   cin >> n >> m;
    cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer,Integer> dp = new HashMap();
		int res = 0;
		for (int i = 0 ; i < n ; ++i) {
			int x = sc.nextInt();
			dp.put(x, dp.getOrDefault(x - 1, 0) + 1);
			res = Math.max(res, dp.get(x));
		}
		System.out.println(n - res);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 54440
// 6/7
// AGC045-Aのための例題
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

ll oddsolve(ll a) {
    return (a + 1) / 2 % 2;
}

ll solve(ll a) {
    if (a % 2) return oddsolve(a);
    else return oddsolve(a + 1) ^ (a + 1);  // a+1の結果からa+1を引く（XORの場合は引くもタスも一緒）
}

int main() {
    ll A, B;
    cin >> A >> B;

    cout << (solve(A - 1) ^ solve(B)) << endl;
}

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

int Size = 10;

int main(void) {
    int height[Size];
    
    for(int i = 0; i < Size; ++i) {
        cin >> height[i];
    }
    sort(height, height + Size);
    for(int i = 1; i <= 3; ++i) {
        cout << height[Size - i] << endl;
    }
}


Measured memory_bytes: 3140
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
count1=0
count2=0
t1=x
t2=x
while(t1>=0):
    if(t1 in a):
        count1+=1
    t1+=-1
while(t2<=n):
    if(t2 in a):
        count2+=1
    t2+=1
print(min(count1,count2))

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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> x(n, k-q);
    rep(i,q){
        int a;
        cin >> a;
        --a;
        x[a]++;
    }
    rep(i,n) {
        if(x[i]<=0) puts("No");
        else puts("Yes");
    }
    
    return 0;
}

Measured memory_bytes: 1024
'''
Introduction to Heuristics Contest
A - AtCoder Contest Scheduling
'''

# 本番テストケースは365
D = int(input())

# コンテストタイプごとの満足度の下がりやすさ
C = list(map(int, input().split()))

# 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
S = []
for _ in range(D):
    sday = list(map(int, input().split()))
    S.append(sday)

# とりあえず
for i in range(D):
    tmp = i % 26 + 1
    print(tmp)

Measured memory_bytes: 9392
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> sum(N + 1, 0);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        sum[a]++;
        sum[b + 1]--;
    }

    rep(i, N) { sum[i + 1] += sum[i]; }

    ll ans = 0;
    rep(i, N + 1) {
        if (sum[i] == M)
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    int N; cin >> N;
    int AC=0, WA=0, TLE=0, RE=0;
    REP(i,N){
        string S; cin >> S;
        if(S=="AC") AC++;
        if(S=="WA") WA++;
        if(S=="TLE") TLE++;
        if(S=="RE") RE++;
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

    return 0;
}


Measured memory_bytes: 3628
ary=$stdin.readlines
od=Array.new
ev=Array.new
n = ary[0].to_i
array=ary[1].split.map!(&:to_i)
p=0
while p<n
  od.push(array[p]) if p%2==0
  ev.push(array[p]) if p%2==1
  p+=1
end

  sd_n_ns_od = od.group_by{|i| i}.sort_by{|k,v| v.size}
  sd_n_ns_ev = ev.group_by{|i| i}.sort_by{|k,v| v.size}
answer = 0
if sd_n_ns_od.size == 1 || sd_n_ns_ev.size == 1
  if sd_n_ns_od.size == 1 && sd_n_ns_ev.size == 1
    if sd_n_ns_od.last.first == sd_n_ns_ev.last.first
    answer = n/2
      else
    answer= 0
    end
  end
  if !(sd_n_ns_ev.size == 1)
    most_n_od = sd_n_ns_od.last.first
    most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
    answer=ev.reject{|i| i==most_n_ev}.size
  end
  if !(sd_n_ns_od.size == 1)
      most_n_ev = sd_n_ns_ev.last.first
      most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
      answer=od.reject{|i| i==most_n_od}.size
  end
    else
most_n_od = sd_n_ns_od.last.first
most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
answer1=0
answer1+=od.reject{|i| i==most_n_od}.size
answer1+=ev.reject{|i| i==most_n_ev}.size

most_n_ev = sd_n_ns_ev.last.first
most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
answer2=0
answer2+=ev.reject{|i| i==most_n_ev}.size
answer2+=od.reject{|i| i==most_n_od}.size

 answer = (answer1 <= answer2)?  (answer1):(answer2)
 end
puts answer


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

#define ll long long
#define ar array

int somarDigitos(int numero) {
    int soma = 0;

    while (numero != 0) {
        soma   += numero % 10;
        numero  = numero / 10;
    }

    return soma;
}

int main() {

    ios::sync_with_stdio(false);
    
  	int a, b, n,ans;
  	
  	cin >> n;
  	
  	a=1;
  	b=n-a;
  	ans=somarDigitos(a)+somarDigitos(b);
  	
  	while(a<=b){
  		
  		a++;
  		b--;
		if(ans>somarDigitos(a)+somarDigitos(b)){
			ans=somarDigitos(a)+somarDigitos(b);				
			}
		}
	cout << ans << endl;
	
	
  	
  	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
int main(){
	iOS;
	string s;
	cin >> s;
	cout << s.substr(0,4) << ' ' << s.substr(4) << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

min_count = len(T)
for s in range(len(S) - len(T) + 1):  # T cannot exceed the length of S
    matched = 0
    for i in range(len(T)):
        # print(f'S[{s + i}] == T[{i}]')
        if S[s + i] == T[i]:
            matched += 1
    count = len(T) - matched
    if count < min_count:
        min_count = count
print(min_count)

Measured memory_bytes: 9088
import Data.Function (on)

div'::Int->Int->Double
div' = (/) `on` fromIntegral

main = do
  [w,h,x,y] <- map read . words <$> getLine
  let s = div' (w*h) 2
  let isMulti = if even w && even h && (div w 2) == x && (div h 2) == y then "1" else "0"
  putStrLn $ show s ++ " " ++ isMulti

Measured memory_bytes: 508
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

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

    int main(){
        int n;cin>>n;
        int res = 0;
        REP(i,1,n){
            int now = i,cnt = 0;
            while(now>0){
                now /= 10;
                cnt++;
            }
            if(cnt%2==1)res++;
        }
        cout<<res;
    }
    


Measured memory_bytes: 256
from collections import defaultdict

S = input()
T = input()

ctr_s = defaultdict(list)
ctr_t = defaultdict(list)
for i in range(len(S)):
    ctr_s[S[i]].append(i)
    ctr_t[T[i]].append(i)

ok = True
for key in ctr_s:
    char = T[ctr_s[key][0]]
    ok &= len(ctr_s[key]) == len(ctr_t[char])
    ok &= all(u == v for u, v in zip(ctr_s[key], ctr_t[char]))

if ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 90272
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	ll sum=0,Min=1e10; scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		ll a,b;scanf("%lld%lld",&a,&b);
		sum+=a;
		if(a>b) Min=min(Min,b);
	}
	if(Min==1e10)
		printf("0\n");
	else
		printf("%lld",sum-Min);
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(){
  int K,S;
   cin >> K;
   cin>>S;
  int ans = 0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      if(S-i-j<=K && (S-i-j>=0))
	   ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<int, vector<int>, greater<int> > PQ_ASK;

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

    bool eq = [&] {
        return *min_element(s.begin(), s.end()) == *max_element(s.begin(), s.end());
    }();

    if (eq) {
        cout << 0 << endl;
        ret();
    }

    PQ_ASK ws;
    priority_queue<int> rs;
    rep(i, n) {
        if (s[i] == 'R') rs.push(i);
        else ws.push(i);
    }

    int ans = 0;
    while (ws.top() < rs.top()) {
        ans++;
        int rt = rs.top();
        int wt = ws.top();
        rs.pop();
        ws.pop();
        rs.push(wt);
        ws.push(rt);
    }
    cout << ans << endl;


}


Measured memory_bytes: 4692
// Author: Ishaan Gupta

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
#define endl '\n'
#define pb push_back
#define DEB(x) cout << '>' << #x << ':' << x << endl;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

ll n,w;
ll arr[110][2];
vector<vector<ll>>dp(110,vector<ll>(100010,-1));

ll func(ll ind, ll wr)
{
    if(dp[ind][wr]!=-1)
        return dp[ind][wr];

    if(wr == 0 || ind == n)
        return 0;
    if(arr[ind][0] > wr)
        return dp[ind][wr]=func(ind+1, wr);
    return dp[ind][wr]=max(arr[ind][1]+func(ind+1, wr-arr[ind][0]), func(ind+1, wr));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif

    cin >> n >> w;
    for(ll i = 0; i < n; ++i)
    {
        cin >> arr[i][0]>>arr[i][1];
    }
    cout<<func(0,w);
    return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int dp[n][n]; rep(i,n) rep(j,n) dp[i][j] = 0;
    rep(i,n) {
        if (s[i] == s[n-1]) {
            dp[i][n-1] = 1;
            dp[n-1][i] = 1;
        }
    }
    for (int i = n-2; i >= 0; i--) {
        for (int j = n-2; j >= 0; j--) {
            if (s[i] == s[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
    //rep(i,n) {rep(j,n) {printf("%d ", dp[i][j]);} printf("\n");}
    int ans = 0;
    rep(i,n) {
        rep(j,i) {
            int c = min(dp[i][j], i-j);
            ans = max(ans,c);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 101276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
double sum[200009];
int main()
{
    int n,k;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        int a;scanf("%d",&a);
        sum[i]=sum[i-1]+(1.0/a)*(a+1)*a/2;
    }
    double M=-1;
    for(int i=k;i<=n;i++)
    {
        M=max(M,sum[i]-sum[i-k]);
    }
    printf("%.13lf\n",M);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N; string S; cin>>N>>S;
	vector<int> v(3,0);
	for(int i=0;i<N;i++){
		v[(S[i]-'0')%3]++;
	}
	int ans=v[0]*v[1]*v[2];
	for(int i=0;i<N-1;i++){
		for(int j=i;j<N;j++){
			int d=j-i,now=j+d;
			if(now<N){
				if(S[i]!=S[j] and S[i]!=S[now] and S[j]!=S[now])ans--;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
/***  بسم الله الرحمن ا لرحيم   ***/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
//#include<unordered_map>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define test int t;cin>>t;while(t--)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 2e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y)) * y); }
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
	//file();
	int n;
	cin >> n;
	ll x, g=1;
	while (n--) {
		cin >> x;g = lcm(x, g);
	}
	cout << g;

}

Measured memory_bytes: 256
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
cd = [list(map(int,input().split())) for _ in range(M)]

for x1,y1 in ab:
    tmp = float('inf')
    ans = None
    for num,xy2 in enumerate(cd):
        x2 = xy2[0]
        y2 = xy2[1]
        dist = abs(x1-x2)+abs(y1-y2)
        if dist < tmp:
            tmp = dist
            ans = num + 1
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// yesterday was a series of blunders.
// first failed to properly implement E (which was just really basic dp/brute force), 
// then failed to realize that F is just basic centroid decomposition + dsu.
// (if I could just decently implement that in contest time... 2100 is within reach...)
// such mistakes cannot repeat again.
ll a[3], b[3];
ll dp[36000000];
int main(){
	ll n; cin >> n;
	for (ll i = 0; i<3; i++) cin >> a[i];
	for (ll i = 0; i<3; i++) cin >> b[i];
	for (ll i = 0; i<=n; i++){
		dp[i] = max(dp[i], i);
		for (ll j = 0; j<3; j++){
			if (i - a[j] >= 0) dp[i] = max(dp[i], dp[i - a[j]] + b[j]);
		}
	}
	n = dp[n];
	for (ll i = 0; i<=n; i++){
		dp[i] = i;
		for (ll j = 0; j<3; j++){
			if (i - b[j] >= 0) dp[i] = max(dp[i], dp[i - b[j]] +  a[j]);
		}
	}
	n = dp[n]; cout << n << endl;
}

Measured memory_bytes: 196864
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string a, b;
    cin >> a >> b;
    int n = stoi(a + b);
    for(int i = 1; i < sqrt(n) + 1; i++){
        if(i * i == n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (a-c) * (b-d) << endl;

}



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

int main(){
  int N;
  cin >> N;
  int A,B;
  int min_sum = 80;
  for(int i=1; i<=N/2; i++){
    int sum = 0;
    A = i;
    B = N-i;
    while(A>0){
      sum += A % 10;
      A /= 10;
    }
    while(B>0){
      sum += B % 10;
      B /= 10;
    }
    if(sum < min_sum){
      min_sum = sum;
    }
  }
  cout << min_sum << endl;
}

Measured memory_bytes: 256
#ifndef COMPETITIVE_HEADER
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;
#endif

int n,m,a,b;
vvi edges, children;
vpi ans, tree;
int visited[100010];
int weight[100010];

void exec(int i){
    for(auto p : children[i]) exec(p);
    if (i == 0) return;
    if ((weight[i] % 2) == 1){
        weight[i]++;
        ans.eb(i, visited[i]);
    } else {
        weight[visited[i]]++;
        ans.eb(visited[i], i);
    }
}

signed main(){
    I(n); I(m);
    edges.resize(n);
    children.resize(n);
    REP(i,m){
        I(a); I(b);
        a--; b--;
        edges[a].pb(b);
        edges[b].pb(a);
    }
    if (m%2){
        cout << -1 << endl;
        return 0;
    }
    REP(i, n) visited[i] = -2;
    deque<int> q;
    q.pb(0);
    visited[0] = -1;
    while(!q.empty()){
        auto p = q.back();
        cerr << p << " ";
        q.pop_back();
        for(auto nxt: edges[p]){
            if (visited[nxt] != -2) continue;
            visited[nxt] = p;
            children[p].pb(nxt);
            tree.eb(p, nxt);
            q.pb(nxt);
        }
    }
    cerr << endl;
    REP(i,n){
        for(auto j: edges[i]){
            if (j < i) continue;
            if (visited[i] == j || visited[j] == i) continue;
            weight[i]++;
            ans.eb(i,j);
        }
    }

    exec(0);
    for(auto p: ans){
        printf("%lld %lld\n", p.first+1, p.second+1);
    }
}

Measured memory_bytes: 25020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%lld",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 300007
ll dp[2097155];

int main()
{
    ll n,i,j,k,x,y,r;
    cin>>n;
    int comp[n+1][n+1];
    dp[0]=1;
    fo(i,1,n+1)
    {
        fo(j,1,n+1) cin>>comp[i][j];
    }
    x=(ll)(pow(2,n));
    fo(i,1,x)
    {
        k=__builtin_popcount(i);
        y=(x/2); r=1;
        while(y>0){
            if(y&i && comp[k][r]){
                dp[i]=(dp[i]+dp[(i^y)])%mo;
            }
            r++;
            y/=2;
        }
    }
    cout<<dp[x-1]<<endl;
}


Measured memory_bytes: 16640
#include <stdio.h>

int main() {

  int a,b,r,tmp;

  scanf("%d%d",&a,&b);

  /* a>bを確認/入れ替え */
  if(a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッド */
  r = a % b;

  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }

  printf("%d\n",b);

  return 0;
}



Measured memory_bytes: 2140
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<math.h>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int n,cnt=0,len,flag=0;
	string s,str;
	cin >> s >> n;
	len=s.size();
	REP(i,n){
		cin >> str;
		str=str+str;
		if(str.find(s)!=string::npos)
			flag=1;
		if(flag==1)
			cnt++;
		str.clear();
		flag=0;
	}
	cout << cnt << endl;
	return 0;
}			

Measured memory_bytes: 1212
let words str =
  let len = String.length str in
  let buf = Buffer.create 10 in
  let rec loop acc = function
      i when i = len -> acc, (Buffer.contents buf |> int_of_string)
    | i ->
      loop
        (match str.[i] with
         | ' ' ->
           let v = Buffer.contents buf |> int_of_string in
           Buffer.clear buf; v
         | c ->
           Buffer.add_char buf c; acc)
        (i+1)
  in loop 0 0

let bsearch predicate maxv =
  let rec loop minp maxp =
    match compare minp maxp with
      0 -> minp
    | _ ->
      let middle =
        match maxp+minp with
          v when v mod 2 = 0 -> v/2
        | v -> v/2 + 1 in
      if middle = maxp then (if predicate minp then minp else maxp) else
        match predicate middle with
          true -> loop minp middle
        | false -> loop middle maxp
  in
  loop 1 maxv

let check num_of_truck goods capacity =
  let len = Array.length goods in
  let rec loop acc = function
      _, i when i >= len -> true
    | 0, _  -> false
    | rem_truck, i -> match goods.(i)+acc with
        x when x > capacity -> loop 0 (rem_truck-1,i)
      | x -> loop x (rem_truck,i+1)
  in
  loop 0 (num_of_truck,0)

let () =
  let n,num_of_truck = read_line () |> words in
  let goods = Array.init n (fun _ -> read_int ()) in
  let sum = Array.fold_left (fun acc v -> acc+v) 0 goods in
  bsearch (check num_of_truck goods) sum |> Printf.printf "%d\n"

Measured memory_bytes: 5184
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int getans(const int nowx, const int nowy,const int nowhp , const vector<vector<int>>&field, vector<vector<vector<int>>>&memo) {
	if (memo[nowx][nowy][nowhp]!= -2)return memo[nowx][nowy][nowhp];
	else {
		memo[nowx][nowy][nowhp] = 1000000;
		int ans = 100000;
		if (!nowhp)return memo[nowx][nowy][nowhp] = 1000000;
		for (int way = 0; way < 4; ++way) {
			const int nextx = nowx + dx[way];
			const int nexty = nowy + dy[way];
			 int nexthp = nowhp - 1;
			 bool ok = true;
			 switch (field[nexty][nextx]) {
			 case 0:
				 ok = false;
			 case 1:
			 case 2:
				 break;
			 case 3:
				 return memo[nowx][nowy][nowhp]= 1;
				 break;
			 case 4: {
				
				nexthp = 5;
				break;
			 default:
				 assert(false);
			 }
			 }
			 if (ok) {
				 ans = min(ans, 1 + getans(nextx, nexty,nexthp, field, memo));
			 }
		}
		return memo[nowx][nowy][nowhp]=ans;
	}
}

int main() {
	while (1) {
		int W, H; cin >> W >> H;
		if (!W)break;
		vector<vector<int>>field(H+2, vector<int>(W+2));
		int sx, sy;
		map<pair<int, int>, int>sweets;
		int sw = 0;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				int num; cin >> num;
				if (num == 2) {
					num = 1;
					sx = j + 1; sy = i + 1;
				}
				field[i + 1][j + 1] = num;
			}
		}
		vector<vector<vector<int>>>memo(W + 2, vector<vector<int>>(H + 2, vector<int>(8,-2)));
		
		int ans = getans(sx, sy, 5, field, memo);
		if (ans >= 100000)ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  rep(i,t){
    int n;
    cin>>n;

    vector<ll> p(n);
    rep(i,n){
      cin>>p[i];
    }
    
    string s;
    cin>>s;
    
    vector<ll> base;
    for(int i=n-1;i>=0;i--){
      for(auto z : base){
        chmin(p[i],p[i]^z);
      }

      if(s[i]=='0') base.pb(p[i]);
      else if(p[i]>0) {
        cout << 1 << endl;
        break;
      }
      if(i==0) cout << 0 << endl;
    }


  }

}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(void){
	int k,s;
		cin >> k >> s;
		
	int res=0;
	for(int x=0;x<=k;x++){
		for(int y=max(0,s-x-k) ;y<=k&&x+y<=s ;y++)
			res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 1000
using namespace std;

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

  int n;
  cin >> n;
  vector< int > a;
  for(int i = 0; i < n; i++){
    int j;
    cin >> j;
    a.push_back(j);
  }

  sort(a.begin(), a.end(), greater< int >());
  int alice = 0, bob = 0;
  for(int i = n - 1; i >= 0; i--){
    if(i % 2 == 0) alice += a[i];
    else bob += a[i];
  }
  cout << (alice - bob) << endl;

  return 0;
}


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

using Info = std::array<int, 3>;

std::vector<std::string> board;
int H, W;
int goal[2];
Info now{};
std::string program;

int dir[4][2]{{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
char dir_char[8]{"NWSE"};
int ans{};

bool calcProgram(int&);
bool calcWhile(int&);
bool calcIf(int&);
bool calcBehave(int&);
bool calcCondition(int);
void readThrough(int&);

int main()
{
	scanf("%d%d", &H, &W);
	board.resize(H);
	for (auto& e: board) std::cin >> e;
	std::cin >> program;
	for (int i{}; i < H; i++)
		for (int j{}; j < W; j++)
			if (board[i][j] == 's')
			{
				now[0] = i;
				now[1] = j;
				board[i][j] = '.';
			}
			else if (board[i][j] == 'g')
			{
				goal[0] = i;
				goal[1] = j;
				board[i][j] = '.';
			}
	int s_i{};
	if (calcProgram(s_i))
		puts("-1");

	return 0;
}

// 即終了ならfalse
bool calcProgram(int& s_i)
{
	while (s_i < (int)program.size() && program[s_i] != ']' && program[s_i] != '}')
		if (program[s_i] == '{')
		{
			if (!calcWhile(s_i))
				return false;
		}
		else if (program[s_i] == '[')
		{
			if (!calcIf(s_i))
				return false;
		}
		else
		{
			if (!calcBehave(s_i))
				return false;
		}
	return true;
}

// 即終了ならfalse
bool calcWhile(int& s_i)
{
	std::set<Info> visited;
	s_i++;
	int program_begin{s_i + 1};
	if (program[s_i] == '~') program_begin++;
	while (calcCondition(s_i))
	{
		if (visited.find(now) != visited.end())
		{
			puts("-1");
			return false;
		}
		visited.insert(now);
		int inner_i{program_begin};
		if (!calcProgram(inner_i))
			return false;
	}
	s_i = program_begin;
	readThrough(s_i);
	s_i++;
	return true;
}

// 即終了ならfalse
bool calcIf(int& s_i)
{
	s_i++;
	int program_begin{s_i + 1};
	if (program[s_i] == '~') program_begin++;
	if (calcCondition(s_i))
	{
		int inner_i{program_begin};
		if (!calcProgram(inner_i))
			return false;
	}
	s_i = program_begin;
	readThrough(s_i);
	s_i++;
	return true;
}

bool calcCondition(int s_i)
{
	bool reverse{};
	if (program[s_i] == '~')
	{
		reverse = true;
		s_i++;
	}
	if (program[s_i] == 'T') return true ^ reverse;
	for (int i{}; i < 4; i++)
		if (program[s_i] == dir_char[i])
			return (i == now[2]) ^ reverse;
	return (board[now[0] + dir[now[2]][0]][now[1] + dir[now[2]][1]] == '#') ^ reverse;
}

void readThrough(int& s_i)
{
	int if_count{}, while_count{};
	while (if_count >= 0 && while_count >= 0 && s_i < (int)program.size())
	{
		if (program[s_i] == '[') if_count++;
		else if (program[s_i] == ']') if_count--;
		else if (program[s_i] == '{') while_count++;
		else if (program[s_i] == '}') while_count--;
		s_i++;
	}
	s_i--;
	return;
}

// 即終了ならfalse
bool calcBehave(int& s_i)
{
	ans++;
	if (program[s_i] == '^')
	{
		if (board[now[0] + dir[now[2]][0]][now[1] + dir[now[2]][1]] != '#')
		{
			now[0] += dir[now[2]][0];
			now[1] += dir[now[2]][1];
		}
	}
	else if (program[s_i] == 'v')
	{
		if (board[now[0] - dir[now[2]][0]][now[1] - dir[now[2]][1]] != '#')
		{
			now[0] -= dir[now[2]][0];
			now[1] -= dir[now[2]][1];
		}
	}
	else if (program[s_i] == '<')
		now[2] = (now[2] + 1) % 4;
	else
		now[2] = (now[2] + 3) % 4;
	
	if (now[0] == goal[0] && now[1] == goal[1])
	{
		printf("%d\n", ans);
		return false;
	}
	s_i++;
	return true;
}


Measured memory_bytes: 3360
#include "bits/stdc++.h"
using namespace std;
int hmae[10];
int hmigi[10];
int cnt[21];
int main()
{
	int w;int d;
	while(1)
	{
		cin>>w>>d;
		int ans=0;
		if(w==0)
			break;
		for(int i=0;i<w;i++)
			cin>>hmae[i];
		for(int i=0;i<d;i++)
			cin>>hmigi[i];
		fill(cnt,cnt+21,0);
		for(int i=0;i<w;i++)
		{
			ans+=hmae[i];
			cnt[hmae[i]]++;
		}
		for(int i=0;i<d;i++)
		{
			if(cnt[hmigi[i]]==0)
				ans+=hmigi[i];
			else
				cnt[hmigi[i]]--;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3028
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<lint, lint>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
constexpr double Pi = 3.141592653589793;

template<class T> using prique = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

lint fact[3000000];
void fact_init(lint n, lint m = mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

int main() {
	int x;
	cin >> x;
	cout << 10 - x / 200 << endl;
}

Measured memory_bytes: 3628