akhauriyash/Code-Regression huggingface dataset:
s = input()
k = int(input())
same = len([i for i in s if i!=s[0]])
s = s+s
count = 1
a1 = 0
a2 = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    count += 1
  else:
    a2 += count//2
    count = 1
  if i == len(s)//2-2:
    a1 = a2
    if count > 1:
      a1 += count//2
if count > 1:
  a2 += count//2
ans = a1 + (a2-a1)*(k-1)
if same != 0:
  print(ans)
else:
  print((len(s)//2)*k//2)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int stoi(string s){
	int res=0;
	for(int i=s.size()-1;i>=0;i--){
		res+=(s[i]-'0')*pow(10,s.size()-1-i);
	}
	return res;
}

string itos(int x){
	int size=log10(x);
	string res="";
	for(int i=size;i>=0;i--){
		int sla=pow(10,i);
		res+=(char)(x/sla+'0');
		x%=(int)pow(10,i);
	}
	return res;
}

int main(){
	string a,na,pre;
	int l;
	while(cin>>a>>l){
		vector<int> vec;
		if(a=="0" && l==0)break;
		vec.push_back(stoi(a));
		pair<int,int> ans;
		rep(p,20){
			a=itos(vec[vec.size()-1]);
			ans.first=ans.second=-1;
			int size=a.size();
			if(a.size()<l){
				for(int i=0;i<l-size;i++){
					string alt='0'+a;
					a=alt;
				}
			}
			sort(a.begin(),a.end());
			int mini=stoi(a);
			string res="";
			for(int i=0;i<a.size();i++){
				res+=a[a.size()-1-i];
			}
			int maxi=stoi(res);
			na=itos(maxi-mini);
			rep(i,vec.size()){
				if(vec[i]==stoi(na)){
					ans.first=vec.size();
					ans.second=i;
					break;
				}
			}
			vec.push_back(stoi(na));
			if(ans.first!=-1)break;
		}
		cout<<ans.second<<" "<<vec[ans.first]<<" "<<ans.first-ans.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 1312
/*
 _  __    _   _   _ ____ _____ 
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |  
| . \  / ___ \ |_| |___) || |  
|_|\_\/_/   \_\___/|____/ |_|  
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
vl v,dp;
int f(int x){
    if(x==0){
        return 0;
    }
    if(x<0){
        return intlimit;
    }
    if(dp[x]!=-1){
        return dp[x];
    }
     int zg = min(f(x-1)+abs(v[x-1]-v[x]),f(x-2)+abs(v[x-2]-v[x]));
     dp[x] = zg;
     return zg;
}
int main()
{
    int n;
    cin >> n;
    v.resize(n);
    dp.resize(n,-1);
    rep(i,0,n){
        cin >> v[i];
    }
    dp[n-1] = f(n-1);
    cout << dp[n-1];
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

    int ans = 0;
    for(int i = a; i <= b; i++){
        string s = to_string(i);
        reverse(s.begin(), s.end());
        string t = to_string(i);
        if(s == t) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char a[(int)2e5+10],b[(int)2e5+10];

int main(){
	scanf("%s",a);
	scanf("%s",b);
	int n = strlen(a);
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=(a[i]!=b[i]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2104
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x, y;
    
    while (1) {
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }
        else{
            if(x<y){
                printf("%d %d\n", x, y);
            }
            else{
                printf("%d %d\n", y, x);
            }
        }
    }
    return 0;
}


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

int main()
{
    int n,m,sumW;
    cin>>n>>m;
    string arr[n];
    bool row[n]={0},col[m]={0};
    for(int i=0; i<n; i++)

        cin>>arr[i];
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(arr[i][j]=='#'){
                row[i]=1;col[j]=1;
            }

  for(int i=0;i<n;i++)
  {
      if(row[i])
      {
          for(int j=0;j<m;j++)
          {
              if(col[j])
                cout<<arr[i][j];
          }
          cout<<endl;
      }

  }



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
	long int n;
	long int a;
	long int ans = 0;
	scanf("%ld", &n);
	for (long int i = 0; i < n; i++)
	{
		scanf("%ld", &a);
		ans += a;
	}
	printf("%ld", ans - n);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int D;
	scanf("%d",&D);
	if (D==25){
		puts("Christmas");
	}
	else if (D == 24){
		puts("Christmas Eve");
	}
	else if(D==23){
		puts("Christmas Eve Eve");
	}
	else if(D ==22){
		puts("Christmas Eve Eve Eve");
	}
}

Measured memory_bytes: 128
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n);V a(n);V b(n);VECIN2(a,b);
  ll na=a[0];ll nb=b[0];
  FOR(i,1,n){
    ll nn=max(1LL,max((na+a[i]-1)/a[i],(nb+b[i]-1)/b[i]));
    na=a[i]*nn;nb=b[i]*nn;
  }
  COUT(na+nb);

  return 0;
}


Measured memory_bytes: 256
import queue
N = int(input())
ans = [-1]*N
odd = [[] for _ in range(N)]
even = [[] for _ in range(N)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    if w % 2 == 0:
        even[u-1].append(v-1)
        even[v-1].append(u-1)
    else:
        odd[u-1].append(v-1)
        odd[v-1].append(u-1)

q = queue.Queue()
q.put(0)
ans[0] = 0

while (not q.empty()):
    now = q.get()
    nowa = ans[now]
    for i in odd[now]:
        if ans[i] == -1:
            if nowa == 0:
                ans[i] = 1
            else:
                ans[i] = 0
            q.put(i)
    for j in even[now]:
        if ans[j] == -1:
            ans[j] = nowa
            q.put(j)

for i in ans:
    print(i)

Measured memory_bytes: 92828
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
using namespace std;
 
int a[1010];
 
bool check(int n){
	string s=to_string(n);
	int m=s.size();
	rep(i,m-1) if(s[i]+1!=s[i+1]) return false;
	return true;
}
 
int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
 
	int ans=-1;
	rep(j,n)rep(i,j){
		int cur=a[i]*a[j];
		if(check(cur) && ans<cur) ans=cur;
	}
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 3260
#include <stdio.h>
struct data{
	int d,p;
};
int main(void){
	struct data D[10000],tmp;
	int n,m,i,j,ans;
	while(1){
		scanf("%d %d",&n,&m);
		if(!n)
			break;
		for(i=0;i<n;i++)
			scanf("%d %d",&D[i].d,&D[i].p);
		for(i=0;i<n-1;i++){
			for(j=n-1;j>i;j--){
				if(D[j-1].p<D[j].p){
					tmp=D[j-1];
					D[j-1]=D[j];
					D[j]=tmp;
				}
			}
		}
		for(i=0;i<n;i++){
			if(!m)
				break;
			if(D[i].d<m){
				m-=D[i].d;
				D[i].d=0;
			}
			else{
				D[i].d-=m;
				m=0;
			}
		}
		ans=0;
		for(i=0;i<n;i++)
			ans+=D[i].d*D[i].p;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <algorithm>
#define min(a,b) ((a<b) ? (a) : (b))

using namespace std;

struct lucrare
{
	int in, sf, poz;
};

bool comp(lucrare a, lucrare b)
{
	return a.poz < b.poz;
}

void propaga(int nod, int a, int b);
void update(int nod, int a, int b, int x, int y, int val);

int n, q, t[200005], aint[800005], lazy[800005], stop[200005];
lucrare v[200005];

int main()
{
	int i, j, jj;

	cin >> n >> q;
	for (i = 1; i <= n; i++)
		cin >> v[i].in >> v[i].sf >> v[i].poz;
	for (i = 1; i <= q; i++)
		cin >> t[i];
	sort(v + 1, v + 1 + n, comp);
	for (i = 1; i <= n; i++)
	{
		j = lower_bound(t + 1, t + 1 + q, v[i].in - v[i].poz) - t;
		jj = lower_bound(t + 1, t + 1 + q, v[i].sf - v[i].poz) - t - 1;
		if (t[j] < v[i].sf-v[i].poz)
			update(1, 1, q, j, jj, v[i].poz);
	}
	propaga(1, 1, q);
	for (i = 1; i <= q; i++)
	{
		if (stop[i])
			cout << stop[i] << '\n';
		else cout << -1 << '\n';
	}
	return 0;
}

void update(int nod, int a, int b, int x, int y, int val)
{
	if (lazy[nod] || aint[nod])
		return;
	if (a == b)
	{
		aint[nod] = val;
		return;
	}
	if (x <= a && b <= y)
	{
		lazy[nod] = val;
		return;
	}
	int mij = (a + b) / 2;
	if (x <= mij)
		update(2 * nod, a, mij, x, y, val);
	if (y > mij)
		update(2 * nod + 1, mij + 1, b, x, y, val);
}

void propaga(int nod, int a, int b)
{
	if (lazy[nod] && a < b)
	{
		if (lazy[2 * nod])
		{
			if (lazy[2 * nod] > lazy[nod])
				lazy[2 * nod] = lazy[nod];
		}
		else lazy[2 * nod] = lazy[nod];
		if (lazy[2 * nod + 1])
		{
			if (lazy[2 * nod + 1] > lazy[nod])
				lazy[2 * nod + 1] = lazy[nod];
		}
		else lazy[2 * nod + 1] = lazy[nod];
		lazy[nod] = 0;
	}
	if (a == b)
	{
		if (aint[nod] && lazy[nod])
			stop[a] = min(aint[nod], lazy[nod]);
		else if (aint[nod])
			stop[a] = aint[nod];
		else stop[a] = lazy[nod];
	}
	else
	{
		int mij = (a + b) / 2;
		propaga(2 * nod, a, mij);
		propaga(2 * nod + 1, mij + 1, b);
	}
}

Measured memory_bytes: 11008
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

const int INF = 1 << 30;

struct vtx {
  int x;
  VI ch;
  int op;
};

bool dfs(vector<vtx> &vs, int p) {
  vtx &v = vs[p];
  if(v.ch.size() == 0) {
    v.op = 0;
    return true;
  }
  FOR(c,v.ch) {
    if(!dfs(vs, c)) {
      return false;
    }
  }
  vector<VI> dp(v.ch.size() + 1, VI(v.x + 1, INF));
  dp[0][0] = 0;
  REP(i,0,v.ch.size()) {
    vtx &c = vs[v.ch[i]];
    REP(j,0,v.x+1) {
      if(c.x <= j) {
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-c.x] + c.op);
      }
      if(c.op <= j) {
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-c.op] + c.x);
      }
    }
  }
  v.op = INF;
  FOR(a,dp[v.ch.size()]) {
    v.op = min(v.op, a);
  }
  return v.op != INF;
}

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vtx> vs(N);
  REP(i,1,N) {
    int j;
    cin >> j;
    vs[j-1].ch.push_back(i);
  }
  FOR(v,vs) {
    cin >> v.x;
  }
  cout << (dfs(vs, 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;;

  return 0;
}


Measured memory_bytes: 1364
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++) {
    if(i%k==0) {
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
  return 0;
}

Measured memory_bytes: 3544
#include <cstdio>

int main(void)
{
    struct vectorInt{
        int x,y;
    }v[4],dv;
int     tmp;
    scanf("%d%d%d%d",&v[0].x,&v[0].y,&v[1].x,&v[1].y);
    dv.x=v[1].x-v[0].x;
    dv.y=v[1].y-v[0].y;
    tmp=dv.x;
    dv.x=-dv.y;
    dv.y=tmp;

    v[2].x=v[1].x+dv.x;
    v[2].y=v[1].y+dv.y;

    tmp=dv.x;
    dv.x=-dv.y;
    dv.y=tmp;
    v[3].x=v[2].x+dv.x;
    v[3].y=v[2].y+dv.y;

    printf("%d %d %d %d\n",v[2].x,v[2].y,v[3].x,v[3].y);
    return 0;
}


Measured memory_bytes: 128
N , mod = int(input()) , 10**9+7

memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1] ,t[i] = t[i],t[i-1]
        
        if ''.join(t).count("AGC") >= 1:
            return False
    return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0

    for c in "AGCT":
        if ok(last3+c):
            ret = (ret + dfs(cur+1,last3[1:]+c)) % mod
    memo[cur][last3] = ret
    return ret

print(dfs(0,"TTT"))

Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  pair<int,int> S[10];
  for(int i=0;i<K;i++){
    int L,R;
    cin>>L>>R;
    S[i]=make_pair(L,R);
  }
  long long dp[200002];
  long long ep[200002];
  for(int i=1;i<=N+1;i++){
   dp[i]=0; ep[i]=0;
  }
  dp[1]=1;
  for(int i=1;i<N;i++){
    for(int j=0;j<K;j++){
      ep[i+S[j].first]+=dp[i];
      ep[i+S[j].second+1]-=dp[i];
    }
    ep[i+1]=ep[i+1]+ep[i];
    dp[i+1]=(ep[i+1]%998244353);
  }
  cout<<dp[N]<<endl;
  
  return 0;
}

Measured memory_bytes: 6316
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

long double constexpr pi = 3.141592653589793;

template<class T>
constexpr T sigma1(T i, T n){
    return (n - i + 1) * (i + n) / 2;
}

template<class T>
constexpr T sigma2(T i, T n){
    return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6 :
            sigma2(1, n) - sigma2(1, i - 1));
}

template<class T>
constexpr T sigma3(T i, T n){
    if (i == 1) {
        auto temp = sigma1(i, n);
        return temp * temp;
    }
    return sigma2(1, n) - sigma2(1, i - 1);
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max() - 1;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


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

    ll a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta1 = 2 * M_PI * ((h +  m / 60.) / 12),
        theta2 = 2 * M_PI * m / 60;
    double theta = abs(theta1 - theta2);
    if (theta >= M_PI) {
        theta = 2 * M_PI - theta;
    }
    cout << sqrt(a * a + b * b - 2 * a * b * cos(theta)) << "\n";



    return 0;
}


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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    string str;
    cin >> str;

    int ar[50]={0};

    loop(i, str.length()){
        int ind = str[i]-'a';
        ar[ind]++;
    }

    loop(i,26){
        if(ar[i]%2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout <<"Yes" << endl;
    
    return 0;
}

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

int main(){
double n, k, a, x;
std::cin >> n >> k;
for(int t = 0; t < n ; t++){
a = std::log(k/(t+1)) / std::log(2);
if(a > 0){
//std::cout << a <<std::endl;
a = ceil(a);
}else{
a = 0;
}
//std::cout << a << std::endl;
x = x + pow(0.5,a)/n;
//std::cout << x << std::endl;
}
std::cout << std::setprecision(12) << x << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}

int main(){
    int k; cin>>k;
    string s; cin>>s;
    int n=s.size();
    if(n<=k) cout<<s<<'\n';
    else{
        for(int i=0;i<k;i++) cout<<s[i]; puts("...");
    }
}

Measured memory_bytes: 3628
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
adj = [0] * N
good = [1]*N
for j in range(N):
    adj[j] = set()
for k in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        good[B - 1] = 0
    if H[A - 1] <= H[B - 1]:
        good[A - 1] = 0
print(sum(good))


Measured memory_bytes: 36896
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
/*
 
 
 
 */

public class Main {

    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int t=1;
        //t = sc.ni();
        while(t-->0) {
        	solve(pw,sc);
        }
       
        pw.close();
    }
    static final int ma = (int)1e6+1; 
   
    private static void solve(PrintWriter pw, FastScanner sc) {
    	int[] l = new int[ma];
    	fill(l);
//    	for(int i=2;i<20;i++)
//    		pw.print(l[i]+" ");
    	int n = sc.ni();
    	long count=1;
    	for(int i=2;i<n;i++) {
    		HashMap<Integer,Integer> mp = new HashMap<>();
    		int te = i;
    		while(te>1) {
    			mp.put(l[te],mp.getOrDefault(l[te],0)+1);
    			te=te/l[te];
    		}
    		long tem=1;
    		for(Map.Entry<Integer, Integer> e : mp.entrySet()) {
    			tem=tem*(e.getValue()+1);
    		}
    		count+=tem;
    		
    	}
    	pw.print(count);
	}
    
    static void fill(int[] l) {
    	int t=0;
    	int[] pr = new int[ma];
    	for(int i=2;i<ma;i++) {
    		if(l[i]==0) {
    			l[i]=i;
    			pr[t++]=i;
    		}
    		for(int j=0;j<t&&pr[j]<=l[i]&&i*pr[j]<ma;++j) {
    			l[i*pr[j]]=pr[j];
    		}
    	}
    }

	static <T> void deb(T x,int o){
       System.out.print(x);
       if(o==0) {
    	   System.out.println();
    	   
       }
    }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String ne() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String ne(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int ni() {
			return Integer.parseInt(ne());
		}
		
		long nl() {
			return Long.parseLong(ne());
		}
		
		double nd() {
			return Double.parseDouble(ne());
		}
		
	    
	}
   
}

Measured memory_bytes: 58588
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    map<P, int> m;
    rep(i, n){
        rep(j, n){
            if(i == j){
                continue;
            }
            P p = {x[i] - x[j], y[i] - y[j]};
            m[p]++;
        }
    }

    int ans = INF;
    for(pair<P, int> p : m){
        ans = min(ans, n - p.second);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[105];

int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &in[i]);
	sort(in + 1, in + N + 1);

	return !printf("%d\n", in[N] - in[1]);
}

Measured memory_bytes: 256
import numpy as np
import math
import collections

N = input()
A = list(map(int, input().split()))

ans = 1
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()

if ans > 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 40236
#include <stdio.h>

int main(){
int N;
scanf("%d",&N);

int V[N],C[N];
for (int i=0; i<N; i++) {
  scanf("%d",&V[i]);
}
for (int j=0; j<N; j++) {
  scanf("%d",&C[j]);
}

int ans = 0;
for (int k=0; k<N; k++) {
  if (V[k] > C[k]) {
    ans += V[k] - C[k];
  }
}

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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	long n;
	cin >> n;
	long count = 0;
	long j = 1;
	long t = -1;
	for (long i = 0;i < n;i++) {
		long a;
		cin >> a;
		if (a == j) {
			j++;
			count = count+i - t-1;
			t = i;
		}
	}
	if (j == 1) {
		cout << -1;
	}
	else {
		cout << n-j+1;
	}

}







Measured memory_bytes: 256
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define ABS(a) (a < 0 ? -a : a)
#define YesNo(flag) (flag ? "Yes\n" : "No\n")
#define YESNO(flag) (flag ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)2e5 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
using namespace std;

typedef unsigned long long ull;

int a, b;
int h, m;

double dist(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
	cin >> a >> b >> h >> m;

	double alpha = (h * 60 + m) * 2 * PI / (12 * 60);
	double beta = (h * 60 + m) * 2 * PI / 60;

	double newAX = a * cos(alpha);
	double newAY = a * sin(alpha);

	double newBX = b * cos(beta);
	double newBY = b * sin(beta);
	
	cout << fixed;
	cout << setprecision(15) << dist(newAX, newAY, newBX, newBY) << '\n';
	return 0;
}

Measured memory_bytes: 4100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,a,b,c=0,d=0;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        int x=0;
        if(s[i]=='a'&&c<a+b){
            c++;
            x++;
        }
        if(s[i]=='b'&&c<a+b&&d+1<=b){
            c++;
            x++;
            d++;
        }
        if(x==0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
const ll MOD = 1e9+7;

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

int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
    return 0;
  }
  cout << "consonant" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() <= k) cout << s;
	else {
		string ans = "";
		for(int i = 0; i < k; i++)
		ans += s[i];
		ans += "...";
		cout << ans;
	}
}


Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int n;
	cin >> n;
	int h, h1;
	int co = 0, min = 0;
	for (int i = 0; i < n; i++) {
		cin >> h;
		if (i != 0) {
			if (h1 >= h) {
				co++;
			}
			else {
				if (min < co) {
					min = co;
				}
				co = 0;
			}
		}
		h1 = h;
	}
	if (min < co) {
		min = co;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
char a[186][186];
int b[186][186];
int main()
{
    int n,m,i,j;
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        cin>>a[i][j];
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(a[i][j]=='.')
            {
                if(a[i][j-1]=='#')b[i][j]++;
                if(a[i-1][j-1]=='#')b[i][j]++;
                if(a[i+1][j-1]=='#')b[i][j]++;
                if(a[i-1][j]=='#')b[i][j]++;
                if(a[i+1][j]=='#')b[i][j]++;
                if(a[i-1][j+1]=='#')b[i][j]++;
                if(a[i][j+1]=='#')b[i][j]++;
                if(a[i+1][j+1]=='#')b[i][j]++;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(a[i][j]=='#')printf("#");
            else printf("%d",b[i][j]);
        }
        printf("\n");
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000LL;
ll dp[1000005];
vector <int> vec[1005];
ll cost[1005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int x;
        cin >> cost[i] >> x;
        while(x--){
            int v;
            cin >> v;
            vec[i].push_back(v-1);
        }
    }
    for(int i=1; i<(1<<n); i++) dp[i] = INF;
    for(int i=0; i<(1<<n); i++){
        for(int j=1; j<=m; j++){
            int tren = i;
            for(auto c : vec[j]) tren |= (1<<c);
            dp[tren] = min(dp[tren], dp[i] + cost[j]);
        }
    }
    if(dp[(1<<n)-1] == INF) cout << -1;
    else cout << dp[(1<<n)-1];
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  ll x;
  cin >> x;
  if (x <= 6) cout << 1 << endl;
  else {
    if (x <= 11) cout << 2 << endl;
    else {
      if (x % 11 == 0) cout << (x/11) * 2 << endl;
      else {
        if (11 * (x/11) + 6 >=x) cout << (x/11) * 2 + 1 << endl;
        else cout << (x/11) * 2 + 2 << endl;
        }
    }
  }
}


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

int main(){
int e,x,y,z,min;

while(1){
cin >> e;
if(e == 0)break;
min = e;
for(z=0;z*z*z<=e;z++){
y=(int)sqrt((double)(e-z*z*z));
x = e-z*z*z-y*y;

min = (min > x+y+z)?x+y+z:min;
}

cout << min << endl;
}
return 0;
}

Measured memory_bytes: 1160
import Data.Array (listArray, (!), bounds)

main = ps `seq` main'
    where
    ps = primesUnder 1000000
    main' = interact (unlines . map step . lines)
    step = show . count ps . read 

primesUnder m = ps `seq` listArray (1, length ps) ps
    where
    ps = siege [2..m]
    siege (p:xs)
        | p*p > m = p:xs
        | otherwise = p:siege [x|x<-xs, x `mod` p /= 0]

count ps x = count' a b
    where
    (a,b) = bounds ps
    count' a b
        | x == ps!m = m
        | x < ps!m = if a == m then m-1 else count' a (m-1)
        | x > ps!m = if b == m then m else count' (m+1) b
        where m = (a+b) `div` 2

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    string line;
    cin >> line;
    cout << (ALL (find, line, '7') == line.end() ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3484
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)x.size()
#define vb vector<bool>
const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int vec[4][4];
int main(){
        _ios;

	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++) cin>>vec[i][j];
	}
	vector<vector<bool>> m(3,vb(3));
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(vec[j][k]==x){
					m[j][k]=true;
				}
			}
		}
	}
	bool ok=false;
	for(int i=0;i<3;i++){
		bool okk=true;
		for(int j=0;j<3;j++){
			if(!m[i][j]){
				okk=false;
				break;
			}
		}
		if(okk) ok=true;
	}
	if(ok) cout<<"Yes"<<endl;
	else{
		if((m[0][0] && m[1][1] && m[2][2]) || (m[2][0] && m[1][1] && m[0][2])) cout<<"Yes"<<endl;
		else{
			for(int i=0;i<3;i++){
				bool okk=true;
				for(int j=0;j<3;j++){
					if(!m[j][i]){
						okk=false;
						break;
					}
				}
				if(okk) ok=true;
			}
			if(ok) cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
	}

return 0;
}







Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

