akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
  int n,a,b=0,c=0;
  while(scanf("%d",&n),n){
    b=-1;
    c=0;
    while(n--){
      scanf("%d",&a);
      if(a-b==1){
	if(c==1){
	  printf("-");
	  c=2;
	}
      }
      else{
	if(c==2){
	  printf("%d",b);
	  c=0;
	}
	if(b+1)printf(" ");
	printf("%d",a);
	c=1;
      }
      b=a;
    }
    if(c==2)printf("%d",b);
    printf("\n");
  }
  return 0;
}

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


int main()
{
	int n; cin >> n;
	for (int i = 1; i < 10; ++i)
		for (int j = 1; j < 10; ++j)
			if (i * j == n)
			{
				cout << "Yes" << endl;
				return 0;
			}
	cout << "No" << endl;
}



Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	inputs := scanIntNums()
	M := inputs[1]

	acMap := make(map[int]bool)
	waMap := make(map[int]int)

	for i := 0; i < M; i++ {
		ss := scanStrings()
		n, _ := strconv.Atoi(ss[0])
		if ss[1] == "AC" {
			acMap[n] = true
			continue
		}
		if !acMap[n] {
			waMap[n]++
		}
	}

	fmt.Println(countBoolMap(acMap), " ", countIntMap(waMap, acMap))
}

func countBoolMap(cbm map[int]bool) int {
	var sum int
	for _, value := range cbm {
		if value == true {
			sum++
		}
	}
	return sum
}

func countIntMap(cim map[int]int, cbm map[int]bool) int {
	var sum int
	for key, value := range cim {
		if cbm[key] {
			sum += value
		}
	}
	return sum
}
func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}

