akhauriyash/Code-Regression huggingface dataset:
import numpy as np

D = int(input())
c = np.array( list(map(int, input().split())) )
#
s = [[] for i in range(D)]
for i in range(D):
  s[i] = np.array( list(map(int, input().split())) )
#
v = 0
cc =  np.array( [0]*26 )
last = np.array( [-1]*26 )
for d in range(D):
  cc += c
  av = s[d] - sum( cc ) + cc
  av2 = av + cc + c
  m = max(av2)
  for t in range(26):
    if av2[t] == m:
      cc[t] = 0
      v += av[t]
      print(t+1)
      break
#
#print( v )


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

int main(){
  string s;
  cin >> s;
  int a = s.at(6);
  //cout << a << endl;
  if(s.at(5)=='1') cout << "TBD" << endl;
  else if(4<(a-48)) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());
        string[] strA = Console.ReadLine().Split(' ');
 
        bool[] array = new bool[1000000000];
        //for(int i = 0; i < 1000000000; i++) array[i] = false;
        foreach(string str in strA)
        {
          int x = int.Parse(str);
          if(array[x])
          {
	        Console.WriteLine("NO");
            return;
          }
          array[x] = true;
        }
        Console.WriteLine("YES");                  
	}
}

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

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(9);

    REP(i,n) {
        int x; cin >> x;
        if (x >=3200) v[8]++;
        else v[x/400]++;
    }

    int mn = 0, mx = 0;
    REP(i,8) {
        if(v[i] != 0) {
            mn++;
            mx++;
        }
    }
    if (mn == 0 && v[8] != 0) mn++;
    mx += v[8];

    cout << mn << " " << mx << endl; 

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n, m, x, i, y=0, z=0;
    
    scanf("%d%d%d", &n, &m, &x);

    int a[m];
    
    for(i=0;i<m;i++){
        scanf("%d", &a[i]);
        if(a[i]<x){
            y = y+1;
        }
        else if(a[i>x]){
            z = z+1;
        }
    }

    if(y>z){
        printf("%d", z);
    }
    else{
        printf("%d", y);
    }

    return 0;
}

Measured memory_bytes: 128
# https://beta.atcoder.jp/contests/abc095/tasks/abc095_b


