akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string a="";
    string b="";

    int count=0;


    cin>>a;
    cin>>b;
    for(int i=0;i<3;i++){
        if(a[i] == b[i])count++;
    }


    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        if(a[i]%2!=0) continue;
        else if(a[i]%2==0){
            while(a[i]%2==0){
                a[i]/=2;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

bool memo[100000][11];//点、深さ
VV<> G(100000);
ll color[100000];

void dfs(ll p, ll dep, ll col){
    if(memo[p][dep]) return;
    memo[p][dep] = true;
    if(!dep){
		color[p] = col;
		return;
    }
    dfs(p, dep - 1, col);
    for(auto v:G[p]) dfs(v, dep - 1, col);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    REP(i, 100000)REP(j, 11) memo[i][j] = 0;
    ll n, m; cin >> n >> m;
    REP(i, m){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll q; cin >> q;
    V<> v(q), d(q), c(q);
    REP(i, q) cin >> v[i] >> d[i] >> c[i];
    RREP(i, q) dfs(v[i] - 1, d[i], c[i]);
    REP(i, n) cout << color[i] << endl;
}


Measured memory_bytes: 13544
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=5010;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,ans,rt[N],cnt,sz[N];
int fac[N],C[N][N],f[N];
int bgn[N],nxt[N<<1],to[N<<1],E;
inline void Add(int &x,int y){x+=y;x>=mod?x-=mod:0;}
inline void add_edge(int u,int v){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;}
inline void init()
{
	fac[0]=1;
	For(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
	For(i,0,n){C[i][0]=1;For(j,1,i)Add(C[i][j]=C[i-1][j],C[i-1][j-1]);}
}
inline void Get_root(int u,int f)
{
	sz[u]=1;
	int flag=1;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		Get_root(v,u);sz[u]+=sz[v];
		if(sz[v]>n>>1)flag=0;
	}
	if(n-sz[u]>n>>1)flag=0;
	if(flag==1)rt[++cnt]=u;
}
inline void dfs(int u,int f)
{
	sz[u]=1;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		dfs(v,u);sz[u]+=sz[v];
	}
}
int main()
{
	int x,y;
	file();
	read(n);
	init();
	For(i,2,n)read(x),read(y),add_edge(x,y),add_edge(y,x);
	Get_root(1,0);
	if(cnt==2){printf("%lld\n",1ll*fac[n/2]*fac[n/2]%mod);exit(0);}
	dfs(rt[1],0);
	f[0]=1;
	int ret=0;
	for(int v,i=bgn[rt[1]];i;i=nxt[i])
	{
		int now=sz[v=to[i]];
		rFor(j,ret,0)
			For(k,1,now)
				Add(f[j+k],1ll*f[j]*C[now][k]%mod*C[now][k]%mod*fac[k]%mod);
		ret+=now;
	}
	For(i,0,n)
		if(i&1)
			Add(ans,mod-1ll*f[i]*fac[n-i]%mod);
		else
			Add(ans,1ll*f[i]*fac[n-i]%mod);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 96896
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int pedras[100100];  ///Inicializo o vetor das pedras;
long long dp[100100]; ///Guardo os valores da funcao frog nesse vetor dp;

int n,k;

///Aqui comeca a funcão do frog2 top-down recursiva

int frog2(int i,int j){

    if(dp[i] != -1){
        return dp[i];
    }

    if(i>=j) return dp[i]=0;
    
    int menor = 1000000000;

    for(int x=1;x<=k;x++){ 
        if(i+x <= j){  
            long long cost = (frog2(i+x,j)+ abs(pedras[i]-pedras[i+x]));
  
            if(cost < menor){ ///Acho o menor custo dentre as tentativas k;
                menor = cost;
            }

        }
    }

    return dp[i] = menor;
}
////////////////////////////////////////////////////////

int main(){

    memset(dp,-1,sizeof(dp));

    cin >>n>>k;

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

    cout<<frog2(0,n-1)<<endl;
}

Measured memory_bytes: 12576
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <ctime>

using namespace std;


int main()
{
    //freopen("../input.txt", "r", stdin);
    int x;
    cin >> x;

    cout << (x / 500) * 1000 + (x % 500) / 5 * 5;


    return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
int main()
{
  int i,j,k;
  int n;
  int x[100],y[100];
  double p,r;
  double data;
  double result;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&x[i]);
  for(i=0;i<n;i++) scanf("%d",&y[i]);

  result=0.0;
  for(i=0;i<n;i++)
    {
      if(x[i]-y[i]>=0) result+=x[i]-y[i];
      else result-=x[i]-y[i];
    }
  printf("%f\n",result);

  result=0.0;
  data=0.0;
  for(i=0;i<n;i++) data+=(x[i]-y[i])*(x[i]-y[i]);
  for(i=0;i<10;i++)
    {
      r=1.0;
      for(j=0;j<i;j++) r/=10;
      while(1)
	{
	  if((result+r)*(result+r)>data) break;
	  else result+=r;
	}
    }
  printf("%f\n",result);

  result=0.0;
  data=0.0;
  for(i=0;i<n;i++)
    {
      if (x[i]-y[i]>=0) data+=(x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]);
      else  data-=(x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]);
    }
  for(i=0;i<10;i++)
    {
      r=1.0;
      for(j=0;j<i;j++) r/=10;
      while(1)
	{
	  if((result+r)*(result+r)*(result+r)>data) break;
	  else result+=r;
	}
    }
  printf("%f\n",result);

  result=x[0]-y[0];
  if(result<0) result*=(-1);
  for(i=1;i<n;i++)
    {
      if(x[i]-y[i]>=0)
	{
	  if(x[i]-y[i]>result) result=x[i]-y[i];
	}
      else
	{
	  if((x[i]-y[i])*(-1)>result) result=(x[i]-y[i])*(-1);
	}
    }
  printf("%f\n",result);

  return 0;
}

Measured memory_bytes: 632
#include<stdio.h>
int main()
{
	int S, h, m, s;
	scanf("%d", &S);
	h = S / 3600;
	S = S % 3600;
	m = S / 60;
	S = S % 60;
	s = S;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 2676
#include <iostream>

using namespace std;

int main(){
	int x;
	while(true){
		cin >> x;
		if(x == 0)
			return 0;
		int count = 0;
		while(x != 1){
			if(x%2 == 0)
				x = x/2;
			else
				x = 3*x + 1;
			count++;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 2980
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<algorithm>
using namespace std;
const int MR=2000000;


int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int ans=0;
	if(n>k) ans=x*k+y*(n-k);
	else ans=x*n;
	cout<<ans<<endl;
	return 0;
}



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

int main() {
    long long x,y,ans;
    
    cin >> x >> y;
    
    for(long long i=0;i<=x;i++){
        ans = 2*i+4*(x-i);
        if(ans == y){
            cout << "Yes";
            return 0;
        }
    }
    
    cout << "No" << endl;
    
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();


		int max = 0;
		int min = 0;
		int temp = 0;

		temp = a + b - n;
		if(temp <= 0) {
			min = 0;
		}
		else {
			min = temp;
		}

		if(a>=b) {
			max = b;
		}else if(a < b) {
			max = a;

		}


		System.out.println(max + " "+ min);

	}

}

Measured memory_bytes: 22612
from collections import Counter

n = int(input())
c = list(input())
count = Counter(c)
ans = float('inf')
w = 0
r = 0

if count.get('R'):
    r = count['R']

ans = max(w, r)

for i in range(n):
    if c[i]=='W':
        w += 1
    else:
        r -= 1
    ans =min(max(w,r), ans)
print(ans)

Measured memory_bytes: 11084
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;

// long long l[100];

int main() {
  string s,t;
  cin >> s >> t;
  reverse(t.begin(),t.end());
  if (s==t) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main(){
int n;
  cin>>n;
   vector<int> h(n);
  for(int i=0;i<n;i++){
  cin>>h[i];
  }
  vector<ll> dp(n,INT_MAX);
  dp[0]=0;
  
  for(int i=1;i<n;i++){
      
      if(i>1)
        dp[i] = min(dp[i],dp[i-2]+abs(h[i] - h[i-2]));
      dp[i] = min(dp[i],dp[i-1] + abs(h[i]-h[i-1]));
  }
  cout<<dp[n-1]<<"\n";
  return 0;
}

Measured memory_bytes: 4228
import sys

def main():

    # sys.stdin = open("input154a.txt")

    s, t = input().split()
    a, b = map(int, input().split())
    u    = input()

    if s == u:
        a -= 1
    else:
        b -= 1

    print(str(a) + " " + str(b))

if __name__ == "__main__":
    main()


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

int main()
{
    string s;
    cin >> s;
    int a = (int)s.find('A');
    int z = (int)s.rfind('Z');
    string sub = s.substr(a,z-a+1);
    cout << sub.size() << endl;
    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(n),b(n),c;
    ll suma=0,sumb=0;
    rep(i,n){
        cin>>a[i];
        suma+=a[i];
    }
    ll cnt1=0,cnt2=0,s=0;
    rep(i,n){
        cin>>b[i];
        if(a[i]<b[i]){
            cnt1++;
            s+=b[i]-a[i];
        }
        else if(a[i]>b[i]) c.push_back(a[i]-b[i]);
        sumb+=b[i];
    }
    sort(all(c));
    int i=c.size()-1;
    while(s>0){
        s-=c[i];
        cnt2++;
        i--;
    }
    if(suma<sumb) cout<<-1;
    else cout<<cnt1+cnt2;
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;


int main(){
    int n, i, j;
    cin >> n;
    int a[n], b[n], c[n];
    int dp[n][3] = {};
    for(i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    for(i = 0; i < n; i++){
        dp[i+1][0] = MAX(dp[i][1], dp[i][2]) + a[i];
        dp[i+1][1] = MAX(dp[i][0], dp[i][2]) + b[i];
        dp[i+1][2] = MAX(dp[i][0], dp[i][1]) + c[i];
    }

    cout << MAX(MAX(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int x, a;
	cin >> x >> a;
	
	if(x < a)
		cout << "0" << endl;
	else
		cout << "10"  << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
ab =
  readlines.map do |i|
    i.chomp.split.map(&:to_i)
  end.to_a

days = 1.upto(m).map.to_a
sorted = ab.sort{|a,b| b[1] <=> a[1]}

sum = 0
# 報酬が大きい順に見ていけばGreedyで最適解でそう
# O(mn)を避けるためにbsearchを使うけど、dayで回すと難しいからworkで回す
sorted.each do |a, b|
  break if days.size == 0

  # 報酬もらえるまでの猶予日リストからworkの日数以上の日を消す
  day = days.bsearch_index{|i| i >= a}
  next if day.nil?

  sum += b
  days.delete_at(day)
end

puts sum

Measured memory_bytes: 19972
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}
const ll MOD = 1000000007;

int main()
{
    int A, B, X;
	scanf("%d%d%d", &A, &B, &X);
 
	bool isok = X >= A && X <= A + B;
 
	if (isok) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!long).array;
    A.sort();

    auto a = A.front;
    auto b = A.back;
    auto ans = b - a;

    for (int x = 1, y = N - 2; x <= y; ) {
        auto ax = abs(a - A[x]);
        auto ay = abs(a - A[y]);
        auto bx = abs(b - A[x]);
        auto by = abs(b - A[y]);
        if (max(ax, ay) >= max(bx, by)) {
            ans += max(ax, ay);
            if (ax >= ay) {
                a = A[x];
                x += 1;
            } else {
                a = A[y];
                y -= 1;
            }
        } else {
            ans += max(bx, by);
            if (bx >= by) {
                b = A[x];
                x += 1;
            } else {
                b = A[y];
                y -= 1;
            }
        }
    }

    ans.writeln;
}


Measured memory_bytes: 4092
import Control.Monad
import Control.Applicative
import Data.List

calc:: [Int] -> Int -> Int
calc x highest
  |x == [] = 0
  |otherwise = calc(tail x) higher + (higher - front)
  where front = head x
        higher = max front highest

main = do
    _ <- getLine
    x <- map read . words <$> getLine
    putStrLn(show(calc x 0))

Measured memory_bytes: 64132
#include<bits/stdc++.h>
using lint = long long;
int main() {
	lint n, k;
	scanf("%lld%lld", &n, &k);
	lint ans = 0;
	for (lint b = k + 1; b <= n; b++) {
		for (lint pa = 0; pa*b <= n; pa++) {
			lint a = pa*b;
			lint q = std::min(n, a + b - 1) - (a + k)+1;
			if (q > 0)ans += q;
		}
	}
	if (k == 0)ans -= n;
	printf("%lld", ans);
}

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

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



map<int, int> factorize(int x)
{
    int n = x;
    map<int, int> m;
    for(int i = 2; i*i <= n and x > 1; ++i)
        while(x % i == 0)
            m[i]++, x /= i;
    if(x > 1)
        m[x]++;
    return m;
}

vector<int> v1;

int32_t main()
{




      int x;
      cin >> x;


      

      for(int i = 1; i <= 10000; i++)
      {
        v1.push_back(i*(i+1)/2);
      }


      map<int,int> mp = factorize(x);



      vector<int> v;

      for(auto i : mp)
      {
        v.push_back(i.second);
      }

      int ans  =0;

      for(int i = 0; i < v.size(); i++)
      {
        int k = v[i];

        int j = 1;

        while(k -j>=0)
        {
          k-=j;
          j++;
          ans++;
        }

      }

      cout << ans;





    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <cmath>


struct Point {double x, y;};
double th = M_PI * 60.0 / 180.0;


void koch (int n, Point a, Point b) {
    if (n == 0) return;
    Point s, t, u;
    s.x = (2.0 * a.x + 1. * b.x) / 3.;
    s.y = (2.0 * a.y + 1. * b.y) / 3.;

    t.x = (1.0 * a.x + 2. * b.x) / 3.;
    t.y = (1.0 * a.y + 2. * b.y) / 3.;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    koch(n - 1, a, s);
    std::printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    std::printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    std::printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}


int main (int argc, char ** argv) {
    int n = 0;
    std::cin >> n;
    Point p1 = {0, 0};
    Point p2 = {100, 0};
    std::printf("%.8f %.8f\n", p1.x, p1.y);
    koch(n, p1, p2);
    std::printf("%.8f %.8f\n", p2.x, p2.y);
}




Measured memory_bytes: 3348
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

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

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll x;
	cin >> x;
	cout << !x << endl;

	return 0;
}


Measured memory_bytes: 3596
n = str(input())
d1 = n[0]
d2 = n[1]
d3 = n[2]

if d1 == 'R':
    if d2 == 'R':
        if d3 == 'R':
            print(3)
        else:
            print(2)    
    else:
        print(1)
elif d2 == 'R':
    if d3 == 'R':
        print(2)
    else:
        print(1)
elif d3 =='R':
    print(1)
else:
    print(0)

Measured memory_bytes: 9152
#include <stdio.h>

#define N 500001

int n;

int left(i) {return 2*i;}
int right(i) {return 2*i+1;}

void maxHeapify(int *H, int i) {
	int l = left(i);
	int r = right(i);
	int largest;
	int tmp;

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

	if (largest != i) {
		tmp = H[i];
		H[i] = H[largest];
		H[largest] = tmp;
		maxHeapify(H, largest);
	}
}

void buildMaxHeap(int *H) {
	int i;
	for (i = n/2; i >= 1; i--) {
		maxHeapify(H, i);
	}
}

int main() {
	int i;
	int H[N];

	scanf("%d",&n);
	for (i = 1; i <= n; i++) scanf("%d", &H[i]);

	buildMaxHeap(H);
	for (i = 1; i<= n; i++) printf(" %d", H[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 2552
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
D = set(LI())
for i in range(n, 100000):
    if not set([int(j) for j in str(i)]) & D:
        print(i)
        break







Measured memory_bytes: 42220
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> a(m);
	for (int i=0; i<m; i++) cin >> a[i];
	int sum=0;

	for (int i=0; i<m; i++) sum += a[i];

	if (sum > n)
		cout << "-1" << endl;
	else {
		cout << n-sum << endl;
	}

	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int t = 0, h = 0;
    int a, b, c;
    while(1){
       if(scanf("%d,%d,%d", &a, &b, &c) == EOF) break;
        // cout << a << b << c << endl;
        if(a * a + b * b == c * c) t++;
        else if(a == b) h++;
    }
    o(t);
    o(h);
}

Measured memory_bytes: 3144
#include<iostream>
using namespace std;
int main() {
	int n,oki[1111],ok,ans[11111],an;
	ok = 0;
	an = 0;
	while(cin >> n) {
		if (n == 0) {
			an = an + 1;
			ans[an] = oki[ok];
			ok = ok - 1;
		}
		else {
			ok = ok + 1;
			oki[ok] = n;
		}
	}
	for (int i = 1; i <= an; i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


/*const int MOD = (int) 1e9 + 7;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}*/

/*int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/

using namespace std;

const int MOD1 = 666013;
const int MOD2 = 666019;

const int MAXN = (int) 5e5;
const int B = 41;

int len[MAXN + 1], vis[MAXN + 1], to[MAXN + 1];

void dfs(int nod) {
    vis[nod] = 1;

    if(to[nod] != -1 && vis[to[nod]] == 1) {
        cout << -1;
        exit(0);
    }

    if(to[nod] != -1) {
        dfs(to[nod]);
    }

    vis[nod] = 2;

    if(to[nod] == -1) {
        len[nod] = 0;
    }
    else {
        len[nod] = len[to[nod]] + 1;
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string s, t, aux;
    cin >> s >> t;

    while(aux.size() <= s.size() + t.size()) {
        for(auto it : s) {
            aux.push_back(it);
        }
    }

    int val1 = 0, val2 = 0;
    for(auto it : t) {
        val1 = (val1 * B + it - 'a' + 1) % MOD1;
        val2 = (val2 * B + it - 'a' + 1) % MOD2;
    }

    vector <ull> hsh1(aux.size() + 1), hsh2(aux.size() + 1);

    int pw1 = 1, pw2 = 1;
    for(i = 1; i <= t.size(); i++) {
        pw1 *= B, pw2 *= B;
        pw1 %= MOD1, pw2 %= MOD2;
    }

    hsh1[0] = hsh2[0] = aux[0] - 'a' + 1;
    for(i = 1; i < aux.size(); i++) {
        hsh1[i] = (hsh1[i - 1] * B + aux[i] - 'a' + 1) % MOD1;
        hsh2[i] = (hsh2[i - 1] * B + aux[i] - 'a' + 1) % MOD2;
    }

    for(i = 0; i < s.size(); i++) {
        int cur1 = hsh1[i + t.size() - 1], cur2 = hsh2[i + t.size() - 1];
        if(i > 0) {
            cur1 += MOD1 - (1LL * hsh1[i - 1] * pw1) % MOD1;
            if(cur1 >= MOD1) cur1 -= MOD1;

            cur2 += MOD2 - (1LL * hsh2[i - 1] * pw2) % MOD2;
            if(cur2 >= MOD2) cur2 -= MOD2;
        }
        if(cur1 == val1 && cur2 == val2) {
            to[i] = (i + t.size()) % s.size();
        }
        else {
            to[i] = -1;
        }
    }

    for(i = 0; i < s.size(); i++) {
        if(vis[i] == 0) {
            dfs(i);
        }
    }

    int ans = 0;
    for(i = 0; i < s.size(); i++) {
        ans = max(ans, len[i]);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 36636
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define ep emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

const int MOD = 1e9+7;

bool isprime(int x){
	if(x<=1) return false;
  	if(x==2 || x==3) return true;
  	for(int i=2; i*i<=x; i++){
    	if(x%i==0) return false;
    }
  	return true;
}

int nextprime(int p){
	if(!isprime(p)) return 0;
  	if(p==2) return 3;
  	p += 2;
  	while(!isprime(p)) p += 2;
  	return p;
}

void Main()
{
	int n;
  	cin >> n;
	if(n==1) {
      	cout << 1 << endl; 
    	return;
    }
  
  	vi prime;
  	int x = 2;
  	while(x<=n){
    	prime.ep(x);
      	x = nextprime(x);
    }
  	int sz = prime.size();
  	
  	// cnt[i] = n! を p[i] で何回割れるか？
	// cnt[i] = [n/p] + [n/p^2] + ...
	vll cnt(sz);
  	rep(i,sz){
      	ll d = prime[i];
    	while(n/d>=1){
      		cnt[i] += n/d;
      		d *= prime[i];
        }
    }
  	
  	// cout << sz << endl;
  	// rep(i,sz) cout << prime[i] << ": " << cnt[i] << endl;
  	
  	ll ans = 1;
  	rep(i,sz){
    	ans = ((ans%MOD) * ((cnt[i]+1)%MOD)) %MOD;
    } 
  	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define pb push_back

int main(){
    int n;
    int aa[100100];
    memset(aa,0,sizeof(aa));
    cin>>n;
    long long ans = 0;
    for (int i=1;i<=n;i++){
        int cur;
        cin>>cur;
        aa[cur]++;
        ans+=cur;
    }
    int q;
    int b,c;
    cin>>q;
    for (int i=1;i<=q;i++){
        cin>>b>>c;
        int tmp = aa[b];
        ans += (c-b)*tmp;
        aa[b]=0;
        aa[c]+=tmp;
        cout<<ans<<endl;
    }
}


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

int main(){
	int N;
	cin >> N;
	vector<pair<double,double>> p(N);
	rep(i,N){
		double x,y;
		cin >> x >> y;
		p[i] = make_pair(x,y);
	}
	
	vector<int> d(N);
	rep(i,N){
		d[i] = i;
	}
	
	double ans = 0;
	
	do{
		rep(i,N-1){
			ans += sqrt((p[d[i]].first-p[d[i+1]].first)*(p[d[i]].first-p[d[i+1]].first) + (p[d[i]].second-p[d[i+1]].second)*(p[d[i]].second-p[d[i+1]].second));
		}
		
	}while (next_permutation(d.begin(),d.end()));
	
	double kaizyo = 1;
	REP(i,N){
		kaizyo *= i;
	}
	printf("%.10f", ans/kaizyo);
	puts("");
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

LLI dp[2200][2200];
bool visited[2200][2200];

LLI rec(int i, int j, const vector<int> &S, const vector<int> &T){
  if(i==0 or j==0) return dp[i][j] = 1;
  
  if(visited[i][j]) return dp[i][j];
  visited[i][j] = true;

  if(S[i-1] == T[j-1]){
    (dp[i][j] += rec(i-1,j-1,S,T)) %= mod;
  }

  (dp[i][j] += ((rec(i-1,j,S,T) + rec(i,j-1,S,T))%mod - rec(i-1,j-1,S,T)+mod)%mod) %= mod;
  

  return dp[i][j];
}

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

  int N,M;
  while(cin >> N >> M){
    vector<int> S(N), T(M); cin >> S >> T;

    fill_array(dp, 0);
    fill_array(visited, false);

    LLI ans = rec(N,M,S,T);

    
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 43136
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()

int main(){
	int n;
	cin>>n;
	vector<int> v;
	rep(i,n)v.push_back(i+1);
	int p=0,q=0,tmp;
	rep(i,n){
		cin>>tmp;
		p=p*10+tmp;
	}
	rep(i,n){
		cin>>tmp;
		q=q*10+tmp;
	}
	int count=0,num,a,b;
	do{
		num=0;
		count++;
		for(int& i:v)num=num*10+i;
		if(num==p)a=count;
		if(num==q)b=count;
	}while(next_permutation(all(v)));
	cout<<abs(b-a);
	return 0;
}

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

int main() {
    
    while (true) {
        int n, x; cin >> n >> x;
        if (n == 0 && x == 0) break;
        int count = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (x - i - j > j && x - i - j <= n)
                    count++;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3096
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	const ll R = 0, G = 1, B = 2;
	ll T;
	rd(T);
	repi(I, 0, T) {
		ll cards[3][10] = {};
		ll inputINT[10] = {};
		ll count[3] = {};
		ll ans = 0;
		repi(i, 0, 9) rd(inputINT[i]);
		repi(i, 0, 9) {
			char ch;
			rd(ch);
			if (ch == 'R') {
				cards[R][count[R]] = inputINT[i];
				count[R]++;
			}
			else if (ch == 'G') {
				cards[G][count[G]] = inputINT[i];
				count[G]++;
			}
			else if (ch == 'B') {
				cards[B][count[B]] = inputINT[i];
				count[B]++;
			}
		}
		if (count[R] % 3 == 0 && count[G] % 3 == 0 && count[B] % 3 == 0) {
			ll c = 0;
			repi(i, 0, 3) {
				sort(cards[i], cards[i] + count[i]);
				do {
					bool flag[3] = {};
					repi(j, 0, count[i] / 3) {
						if ((cards[i][j * 3] == cards[i][j * 3 + 1] && cards[i][j * 3 + 1] == cards[i][j * 3 + 2])
							|| (cards[i][j * 3] == cards[i][j * 3 + 1] - 1 && cards[i][j * 3] == cards[i][j * 3 + 2] - 2)) {
							flag[j] = true;
						}
					}
					bool judge = true;
					repi(j, 0, count[i] / 3) judge &= flag[j];
					if (judge) {
						c += count[i] / 3;
						break;
					}
				} while (next_permutation(cards[i], cards[i] + count[i]));
				if (c == 3) {
					/*
					repi(k, 0, 3) {
						repi(l, 0, 9) {
							cout << cards[k][l] << " ";
						}
						wl();
					}
					*/
					ans = 1;
					break;
				}
			}
		}
		wrln(ans);
	}
	return 0;
}



Measured memory_bytes: 3140
#include<iostream>
#include<string>
int main()
{
    int k;
    std::string s;
    std::cin >> k >> s;

    if (s.size()<=k){
        std::cout << s << std::endl;
    }
    else{
        for (int i = 0; i < k; i++)
            std::cout << s[i];
            std::cout << "..." << std::endl;
    }
    
}


Measured memory_bytes: 3640
S = input()

if S[1:2] == 'S':
    if 'R' in S:
        print(1)
    else:
        print(0)
else:
    if not 'S' in S:
        print(3)
    else:
        if S == 'SRS':
            print(1)
        else:
            print(2)

Measured memory_bytes: 9032
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
			int n = sc.nextInt();
			calc(n);
	}
	public void calc(int n){
		if(n == 1){
			System.out.println(0);
			return;
		}
		int count = 1;
		int a = n / 3;
		int b = (n - a) / 2;
		int c = n - a - b;
		
		while(c != 1){
			a = c / 3;
			b = (c - a) / 2;
			c = c - a - b;
			
			count++;
		}
		System.out.println(count);
	}

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

Measured memory_bytes: 17360
H, W = map(int, input().split())
S = [input() for _ in range(H)]

from collections import deque

def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited = [[-1]*W for _ in range(H)]
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+i, x+j
            if not 0 <= new_y < H or not 0 <= new_x < W:
                continue
            if S[new_y][new_x] ==  "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x]+1
                q.append([new_y, new_x])
    return max(max(l) for l in visited)

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, bfs(i, j))
print (ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    char pl = 'g';
    int ans = 0;
    rep(i, n) {
        if (i % 2 == 0) pl = 'g';
        else pl = 'p'; 
        if (pl == 'p' && s[i] == 'g') ans++;
        if (pl == 'g' && s[i] == 'p') ans--;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;

    while (K > 0) {
        if (A >= B) {
            B *= 2;
        }
        else if (B >= C) {
            C *= 2;
        }
        else {
            break;
        }
        --K;
    }
    if (A < B && B < C) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<algorithm>
const int M = 1e5;
int a[M];
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i = 0; i < n;i++){
		cin>>a[i];
	}
	if(n%2 != 0)
		cout<<0<<endl;
	else{
		sort(a,a+n);
		if(a[n/2] == a[n/2-1])
			cout<<0<<endl;
		else
			cout<<a[n/2] - a[n/2-1]<<endl;
	}
	return 0;
}

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

int main() {
    /* Input */
    long long int N;
    cin >> N;
        
    /* Main Logic */
    long long int an = 1;
    long long int sumAn = 0;

    string ans = "";

    int i = 0;
    while (1) {
        an *= 26;
        sumAn += an;
        if (N <= sumAn) {
            // N番目の数がいる項の一つ前の項のおしりの番目
            long long int tailOfAn_1 = sumAn - an;
            // N番目の数がいる項の中でのNの番目を求る(0スタート)
            long long int smallN = N - (tailOfAn_1 + 1);
            rep (j, i + 1) {
                ans.append(1, smallN % 26 + 'a');
                smallN /= 26;
            }
            break;
        }
        i++;
    }

    reverse(ans.begin(), ans.end());
    
    /* Output */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;


int main(void) {
    int n, k;
    cin >> n >> k;
    int h[n];
    rep (i, n) cin >> h[i];

    sort(h, h + n);

    ll ans = 0;
    rep (i, max(0, n - k)) ans += h[i];
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
    print(n//2)
    exit()

a1=a[::2]
a2=a[1::2]

import collections

c1=collections.Counter(a1)
c2=collections.Counter(a2)

cc1=c1.most_common(2)
cc2=c2.most_common(2)

if len(cc1)==1:
    print(n//2-cc2[0][1])
elif len(cc2)==1:
    print(n//2-cc1[0][1])
elif cc1[0][0]!=cc2[0][0]:
    print(n-cc1[0][1]-cc2[0][1])
elif cc1[0][0]==cc2[0][0]:
    if cc1[1][1]>=cc2[1][1]:
        print(n-cc1[1][1]-cc2[0][1])
    else:
        print(n-cc1[0][1]-cc2[1][1])

Measured memory_bytes: 18932
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt(),c=nxt(),k=nxt();
    int ans=0;
    ans+=min(a,k);
    k-=min(a,k);
    if(k==0)
    {
        cout<<ans<<endl;
        return 0;
    }
    k-=min(k,b);
    if(k==0)
    {
        cout<<ans<<endl;
        return 0;
    }
    ans-=min(k,c);
    cout<<ans<<endl;
    
    
    
    return 0;   
}




 
 


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

#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
// typedef priority_queue<int, vector<int>, greater<int>> min_pq;

std::random_device rd_device;
std::mt19937 rng(rd_device());

template<typename T>
void printVec(vector<T> &vec) {
    for (auto &v : vec) cout<<v<<" ";
    cout<<endl;
}

void sleep(int ms) {
    std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}

int main() {
    std::srand(std::time(0));
    ios::sync_with_stdio(false);
//    cin.exceptions(ios_base::failbit);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(10);
    cout<<fixed;
    
    int a, b, t;
    cin>>a>>b>>t;
    cout<<b * (int)((t+0.5)/a)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int A,B;
    cin>>A>>B;
    if(B==1) cout<<0<<endl;
    else{
    B-=2;
    B/=(A-1);
    B++;
    cout<<B<<endl;
}}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n,y;
    cin >> n >> y;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(10000 * i + 5000 * j + 1000 * (n-i-j) == y && (n-i-j >= 0)){
                cout << i << ' ' << j << ' '  << (n-i-j);
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n][n];
    for(ll k=0;k<n;k++){
        for(ll i=0;i<=n-1-k;i++){
            if(k==0){
                dp[i][i+k]=a[i];
            }else{
                dp[i][i+k]=max(a[i]-dp[i+1][i+k],a[i+k]-dp[i][i+k-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 70400
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine


main = do
  s <- getLine 
  print . fst . foldl' update (0, head s) $ tail s

update (count, prv) c = if c == prv then (count, prv) else (count + 1, c)


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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int n;
  cin >> n;
  n%=10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
     cout << "hon";
  else if(n == 0 || n == 1 || n == 6 || n == 8 )
    cout << "pon";
  else
   cout << "bon"; 
  
  
  
}

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

int lcm(int a, int b){
  int ref, tmp;
  if ( a < b ){
    tmp = a;
    a = b;
    b = tmp;
  }
  ref = a % b;
  while(ref != 0){
    a = b;
    b = ref;
    ref = a % b;
  }
  return b;
}

int main(){
  long long a,b,c,d,e;
  cin >> a >> b >> c >> d;
  e = (c * d ) / lcm(c, d);
  long long ans1 = b - (b / c) - (b / d) + (b / e);
  long long ans2 = a - 1  - ((a - 1) / c) - ((a - 1)/ d) + ((a - 1) / e);                      
  
  cout << ans1 - ans2  << endl;
  
}


Measured memory_bytes: 256