func scanStrings() []string {
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
char str[200];
int n;
int f(int x)
{
    int ans=0;
    set<char> s1,s2;
    for(int i=0;i<=x-1;i++)
        s1.insert(str[i]);
    for(int i=x;i<n;i++)
    {
        if(!s2.count(str[i]))
         ans+=s1.count(str[i]);
         s2.insert(str[i]);
    }

    return ans;
}
int main(){

    scanf("%d%s",&n,str);
    int ans=0;
    for(int i=1;i<=n-1;i++)
      ans=max(ans,f(i));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int pasta ,juice ,price=0 ,most ,min;
  cin >> min;
  for( int i=0 ; i<2 ; i++ ){
    cin >> pasta;
    if( pasta < min ){
      min = pasta;
    }
  }

  price += min;

  cin >> min;
  cin >> juice;

  if( min > juice ){
    min = juice;
  }

  price += min;
  price -= 50;

  cout << price << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool submit[125252];
bool ac[125252];
int wa[125252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, m;
  cin>>n>>m;
  REP(i, m){
    int p;
    string s;
    cin>>p>>s;
    submit[p]=true;
    if(!ac[p]){
      if(s=="AC"){
        ac[p]=true;
      }
      else{
        ++wa[p];
      }
    }
  }
  int a=0, b=0;
  REP(i, n+1){
    if(submit[i]){
      if(ac[i]){
        ++a;
        b+=wa[i];
      }
    }
  }
  cout<<a<<' '<<b<<'\n';
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if((to_string(i)).size() % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc,char** argv){
  int n,k;
  cin >> n >> k;
  int h[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  vector<vector<int> >cost;
  cost.resize(n);
  cost[0].resize(k);
  for(int i = 0; i < k; i++){
    cost[0][i] = 0;
  }
  for(int i = 1; i < n; i++){
    cost[i].resize(k);
    for(int j = 0; j < k; j++){
      cost[i][j] = 10000;
    }
  }

  for(int i = 1; i < n; i++){
    for(int j = 0; j < k; j++){
      if(i-j <= 0){
        break;
      }else{
        cost[i][j] = *min_element(cost[i-j-1].begin(),cost[i-j-1].end()) + abs(h[i]-h[i-j-1]);
      }
    }
  }
  cout << *min_element(cost[n-1].begin(),cost[n-1].end()) << endl;

  return 0;
}


Measured memory_bytes: 43648
#include <stdio.h>

int main()
{
 int i, j, a, k;
 int temp;
 int r[100];

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

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

   for ( k = 0; k < a-1; ++k ) {
    printf("%d ", r[k]);
   }
   printf("%d\n", r[a-1]);

 }

 return 0;
}



Measured memory_bytes: 2120
#include<stdio.h>
#define INF 100000000000000000
#define NMAX 1000
#define MMAX 2000
int a[MMAX], b[MMAX], c[MMAX];
long long int dist[NMAX];
long long int Bellman(int n, int m);
int main(void)
{
  int i, n, m;
  long long int res;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    a[i]--;
    b[i]--;
    c[i] *= -1;
  }
  res = Bellman(n, m);
  if (res == INF) printf("inf\n");
  else printf("%lld\n", -res);
  return 0;
}


long long int Bellman(int n, int m)
{
  int i, j, update;
  for (i = 0; i < n; i++) dist[i] = INF;
  dist[0] = 0;
  for (i = 0; i < n - 1; i++) {
    update = 0;
    for (j = 0; j < m; j++) {
      if (dist[a[j]] < INF) {
	if (dist[b[j]] > dist[a[j]] + c[j]) {
	  dist[b[j]] = dist[a[j]] + c[j];
	  update = i + 1;
	}
      }
    }
    if (!update) return dist[n-1];
  }
  for (j = 0; j < m; j++) {
    if (dist[a[j]] < INF) {
      if (dist[b[j]] > dist[a[j]] + c[j]) {
	dist[b[j]] = dist[a[j]] + c[j];
	if (b[j] == n - 1) return INF;
      } 
    }
  }
  return dist[n-1];
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void){
    char text[]="000";
    scanf("%s",text);
    if(strncmp("7",&text[0],1)==0){
        printf("Yes");
    }else if(strncmp("7",&text[1],1)==0){
        printf("Yes");
    }else if(strncmp("7",&text[2],1)==0){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

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

const int NIL = -1;
const int INF = 1000000000;

typedef tuple<int, int, int, bool> Uncertain;

int BellmanFord(const vector<vector<int>>& g, int start) {
  vector<int> distance(g.size(), INF);
  distance[start] = 0;
  for(int step = 1; step <= g.size(); ++step) {
    for(int i = 0; i < g.size(); ++i) {
      for(int j = 0; j < g.size(); ++j) {
        if(g[i][j] == INF) continue;
        if(distance[j] <= distance[i] + g[i][j]) continue;
        if(step == g.size()) return NIL;
        distance[j] = distance[i] + g[i][j];
      }
    }
  }
  return *max_element(begin(distance), end(distance));
}

int solve(const vector<vector<int>>& g, const vector<Uncertain>& uncertain, bitset<8> bit = 0, int depth = 0) {
  if(depth == uncertain.size()) {
    auto h(g);
    for(int i = 0; i < uncertain.size(); ++i) {
      int u, v, d;
      bool positive;
      tie(u, v, d, positive) = uncertain[i];
      if(bit[i]) swap(u, v);
      h[v][u] = 0;
      if(positive) h[v][u] = -d;
      else         h[u][v] = d;
    }
    return BellmanFord(h, 0);
  }
  return max(solve(g, uncertain, bit.set(depth), depth + 1), solve(g, uncertain, bit.reset(depth), depth + 1));
}

int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<int>> g(N, vector<int>(N, INF));
  for(int i = 1; i < N; ++i) g[i][0] = 0;
  vector<Uncertain> uncertain;
  for(int i = 0; i < C; ++i) {
    string s;
    cin >> s;
    // parse
    enum {LESS = '<', EQUAL = '*', MORE = '>'};
    int u = 0, v = 0, d = 0;
    char order;
    bool positive;
    int index = 0;
    while(isdigit(s[index])) u = 10 * u + (s[index++] - '0');
    if((order = s[index++]) != EQUAL) ++index;
    while(isdigit(s[index])) v = 10 * v + (s[index++] - '0');
    positive = (s[index++] == '+');
    while(isdigit(s[index])) d = 10 * d + (s[index++] - '0');
    // edge
    --u;
    --v;
    if(order == EQUAL) {
      uncertain.emplace_back(u, v, d, positive);
    } else {
      if(order == MORE) swap(u, v);
      g[v][u] = 0;
      if(positive) g[v][u] = -d;
      else         g[u][v] = d;
    }
  }
  // output
  int answer = solve(g, uncertain);
  if(answer == INF) cout << "inf";
  else              cout << answer;
  cout << endl;
}

Measured memory_bytes: 1316
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}


map<ll, ll> memo;

ll func(ll x, ll a, ll b, ll c, ll d){
    if(x == 0)
        return 0;
    if(x == 1)
        return d;

    if(memo.count(x))
        return memo[x];

    ll ans = 1000000000000000000LL;
    if(x%2==0) ans = min(ans, func(x/2,a,b,c,d)+a);
    else ans = min(ans, min(func((x-1)/2, a, b, c, d)+a+d, func((x+1)/2, a, b, c,d)+a+d));

    if(x%3==0) ans = min(ans, func(x/3,a,b,c,d)+b);
    else if(x%3==1) ans = min(ans, func((x-1)/3, a,b,c,d)+b+d);
    else ans = min(ans, func((x+1)/3,a,b,c,d)+b+d);

    if(x%5==0) ans = min(ans, func(x/5,a,b,c,d)+c);
    else if(x%5==1) ans = min(ans, func((x-1)/5,a,b,c,d)+c+d);
    else if(x%5==2) ans = min(ans, func((x-2)/5,a,b,c,d)+c+2*d);
    else if(x%5==3) ans = min(ans, func((x+2)/5,a,b,c,d)+c+2*d);
    else ans = min(ans, func((x+1)/5,a,b,c,d)+c+d);

    double tmp = d;
    tmp = tmp * (double)x;
    if(tmp < 1e18){
        ans = min(ans, d*x);
    }

    return memo[x] = ans;

}
int main() {
    int t;
    cin >> t;
    REP(cases, t){
        memo.clear();
        ll n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;

        cout << func(n, a, b, c, d) << endl;

    //    for(auto t: memo) cout << t.first << "," << t.second << endl;
    }

    
       
    return 0;
}

Measured memory_bytes: 3820
#include <iostream>

using namespace std;

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

	bool ret = false;

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ret = true;
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ret = true;
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) ret = true;

	cout << (ret ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
program testcase
    integer(8) n
    integer(8) :: i= 0
    integer(8) :: c0 = 0
    integer(8) :: c1 = 0
    integer(8) :: c2 = 0
    integer(8) :: c3 = 0
    character(3) str
    read *, n
    do
        if(i == n)exit
        read *, str
        if(str .eq. "AC")then
            c0 = c0 + 1
        else if(str .eq. "WA")then
            c1 = c1 + 1
        else if(str .eq. "TLE")then
            c2 = c2 + 1
        else if(str .eq. "RE")then
            c3 = c3 + 1
        end if
        i = i + 1
    end do
    print "('AC x ',i0)", c0
    print "('WA x ',i0)", c1
    print "('TLE x ',i0)", c2
    print "('RE x ',i0)", c3
end program

Measured memory_bytes: 2932
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int c=INF;
  rep(i,201){
    int d=0;
  rep(j,a){
  d+=((i-100)-b[j])*((i-100)-b[j]);
  }
    chmin(c,d);
  }
  out(c);
}

Measured memory_bytes: 3648
#include <cstdio>
#include <queue>

int n;
std::vector<int> edges[100010];
int degree[100010];
std::queue<int> queue;
bool removed[100010];

int main(void)
{
    int u,v;
    int i;
    int e;

    //freopen("x.in","r",stdin);

    scanf("%d",&n);
    for(i = 1;i < n;++i)
        scanf("%d %d",&u,&v),edges[u].push_back(v),edges[v].push_back(u),++degree[v],++degree[u];

    for(i = 1;i <= n;++i)
        if(degree[i] == 1)
            queue.push(i);

    while(!queue.empty())
    {
        u = queue.front();
        queue.pop();
        if(removed[u])
            continue;
        if(!degree[u])
            return puts("First"),0;
        for(e = 0;e < edges[u].size();++e)
            if(!removed[edges[u][e]])
                v = edges[u][e];
        removed[v] = removed[u] = true;
        for(e = 0;e < edges[v].size();++e)
            if(!removed[edges[v][e]] && --degree[edges[v][e]] == 1)
                queue.push(edges[v][e]);
            else if(!removed[edges[v][e]] && degree[edges[v][e]] == 0)
                return puts("First"),0;
    }
    puts("Second");

    return 0;
}

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

using namespace std;

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    
    int ans =0;

    for(int i=1; i<=n; i++){

        int sum=0;
        int t = i;

        while(t > 0){
            sum += t%10;
            t /= 10;
        }

        if(sum >= a && sum <= b)
            ans += i;
    }

    cout << ans << endl;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> input_a;
  vector<int> input_b;
  int count=0;
  bool flg=false;
  for(int i=0;i<N;i++){
  	int c,d;
    cin >> c;
    cin >> d;
    if(c==d){
    	count++;
    }else{
    	count=0;
    }
    
    if(count == 3){
      flg=true;
    }
  }
	
  if(flg){
  	cout << "Yes";
  }else{
  	cout << "No";
  }
  
  return 0;
}



