akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXL = 2000;

bool ngAC[MAXL*5], ngBC[MAXL*5];

int main() {
  std::string a, b, c; std::cin >> a >> b >> c;
  int aL = a.size(), bL = b.size(), cL = c.size();
  int mL = std::max(aL, std::max(bL, cL));
  std::fill_n(ngAC, MAXL*5, false);
  std::fill_n(ngBC, MAXL*5, false);
  for(int i = 0; i < aL; ++i) for(int j = 0; j < cL; ++j) {
    if(a[i]!='?' && c[j]!='?' && a[i]!=c[j]) ngAC[MAXL*2+i-j] = true;
  }
  for(int i = 0; i < bL; ++i) for(int j = 0; j < cL; ++j) {
    if(b[i]!='?' && c[j]!='?' && b[i]!=c[j]) ngBC[MAXL*2+i-j] = true;
  }
  
  int ans = aL+bL+cL;
  for(int ob = -MAXL*2; ob < MAXL*2; ++ob) {
    int bl = std::min(0, ob), br = std::max(aL, ob+bL);
    if(br - bl > ans) continue;
    // check AB match
    bool ok = true;
    for(int x = std::max(0, ob); x < std::min(aL, ob+bL); ++x) {
      if(a[x]!='?' && b[x-ob]!='?' && a[x]!=b[x-ob]) { ok = false; break; }
    }
    if(!ok) continue;
    for(int oc = -MAXL*2; oc < MAXL*2; ++oc) {
      int cl = std::min(bl, oc), cr = std::max(br, oc+cL);
      if(cr - cl > ans) continue;
      if(ngAC[MAXL*2+oc]) continue;
      if(ngBC[MAXL*2+oc-ob]) continue;
      ans = cr - cl;
    }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int N, M; cin >> N >> M;
  vector <int> Graph[N];

  for (int i = 0; i < M; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  for (int i = 0; i < N; i++){
    cout << Graph[i].size() << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;

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

int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::vector<int> h(N);
    for (int i = 0; i < N; i++) {
        std::cin >> h[i];
    }

    // dp table
    std::vector<ll> dp(N+2, INF);

    // init dp table
    // ok

    // init condition
    dp[0] = 0;

    // loop
    for (int i = 0; i < N; i++) {
        chmin(dp[i+1], dp[i] + std::abs(h[i+1] - h[i]));
        chmin(dp[i+2], dp[i] + std::abs(h[i+2] - h[i]));
    }

    std::cout << dp[N-1] << std::endl;
    return 0;
}

Measured memory_bytes: 1408
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val heights = Array.tabulate(n){_ ⇒ readLine.trim.toInt}.sorted
  println(
    (0 to (n - k)).map{it ⇒ heights(it + k - 1) - heights(it)}.min
  )

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

Measured memory_bytes: 38720
#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>

int main() {
    long long n, t, a;

    std::cin >> n;

    long long tt = 1, ta = 1;

    for (int i = 0; i < n; i++) {
        std::cin >> t >> a;

        long long nn = std::max((tt + t - 1) / t, (ta + a - 1) / a);
        tt = nn * t;
        ta = nn * a;
    }

    std::cout << tt + ta << std::endl;

    return 0;
}

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

int main( void )
{
    string s;
    int n;
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        set <string> V;
        cin >> s;
        int l = s.size();
        for ( int i = 1; i < l; i++ ) {
            string left = s.substr( 0, i );
            string right = s.substr( i );
            string left_r = left, right_r = right;
            reverse( left_r.begin(), left_r.end() );
            reverse( right_r.begin(), right_r.end() );
            V.insert( left + right );
            V.insert( right + left );
            V.insert( left + right_r );
            V.insert( right_r + left );
            V.insert( left_r + right );
            V.insert( right + left_r );
            V.insert( left_r + right_r );
            V.insert( right_r + left_r );
        }
        cout << V.size() << endl;
    }
    return 0;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int m;
    set<int> S;
    cin >> m;
    int val = 7 % m;
    while (val && S.count(val) == 0) {
        S.insert(val);
        val = (val * 10 + 7) % m;
    }
    if (val == 0)
        cout << S.size() + 1 << endl;
    else
        cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 50524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		S = S.replaceAll("eraser", "");
		S = S.replaceAll("erase", "");
		S = S.replaceAll("dreamer", "");
		S = S.replaceAll("dream", "");
		if(S.length() == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 30880
n=int(input())
s=input()
a=0
if n%2!=0:
    print('No')
else:
    for i in range(n//2):
        if s[i]==s[i+n//2]:
            a+=1
        else:
            print('No')
            break
    if a==n//2:
        print('Yes')


Measured memory_bytes: 2940
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
bool valid(int x){
    if(x%2){
        return 1;
    }
    return x%3==0||x%5==0;
}
int main(){
    int n;
    R(n);
    REP(i,n){
        int x;
        R(x);
        if(!valid(x)){
            W("DENIED");
            return 0;
        }
    }
    W("APPROVED");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();

        if ((a * b) % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }

    }
}

Measured memory_bytes: 20820
#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
  double a, b, c;
  double area, length, height;

  std::cin >> a >> b >> c;

  double C = c * (M_PI/180);


  area = 0.5 * a * b * sin(C);
  length = sqrt((a*a) + (b*b) - (2 * a * b * cos(C))) + a + b;
  height = b * sin(C);

  std::cout << std::fixed;
  std::cout << std::setprecision(8) << area << std::endl;
  std::cout << std::setprecision(8) << length << std::endl;
  std::cout << std::setprecision(8) << height<< std::endl;
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main (void)
{
	char W[11] ;
    char T[1001] ;
    char END[12] = "END_OF_TEXT";		//??????????????¨
    
    int counter = 0;       				//???????????°
    int i = 0 ;	
    int j = 0 ;						//???????????°
    
    scanf("%s", W);						//??¢????????????W???????´?
    
    for(i = 0 ; W[i] != '\0' ; i++)
    {
    	W[i] = tolower(W[i]);       	//W????°??????????
    }

	/*????????????????????????????????????*/
    
    while(1)
    {
    	scanf("%s", T);					//T????¬?????????????????´?
        if(!strcmp(T,END))     		//T???END_OF_TEXT??§????????´???
        {
        	break;                      //?????????????????????
        }
        
        for(j = 0 ; T[j] != '\0' ; j++)
    	{
    		T[j] = tolower(T[j]);       	//T????°??????????
   		}
        
        if(!strcmp(W,T))
        {
        	counter++;
        }
    }
    
    printf("%d\n",counter);				//???????????¨???
    
    return 0;

}

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

void solve()
{
    ll n,i,sum=0,mod=1e9+7,currsum=0,ans=0;
    cin>>n;
    vector<ll> v(n);

    for(i=0;i<n;i++)
    {
        cin>>v[i];
        sum=(sum+v[i])%mod;
        sum=(sum%mod+mod)%mod;
    }

    for(i=0;i<n-1;i++)
    {
        currsum=(currsum+v[i])%mod;
        currsum=(currsum%mod+mod)%mod;

        ans=(ans%mod+((sum-currsum)%mod*v[i]%mod)%mod)%mod;
        ans=(ans%mod+mod)%mod;
    }

    cout<<ans;
}

int main()
{
    solve();
}

Measured memory_bytes: 4788
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;

vector<int> pnt = {2,3};

bool isPrime(int& n) {
    bool flag = false;

    for (int i = 0; i < pnt.size() || n <= pnt[i]; ++i) {
        if (n == pnt[i]) {
            return true;
        } else if (n % pnt[i] == 0) {
            return false;
        }
    }

    for (int i = pnt.back() + 2; i <= ceil(sqrt(n)); i = i + 2) {
        flag = true;
        for (int j = 0; j < pnt.size(); ++j) {
            if (i % pnt[j] == 0) {
                flag = false;
                break;
            }
        }

        if (flag) {
            pnt.push_back(i);
            if (n % i == 0) {
                return false;
            }
        } else {
            continue;
        }

    }

    return true;
}

int main() {
    int N, counter = 0;
    int tmp;
    bool flag;
    cin >> N;

    for (int i = 0; i < N; ++i) {
        cin >> tmp;
        flag = true;

        if (isPrime(tmp)) {
            counter++;
        }
    }

    cout << counter << endl;
}



Measured memory_bytes: 3100
n = int(input())
cnt = 0
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    if a[i][0] == a[i][1]:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 9096
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n - 2):
  if (p[i] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] and p[i + 1] > p[i + 2]): ans += 1
print(ans)    
         
        

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]!=s[2]&&s[0]==s[1]&&s[2]==s[3]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
<?php
# B - Good Distance

fscanf(STDIN, "%d %d", $N, $D);
$array = [];
for ($i=0;$i<$N;$i++) {
    $array[] = explode(' ', fgets(STDIN));
}

$count = 0;
for ($i=0;$i<$N-1;$i++) {
    for ($j=$i+1;$j<$N;$j++) {
        $sum = 0;
        for ($k=0;$k<$D;$k++) {
            $sum += abs(intval($array[$i][$k]) - intval($array[$j][$k])) * abs(intval($array[$i][$k]) - intval($array[$j][$k]));
        }
        if (is_decimal(sqrt($sum)) && $sum != 0) {
            $count++;
        }
    }
}

echo $count . PHP_EOL;

function is_decimal($value) {
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}


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

#define ll long long

int N = 1e5 +4;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll int x, y;
	
	cin >> x >> y;
	ll int cnt = 0;
	ll int arr[N] = {0}; 
	for(int i = 1; i<=x; ++i)
	{
		
		ll int n, n2, total;
		cin >> n >> n2;
		
		if( (n*n)+(n2*n2) <= y*y)
			cnt++;	
			
	}
		cout << cnt << "\n";
	
		

	
	return 0;
}


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

int main(){
	int a, b, c; cin >> a >> b >> c;
	int av = a + b + c;
	cout << (!(av & 1) && (av / 2 == a || av / 2 == b || av / 2 == c) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
alph = 'abcdefghijklmnopqrstuvwxyz'

s = input()
if s[0] == 'A' and s[1] in alph and s[-1] in alph:
    c = 0
    cnt = 0
    for i in range(2,len(s)-1):
        if s[i] == 'C':
            c += 1
        else:
            if s[i] in alph:
                cnt += 1
                
    if c == 1 and cnt == len(s)-4:
        print('AC')
        exit()

print('WA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int l = s.size();
	bool x = l%2;
	char ini = s[0], fin = s[l-1];
	if(ini==fin){
		if(x)cout<<"Second"<<endl;
		else cout<<"First"<<endl;
	}else{
		if(not x)cout<<"Second"<<endl;
		else cout<<"First"<<endl;
	}
}


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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define GOOGLE 0
#define MULTIPLE_TC 0

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes\n" : "No\n");
}

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

  pre();

  int t = 1, T;

  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}


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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


using Int = __int128_t;
Int abs128(Int val){return val<0?-val:val;}

ostream &operator<<(ostream &os,Int val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,Int &val){
  string s;
  is>>s;
  val=0;
  for(int i=0;i<(int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}


//INSERT ABOVE HERE
signed main(){
  Int n,b;
  cin>>n>>b;
  vector<Int> x1(n),y1(n),d1(n);
  vector<Int> x2(n),y2(n),d2(n);
  for(Int i=0;i<n;i++)
    cin>>x1[i]>>y1[i]>>d1[i]>>x2[i]>>y2[i]>>d2[i];

  auto comp=[](auto &a,auto &b){
    vector<Int> res;
    res.emplace_back(0);
    res.emplace_back(1e8);
    for(Int i=0;i<(Int)a.size();i++)
      res.emplace_back(a[i]);
    for(Int i=0;i<(Int)b.size();i++)
      res.emplace_back(b[i]);
    sort(res.begin(),res.end());
    res.erase(unique(res.begin(),res.end()),res.end());
    return res;
  };

  auto vx=comp(x1,x2);
  auto vy=comp(y1,y2);
  auto vd=comp(d1,d2);

  auto get=[&](auto &v,Int x){
    return lower_bound(v.begin(),v.end(),x)-v.begin();
  };

  auto s=make_v<Int>(vx.size()+1,vy.size()+1,vd.size()+1);
  fill_v(s,0);

  for(Int l=0;l<n;l++)
    for(Int i=get(vx,x1[l]);i<get(vx,x2[l]);i++)
      for(Int j=get(vy,y1[l]);j<get(vy,y2[l]);j++)
	for(Int k=get(vd,d1[l]);k<get(vd,d2[l]);k++)
	  s[i][j][k]++;

  if(0){
    for(Int i=0;i<(Int)vx.size()-1;i++)
      for(Int j=0;j<(Int)vy.size()-1;j++)
	for(Int k=0;k<(Int)vd.size()-1;k++)
	  cout<<(s[i][j][k]>=b)<<":"<<(vx[i+1]-vx[i])*(vy[j+1]-vy[j])*(vd[k+1]-vd[k])<<endl;
  }
	    
  Int ans=0;
  for(Int i=0;i<(Int)vx.size()-1;i++)
    for(Int j=0;j<(Int)vy.size()-1;j++)
      for(Int k=0;k<(Int)vd.size()-1;k++)
	ans+=(s[i][j][k]>=b)*(vx[i+1]-vx[i])
	  *(vy[j+1]-vy[j])*(vd[k+1]-vd[k]);
 
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 20580
use proconio::input;
use std::collections::BinaryHeap;
use std::cmp::Reverse;

struct Node {
    edge: Vec<(usize, i64)>
}

struct Graph
{
    node: Vec<Node>,
}

impl Node {
    fn new() -> Self {
        Node {
            edge: Vec::new(),
        }
    }
}

impl Graph {
    fn new(n: usize) -> Self {
        Graph {
            node: (0..n).map(|_| Node::new()).collect::<Vec<Node>>(),
        }
    }

    fn add_edge(&mut self, a: usize, b: usize, dist: i64) {
        self.node[a].edge.push((b, dist));
        self.node[b].edge.push((a, dist));
    }

    fn dijkstra(&self, start: usize, goal: usize) -> i64 {
        let inf = 1i64 << 60;
        let mut cost = vec![inf; self.node.len()];
        cost[start] = 0;

        let mut q = BinaryHeap::new();
        q.push(Reverse((0, start)));

        while let Some(Reverse((cst, idx))) = q.pop() {
            for &(nxt, dist) in self.node[idx].edge.iter() {
                let cst = dist + cst;
                if cost[nxt] <= cst {
                    continue;
                }
                cost[nxt] = cst;
                q.push(Reverse((cst, nxt)));
            }
        }

        cost[goal]
    }
}

fn main()
{
    input! {
    n:usize,
    v:[[i64;n];n],
    }

    let mut dist = Vec::new();
    for i in 0..n {
        for j in i + 1..n {
            dist.push((v[i][j], i, j));
        }
    }
    dist.sort();
    let mut graph = Graph::new(n);
    let mut ans = 0;
    for (d, a, b) in dist {
        let dist = graph.dijkstra(a, b);
        if dist < d {
            ans = -1;
            break;
        }

        if dist > d {
            graph.add_edge(a, b, d);
            ans += d;
        }
    }

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

Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
//#define int long long  
signed main(){
    int N,M,X;
    int A[104]={};
    bool umu[104]={};
    int sum=0;
    cin >> N >> M >> X;
    REP(i,M){cin >> A[i];umu[A[i]]++;}
    REP(i,X){
        sum+=umu[i];
    }
    cout << min(sum,M-sum) << endl;
    
	return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if ((e - a) <= k)
    cout << "Yay!" << endl;
  
  else
    cout << ":(" << endl;
}

Measured memory_bytes: 256
from collections import deque

def main():
    H, W = map(int, input().split())
    S = list(list(input()) for _ in range(H))
    visited = [[False] * W for _ in range(H)]
    blacks = []
    ans = 0
    dh = [0,1,0,-1]
    dw = [1,0,-1,0]
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                blacks.append((h,w))

    for h, w in blacks:
        if not visited[h][w]:
            Q = deque([(h,w)])
            white = 0
            black = 1
            visited[h][w] = True
            while Q:
                i, j = Q.pop()
                now = S[i][j]

                for n in range(4):
                    nh = i + dh[n]
                    nw = j + dw[n]

                    if 0 <= nh < H and 0 <= nw < W:
                        if not visited[nh][nw]:
                            if now != S[nh][nw]:
                                visited[nh][nw] = True
                                Q.append((nh,nw))
                                if S[nh][nw] == '.':
                                    white += 1
                                else:
                                    black += 1
            ans += white * black

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 58028
#include<iostream>
#include <string>
using namespace std;
string s[200000];
int main()
{
	int n,t=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i]; 
	}
	sort(s,s+n);
	for(int i=0;i<n-1;i++)
	{
		if(s[i]!=s[i+1])t++;
	}
	cout<<t;
	return 0;
}

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

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

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  int a, vA, b, vB, t; cin >> a >> vA >> b >> vB >> t;
  cout << (abs(a - b) <= static_cast<LL>(t) * (vA - vB) ? "YES" : "NO") << '\n';

  return 0;
}

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

int main() {
	int N; cin >> N;
	int M; cin >> M;
	int x[110000];
	if (N >= M) {
		cout << 0;
		return 0;
	}
	
	for (int i = 0; i < M; i++) {
		cin >> x[i];
	}
	sort(x, x + M);
	int sum = x[M - 1] - x[0];
	for (int i = 1; i < M; i++) {
		x[i - 1] = x[i] - x[i - 1];
	}
	sort(x, x + M - 1);
	while (N > 1) {
		sum -= x[M - N];
		N--;
	}
	cout << sum;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int a = Integer.parseInt(strArr[0]);
            int b = Integer.parseInt(strArr[1]);

            String answer = "Odd";
            if (a%2 == 0 || b%2 == 0) {
            	answer = "Even";
			}

            System.out.println(answer);

		} catch (Exception e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 32144
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  const Int MOD = 1e9+7;
  Int s;
  cin>>s;
  
  using P = tuple<Int, Int, Int>;
  deque<P> d;
  Int x=0,a=1,l=0,k=9;
  while(x<s){
    Int c=min((s-x)/a,k);
    if(!c) break;
    x+=a*c;
    l+=c;
    d.emplace_back(a++,c,k);
    k=k*10%MOD;
  }
        
  Int ans=0;
  Int B=1<<14;
  
  vector<Int> po1(B,1),po2(B,1);
  for(Int i=1;i<B;i++) po1[i]=po1[i-1]*10%MOD;
  po2[1]=po1[B-1]*10%MOD;
  for(Int i=2;i<B;i++) po2[i]=po2[i-1]*po2[1]%MOD;
  
  while(l){
    while(x<s){
      Int flg=0,pk=k;
      if(get<0>(d.back())<9&&
	 get<1>(d.back())==get<2>(d.back())){
	d.emplace_back(a++,0,k);
	k=k*10%MOD;
	flg=1;       
      }
      
      if(d.size()==1u){
	a=s/l;	
	k=po2[(a-1)/B]*po1[(a-1)%B]%MOD*9%MOD;
	x=a*l;
	d.front()=P(a++,l,k);	
	k=k*10%MOD;
	d.emplace_back(a++,0,k);
	k=k*10%MOD;
      }
      Int e=get<0>(d.back());
      Int b=get<0>(d.front());
      Int c=min((s-x)/(e-b),get<1>(d[0]));
      
      if(!c){
	if(!get<1>(d.back())){
	  d.pop_back();
	  if(flg) a--,k=pk;
	}
	break;
      }
      
      if(get<0>(d.back())<9)
	chmin(c,get<2>(d.back())-get<1>(d.back()));
      
      get<1>(d[0])-=c;
      if(!get<1>(d[0]))	d.pop_front();
      x-=b*c;
      l-=c;
      get<1>(d.back())+=c;
      x+=e*c;
      l+=c;
    }
    
    if(0){
      Int y=0,z=0;
      for(auto p:d) y+=get<1>(p),z+=get<0>(p)*get<1>(p);
      assert(y==l);
      assert(z==x);
      for(auto p:d) if(get<1>(p)!=l) if(get<1>(p)>get<2>(p)){
	    cout<<x<<" "<<s<<":"<<l<<endl;
	    for(auto p:d) cout<<get<0>(p)<<" "<<get<1>(p)<<" "<<get<2>(p)<<endl;
	    cout<<endl;
	  }
      for(auto p:d) if(get<1>(p)!=l) assert(get<1>(p)<=get<2>(p));
    }

    if(0){
      cout<<x<<" "<<s<<":"<<l<<endl;
      for(auto p:d) cout<<get<0>(p)<<" "<<get<1>(p)<<" "<<get<2>(p)<<endl;
      cout<<endl;
    }
    
    if(x==s){
      if(d.size()==1u) assert(get<1>(d[0])==l);
      if(d.size()==1u) assert(get<0>(d[0])*l==s);
      
      if(d.size()==1u)
	ans+=get<2>(d[0])+MOD-l+1;
      else
	ans++;     
      ans%=MOD;
    }

    x-=get<0>(d[0]);
    l--;
    if(!--get<1>(d[0])) d.pop_front();

    if(!l) break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a[] = new int[3];
        a[0] = scan.nextInt();
        a[1] = scan.nextInt();
        a[2] = scan.nextInt();
        Arrays.sort(a);

        System.out.println(Math.abs(a[2] - a[1]) + Math.abs(a[1] - a[0]));

        
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> l(2*N);
  rep(i,2*N){
    cin >> l[i];
  }
  sort(All(l));
  int ans = 0;
  for(int i=2*N-2;i>=0;i-=2){
    ans += l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    ll n; cin >> n;
    ll k; cin >> k;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        --a[i];
    }
    vector<ll> check(n,-1);
    ll now = 0;
    ll time = 0;
    check[now] = time;
    while(true){
        now = a[now];
        if(check[now] == -1){
            time++;
            check[now] = time;
        }else break;
    }
    ll syuuki = time + 1 - check[now];
    //cout << "time" << endl;
    //cout << time << endl;
    //cout << "syuuki" << endl;
    //cout << syuuki << endl;
    if(k <= time + 1) {
        int pos = 0;
        rep(i,k){
            pos = a[pos];
        }
        pos++;
        cout << pos << endl;
        return 0;
    }
    ll nokori = (k - time - 1) % syuuki;
    rep(i, nokori){
        now = a[now];
    }
    now++;//i-indexed
    cout << now << endl;
    //cout << " " << endl;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

const int width = 100000;

int main(){
  int N;
  cin >> N;
  vector<int> A(N), cnt(width+1, 0);
  int dou = 0;
  REP(i, N){
    cin >> A[i];
    cnt[A[i]]++;
    if(cnt[A[i]]>=2){
      dou++;
    }
  }

  if(dou%2){
    cout << N-dou-1 << endl;
  }
  else{
    cout << N-dou << endl;
  }

  return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll s = (b / x) - (std::max(a - 1, (ll)0) / x);
    if (a == 0)
        s++;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<long long> a(5,0);
  for(int i=0;i<n;i++){
    string s;
    cin >>s;
    char t=s.at(0);
    if( t=='M'){
      a.at(0)++;
    }
    else if(t =='R'){
      a.at(1)++;
    }
    else if(t=='C'){
      a.at(2)++;
    }
    else if(t=='H'){
      a.at(3)++;
    }
    else if(t=='A'){
      a.at(4)++;
    }
  }
  long long ans=0;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
        ans+=a.at(i)*a.at(j)*a.at(k);
      }
    }
  }
  cout << ans;
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main() {
	char s[51] ;
	memset(s,32,sizeof(s));
	int N , K;
	cin >> N  >> K;
	for(int i = 0 ; i < N ; i++){
		cin >> s[i] ;
		if(i == K-1) s[i] += 32 ;
		cout << s[i];
 	}
 	
	return 0 ;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, d = li()

print(-(-n // (2*d + 1) ))

Measured memory_bytes: 3064
#include<stdio.h>
 
int main()
{
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if (W>=x+r && H>=y+r && r<=x && r<=y && x>=0 && y>=0){
        printf("Yes\n");}
        else {
            printf("No\n");}
             
    return 0;
}


Measured memory_bytes: 2100
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def prime_factorize(m):
    pf={}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf

a,b = map(int, input().split())
g = gcd(a,b)
pf = prime_factorize(g)
print(len(pf.keys()) + 1)


Measured memory_bytes: 9464
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans = (sum(a) % mod) ** 2
for i in range(n):
    ans -= a[i] ** 2
    ans %= mod
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + mod) // 2)

Measured memory_bytes: 31436
#include <cstdio>
#include <cstdlib>

int main(){
    int i;
    int N;
    scanf("%d", &N);
  
    char *str;
    int *west;
    int *east;
    str = (char *)malloc(sizeof(char) * N);
    west = (int *)malloc(sizeof(int) * (N+1));
    east = (int *)malloc(sizeof(int) * (N+1));

    west[0] = 0;
    east[0] = 0;
    scanf("%s", str);
    //printf("%s\n", str);
    for(i=1; i<N+1; i++){
        if(str[i-1] == 'W'){
            west[i] = west[i-1] + 1;
            east[i] = east[i-1];
        }else{
            east[i] = east[i-1] + 1;
            west[i] = west[i-1];
        }
    }

    int tmp;
    int min = N;
    for(i=1; i<N+1; i++){
        tmp = west[i-1] + east[N] - east[i];
        if(tmp < min)
            min = tmp;
    }
    //for(i=0; i<N+1; i++){
    //    printf("east: %d\n", east[i]);
    //}
    //for(i=0; i<N+1; i++){
    //    printf("west: %d\n", west[i]);
    //}

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

    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  vii h(n, 0), count(n, 0);
  cin >> h;

  eper(i, n-1, 1) {
    if (h[i-1] >= h[i]) count[i-1] += count[i] + 1;
    else count[i-1] = 0;
  }
  int ans = 0;
  rep(i, 0, n) {
    chmax(ans, count[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
ll n, x;
ll p[55];
ll tot[55];

ll rec(ll n, ll x) {
  if(x >= tot[n]) {
    return p[n];
  } else if(x <= 1) {
    return 0;
  } else if(x <= tot[n] / 2) {
    return rec(n - 1, x - 1);
  } else {
    return rec(n - 1, x - 1) + 1 + rec(n - 1, x - ((tot[n] + 1) / 2));
  }
}

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

  cin >> n >> x;

  p[0] = 1, tot[0] = 1;
  REP(i, n) {
    p[i + 1] = p[i] * 2 + 1;
    tot[i + 1] = tot[i] * 2 + 3;
  }

  cout << rec(n, x) << endl;
}


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

int main(){
  int N;
  string S,ans;
  cin>>N;
  cin>>S;

  for(int i=0;i<S.size();i++){
    int num = S.at(i)-'A';
    char in;
    if(num+N>25){
      in = num+N-26+'A';
    }else{
      in = num+N+'A';
    }
    ans.push_back(in);
  }
  cout<<ans<<endl;
}


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

int eval(int num1, int num2, char operand) {
    switch(operand){
        case '+': return(num1 + num2);
        case '-': return(num1 - num2);
        case '*': return(num1 * num2);
    }
    return(0);
}

int main()
{
    int input;
    int num1, num2;
    std::string s;
    std::getline(std::cin, s);
    std::stringstream ss{s + ' '};
    std::stack<int> stack;
    while(std::getline(ss, s, ' ')) {
        if (std::all_of(s.cbegin(), s.cend(), isdigit)) {
            stack.push(std::stoi(s));
        } else {
            num2 = stack.top(); stack.pop();
            num1 = stack.top(); stack.pop();
            stack.push(eval(num1, num2, s[0]));
        }
    }
    std::cout << stack.top() << std::endl;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];
  r(i,n)a[i]=0;
  r(i,n-1){
    int b;
    cin >> b;
    a[b-1]++;
  }
  r(i,n){
    cout<<a[i]<<endl;
  }
}

Measured memory_bytes: 4416
#include <cstdio>
#include <algorithm>

const int MAXN = 2e5 + 5;

int n, k;
long long int ans;
int arr[MAXN];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
    }
    k = n - k;
    std::sort(arr + 1, arr + n + 1);
    for (int i = 1; i <= k; ++i) {
        ans += arr[i];
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;

int n,m;
vector<int> adj[MAXN];
int col[MAXN];

bool dfs(int u,int color)
{
	if(col[u])
		return color==col[u];
	col[u]=color;
	bool ret=true;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(!dfs(v,color==1?2:1))
			ret=false;
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int a=0,b=0,c=0;
	for(int i=1;i<=n;i++)
		if(!col[i])
		{
			if(adj[i].size()==0U)
				c++,col[i]=1;
			else
			{
				if(dfs(i,1))
					a++;
				else
					b++;
			}
		}
	long long ans=1LL*c*c+2LL*c*(n-c)+2LL*a*a+2LL*a*b+1LL*b*b;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 10880
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    for i in range(1, n + 1):
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
  except:
    pass
print((r, 0)[n > 1])


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

int n, q, cnt = 0;
vector<int> edge[100005];
bool ch[100005] = {0};
int num[100005] = {0};

int solve(int now, int bf);

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  solve(0, -1);
  cin >> q;
  for(int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    if(num[--a] == num[--b])
      cout << 2 << endl;
    else
      cout << 1 << endl;
  }
  return 0;
}

int solve(int now, int bf) {
  if(ch[now]) return num[now];
  ch[now] = 1;
  num[now] = ++cnt;
  for(int i = 0; i < edge[now].size(); ++i) {
    if(edge[now][i] != bf) {
      num[now] = min(num[now], solve(edge[now][i], now));
    }
  }
  return num[now];
}


Measured memory_bytes: 15356
if __name__ == '__main__':
    inputList = input().split()

    A = int(inputList[0])
    B = int(inputList[1])
    C = int(inputList[2])
    K = int(inputList[3])
    limit = pow(10, 18)

    if K % 2 == 0:
        result = A - B
    else:
        result = B - A

    if result > limit:
        result = "Unfair"

    print(result)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int check_max(int n, int a[]){
	int max = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] > max)
		{
			max = a[i];
		}
	}
	return max;
}

int main(){
	int n;
	int a[101];
	int check[101] = {0};
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int max = check_max(n, a);
	int lower_limit;
	if(max % 2 == 0){
		lower_limit =  max / 2;
	} else {
		lower_limit = max / 2 + 1;
	}

	int lowest_num_count = 0;
	for (int i = 0; i < n; ++i)
	{
		if(check[a[i]] == false) {
			check[a[i]] = true;
		}
		if(lower_limit == a[i]){
			lowest_num_count++;
			if (lowest_num_count == 2 && (max%2 ==0))
			{
				cout << "Impossible" << endl;
				return 0;
			}

			if (lowest_num_count == 3 && (max%2 ==1))
			{
				cout << "Impossible" << endl;
				return 0;
			}
		}
		if(lower_limit > a[i]){
			cout << "Impossible" << endl;
			return 0;
		}
	}

	for (int i = lower_limit; i <= max; ++i)
	{
		if (check[i] == false)
		{
			cout << "Impossible" << endl;
			return 0; 
		}
	}


	cout << "Possible" << endl;
	return 0;

}


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

typedef long long ll;

int main() {
    int N, L;
    cin >> N >> L;
    int m = 1000000;
    int idx;
    for (int i=1;i<=N;i++){
        if (m > abs(L+i-1)) {
            m = abs(L+i-1);
            idx = i;
        }
    }
    int ans = 0;
    for (int i=1;i<=N;i++){
        if (i != idx){
            ans += L+i-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
for i in lst:
    ans.append(abs(i-X))
small = min(ans)
for i in ans:
    if i%small != 0:
        while i%small != 0:
            i = i%small
            small = small - i
print(small)

Measured memory_bytes: 14252