akhauriyash/Code-Regression huggingface dataset:
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int prime(int a)
{
	if(a<2)
	return 1;
	
	for(int i=2 ; (i*i)<=a ; i++)
	{
		if(a%i==0)
		return 0;
	}
	
	return 1;
}

int main()
{
	int n;
	scd(n);
	int b;
	int d=0;
	forin(i,0,n)
	{
		scd(b);
		if(prime(b)==1)
		d++;	
	}	
	printf("%d\n",d);
	return 0;
}

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

using namespace std;
// #define DEBUG
// #define TIME
/*
Learn : -
Problem Type : -
Source : -
*/
#pragma GCC optimize ("Ofast")
#define sint( a ) int a; qread(a);
#define sint2( a, b ) int a,b; qread(a),qread(b);
#define sint3( a, b, c ) int a,b,c; qread(a),qread(b),qread(c);
#define int1( a ) qread(a);
#define int2( a, b ) qread(a),qread(b);
#define int3( a, b, c ) qread(a),qread(b),qread(c);
#define mkp make_pair
#define mkt make_tuple
#define pb emplace_back
#define inf INT_MAX
#define all( x ) (x).begin(),(x).end()
#define F first
#define S second
#define sdouble( a ) double a; scanf("%lf",&a);
#define slong( a ) long long a; scanf("%lld",&a);
#define cstring( a, x ) char a[x]; scanf("%s",a);
#define sstring( a ) string a;cin>>a;
#define rev( s ) reverse(all(s));
#define FOR( a, b, c ) for(int a=b;a<c;a++)
#define ROF( a, b, c ) for(int a=b;a>c;a--)
#define pause system("pause")
#define endl printf("\n")
#define fastio {ios::sync_with_stdio(false);cin.tie(NULL);}
#define null NULL
#ifdef DEBUG
#define debug(x) cout<< #x << " = " << x;endl;
#else
#define debug( x )
#endif
#define OPEN freopen("input.txt","r",stdin)
#define SEND freopen("output.txt","w",stdout)
#ifdef COM
#define IN(x)
#define OUT(x)
#else
#define IN( x ) freopen(x,"r",stdin);
#define OUT( x ) freopen(x,"w",stdout);
#endif
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector <ii> vii;
typedef long long ll;

void qread( int &x )
{
	int neg = 1;
	x = 0;
	register char c = getchar();
	while(c < '0' || c > '9')
	{
		if(c == '-')neg = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9')x = 10 * x + c - '0', c = getchar();
	x *= neg;
}

void Wl( int x )
{
	printf("%d\n", x);
}

void Wl( double x )
{
	printf("%lf\n", x);
}

void Wl( string x )
{
	printf("%s\n", x.c_str());
}

void Wl( ll x )
{
	printf("%lld\n", x);
}

void W( int x )
{
	printf("%d ", x);
}

void W( double x )
{
	printf("%lf ", x);
}

void W( string x )
{
	printf("%s ", x.c_str());
}

void W( ll x )
{
	printf("%lld ", x);
}
ll a[2005];
ll mn[2005];
int main()
{
    sint(n);
	slong(spell);
	ll ans=LLONG_MAX;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		mn[i]=a[i];
	}
	for(int use_spell=0;use_spell<n;use_spell++)
	{
		ll cth=0;
		for(int i=0;i<n;i++)
		{
			cth += mn[i];
		}
		for(int i=0;i<n;i++)
		{
			mn[i] = min(mn[i] , a[((i-use_spell-1)+n)%n]);
		}
		ans = min(ans, cth + use_spell * spell);
	}
	Wl(ans);
}


Measured memory_bytes: 256
# 複数行のスペース区切りの文字列をリストに
n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]

e = sorted(e, key=lambda x: x[1])
t=0
flg=0
for i in range(n):
    t+=e[i][0]
#     print(t,e[i][1])
    if(t>e[i][1]):
        flg=1
if flg==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 42716
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    ll d, t, s;
    cin >>d >> t >> s;

    if(t*s >= d) cout << "Yes" << EL;
    else cout << "No" << EL;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[2001];