Measured memory_bytes: 3580
//  main.cpp
//  AGC040A2
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    string S;
    cin>>S;
    vector<int>count_L(S.length()+1,0);
    vector<int>count_R(S.length()+1,0);
    for (long i=1; i<=S.length(); i++) {
        if (S.at(i-1)=='<') {
            count_L.at(i)=count_L.at(i-1)+1;
        }else{
            count_L.at(i)=0;
        }
    }
    for (long j=S.length()-1; j>=0; j--) {
        if (S.at(j)=='>') {
            count_R.at(j)=count_R.at(j+1)+1;
        }else{
            count_R.at(j)=0;
        }
    }
    long long ans=0;
    for (long k=0; k<=S.length(); k++) {
        //cout<<"L="<<count_L.at(k)<<" R="<<count_R.at(k)<<endl;
        ans+=max(count_L.at(k),count_R.at(k));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M, count; cin >> N;
  M = 0; count = 0; 
  vector<int> H(N);
  
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  
  for(int i = 0; i < N - 1; i++){
    if(H[i] >= H[i+ 1])
      count++;
    else if(H[i] < H[i+ 1]){
      M = max(M, count);
      count = 0;
    }
  }
  M = max(M, count);
  cout << M << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 

#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

const int mod = 998244353;

struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};



