akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    int ans = 0;
    for (int i = 0; i < (int)s.length();) {
        int j = i;
        while (j < (int)s.length() && s[i] == s[j]) {
            j++;
        }
        ans++;
        i = j;
    }

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


Measured memory_bytes: 512
S = input()
alphabets = set(chr(ord("a") + x) for x in range(26))

def F_short(S):
  se = alphabets - set(S)
  x = min(se)
  return S + x

def F_long(S):
  if S == "".join(sorted(alphabets, reverse=True)):
    return "-1"
  
  cand = []
  S = list(S)
  while True:
    x = S[-1]
    if not cand or (x > max(cand)):
      cand.append(S.pop())
      continue
    y = min(ch for ch in cand if ch > x)
    return "".join(S[:-1]) + y

L = len(S)
ans = F_short(S) if L < 26 else F_long(S)
print(ans)

Measured memory_bytes: 3064
module Main where

import Data.Functor

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [w,h,x,y,r] <- getInts
  ; putStrLn (check' (w,h,x,y,r))
  }

check :: (Int,Int,Int,Int,Int) -> String
check (w,h,x,y,r)
  | x < r     = "No"
  | y < r     = "No"
  | x > w-r   = "No"
  | y > h-r   = "No"
  | otherwise = "Yes"

check' :: (Int,Int,Int,Int,Int) -> String
check' (w,h,x,y,r)
 | r <= x && x <= w - r && r <= y && y <= h - r = "Yes"
 | otherwise                                    = "No"

Measured memory_bytes: 3652
/**
 *    author:  tourist
 *    created: 29.09.2018 15:30:23       
**/
#include <bits/stdc++.h>

using namespace std;

void err() {
  cout << -1 << '\n';
  exit(0);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  if (s[n - 1] != '0') {
    err();
  }
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[n - 2 - i]) {
      err();
    }
  }
  if (s[0] != '1') {
    err();
  }
  int last = 0;
  cout << 1 << " " << 2 << '\n';
  for (int i = 1; i < n - 1; i++) {
    cout << last + 1 << " " << i + 2 << '\n';
    if (s[i] == '1') {
      last = i + 1;
    }
  }
  return 0;
}


Measured memory_bytes: 1616
#include <iostream>
using namespace std;
int main(void){
	int n;
	cin>>n;
	int min,max,input;
	long long int sum;
	cin>>min;
	max=min;
	sum=min;
	for(int i=1;i<n;i++){
		cin>>input;
		sum=sum+input;
		if(min>input){
			min=input;
		}
		if(max<input){
			max=input;
		}
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n);
    long long cum = 0;
    for (int i = 0 ;i < n ;i++) {
        cin >> a[i];
        if (i&1)
            cum -= a[i];
        else
            cum += a[i];
    }

    for (int i = 0 ;i < n ;i++) {
        cout << cum << ' ';
        cum = (a[i] - cum / 2) * 2;
    }
}