def solve():
    n, x = map(int, input().split())
    m = [int(input()) for _ in range(n)]
    min_donut = min(m)
    x -= sum(m)
    print(n + x // min_donut)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
pre_ai = A[0]
for i in range(1, N):
    ai = A[i]
    over = max(pre_ai + ai - x, 0)
    ans += over
    pre_ai = max(ai - over, 0)
print(ans)

Measured memory_bytes: 85880
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  long long N, Q, R;
  long long ans = pow(10, 12) + 1;
  cin >> N;
  rep(i, sqrt(N)+1){
    Q = N / (i+1);
    R = N % (i+1);
    if (R == 0) ans = min(ans, i + Q - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
int xorcount( string str ){
	int s = str.size();
	int res = 0;
	res += modpow( 3, s-1 );
	int pos = -1;
	for(int i=1;i<str.size();i++){
		if( str[i]== '1'){
			pos = i;
			break;
		}
	}
	if( pos == -1){
		return res+2;
	}
	else{
		return ( res + xorcount( str.substr(pos,s-pos) ) * 2 )%inf;
	}
}
signed main(){
	string l;
	cin>> l;
	reverse(l.begin(),l.end());
	int s = l.size();
	int ans = 0;
	if( l[0] == '1' ) ans = 3; else ans = 1;
	for(int i=1;i<s;i++){
		if( l[i] == '1'){
			ans = 2*ans + modpow(3,i);
			ans %= inf;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    set<char> a,b, both;
    for (int j = 0; j <= i; ++j)
      a.insert(s[j]);
    
    for (int j = i+1; j < n; ++j)
      b.insert(s[j]);

    set_intersection(a.begin(), a.end(),
                     b.begin(), b.end(),
                     inserter(both, both.end()));
    ans = max(ans, (int)both.size());
  }
  cout << ans << "\n";
}


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



int main()
{
	int flag=0;
	string s;
	cin>>s;
	if(s[2]==s[3]){
		if(s[4]==s[5]){
			flag=1;
		}
	}
	if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e9+7;
const int N = 2e5+10;
const long long inf= 1e18;
 
ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}
 
 
void solve()
{
   int x;cin>>x;
   int f=0;
   loop(i,-900,900)
   {
       loop(j,-900,900)
       {
           if(power(i,5)-power(j,5)==x)
           {
               cout<<i<<" "<<j;
               f=1;
               break;
           }
       }
       if(f)break;
   }
   
 
    
}
 
int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int C = scan.nextInt();
    
    int rest;
    if(B+C < A) {rest =0;}
    else rest = B+C-A;

	
	
	System.out.println(rest);

		
	}

}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, p;
    while(cin >> n >> p, n|p){
        vector<int> v(n); int cur = 0, cnt = 0;
        int pp = p;
        while(true){
            if(p) {
                v[cur]++, p--;
                if(p == 0 && v[cur] == pp){
                    cout << cur << "\n";
                    break;
                }
            }
            else {
                p += v[cur];
                v[cur] = 0;
            }
            cur++;
            if(cur >= n) cur -= n;
        }
    }
    return 0;
}



Measured memory_bytes: 2980
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(x);
    ll p = x;
    while (true)
    {
        reps(i, 2, (ll)sqrt(p+1)+1)
        {
            if (p % i == 0) goto end;
        }
        break;
        end:;
        ++p;
    }
    cout << p << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    string str;
    cin>>str;
    if(str[2]==str[3] && str[4]==str[5])
    {
        cout<<"Yes\n";
    }
    else cout<<"No\n";

    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::cmp;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let p: usize = input();
    let q: usize = input();
    let r: usize = input();
    println!("{}",cmp::min(p+q,cmp::min(q+r,r+p)));
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n,m,i,j,k,s;
    scanf("%d%d",&n,&m);
    k=sqrt(m);
    s=1;
    for(i=1;i<=k;i++)
    if(m%i==0)
    {
        if(m/i>=n)
            s=max(s,i);
        if(i>=n)
            s=max(s,m/i);
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	string s; cin >> s;
	int ans = mod;
	map<char, bool> m;
	rep(i, s.size())m[s[i]] = true;
	rep(i, 26) {
		char c = (char)('a' + i);
		if (!m[c])continue;
		int loop = 0;
		string str = s;
		while (true) {
			bool ok = false;
			rep(j, str.size()) if (str[j] != str[0]) ok = true;
			if (!ok) break;
			string _str = "";
			++loop;
			rep(j, str.size() - 1) {
				if (str[j] == c || str[j + 1] == c)_str += c;
				else _str += str[j];
			}
			str = _str;
		}
		ans = min(ans, loop);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int a,b;
    cin >> a >> b;
    //処理
    //出力
    cout << (a-1)*(b-1) << ENT;
    return 0;
}

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


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

int LinearSearch(int x, int S[], int N) {
	S[N] = x;
	for (int i = 0; ; i++) {
		if (S[i] == x)
			if (i < N) {
				return i;
			}
			else
				return -1;
	}

}

int main()
{
	int N, X, Y, Z;
	int a[100] = { 0 };
	int b[100] = { 0 };
	int c[100] = { 0 };
	int count = 0;
	cin >> N;
	cin >> X;
	for (int i = 0; i < X; i++) {
		cin >> a[i];
	}
	cin >> Y;
	for (int i = 0; i < Y; i++) {
		cin >> b[i];
	}
	cin >> Z;
	for (int i = 0; i < Z; i++) {
		cin >> c[i];
		if (LinearSearch(c[i], a, X) == -1)
			count++;
		else
			if (LinearSearch(c[i], b, Y) >= 0)
				count++;

		
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(); //nums
		long k = sc.nextLong(); //"pairs"
		long s = sc.nextLong(); //sum
		
		long filler = s==1000000000?1:s+1;
		
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0; i < n; i++)
		{
			if(i>0)sb.append(" ");
			if(i < k)
			{
				sb.append(s);
			}
			else
			{
				sb.append(filler);
			}
		}
		System.out.print(sb);

	}

}


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

int main(){
  int n;
  cin >> n;
  int sum = 0;
  bool f = true;

  for(int i=0;i<n;i++){
    char c;
    int x;
    cin >> c >> x;
    if(c=='(')sum += x;
    else sum -= x;
    if(sum<0)f = false;
  }

  if(sum!=0)f = false;

  cout << (f?"YES":"NO") << endl;
}

Measured memory_bytes: 1160
#include <iostream>

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

using namespace std;

int main()
{
  int n, y;
  cin >> n >> y;
  int ta;
  bool ok = false;
  rep(a, n)
  {
    ta = 10000 * a;
    rep(b, n)
    {
      int c = n - a - b;
      if(c >=0 && (ta + (b * 5000) + (c * 1000)) == y)
      {
        ok = true;
        printf("%d %d %d\n", a, b, c);
        break;
      }
    }
    if(ok) break;
  }
  if(!ok)
    cout << "-1 -1 -1" << endl;

  return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B

main = getLine >> breads >>= print . solve

solve :: [Int] -> Int
solve = check . filter (\x -> length x > 1) . group . sortBy (flip compare)
    where
        check (x : y : _)
            | length x > 3 = head x * head x
            | otherwise = head x * head y
        check (x : _)
            | length x > 3 = head x * head x
            | otherwise = 0
        check _ = 0
        
breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 15740
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc165_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000



int main() {
    int k, a, b;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);
    for(int i=a; i<=b; i++) {
        if(i%k==0) {
            printf("OK\n");
            return 0;
        }
    }
    printf("NG\n");
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=10000010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int dp[1010][1010];
int dfs(int i,int u,int s){
	if(i==10){
		if(u==0&&s==0){
			return 1;
		}else{
			return 0;
		}
	}
	int ret=0;
	ret+=dfs(i+1,u-1,s-i);
	ret+=dfs(i+1,u,s);
	return ret;
}
int main(){
	int n,s;
	while(cin>>n>>s,n+s){
		cout<<dfs(0,n,s)<<endl;
	}
}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.*;
public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        String s = reader.readLine();
        
        String arr[]=s.split(" ");
        
        int a = Integer.valueOf(arr[0]);
   
        System.out.println(3 * a * a);
        
        
    }

}