int main(){
	int n; cin>> n;
	string s; cin>> s;
	int ans = 0;
	for(int i = 0; i <= 9; i++){
		for(int j = 0; j <= 9; j++){
			for(int k = 0; k <= 9; k++){
				bool ok1 = false, ok2 =false, ok3=false;
				for(int r = 0; r < n; r++){
					if(ok1 == false && ok2 == false && ok3 == false){
						if(s[r]-'0' == i) ok1 = true;
					}
					else if(ok1 == true && ok2 == false && ok3 == false){ 
						if(s[r]-'0' == j) ok2 = true;
					}
					else if(ok1 == true && ok2 == true && ok3 == false){ 
						if(s[r]-'0' == k) ok3 = true;
					}
					
				}
				if(ok1 && ok2 && ok3)
					ans += 1;
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }

 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       ll a;
       cin>>a;
       a=a+a*a+a*a*a;
       pp(a);
     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

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

int main(){
	int x,y;
	cin >> x >> y;
	int t = 1;
	while(t * x - (t - 1) < y){
		t++;
	}
	if(y == 1){
		cout << 0 << endl;
		return 0;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}




Measured memory_bytes: 1220
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データの読み込みの準備
		Scanner sc = new Scanner(System.in);
		String word = sc.next();
		
		int counter = 0;
		
		while (true){
			//一単語ずつ代入
			String temp = sc.next();
			
			//終了条件の確認
			if (temp.equals("END_OF_TEXT")){
				break;	
			}
			
			//大文字小文字を無視して比較
			if (word.equalsIgnoreCase(temp)){
				//一致した場合は、カウンターを加算
				counter++;
			}
		}
		
		//結果を出力
		System.out.println(counter);
	}
}


Measured memory_bytes: 26380
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(2 * 10 ** 5 + 10)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265776
A, B, C = map(int, input().split())

for i in range(1000000):
  #print(i, A, B, C)
  if A%2 == 1 or B%2 == 1 or C%2 == 1:
    break
  if A==B and B==C:
    print(-1)
    exit(0)
  A, B, C = B//2+C//2, A//2+C//2, A//2+B//2
  
print(i)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, D, X;
  cin >> N >> D >> X;
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
   int ans = X;
   for(int i = 0; i < N; i++){
    int tmp = (D - 1) / A[i] + 1;
     ans += tmp;
   }
    cout << ans << endl;
 }
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;

vector<int> cost(1000000);
vector<vector<int>> data(1000000);


int main(){
    int L, R, d, answer = 0;
    cin >> L >> R >> d;
    for(int i = L; i <= R; i++){
        if(i%d == 0) answer++;
    }
    cout << answer << endl;
}

Measured memory_bytes: 30528
import networkx as nx
def MAP(): return map(int, input().split())
n,q=MAP()
g=nx.utils.UnionFind(range(n))
for _ in range(q):
    t,u,v=MAP()
    if t==0:g.union(u,v)
    else:print(1 if g[u]==g[v] else 0)

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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector <int> dp, a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	for (int i=n-1; i>=0; i--) {
		auto l = upper_bound(dp.begin(), dp.end(), a[i]);
		if (l == dp.end()) {
			dp.push_back(a[i]);
		} else {
			dp[l-dp.begin()] = a[i];
		}
	}
	cout << dp.size();
	return 0;
}


