akhauriyash/Code-Regression huggingface dataset:
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
/// 最小公倍数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
  int N;
  cin >> N;
  vector<char> A(N),B(N) ,C(N);
for(int i = 0; i < N; i++){
      cin >> A[i];
  }
  for(int i = 0; i < N; i++){
      cin >> B[i];
  }
for(int i = 0; i < N; i++){
      cin >> C[i];
  }
  vector<int> D(N);
  for(int i = 0 ; i < N; i++){
      if(A[i] == B[i] && B[i] == C[i]) D[i] = 0;
      else{
          if(A[i] == B[i] || B[i] == C[i] || A[i] == C[i]) D[i] = 1;
          else{
              D[i] = 2;
          }
      }
  }

cout << accumulate(D.begin(), D.end(),0) << endl;

  }



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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

if n == 1:
  if k == alist[0]:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
else:
  r = gcd(alist[1], alist[0])
  for _a in alist[2:]:
    r = gcd(_a, r)
  if k <= alist[-1] and k % r == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')


Measured memory_bytes: 14224
n=int(input())
a=[int(i) for i in input().split()]


a.sort()

count=0


def get_num(a):
    count=1
    taishou = a.pop()
    while a!=[]:
        second=a.pop()
        if taishou==second:
            count+=1
        else:
            a.append(second)
            break
    if count==1:
        return taishou,0
    elif count==2 or count==3:
        return taishou,1
    else:
        return taishou,2

one=0
two=0


while a!=[] and (one==0 or two==0):
    hen,length=get_num(a)
    if length==1:
        if one==0:
            one=hen
        else:
            two=hen
    elif length==2:
        if one==0:
            one=hen
            two=hen
        else:
            two=hen

print(one*two)



Measured memory_bytes: 20372
#include <bits/stdc++.h>                                                                               
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)
#define FORE(v1, v2) for (v1 = 0; v1 <= v2; ++v1)
#define FORO(v1, v2) for (v1 = 1; v1 < v2; ++v1)
#define FOROE(v1, v2) for (v1 = 1; v1 <= v2; ++v1)
using ll = long long;
constexpr ll kMod = 1'000'000'007;
int main () {
  int h, a;
  cin >> h >> a;
  cout << ceil(double(h)/a) << endl;
  return 0;
}


Measured memory_bytes: 256
// #include <stdio.h>
// #include <string.h>
//#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>

using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
    
int main()
{
  	int Nmax = 100000;
    char String[Nmax];
    int N;
    int i,j,k;
    int len;   // 文字列の長さ
    int flag=0;
    int t[Nmax];
    int x[Nmax];
    int y[Nmax];
    int M,D;
    int count = 0;
    int d1,d10;
    int d,m;
 /*   
    // int型スタック
    stack<int> stack;   
    stack.push(777);
    stack.push(778);
    stack.push(779);
  
	int tmpsl = stack.top();  // LAST要素の参照
 // 	int tpmsf = stack.back(); // FIRST要素の参照
 //	printf("%d %d \n",tmpsl,tmpsf);
    stack.pop();// LAST要素の削除（取出しではない）
 // 	if( stack.empty() == true) printf("empty stack\n");
     
    // int型キュー
    queue<int> que;
  	que.push(999);
  	que.push(998);   
  	que.push(997);    
  	int tmpqs = que.front(); // FIRST要素の参照
  	int tmpqe = que.back();  // LAST要素の参照
 //	printf("%d %d \n",tmpqs,tmpqe);
  	que.pop();  // FIRST要素の削除（取出しではない）
  //	if( que.empty() == true) printf("empty que\n");
    
    // ２次元座標を扱うキュー
    queue<XY> xyque; // ２次元座標型変数のキュー
  	XY p; 
  	xyque.pop();	// FIRST要素の削除。キューが空のときは削除が予約されて次のPOPが即削除される
  	xyque.push( XY(5,5) );
    xyque.push( XY(5,5) );
   	p = xyque.front();  // FIRST要素からのコピー
 // 	printf("%d %d\n", p.first, p.second);
  	
    
  que.back();
  //  sort(&(que.front()), &(que.back()));
        
 */   
      
    // 入力読込
    // 文字列
 //   scanf("%s", String);   
    
    // 数列
    scanf("%d %d", &M,&D);
//    for(i=1;i<=N;i++){
//        scanf("%d %d %d",&t[i],&x[i],&y[i]);
//    }
    
    // 文字列の長さをチェック
    // 文字列は配列の0からlen-1に格納されてる
//    len = strlen( String );
//  	printf("%d\n",len);
    
    for(m=1;m<=M;m++){
        for(d=1;d<=D;d++){
            d1 = d%10;
            d10 = d/10;
            if((m == d1*d10) && (d1>=2) && (d10 >=2))  count++;
        }
    }
    
    
    // 結果出力
    printf("%d",count);
/*    
    if(flag == -1)
        printf("NO \n");
    else
        printf("YES \n");
  */      
  
  return 0;
   
}

