akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(input())

d = [[] for _ in range(10)]
for i in range(n):
    d[int(s[i])].append(i)

def lower_bound(al,k):
    if len(al)==0:
        return -1
    ng = -1
    ok = len(al)
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if al[mid]>k:
            ok = mid
        else:
            ng = mid
    if ok==len(al):
        return -1
    return ok

def check(pl):
    pos = -1
    res = []
    for i in range(3):
        pos = lower_bound(d[pl[i]], pos)
        if pos<0:
            return False
        pos = d[pl[i]][pos]
        res.append(pos)
    return True

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if check([i,j,k]):
                res += 1

print(res)

Measured memory_bytes: 4584
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
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;}
// clang-format on

void solve(long long N) {
  ll ans = N / 2;
  if (N % 2 == 0) {
    ans -= 1;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
n = gets.chomp.to_i
num_of_digit = n.to_s.size

def make_n_753 n
  return [[7], [5], [3]] if n == 1
  make_n_753(n - 1).product [7, 5, 3]
end

ans = num_of_digit.times.inject(0) do |sum, i|
  list = make_n_753(i + 1)
  cnt = list.count do |num|
    num = num.flatten
    num.uniq.size == 3 && num.join.to_i <= n
  end
  sum + cnt
end

puts ans

Measured memory_bytes: 17528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define sq(x) ((x)*(x))
#define pi pair<long long,long long>
#define ds(a) ( sq(a.x)+sq(a.y) )

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

i64 a[505][505] ;

int main()
{
    i64 i , j , k , l , m , n ;
    i64 h , w , H , W ;

    scanf("%lld %lld %lld %lld",&H,&W,&h,&w) ;

    for(i=1 ; i<=H ; i++)
    {
        for(j=1 ; j<=W ; j++) a[i][j] = 3000LL ;
    }

    for(i=h ; i<=H ; i+=h )
    {
        for(j=w ; j<=W ; j+=w) a[i][j] = (h*w - 1 )*(3000LL)*(-1) - 1 ;
    }
    i64 sum = 0 ;
    for(i=1 ; i<=H ; i++)
    {
        for(j=1 ; j<=W ; j++) sum += a[i][j] ;
    }

    if(sum>0){
        printf("Yes\n") ;
        for(i=1 ; i<=H ; i++)
        {
            for(j=1 ; j<W ; j++) printf("%lld ",a[i][j]) ;
            printf("%lld\n",a[i][W]) ;
        }
    }
    else printf("No\n") ;

    return 0 ;
}


Measured memory_bytes: 3584
object Main extends App {
  val sc = new FastScanner(System.in)
  val n = sc.nextInt()
  val as = Vector.fill(n)(sc.nextInt()).sorted
  val duplicates = as.groupBy(identity).view.mapValues(_.length).filter{case (_,v) => v >= 2}.keySet
  val d = Array.fill(1000000)(true)
  var ans = 0
  for (a <- as.distinct) {
    if (d(a-1)) {
      if (!duplicates(a)) {
        ans += 1
      }
      var i = 1
      while (a * i <= 1000000) {
        d(a * i - 1) = false
        i += 1
      }
    }
  }
  println(ans)
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 166008
#include <stdio.h>
int main()
{
        int a, number[255], n, ans = 0, i = 0, copy = 546461, flag = 0;
  scanf("%d", &a);
        for (n = 0; n <= a - 1; n++) {
                scanf("%d", &number[n]);
        }
        for (ans = 0; ans<200 ; ans++) {
                for (i=0; i<n; i++) {
                        if (number[i]%2==0) {
                                number[i]=number[i]/2;
                        } else {
                                flag++;
                        }
                }
                if (flag!=0) {
                        break;
                }
        }
        printf("%d", ans);
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

long long n;
long long k;
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    if(n >= k){
        cout << min(n % k, abs((n % k) - k)) << "\n";
        return 0;
    }
    long long l = 0, r = max(2ll, (long long)1e18 / k);
    while(l < r){
        long long m = (l + r) / 2;
        if(n + (k * m) >= k){
            r = m;
        }
        else{
            l = m + 1;
        }
    }
    n += (l * k);
    cout << min(n % k, abs((n % k) - k)) << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
    
int main(){
    int n,a,b,maxs=0;
    cin >> n ;
    vector<int> c(100003,0),sum(100003,0);
    for (int i = 0; i < n ; i++) {
        cin >> a >> b;
        c[a]++;
        c[b+1]--;
    }
    sum[0]=1;
    for(int i=0; i<100002 ; i++){
        sum[i+1] = sum[i]+c[i+1];
    }
    for(int i=1;i<=100002;i++){
        if (sum[i]>=i) maxs = i;
    }
    cout << max(0,maxs-1) << endl;
    return 0;
    
    
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long water[] = new long[num];
		for(int i = 0; i < num; i ++) {
			water[i] = sc.nextLong();
		}
		long ans[] = new long[num];
		long sum = water[num - 1];
		for(int i = 0; i < num - 1; i ++) {
			sum += water[i] * (i % 2 == 0 ? 1 : -1);
		}
		ans[0] = sum / 2;
		System.out.print(ans[0] * 2+" ");
		for(int i = 1; i < num; i ++) {
			ans[i] = water[i - 1] - ans[i - 1];
			System.out.print(ans[i] * 2+" ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 68088
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
  string s;
  cin >> s;
  stack<char> storedKey;
  int sz = s.size();
  for(int i = 0; i < sz; i++) {
    if(s[i] == 'B') {
        if(!storedKey.empty()) {
            storedKey.pop();
        }
    } else {
            storedKey.push(s[i]);
    }
  }
  string ans = "";
  if(!storedKey.empty()) {
      while(!storedKey.empty()) {
          ans += storedKey.top();
          storedKey.pop();
      }
  }
  for(int i = ans.size() - 1; i >= 0; i--) {
      cout << ans[i];
  }
  
  
}


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

int main()
{
	 double d,t,s;
    cin>>d>>t>>s;
    //cout<<d/s;
    
    
    if(d/s<=t)
    {
        cout<<"Yes";
    }
    
    else
    {
        cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s;
    string t;
    string u;
    int a;
    int b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u){
        cout << a - 1 << " " << b << endl;
    }
    else if(t == u){
        cout << a << " " << b - 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		
		int kari;
	
		Scanner scan = new Scanner(System.in);
	
	int[] taller = new int[3];
	
		for(int i=0; i<3; i++){
			taller[i] = 0;}
	
	for(int i=0; i<10; i++){
		int tall = scan.nextInt();
		if(taller[2]<=tall){
			taller[2] = tall;
		if(taller[1]<=taller[2]){
			kari = taller[2];
			taller[2] = taller[1];
			taller[1] = kari;
		if(taller[0]<=taller[1]){
			kari = taller[1];
			taller[1] = taller[0];
			taller[0] = kari;}}}}
			
			
	for(int i=0; i<3; i++){
		System.out.println(taller[i]);}
	}
}


Measured memory_bytes: 26244
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <map>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;


int main(){
    int x,y,z,ptr=0;
    string player[3]={"A","B","C"};
    x=y=z=0;
    string a,b,c;
    cin >> a>> b >>c;
    while(1){
        if (ptr==0){
            if (x==a.size()) break;
            ptr=(a[x]-'a');x++;
        }else if (ptr==1){
            if (y==b.size()) break;
            ptr=(b[y]-'a');y++;
        }else{
            if (z==c.size()) break;
            ptr=(c[z]-'a');z++;
        }
    }
    cout << player[ptr] <<endl;
    return 0;
}


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

int main() {
  int N,Answer=0,l,r;
  cin >> N;
  
  rep(i, N){
    cin >> l >> r;
    Answer += r - l +1;
    }
  cout << Answer << endl;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        map<int, int> cnt;
        for (int i = 0; i < n; i ++) {
                int a;
                scanf("%d", &a);
                cnt[a] ++;
        }
        vector<int> num;
        for (auto c : cnt) num.push_back(c.second);
        int diff = max(0, (int) num.size() - k);
        sort(num.begin(), num.end());
        int ans = 0;
        for (int i = 0; i < diff; i ++) ans += num[i];
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		ll n,ma=-2000000000001,mi=2000000000001;
		cin>>n;
		ll x,y,mxp=ma,mxm=ma,mip=mi,mim=mi;
		for(int i=0;i<n;i++)
		{
			cin>>x>>y;
			mxp=max(mxp,x+y);
			mxm=max(mxm,x-y);
			mip=min(mip,x+y);
			mim=min(mim,x-y);
		}
		cout<<max(mxp-mip,mxm-mim);
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;



const int MXN = 1e5;
vector<int>g[MXN+1];
vector<int>dp(MXN+1);
vector<int>ans(MXN+1);
vector<int>pd(MXN+1);
int MOD,n;


	
	
void dfs1(int u,int p){
	dp[u]=1;
	vector<int>temp;
	vector<int>chld;
	for(auto v:g[u])
	{
		if(v!=p)
		{
			dfs1(v,u);
			dp[u]*=(1+dp[v]);
			dp[u]%=MOD;
			chld.push_back(v);
			temp.push_back(1+dp[v]);
		}
	}
	vector<int>ft;
	int x=1;
	for(int i=0;i<chld.size();i++)
	{
		x*=temp[i];
		x%=MOD;
		ft.push_back(x);
	}
	vector<int>bt;
	int y=1;
	for(int i=chld.size()-1;i>=0;i--)
	{
		y*=temp[i];
		y%=MOD;
		bt.push_back(y);
	}
	reverse(bt.begin(),bt.end());
	for(int i=0;i<chld.size();i++)
	{
		x=1,y=1;
		if(i-1>=0)x=ft[i-1];
		if(i+1< chld.size())y=bt[i+1];
		pd[chld[i]]=(x*y)%MOD;
	}
	ft.clear();
	bt.clear();
	
}

void dfs2(int u,int p){
	int udp;
	if( p )
	{
		udp=((pd[u]+1)*dp[u])%MOD;
		for(auto v:g[u])
		if(v!=p)
		{
			pd[v]*=(pd[u]+1);
            pd[v]%=MOD;
		}
		swap(udp,dp[u]);
	}
		
	
	ans[u]=dp[u];
	
	for(auto v:g[u])
	if(v!=p)dfs2(v,u);
	
	if(p)
	{
		swap(dp[u],udp);
	}
}
		
	
	
		
int32_t main()
{
   IOS
   cin>>n>>MOD;
   for(int i=1;i<n;i++)
   {
	   int u,v;cin>>u>>v;
	   g[u].push_back(v);
	   g[v].push_back(u);
   }
   dfs1(1,0);
   dfs2(1,0);
   
   for(int i=1;i<=n;i++)
   cout<<ans[i]<<" ";
   cout<<endl;
   
  
}


Measured memory_bytes: 23040
#coding:utf-8
from copy import deepcopy

n = int(input())
A = list(input().split())
B = deepcopy(A)


def BubbleSort(A,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                A[j], A[j-1] = A[j-1], A[j]


def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])

print(A)
print("Stable")

print(B)
if A == B:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 6352
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b,c,k = map(int,input().split())
ans += min(k,a)
k -= a
if k <= 0:
  print(ans)
  exit()
k -= b
if k <= 0:
  print(ans)
  exit()
ans -= min(k,c)
print(ans)

Measured memory_bytes: 65480
#include <iostream>

using namespace std;

int main(void)
{
    int N;

    cin >> N;

    for (int i = N; i < 1000; i++) {
        int a, b, c;
        a = i / 100;
        b = i % 10;
        c = (i - a*100 - b) / 10;

        if (a == b && b == c) {
            cout << i << endl;
            break;
        }
    }    

    return 0;
}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

H = int(input())
W = int(input())
N = int(input())

#a, b, c = (int(i) for i in input().split())  
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

m = max(H, W)

print(math.ceil(N/m))


Measured memory_bytes: 38516
n,l = map(int,input().split())
L = list(map(int,input().split()))
flag = False
cur = 0
for i in range(n-1):
    if L[i]+L[i+1] >= l:
        flag = True
        cur = i+1
        break
if flag:
    print('Possible')
    for i in range(1,cur):
        print(i)
    for i in range(n-1,cur,-1):
        print(i)
    print(cur)
else:
    print('Impossible')

Measured memory_bytes: 14064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  for(int i= 0; i<=x ; i++){//i = 鶴の頭数　j =亀の頭数
      int asi = 2*i+4*(x-i);
      if(asi == y){
        cout << "Yes" << endl;
        return 0;
      }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,H[100001];
	scan(N);
	int flag=1,m=INF;
	rep(i,N){
		scan(H[i]);
	}
	for(int i=N-1;i>=0;i--){
		if(H[i]-1>m) flag=0;
		m=min(m,H[i]);
	}
	if(flag) prin("Yes");
	else prin("No");
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int N, M;
vector<vector<int>> G;
int ans = 0;

void dfs(int curr, std::set<int>& st) {

  if (st.size() == N) {
    ans++;
    return;
  }

  rep(i, G[curr].size()) {
    int next = G[curr][i];
    if (st.count(next)) {
      continue;
    }
    st.insert(next);
    dfs(next, st);
    st.erase(next);
  }
}

int main() {

  cin >> N >> M;
  G.resize(N);
  rep(i, M) {
    int a, b; cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  set<int> st; st.insert(0);
  dfs(0, st);

  std::cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=1e6+11;
int n,m;
char c[3];
char s[N],id[N],op[N];
int mx[27],mn[27],p[27],hv[N];
inline bool check1(int x){
	rep(i,1,m){
		if(id[i]==s[x]){
			if(op[i]=='L')
				--x;
			else
				++x;
		}
		if(x<1)return 1;
	}
	return 0;
}
inline bool check2(int x){
	rep(i,1,m){
		if(id[i]==s[x]){
			if(op[i]=='L')
				--x;
			else
				++x;
		}
		if(x>n)return 1;
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	rep(i,1,m){
		scanf("%s%s",c,c+1);
		id[i]=c[0],op[i]=c[1];
	}
	if(check1(n)||check2(1)){
		puts("0");
		return 0;
	}
	int l=0;
	_rep(i,log2(n),0)
		if(check1(l|(1<<i)))
			l|=(1<<i);
	int r=0;
	_rep(i,log2(n),0)
		if(check2(n+1-(r|(1<<i))))
			r|=(1<<i);
	printf("%d\n",n-r-l);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

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


Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int sum = 0;
        if(K <= A) {
            System.out.println(K);
            return;
        } else {
            sum = A;
            K -= A;
            if(K <= B) {
                System.out.println(sum);
                return;
            } else {
                K -=B;
                if(K > 0) {
                    sum -= K;
                    System.out.println(sum);
                    return;
                }else {
                    System.out.println(sum);
                }
            }
        }



        System.out.println(sum);
    }
}

Measured memory_bytes: 35556
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		
		int currentHighestLength = 0;
		int counter = 0;
		
		while (counter < str.length()) {
			int testLength = 1;
			int currentHighestTestLength = 0;
			if (str.charAt(counter) == 'A' && str.length() - counter > currentHighestLength) {
				while (counter + testLength < str.length()) {
					if (str.charAt(counter + testLength) == 'Z' && testLength + 1 > currentHighestLength) {
						currentHighestTestLength = testLength + 1;
						testLength++;
					} else {
						testLength++;
					}
				}
				counter = str.length();
			} else {
				counter++;
			}
			if (currentHighestTestLength > currentHighestLength) {
				currentHighestLength = currentHighestTestLength;
			} else {
			}
		}
		System.out.println(currentHighestLength);
	}

}


Measured memory_bytes: 27340
#import re
import sys
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n = str(input())
    c = n[-1]
    if c in ["2","4","5","7","9"]:
        print("hon")
    elif c == "3":
        print("bon")
    else:
        print("pon")

    
if __name__ == '__main__':
    main()


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 998244353;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

struct mint {
    long long x;
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<vector<mint>> dp(c-a+1, vector<mint>(d-b+1));
    rep(i,c-a+1) dp[i][0] = mint(b).pow(i);
    rep(j,d-b+1) dp[0][j] = mint(a).pow(j);
    rep(i,c-a){
        rep(j,d-b){
            dp[i+1][j+1] = mint(b+j+1) * dp[i][j+1] + mint(a+i+1) * dp[i+1][j] - mint(a+i) * mint(b+j) * dp[i][j];
        }
    }
    cout << dp[c-a][d-b] << endl;
    return 0;
}

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

int main()
{
    long x,y;
    cin >> x;
    y = x/500*1000 + (x%500)/5*5;
    cout << y;
    return 0;

}

Measured memory_bytes: 256
import javax.swing.text.html.HTMLDocument;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

class Main {
    public static void main(String[] args){
        try {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String[] ss=br.readLine().split(" ");
            long a=Long.parseLong(ss[0]);
            long b=Long.parseLong(ss[1]);
            long c=Long.parseLong(ss[2]);
            long k=Long.parseLong(ss[3]);
            if(k<=a+b){
                System.out.println(Math.min(k,a));
            }else{
                k-=(a+b);
                System.out.println(a-k);
            }
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }
    }
    static void dfs(ArrayList<HashSet<Integer>> list,boolean[] vis,int i){
        vis[i]=true;
        Iterator<Integer> it=list.get(i).iterator();
        while(it.hasNext()){
            int u=it.next();
            if(!vis[u]){
                dfs(list,vis,u);
            }
        }
    }
    static int modInverse(int x,int m){
        return power(x,m-2,m);
    }
    static int power(int x, int y, int m)
    {
        if (y == 0)
            return 1;

        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        return (int)((y%2==0)? p : (x*p)%m);
    }
    static void shuffle(String[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            String temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static class quad{
        int a,b,c,d;
        public quad(int a,int b,int c,int d){
            this.a=a;
            this.b=b;
            this.c=c;
            this.d=d;
        }
    }
}

Measured memory_bytes: 32624
#include <stdio.h>

int main() {
  int a[101][101] = {0};
  int b[101] = {0};
  int d[101] = {0};
  int i,j,r,c;
  int x;
  int e = 0;

  scanf("%d %d" , &r,&c);

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

  for(j=0; j<r; j++){
    for(i=0; i<c; i++) {
      b[i] += a[j][i];
    }
  }

  for(j=0; j<r; j++){
    for(i=0; i<c; i++){
      d[j] += a[j][i];
    }
  }

  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      printf("%d ",a[j][i]);
    }
    printf("%d\n", d[j]);
  }
  for(i =0; i<c; i++) {
    printf("%d " ,b[i]);
    e += b[i];
  }
  printf("%d\n", e);

  return 0;
}



Measured memory_bytes: 2040
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
INF = float('inf')


def find(par, u):
    if par[u] != u:
        par[u] = find(par, par[u])
    return par[u]


def union(rnk, par, u, v):
    x, y = find(par, u), find(par, v)
    if rnk[x] > rnk[y]:
        par[y] = x
    elif rnk[x] < rnk[y]:
        par[x] = y
    else:
        par[x] = y
        rnk[y] += 1


def solve():
    N = int(input())
    E = defaultdict(list)
    for _ in range(N - 1):
        u, v = it()
        x, y = min(u, v), max(u, v)
        E[x].append(y)
    
    for u in range(1, N + 1):
        E[u].sort()

    par = [0] * (N + 1)
    rnk = [0] * (N + 1)
    for u in range(1, N + 1):
        par[u] = u

    ans = 0
    cur = 0
    for u in range(N, 0, -1):
        if E[u]:
            v = E[u][0]
            cur += v - u
            union(rnk, par, u, v)
        else:
            cur += N + 1 - u
        for v in E[u][1:]:
            if find(par, v) != find(par, u):
                cur -= (N + 1 - v)
                union(rnk, par, u, v)
        ans += cur
    return ans


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 60592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC164C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N=int.Parse(Console.ReadLine());
            //string[,] S = new string[N,1];
            int count=1;
            //Queue<string> seen = new Queue<string>();
            var list = new List<string>();
            for (int i = 0; i < N; i++)
            {
                //seen.Enqueue(Console.ReadLine());
                //S[i,0] = Console.ReadLine();
                list.Add(Console.ReadLine());
            }
            list.Sort();
            for(int i = 0; i < N-1; i++)
            {
                if (list[i] != list[i + 1])
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 40736
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    if N <= 999:
        print("ABC")
    else:
        print("ABD")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    string n;
    int k;
    cin >> n >> k;
    int len = (int)n.size();

    vector<vector<ll>> dp1(len+1, vector<ll>(4)), dp2(len+1, vector<ll>(4));
    dp1.at(0).at(0) = 1;
    for (int i=0; i<len; i++) {
        int cur = n.at(i) - '0';
        for (int j=0; j<4; j++) {
            dp2.at(i+1).at(j) += dp2.at(i).at(j);
            if (j != 0) dp2.at(i+1).at(j) += dp2.at(i).at(j-1) * 9;
        }
        if (cur == 0) {
            for (int j=0; j<4; j++) {
                dp1.at(i+1).at(j) += dp1.at(i).at(j);
            }
        } else {
            for (int j=1; j<4; j++) {
                dp1.at(i+1).at(j) += dp1.at(i).at(j-1);
            }
            for (int j=0; j<4; j++) {
                dp2.at(i+1).at(j) += dp1.at(i).at(j);
                if (j != 0) dp2.at(i+1).at(j) += dp1.at(i).at(j-1) * (cur - 1);
            }
        }
    }

    cout << dp1.at(len).at(k) + dp2.at(len).at(k) << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
// #define INF 
// #define MOD 1e9+7
#define F first
#define S second
using namespace std;



int main() {
	
	int n,k,MOD = 1e9+7;
	cin>>n>>k;
	long long arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	
	vector<vector<long long>>dp(n+1,vector<long long>(k+1,0));
	vector<long long>prev(k+1,0), nxt(k+1,0);
	
	
	for(int i=0;i<=n;i++)
	{
	    dp[i][0]=1;
	    nxt[0]=1;
	    //cout<<"1"<<" ";
	    for(int j=1;j<=k;j++)
	    {
	        
            
            if(i!=0)
            {
        	    if(j<=arr[i-1])
            	    dp[i][j] = prev[j];
        	    else
            	    dp[i][j] = (prev[j]%MOD - prev[j-arr[i-1]-1]%MOD + MOD)%MOD;
            }
    	    nxt[j] = (nxt[j-1]%MOD + dp[i][j]%MOD)%MOD;
    	    
    	    //cout<<dp[i][j]<<" ";
	    }
	    //cout<<endl;
	    prev=nxt;
	}
	cout<<dp[n][k];
	
	return 0;
}


Measured memory_bytes: 83648
package main

import "fmt"

func main() {
	var b string
	fmt.Scan(&b)

	switch b {
	case "A":
		fmt.Println("T")
	case "T":
		fmt.Println("A")
	case "C":
		fmt.Println("G")
	case "G":
		fmt.Println("C")
	}
}


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

int main() {
  int W,H,N;
  cin >> W >> H >> N;
  vector<tuple<int,int,int>> vec(N);
  for(int i = 0;i < N;i++) {
    int A,B,C;
    cin >> A >> B >> C;
    vec.at(i) = make_tuple(A,B,C);
  }
  int A = 0;
  int B = W;
  int C = 0;
  int D = H;
  for(int i = 0;i < N;i++) {
    if(get<2>(vec.at(i)) == 1) {
      A = max(A,get<0>(vec.at(i)));
    }
    else if(get<2>(vec.at(i)) == 2) {
      B = min(B,get<0>(vec.at(i)));
    }
    else if(get<2>(vec.at(i)) == 3) {
      C = max(C,get<1>(vec.at(i)));
    }
    else {
      D = min(D,get<1>(vec.at(i)));
    }
  }
  if(A - B >= 0 || C - D >= 0) {
    cout << 0 << endl;
  }
  else {
    cout << ( B - A ) * ( D - C ) << endl;
  }
}

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

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  cin >> H;

  for (int i = 1; i <= H; i++) cin >> A[i];

  for (int i = H / 2; i >= 1; i--) maxHeapify(i);

  for (int i = 1; i <= H; i++) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 4940
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<bitset>
using namespace std;
const int M=100005;
bitset<405> bt[405];
int n,m,ans,x[M],y[M],die[405];
int read()
{
   int x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return x*f;
}
int main()
{
	n=read();m=read();
	for (int i=1;i<=m;i++) x[i]=read(),y[i]=read();
	for (int i=1;i<=n;i++)
	{
		bt[i][i]=1;
		for (int j=m;j>=1;j--)
		{
			if (bt[i][x[j]]&&bt[i][y[j]]) die[i]=1;
			if (bt[i][x[j]]||bt[i][y[j]]) bt[i][x[j]]=bt[i][y[j]]=1;
		}
	}
	for (int i=1;i<n;i++)
	  if (!die[i])
	  for (int j=i+1;j<=n;j++)
	    if (!die[j]&&(bt[i]&bt[j]).none()) ans++;
	printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    string s;
    cin>>s;
    int n=s.length();
    int fx =0;
    rep(i,n){
        fx += s[i]-'0';
    }
    YN(stoi(s)%fx==0);
}

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

int solve(int n,int a[]){
    int ans=0;
    int next=1;
    int pre=0;
    rep(i,n)
    {
        if(a[i]==next){
            ans+=i-pre;
            next++;
            pre=i+1;;
        }else
        {
            continue;
        }
        
    }
    ans+=n-pre;
    return next>1?ans:-1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n;
cin>>n;
int a[n];

rep(i,n)cin>>a[i];
cout<<solve(n,a)<<endl;
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 K, X;
  cin >> K >> X;
  cout << ((K*500 >= X) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll A, B, N;
    cin >> A >> B >> N;

    ll m = min(B - 1, N);
    put(A * m / B);
}
signed main(){ Main();return 0;}

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

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (auto &i : s)
	{
		cin >> i;
	}
	int ans = 0;
	for (int b = 0; b < n; b++)
	{
		vector<string> t(s);
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				t[i][j] = s[i][(j + b) % n];
			}
		}
		bool f = true;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				f &= t[i][j] == t[j][i];
			}
		}
		if (f)
		{
			ans++;
		}
	}
	ans *= n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int n,i,j,ans=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        int c=1;
        for(j=0;j<i;j++){
            if(a[i]<a[j]){
                c=0;
                break;
            }
        }
        if(c) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	static long startTime = System.currentTimeMillis();
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		long A = sc.nextLong();
		long B = sc.nextLong();
		for (long i = B + 1; ; i++) {
			if ((i & 0xFF) == 0 && System.currentTimeMillis() - startTime > 3500) break;
			long ca = i / A + i % A;
			long remb = i % B;
			long cb = i / B + remb / A + remb % A;
			if (ca < cb) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}

}



Measured memory_bytes: 26460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

  
int main(){
  int x;
  cin>>x;
  int ans=1;
  for (int b = 2; b <= x; b++){
        int v = b * b;
        while( v<=x ){
            ans=max(ans,v);
            v *= b;
        }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int X, happiness = 0;
	cin >> X;

	while (X > 0) {
		if (X / 500 >= 1) {
			happiness += 1000;
			X -= 500;
		}
		else if (X / 5 >= 1) {
			happiness += 5;
			X -= 5;
		}
		else {
			X = 0;
		}
	}

	cout << happiness;
}

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

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

using ull = unsigned long long;
using P = pair<int, int>;

const ull INF = 1e18;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  ull a[N];
  rep (i, N) cin >> a[i];

  bool flag = false;

  rep (i, N) {
    if (a[i] == 0) {
      flag = true;
      break;
    }
  }

  if (flag) {
    cout << 0 << endl;
    return 0;
  }

  ull ans = a[0];
  reps (i, 1, N) {
    if (ans > INF || (ans == INF && a[i] != 1)) {
      flag = true;
      break;
    }

    ull tmp_ans = ans * a[i];
    if (tmp_ans == INF) {
      ans = tmp_ans;
      continue;
    }

    string tmp = to_string(ans);
    string tmp2 = to_string(a[i]);
    if (tmp2.size() > 19 - tmp.size()) {
      flag = true;
      break;
    }

    ans *= a[i];
  }

  if (flag || ans > INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4472
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int n;
    string s;
    cin >> n >> s;
    char c = s.at(0);
    int res = 1;
    for(int i=0; i<n; i++){
        if(s.at(i)!=c){
            c = s.at(i);
            res++;
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int cntDivisors(int n)
{
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        if(n % i == 0) cnt++;
    }
    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cnt = 0;
    int n;
    cin >> n;
    for(int i = 105; i < n + 1; i += 2)
    {
        if(cntDivisors(i) == 8) cnt++;
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input() #sys.stdin.readlineは最後が改行
s=s+s[0]

ans = ['X']*(n+2)

ans[0] = 'S'
ans[1] = 'S'

for zero, one in ['SS','SW','WS','WW']:
    ans[0] = zero
    ans[1] = one
    for i in range(1,n+1):
        if (s[i] == 'o' and ans[i]=='S') or (s[i] == 'x' and ans[i]=='W'):
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = 'S' if ans[i-1]=='W' else 'W'

    if ans[0:2] == ans[n:]:
        print(*ans[:n],sep='')
        exit()

print(-1)


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

int main()
{
  int N, K;
  cin >> N >> K;
  typedef long long ll;
  vector<ll> H(N);
  for (auto & h : H)
    cin >> h;
  sort(H.begin(), H.end());
  auto b = H.begin();
  auto e = H.end() - K;
  cout << ((b <= e) ? accumulate(b, e, 0LL) : 0);
  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define EPS     1e-11
#define INF     0x7fffffff
#define LL_INF  0x7fffffffffffffff

typedef long long LL;
struct Point {
        int x, y;
};
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n+1);
    for (int i = 0; i <= n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int res = v[1] - v[0];
    for (int i = 2; i <= n; i++) {
        res = gcd(v[i] - v[0], res);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
N = int(input())
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(N) :
    if i + 1 < N :
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i + 2 < N :
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))
        
print(dp[-1])

Measured memory_bytes: 52672
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a;i<=b;++i)
#define UF(i,a,b) for(register int i=a;i>=b;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
inline int r(int &x)
{
    int f=1;x=0;
    char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
    return x*=f;
}
inline ll r(ll &x)
{
    ll f=1ll;x=0ll;
    char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1ll;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(ll)(c-'0');
    return x*=f;
}
inline ull r(ull &x)
{
    x=0ull;
    char c=getchar();
    for(;!isdigit(c);c=getchar());
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(ull)(c-'0');
    return x;
}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define mp(a,b) make_pair(a,b)
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

int prime_have[10];
int prime_num[10];
int primes=0;
ll ni[100020];
int nownum=0;
const ll mod=1000000007ll;
ll qp(ll a,ll b)
{
	if(b==1ll) return a;
	ll w=qp(a,b/2);
	if(b&1) return ((w*w)%mod)*a%mod;
	else return (w*w)%mod;
}
ll _ni(ll a){return qp(a,mod-2);}
void prework()
{
	ni[0]=1;
	ll a=1;
	F(i,1,100010)
	{
		a=a*i%mod;
		ni[i]=_ni(a);
	}
	return;
}
int m,n;
void solve()
{
	F(i,2,100000)
	{
		nownum=0;
		while(m%i==0) {m/=i;++nownum;}
		if(nownum!=0) {prime_have[++primes]=i;prime_num[primes]=nownum;}
	}
	if(m!=1) {prime_have[++primes]=m;prime_num[primes]=1;}
	//F(i,1,primes) printf("%d,%d\n",prime_have[i],prime_num[i]);
	ll ans=1;
	F(i,1,primes)
	{
		F(j,1,n-1) ans=ans*(prime_num[i]+j)%mod;
		ans=ans*ni[n-1]%mod;
	}
	printf("%lld\n",ans);
	return;
}
int main()
{
	prework();
	r(n),r(m);
	solve();
	return 0;//ok
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

ll dp[100005][4];
const int MOD = 1e9+7;
int main(){
  string s; cin >> s;
  
  dp[0][0] = 1;
  rep(i,s.size()){
    rep(j,4){
      if(s[i] == '?'){
        dp[i+1][j] += dp[i][j]*3;
        dp[i+1][j] %= MOD;
      }else{
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] %= MOD;
      }
    }
    if(s[i] == 'A' || s[i] == '?'){
      dp[i+1][1] += dp[i][0];
      dp[i+1][1] %= MOD;
    }
    if(s[i] == 'B' || s[i] == '?') {
      dp[i+1][2] += dp[i][1];
      dp[i+1][2] %= MOD;
    }
    if(s[i] == 'C' || s[i] == '?'){
      dp[i+1][3] += dp[i][2];
      dp[i+1][3] %= MOD;
    }
  }
  
  cout << dp[s.size()][3] << endl;
  
  return 0;
}

Measured memory_bytes: 3584