Measured memory_bytes: 21204
#!/usr/bin/env python3
n, k = map(int, input().split())

num = set()

for i in range(k):
  d = int(input())
  tmp = [int(x) for x in input().split()]
  for j in range(d):
    num.add(tmp[j])
  # print(num)

print(n- len(num))

Measured memory_bytes: 9204
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[2*n];
    for(int i = 0; i < 2 * n; i++){
        cin >> a[i];
    }
    sort(a,a+2*n);
    int ans = 0;
    for(int i = 0; i < 2 * n; i += 2){
        ans += a[i];
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
	int isprime(int n){
		for(int i=2;i*i<=n;i++){
			if(n%i==0)return 0;
		}
		return 1;
	}
	int main(){
		int v,k;
		while(1){
			scanf("%d",&v);
			if(v==0)break;
			for(k=v;k>=0;k--){
				if(isprime(k)==1 && isprime(k-2)==1){
					printf("%d %d\n",k-2,k);
					break;
				}
			}
		}
		return 0;
	}

Measured memory_bytes: 2728
#include<iostream>
#include <stdlib.h> 
using namespace std;

int main()
{
	int size;
	cin >> size;
	int a[size];
	for(int i=0;i<size;i++)
		cin >> a[i];
	int maxAbs=0;
	for(int i1=1;i1<size;i1++)
		for(int i2=0;i2<i1;i2++)
			if(abs(a[i1]-a[i2])>maxAbs)
				maxAbs=abs(a[i1]-a[i2]);
	cout << maxAbs;
	return 0;
}

Measured memory_bytes: 256
/*

Code for problem A by cookiedoth
Generated 07 Jun 2020 at 03.00 PM


█▒▒▒▒▒▒▒▒▒
10%
███▒▒▒▒▒▒▒
30%
█████▒▒▒▒▒
50%
███████▒▒▒
70%
██████████
100%

¯\_(ツ)_/¯
^_^
-_-

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int B = 60;

struct gauss : vector<ll> {
	gauss() {
		resize(B);
	}

	ll add(ll x, int put) {
		for (int i = B - 1; i >= 0; --i) {
			if ((x >> i) & 1) {
				if ((*this)[i]) {
					x ^= (*this)[i];
				} else {
					if (put) {
						(*this)[i] = x;
						break;
					}
				}
			}
		}
		return x;
	}
};

const int mx = 210;
int n;
ll a[mx];

void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	string s;
	cin >> s;
	gauss G;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '0') {
			G.add(a[i], 1);
		} else {
			if (G.add(a[i], 0)) {
				cout << 1 << '\n';
				return;
			}
		}
	}
	cout << 0 << '\n';
}

signed main() {
	fast_io();
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
}


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

using namespace std;

int main(){
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  // xがkの倍数...xがkで割り切れる
  // aをkで割った商が、bをkで割った商と異なる
  if(a%k==0||b%k==0||(b/k)-(a/k)>=1){
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
N,C = gets.split.map(&:to_i)
ss = (0...C).map{ [] }
N.times {
  s,t,c = gets.split.map(&:to_i)
  ss[c-1] << [s,0]  
  ss[c-1] << [t,1]
}
sss = []
ss.each{ |ss| 
  ss.sort! 
  (0...ss.size).reverse_each{ |i|
    if i+1 < ss.size && ss[i][0] == ss[i+1][0]
      ss.slice!(i,2)
    end
  }
  ss.each{ |u,v|
    sss << [v == 0 ? u-0.5 : u, v]
  }  
}
sss.sort!
ans = 0
s = 0
sss.each{ |u,v|
  if v == 0
    s += 1
    ans = [ans, s].max
  else
    s -= 1
  end  
}
p ans


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = int(2000) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;

int n, k;

ld binpow (ld a, ll n){
    if (n == 0) return 1;
    if (n & 1) return binpow(a, n - 1) * a;
    else {
        int b = binpow(a, n / 2);
        return b * b;
    }
}

int main (){
    cin >> n >> k;
    ld ans = 0;
    for (int i = 1; i <= n; ++i){
        if (i < k){
            ld cur = i;
            ll kol = 0;
            while (cur < k){
                cur *= 2;
                kol++;
            }
            ld kek = binpow(2.0, kol);
            kek = kek * 1.0 * n;
            ans += (1.0 / kek);
        } else ans += (1.0 / n);
    }
    cout << fixed << setprecision(12) << ans << "\n";
}


Measured memory_bytes: 256
n,k = map(int,input().split())

if k%2 == 1:
    cnts = []
    for i in range(1,n+1):
        if i % k == 0:
            cnts.append(i)
    print(len(cnts)**3)
else:
    k0 = 0
    k1 = 0
    for i in range(1,n+1):
        if i % k == 0:
            k0 += 1
        elif i %k == k//2:
            k1 += 1
    print(k0**3 + k1**3)

Measured memory_bytes: 52080
n = int(input())
v = list(map(int,input().split()))
v1 = []
v2 = []
for i in range(n):
    if i%2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

sv1 = set(v1)
sv2 = set(v2)
if len(sv1) == 1 and len(sv2) == 1 :
    if sv1 != sv2:
        print(0)
    else:
        print(n//2)
else:
    dic1 = { i : 0 for i in sv1}
    dic2 = { i : 0 for i in sv2}
    for i in v1:
        dic1[i] = dic1[i] + 1
    for i in v2:
        dic2[i] = dic2[i] + 1
    #print(dic1, dic2)
    dic1 = sorted(dic1.items(), key=lambda x: -x[1])
    dic2 = sorted(dic2.items(), key=lambda x: -x[1])
    if dic1[0][0] != dic2[0][0]:
        print(n-(dic1[0][1]+dic2[0][1]))
    else:
        if len(dic1)==1:
            print(n- (dic1[0][1]+dic2[1][1]))
        elif len(dic2)==1:
            print(n- (dic1[1][1]+dic2[0][1]))
        elif dic1[1][1]+dic2[0][1] >= dic1[0][1]+dic2[1][1] :
            print(n- (dic1[1][1]+dic2[0][1]))
        else :
            print(n- (dic1[0][1]+dic2[1][1]))


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

int main() {
    int r, c; cin >> r >> c;
    vector<vector<int>> rc(r+1, vector<int>(c+1));
    vector<int> vec_c(c);
    rep(i, r) {
        int sum = 0;
        rep(j, c) {
            cin >> rc.at(i).at(j);
            sum += rc.at(i).at(j);
            vec_c.at(j) += rc.at(i).at(j);
        }
        rc.at(i).at(c) = sum;
    }
    rep(i, r) {
        rep(j, c+1) {
            cout << rc.at(i).at(j);
            if (j != c) {
                cout << " ";
            }
        }
        cout << endl;
    }
    int sum = 0;
    rep(i, c) {
        cout << vec_c.at(i);
        sum+= vec_c.at(i);
            cout << " ";
    }
    cout << sum <<endl;
}


Measured memory_bytes: 3148
H, W = map(int, input().split(' '))
masu = [input() for i in range(H)]
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1, 1, 1]
ans = []
for i in range(H):
    a = []
    for j in range(W):
        if (masu[i][j] == '#'):
            a.append('#')
            continue
        cnt = 0
        for d in range(len(dx)):
            x = i + dx[d]
            y = j + dy[d]
            if (x < 0 or H <= x):
                continue
            if (y < 0 or W <= y):
                continue
            if (masu[x][y] == '#'):
                cnt += 1
        a.append(str(cnt))
    ans.append(a)
for b in ans:
    print("".join(b))


Measured memory_bytes: 3188
fn main() {
    let x: i32 = read();
    let a: i32 = read();
    let b: i32 = read();

    if (a - x).abs() > (b - x).abs() {
        println!("B");
    } else {
        println!("A");
    }
}



use std::io::*;
use std::str::FromStr;

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

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
	string s;
	int c_idx = 0;
	cin >> s;
	if(s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	for(int i = 2; i < s.length() - 1; i++) {
		if(s[i] == 'C') {
			if(c_idx != 0) {
				cout << "WA" << endl;
				return 0;
			} else {
				c_idx = i;
			}
		}
	}
	if(c_idx == 0) {
		cout << "WA" << endl;
		return 0;
	}
	for(int i = 0; i < s.length(); i++) {
		if(i == 0 || i == c_idx) {
			continue;
		} else if('A' <= s[i] && s[i] <= 'Z') {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
li = [list(map(int,input().split())) for i in range(n)]
lis.sort(key=lambda x:x[1],reverse=True)
li.sort()
ans = 0
for lisx,lisy in lis:
  for lix,liy in li:
    if lisx < lix and lisy < liy:
      ans +=1
      li.remove([lix,liy])
      break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

// クイックソート用の昇順関数
int cmpnum(const void * n1, const void * n2) 
{
	if (*(long *)n1 > *(long *)n2)
		return 1;
	else if (*(long *)n1 < *(long *)n2)
		return -1;
	else
		return 0;
}

int main(void)
{
	long N;
	scanf("%ld", &N);
	long d[N];
	long count = 0;
	long arc = N / 2;
	long abc = (N / 2) - 1;
	long i = 0;
	while (i < N)
	{
		scanf("%ld", &d[i]);
		i++;
	}
	qsort(d, sizeof(d) / sizeof(d[0]), sizeof(long), cmpnum);
	printf("%ld\n",d[arc] - d[abc]);
}


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

int main()
{
    int n, mx = -1, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        int f = 0, j = i;
        while(j%2 == 0){f++;j/=2;}
        if(mx < f)
        {
            mx = f;
            ans = i;
        }
    }
    printf("%d", ans);
    return 0;
}


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

int main(void){
    int K;
    string S;
    cin >> K >> S;
    if(S.size() <= K){
        cout << S << endl;
        return 0;
    }
    for(int i = 0 ; i < K ; i++){
        cout << S.at(i);
    }
    cout << "..." << endl; 
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, l;
    cin >> n >> l;
    vs s(n);
    rep(i, n) cin >> s[i];
    VSORT(s);
    string ans;
    rep(i, n) ans += s[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            long x = long.Parse(s[0]);
            long y = long.Parse(s[1]);
            long z = long.Parse(s[2]);

            //偶数同士の組み合わせと奇数同士の組み合わせなので、mC2とnC2を求める
            
            Console.WriteLine(z + " " + x + " " + y);
        }
    }


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

int main() {
  int N;
  scanf("%d", &N);

  vector<vector<int>> S(2, vector<int>(N + 1, 0));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      int A;
      cin >> A;
      S.at(i).at(j + 1) = S.at(i).at(j) + A;
    }
  }
  
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int sum = 0;
    int left = 0;
    int right = i;
    sum += S.at(0).at(right) - S.at(0).at(left);
    sum += S.at(1).at(N) - S.at(1).at(right - 1);
    ans = max(ans, sum);
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
ll f(ll a,ll b){
  ll res = 0;
  while(a>0||b>0){
    res++;
    a /= 10;
    b /= 10;
  }
  return res;
}
signed main(){
  cioacc();
  ll n;
  cin >> n;
  ll ans = LLONG_MAX;
  FOR(i,1,sqrt(n)+1){
    if(n%i==0){
      ans = min(ans,f(i,n/i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
s_dict = {}
ans = ['{'] * N

for i in S:
    if i in s_dict:
        s_dict[i] += 1
    else:
        s_dict[i] = 1

s_dict = sorted(s_dict.items(), key = lambda x: -x[1])


max_count = s_dict[0][1]
for i in range(len(s_dict)):
    if s_dict[i][1] == max_count:
        ans[i] = s_dict[i][0]
    else:
        break

ans.sort()
for i in ans:
    if i == '{':
        break
    else:
        print(i)

Measured memory_bytes: 110800
#include <stdio.h>

int main() {
	
	int n, i, j, k, v;
	int a[100] = {0};

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

	for (i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;

		for(k = 0; k < n; k++) {
			if (k == 0) {
				printf("%d", a[k]);
			}
			else {
				printf(" %d", a[k]);
			}
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 612
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N =1e5+3;


  
int main()
{
    
     ll n;
     lscf(n);
     
     ll ans=0;
     
    for(ll i=2;i*i<n;i++)
    {
       
        if(n%i==0)
        {

            ll ctr=0;
            
            while(n%i==0)
            {
                n/=i;
                ctr++;
            }
            
            ll st=1;
            
            while(ctr>=st)
            {
                ans++;
                ctr-=st;
                st++;
            }
       
        }
        
    }
    
    if(n>1)
    ans++;

   lprin(ans);
     
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w,ans=0;
    cin >> h >> w;
    char a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) cin >> a[i][j];
    }
    vector<vector<int>> b(h,vector<int> (w));
    for(int k=0;k<h;k++){
        for(int i=0;i<w;){
            int j = i;
            while(j<w&&a[k][j]==a[k][i]) j++;
            if(a[k][i]=='#') b[k][i] = 0;
            else{
                for(int l=i;l<j;l++) b[k][l] = j-i;
            }
            i = j;
        }
    }
    vector<vector<int>> c(h,vector<int> (w));
    for(int k=0;k<w;k++){
        for(int i=0;i<h;){
            int j = i;
            while(j<h&&a[j][k]==a[i][k]) j++;
            if(a[i][k]=='#') c[i][k] = 0;
            else{
                for(int l=i;l<j;l++) c[l][k] = j-i;
            }
            i = j;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) ans = max(ans,b[i][j]+c[i][j]-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#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,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const ll MAX_N = 10000;
static const ll MAX_M = 10000;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    int N, ans = 0, cnt = 0, sum = 0;
    cin >> N;
    vector<int> W;
    for(int i = 0; i < N; i++){
        int tmp; cin >> tmp;
        W.push_back(tmp);
        sum += tmp;
    }
    int tsum = 0;
    REP(i,N){
        tsum += W[i];
        if((double)sum/2 == tsum){
            p(0);
            break;
        }else if((double)sum/2 < tsum){
            ans = min(fabs(sum - 2 * tsum), fabs(sum - 2 * tsum + 2 * W[i]));
            p(ans);
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE
//ABS, task 09, 2020/04/11
//ms, ac
/*
*/

int main(void){
  int N;

  cin >>N;

  if(N/100==7 || (N%100)/10==7 || N%10==7){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}


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

int main() {
	string N; cin >> N;
	int S = 0; int SumN = stoi(N);
	for (int i = 0; i < N.size(); i++) {
		int tmp = N[i] - '0';
		S += tmp;
	}
	cout << (SumN % S == 0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
ll dp[100002][101];
int main() 
{   fastio;
    int n,W;
    cin>>n>>W;
    vi w(n+1),v(n+1);
    range(i,1,n+1)cin>>w[i]>>v[i];
    range(i,0,n+1){
      range(j,0,W+1){
        if(i==0||j==0){
          dp[i][j]=0;
          continue;
        }
        dp[j][i]=dp[j][i-1];
        if(j-w[i]>=0)
          dp[j][i]=max(dp[j][i-1],dp[j-w[i]][i-1]+v[i]);
      }
    }
    cout<<dp[W][n];
}

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

int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

const int mod = 1000000007;
int n, m, lst;

struct Matrix {
    int a[4][4];
    Matrix() { memset(a, 0, sizeof a); }
    void init() {
        for (int i = 0; i < 4; i++)
            a[i][i] = 1;
    }
    friend Matrix operator* (Matrix a, Matrix b) {
        Matrix c;
        for (int i = 0; i < 4; i++)
            for (int j = 0; j < 4; j++)
                for (int k = 0; k < 4; k++)
                    c.a[i][j] = (c.a[i][j] + 1ll * a.a[i][k] * b.a[k][j]) % mod;
        return c;
    }
}ans, a, b;

Matrix mpow(Matrix a, int k) {
    Matrix re;
    re.init();
    for (; k; k >>= 1, a = a * a)
        if (k & 1) re = re * a;
    return re;
}

int main() {
    n = read(), m = read();
    a.a[0][0] = 1, a.a[0][1] = 1, a.a[0][2] = 1, a.a[0][3] = 1;
    a.a[1][0] = 0, a.a[1][1] = 1, a.a[1][2] = 0, a.a[1][3] = 1;
    a.a[2][0] = 0, a.a[2][1] = 0, a.a[2][2] = 1, a.a[2][3] = 1;
    a.a[3][0] = 1, a.a[3][1] = 1, a.a[3][2] = 1, a.a[3][3] = 2;
    b.a[0][0] = 1, b.a[0][1] = 1, b.a[0][2] = 1, b.a[0][3] = 1;
    b.a[1][0] = 0, b.a[1][1] = 1, b.a[1][2] = 0, b.a[1][3] = 1;
    b.a[2][0] = 0, b.a[2][1] = 0, b.a[2][2] = 1, b.a[2][3] = 1;
    b.a[3][0] = 0, b.a[3][1] = 0, b.a[3][2] = 0, b.a[3][3] = 1;
    ans.init();
    for (int i = 1; i <= m; i++) {
        int x = read();
        ans = (i > 1 ? ans * b * mpow(a, x - lst - 1) : ans * mpow(a, x - lst));
        lst = x;
    }
    ans = ans * b * mpow(a, n - lst - 1);
    cout << ans.a[0][3] << endl;
}

Measured memory_bytes: 384
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
char w[14][14] = {};
LL ans = 0;
void dfs(LL x, LL y) {
	w[x][y] = '0';
	if (x < 11)
		if(w[x+1][y]=='1')
		dfs(x + 1, y);
	if (y < 11)
		if (w[x][y+1] == '1')
		dfs(x, y + 1);
	if (x > 0)
		if (w[x - 1][y] == '1')
		dfs(x - 1, y);
	if (y > 0)
		if (w[x][y-1] == '1')
		dfs(x, y - 1);
}
int main() {
	while (cin >> w[0][0]) {
		ans = 0;
		for (int i = 0; i < 12; i++)
			for (int j = 0; j < 12; j++) {
				if(!(i==0&&j==0))
				cin >> w[i][j];
			}	
		for (int i = 0; i < 12; i++)
			for (int j = 0; j < 12; j++) {
				if (w[i][j] == '1') {
					ans++; dfs(i, j);
				}
			}
	
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main()
{
    double N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i >= K)
        {
            ans += 1 / N;
        }
        else
        {
            ans += pow(0.5, ceil(log2(K / double(i)))) / N;
        }
    }
    cout << setprecision(15) << fixed << ans << endl;
}


Measured memory_bytes: 512
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
ll fact[250001];
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin.sync_with_stdio(false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        ll n,m;cin>>n>>m;
        ll ans=(n*(n-1))/2+(m*(m-1))/2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	string T;
	cin >> T;

	int result = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] != T[i])
		{
			result++;
		}
	}

	cout << result;
	
	return 0;
}


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 2e5+7;

int main(){
	setIO();
	int n;
	string s;
	cin >> n >> s;
	int w = 0, r = 0;
	for (int i = 0; i < n; i++){
		s[i] == 'R'?r++:w++;
	}
	if (!w || !r) cout << "0\n";
	else{
		int ans = 0;
		for (int i = 0; i < r; i++)
			if (s[i] == 'W')
				ans++;
		cout << ans << endl;
	}
	//RRRRWWWW
}

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

Pr = list(map(int, input().split()))
I = list(map(int, input().split()))
Po = []

def Rec(Pr,I):
  a = I.index(Pr[0])
  if a >= 1:
    Rec(Pr[1:a+1],I[0:a])
    if a < len(Pr)-1:
      Rec(Pr[a+1:],I[a+1:])
    Po.append(Pr[0])
  else:
    A = []
    A.append(Pr[0])
    if len(Pr) > 1:
      Rec(Pr[1:],I[1:])
    while A != []:
      Po.append(A.pop())

Rec(Pr, I)

print(" ".join(map(str, Po)))


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;

signed main(){
	cin>>S;
	if(S.back()=='s'){
		cout<<S<<"es"<<endl;
	}
	else{
		cout<<S<<"s"<<endl;
	}
	return 0;
}


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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    int k; string s;
    cin >> k >> s;
    for(int i = 0; i < min(k,(int)s.size()); i++) cout << s[i];
    if(k < s.size()) cout << "...";
    cout << endl;
    return 0;
}



Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, ans = 0;
    string A, B, C;
    cin >> N >> A >> B >> C;
    REP(i, N) {
        map<char, int> m;
        m[A[i]]++;
        m[B[i]]++;
        m[C[i]]++;
        ans += m.size() - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int s = sc.nextInt();
    
    //0<=x,y,z<=k
	int sum = 0;
    for(int x=0 ; x<=k ; x++){
      for(int y=0 ; y<=k ; y++){
        int z = s-(x+y);
          if( (0<=z) && (z<=k) ){
            sum++;
          
        }
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22096