Measured memory_bytes: 3704
#include <cstdio>
#include <algorithm>
using namespace std;
int a[12],sum[12][1010];
int H,W,K,ans=2000;
char s[12][1010];
int judge(int cnt,int la,int j){//num>K 1,num<=K 0
	int i,num;
	a[cnt+1]=H;//此句很关键，事关最后的边界。
	for(i=1;i<=cnt+1;i++){
		num=sum[a[i]][j]-sum[a[i]][la]-sum[a[i-1]][j]+sum[a[i-1]][la];
		//printf("num=%d\n",num);
		if(num>K) return 1;
	}
	return 0;
}
void solve(int cnt){
	int j,tot,la;
	tot=cnt,la=0;
	for(j=1;j<=W;j++)
		if(judge(cnt,la,j))tot++,la=j-1;
	//printf("tot=%d cnt=%d\n",tot,cnt);
	if(!judge(cnt,W-1,W))ans=min(ans,tot);
}
void dfs(int step,int cnt){//step代表dfs执行步数，cnt代表对行进行切割的刀数
	//printf("step=%d cnt=%d\n",step,cnt);
	if(step==H){
		/*printf("step=%d cnt=%d\n",step,cnt);
		for(int i=1;i<=cnt+1;i++)printf("a[%d]=%d ",i,a[i]);
		printf("\n\n");*/
		//printf("cnt=%d\n",cnt);
		solve(cnt);
		return;
	}
	//以下写法对应着C(n,0),C(n,1),C(n,2),...,C(n,n-1),C(n,n)等情况
	dfs(step+1,cnt);
	a[cnt+1]=step,dfs(step+1,cnt+1);
	
}
int main(){
	int i,j;
	scanf("%d%d%d",&H,&W,&K);
	for(i=1;i<=H;i++)scanf("%s",s[i]+1);
	for(i=1;i<=H;i++)
		for(j=1;j<=W;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+s[i][j]-'0';//二维前缀和
	/*for(i=1;i<=H;i++){
		for(j=1;j<=W;j++)
			printf("%d ",sum[i][j]);
		printf("\n");
	}*/
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n,k=map(int,input().split())
a=list(map(int,input().split()))
m=0
if k==0:
    m=1
else:
    m=int(math.log2(k)+1)
lst=[0]*m
for i in range(n):
    for j in range(m):
        if a[i]&(1<<j):
            lst[j]+=1
# print(lst)

ans=0
ans2=0
for i in range(m):
    if lst[m-i-1]<=n/2 and ans+pow(2,m-i-1)<=k:
        ans+=pow(2,m-i-1)
# print(ans)
# print(ans2)
for i in range(n):
    ans2+=ans^a[i]

print(ans2)

Measured memory_bytes: 16680
/* 
    AABRA KA DABRA.. !! 
*/
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
typedef pair<int,int> pii;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){   for(int i=2; i*i<=n; i++)   if(n%i==0)  return 0;   return 1;}

int dx[]    =  { 1 ,  0,  -1,  0,  -1,  -1,  1,   1};
int dy[]    =  { 0 ,  1,  0, -1,  -1,   1,  1,  -1};
char dir[]  =  {'D','R','U','L'};

const int maxn = 200005;

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



void solve()
{
    int n,i,j,k,m;
    string s,t;
    cin>>s>>t;
    m=0;
    rep(i,sz(s))
        if(s[i]!=t[i])
            m++;
    cout<<m;
}
signed main()
{
    RAGE;    
    int t=1;
    //  cin>>t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 3888
#include<cstdio>
int pretm,prex,prey,n,tm,x,y;
bool travel(int p,int x,int y){
	if(x<0) x=-x; if(y<0) y=-y;
	if(x+y>p||(x+y+p)%2) return 0; return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d%d",&tm,&x,&y);
		if(!travel(tm-pretm,x-prex,y-prey)){
			printf("No"); return 0;
		}
		pretm=tm; prex=x; prey=y;
	}
	printf("Yes"); return 0;
}

Measured memory_bytes: 128
n = int(input())
*A, = map(int, input().split())
even = 0; odd = 0;
S = 0
for i, a in enumerate(A):
    S += a
    if i % 2 == 0 and S <= 0:
        even += -S + 1
        S = 1
    elif i % 2 == 1 and S >= 0:
        even += S + 1
        S = -1
S = 0
for i, a in enumerate(A):
    S += a
    if i % 2 == 0 and S >= 0:
        odd += S + 1
        S = -1
    elif i % 2 == 1 and S <= 0:
        odd += -S + 1
        S = 1
print(min(even, odd))

Measured memory_bytes: 14644
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    int cnt = 0;
    int buf = 0;
    for (int i=1; i<n; i++) {
        if (a.at(i) > a.at(i-1)) {
            cnt = max(cnt, buf);
            buf = 0;
        }
        else {
            buf++;
        }
    }
    cnt = max(cnt, buf);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h, w;
    cin >> w >> h;
    vector<pair<int, int>> v(h + w);
    rep(i, w) {
        int p;
        cin >> p;
        v[i] = make_pair(p, 0);
    }
    rep(i, h) {
        int q;
        cin >> q;
        v[i + w] = make_pair(q, 1);
    }
    sort(all(v));

    int zero = h + 1, one = w + 1;
    ll ans = 0;
    for (auto p : v) {
        int x = p.first;
        int k = p.second;
        if (k == 0) {
            ans += (ll)x * zero;
            one--;
        } else {
            ans += (ll)x * one;
            zero--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    string s, t; cin>>s>>t;
    int a, b; cin>>a>>b;
    string u; cin>>u;

    if(u == s) a--;
    else b--;

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF){
		a=a+b;
		int index=0;
		while(a>0&&(a=a/10)>0)
			index++;
		printf("%d\n",index+1);
	}
	return 0;
}


Measured memory_bytes: 3092
N = int(input())
S = input()

kouho = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            kouho.append(str(i)+ str(j) + str(k))

cnt = 0
for pwd in kouho:
    point = 0
    for word in S:
        if word == pwd[point]:
            point += 1
            if point == 3:
                cnt += 1
                break

print(cnt)
        



Measured memory_bytes: 41180
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        long n=scanner.nextInt(),a[]=new long[(int)n+1];
        for(int i=2,k=i;i<=n;i++,k=i)for(int j=2;j<=i&&k>1;j++)for(;k%j==0;k/=j)a[j]++;
        System.out.println(java.util.Arrays.stream(a).reduce(1,(l,m)->l*(m+1)%1000000007));
    }
}

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

