akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
ans=0
dic={}
a=[]
for b in range(n):
  k,*a=map(int,input().split())
  for c in a:
    if c in dic:
      dic[c]+=1
    else:
      dic[c]=1
for d in dic:
  if dic[d]==n:
    ans+=1
print(ans)

Measured memory_bytes: 3064
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 10000, MAXI = 10000;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 10;
//     cout << tc << "\n";
//     while (tc--)
//     {
//         int n = rand()%N+1;
//         cout << n << " ";
//         cout << rand()%n + 1 << "\n";
//         for(int i=1;i<=n;i++)
//             cout << rand()%MAXI + 1 << " ";
//         cout << "\n";
//         cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 100005
 
 
// Driver code to test above functions
int32_t main()
{
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
   	int a, b, c, k;
   	cin >> a >> b >> c >> k;

   	int ans = 0;

   	int x = min(a, k);
   	k-=x;

   	ans += x;

   	x = min(b, k);
   	k-=x;

   	x = min(c, k);
   	ans -= x;

   	cout << ans;

    return 0;
 
} 

Measured memory_bytes: 3648
#include <stdio.h>

int main() {

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

    int arr[k * 2];

    int cnt = 0;
    int maxdata = a + k;
    for (int i = 0; i < k; i++) {
        if (a + i <= b) {
            //printf("%d\n", a + i);
            arr[i] = a + i;
            cnt++;
        }
    }


    //printf("%d %d\n", maxdata, b - k + 1);

    if (maxdata <= b - k + 1) {
        maxdata = b - k + 1;
    }

    for (int j = maxdata; j <= b; j++) {
        if (j >= a) {
            //printf("%d\n", j);
            arr[cnt] = j;
            cnt++;
        }
    }

    for (int k = 0; k < cnt; k++) {
        printf("%d\n", arr[k]);
    }

    //    printf("cnt=%d\n", cnt);
    //    puts("----");
    //
    //    for (int i = 0; i < cnt - 1; i++) {
    //        for (int j = i + 1; j < cnt; j++) {
    //            printf("%d %d\n", arr[i], arr[j]);
    //        }
    //    }

    return 0;
}


Measured memory_bytes: 1700
#include <iostream>

using namespace std;