memo = [{} for _ in range(51)]

def rec(x, k):
    """レベルxバーガーを下からk枚食べた時のパティの枚数"""
    M = 2 ** (x+2) - 3
    if k in memo[x].keys():
        return memo[x][k]
    if k <= x:
        return 0
    if x == 1:
        if k in [2, 3, 4]:
            return k - 1
        elif k == 5:
            return 3
        elif k == 1:
            return 0
        else:
            return 3
    else:
        if k < (M+1) // 2:
            ret = rec(x-1, k-1)
            memo[x][k] = ret
        elif k > (M+1) // 2:
            ret = rec(x-1, (M-3)//2) + 1 + rec(x-1, k-2-(M-3)//2)
            memo[x][k] = ret
        else:
            ret = rec(x-1, (M-3)//2) + 1
            memo[x][k] = ret
        return ret

def solve(N: int, X: int):
    print(rec(N, X))
    # print(memo)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    X = int(next(tokens))  # type: int
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <string>
#include <map>
#include <utility>
const int maxn = 1e5+1;
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if (a*b==15 ){
        cout<<"*";
        return 0;
    }
    if (a+b==15 ){
        cout<<"+";
        return 0;
    }
    cout<<"x";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <functional>

inline void
rep(int n, std::function<void(int)> f) {
    for (int i = 0; i < n; i++) {
        f(i);
    }
};

typedef std::pair<int, int> P;

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	
	int n, q, l, r;
	std::deque<P> v;
	
	int tmp, k;
	rep(5, [&](int i) {
			std::cin >> tmp;
			v.push_back(std::make_pair(0, tmp));
			});
	for (auto& e : v) {
		int sa = e.second % 10;
		if (sa != 0) {
			e.first = sa;
		}
		else {
			e.first = 10;
		}
	}
	std::sort(v.rbegin(), v.rend());
	int last = v.back().second;
	v.pop_back();
	int sum = 0;
	for (const auto& e : v) {
		int sa = e.second % 10;
		if (sa != 0) {
			sum += (e.second / 10 + 1) * 10;
		}
		else {
			sum += (e.second / 10) * 10;
		}
	}

	std::cout << sum + last << '\n';

	return 0;
}



Measured memory_bytes: 256
mat = Array.new(15){Array.new(15){0}}
readlines.map(&:to_i).each{|n|
  break if n == 0
  n2 = n * n
  n.times{|i|
    n.times{|j|
      mat[i][j] = 0
    }
  }
  ii = 1
  x = n/2+1
  y = n/2
  mat[x][y] = ii
  ii += 1
  x = (x+1) % n
  y = (y+1) % n
  loop do
    break if ii > n2
    if mat[x][y] == 0
      mat[x][y] = ii
      ii += 1
      y = (y+1) % n
    else
      if y == 0
        y = n-1
      else
        y -= 1
      end
    end
    x = (x+1) % n
  end
  n.times{|i|
    n.times{|j|
      printf "%4d", mat[i][j]
    }
    puts
  }
}

Measured memory_bytes: 8688
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, m, a[1000] = {}, sum = 0, cnt = 0;

int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	rep(i, n) {
		if (sum % (4 * m)) {
			if (a[i] > sum / 4 / m)cnt++;
		}
		else {
			if (a[i] >= sum / 4 / m)cnt++;
		}
	}
	if (cnt >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 600005;
const int mod = 998244353;

int n, k;
char str[MAXN];
int L[MAXN], R[MAXN];
vector<int> stk[6969];

int main(){
	scanf("%d %s",&n,str);
	for(int i=0; i<3*n; i++){
		stk[str[i]].push_back(i);
	}
	for(int i=0; i<n; i++){
		int x = stk['R'][i];
		int y = stk['G'][i];
		int z = stk['B'][i];
		L[min({x, y, z})] = 1;
		R[max({x, y, z})] = 1;
	}
	lint ret = 1;
	int mtch = 0;
	for(int i=0; i<3*n; i++){
		if(!L[i] && !R[i]){
			ret *= mtch;
			ret %= mod;
			mtch--;
		}
		if(L[i]) mtch++;
	}
	mtch = 0;
	for(int i=3*n-1; i>=0; i--){
		if(!L[i] && !R[i]){
			ret *= mtch;
			ret %= mod;
			mtch--;
		}
		if(R[i]) mtch++;
	}
	for(int i=1; i<=n; i++) ret = ret * i % mod;
	cout << ret << endl;
}


Measured memory_bytes: 5360
#include <iostream>
#include <string>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな　オーバーフローする
//開区間と閉区間どうにかしろ
//アルファベットが何番目かは x=s[i]-'a'
const ll MOD = 1000000007;

int LCS(string x,string y){
    int nx=x.size();
    int ny=y.size();
    int dp[nx][ny];
    //dp[i][j]:=xを上からi個、yを上からj個見たときの最長部分文字列の長さ
    memset(dp,0,sizeof(dp));
    if(x[0]==y[0]) dp[0][0]=1;
    else dp[0][0]=0;
    //dp[i+1][j]= (if x[i+1]==y[j]:dp[i][j]+1 else dp[i][j])
    rep(i,nx){
        rep(j,ny){
            if(x[i]==y[j]){
                if(i>0 && j>0) dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=1;
            }
            else if(i>0 && j>0) dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else if(i>0) dp[i][j]=dp[i-1][j];
            else if(j>0) dp[i][j]=dp[i][j-1];
        }
    }
    return dp[nx-1][ny-1];
}

int main(){
    int q;
    cin >> q;
    rep(i,q){
        string x,y;
       cin >> x >> y;
        cout << LCS(x,y) << endl;
    }
}



Measured memory_bytes: 7060
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;
 

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
//#define int long long

 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
 
const int MAXN = 2e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = INT64_MAX;


mt19937 rnd(time(0));


signed main() {
	FAST_IO;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = min(a, k);
	k -= ans;
	if (k > 0) {
		k -= min(k, b);
		if (k > 0) {
			ans -= min(k, c);
		}
	}
	cout << ans << "\n";
 	return 0;
}

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

int main(){

int x,y;
cin>>x>>y;

if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)
{
  if(y==1||y==5||y==3||y==8||y==7||y==10||y==12){
     cout<<"Yes";
  }
  else{
    cout<<"No"<<endl;
  }
}
else if(x==4||x==6||x==9||x==11){
  if(y==4||y==6||y==9||y==11){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;;;
  }
}
else{
  cout<<"No"<<endl;
}

return 0;}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;
int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};

int main(){
    int H,N;cin>>H>>N;
    int A[N],B[N];
    int max_A=0;
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
        max_A=max(max_A,A[i]);
    }
    int dp[H+max_A];
    for(int i=0;i<H+max_A;i++) dp[i]=INFi;
  dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=A[i];j<H+max_A;j++){
            dp[j]=min(dp[j],dp[j-A[i]]+B[i]);
        }
    }
    int ans=INFi;
    for(int i=H;i<H+max_A;i++){
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

if p == q:
    print(0)
else:
    cnt = 1
    a,b = 0,0
    for i in permutations(list(range(1,n+1))):
        if i == p:
            a = cnt
        elif i == q:
            b = cnt
        else:
            pass
    
        cnt += 1
    
    print(abs(a-b))

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

int main()
{
	int n,i,j,c=0;
	int a[]={105,135,165,189,195};
	scanf("%d",&n);
	if(n<105)
	{
		printf("%d",c);
	}
	else
	{
		for(i=105;i<=n;i++)
		{
			for(j=0;j<5;j++)
			{
				if(i==a[j])
				{
					c++;
					break;
				}
				
			}
			
		}
		printf("%d",c);
	}
	
	
    return 0;  
}

Measured memory_bytes: 128