Measured memory_bytes: 1276
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O2")
// #pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// #define int ll
#define pb push_back
#define pob pop_back
#define __bp __builtin_popcount
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pdd = pair<ld,ld>;
using vint = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
#define F first
#define S second
const int N = 2e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ll INF = 1e18+7;
const int Mod = 998244353;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(7) << fixed;
}

ll n, x, m;
bool used[N];

void solve()
{
	cin >> n >> x >> m;
	ull ans = 0;
	vint pos;
	for (;n; --n)
	{
		pos.pb(x);
		if (used[x])
			break;
		used[x] = 1;
		ans += x;
		x *= x;
		x %= m;
	}
	// cerr << n << endl;
	if (!used[x])
	{
		cout << ans << '\n';
		return;
	}
	reverse(pos.begin(), pos.end());
	ll cycle_sum = pos[0];
	ll cycle_size = 1;
	for (;; ++cycle_size)
	{
		if (pos[cycle_size] == x)
			break;
		cycle_sum += pos[cycle_size];
	}
	ll cycle_cnt = n / cycle_size;
	ans += ull(cycle_sum) * cycle_cnt;
	n %= cycle_size;
	// cerr << cycle_size << endl;
	// cerr << cycle_sum << endl;
	// cerr << cycle_cnt << endl;
	for (int i = 0; i < n; ++i)
	{
		ans += x;
		x *= x;
		x %= m;
	}
	cout << ans << '\n';
}

signed main()
{
	io();
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		// solve();
		solve();
//		cerr << '\n';

	}
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int mod=1e9+7;