int main(){

    int a, b;
    cin >> a >> b;

    if (a >= 1 && a <=9 && b >=1 && b <=9){
        cout << a * b;
    } else {
        cout << "-1" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let big_int = 1000_000_000 + 7;
    let max_digit = 61;
    let mut sum1b = vec![vec![0; max_digit]; n];

    for i in 0..max_digit {
        sum1b[0][i] = (a[0] >> i) & 1;
    }
    for j in 1..n {
        for i in 0..max_digit {
            sum1b[j][i] = ((a[j] >> i) & 1) + sum1b[j - 1][i];
        }
    }
    // debug!(sum1b);

    let mut ans = 0i64;
    for j in 0..n {
        for i in 0..max_digit {
            let mut temp = 1 << i;
            temp %= big_int;
            if (a[j] >> i) & 1 == 0 {
                temp *= sum1b[n - 1][i] - sum1b[j][i];
            } else {
                temp *= (n - 1 - j) as i64 - (sum1b[n - 1][i] - sum1b[j][i]);
            }
            temp %= big_int;
            ans += temp;
            ans %= big_int;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define int long long int
#define double long double
#define endl "\n"
#define sz(x) (int)x.size()

using namespace std;

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

  int n;
  cin>>n;

  cout<<(1000-n%1000)%1000<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
const int Maxn = 1e5 + 1;
using std::cin;
using std::cout;
using std::pair;
using std::vector;
using std::priority_queue;
int n, k, w[ Maxn ];
bool b[ Maxn ];
std::vector < int > v[ Maxn ];
std::priority_queue < pair < int, int >, vector < pair < int, int > >, std::greater < pair < int, int > > > Q;
int main( )
{
	std::ios::sync_with_stdio( false );
	cin >> n;
	for( int i = 1; i < n; ++i )
	{
		int a, b;
		cin >> a >> b;
		v[ a ].push_back( b );
		v[ b ].push_back( a );
	}
	cin >> k;
	for( int i = 1; i <= k; ++i )
	{
		int tmp;
		cin >> tmp;
		cin >> w[ tmp ];
		b[ tmp ] = 1;
		Q.push( std::make_pair( w[ tmp ], tmp ) );
	}
	while( !Q.empty( ) )
	{
		auto tp = Q.top( );
		Q.pop( );
		for( auto &to: v[ tp.second ] )
		{
			if( b[ to ] )
				continue;
			bool flag = 0;
			for( auto &t: v[ to ] )
				if( b[ t ] )
					flag |= abs( tp.first + 1 - w[ t ] ) != 1;
			if( !flag )
				Q.push( std::make_pair( w[ to ] = tp.first + 1, to ) ),
				b[ to ] = 1;
		}
	}
	bool flag = 1;
	for( int i = 1; i <= n; ++i )
		flag &= b[ i ];
	for( int i = 1; i <= n; ++i )
		for( auto &to: v[ i ] )
			flag &= abs( w[ to ] - w[ i ] ) == 1;
	cout << ( flag ? "Yes\n" : "No\n" );
	if( !flag ) return 0;
	for( int i = 1; i <= n; ++i )
		cout << w[ i ] << '\n'; 
	return 0;
}

Measured memory_bytes: 10720
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n|m)
	{
		int p[10000];
		for (int i = 0; i < n; ++i)
			scanf("%d", p + i);
		sort(p, p + n);

		int res = accumulate(p, p + n, 0);
		for (int i = 0; i < n / m; ++i)
			res -= p[n-m - m*i];
		printf("%d\n", res);
	}

	return 0;
}

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

int main(){
  string a;
  cin >> a;
  long long int digit = a.size();
  long long int n = 1;
  long long int ans=0;
  n <<= digit-1;
  for(int bit=0; bit<n; bit++){
    long long int t = 0;
    for(int i=0; i<digit; i++){
      t = t*10 + (a[i]-'0');
      if (bit & (1<<i)){
        ans += t;
        t=0;
      }
    }
    ans += t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define ll long long int

#include <bits/stdc++.h>

using namespace std;

int main() {

    vector<int> vc;
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        vc.push_back(x);
    }
    sort(vc.begin(), vc.end());
    ll sum = 0;
    for (int i = 0; i < k; i++)sum += vc[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3556
import sys
input = sys.stdin.readline


def main():
    N = int(input())

    x = int(N / 1.08)

    if N == int(x * 1.08):
        print(x)
    elif N == int((x + 1) * 1.08):
        print(x + 1)
    elif N == int((x + 2) * 1.08):
        print(x + 2)
    elif N == int((x - 1) * 1.08):
        print(x - 1)
    elif N == int((x - 2) * 1.08):
        print(x - 2)
    else:
        print(":(")



if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
n,m =map(int,input().split())

a =  [int(x)//2 for x in input().split()]

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

import math

lcm1 = 1
for i in a:
    lcm1 = lcm(lcm1, i)
    if((lcm1//i)%2==0):
        print(0)
        exit()

print(math.ceil((m//lcm1)/2))			

Measured memory_bytes: 82656
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;

const ll INF = ll(1e18) + 1;

typedef struct {
	ll cost;
	ll damage;
}magic;

unsigned long long int a(ulli n, ulli b) {
	if (b <= 1) {
		return n;
	}
	else {
		return a(n * 2, b - 1);
	}
}

ll mina(ll a, ll b) {
	return (a > b) ? b : a;
}

void Main()
{
	ll n, ans = 0, min = INF;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		if (min >= a[i]) {
			ans++;
			min = a[i];
		}
	}
	cout << ans << endl;
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 1792
while True :
	n, x = map(int, input().split())
	count = 0
	if n == 0 and x == 0 :
		break
	for i in range(1, n+1) :
		for j in range(i+1, n+1) :
			for k in range(j+1, n+1) :
				if i + j + k == x :
					count += 1
	print(count)




Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int number = input();

		int hour = number / (60 * 60);
		int minute = (number % (60 * 60)) / 60;
		int second = number % 60;

		System.out.println(hour + ":" + minute + ":" + second);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26260
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

int main()
{
    int abc[3];
    cin >> abc[0] >> abc[1] >> abc[2];
    sort(begin(abc), end(abc), greater<int>());

    if(abc[0] == abc[1]+abc[2]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b;
  cin >> a >> b;
  FOR(i, 1, 4) {
    if((a * b * i) % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
	return 0;
}

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

int main()
{
    char s[4];
    cin>>s;
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])cout<<"Yes";
    else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])cout<<"Yes";
    else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

int a[1005][1005];

int main()
{
    int n,m,t,p;
    while (scanf("%d%d%d%d",&m,&n,&t,&p))
    {
        if (n==0 && m==0 && t==0 && p==0) break;
        int ox=0,oy=0;
        memset(a,0,sizeof(a));
        for (int i=0;i<n;i++)
            for (int j=0;j<m;j++)
                a[i][j]=1;


        for (int i=0;i<t;i++)
        {
            int d,c;
            scanf("%d%d",&d,&c);
            if (d==2)
            {
                for (int j=c+ox;j<c+ox+c;j++)
                    for (int k=oy;k<oy+m;k++)
                        if (2*(c+ox)-j-1>=0) a[j][k]+=a[2*(c+ox)-j-1][k];
                ox+=c;
                n=max(n-c,c);
            }

            if (d==1)
            {
                for (int j=ox;j<ox+n;j++)
                    for (int k=c+oy;k<c+oy+c;k++)
                       if (2*(c+oy)-k-1>=0) a[j][k]+=a[j][2*(c+oy)-k-1];

                oy+=c;
                m=max(m-c,c);
            }


        }
        for (int i=0;i<p;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                printf("%d\n",a[y+ox][x+oy]);
            }
    }
    return 0;
}



Measured memory_bytes: 7060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

bool unbalance(string x){
    if(x[0]==x[1]||x[1]==x[2]||x[2]==x[0])return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    if(s.size()==2){
        if(s[0]==s[1])cout<<"1 2";
        else cout<<"-1 -1";
    }else{
        rep(i,s.size()-2){
            string str = s.substr(i,3);
            if(unbalance(str)){cout<<i+1<<" "<<i+3;return 0;}
        }
        cout<<"-1 -1";
    }
    return 0;
}

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

int main(){
    int r,c;
    cin >> r >> c;
    vector<vector<int> >  a(r+2,vector<int>(c+2,0));
    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            cin >> a[i][j];
        }
    }
    for(int j=1; j<=c; j++)
        for(int i=1; i<=r; i++)
            a[r+1][j]+=a[i][j];
    
    for(int i=1; i<=r+1; i++)
        for(int j=1; j<=c; j++)
            a[i][c+1]+=a[i][j];
    
    for(int i=1; i<=r+1; i++){
        for(int j=1; j<=c+1; j++){
            if(j!=c+1)
                cout << a[i][j] << " ";
            else
                cout << a[i][j] << endl;
        }
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2==1){
        cout << "No"<<endl;
    }else{
        string s2=s.substr(n/2);
        string s1=s.erase(n/2);
        if(s1==s2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
int[] array = new int[n];

for(int i=0; i<n; i++){
array[i] = sc.nextInt();
}

Arrays.sort(array);

System.out.println(array[n-1] - array[0]);
    }

}


Measured memory_bytes: 20688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,A,B; cin>>N>>A>>B;
	int mini, maxi;

	if(N<A+B){
		mini = A+B-N;
	}
	else{
		mini = 0;
	}
	if(A>B){
		maxi = B;
	}
	else{
		maxi = A;
	}

	cout<<maxi<<" "<<mini<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define pb push_back
#define I push_back
const ll maxs = 1e6 + 7;

vector<ll>S;

void pre()
{
    S.I(2);
    ll day = 1;
    for(ll i = 3;i < maxs;++i)
    {
        
        if(day % 7 == 1 )
            S.I(i);
        else if(day % 7 == 2)
        {
            
            if(i % 100 == 0)
            {
                if(i % 400 != 0)
                    S.I(i);
            }
            else if(i % 4 != 0)
            {
                S.I(i);
            }
        }
        
         if(i % 100 == 0)
            {
                if(i % 400 != 0)
                    day++;
                else
                    day = day + 2;
            }
        else{
            if(i % 4 == 0)
                day = day  + 2;
            else
                day++;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s1,s2,s3;
    cin >> s1 >> s2 ;
    ll a,b;
    cin >> a >> b;
    cin >> s3;
    if(s1 == s3)
    {
        a--;
        cout << a << " " << b; 
    }
    else
    {
         b--;
        cout << a << " " << b; 
    }
    
}

Measured memory_bytes: 256
n = int(input())
l = []
for _ in range(n):
    l.append(input())

a,b,c, = 0,0,0
ans = 0
for ll in l:
    for i in range(len(ll)-1):
        if ll[i:i+2] == 'AB':
            ans += 1
    if ll[-1] == 'A' and ll[0] != 'B':
        a += 1
    elif ll[-1] != 'A' and ll[0] == 'B':
        b += 1
    elif ll[-1] == 'A' and ll[0] == 'B':
        c += 1
if a == b == 0:
    print(max(ans+c-1,ans))
elif a == 0 or b == 0:
    print(ans+c)
else:
    print(ans + c+1 + min(a-1,b-1))


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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		long int max = -100001; 
		for (int i = 0; i < n; i++) {
			long int tmp = 0;
			for (int j = i; j < n ; j++) {
				tmp += nums[j];
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 3004
use std::io::stdin;

fn main() {
    let mut ss = String::new();
    stdin().read_line(&mut ss).ok();
    let h: usize;
    let w: usize;
    let v: Vec<usize> = ss
        .trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    h = v[0];
    w = v[1];
    let mut s: Vec<Vec<char>> = Vec::new();
    for _i in 0..h {
        ss = String::from("");
        stdin().read_line(&mut ss).ok();
        s.push(ss.as_str().chars().collect());
    }
    let mut dw: Vec<Vec<i32>> = Vec::new();
    let mut dh: Vec<Vec<i32>> = Vec::new();
    for i in 0..h {
        let mut cw: Vec<i32> = Vec::new();
        let mut count = 0;
        for j in 0..w {
            if s[i][j] == '#' {
                cw.push(0);
            } else if j == 0 || s[i][j - 1] == '#' {
                count = 0;
                for k in j..w {
                    if s[i][k] == '.' {
                        count += 1;
                    } else {
                        break;
                    }
                }
                cw.push(count);
            } else {
                //cw.push(cw[j - 1]);
                cw.push(count);
            }
        }
        dw.push(cw);
    }
    for j in 0..w {
        let mut ch: Vec<i32> = Vec::new();
        let mut count = 0;
        for i in 0..h {
            if s[i][j] == '#' {
                ch.push(0);
            } else if i == 0 || s[i - 1][j] == '#' {
                count = 0;
                for k in i..h {
                    if s[k][j] == '.' {
                        count += 1;
                    } else {
                        break;
                    }
                }
                ch.push(count);
            } else {
                //ch.push(ch[i - 1]);
                ch.push(count);
            }
        }
        dh.push(ch);
    }
    let mut max = 0;
    for i in 0..h {
        for j in 0..w {
            let sum = dw[i][j] + dh[j][i];
            if max < sum {
                max = sum;
            }
        }
    }
    println!("{}", max - 1);
}


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

int main() {
    int a, b, c;
    int64_t k;
    cin >> a >> b >> c >> k;

    int ans = a-b;
    if(k%2 != 0) ans *= -1;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    string s; cin >> s;
    string target = "keyence";
    int n = s.size();

    if(s == target) {
        cout << "YES" << endl;
        return 0;
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            string t = "";
            for(int k = 0; k < n; k++) {
                if(i <= k && k <= j) {
                    continue;
                }
                t.push_back(s[k]);
            }
            if(t == target) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;

int main() {
    int a, b;
    cin >> a >> b;
    ll ans = 0;
    if (a <= b) {
        ans = a;
    } else {
        ans = a - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mx=1e5+7;
int n,mem[mx];

ll solve(vector <int> v[],int i)
{
    //cout<<"i ="<<i<<endl;
    if(i>n)
    return 0;
    if(mem[i]!=-1)
        return mem[i];
    ll ans=0;
   // cout<<i<<" i/v[i] "<<v[i].size()<<endl;


    for(int j=0;j<v[i].size();j++)
            ans=max(ans,solve(v,v[i][j])+1);
    return mem[i]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    int s,x,y;
    ll ans=0;
    cin>>n>>s;
    vector<int> v[n+2];

    while(s--)
    {
        scanf("%d %d",&x,&y);
        v[x].push_back(y);
    }
for(int i=1;i<=n;i++)
    ans=max(ans,solve(v,i));

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


Measured memory_bytes: 8192
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

const int sz=2e5 + 5;
int f[sz];

void sub_self(int& a,int b){
    a-=b;
    if(a<0){
        a+=mod;
    }
}

int mul(int a,int b){
    return ((ll)a*b) % mod;
}

void fact(){
    f[0]=1;
    for(int i=1;i<=sz;i++){
        f[i]=mul(f[i-1],i);
    }
}

int power(int a,int b){
    int ans=1;
    while(b>0){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b>>1;
    }
    return ans;
}

int path(int x1,int y1,int x2,int y2){
    int n=x2-x1;
    int m=y2-y1;
    int a=f[n+m];
    int b=mul(f[n],f[m]);
    return mul(a,power(b,mod-2));
}

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,m,k;
    cin>>n>>m>>k;
    vector<pair<int,int>> v(k);
    
    for(int i=0;i<k;i++){
        int r,c;
        cin>>r>>c;
        v[i]={r,c};
    }
    
    sort(v.begin(),v.end(),[&](pair<int,int> a,pair<int,int>b){
        return (a.first + a.second) <  (b.first + b.second) ;
    });
    fact();

    vector<int> dp(k+1);
    v.emplace_back(n,m);
    
    for(int i=0;i<=k;i++){
        int tmp=path(1,1,v[i].first,v[i].second);
        for(int j=0;j<i;j++){
            if(v[j].first<=v[i].first && v[j].second<=v[i].second){
                sub_self(tmp,mul(dp[j],path(v[j].first,v[j].second,
                    v[i].first,v[i].second)));
            }
        }

        dp[i]=tmp;
        
    }

    cout<<dp[k]<<"\n";
    
 }


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],t[N],d[N],b[N];
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int main(){
	int n=read(),k=read();
	for (int i=1;i<=n;i++){
		int u=read();
		if (u==0) k--;
		if (u<0) a[++a[0]]=u;
		if (u>0) b[++b[0]]=u;
	}
	reverse(a+1,a+1+a[0]);
	int ans=1e9;
	if (b[0]>=k) ans=b[k]; 
	for (int i=max(1,k-b[0]);i<=min(k,a[0]);i++){
		int x=a[i],y=b[k-i];
		if (abs(x)<y) ans=min(ans,abs(x)*2+y);
		else ans=min(ans,abs(x)+y*2);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

ll lcm(ll a, ll b){
    return a*b/__gcd(a, b);
}

int main(){
    ll a,b;int c,d;cin>>a>>b>>c>>d;
    ll k = lcm(c, d);
    ll setc, setd, setcd;
    if(a%c==0)setc=b/c-a/c+1;else{setc=b/c-a/c;}
    if(a%d==0)setd=b/d-a/d+1;else{setd=b/d-a/d;}
    if(a%k==0)setcd=b/k-a/k+1;else{setcd=b/k-a/k;}
    ll ans = (b-a+1)-setc-setd+setcd;
    co(ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

int main(void){
	ll i,x,y,p,q,r,ans=1ll;
	cin >> x >> y;
	if((x+y)%3){
		cout << 0 << endl;
		return 0;
	}
	r = (x+y)/3;
	q = x - r;
	p = y - r;
	if(p<0 || q<0){
		cout << 0 << endl;
		return 0;
	}
	for(i=1; i<=r; ++i){
		mul_mod(ans,i);
	}
	for(i=1; i<=p; ++i){
		mul_mod(ans,rwpw(i,MOD-2));
	}
	for(i=1; i<=q; ++i){
		mul_mod(ans,rwpw(i,MOD-2));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

lli gcd(lli x, lli y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

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

    vector<lli> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    vector<lli> L(N + 1);
    vector<lli> R(N + 1);

    for (int i = 0; i < N; i++) {
        if (i != 0) {
            L[i + 1] = gcd(L[i], A[i - 1]);
        }
        R[N - 1 - i] = gcd(R[N - i], A[N - 1 - i]);
    }

    lli ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, gcd(L[i + 1], R[i + 1]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <cstdio>
char str[100005];
int main(){
	scanf("%s", str);
	for(int i = 0; str[i]; i ++){
		if(str[i+1] && str[i] == str[i+1]) return printf("%d %d\n", i+1, i+2), 0;
		if(str[i+2] && str[i] == str[i+2]) return printf("%d %d\n", i+1, i+3), 0;	
	}
	return printf("%d %d\n", -1, -1), 0;
}

Measured memory_bytes: 256
def ascan; gets.split.map(&:to_i);end

ii,oo,tt,jj,ll,ss,zz = ascan

# t, s, zは使えない
# どう使っても端が余るから

# o
# 無条件で長方形
# ii,jj,ll,lij が考えられる．

md = 2*2*2*3*3*5*7
k = 0

k+= oo
k+= ii/md*md; ii%=md
k+= jj/md*md; jj%=md
k+= ll/md*md; ll%=md

kp = 0
0.upto([ii, jj, ll].min) do |c|
    y = [ii-c,0].max/2*2+ [jj-c,0].max/2*2 + [ll-c,0].max/2*2
    y += c*3
    kp = [kp, y].max
end

k += kp

p k


Measured memory_bytes: 1788
n = int(input())
h = list(map(int, input().split()))

now = 0
ans = 0
cur = 0
for x in h:
    if x <= now:
        cur += 1
    else:
        ans = max(ans, cur)
        cur = 0
    now = x
ans = max(ans, cur)
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e2 + 7;

int n, m, k;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define fi first
#define se second
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000000000000000
using namespace std;
int main(){
    //double start_time = clock();
    ll n,x;
    cin>>n>>x;
    ll a[n],w[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i]>>w[i];
    }
    ll dp[n+1][x+1];
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; j <= x; ++j)
        {
            if(i==0 || j==0){
                dp[i][j]=0;
            }
            else if(a[i-1]<=j){
                dp[i][j]=max(w[i-1] + dp[i-1][j-a[i-1]],dp[i-1][j]);
            }
            else 
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][x];
    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;
    cin >> N;
    ve<ve<int>> G(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    queue<int> F,S;
    set<int> done;
    int ff = 0, ss = 0;
    F.push(0);
    S.push(N-1);
    done.insert(0),done.insert(N-1);
    
    while (done.size() < N) {
        
        queue<int> F1;
        while (!F.empty()) {
            int fff = F.front();
            F.pop();
            for (auto p : G[fff]) {
                if(done.count(p)) continue;
                ff++;
                F1.push(p);
                done.insert(p);
            }
        }
        F = F1;
        
        queue<int> S1;
        while (!S.empty()) {
            int sss = S.front();
            S.pop();
            for (auto p :G[sss]) {
                if(done.count(p)) continue;
                ss++;
                S1.push(p);
                done.insert(p);
            }
        }
        S = S1;
    }

    if(ss < ff) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
    //cout << ff csp ss << endl;
    
    return 0;
}


Measured memory_bytes: 10880
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
int main()
{
//    freopen("in.txt","r",stdin);
    int R;
    cin>>R;
    string ans;
    if(R<1200)ans="ABC";
    else if(R>=1200&&R<2800)ans="ARC";
    else ans="AGC";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

// エラトステネスの篩
// O(n log log n)
// Verified: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3452800
vector<bool> eratos(int n) {
	vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (!is_prime[i])continue;
		for (int j = i * i; j <= n; j += i)
			is_prime[j] = false;
	}
	return is_prime;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int ans = 0;
	auto e = eratos(N + 2);
	rep(p, 3, N + 1) {
		if (e[p] && e[p + 2])
			ans += 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<set<int> > f(n);
    vector<set<int> > have(n);

    int cnt = 0;
    REP(i,n){
      int m = getInt();
      REP(j,m){
	f[i].insert(getInt());
      }
      have[i].insert(i);
    }

    REP(i,30){
      vector<int> meet;
      REP(j,n) if(f[j].count(i+1) != 0){
	meet.push_back(j);
      }
      REP(j, meet.size()){
	REP(k, meet.size()){
	  have[meet[j]].insert(have[meet[k]].begin(), have[meet[k]].end());
	}
	if(have[meet[j]].size() == n){
	  print(i+1);
	  goto end;
	}
      }
    }
    print(-1);
  end:;
  }
  return 0;
}

Measured memory_bytes: 976
#include <cstdio>

const int MAXN = 3e3+3, MOD = 1e9+7;

int add(int x, int y, int mod) {
	return x+y < mod ? x+y : (x+y) % mod;
}

int n, m, dp[MAXN][MAXN][2];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		dp[0][i][0] = 1;
	}
	dp[0][0][1] = 1;

	for (int i = 0; i < m; ++i) {
		for (int j = 0; j <= n; ++j) {
			int t0 = dp[i][j][0], t1 = dp[i][j][1];
			if (j > 0) {
				dp[i+1][j][1] = add(dp[i+1][j][1], t1, MOD); // RB
				dp[i+1][j-1][1] = add(dp[i+1][j-1][1], t1, MOD); // RR
			}
			if (j < n) {
				dp[i+1][j][1] = add(dp[i+1][j][1], t1, MOD); // BR
				dp[i+1][j+1][1] = add(dp[i+1][j+1][1], t1, MOD); // BB

				dp[i+1][j][0] = add(dp[i+1][j][0], t0, MOD); // BR
				dp[i+1][j+1][0] = add(dp[i+1][j+1][0], t0, MOD); // BB
			}
			if (j == 1) {
				// ulazak u prvi stupac
				dp[i+1][j][1] = add(dp[i+1][j][1], t0, MOD); // RB
				dp[i+1][j-1][1] = add(dp[i+1][j-1][1], t0, MOD); // RR
			}
			if (j > 1) {
				dp[i+1][j][0] = add(dp[i+1][j][0], t0, MOD); // RB
				dp[i+1][j-1][0] = add(dp[i+1][j-1][0], t0, MOD); // RR
			}			
		}
	}

	int sol = 0;
	for (int i = 0; i <= n; ++i) {
		sol = add(sol, dp[m][i][1], MOD);
	}

	printf("%d\n", sol);
	return 0;
}




Measured memory_bytes: 70528
use std::io::*;
use std::str::FromStr;
use std::collections::BTreeMap;

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")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let h: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut ret: Vec<bool> = (0..n).map(|_| true).collect();

    for _ in 0..m {
        let a: usize = read::<usize>() - 1;
        let b: usize = read::<usize>() - 1;

        if h[a] < h[b] {
            ret[a] = false;
        } else if h[b] < h[a] {
            ret[b] = false;
        } else {
            ret[a] = false;
            ret[b] = false;
        }
    }

    println!("{}", (&ret).into_iter().fold(0, |a, &b| if b { a + 1 } else { a }));
}


Measured memory_bytes: 2796
// https://atcoder.jp/contests/abc158/tasks/abc158_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int a = 0, b = 0;
    for (auto &x : s) {
        if (x == 'A')
            a++;
        else if (x == 'B')
            b++;
    }
    if (a == 0 || b == 0) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

    return 0;
}


Measured memory_bytes: 256
# import math
# import bisect
# import heapq
# from collections import deque

n = int(input())
score = [list(map(int, input().split())) for _ in range(n)]


for i in range(n):
    if i == 0:
        t1 = score[i][0]
        t2 = score[i][1]
        t3 = score[i][2]
    else:
        x1 = t1
        x2 = t2
        x3 = t3

        t1 = max(x2,x3) + score[i][0]
        t2 = max(x1,x3) + score[i][1]
        t3 = max(x1,x2) + score[i][2]

print(max(t1,t2,t3))



Measured memory_bytes: 30580
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

LL getUnion(LL a, LL b, LL c, LL d)
{
	LL r = min(d, b) - max(a, c) + 1;
	LL com = max(r, 0LL);
	return b - a + 1 + d - c + 1 - com;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	
	LL a, b;
	cin >> a >> b;
	if (a == b)
	{
		cout << 1 << endl;
		return 0;
	}

	int p = -1;
	FOR(i, 0, 62)
	{
		if ((a >> i) == (b >> i))
		{
			p = i;
			break;
		}
	}

	p--;
	LL mask = (1LL << p) - 1;
	LL c = a | mask;

	//cout << "!" << a << " " << c << endl;
	LL ans = c - a + 1;
	LL tmp = b & mask;
	int k = 0;
	while ((tmp >> k) != 0) k++;
	tmp = (1LL << k) - 1;

	LL l1 = c + 1;
	LL r1 = b | tmp;
	LL l2 = a | (1LL << p);
	LL r2 = l2 | mask;

	//cout << l1 << " " << r1 << " - " << l2 << " " << r2 << endl;
	//cout << getUnion(l1, r1, l2, r2) << endl;
	ans += getUnion(l1, r1, l2, r2);

	cout << ans << endl;
}


Measured memory_bytes: 512
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

constexpr int32_t kMaxNumberOfVertices = 100;

// ****************************************************

void CallCycleDetection(std::istream &input_stream);

// ****************************************************

struct Vertex {
  bool discovered_{false};
  bool completed_{false};
  std::vector<int32_t> next;
};

class CycleDetection {
 public:
  CycleDetection() noexcept;
  ~CycleDetection() noexcept;
  void SetNumberOfVertices(const int32_t number_of_vertices) noexcept;
  void AddEdge(const int32_t vertex_from, const int32_t vertex_to) noexcept;
  bool HaveCycle() noexcept;

 private:
  void Dfs(const int32_t vertex_index) noexcept;

 private:
  int32_t number_of_vertices_;
  bool have_cycle_;
  Vertex vertices_[kMaxNumberOfVertices];
};

void CallCycleDetection(std::istream &input_stream) {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  CycleDetection *cycle_detection = new CycleDetection();
  try {
    int32_t number_of_vertices, number_of_edges;
    input_stream >> number_of_vertices >> number_of_edges;
    cycle_detection->SetNumberOfVertices(number_of_vertices);
    for (int32_t i = 0; i < number_of_edges; ++i) {
      int32_t vertex_from, vertex_to;
      input_stream >> vertex_from >> vertex_to;
      cycle_detection->AddEdge(vertex_from, vertex_to);
    }
    const bool have_cycle = cycle_detection->HaveCycle();
    if (have_cycle) {
      std::cout << "1" << std::endl;
    } else {
      std::cout << "0" << std::endl;
    }
  } catch (...) {
    std::cerr << "ERROR: CallCycleDetection()" << std::endl;
    throw;
  }
  delete cycle_detection;
}

// ****************************************************

CycleDetection::CycleDetection() noexcept : number_of_vertices_(0), have_cycle_(false) {}

CycleDetection::~CycleDetection() noexcept {}

void CycleDetection::SetNumberOfVertices(const int32_t number_of_vertices) noexcept {
  number_of_vertices_ = number_of_vertices;
}

void CycleDetection::AddEdge(const int32_t vertex_from, const int32_t vertex_to) noexcept {
  vertices_[vertex_from].next.push_back(vertex_to);
}

bool CycleDetection::HaveCycle() noexcept {
  for (int32_t start_index = 0; start_index < number_of_vertices_; ++start_index) {
    if (!vertices_[start_index].completed_) {
      Dfs(start_index);
    }
  }
  return have_cycle_;
}

void CycleDetection::Dfs(const int32_t vertex_index) noexcept {
  if ((!vertices_[vertex_index].completed_) && (vertices_[vertex_index].discovered_)) {
    have_cycle_ = true;
  } else {
    vertices_[vertex_index].discovered_ = true;
    for (const int32_t next_index : vertices_[vertex_index].next) {
      if (!vertices_[vertex_index].completed_) {
        Dfs(next_index);
      }
    }
    vertices_[vertex_index].completed_ = true;
  }
}

// **********************************************************************

int main() {
  try {
    CallCycleDetection(std::cin);
  } catch (...) {
    std::cerr << "ERROR: main()" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3232
#include<stdio.h>
int main()
{
    int n,i, j, ans=0, ans1=0, min=5050;

    scanf("%d",&n);

    int ar[n];

    for (i=0;i<n;i++)
    {
        scanf("%d",&ar[i]);
    }
    for (j=1;j<=n;j++)
    {
        for (i=0;i<j;i++)
        {
            ans=ans+ar[i];
        }
        for (i=j;i<n;i++)
        {
            ans1=ans1+ar[i];
        }
        if(min>abs(ans-ans1))
        {
            min=abs(ans-ans1);
        }
        ans= 0;
        ans1= 0;
    }
    printf("%d\n",min);

    return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[200200], b[200200], res;

int bit(int k) {
	int ta[200200] = {}, m = 1<<k;
	ll p = 0;
	rep(i,n) ta[i] = a[i] %(m*2);
	sort(ta,ta+n);
	rep(i,n) {
		int s = b[i] %(m*2);
		p += lower_bound(ta,ta+n,m*2-s) - lower_bound(ta,ta+n,m-s);
		p += lower_bound(ta,ta+n,m*4-s) - lower_bound(ta,ta+n,m*3-s);
	}
	return m*(p%2);
}

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rept(i,28) res += bit(i);
	cout << res << ln;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

ll a[64] = {0, 1};
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    for(i = 2;i < 64;++i)a[i] = a[i - 1] * 2;
    ll n; cin >> n;
    rep(i, 64)if(a[i] <= n && n < a[i + 1]){
      pri(i);
      return 0;
    }

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3112