Measured memory_bytes: 760
#include <stdio.h>

int min(int a, int b){
  return 0 <= (b-a) ? a : b;
}
int main(){
  int a,b,c,x,
      i,j,res;
  
  scanf("%d%d%d%d", &a, &b, &c, &x);
  
  for(i=min(x/500, a); 0<=i; i--){
    for(j=min((x-500*i)/100,b); 0<=j; j--){
      if(x - (500*i+100*j) <= 50 * c){
        res++;
      }
    }
  }
  
  printf("%d", res);
  
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll K;
  string S;
  cin >> K >> S;
  if (S.length() <= K) {
    cout << S << endl;
  } else {
    string ans = S.substr(0, K) + "...";
    cout << ans << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
const ll unllMOD = 1e18;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/
//cout << std::fixed << std::setprecision(12) <<<< endl;

int main() {
	ll N;
	cin>>N;
	bool ok=0;
	ll p=sqrt(N);
	vector<ll>a(p+10);
	for(ll i=0;i<p+10;i++) a[i]=0;
	ll n=N;
	ll ans=0;
	for(ll i=2;i<=p+10;i++){
		while(1){
			if(n%i==0)n/=i;
			else break;
			a[i]++;
		}
		if(n<i)break;
	}
	for(ll i=2;i<p+10;i++){
		if(a[i]!=0){
			for(ll u=1;;u++){
				if(a[i]-u>=0){
					ans++;
					a[i]-=u;
				}
				else break;
			}
		}
	}
	if(n!=1)ans++;
	if(N==1)cout<<0<<endl;
	else cout<<ans<<endl;
}

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

int main() {
  int n, sum = 0, dmin = 100;
  cin >> n;
  for(int i = 0; i < n; i++){
  	int a;
    cin >> a;
    sum = 0;
    while(a % 2 == 0){
      a /= 2;
      sum++;
    }
    dmin = min(sum, dmin);
  }
  cout << dmin << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

A.sort()

if N % 2 == 0:
  check = []
  for i in range(1, N + 1, 2):
    check.append(i)
    check.append(i)
  if A != check:
    print(0)
    exit(0)
else:
  check = [0]
  for i in range(2, N + 1, 2):
    check.append(i)
    check.append(i)
  if A != check:
    print(0)
    exit()

ans = 1
for _ in range(N // 2):
  ans *= 2
  ans %= MOD
print(ans)

Measured memory_bytes: 14008
import java.util.*;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int i = sc.nextInt();
        for (int j = 1; j < i; j++) {
            N--;
        }
        System.out.println(N);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	int buf = a - b;
	cout << max(c - buf, 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n;
	cin >> n;
	map<string, int> mp;
	char end;
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		mp[s]++;
		if (mp[s] != 1){
			cout << "No" << endl;
			return 0;
		}
		if (i != 0){
			if (s[0] != end){
				cout << "No" << endl;
				return 0;
			}
		}
		end = s[s.length()-1];
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)


void solve(long long A, long long B){
  int count=1;
  int result=0;
  while(count<B){
    count+=A-1;
    result++;
  }
  cout<<result<<endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

#define INF 1000000000.0

using namespace std;

int n, m, p, a, b, x, y, z, t[8];

double dp[256][30];

vector<pair<int, int> > G[30];

int main()
{
	while (true)
	{
		scanf("%d", &n);
		scanf("%d", &m);
		scanf("%d", &p);
		scanf("%d", &a);
		scanf("%d", &b);
		
		if (!a) break;

		for (int i = 0; i < m; i++) G[i].clear();

		for (int i = 0; i < n; i++) scanf("%d", &t[i]);

		for (int i = 0; i < p; i++)
		{
			scanf("%d", &x);
			scanf("%d", &y);
			scanf("%d", &z);

			G[x - 1].push_back(make_pair(y - 1, z));
			G[y - 1].push_back(make_pair(x - 1, z));
		}

		for (int i = 0; i < (1 << n); i++)
		{
			for (int j = 0; j < m; j++)
			{
				dp[i][j] = INF;
			}
		}

		dp[0][a - 1] = 0.0;

		for (int i = 1; i < (1 << n); i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (i & (1 << j))
				{
					for (int k = 0; k < m; k++)
					{
						for (int l = 0; l < G[k].size(); l++)
						{
							int node = G[k][l].first;

							double dist = G[k][l].second * 1.0 / t[j];

							dp[i][node] = min(dp[i][node], dp[i - (1 << j)][k] + dist);
						}
					}
				}
			}
		}

		double ret = INF;

		for (int i = 0; i < (1 << n); i++)
		{
			ret = min(ret, dp[i][b - 1]);
		}

		if (ret != INF)
		{
			printf("%.12f\n", ret);
		}
		else
		{
			printf("Impossible\n");
		}
	}

	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD2 1000000007
#define MOD 1000000009
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vvi vector <vector<int>>
#define F first
#define S second




int main()
{   
    IOS;
        #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
        #endif
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll q = (ll)a * c;
    ll t = (ll)b * d;
    ll e = (ll)a * d;
    ll r = (ll)b * c;
    ll mx1 = max( q, t);
    ll mx2 = max(e, r);
    cout << max(mx1, mx2);

    
    
return 0;
}

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

using namespace std;

int result[110][110];

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int current = 0;
  for (int y = 0; y < H; y++) {
    if (y % 2 == 0) {
      for (int x = 0; x < W; x++) {
        result[y][x] = current;
        A[current]--;
        if (A[current] == 0) current++;
      }
    } else {
      for (int x = W - 1; x >= 0; x--) {
        result[y][x] = current;
        A[current]--;
        if (A[current] == 0) current++;
      }
    }
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      printf("%d", result[y][x] + 1);
      if (x < W - 1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<long double> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  vector<pair<long double, int>> p;
  int prev = 0;
  for (int i = 0; i <= n; i++) {
    if (v[i] != v[prev]) {
      p.emplace_back(make_pair(v[prev], i - prev));
      prev = i;
    }
  }
  sort(p.begin(), p.end(), greater<pair<long double, int>>());

  map<long double, ll> mp;

  auto nCk = [&](ll n, ll k) {
    ll comb = 1;
    for (ll i = 1; i <= k; i++) {
      comb *= n - i + 1;
      comb /= i;
    }
    return comb;
  };

  auto calc = [&](int m) {
    long double avg = 0.0;
    int cnt = 0;
    int i = 0;
    int add = 0;
    while (cnt < m && i < p.size()) {
      add = min(m - cnt, p[i].second);
      cnt += add;
      avg += p[i].first * add;
      i++;
    }
    i--;
    avg /= (long double)m;
    mp[avg] += nCk(p[i].second, add);
  };

  for (int len = a; len <= b; len++) {
    calc(len);
  }
  pair<long double, ll> res;
  res = make_pair(0.0, 0LL);
  for (auto e : mp) {
    if (e.first > res.first) {
      res.first = e.first;
      res.second = e.second;
    }
  }
  printf("%.12Lf\n", res.first);
  printf("%Ld\n", res.second);
  return 0; 
} 

Measured memory_bytes: 256
N = gets.chomp.to_i

AL = %w[a b c d e f g h i j]

def dfs(arr, mx)
  if arr.size == N
    puts arr.join('')
    return
  end

  AL.each do |alf|
    if alf <= mx.succ
      c_arr = arr.dup
      c_arr.push(alf)
      dfs(c_arr, [alf, mx].max)
    end
  end
end

dfs(['a'], 'a')


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  vector<char> alp;
  for (char c = 'a'; c <= 'z'; c++) alp.push_back(c);

  int n;
  cin >> n;
  vector<vector<int>> varifi(n, vector<int>(100));
  map<string, ll> mis;
  rep(i, n) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      auto itr = find(alp.begin(), alp.end(), s[j]);
      ++varifi[i][itr - alp.begin()];
    }
    string tmp = "";
    for (int k = 0; k < 26; k++) tmp += to_string(varifi[i][k]);
    ++mis[tmp];
  }

  ll ans = 0;
  for (auto v : mis) {
    if (v.second < 2) continue;
    ans += v.second * (v.second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 58684
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition( int p, int r ){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i + 1;
}

int main( void ){
  int i,q;

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

  q = partition( 0 , n - 1 );

  for( i = 0 ; i < n ; i++ ){
    if( i ){
      printf(" ");
    }
    if( i == q ){
      printf("[");
    }
    printf("%d",A[i]);
    if( i == q ){
      printf("]");
    }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#include <iostream>
#include <string.h>
#include <algorithm>

const long long INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    long long L, R;
    cin >> L >> R;

    long long min = INF;

    for(long long i = L; i < R; i++) {
        for(long long j = L+1; j <= R; j++) {
            if((i*j)%2019 < min) {
                min = (i*j)%2019;
            }
            if(min == 0) break;
        }
        if(min == 0) break;
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/27 14:00:46 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	string	s;
	ll		k;
	cin >> s >> k;

	ll	sum;
	sum = 0;
	ll	cnt;
	cnt = 0;
	for (int i = 1; i < s.size(); i++)
	{
		if (s.at(i) == s.at(i - 1))
		{
			cnt++;
			if (cnt % 2)
				sum++;
		}
		else
			cnt = 0;
	}
	sum *= k;
	if (s.at(0) == s.back())
	{
		ll	na, nb;
		na = 1;
		nb = 1;

		rep(i, s.size() - 1)
		{
			if (s.at(i) == s.at(i + 1))
				na++;
			else
				break ;
		}
		if (na == s.size() && na % 2)
			sum += k / 2;
		else
		{
			for (int i = s.size() - 1; i > 0; i--)
			{
				if (s.at(i) == s.at(i - 1))
					nb++;
				else
					break;
			}
			if (na * nb % 2)
				sum += k - 1;
		}
	}
	cout << sum << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
// atcoder/abc136/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;
    --a[0];
    for (int i = 0; i + 1 < a.size(); ++i) {
      if (a[i] < a[i + 1]) {
        --a[i + 1];
      }
    }
    bool f = true;
    for (int i = 0; i + 1 < a.size(); ++i) {
      f = f && (a[i] <= a[i + 1]);
    }
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


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

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

#define fr first
#define sc second

int main(){
	ll n,k;
	cin >> n >> k;
	
	if(k == 0){
		cout << n*n << endl;
		return 0;
	}
	
	ll ret = 0;
	for(ll b = k+1 ; b <= n ; b ++){
		ll x = (n+1)/b;
		ll y = (n+1)%b;
		ret += x*(b-k) + max(0LL,y-k);
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
N = int(input())
ans = ""
while N:
    if N % 2:
        ans += "1"
        N = -((N - 1) // 2)
    else:
        ans += "0"
        N = -(N // 2)
if len(ans) == 0:
    ans = "0"
print(ans[::-1])

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

flag = [False]*n
nums = [0]*n
for _ in range(m):
  p,s = input().split()
  p = int(p)-1
  if s == "AC": flag[p] = True
  elif flag[p] == False: nums[p] += 1
ac = flag.count(True)
wa = 0
for i in range(n):
  if flag[i]: wa += nums[i]
print(ac, wa)

Measured memory_bytes: 10340
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, V;
int K;
int L[20];
int X[200000];
int U[200000];
int F[20][200000];
bool B[200000];
int dp[2][1<<20];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (x < y) swap(x, y);
  U[y] = x;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> V;
  rep(i, N) cin >> X[i];
  int t = V;
  //L[K++] = t;
  while (t > 0) {
    t /= 2;
    L[K++] = t;
  }

  rep(e, 2) {
    rep(k, K) {
      rep(i, N) U[i] = i;
      rep(i, N-1) {
        int d = abs(X[i+1]-X[i]);
        if (d <= L[k]) unite(i, i+1);
      }
      rep(i, N) F[k][i] = find(i);
    }
    dp[e][0] = 0;
    rep(b, 1<<K) {
      int x = dp[e][b];
      rep(i, K) {
        if ((1<<i) & b) continue;
        int nx = x;
        if (x != N) nx = F[i][x]+1;
        int nb = b | (1<<i);
        dp[e][nb] = max(dp[e][nb], nx);
      }
    }
    reverse(X, X+N);
  }

  rep(i, N) U[i] = i;
  rep(i, N-1) {
    int d = X[i+1]-X[i];
    if (d <= V) unite(i, i+1);
  }
  rep(lb, 1<<K) {
    int rb = ((1<<K)-1) ^ lb;
    int a = dp[0][lb],
        b = N-1-(dp[1][rb]);
    if (a > b) {
      // all possible
      rep(i, N) {
        cout << "Possible\n";
      }
      return 0;
    }
    if (same(a, b)) {
      B[find(a)] = true;
    }
  }

  rep(x, N) {
    if (B[find(x)]) cout << "Possible\n";
    else cout << "Impossible\n";
  }
  return 0;
}


Measured memory_bytes: 25600
use proconio::*;

fn main() {
    input! {
        n: usize,
    }

    let mut p = vec![];
    let mut v = vec![];
    for _ in 0..n {
        input! {
            a: i64,
            b: i64,
        }

        p.push(a);
        v.push(b);
    }

    p.sort();
    v.sort();
    v.reverse();

    let iter = n / 2;

    let ans = if n % 2 == 1 {
        v[iter] - p[iter] + 1
    } else {
        v[iter] - p[iter] + v[iter - 1] - p[iter - 1] + 1
    };

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

Measured memory_bytes: 9764
A,B=map(int,input().split())
count = 0
for i in range(A,B+1):
    tmp = str(i)
    for j in range(len(tmp)):
        if tmp[j] != tmp[len(tmp)-j-1]:
            break
    if j == len(tmp)-1:
        count +=1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h;
  cin >> h >> w;
  string s[h];
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      cout << s[i/2][j];
    }
    cout << endl;
  } 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define pb push_back

void solve(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	forn(i,0,n){
		cin >> a[i];
	}
	ll dp[n];
	dp[n-1] = 0;
	dp[n-2] = abs(a[n-2]-a[n-1]);
	for(int i=n-3;i>=0;--i){
		dp[i] = min(dp[i+1]+abs(a[i]-a[i+1]),dp[i+2]+abs(a[i]-a[i+2]));
	}
	cout<<dp[0];
	return ;
}

int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

Measured memory_bytes: 4768
#include <stdio.h>

typedef long long Int;

Int min(Int a, Int b)
{
  return a<b ? a : b;
}

Int dif(Int a, Int b)
{
  return a>b ? a-b : b-a;
}

int main(void)
{
  Int n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
    
  if (dif(a,b) % 2 == 0) {
    printf("%lld", dif(a,b)/2);
    return 0;
  }
  
  printf("%lld", min(dif(2-a,b+1), dif(2*n-a,b-1))/2);
  
  return 0;
}


Measured memory_bytes: 256
require 'set'

def main
  n = ARGF.gets.to_i

  chars = ARGF.gets.chars.to_a

  max_common = 0
  0.upto(n-2) do |i|
    s1 = Set.new(chars[0..i])
    s2 = Set.new(chars[i+1..n-1])

    max_common = [max_common, (s1 & s2).count].max
  end

  puts max_common
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <complex>
#include <algorithm>

using namespace std;

typedef complex<double> Point;
typedef vector<Point> Polygon;
const int N = 10;
const double EPS = 1.0e-10;

bool is_Online(Point a, Point b, Point c){
  return abs(a-c)+abs(b-c)<abs(a-b)+EPS;
}

bool is_touch(Polygon &a, Polygon &b){
  for(int i=0;i<a.size();i++){
    for(int j=0;j<b.size();j++){
      bool c[4];
      Point p1=a[i], p2=a[(i+1)%a.size()], p3=b[j], p4=b[(j+1)%b.size()];
      c[2]=is_Online(p1, p2, p3);
      c[3]=is_Online(p1, p2, p4);
      c[0]=is_Online(p3, p4, p1);
      c[1]=is_Online(p3, p4, p2);
      if((c[0] && c[1]) || (c[2] && c[3])) return true;
      if((c[0] && c[2] && p1!=p3) || (c[0] && c[3] && p1!=p4) || (c[1] && c[2] && p2!=p3) || (c[1] && c[3] && p2!=p4)) return true;
    }
  }
  return false;
}

bool is_Touch(vector<Polygon> &a, vector<Polygon> &b){
  for(int i=0;i<a.size();i++){
    for(int j=0;j<b.size();j++){
      if(is_touch(a[i], b[j])) return true;
    }
  }
  return false;
}

int ans;
void dfs(int now, int n, int cnt, vector<int> *G, int *color, bool *used){
  if(cnt>ans) return;
  if(now==n){
    ans=min(ans, cnt);
    return;
  }
  for(int i=0;i<=now;i++){
    bool f=true;
    for(int j=0;j<G[now].size();j++){
      if(color[G[now][j]]==i){
	f=false;
	break;
      }
    }
    if(f){
      bool tmp=used[i];
      color[now]=i;
      if(used[i]){
	dfs(now+1, n, cnt, G, color, used);
      }else{
	used[i]=true;
	dfs(now+1, n, cnt+1, G, color, used);
	used[i]=false;
      }
      color[now]=-1;
    }
  }
}

main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    vector<Polygon> country[N];
    int color[N];
    map<string, int> ntoi;
    bool used[N];
    vector<int> G[N];
    fill(used, used+N, false);
    int index=0;
    for(int i=0;i<n;i++){
      string name;
      getline(cin, name);
      getline(cin, name);
      if(ntoi.find(name)==ntoi.end()){
	ntoi[name]=index++;
      }
      Polygon in;
      while(1){
	Point t;
	cin >> t.real();
	if(t.real()==-1) break;
	cin >> t.imag();
	in.push_back(t);
      }
      country[ntoi[name]].push_back(in);
    }
    for(int i=0;i<ntoi.size();i++){
      for(int j=i+1;j<ntoi.size();j++){
	if(is_Touch(country[i], country[j])) G[i].push_back(j), G[j].push_back(i);
      }
    }
    fill(color, color+N, -1);
    ans=10;
    dfs(0, ntoi.size(), 0, G, color, used);
    cout << ans << endl;
   
  }
  return 0;
}

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

int main(){
    
    int n;
    cin >> n;
    vector<int>xor_values(n);
    int total_xor  = 0;
    for(int i = 0; i < n; i++){
        cin >> xor_values[i];
        total_xor = total_xor^xor_values[i];
    }
    //vector<int>res;
    for(int j = 0; j < n; j++){
        long long current_value  = xor_values[j];
        int result = 0;
        for(int i = 0; i < 32; i++){
            long long bit = (1 << i);
            int bit_value = current_value&bit;
            int xor_bit = total_xor&bit;
            if(bit_value == 0){
                result |= (bit&xor_bit);
            }else{
                result |= (bit^xor_bit);
            }
        }
        //res.push_back(result);
        cout << result << endl;
    }
    //for(int i = 0; i < n; i++){
        //int r = 0;
        //for(int j = 0; j < n; j++){
            //if(j!= i){
                //r ^= res[j];
            //}
        //}
        //cout << r << endl; 
    //}
    
}


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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}


int main(){
int H, N;
cin >> H >> N;
vector<int> A(N);
vector<int> B(N);
REP(i, N) cin >> A[i] >> B[i];
vector<vector<ll>>dp(N + 1, vector<ll>(H + 1, INF));
dp[0][0] = 0;
REP(i, N)for(int j = 0; j <= H; ++ j){
  dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
  dp[i + 1][min(j + A[i], H)] = min(dp[i + 1][min(j + A[i], H)], dp[i + 1][j] + B[i]);
}

print(dp[N][H]);


}




Measured memory_bytes: 78592
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    W, H, x, y = map(int, input().split())

    maxarea = W * H / 2

    print("{:.6f} {}".format(maxarea, "1" if 2 * x == W and 2 * y == H else "0"))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
map<int,int>m;
vector<int>v;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(m[x]==0)v.push_back(x);
		m[x]++;
	}
	int ans=0;
	for(int i=0;i<v.size();i++)
		if(v[i]>m[v[i]])ans+=m[v[i]];
		else if(v[i]<m[v[i]])ans+=m[v[i]]-v[i];
	cout<<ans;
}

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

using namespace std;

int main()
{
    int n;
    long long a[10005];
    long long b[10005];
    while(scanf("%d",&n)!=EOF){
        long long sum1=0,sum2=0;
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%lld",&b[i]);
        }
        for(int i=1;i<=n;i++){
            if(a[i]>b[i]) sum1+=a[i]-b[i];
            else if(a[i]<b[i]) sum2+=((b[i]-a[i])/2);
        }
        if(sum1<=sum2) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=105;
int d[15][15];
int cd[15][15];
int f[maxn][maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A,B;
    cin>>A>>B;
    for(int i=1;i<=A;i++)
    {
        for(int j=1;j<=B;j++)
            cin>>d[i][j];
    }
    for(int a=0;a<maxn;a++)
    {
        for(int b=0;b<maxn;b++)
        {
            for(int x=1;x<=A;x++)
            {
                for(int y=1;y<=B;y++)
                    f[a][b]=max(f[a][b],d[x][y]-a*x-b*y);
            }
        }
    }
    memset(cd,0x3f,sizeof(cd));
    for(int a=0;a<maxn;a++)
    {
        for(int b=0;b<maxn;b++)
        {
            for(int x=1;x<=A;x++)
            {
                for(int y=1;y<=B;y++)
                    cd[x][y]=min(cd[x][y],a*x+b*y+f[a][b]);
            }
        }
    }
    bool ok=1;
    for(int i=1;i<=A;i++)
        for(int j=1;j<=B;j++)
            if(cd[i][j]!=d[i][j])ok=0;
    if(!ok) cout<<"Impossible\n";
    else{
        cout<<"Possible\n";
        cout<<maxn*2<<" "<<2*maxn-2+maxn*maxn<<'\n';
        for(int i=1;i<maxn;i++)
            cout<<i<<" "<<i+1<<" X\n";
        for(int i=maxn+1;i<maxn+maxn;i++)
            cout<<i<<" "<<i+1<<" Y\n";
        for(int i=1;i<=maxn;i++)
        {
            for(int j=maxn+1;j<=maxn*2;j++)
            {
                cout<<i<<" "<<j<<" "<<f[i-1][2*maxn-j]<<'\n';
            }
        }
        cout<<1<<" "<<maxn+maxn<<'\n';
    }

}

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

int main(){
  int a;
  cin>>a;
  if(a<=999){
    cout<<"ABC"<<endl;
  } else {
    cout<<"ABD"<<endl;
  }
}

Measured memory_bytes: 256
import Data.List
import Control.Monad
import Data.Array.IO
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B

type Point = (Int,Int)
type IOField = IOUArray Point Char

main = do
    [h,w] <- map read.words<$>getLine
    fld   <- newArray ((0,0),(h+1,w+1)) '.' :: IO IOField
    forM_ [1..h] $ \i -> do
        ls <- B.getLine
        forM_ [1..w] $ \j -> do
            let c = B.index ls (j-1)
            writeArray fld (i,j) c
    --
    r <- (and <$>) $ forM [1..h] $ \i -> do
            (and <$>) $ forM [1..w] $ \j -> do
                c <- readArray fld (i,j)
                if c == '.'
                    then return True
                    else do
                        ch <- mapM (\(di,dj) ->(=='#') <$> readArray fld (i+di,j+dj)) [(-1,0),(1,0),(0,-1),(0,1)]
                        return $ or ch
    putStrLn $ if r then "Yes" else "No"


Measured memory_bytes: 1276
#include <iostream>

using namespace std;

int main()
{
    int n;
    

    while (cin >> n) {
        int ans = 0;
        for (int i1 = 0; i1 < 10; i1++) {
            for (int i2 = 0; i2 < 10; i2++)
                for (int i3 = 0; i3 < 10; i3++)
                    for (int i4 = 0; i4 < 10; i4++)
                        if (i1 + i2 + i3 + i4 == n)
                            ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)
#define END(x) (*(x.end()-1))

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)/b;
}

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    vector<ll>b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll ans=0;
    for(ll i=n-1;i>=0;--i){
        a[i]+=ans;
        if(a[i]%b[i]!=0){
            ans+=b[i]-a[i]%b[i];
        }
    }
    cout<<ans;
}
/*

*/


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define all(s) s.begin(),s.end()
#define pi 3.14159265358979323846
#define fp(x) fixed<<setprecision(x)<<
template<class T>
T mod(T a){
    if(a < 0){
        a += 1000000007;
    }
    return a%1000000007; 
}
template<class T>
T addmod(T a, T b){
    return (mod(a) + mod(b)) % 1000000007;
}
template<class T>
T prodmod(T a, T b){
    return (mod(a) * mod(b)) % 1000000007;
}
template<class T>
T bin_exp(T a, T b)
{
    T res = 1;
    T temp = 1;
    if (b <= 1)
        return a;
    if (b %2 == 0)
        res = bin_exp(a * a, b / 2);
    else
    {
        res *= a;
        temp = bin_exp(a, --b);
    }
    return res * temp;
}
template<class T>
T bin_expmod(T a, T b)
{
    T res = 1;
    T temp = 1;
    if (b <= 1)
        return a;
    if (b %2 == 0)
        res = bin_expmod(prodmod(a,a), b / 2);
    else
    {
        res = prodmod(a,res);
        temp = bin_exp(a, --b);
    }
    return prodmod(res , temp);
}

template<class T>
int digit(T a)
{
    vector<long long> dig = {
        0,
        9,
        99,
        999,
        9999,
        99999,
        999999,
        9999999,
        99999999,
        999999999,
        9999999999,
        99999999999,
        999999999999,
        9999999999999,
        99999999999999,
        999999999999999,
        9999999999999999,
        99999999999999999,
        999999999999999999,
        INT64_MAX};
    auto it = lower_bound(dig.begin(), dig.end(), a);
    int idx = (it - dig.begin());
    return idx;
}
template<class T>
int sumAllInts(T n){
    int a = 1;
    int su = 0;
    while(n){
        su += n%10;
        n/=10;
    }
    return su;
}
template<class T>
void split(char c,T s){
    int n = s.size();
    int i = 0;
    while ((cout<<s[i],i+=1) && (i<n) && (cout<<c<<' '));
}
void solve(){
    long long int N,M;
    cin>>N>>M;
    if((N*2)<M)
    cout<<N+((M-(N*2))/4);
    else if((N*2)>M)
    cout<<M/2;
    else
    {
        cout<<N;
    }
    
   
}
int main(){
    quickie;
    //txt;
    int t=1;
    while(t--){
        solve(); 
        newl; 
    } 
    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int tmp = a, cnt = 1;
    if(b==1){
      cout<<0<<endl;
      return 0;
    }
	while (tmp < b)
	{
		tmp += a - 1;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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



int main(){
  int N;
  cin>>N;
  
  map<int64_t,int64_t> aho;
  for(int i=0;i<N;i++){
    int64_t a;
    cin>>a;
    aho[a]++;
  }
  int64_t one=0;
  int64_t two=0;
  for(auto & x:aho){
    if(x.second>=4){
      if(one<=x.first){
        one=x.first;
      }
      if(two<=x.first){
        two=x.first;
      }
    }
    else if(x.second>=2){
      if(one>=two){
        if(two<=x.first) two=x.first;
      }
      else{
         if(one<=x.first) one=x.first;
      }
    }
  }
  cout<<one*two<<endl;
}

Measured memory_bytes: 9672
import functools as ft

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def gcd_list(numbers):
    return ft.reduce(gcd,numbers)

N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]

def MinusX(Xi_):
    return abs(Xi_-X)

def main(Xi):
    Xi = map(MinusX,Xi)
    output = gcd_list(Xi)
    print(output)

if __name__ == "__main__":
    main(Xi)


Measured memory_bytes: 14596
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	std::string s, t, r;

	std::cin >> s >> t >> r;

	std::transform(s.begin(), s.end(), s.begin(), ::toupper);
	std::transform(t.begin(), t.end(), t.begin(), ::toupper);
	std::transform(r.begin(), r.end(), r.begin(), ::toupper);

	std::cout << s[0] << t[0] << r[0] << std::endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ARegistration solver = new ARegistration();
        solver.solve(1, in, out);
        out.close();
    }

    static class ARegistration {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str1 = s.nextString();
            String str2 = s.nextString();
            if (str2.length() == str1.length() + 1 && str2.startsWith(str1)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32368
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rnd(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

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


int main() {
	int n; cin >> n;
	vector<string> s(n);
	Loop(i, n) {
		cin >> s[i];
	}
	ll ans = 0;
	Loop(k, n) {
		bool judge = true;
		Loop(i, n) {
			if (!judge) break;
			Loop(j, n) {
				if (!judge) break;
				if (s[i][(j + k) % n] != s[j][(i + k) % n]) judge = false;
			}
		}
		if (judge) ans += n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384