using namespace std;

int main(){

vector<int> ans {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k; cin>>k;
cout<<ans[k-1];
    return 0;
}


Measured memory_bytes: 384
N = int(input())
waku = []
for i in range(N):
    a,b = map(int, input().split())
    waku.append([b,a])
waku1 = sorted(waku)
ans = True
p1 = p2 = 0
for i,j in waku1:
    p1 += j
    if p1 > i:
        ans = False
        break

print("Yes" if ans else "No")

Measured memory_bytes: 37948
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static long K = Long.parseLong(sc.next());
	static long A = Long.parseLong(sc.next());
	static long B = Long.parseLong(sc.next());
	public static void main(String[] args) {
		if (B-A <= 2 || K-A <= 0) {
			System.out.println(K+1);
			return;
		}
//		long trade = (K+1)/(A+2);
		// 一度Aまでビスケットを増やしてしまえば何回でも叩ける
		long trade = (K+1 - A) / 2;
//		System.out.println(trade);
//		System.out.println(B-A-2);
		long ans = trade * (B-A-2) + K + 1;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef vector<ll> vl;
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll q;cin>>q;
  rep(i,q){
    ll x,y;
    cin>>x>>y;
    if(x>y)swap(x,y);
    ll ans=x-1;
    long double k=sqrt(x*y-0.75)-x+0.5;
    ll lk=k;
    ans+=k+(x*y-1)/(x+k);
    if(x==y)cout<<ans<<endl;
    else cout<<ans-1<<endl;
  }
}


Measured memory_bytes: 3660
typedef int ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll k,a,b;
    std::cin >> k;
    std::cin >> a>>b;
    
    for (int i = a; i <= b; i++) {
        if(i%k==0){
            std::cout << "OK" << std::endl;
            return 0;
        }
    }
    std::cout << "NG" << std::endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N;
  cin>>N;
  ll ans[100];
  ans[0]=2;
  ans[1]=1;
  for (int i(2);i<=N;i++){
    ans[i]=ans[i-1]+ans[i-2];
  }
  cout << ans[N] << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll X;
    cin >> n >> X;
    ll x;
    cin >> x;
    ll ans = abs(X - x);
    rep(i,n-1){
        cin >> x;
        ans = gcd(ans, abs(X - x));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int s;
    cin >> s;
    int h = s / 3600;
    s %= 3600;
    int m = s / 60;
    s %= 60;
    cout << h << ':' << m << ':' << s << endl;

    return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int R; cin >> R;
    if(R < 1200) cout << "ABC" << endl;
    else if(R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(raw_input())

f=[]
for _ in range(N):
  f.append(map(int,raw_input().split(' ')))

p=[]
for _ in range(N):
  p.append(map(int,raw_input().split(' ')))

s=float('-inf')
for t in range(1,1024):
  l=map(int,list(bin(t)[2:].zfill(10)))
  tmp=0
  for i in range(N):
    c=0
    for t in range(10):
      if l[t]==0:
        continue
      if f[i][t]:
        c+=1

    tmp+=p[i][c]

  if tmp>s:
    s=tmp
    
print s


Measured memory_bytes: 2696
N = int(input())
if N == 0:
  print(0)
else:
  ans = ""
  x = 0
  keta = 0
  while x != N:
    if (N - x) % 2 ** (keta + 1)== 0:
      ans = "0" + ans
    else:
      ans = "1" + ans
      x += (-2) ** keta
    keta += 1
  
  print(ans)

Measured memory_bytes: 3064
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    S, T = input(str, str)
    ans = ""
    for n in range(N):
        ans += S[n] + T[n]
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3316
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        for(int i=0;i<3;i++){
            String x=scn.next();
            System.out.print(x.charAt(i));
        } 
        System.out.println();
    }
}

Measured memory_bytes: 21716
use proconio::input;

macro_rules! chmax {
    ($max_v: expr, $v: expr) => {
        if $v > $max_v {
            $max_v = $v;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    };
    let ca = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, a_i| {
            *acc += a_i;
            if *acc <= k {
                Some(*acc)
            } else {
                None
            }
        }))
        .collect::<Vec<_>>();
    let cb = std::iter::once(0)
        .chain(b.iter().scan(0, |acc, b_i| {
            *acc += b_i;
            if *acc <= k {
                Some(*acc)
            } else {
                None
            }
        }))
        .collect::<Vec<_>>();

    let mut ans = 0;
    let mut j = cb.len() - 1;
    for (i, &ca_i) in ca.iter().enumerate() {
        while ca_i + cb[j] > k {
            j -= 1;
        }
        chmax!(ans, i + j);
    }

    // 二分探索 (superslice の upper_bound) を使う方法
    // for i in 0..=n {
    //     let x = k - ca[i];
    //     if x < 0 {
    //         continue;
    //     }
    //     let j = cb.upper_bound(&x);
    //     chmax!(ans, i + j - 1);
    // }

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


Measured memory_bytes: 10396
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
ll a[65],b[1005];
int n;
char s[1005];
void Insert(ll x){
	Rep(i,60,0)
		if (x&(1ll<<i))
			if (!a[i]) a[i]=x,x=0;
			else x^=a[i];
}
bool In(ll x){
	Rep(i,60,0) x=min(x,x^a[i]);
	return x==0;
}
void solve(){
	scanf("%d",&n);
	For(i,0,60) a[i]=0;
	For(i,1,n) scanf("%lld",&b[i]);
	scanf("%s",s+1);
	Rep(i,n,1)
		if (s[i]=='0') Insert(b[i]);
		else if (!In(b[i])) return puts("1"),void(0);
	puts("0");
}
int main(){
	int T;
	scanf("%d",&T);
	while (T--) solve();
}
/*
>_<
*/ 

Measured memory_bytes: 3688
Imports System.Collections.Generic

Module Module1
    Dim ans As Long = 0

    Function judge(n As Long) As Long
        Dim dic As New HashSet(Of Long)
        Dim res As Long = 0
        Dim i = 1

        Do While i ^ 2 <= n
            If n Mod i = 0 Then
                dic.Add(i)
                dic.Add(n \ i)
            End If
            i = i + 1
        Loop

        If dic.Count = 8 Then res = 1
        Return res
    End Function

    Sub Main()
        Dim N As Long = Console.ReadLine()

        For i As Long = 1 To N Step 2
            ans = ans + judge(i)
        Next

        Console.WriteLine(ans)
    End Sub

End Module

Measured memory_bytes: 22224
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define MAX 1400
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;}