signed main()
{
    int N; cin>>N;
    int ans=1;
    for(int i=1;i<=N;i++){
        ans*=i;
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let a = read::<u32>();
    let p = read::<u32>() + a * 3;
    println!("{}", p / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	const int MAX_N = 100 + 10;
    int N;
    vector<tuple<string, int, int>> v;
    cin >> N;
    for (int i = 1; i <= N; ++i){
    	string s;
    	int p;
    	cin >> s >> p;
    	v.push_back(make_tuple(s, p, i));
    }

    bool check;

    check = true;
    while(check){
    	check = false;
    	for (int i = 0; i < N-1; ++i){
    		if (get<0>(v[i]) > get<0>(v[i+1])) {
    			swap(v[i], v[i+1]);
    			check = true;
    		}
    	}
    }

    check = true;
    while(check){
    	check = false;
    	for (int i = 0; i < N-1; ++i){
    		if (get<0>(v[i]) == get<0>(v[i+1])
    		&& get<1>(v[i]) < get<1>(v[i+1])) {
    			swap(v[i], v[i+1]);
    			check = true;
    		}
    	}
    }



    for (auto _v : v){
    	cout << get<2>(_v) << endl;
    }
    return 0;
}

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

int main(){
  int n,k;cin>>n>>k;
  vector<int> a(n,0);
  REP(i,n) cin>>a.at(i);

  REP(i,k){
    vector<int> b(n+1,0),c(n+1,0);
    REP(j,n){
      b.at(max(0,j-a.at(j)))++;
      b.at(min(n,j+a.at(j)+1))--;
    }
    REP(j,n) c.at(j+1)=c.at(j)+b.at(j);
    REP(j,n) a.at(j)=c.at(j+1);

    bool f=1;
    REP(j,n) if(a.at(j)!=n) f=0;
    if(f) break;
  }

  REP(i,n) cout<<a.at(i)<<" ";
}

Measured memory_bytes: 5636
main=do
 [n,m]<-map read.words<$>getLine
 sc<-map(map read.words).lines<$>getContents
 let ok=filter(\x->f(show x)sc)[(if n==1 then 0 else 10^(n-1))..10^n-1]
 print$if null ok then -1 else head ok
f x[]=True
f x([s,c]:sc)=if fromEnum(x!!(s-1))-48==c then f x sc else False

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    string S;
    cin >> S;
    int year = atoi(S.substr(0, 4).c_str());
    int month = atoi(S.substr(5, 7).c_str());
    int day = atoi(S.substr(8, 10).c_str());
    if (year < 2019)
    {
        cout << "Heisei" << endl;
    }
    else if (year == 2019 && month < 4)
    {
        cout << "Heisei" << endl;
    }
    else if (year == 2019 && month == 4 && day <= 30)
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
}


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

typedef long long ll;

ll inf = 1e9+7;
ll fact[200010] = {0};
ll inv[200010] = {0};

ll mult(ll n, ll m){
    if(m==0) return 1;
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			fact[i] = 1;
			inv[i] = 1;
		}
		else{
			fact[i] = (i*fact[i-1])%inf;
			inv[i] = mult(fact[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	else return (((fact[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll hcomb(ll n,ll k){
	if(n==0 && k==0) return 1;
	return comb(n+k-1,k);
}

int main(){
    ll N,K;
    cin >> N >> K;
    factorial(N+K);
    for(ll i=1;i<=K;i++){
        cout << comb(N-K+1,i)%inf*hcomb(i,K-i)%inf << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  int N; scanf("%d", &N);
  int res = N;
  for ( int i = 0; i <= N; ++i ) {
    int cc = 0;
    int t = i;
    while (t > 0) cc += t % 6, t /= 6;
    t = N - i;
    while (t > 0) cc += t % 9, t /= 9;
    if (res > cc) res = cc ;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 128
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
ans=0
lst=[]
for i in range(n):
    lst.append(s.count(s[i]))
for i in range(n):
    lst[i]-=t.count(s[i])
if max(lst)<=0:
    print(0)
else:
    print(max(lst))

Measured memory_bytes: 3064
/***********************************************
#
#      Filename: d.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-05-20 10:05:23
***********************************************/
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> a;
vector<double> dp;
vector<double> dp2;

double dfs(int cur, int par) {
    double ans = 0;
    int cnt = 0;
    for (auto v : a[cur]) {
        if (v != par) {
            ans += 1.0 + dfs(v, cur);
            ++ cnt;
        }
    }
    if (cnt) ans /= cnt;
    dp[cur] = ans;
    return ans;
}

void dfs2(int cur, int par, double back) {
//    cout << "cur: " << cur << " par: " << par << " back= " << back << endl;
    double ans = 0.0;
    for (auto v : a[cur]) {
        if (v == par) ans += back + 1.0;
        else ans += dp[v] + 1.0;
    }
    dp2[cur] = ans / a[cur].size();

    for (auto v : a[cur]) {
        if (v != par) {
            dfs2(v, cur, (ans - dp[v]-1) / max(1, (int)a[cur].size() - 1) );
        }
    }
}

int main()
{
    cin >> n;
    int u, v;
    a = vector<vector<int>> (n);
    dp = vector<double>(n);
    dp2 = vector<double>(n);
    for (int i = 0; i < n-1; ++ i) {
        cin >> u >> v;
        -- u; -- v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    dfs(0, -1);
    dfs2(0, -1, 0);
    
    for (int i = 0; i < n; ++ i)
        cout << fixed << setprecision(12) << dp2[i] << endl;
    return 0;
}


Measured memory_bytes: 18816
import java.util.Scanner;


public class Main {

	static Scanner sc = new Scanner(System.in);
	static int sum;

	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}

	public static Boolean read(){
		if(!sc.hasNextInt())  return false;

		sum = sc.nextInt();
		sum += sc.nextInt();
		return true;
	}


	public static void solve(){
		System.out.println(Integer.toString(sum).length());
	}

}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n;
	string x;
	set<string> s;
	cin >> n;
	for(long long i = 0; i < n; ++i){
		cin >> x;
		s.insert(x);
	}
	cout << s.size();

	return 0;
}



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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,k,k2;
mat b,w;
lli x,y;
char c;
lli ans = 0;

lli getW(lli a,lli b,lli c,lli d){
  return w[c][d]-w[a][d]-w[c][b]+w[a][b];
}
lli getB(lli a,lli b_,lli c,lli d){
  return b[c][d]-b[a][d]-b[c][b_]+b[a][b_];
}

int main(){
  cin >> n >> k;
  k2 = 2*k;
  b = mat(k2+1,vll(k2+1));
  w = mat(k2+1,vll(k2+1));
  for(lli i = 0;i < n;i++){
    cin >> x >> y >> c;
    if(c == 'W') w[x%k2+1][y%k2+1]++;
    if(c == 'B') b[x%k2+1][y%k2+1]++;
  }

  for(lli i = 1;i <= k2;i++) for(lli j = 1;j <= k2;j++) w[i][j] += w[i-1][j];
  for(lli i = 1;i <= k2;i++) for(lli j = 1;j <= k2;j++) w[i][j] += w[i][j-1];
  for(lli i = 1;i <= k2;i++) for(lli j = 1;j <= k2;j++) b[i][j] += b[i-1][j];
  for(lli i = 1;i <= k2;i++) for(lli j = 1;j <= k2;j++) b[i][j] += b[i][j-1];

  for(lli i = 0;i <= k;i++){
    for(lli j = 0;j <= k;j++){
      lli ansB =
      getB(0,0,i,j)+
      getB(i+k,0,k2,j)+
      getB(i,j,i+k,j+k)+
      getB(0,j+k,i,k2)+
      getB(i+k,j+k,k2,k2)+
      getW(i,0,i+k,j)+
      getW(0,j,i,j+k)+
      getW(i+k,j,k2,j+k)+
      getW(i,j+k,i+k,k2);
      lli ansW =
      getW(0,0,i,j)+
      getW(i+k,0,k2,j)+
      getW(i,j,i+k,j+k)+
      getW(0,j+k,i,k2)+
      getW(i+k,j+k,k2,k2)+
      getB(i,0,i+k,j)+
      getB(0,j,i,j+k)+
      getB(i+k,j,k2,j+k)+
      getB(i,j+k,i+k,k2);
      ans = max(ans,ansB);
      ans = max(ans,ansW);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 62976
'use strict'

function Main(input) {
  let max = 0;
  let cnt = 0;
  const arr = input.split('\n');
  const len = arr[0];
  const str = String(arr[1]);
  for (let i = 0; i < len; i++) {
    if (str.charAt(i) === 'I') {
      cnt += 1;
      max = Math.max(max, cnt);
    } else if (str.charAt(i) === 'D') {
      cnt -= 1;
    }
  }
  console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
// A
// DeP
#include <map>
#include <string>
#include <iostream>
using namespace std;

const int MAXN = 1e5;

int n, A[MAXN], sum;
string S;
map<string, int> M;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> S >> A[i], M[S] = i;
    cin >> S;
    for (int i = M[S]+1; i <= n; ++i) sum += A[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {


  private static void solve() {
    int n = ni();
    long x = nl();
    
    long[] num = new long[51];
    long[] pnum = new long[51];
    num[0] = 1;
    pnum[0] = 1;
    for (int i = 1; i <= 50; i ++) {
      num[i] = num[i - 1] * 2 + 3;
      pnum[i] = pnum[i - 1] * 2 + 1;
    }
    
    
    long ret = 0;
    for (int i = n; i >= 0; i --) {
      if (x >= num[i]) {
        x -= num[i];
        ret += pnum[i];
        if (x > 0) {
          ret ++;
          x --;
        }
      }
      if (x >= num[i]) {
        x -= num[i];
        ret += pnum[i];
      }
      x --;
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 24788
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#define ll long long
//for (auto &x : a) { cin >> x; }
using namespace std;

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

    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0; i<n; i++){
        cin >> a[i];
    }
    ll wm = 0;
    ll ans = 0;
    for(ll i=0; i<n; i++){
        if(a[i] < wm){
            ans += wm - a[i];
            a[i] = wm;
        }
        wm = max(wm, a[i]);
    }
    cout << ans;
}

Measured memory_bytes: 5180
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int N, K, A[112345];

int main() {

	scanf("%d%d", &N, &K);
	rep(i, N) scanf("%d", &A[i]);




	printf("%d\n", (int)ceil((double)(N - 1) / (K - 1)));

	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {

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

		try {

			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String[] inputStringList = br.readLine().split("\\s+");

			List<String> fiveList = new ArrayList<>();
			List<String> sevenList = new ArrayList<>();

			for (String inputString : inputStringList) {
				if (inputString.equals("5")) {
					fiveList.add(inputString);
				} else if (inputString.equals("7")) {
					sevenList.add(inputString);
				}
			}
			
			String result;
			if (fiveList.size() == 2 && sevenList.size() == 1) {
				result = "YES";
			} else {
				result = "NO";
			}
			
			System.out.println(result);
			
		} catch (IOException | NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

	}
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector <int>> A(M);
  vector<int> p(M);
  int ans = 0;
  
  for(int i = 0; i < M; i++){
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      A.at(i).push_back(j);
      cin >> A.at(i).at(j);
    }
  }
  for(int i = 0; i < M; i++){
    cin >> p.at(i);
  }
  
  
  
  for(int tmp = 0; tmp < (1 << 10); tmp++){
    bitset<10> s(tmp);
    bool x = true;
    for(int i = 0; i < M; i++){
      int c = 0;
      for(int j = 0; j < A.at(i).size(); j++){
        if(s.test(A.at(i).at(j) - 1)){
          c++;
        }
      }
      if(c % 2 != p.at(i)){
        x = false;
        break;
      }
    }
    if(x){
      ans++;
    }
    if(s.count() == N){
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void calc(string[] ss) {
    int rows = cast(int) ss.length;
    int cols = cast(int) ss[0].length;

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (ss[i][j] == '#') {
                write('#');
                continue;
            }

            int bomb = 0;
            for (int dr = -1; dr <= 1; dr++) {
                for (int dc = -1; dc <= 1; dc++) {
                    if (dr == 0 && dc == 0)
                        continue;

                    int r = i + dr;
                    int c = j + dc;
                    if (0 <= r && r < rows && 0 <= c && c < cols) {
                        if (ss[r][c] == '#') {
                            bomb++;
                        }
                    }
                }
            }

            write(bomb);

        }
        writeln();
    }

}

void main() {
    auto hw = readints;
    int rows = hw[0];
    string[] ss;
    for (int i = 0; i < rows; i++) {
        ss ~= readln.chomp;
    }

    calc(ss);
}


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

int main(){
    int n;
    cin >>n;
    for(int i = 0; i < n; i++){
        int s;
        cin >>s;
        cout <<"Case " <<i + 1 <<":" <<endl;
        for(int j = 0; j < 10; j++){
            s = (s * s) % 1000000 / 100;
            cout <<s <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
 
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int[] xs = new int[n];
    int[] ys = new int[m];
    for(int i = 0; i < n; i++){
      xs[i] = sc.nextInt();
    }
    for(int i = 0; i < m; i++){
      ys[i] = sc.nextInt();
    }
    
    Arrays.sort(xs);
    Arrays.sort(ys);
    if(xs[n-1] < ys[0] && xs[n-1] < y && ys[0] > x){
      System.out.println("No War");
    }else{
      System.out.println("War");
    }
  }
}

Measured memory_bytes: 23892
# 素因数分解
N = int(input())
ans = 0
s = 0
for i in range(1,N+1,2):
    L = i
    divisors=[0]*(i+1)
    cnt = 1
    # 素因数分解
    for j in range(2,N+1):
        while True:
            if L % j == 0:
                divisors[j] += 1
                L //= j
                if L == 1:
                    s = 1 #1はこれ以上素因数を産まない
                    break
            else:
                break

    for div in divisors:
        cnt *= (div+1)
    if cnt == 8:
        ans += 1
    # print(i,cnt,ans,divisors)

print(ans)

Measured memory_bytes: 3064
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

long long result, n,m,k;

string s[1000];
string t[1000];
string bufS[10];

int main() {
	result = 0;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	cin >> m;

	for (int i = 0; i < m; i++) {
		cin >> t[i];
	}

	for (int i = 0; i < n; i++) {
		bufS[0].clear();
		bufS[0] = s[i];
		k = 0;

		for (int j = 0; j < n; j++) {
			if (bufS[0] == s[j]) {
				k++;
			}
		}
		for (int j = 0; j < m; j++) {
			if (bufS[0] == t[j]) {
				k--;
			}
		}

		if (result <= k) {
			result = k;
		}

	}

	cout << result << endl;

return 0;
}

Measured memory_bytes: 384
n = int(input())
A  = list(map(int, input().split()))
if sum(A)==0:
    print('Yes')
    exit()
if n%3==0:
    a=A[0]
    for i in range(1,n):
        a = a^A[i]
    if a==0:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 20804
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    num = (sum(A) + (4 * M) - 1) // (4 * M)
    A.sort(reverse=1)
    if A[M-1] >= num:
        print('Yes')
    else:
        print('No')


main()


Measured memory_bytes: 3060