int main(){
    cin >>n;
    int res=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=3;i<=n;i++)    
    for(int j=i-1;j>=1;j--){
    bool kt=1;
    for(int l=j-1;l>=1;l--)
    if (a[i]<a[j]+a[l] && a[j]<a[j]+a[i] && a[l]<a[i]+a[j]) res++; else {kt=0;break;}
    if (kt=0) break;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**18

dp = [INF]*n
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    for k in range(1, k+1):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))

print(dp[n-1])


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

int main()
{
  int N, A;
  cin >> N >> A;
  
  const auto target {N % 500};
  if (target <= A) {
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int main() {
  FIO
  string s; read(s);
  if (s.back() == 's')
    s += "es";
  else
    s += "s";
  print(s);
  return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h> 
using namespace std;
#define pb push_back
#define vi vector<int>
#define ss second
#define ff first
#define ll long long
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
#define w(x) int x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
ll ab(ll a,ll b)
{
      if(a>b)
      return a-b;
return b-a;
}
int main() 
{
      ll n,i=0,k;
      cin>>n>>k;
      ll a[n];
      while(i<n)
      {
            cin>>a[i];
            i++;
      }
      ll dp[n];
      dp[0]=0;
      for(ll i=1;i<n;i++)
      {
            dp[i]=INT_MAX;
            for(ll j=i-1;j>=0&&i-j<=k;j--)
            {
            dp[i]=min(dp[i],dp[j]+ab(a[j],a[i]));
            }
      }
      cout<<dp[n-1];
      return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long k = scan.nextLong();

		long ans;
		if(n % k == 0) {
			ans = 0;
		}else {
			if(Math.abs(n % k) > Math.abs((n % k) - k)){
				ans = Math.abs((n % k) - k);
			}else {
				ans = Math.abs(n % k);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int n; cin >> n;
    map<string, int> smap;
    rep(i, n) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        ++smap[s];
    }
    ll ans= 0;
    for(auto a : smap) {
        int t = a.second;
        ans += ((ll)t * (t-1)/2);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 11136
package main

import "fmt"

func main() {

	var n, nin, sum int
	fmt.Scanln(&n)
	buf := make([]int, 0)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &nin)
		buf = append(buf, nin)
		sum += nin
	}
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			if buf[i] > buf[j] {
				buf[i], buf[j] = swap(buf[i], buf[j])
			}
		}
	}

	fmt.Println(buf[0], buf[n-1], sum)

}

func swap(a, b int) (int, int) {
	return b, a
}




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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)

int main(void) {
    int n;
    cin >> n;
    vector<int> A(n);
    REP(i, n) cin >> A[i];
    int q;
    cin >> q;
    vector<int> m(q);
    REP(i, q) cin >> m[i];
    vector<bool> ans(q, false);
    REP(i, 1 << n) {
        vector<bool> b(n);
        REP(j, n) { b[j] = (i >> j) & 1; }
        int sum = 0;
        REP(j, n) if (b[j]) sum += A[j];
        REP(j, q) if (sum == m[j]) ans[j] = true;
    }
    REP(i, q)
    cout << [&] { return (ans[i]) ? "yes" : "no"; }() << endl;
    return 0;
}


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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    for(int i=0; i<=A; i++){
        for(int j=0; j<=B; j++){
            for(int k=0; k<=C; k++){
                int sum = 500*i + 100*j + 50*k;
                if(sum == X){
                    res++;
                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
a = [[[0 for r in range (10)] for f in range(3)] for b in range(4)]
ans = ""

n = input()
for i in range(0, n):
    b, f, r, v = map(int, raw_input().split(" "))
    a[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            ans += " "+str(a[b][f][r])
        if (b!=3 or f!=2 or r!=9):
            ans += "\n"
    if (b != 3):
        ans += "#"*20+"\n"

print(ans)

Measured memory_bytes: 6356
#B
#入力
N=int(input())


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
x=0
#総和
x+=N*(N+1)//2

#3の倍数の総和
Z=N//3
x-=3*Z*(Z+1)//2

#5
Z=N//5
x-=5*Z*(Z+1)//2

#15
Z=N//15
x+=15*Z*(Z+1)//2

print(x)

Measured memory_bytes: 9192
def main():
    row_input = input()
    split_input = row_input.split()

    N = int(split_input[0])
    M = int(split_input[1])

    ansors = []
    for i in range(N):
        row_input = input()
        split_input = row_input.split()
        ansor = []
        for k in range(1, int(split_input[0])+1):
            ansor.append(int(split_input[k]))
        ansors.append(ansor)

    food_list = []
    for i in range(1,M+1):
        food_list.append(i)

    for ans in ansors:
        length = len(food_list)
        diff = 0
        for i in range(length):
            target_food = food_list[i-diff]
            if target_food in ans:
                pass
            else:
                food_list.remove(target_food)
                diff+=1

    result = len(food_list)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
S = input()

uns = 0
for d in range(1, (N - 1) // 2 + 1):
    for i in range(N - 2 * d):
        s, t, u = S[i], S[i + d], S[i + 2 * d]
        if s != t and t != u and u != s:
            uns += 1

r = S.count('R')
g = S.count('G')
b = N - r - g # = S.count('B')

ans = r * g * b - uns
print(ans)

Measured memory_bytes: 9148
import itertools
def main():
    n,k = tuple([int(t)for t in input().split()])

    a = tuple([int(t)for t in input().split()])

    for _ in range(min(41,k)):
        b = [0]*(n+1)
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n,i+a[i]+1)
            b[l] += 1
            b[r] -= 1
        a = list(itertools.accumulate(b))[:n]

    print(*a)



if __name__ == "__main__":
    main()


Measured memory_bytes: 181616
#include<stdio.h>
#define N (100010)
int s[N];
int main(){	
	int n;
	scanf("%d",&n);
	for (int i=0,a;i<n;i++){
		scanf("%d",&a);
		s[a]++;
	}
	int cnt=0;
	for (int i=1;i<N;i++){
		if (s[i]>1) cnt+=s[i]-1;
	}
	printf("%d\n",n-cnt-(cnt&1));
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int n,x,d=0,l,i;
  cin>>n>>x;
  for(i=1;i<=n;++i){
    cin>>l;
    d+=l;
    if (d>x){
      break;
    }
  };
  cout<<i;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		for (int x = 0; x <= N; x++) {
			for (int y = 0; y <= N; y++) {
				int z = (Y - x * 10000 - y * 5000) / 1000;
				if (z >= 0 && x + y + z == N) {
					System.out.println(x + " " + y + " " + z);
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll  l,r;
  cin>>l>>r;
  if(r-l>=2100)
  {
    cout<<0<<endl;
    return 0;
  }
  ll res=2019;
  repi(i,l,r+1)
  {
    repi(j,i+1,r+1)
    {
      chmin(res,((ll)i*j)%2019);
      //if(res==0){cout<<i<<" "<<j<<endl;break;}
    }
    //if(res==0)break;
  }

  cout<<res<<endl;
  return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll cnt[1000010];

void pre(ll n){
    cnt[0]=0;
    for(ll i=1;i<=n;i++){
        ll add = 0;
        ll x = i;
        while(x%2==0)x/=2,add++;
        cnt[i] = cnt[i-1]+add;
    }
}

ll coff[3]={};
int  A(int x){
    if(x>=0)return x;
    else return -x;
}

int main(void){
    ll n;
    string s;
    cin>>n>>s;
    vector<int>a;
    for(int i=0;i<n-1;i++){
        int x = s[i]-'0';
        int y = s[i+1]-'0';
        a.push_back(A(x-y));
    }
    pre(n);
    for(ll i=0;i<a.size();i++){
        ll v = cnt[a.size()-1] -cnt[i] - cnt[a.size()-1-i];
        if(v==0)coff[a[i]]+=1;
    }
    //cout<<coff[1]<<endl;
    if(coff[1]%2==1){
        cout<<1<<endl;
        return 0;
    }
    else{
        if(coff[1]!=0)cout<<0<<endl;
        else{
            for(int i=0;i<a.size();i++){
                a[i]=a[i]/2;
            }
            coff[0]=0;
            coff[1]=0;
            coff[2]=0;
            for(ll i=0;i<a.size();i++){
                ll v = cnt[a.size()-1] -cnt[i] - cnt[a.size()-1-i];
                if(v==0)coff[a[i]]+=1;
            }
            if(coff[1]%2==1)cout<<2<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 13432
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

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

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

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

int n;
string s;

int main()
{
	cin>>n>>s;
	s.erase(unique(s.begin(),s.end()),s.end());
	cout<<s.size()<<endl;
	return 0;
}









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

int main(){
   int n;
   cin >> n;
   string s, t;
   cin >> s >> t;
   int i;
   string u;
   for(i = 0; i < n; i++){
       u += s.at(i);
       u += t.at(i);
   }
   cout << u << endl;
   return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc178/tasks/abc178_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
    int x = a.n + b.n;
    return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
    int x = a.n - b.n;
    return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
    for (int i = I_.size(); i <= n; i++) {
        I_.push_back(I_[MOD % i] * (MOD - MOD / i));
        F_.push_back(F_[i - 1] * i);
        R_.push_back(R_[i - 1] * I_[i]);
    }
}

mint I(int n) {
    check_fact(abs(n));
    return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
    check_fact(n);
    return n < 0 ? 0 : F_[n];
}
mint R(int n) {
    check_fact(n);
    return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

void solve() {
    int N;
    cin >> N;
    mint ans = 0;
    FOR(i, 1, N / 3 + 1) { ans += C(N - i * 3 + i - 1, i - 1); }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3676
#include<stdio.h>
int main(void)

{
int i,n;
int number;
long long int sum=0;
int min=0;
int max=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&number);
if(i==0)
{
min=number;
max=number;
}
if(number<min)min=number;
if(number>max)max=number;
sum+=number;
}
printf("%d %d %lld\n",min,max,sum);
return 0;
}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a > b){
		a = b;
	}
	if (c > d){
		c = d;
	}
	
	cout << a + c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  int a, b, c, d;
  a = n % 10;
  b = (n / 10) % 10;
  c = (n / 100) % 10;
  d = (n / 1000) % 10;
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<bool> a(N+1, false);
    vector<int> dp(N+1);
    int temp;
    for (int i = 0; i < M; i++)
    {
        cin >> temp;
        a[temp] = true;
    }
    dp[0] = 1;
    dp[1] = (a[0] ? 0 : 1);
    for (int i = 2; i <= N; i++) dp[i] = ((a[i-1] ? 0 : dp[i-1]) + (a[i-2] ? 0 : dp[i-2])) % 1000000007;
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	int n, k;
	vector<int>list;
	int maxn = 0;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	int m = min(n, k);

	for (int l = 0; l <= m; l++) {
		for (int r = 0; r <= m - l; r++) {

			vector<int>x;
			int sum = 0;

			for (int i = 0; i < n; i++) {
				if (l <= i && (n - r - 1 ) >= i) continue;
				x.push_back(list[i]);
				sum += list[i];
			}

			sort(x.begin(), x.end());

			//cout << "sum1->" << sum << endl;

			for (int i = 0; i < min((int)x.size(), k - l - r ) && x[i] < 0; i++){
				sum -= x[i];
			}

			//cout << "sum2->" << sum << endl;

			maxn = max(maxn, sum);
		}
	}



	cout << maxn << endl;



	getchar();
	getchar();
	return 0;
}

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

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

    int n;
    cin >> n;

    vector<double> v(n);
    REP(i, n) cin >> v[i];
    sort(v.begin(), v.end());

    double ans = v[0];
    REP(i, n - 1)
        ans = (ans + v[i + 1]) / 2.0;

    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[5];
int b[5];
int main(){
	scanf("%s",a);
	for(int i=0;i<=2;i++)b[i]=a[i]-'0';
	if(b[0]==b[2]){
		cout<<"Yes"<<endl;
		return 0;
	}
	else{
		cout<<"No"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int X; cin>>X;
	vi yen{0,100,101,102,103,104,105};
	vvi dp(yen.size()+1, vi(X+1));
	rp(i, 1, dp.size()){
		int y = yen[i];
		rp(j, y, X+1)
			// dp[i][j] = max({dp[i][j-y]+y, dp[i-1][j-y]+y});
			dp[i][j] = max({dp[i-1][j], dp[i][j-y]+y, dp[i-1][j-y]+y});
	}

	// rp(i,0,dp.size()){cout<<dp[i][X]<<" ";}puts("");///

	rp(i,1,dp.size()){
		if(dp[i][X]==X){
			puts("1");
			return 0;
		}
	}
	puts("0");
}


Measured memory_bytes: 3712
S = list(input())
n = len(S)

def hantei(s):
	length = len(s)
	for i in range(length//2):
		if s[i] != s[-i-1]:
			return False
	return True

if hantei(S) and hantei(S[:(n-1)//2]) and hantei(S[(n+3)//2-1:]):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 3060
import sys
from collections import deque

input = sys.stdin.readline
digtmp = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def flatten_2dim(array):
    return [item for sublist in array for item in sublist]

def main():
    H, W = map(int, input().split())
    grid = []; black = deque([])
    grid.append([0]*(W+2))
    for i in range(H):
        tmp = list(input()[:-1])
        for j in range(W):
            if tmp[j] == '#':
                black.append((i+1, j+1))
                tmp[j] = 0
        grid.append([0] + tmp + [0])
    grid.append([0]*(W+2))

    for _ in range(pow(10, 6)):
        fr = black.popleft()
        gfr = grid[fr[0]][fr[1]]
        for d in digtmp:
            to = (fr[0]+d[0], fr[1]+d[1])
            gto = grid[to[0]][to[1]]
            if gto == '.':
                grid[to[0]][to[1]] = gfr + 1
                black.append(to)
            elif gto != '#':
                if gfr + 1 < gto:
                    grid[to[0]][to[1]] = gfr + 1
                    black.append(to)
            else:
                pass
        if len(black) == 0:
            break
    
    ans = max(flatten_2dim(grid))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 182200
#include<stdio.h>

int main(void){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    x3 = y1-y2+x2;
    y3 = x2-x1+y2;
    x4 = y1-y2+x1;
    y4 = x2-x1+y1;
    printf("%d %d %d %d",x3,y3,x4,y4);
    return 0;
}


Measured memory_bytes: 128
using System;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(input[0]);
            var y = int.Parse(input[1]);
            var get = 0;

            switch (x)
            {
                case 1:
                    get += 300000;
                    break;
                case 2:
                    get += 200000;
                    break;
                case 3:
                    get += 100000;
                    break;
                default:
                    break;
            }
            switch (y)
            {
                case 1:
                    get += 300000;
                    break;
                case 2:
                    get += 200000;
                    break;
                case 3:
                    get += 100000;
                    break;
                default:
                    break;
            }

            if(x == 1 && y == 1){
                get += 400000;
            }

            Console.WriteLine(get);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string ans="No";
    if(abs(c-a)<=d) ans="Yes";
    if(abs(b-a)<=d && abs(c-b)<=d) ans="Yes";
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

string xor_bit(const string &s, int n) {
  string s_copy = s;
  if (s_copy[n] == '0') {
    s_copy[n] = '1';
  } else {
    s_copy[n] = '0';
  }
  return s_copy;
}

vector<int> calc_first_mod(const string &s) {
  int s_size = s.size();
  vector<int> digit_mod_more0(s_size, 1);
  vector<int> digit_mod_more1(s_size, 1);

  int mod_more0 = (s[s_size - 1] == '1' ? 1 : 0);
  int mod_more1 = mod_more0;

  int pop_count_default = count(ALL(s), '1');
  for (int i = s_size - 2; i >= 0; i--) {
    if (pop_count_default >= 2) {
      digit_mod_more0[i] =
          (digit_mod_more0[i + 1] * 2) % (pop_count_default - 1);
      mod_more0 = (mod_more0 + (s[i] == '1' ? digit_mod_more0[i] : 0)) %
                  (pop_count_default - 1);
    }
    digit_mod_more1[i] = (digit_mod_more1[i + 1] * 2) % (pop_count_default + 1);
    mod_more1 = (mod_more1 + (s[i] == '1' ? digit_mod_more1[i] : 0)) %
                (pop_count_default + 1);
  }
  vector<int> retv(s_size, 1);
  for (size_t i = 0; i < s_size; i++) {
    if (s[i] == '0') {
      retv[i] = (mod_more1 + digit_mod_more1[i]) % (pop_count_default + 1);
    } else {
      if (pop_count_default >= 2) {
        retv[i] = (mod_more0 + pop_count_default - 1 - digit_mod_more0[i]) %
                  (pop_count_default - 1);
      } else {
        retv[i] = -1;
      }
    }
  }

  return retv;
}

int calc_pop_count(int i) {
  int retv = 0;
  while (i > 0) {
    retv += i % 2;
    i /= 2;
  }
  return retv;
}

vector<int> solve(string X) {
  std::vector<int> retv(X.size(), 1);
  auto first_mods = calc_first_mod(X);
  for (size_t i = 0; i < X.size(); i++) {
    int x = first_mods[i];

    if (x == -1) {
      retv[i] = 0;
      continue;
    }

    if (x == 0) {
      continue;
    }

    while (x > 0) {
      x %= calc_pop_count(x);
      retv[i]++;
    }
  }
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  string X;
  cin >> N;
  cin >> X;

  // main procedure
  vector<int> ans = solve(X);

  // output
  for (auto &&x : ans) {
    cout << x << "\n";
  }

  return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,K;
    cin >> A >> B >> K;
    vec<int> ans;
    for(int i=max(A,B);i>=1;i--) if(A%i==0 && B%i==0) ans.push_back(i);
    cout << ans[K-1] << "\n";
}

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

using namespace std;

int main(){
    char s[100001];
    scanf("%s",s);
    int a,c=0,t;
    t=strlen(s);
    a=s[0]=='B'?0+'B':0+'W';
    for (int i=0;i<t;i++) {
        if (0+s[i]!=a) {
            c++;
            a=0+s[i];
        }
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> P;

ll dp[101][100001] = {};

int main(){
    ll n, w, w_i, v, i, j;
    cin >> n >> w;
    for(i=1; i<=n; i++){
        cin >> w_i >> v;
        for(j=0; j<=w; j++){
            if(j>=w_i){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w_i] + v);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << "\n";
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define me(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e3+5;

int h, w;
char mp[maxn][maxn];
int vis[maxn][maxn][4]={0};
int maxs = 0;

int main()
{
    scanf("%d %d ", &h, &w);
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
            scanf("%c", &mp[i][j]);
        getchar();
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(mp[i][j]=='#')
                continue;
            vis[i][j][0] = vis[i][j-1][0] + 1;
            vis[i][j][2] = vis[i-1][j][2] + 1;
        }
    }
    for(int i=h; i>0; i--)
    {
        for(int j=w; j>0; j--)
        {
            if(mp[i][j]=='#')
                continue;
            vis[i][j][1] = vis[i][j+1][1] + 1;
            vis[i][j][3] = vis[i+1][j][3] + 1;
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            int cnt = 0;
            for(int k=0; k<4; k++){
                cnt += vis[i][j][k];
            }
            maxs = max(maxs, cnt);
        }
    }
    cout<<maxs-3<<endl;
    return 0;
}

/**

//
mp[i][j][0] = mp[i][j-1][0] + 1
mp[i][j][1] = mp[i][j+1][1] + 1
mp[i][j][2] = mp[i-1][j][2] + 1
mp[i][j][3] = mp[i+1][j][3] + 1

***/


Measured memory_bytes: 66944
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  string s;
  cin >> s;
  char c='.';
  int count = 0;
  for (int i=0;i<4;i++) {
    if (c==s[i]) {
      count++;
      if (count==2) {
	cout << "Yes" << endl;
	return(0);
      }
    } else {
      count = 0;
    }
    c = s[i];
  }
  cout << "No" << endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};
bool dp[MAX_N]={};

int main() {
	int n;

    cin>>n;
    vector<string> vec;
    string str;
    for(int i=0;i<n;++i){
        cin>>str;
        vec.push_back(str);
    }
    sort(vec.begin(),vec.end());
    int total=1;
    for(int i=0;i<n-1;++i){
        if(vec[i+1]!=vec[i])total++;
    }
    cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 11652
H,W = map(int,input().split())      
board = []                          

d = [(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1),(1,0)]

for i in range(H):
    board.append(list(input().replace('.','0')))

print("\n")

for i in range(H):
    for j in range(W):
        if board[i][j] == '#' :continue

        mine_number = 0

        for k in range(8):

            ii,jj = i + d[k][0], j + d[k][1]

            if ii < 0 or ii>=H: continue    
            if jj < 0 or jj>=W: continue
            if (board[ii][jj] == '#'): mine_number += 1

            board[i][j] = str(mine_number)

for b in board:
    print("".join(b))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main(){
    int N;
    cin >> N;
    int res = N;

    REP(i,N+1){
        int cc=0;
        int t=i;
        while(t>0)  cc+=t%6, t/=6;
        t = N - i;
        while(t>0) cc+=t%9, t/=9;
        if(res>cc)  res=cc;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
main = interact $ show . sol . map read . words

sol [n,m] = if abs (n-m) > 1 then 0 
  else f n @*@ f m @*@ if n==m then 2 else 1

f x = foldl1 (@*@) [1..x]

infixl 7 @*@
(@*@) a b = a*b `mod` (10^9+7 :: Int)

Measured memory_bytes: 10620
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2332&lang=jp
typedef long long ll;
#define INF 1<<30
using namespace std;

void dfs(int n,int v,queue<pair<int,int>>&q, vector<int>& c,vector<int>& masu) {
	if (c[n] <= v) return;
	c[n] = v;
	if (masu[n] == 0) {
		q.push({ v,n });
	}
	else {
		dfs(n + masu[n], v, q, c, masu);
	}
}

void solve(int N,vector<int>& c,vector<int>& masu) {
	queue<pair<int,int>> q;
	q.push({ 0,1 });
	c[1] = 0;

	while (!q.empty()) {
		auto p = q.front(); q.pop();
		int C = p.first;
		int i = p.second;
		for (int j = 1; j <= 6;j++) {
			if (masu[i] != 0) break;
			if (masu[min(i + j, N)] == 0) {
				if (c[min(i + j, N)] > c[i] + 1) {
					c[min(i + j, N)] = c[i] + 1;
					q.push({ c[min(i + j,N)],i + j });
				}
			}
			else {
				dfs(i + j, c[i] + 1,q, c, masu);
			}
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> masu(N + 1, INF);
	vector<int> c(N + 1, INF);
	for (int i = 1;i <= N;i++)cin >> masu[i];
	solve(N,c,masu);
	cout << c[N] << endl;
}

Measured memory_bytes: 6180
#include<stdio.h>

int main(void)
{
	int n;
	const int N = 15;
	while(scanf("%d", &n), n)
	{
		const int n2 = n*n;
		int a[N][N] = {0};
		int i = (n>>1)+1,
			j = n>>1;
		int d = 1;
		while(d <= n2)
		{
			if(!a[i][j])
			{
				a[i][j] = d;
				d++;
				i = (i+1)%n;
				j = (j+1)%n;
			}
			else
			{
				i = (i+1)%n;
				j = (j-1+n)%n;
			}
		}
		for(i = 0; i < n; ++i)
		{
			for(j = 0; j < n; ++j)
				printf("%4d", a[i][j]);
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 0
// bit全探索に初挑戦!٩(๑❛ᴗ❛๑)۶
// 2択の選択肢を2進数で表せる?みたいのを前チラッと見ただけなので見様見真似ですらない...(~_~;)
// ちゃんと勉強します!٩( ᐛ )و
let S: [Int] = readLine()!.map { Int(String($0))! }
var res: String = ""

for i in 0..<8 {
    var num2 = String(i, radix: 2)  // i を2進数の文字列に変換
    num2 = String(repeating: "0", count: 3-num2.count) + num2   // 001とかを作るための0埋め (ちょっと無理やり＞＜ )
    res = "\(S[0])"
    var sum: Int = S[0]
    
    for (j, opt) in num2.enumerated() {
        if opt=="0" {   // 0のときに足す
            res += "+\(S[j+1])"
            sum += S[j+1]
        } else {    // 1のときに引く
            res += "-\(S[j+1])"
            sum -= S[j+1]
        }
    }
    if sum==7 { // 7だったら
        print(res+"=7") // (๑•ૅㅁ•๑)
        break
    }
}

Measured memory_bytes: 7980
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  1000005
bool vis[N];
ll cnt[N];
void solve()
{
	ll n;
	cin>>n;
	vi v(n);
	rep(i,0,n) {
		cin>>v[i];
		cnt[v[i]]++;
	}
	ll ans=0;
	sort(all(v));
	rep(i,0,n) {
		if(vis[v[i]])
			continue;
		if(cnt[v[i]]==1) {
			ans++;
		}
		for(ll j=v[i];j<N;j+=v[i]) {
			vis[j]=1;
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 13388
#include <stdio.h>
#define buf 100000
int partition(int A[],int p,int r);

int main(void){
	int n,i,base;
	int A[buf];

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&A[i]);
	base=partition(A,0,n-1);
	for(i=0;i<n;i++){
		if(i) printf(" ");
		if(i==base)
			printf("[%d]",A[i]);
		else
			printf("%d",A[i]);
	}
	printf("\n");
	return 0;
}
int partition(int A[],int p,int r){
	int x=A[r];
	int i=p-1;
	int j,c;
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			c=A[i];
			A[i]=A[j];
			A[j]=c;
		}
	}
	c=A[i+1];
	A[i+1]=A[r];
	A[r]=c;
	return i+1;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
for(int i=0; i<100; i++){
    C=C-B;
    if(C<1){
        break;
    }
    A=A-D;
    if(A<1){
        break;
    }
}
if(A<1){cout<< NO <<endl;} 
else {cout<< YES <<endl;}
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3776
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 101;
int R, C;
char g[N][N + 1];
int main()
{
	int f[26] = {};
	scanf("%d%d", &R, &C);
	for (int i = 0; i < R; ++i)
		for (int j = 0; j < C; ++j) {
			scanf(" %c", &g[i][j]);
			++f[g[i][j]-'a'];
		}
	int need[5] = {};
	for (int i = 0; i <= (R-1) / 2; ++i)
		for (int j = 0; j <= (C-1) / 2; ++j) {
			if (R - i - 1 == i) {
				if (C - j - 1 == j)
					++need[1];
				else
					++need[2];
			}
			else {
				if (C - j - 1 == j)
					++need[2];
				else
					++need[4];
			}
		}
	priority_queue<int> q;
	for (int i = 0; i < 26; ++i)
		if (f[i])
			q.push(f[i]);
	while (!q.empty()) {
		int x = q.top();
		q.pop();
		bool ok = false;
		for (int i = 4; i > 0; --i) {
			if (!need[i])
				continue;
			if (need[i] && x < i) {
				puts("No");
				return 0;
			}
			--need[i];
			x -= i;
			if (x)
				q.push(x);
			ok = true;
			break;
		}
		if (!ok) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256