struct Rectangle{ll height; ll pos;};

ll getLargestRectangle(ll size, vll buffer) {
  stack<Rectangle> S;
  ll maxv = 0;
  buffer[size] = 0;

  REP(i, size+1) {
    Rectangle rect;
    rect.height = buffer[i];
    rect.pos = i;
    if (S.empty()) {
      S.push(rect);
    } else {
      if (S.top().height < rect.height) {
        S.push(rect);
      } else if (S.top().height > rect.height) {
        ll target = i;
        while(!S.empty() && S.top().height >= rect.height) {
          Rectangle pre = S.top(); S.pop();
          ll area = pre.height * (i-pre.pos);
          chmax(maxv, area);
          target = pre.pos;
        }
        rect.pos = target;
        S.push(rect);
      }
    }
  }
  return maxv;
}

ll H, W;
vvll buffer(MAX, vll(MAX));
vvll T(MAX, vll(MAX));

ll getLargestRectangle() {
  REP(j, W) {
    REP(i, H) {
      if (buffer[i][j]) {
        T[i][j] = 0;
      } else {
        T[i][j] = (i>0) ? T[i-1][j] + 1: 1;
      }
    }
  }
  ll maxv = 0;
  REP(i, H) chmax(maxv, getLargestRectangle(W, T[i]));
  return maxv;
}

int main() {
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> buffer[i][j];
  cout << getLargestRectangle() << endl;
  return 0;
}



Measured memory_bytes: 33340
N = int(input())
yen6, yen9 = [1], [1]
[x for x in yen6 if yen6[-1] <= N and (yen6.append(yen6[-1]*6) or True)]
[x for x in yen9 if yen9[-1] <= N and (yen9.append(yen9[-1]*9) or True)]

yen = sorted(yen6[1:-1] + yen9[1:-1])
dp = [0]
for i in range(1, N+1):
    temp = 1 + dp[i-1]
    for y in yen:
        if i < y:
            break
        if temp > 1 + dp[i-y]:
            temp = 1 + dp[i-y]
    dp.append(temp)

print(dp[-1])

Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<string>

int assign(int num[3]);			// 配列に値を代入する処理
int sort(int num[3]);			// 配列を昇順に並び替える処理
std::string makeAns(int num[3]);// 出力文字列を作成する処理

int main()
{
	int num[3];
	std::string ans;

	assign(num);
	sort(num);
	ans = makeAns(num);

	std::cout << ans << std::endl;
}

int assign(int num[3])
{
	for (int i = 0;i < 3;i++)
	{
		std::cin >> num[i];
	}

	return *num;
}

int sort(int num[3])
{
	std::sort(num, num + 3);
	return *num;
}

std::string makeAns(int num[3])
{
	std::string ans = std::to_string(num[0]) + ' ' + std::to_string(num[1]) + ' ' + std::to_string(num[2]);
	return ans;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

const string YES = "YES";
const string NO = "NO";

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b)
{
    vector<ll> cnt(N);
    for (int i = 0; i < M; i++)
    {
        cnt[a[i]-1]++;
        cnt[b[i]-1]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (cnt[i] % 2 != 0)
        {
            cout << NO << endl;
            return;
        }
    }

    cout << YES << endl;
    return;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
    }
    solve(N, M, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 2560
int main()
{
	int a;
	int b;
	int out1;
	int out2;
	
	/* ????????? */
	a = 0;
	b = 0;
	out1 = 0;
	out2 = 0;
	
	/* ???????????????????¨????????????????????????? */
	scanf("%d %d", &a, &b );
	
	out1 = a * b;
	out2 = ( a + b ) * 2;
	
	/* ?????? */
	printf("%d %d\n", out1, out2 );
	
	return 0;
}

Measured memory_bytes: 596
package main

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

func main() {
	sc := NewScanner()

	s := sc.NextLine()
	t := sc.NextLine()

	if s == t {
		fmt.Printf("Yes\n") // output for debug
		return
	}

	for i := 0; i < len(s); i++ {
		tmp1 := s[0:i]
		tmp2 := s[i:len(s)]
		r := tmp2 + tmp1
		if r == t {
			fmt.Printf("Yes\n") // output for debug
			return
		}
	}
	fmt.Printf("No\n")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

typedef long long ll;
const ll N = 1e5;

int n;
int a[N+5];

int main()
{
    std::ios::sync_with_stdio(false);
    while ( cin >> n )
    {
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        sort(a, a+n);

        deque<int> dq;

        int l = 0;
        int r = n-1;
        int left = a[l];
        int right = a[r];

        ll ans = abs(a[l]-a[r]);

        dq.push_front(a[l]);
        dq.push_back(a[r]);
        l++;
        r--;

        while (l <= r)
        {
            int lfront = abs(a[l] - left);
            int lback = abs(a[l] - right);
            int rfront = abs(a[r] - left);
            int rback = abs(a[r] - right);

            //cout << lfront << " " << lback << endl;
            //cout << rfront << " " << rback << endl;

            int lmx = max(lfront, lback);
            int rmx = max(rfront, rback);

            if (lmx > rmx)
            {
                if (lfront > lback)
                {
                    dq.push_front(a[l]);
                    left = a[l];
                    ans += lfront;
                }
                else
                {
                    dq.push_back(a[l]);
                    right = a[l];
                    ans += lback;
                }

                l++;
            }
            else
            {
                if (rfront > rback)
                {
                    dq.push_front(a[r]);
                    left = a[r];
                    ans += rfront;
                }
                else
                {
                    dq.push_back(a[r]);
                    right = a[r];
                    ans += rback;
                }
                r--;
            }
        }

        //for (int i = 0; i < n; i++)
        //{
            //cout << dq[i] << " ";
        //}
        //cout << endl;

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
N,Y = map(int,input().split())
flag = 0
for i in range(N+1) :
    a = 10000*i
    for j in range(N+1) :
        b = 5000*j
        if (a+b) <= Y :
            c = Y-(a+b)
            k = c//1000
            if flag == 1 :
                break
            elif (i+j+k) == N :
                print(i,j,k)
                flag += 1
if flag == 0 :
    print(-1,-1,-1)


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

int main() {
	int n, m, xma, ymi;
	cin >> n >> m >> xma >> ymi;
	for (int i = 0, x; i < n; i++) {
		cin >> x;
		xma = max(x, xma);
	}
	for (int i = 0, y; i < m; i++) {
		cin >> y;
		ymi = min(y, ymi);
	}
	cout << (xma < ymi ? "No War" : "War") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
 
int main(){
  string s;
  cin >> s;

  vector<char> v;

  for(int i = 0;i < s.size(); ++i){
    if(s[i] == '0')
      v.push_back('0');
    else if(s[i] == '1')
      v.push_back('1');
    else if(v.size() != 0 && s[i] == 'B')
      v.pop_back();
  }
  for(int i = 0;i < v.size();++i)
    cout << v[i];

  cout << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main()
{
    int h,w;
    cin >> h >> w;
    string maze[h];
    int yoko[h][w];
    int tate[h][w];
    rep(i, h) {
        cin >> maze[i];
        rep(j,w) {
            yoko[i][j] = 0;
            tate[i][j] = 0;
        }
    }

    rep(i, h)
    {
        int yokofirst = 0;
        int yokocount = 0;
        bool yokoflag = false;
        rep(j, w)
        {
            if (maze[i][j] == '#')
            {
                if (yokoflag) {
                    REP(k, yokofirst, j) {
                        yoko[i][k] = yokocount;
                    }
                    yokocount = 0;
                    yokoflag = false;
                }
            }
            else
            {
                yokocount += 1;
                if (!yokoflag)
                {
                    yokoflag = true;
                    yokofirst = j;
                }
            }

            if (j == w-1 && yokoflag)
            {
                REP(k, yokofirst, w) {
                    yoko[i][k] = yokocount;
                }
                yokocount = 0;
                yokoflag = false;
            }
        }
    }
    rep(j, w)
    {
        int tatefirst = 0;
        int tatecount = 0;
        bool tateflag = false;
        rep(i, h)
        {
            if (maze[i][j] == '#')
            {
                if (tateflag) {
                    REP(k, tatefirst, i) {
                        tate[k][j] = tatecount;
                    }
                    tatecount = 0;
                    tateflag = false;
                }
            }
            else
            {
                tatecount += 1;
                if (!tateflag)
                {
                    tateflag = true;
                    tatefirst = i;
                }
            }

            if (i == h-1 && tateflag)
            {
                REP(k, tatefirst, h) {
                    tate[k][j] = tatecount;
                }
                tatecount = 0;
                tateflag = false;
            }
        }
    }
    int ans = 0;
    rep(i, h) {
        rep(j,w)
        {
            ans = max(ans, tate[i][j] + yoko[i][j]);
            // cout << yoko[i][j];
        }
        // cout << endl;
    }
    // cout << endl;
    // rep(i,h) {
    //     rep(j,w) {
    //         cout << tate[i][j];
    //     }
    //     cout << endl;
    // }
    cout << ans -1 << endl;
    

}

Measured memory_bytes: 35584
/**
*    created: 09.07.2020 01:09:47
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << (a+b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair

typedef vector<int> vi;

int main() {
	while (true) {
		int n, m, score[1001];
		vi v;
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		REP(i, n) scanf("%d", &score[i]);
		score[n++] = 0;

		REP(i, n) FOR(j, i, n) v.push_back(score[i] + score[j]);
		sort(v.begin(), v.end(), greater<int>());

		int ans = 0;
		REP(i, n) FOR(j, i, n) {
			vi::iterator it = lower_bound(v.begin(), v.end(), m - score[i] - score[j], greater<int>());
			if (it == v.end()) continue;
			ans = max(ans, *it + score[i] + score[j]);
		}

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

Measured memory_bytes: 5072
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n;
    cin >> n;
    ll ans = 0;
    repr(i, 1, n + 1) {
        ll x = i;
        while (x <= n) {
            ans += x;
            //cout << i << " " << "ans += " << x << endl;
            x += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

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

//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/2709881/arsenic28/Rust
trait Joinable {
    fn join(self, sep: &str) -> String;
}

fn main() {
    let n: u64 = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut map = HashMap::new();

    let mut sum: u64 = a.iter().sum();

    for i in a.iter() {
        let count = map.entry(*i).or_insert(0);
        *count += 1;
    }

    let q: usize = read();

    for _ in 0..q {
        let b: u64 = read();
        let c: u64 = read();

        if let Some(b_num) = map.get(&b){
            sum = sum - b_num * b + b_num * c;
        }
        if let Some(num) = map.remove(&b) {
            *map.entry(c).or_insert(0) += num;
        }

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


Measured memory_bytes: 6224
import java.util.Scanner;

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

    	while(true){
    		int x = scan.nextInt();
    		int y = scan.nextInt();

    		if(x == 0 && y == 0) break;

    		if(x > y){
    			int buf = y;
    			y = x;
    			x = buf;
    		}

    		System.out.println(x + " " + y);
    	}
    }
}

Measured memory_bytes: 34652
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 100

int N;
int M[MAX_N];
int p[MAX_N][MAX_N];

int K;
int l[MAX_N];

vector<int> ans_list;

int main(){

	while (true){

		cin >> N;
		if (N == 0)
			break;
		for (int i = 0; i < N; i++){
			cin >> M[i];
			for (int j = 0; j < M[i]; j++){
				cin >> p[i][j];
			}
		}
		cin >> K;
		for (int i = 0; i < K; i++){
			cin >> l[i];
		}

		vector<int> ans;

		for (int num = 0; num < N; num++){
			bool ok = true;
			for (int i = 0; i < K; i++){
				bool flag = false;
				for (int j = 0; j < M[num]; j++){
					if (p[num][j] == l[i])
						flag = true;
				}
				if (!flag){
					ok = false;
					break;
				}
			}
			if (ok)
				ans.push_back(num + 1);
		}

		if (ans.size() != 1)
			ans_list.push_back(-1);
		else
			ans_list.push_back(ans[0]);

	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    long long N, C;
    cin >> N >> C;
    vector<LLP> sushi(N);
    rep(i,N) cin >> sushi[i].first >> sushi[i].second;
    
    sort(sushi.begin(), sushi.end());

    vector<long long> clock(N, 0), antiClock(N, 0);
    vector<long long> clockMax(N, 0), antiClockMax(N, 0);

    clock[0] = sushi[0].second - sushi[0].first;
    clockMax[0] = max((long long)0, clock[0]);

    for (int i = 1; i < N; i++) {
        clock[i] = clock[i - 1] + sushi[i].second - (sushi[i].first - sushi[i - 1].first);
        clockMax[i] = max(clockMax[i - 1], clock[i]);
    }

    antiClock[N - 1] = sushi[N - 1].second - (C - sushi[N - 1].first);
    antiClockMax[N - 1] = max((long long)0, antiClock[N - 1]);
    for (int i = N - 2; i >= 0; i--) {
        antiClock[i] = antiClock[i + 1] + sushi[i].second - (sushi[i + 1].first - sushi[i].first);
        antiClockMax[i] = max(antiClockMax[i + 1], antiClock[i]);
    }

    long long ans = 0;
    for (int i = 0; i <= N - 2; i++) {
        ans = max(ans, clock[i] - sushi[i].first + antiClockMax[i + 1]);
    }
    ans = max(ans, clockMax[N - 1]);
    for (int i = N - 1; i > 0; i--) {
        ans = max(ans, antiClock[i] - (C - sushi[i].first) + clockMax[i - 1]);
    }
    ans = max(ans, antiClockMax[0]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8024
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int cnt[105][105]; //cnt[n!][prime]
void init() {
    vector<bool> isp(101, true);
    isp[0] = isp[1] = false;
    REP(i,2,100) if(isp[i]) for (int j=2*i; j<=100; j+=i) isp[j] = false;

    MSET(cnt, 0);
    REP(i,1,100) {
        REP(j,1,100) cnt[i][j] = cnt[i-1][j];
        REP(j,1,100) if(isp[j]) {
            int x=i, c=0;
            while (x%j==0) x/=j, c++;
            cnt[i][j] += c;
        }
    }
}
int main()
{
    init();
    
    int n;
    while (~scanf("%d", &n)) {
        int ans=0;
        REP(i,1,n) if(cnt[n][i]>=74) ans++;
        REP(i,1,n)REP(j,1,n) if (i!=j) {
            if (cnt[n][i]>=2 && cnt[n][j]>=24) ans++;
            if (cnt[n][i]>=4 && cnt[n][j]>=14) ans++;
        }
        REP(i,1,n)REP(j,1,n)REP(k,j+1,n) if(i!=j && j!=k && i!=k) {
            if (cnt[n][i]>=2 && cnt[n][j]>=4 && cnt[n][k]>=4) ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
def main():

    data = ()
    shuffles = ()
    
    while True:
        input_text = input()
        if input_text == '-': break
        data += (input_text,)
        shuffle_length = int(input())
        shuffles += (sum(int(input()) for i in range(shuffle_length)),)

    for text, shuffles in zip(data, shuffles):
        print(text[(shuffles % len(text)):] + text[:(shuffles % len(text))])
main()

Measured memory_bytes: 7768
#include <stdio.h>
int main()
{
    char S[4], T[4];
    int count = 0;
    scanf("%s\n%s", S, T);
    if (S[0] == T[0])
        count++;
    if (S[1] == T[1])
        count++;
    if (S[2] == T[2])
        count++;
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main(){
	int n, m, i, j, t, k, flag;
	while(~scanf("%d %d", &n, &m)){
		flag = 0;
		if(n == 2 || m == 2) flag = 0;
		else if(n == 4 || n == 6 || n == 9 || n == 11){
			if(m == 4 || m == 6 || m == 9 || m == 11)
				flag = 1;
		}
		else flag = 1;
		if(flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	} 
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
cnt = 0
even = True
 
while(even):
    for i in range(n):
        if a_list[i] % 2 != 0:
            even = False
            break
        else:
          a_list[i] /= 2
    if even:
	    cnt += 1
 
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int n,a[105],i,j,x=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;)
	{
		for(j=i;a[j+1]==a[j];j++);
		x+=(j-i+1)/2; 
		i=j+1;
	}
	printf("%d",x); 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
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; }



//monoid,結合律が成り立ち,単位元が存在するものに対しての演算をクエリに対してO(logn)で
//1-indexed  n(親)->2n,2n+1(子)  k(子)->k/2(親)
//木が1-indexedだけど要素アクセスはseg[0]~seg[n-1]だよ
template< typename Monoid >
struct SegmentTree {
    //monoid型の2数を受け取りmonoidの型の値を返すような関数がF
  using F = function< Monoid(Monoid, Monoid) >;
  //sz:size->完全二分木なのでszはnよりも大きい最小の2のべき乗数
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
  /*宣言は
  int f(int a,int b){return min(a,b);}
  SegmentTree< int > seg(N, f, INT_MAX);
  のようにする。1引数目は要素数、2引数目は関数、3引数目は演算fの単位元
  fは2区間をマージする関数、RMQなら親は子の最小値なのでfは2数の最小値を返す関数
   */
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {

    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
 //setしてbuildするのかな
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }
 
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
 //親へとさかのぼって更新し続ける
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    //for(;k>0;k=k>>1)と同義
    //これ最初のseg[k]の式に入るときにはkは一回k>>1されてる
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 //query聞くときは区間は[a,b)で(a<=x<b)
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    //>>1は/2だから子への遷移
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
 //szは木のサイズなのでこうすることで普通に配列の要素へのアクセスができる。
 //しかし親も更新しなきゃいけないから値変えるときはupdateでやりなさい
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


ll f(ll a,ll b){
    if(a<0) return b;
    if(b<0) return a;
    return b?f(b,a%b):a;
}
int main()
{
    int N;
    cin>>N;
    SegmentTree< ll > seg(N, f, -1);
    rep(i,N){
        ll t;cin>>t;
        seg.set(i,t);
    }
    ll ans=0;
    seg.build();
    for(int i=0;i<N;i++){
        ll memo=seg[i];
        seg.update(i,-1);
        ans=max(ans,seg.query(0,N));
        seg.update(i,memo);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 2304