akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int x = 2 * d + 1;
		if (n % x == 0)
			System.out.println(n / x);
		else
			System.out.println(n / x + 1);
		in.close();
	}
}


Measured memory_bytes: 23764
#include<stdio.h>
#include<math.h>

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

    int L[N];
    int tmp,i,j;

    for(i=0;i<=N-1;i++){
    scanf("%d",&L[i]);
    }

    for(i=0;i<=N-1;i++){
        for(j=i+1;j<=N-1;j++){
            if(L[i]>L[j]){
                tmp = L[i];
                L[i] = L[j];
                L[j] = tmp;
            }
        }
    }

    tmp=0;
    for(i=0;i<=N-2;i++){
        tmp+=L[i];
    }

    if(L[N-1]<tmp){
        printf("Yes");
    }
    else{
        printf("No");
    }

    return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n,0);
  vector<int> b(n-1,0);
  for(int i=0; i<n-1; i++) cin >> b.at(i);
  //入力
  a.at(0) = b.at(0);
  for(int i=1; i<n-1; i++)
    a.at(i) = min(b.at(i),b.at(i-1));
  a.at(n-1) = b.at(n-2);
  //aの決定
  int ans;
  for(int i=0; i<n; i++) ans += a.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 256
n,s=open(0)
n=int(n)
a=l=s[0]<'W'>s[-2]
r=f=0
for b,c in zip(s,s[1:-1]):f^=b==c;a=a*(max(1,n))*(l-r)**f%(10**9+7);n-=1;r+=f;l+=f^1
print(a*(l==r))

Measured memory_bytes: 3512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>	
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>	
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <fstream>
#include <cstdio>
#include <memory.h>

using namespace std;

int h, w;
char board[50][50];
int res = -1;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { -1,0,1,0 };
void bfs()
{
	bool visited[50][50];
	queue <pair<pair<int, int>, int>> que;
	
	memset(visited, false, sizeof(visited));
	que.push(make_pair(make_pair(0, 0), 1));

	while (!que.empty())
	{
		int y = que.front().first.first;
		int x = que.front().first.second;
		int count = que.front().second;
		que.pop();
		if (visited[y][x] == true)
		{
			continue;
		}
		visited[y][x] = true;
		if (y == h - 1 && x == w - 1)
		{
			res = count;
			break;
		}
		for (int k = 0; k < 4; k++)
		{
			int sy = y + dy[k];
			int sx = x + dx[k];
			if (sy < 0 || sy >= h || sx < 0 || sx >= w)
			{
				continue;
			}
			if (board[sy][sx] == '.' && visited[sy][sx] == false)
			{
				que.push(make_pair(make_pair(sy, sx), count + 1));
			}
		}
	}

	return;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int count = 0;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> board[i][j];
			if (board[i][j] == '#')
			{
				count++;
			}
		}
	}
	bfs();
	if (res == -1)
	{
		cout << -1 << '\n';
	}
	else
	{
		int x = h*w - res;
		x -= count;
		cout << x << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    cout << x/(y+z);
}  

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;
string s = ".357";

inline li stoi(string& s) {
    stringstream ss;
    ss << s;
    li x;
    ss >> x;
    return x;
}

inline li calc(li x) {
    li xx = x;
    string now = "";
    while (x > 0) {
        now = s[x % 4] + now;
        if (x % 4 == 0)return 0;
        x /= 4;
    }
    //p2(xx, now);
    return stoi(now);
}

inline bool ok(li x) {
    set<li> st;
    li xx = calc(x);
    while (x > 0) {
        st.insert(x % 4);
        if (x % 4 == 0)return false;
        x /= 4;
    }
    if (st.find(0) != st.end()) {
        return false;
    }
    return (sz(st) == 3);
}

int main() {
    li n;
    cin >> n;

    li now3 = 1;
    li res = 0;
    while (calc(now3) <= n) {
        if (calc(now3) > 1000000000ll) {
            break;
        }
        if (ok(now3)) {
            res++;
        }
        now3++;
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n, k;
    cin >> n >> k;

    if (k == 0)
    {
        cout << n * n << endl;
        return;
    }

    ll ans = 0;
    ll cnt = 0;
    rep(b, n + 1)
    {
        if (b <= k)
            continue;
        ++cnt;
        ans += ((n + 1) / b * cnt) + max(0l, (n + 1) % b - k);
    }
    cout << ans << endl;
}

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


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=0;
  string s;
 
  cin >> s;

  if( s=="ABC" ){ cout << "ARC" << endl; }
  else { cout << "ABC" << endl; }
  
}

Measured memory_bytes: 3628
a, b, c, d = map(int, input().split())

def attack_count(life, power):
    count = life // power
    if life % power == 0:
        return count
    else:
        return count + 1

t_lifespan = attack_count(a, d)
a_lifespan = attack_count(c, b)

if t_lifespan == a_lifespan:
    print("Yes")
elif t_lifespan > a_lifespan:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9180
N, M, C = map(int, input().split())

list_b = []

list_a = []

while len(list_b) < M:
	list_b.extend(input().split())
	
	
for i in range(N):
	list_a_i = []
	while len(list_a_i)< M:
		list_a_i.extend(input().split())
		list_a.append(list_a_i)

count_right = 0


for i in range(N):
	sum_abc = 0
	for j in range(M):
		list_ai = list_a[i]
		sum_abc += int(list_ai[j])*int(list_b[j])
	
	if sum_abc > -C:
		count_right += 1
	else:
		continue
	

print(count_right)

Measured memory_bytes: 3064
/**
 *      purpose : NIKKEI Programming Contest 2019
 *      author  : kyomukyomupurin
 *      created : 2019-01-27 21:05:47
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    int64 a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];

    int64 sum[n];
    rep(i, n) sum[i] = a[i] + b[i];

    sort(sum, sum + n, greater<int64>());

    int64 sumb = accumulate(b, b + n, int64());

    int64 sumT = 0;

    for (int i = 0; i < n; i += 2){
        sumT += sum[i];
    }

    print(sumT - sumb);

    return 0;
}

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

int h1, h2, m1, m2, k;

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

	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int duration = 60 * h2 + m2 - (60 * h1 + m1);
	int ans = max(0, duration - k);
	cout << ans << "\n";
	return 0;
}


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

char win_te(char src)
{
    char dst;
    if (src == 'r')
    {
        dst = 'p';
    }
    else if (src == 's')
    {
        dst = 'r';
    }
    else if (src == 'p')
    {
        dst = 's';
    }
    return dst;
}

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<pair<int, char>> point(3);
    point[0] = make_pair(R, 'r');
    point[1] = make_pair(S, 's');
    point[2] = make_pair(P, 'p');
    sort(point.rbegin(), point.rend());
    string A;

    rep(i, N)
    {
        if (point[0].second == win_te(T[i]))
            A += point[0].second;
        else
            A += "x";
    }

    rep(i, N - K)
    {
        if (A[i] == 'x')
            continue;

        if (A[i] == A[i + K])
            A[i + K] = 'x';
    }

    rep(i, N)
    {
        if (A[i] != 'x')
            continue;

        if (point[1].second == win_te(T[i]))
        {
            A[i] = point[1].second;
        }
    }
    rep(i, N - K)
    {
        if (A[i] == 'x')
            continue;

        if (A[i] == A[i + K])
            A[i + K] = 'x';
    }
    rep(i, N)
    {
        if (A[i] != 'x')
            continue;

        if (point[2].second == win_te(T[i]))
        {
            A[i] = point[2].second;
        }
    }
    rep(i, N - K)
    {
        if (A[i] == 'x')
            continue;

        if (A[i] == A[i + K])
            A[i + K] = 'x';
    }

    long long ans = 0;
    rep(i, N)
    {
        rep(j, 3)
        {
            if (A[i] == point[j].second)
                ans += point[j].first;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
		string s;
		cin>>s;
		int l = s.length();
		int n = l+2;
		char ch[n];
		ch[0] = 'S';
		ch[n-1] = 'S';
		int j = 0;
		for(int i = 1; i<=n-2; i++)
		{
			ch[i] = s[j];
			j++;
		}
		int k = 0;
		int count = 0;int q = 0;
		vector<int> v;
		for(int i = 0; i<n; i++)
		{
			if(ch[i]=='R')
			{
				count++;
			}
			else
			{
				v.push_back(count);
				count = 0;
				continue;
			}
		}
		sort(v.begin(),v.end(),greater<int>());
		int sum = 0;
		for(int i = 0; i<v.size(); i++)
		{
			if(i%2==0)
			{
				sum+=v[i];
			}
		}
		cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  set<int> s;
  int x = 0;
  FOR(i, 0, n) {
    if (a[i] > 3199) {
      ++x;
      continue;
    }
    s.ins(a[i] / 400);
  }
  if (!sz(s)) {
    cout << 1 << " " << sz(s) + x;
    return 0;
  }
  cout << sz(s) << " " << sz(s) + x;

  return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rept(i,k,n) for(long long i = (k); i < (long long)(n); i++)
#define All(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Rsort(v) sort(v.begin(),v.end(),[](auto a, auto b) { return a > b; })
#define Reverse(v) reverse(v.begin(),v.end())
#define MAX 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}
 
ll mod = 1e9+7;
int main(){
    int k;
    cin>>k;
    int c = 1;
    int m=0;
    while(c<=k){
        m = (m*10+7)%k;
        if(m==0){
            cout<<c<<endl;
            return 0;
        }
        c++;
        
    }
    cout<<-1<<endl;
    return 0;
}

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

using namespace std;

int n;
string s;

int check(int mid){
  set<char> a, b;
  int ret = 0;
  for(int i=0; i<=mid; i++) a.insert(s[i]);
  for(int i=mid+1; i<n; i++) b.insert(s[i]);
  for(auto x : a){
    for(auto y : b){
      if(x == y){
        ret++;
        break;
      }
    }
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  int ans = 0;
  for(int i=0; i<n; i++){
    ans = max(ans, check(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def is_success(s, h, w):
    for i in range(h):
        for j in range(w):
            if s[i][j] != '#':
                continue
            if i >= 1 and s[i-1][j] == '#':
                continue
            if i <= h-2 and s[i+1][j] == '#':
                continue
            if j >= 1 and s[i][j-1] == '#':
                continue
            if j <= w-2 and s[i][j+1] == '#':
                continue
            return 'No'

    return 'Yes'


h, w = [int(v) for v in input().split()]
s = []
for i in range(h):
    s.append(input())

print(is_success(s, h, w))

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

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


int main(void){
    int n, x0;
    cin >> n >> x0;
    vector<int> x(n);
    for(int i = 0; i < n; i ++){
        cin >> x[i];
        x[i] -= x0;
    }
    int g = x[0];
    for(int i = 1; i < n; i ++){
        g = gcd(g, x[i]);
    }
    cout << abs(g) << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
vector<ll> paths[200100];
vector<ll> v[2];
vector<ll> num[3];
vector<ll> ans;

void dfs(int now, int from, int idx) {
    v[idx].push_back(now);
    for(auto to : paths[now]) {
        if(to == from) continue;
        dfs(to, now, 1 - idx);
    }
}

void print() {
    for(int i = 0; i < N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) {
        num[i%3].push_back(i);
    }
    ans.resize(N);
    for(int i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    dfs(0, -1, 0);
    if(v[0].size() <= N / 3) {
        for(auto tmp : v[0]) {
            ans[tmp] = num[0].back();
            num[0].pop_back();
        }
        for(auto tmp : v[1]) {
            for(int i = 0; i < 3; i++) {
                if(num[i].empty()) continue;
                ans[tmp] = num[i].back();
                num[i].pop_back();
                break;
            }
        }
        print();
        return 0;
    }
    swap(v[0], v[1]);
    if(v[0].size() <= N / 3) {
        for(auto tmp : v[0]) {
            ans[tmp] = num[0].back();
            num[0].pop_back();
        }
        for(auto tmp : v[1]) {
            for(int i = 0; i < 3; i++) {
                if(num[i].empty()) continue;
                ans[tmp] = num[i].back();
                num[i].pop_back();
                break;
            }
        }
        print();
        return 0;
    }
    for(int i = 0; i < 2; i++) {
        for(auto tmp : v[i]) {
            if(!num[i+1].empty()) {
                ans[tmp] = num[i+1].back();
                num[i+1].pop_back();
                continue;
            } else {
                ans[tmp] = num[0].back();
                num[0].pop_back();
            }
        }
    }
    print();
    return 0;
}


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

int main()
{
  int n,a[100005]={0},i,num=0;
  cin >> n;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(i=1;i<=n;i++)
  {
    if(a[i]==i)
    {
        num++;i++;
    }
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int main(){
	int x,r=0;
	scanf("%d",&x);
	if(x>=1800) r=1;
	else if(x>=1600) r=2;
	else if(x>=1400) r=3;
	else if(x>=1200) r=4;
	else if(x>=1000) r=5;
	else if(x>=800) r=6;
	else if(x>=600) r=7;
	else if(x>=400) r=8;
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1736
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f

let () =
  let [a; b; c; d] = read_ints 4 in
  let res = if a+b > c+d then "Left" else if a+b < c+d then "Right" else "Balanced" in
  printf "%s\n" res


Measured memory_bytes: 384
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	int n;
	cin>>n;
	double even=n/2;
	double odd=n-even;
	double ans=odd/n;
	cout << fixed << setprecision(6) << ans <<endl; 
}
void q2(){
	int n,k,c=0;
	cin>>n>>k;
	while(n--){
	int t; cin>>t;
	if(t>=k)
	c++;
	}
	cout<<c<<endl;
}
void q3(){
	int n;	cin>>n; int arr[n];
	for(int i=1;i<=n;++i){
		int t;
		cin>>t;	t--;
		arr[t]=i;
	}
	for(int i=0;i<n;++i)
	cout<<arr[i]<< " ";
}
void q4(){
	int a,b;
	cin>>a>>b;
	a=__gcd(a,b);
	int cp=1;
	for(int i=2;i<=1000005;++i){
		if(a%i==0){
			cp++;
			while(a%i==0)
			a/=i;
		}
	}
	if(a!=1)
	cp++;
	cout<<cp;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q4();
	return 0;
}


Measured memory_bytes: 256
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

for i in range(N-1):
    time = t[i][1] + t[i][0]
    for j in range(i+1,  N-1):
        if time < t[j][1]:
            time = t[j][1]
        elif (time - t[j][1]) % t[j][2] == 0:
            pass
        else:
            time += t[j][2] - time % t[j][2]
        time += t[j][0]
    print(time)
print(0)





Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		Arrays.sort(a);
		int alice = 0;
		int bob = 0;
		int c = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (c == 0) {
				alice += a[i];
				c = 1;
			}
			else {
				bob += a[i];
				c = 0;
			}
		}
		System.out.println(alice - bob);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),k=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<k;i++) {
    	int d=sc.nextInt();
    	for(int j=0;j<d;j++) {
    		a[sc.nextInt()-1]++;
    	}
    }
    int count=0;
    for(int i:a) {
    	if(i==0)count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 46324
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = (ll)(1e9 + 7);

ll powe(ll x, ll y)
{
    ll temp = 1;
    while (y)
    {
        if (y & 1)
            temp *= x, temp %= mod;
        y = y >> 1;
        x *= x;
        x %= mod;
    }
    return temp;
}

int main()
{
    ll sum = 0;
    ll sq = 0;
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
        sum %= mod;
        sq += (a[i] * a[i]) % mod;
        sq %= mod;
    }
    sum *= sum;
    sum %= mod;
    cout << (((sum - sq + mod) % mod) * powe(2, mod - 2)) % mod << "\n";
}

Measured memory_bytes: 4836
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $arr = explode(" ", trim(fgets(STDIN)));
  sort($arr);
  $ans = 0;
  for($i = 0; $i < $k; $i++){
      $ans = $ans + $arr[$i];
  }
  echo $ans;
?>

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

using namespace std;

int main() {
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> high(N);
    for(int i = 0; i < N; i++) cin >> high.at(i);

    int near = 1000000000;
    for(int i = 0; i < N; i++){
        near = min(near, abs(1000 * A - 1000 * T + high.at(i) * 6));
    }
    for(int i = 0; i < N; i++){
        if(near == abs(1000 * A - 1000 * T + high.at(i) * 6)) cout << i + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner; 
public class Main {
  public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
      if(w>=(x+r)&&0<=(x-r)&&h>=(y+r)&&0<=(y-r)){
          System.out.println("Yes"); 
      }else{
          System.out.println("No");
     }
    sc.close();
  }
}


Measured memory_bytes: 26232
/**
* Motto:   fight till end
* Author: fyter_112
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ump unordered_map<int,int>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=a;i<(n);i++)
#define all(x) x.begin(),x.end()
#define reps(i,j,n)   for(int i=(j);i>=(n);i--)
#define ld long double
#define count(i,n) for(i=n;i>0;i=i/10)
#define kick(ts) cout<<"Case #"<<ts<<": "
#define mod 1000000007
int32_t main()
{
  int n,w,sum=0;
  cin>>n>>w;
  int weight[n],value[n],m=0;
  pii seg[n];
  rep(i,0,n)
  {
    cin>>weight[i]>>value[i];
    seg[i].first=value[i];
    seg[i].second=weight[i];
    sum+=value[i];
  }
  sort(seg,seg+n);
  rep(i,0,n)
  {
    value[i]=seg[i].first;
    weight[i]=seg[i].second;
  }
  int dp[n+1][sum+1];
  rep(i,0,n+1)
  {
    rep(j,0,sum+1)
    {
      if(j==0)
      {
        dp[i][j]=0;
      }
      else if(i==0)
      {
        dp[i][j]=mod;
      }
      else if(j<value[i-1])
      {
        dp[i][j]=dp[i-1][j];
      }
      else
      {
        dp[i][j]=min(dp[i-1][j],weight[i-1]+dp[i-1][j-value[i-1]]);
        if(dp[i][j]<=w)
        {
          m=max(j,m);
        }
      }
    }
  }
  cout << m <<'\n';
}


Measured memory_bytes: 79104
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	int n;
	cin >> n;
	Vl A(n);
	rep(i, n)  cin >> A[i];

	bool f = false;

	rep(i, n) {
		if (A[i] == 0)  f = true;
	}
	if (f) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	rep(i, n) {
		if (ans <= ll(1e18) / A[i]) {
			ans *= A[i];
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4052
#include <stdio.h>

int main(void) {
	int b,r,g,c,s,t;
	int bonus;
	int medal;
	while(1) {
		scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t);
		if((b|r|g|c|s|t)==0)break;
		bonus=b*5+r*3;
		medal=100;
		medal-=(t-s-bonus)*3+bonus*2;
		medal+=b*15;
		medal+=r*15;
		medal+=g*7;
		medal+=c*2;
		medal+=bonus*15;
		printf("%d\n",medal);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
long long ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int l=1,r=0,x=0,y=0;l<=n;x=x^a[l],y=y-a[l],l++){
		while((x^a[r+1])==(y+a[r+1])&&r<n){
			r++;
			x=x^a[r];
			y=y+a[r];
		}
		ans=ans+(r-l+1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4524
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())
dp = [[0,0] for _ in range(N)]
cnt = 0
ans = []
for i in range(1,N):
    if S[i] == "E":
        cnt += 1
dp[0][1] = cnt
ans.append(sum(dp[0]))
for j in range(1,N):
    if S[j-1] == "W":
        dp[j][0] = dp[j-1][0] + 1
    else:
        dp[j][0] = dp[j-1][0]
    if S[j] == "E":
        dp[j][1] = dp[j-1][1] - 1
    else:
        dp[j][1] = dp[j-1][1]
    ans.append(sum(dp[j]))
print(min(ans))

Measured memory_bytes: 57932
n = list(map(int,input().split()))
j = list(input())

for i in range(len(j)):
    if j[i] == 'E':
        n[0], n[3], n[5], n[2] = n[3], n[5], n[2], n[0]

    elif j[i] == 'W':
        n[0], n[2], n[5], n[3] = n[2], n[5], n[3], n[0]

    elif j[i] == 'S':
        n[0], n[4], n[5], n[1] = n[4], n[5], n[1], n[0]

    else:
        n[0], n[1], n[5], n[4]  = n[1], n[5], n[4], n[0]

print(n[0])


Measured memory_bytes: 5612
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
int const maxn=2e6+100;
int const mod=1e9+7;
ll num[maxn];
void init(){
	num[0]=num[1]=1;
	for(int i=2;i<maxn;i++) num[i]=num[i-1]*i%mod;
}
ll qpow(ll m,ll n){
	ll res=1;
	while(n){
		if(n&1) res=res*m%mod;
		n>>=1;
		m=m*m%mod;
	}
	return res;
}
ll C(ll n,ll m){
	return num[n]*qpow(num[m],mod-2)%mod*qpow(num[n-m],mod-2)%mod;
}
int main(){
	init();
	ll r1,r2,c1,c2;
	scanf("%lld%lld%lld%lld",&r1,&c1,&r2,&c2);
	ll res=C(r2+c2+2,c2+1)+C(r1+c1,c1)-C(r2+c1+1,c1)-C(r1+c2+1,c2+1);
	while(res<0) res+=mod;
	printf("%lld\n",res%mod);
}

Measured memory_bytes: 15872
/*
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] a = new long[n];
        int[][] bit = new int[n][40];
        int[] bitK=new int[40];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        for (int i = 0; i < n; i++) {
            int c=0;
            while (a[i]>0) {
                bit[i][c++]=(int)a[i]%2;
                a[i]/=2;
            }
        }
        int c=0;
        long t=k;
        while (t>0){
            bitK[c++]=(int)t%2;
            t/=2;
        }
        int[] cnt=new int[40];
        for (int i = 0; i < 40; i++) {
            for (int j = 0; j < n; j++) {
                cnt[i]+=bit[j][i];
            }
        }
    }
}
*/
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] f=new long[n+1];
        Point[] sushi = new Point[n];
        for (int i = 0; i < n; i++) {
            sushi[i]=(new Point(sc.nextInt(), sc.nextInt()));
        }
        HashSet<Integer> S=new HashSet<>();
        Arrays.sort(sushi,(p1, p2) -> p2.y - p1.y);
        long temp=0;
        int[] s=new int[n+1];
        for (int i = 0; i < k; i++) {
            temp += (long) sushi[i].y;
            S.add(sushi[i].x);
            s[sushi[i].x]++;
        }
        int size=S.size();
        f[size]=temp;
        int left=k-1,right=k;
        while (0<=left&&right<n){
            while (0<=left&&s[sushi[left].x]==1){
                left--;
            }
            while (right<n&&s[sushi[right].x]>0){
                right++;
            }
            if(0<=left&&right<n){
                f[size+1]=f[size]-sushi[left].y+sushi[right].y;
                size++;
                s[sushi[right].x]++;
                s[sushi[left].x]--;
                swap(sushi,left,right);
            }
        }
        long ans=0;
        for (long i = 1; i <= k; i++) {
            if(f[(int)i]>0)ans=max(ans,f[(int)i]+i*i);
        }
        out.println(ans);

    }
    static void swap(Point[] p,int a,int b){
        Point temp=p[a];
        p[a]=p[b];
        p[b]=temp;
    }
}

Measured memory_bytes: 99232
#include <stdio.h>

int main(void){

  int N;
  scanf("%d",&N);
  char S[10000];
  scanf("%s",&S);
  int i, j,  count=0;
  for(j=0;S[j]!='\0';j++){
    count+=1;
  }
  for(i=0;i<count;i++){
    S[i]+=N;
    if(S[i]>'Z'){
      S[i]=S[i]-'Z'-1+'A';
    }
  }
  printf("%s\n",S);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int ans;
const int N_MAX = 12;
const int M_MAX = 12;
vector<pair<pair<int, int>, pair<int, int>>> P;

int A[N_MAX + 1];

int n, m, q;

void point(){
    int newans = 0;
    for(int i = 0; i < P.size(); i++){
        int a = P[i].first.first;
        int b = P[i].first.second;
        int c = P[i].second.first;
        int d = P[i].second.second;
        if (A[b] - A[a] == c) newans += d;
    }
    ans = max(newans, ans);
}

void choice(int k, int s){
    for(int i = s; i <= m; i++){
        A[k] = i;
        if (k == n) point();
        else choice(k+1, i);
    }
}

int main(){
    cin >> n >> m >> q;
    ans = 0;
    for(int i = 0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        P.push_back(make_pair(make_pair(a, b), make_pair(c, d)));
    }
    choice(1, 1);
    cout << ans << endl;
    return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, K;
    cin >> N >> K;
    cout << (K <= (N+1)/2 ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 384
/*
 * src.cpp
 *
 *  Created on: 2016/08/01
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_N=1e2;
const double EPS=1e-10;

#define EQ(a,b) fabs(a-b)<EPS

int R,N;

struct Point{
	double x,y;
	Point(double x=0.0,double y=0.0):x(x),y(y){}
	Point operator +(const Point &p){
		return Point(x+p.x,y+p.y);
	}
	Point operator -(const Point &p){
		return Point(x-p.x,y-p.y);
	}
	Point operator *(double k){
		return Point(x*k,y*k);
	}
	Point operator /(double k){
		return Point(x/k,y/k);
	}
	double norm(){
		return x*x+y*y;
	}
	double abs(){
		return sqrt(norm());
	}
};

typedef pair<Point,Point> P;

typedef Point Vector;

double dot(const Vector &a,const Vector &b){
	return a.x*b.x+a.y*b.y;
}

double cross(const Vector &a,const Vector &b){
	return a.x*b.y-a.y*b.x;
}

struct Segment{
	Point p1,p2;
	Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};

typedef Segment line;

Point project(Segment s,Point p){
	Vector base=s.p2-s.p1;
	double r=dot(base,p-s.p1)/base.norm();
	return s.p1+base*r;
}

struct Circle{
	Point c;
	double r;
	Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

struct UFO{
	Circle cir;
	Vector v;
	bool flg;
};

UFO u[MAX_N];

P getCrossPoints(Circle c,line l){
	Point pr=project(l,c.c);
	Vector e=(l.p2-l.p1)/(l.p2-l.p1).abs();
	double base=sqrt(c.r*c.r-(c.c-pr).norm());
	return make_pair(pr+e*base,pr-e*base);
}

int main(){
	do{
		scanf("%d %d",&R,&N);
		if (R || N){
			REP(i,N){
				int x,y,r,v;
				scanf("%d %d %d %d",&x,&y,&r,&v);
				Vector p=Point((double)x,(double)y);
				u[i].cir=Circle(p,(double)r);
				u[i].flg=true;
				if (EQ(p.abs(),0)){
					u[i].v=Point(0.0,0.0);
				}else{
					u[i].v=p*(-1)/p.abs()*(double)v;
				}
			}
			while (1){
				REP(i,N){
					if (u[i].flg){
						if (u[i].cir.c.norm()<u[i].v.norm() || u[i].cir.c.norm()<R*R){
							u[i].cir.c=Point(0.0,0.0);
						}else{
							u[i].cir.c=u[i].cir.c+u[i].v;
						}
					}
				}
				int a=-1;
				REP(i,N){
					if (u[i].flg){
						if (u[i].cir.c.norm()>R*R){
							if (a==-1 || u[i].cir.c.norm()<u[a].cir.c.norm()){
								a=i;
							}
						}
					}
				}
				if (a==-1){
					break;
				}
				line laser=Segment(Point(),u[a].cir.c);
				Vector e=u[a].cir.c/u[a].cir.c.abs();
				REP(i,N){
					if (u[i].flg){
						if (u[i].cir.c.norm()>R*R){
							Vector pr=project(laser,u[i].cir.c);
							if ((u[i].cir.c-pr).norm()<u[i].cir.r*u[i].cir.r){
								P pa=getCrossPoints(u[i].cir,laser);
								if (dot(e,pa.first)>=0 && pa.first.norm()>R*R){
									u[i].flg=false;
								}
								if (dot(e,pa.second)>=0 && pa.second.norm()>R*R){
									u[i].flg=false;
								}
							}
						}
					}
				}
			}
			int ans=0;
			REP(i,N){
				if (u[i].flg){
					ans++;
				}
			}
			printf("%d\n",ans);
		}
	}while (R || N);
	return 0;
}

Measured memory_bytes: 1196
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

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

inline int bsf(int n)
{
    int z;
    __asm__("bsf %1, %0;" :"=r"(z) :"r"(n));
    return z;
}

int dfs(const vector<int>& coeff, const vector<bool>& can_be_zero,
        int unused, int max_depth, int depth, int sum)
{
    int ret = 0;
    for (int u = unused; u; u -= u & -u) {
        int i = bsf(u);
        if (i == 0 && !can_be_zero[depth])
            continue;
        int next_sum = sum + coeff[depth] * i;
        if (depth + 1 == max_depth)
            ret += (next_sum == 0) ? 1 : 0;
        else
            ret += dfs(coeff, can_be_zero, unused ^ (1 << i), max_depth, depth + 1, next_sum);
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    for (int T = 1; cin >> n, n; ++T) {
        vector<string> words(n);
        map<char, int> mapping;
        int k = 0;
        rep(i, n) {
           cin >> words[i];
           rep(j, words[i].size()) {
               if (!mapping.count(words[i][j]))
                   mapping.insert({ words[i][j], k++ });
               words[i][j] = mapping[words[i][j]];
           }
        }

        vector<bool> can_be_zero(k, true);
        vector<int> coeff(k, 0);
        rep(i, n) {
            int c = words[i][0];
            can_be_zero[c] = can_be_zero[c] && (words[i].size() == 1);
            for (int j = words[i].size() - 1, d = 1; j >= 0; --j, d *= 10)
                coeff[words[i][j]] += (i == n-1) ? -d : d;
        }

        cout << dfs(coeff, can_be_zero, (1 << 10) - 1, k, 0, 0) << endl;
    }
}

Measured memory_bytes: 1208
#include<cstdio>
#include<vector>
#include<queue>
#define N 10000
using namespace std;

int inNum[N]={0};
int V,E;
vector<int> M[N];
vector<bool> visited(N,0);
void topology(){
    queue<int> Q;
    vector<int> ans;
    for(int i=0;i<V;i++){
        if(inNum[i]==0) Q.push(i);
    }
    while(!Q.empty()){
        int node=Q.front();
        Q.pop();
        visited[node]=true;
        ans.push_back(node);
        for(int i=0;i<M[node].size();i++){
            inNum[M[node][i]]--;
            if(!visited[M[node][i]] && inNum[M[node][i]]==0){
                Q.push(M[node][i]);
            }
        }

    }
    if(ans.size()<V){
        printf("Wrong\n");
        return;
    }else{
        for(int i=0;i<ans.size();i++){
            printf("%d\n",ans[i]);
        }
    }
}

int main(){
    scanf("%d%d",&V,&E);
    for(int i=0;i<V;i++){
        inNum[i]=0;
    }
    int s,t;
    for(int i=0;i<E;i++){
        scanf("%d%d",&s,&t);
        inNum[t]++;
        M[s].push_back(t);
    }

    topology();
    return 0;

}



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

int main() {
  
  int P=0, Q=0, R=0;
  
  cin >> P >> Q >> R;
  
  int ABC = P + Q;
  int ACB = R + Q;
  
  int BCA = Q + R;
  int BAC = P + R;
  
  int CAB = R + P;
  int CBA = Q + P;
  
  int ans0 = min((ABC, BCA), CAB);
  int ans1 = min((ACB, BAC), CBA);
  
  int ans = min(ans0, ans1);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x;
    cin >> x;

    int ans = 1;

    FOR(i, 2, x)
    {
        FOR(j, 2, x)
        {
            int bp = 1;
            REP(k, j)
            {
                bp *= i;
            }
            if(bp > x)
            {
                break;
            }else
            {
                chmax(ans, bp);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n;
  cin>>n;
  vector<vector<string> >vecto(n);
  vecto[0].push_back("a");
  string vs="abcdefghi";
  for(int i=1;i<n;i++){
    for(auto s:vecto[i-1]){
      char cha='z';
      for(int j=8;j>=0;j--){
        for(int k=0;k<s.size();k++){
          if(vs[j]==s[k]){
            cha=vs[j];
            break;
          }
        }
        if(cha!='z')break;
      }
      if(cha=='a'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
      }
      if(cha=='b'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
      }
      if(cha=='c'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
      }
      if(cha=='d'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
      }
      if(cha=='e'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
        vecto[i].push_back(s+'f');
      }
      if(cha=='f'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
        vecto[i].push_back(s+'f');
        vecto[i].push_back(s+'g');
      }
      if(cha=='g'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
        vecto[i].push_back(s+'f');
        vecto[i].push_back(s+'g');
        vecto[i].push_back(s+'h');
      }
      if(cha=='h'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
        vecto[i].push_back(s+'f');
        vecto[i].push_back(s+'g');
        vecto[i].push_back(s+'h');
        vecto[i].push_back(s+'i');
      }
      if(cha=='i'){
        vecto[i].push_back(s+'a');
        vecto[i].push_back(s+'b');
        vecto[i].push_back(s+'c');
        vecto[i].push_back(s+'d');
        vecto[i].push_back(s+'e');
        vecto[i].push_back(s+'f');
        vecto[i].push_back(s+'g');
        vecto[i].push_back(s+'h');
        vecto[i].push_back(s+'i');
        vecto[i].push_back(s+'j');
      }
    }
  }
  for(auto s:vecto[n-1]){
    cout<<s<<endl;
  }
}
      
      
      

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

int main() {
  int a, b;
  cin >> a >> b;
  string A, B;
  for (int i = 0; i < b; i++) {
    A += char('0' + a);
  }
  for (int i = 0; i < a; i++) {
    B += char('0' + b);
  }
  cout << ((A < B) ? A : B) << "\n";
}

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

int A[100001];

int main(void){
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    for (int i = 0; i < N; i++) {
        if (A[i] % 2) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919810893;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N;
    cin >> N;
    vector<double>t(N), v(N);
    rep(i, N)cin >> t[i];
    rep(i, N)cin >> v[i];
    ll total = 0;
    rep(i, N)total += t[i];
    vector<double>mx(2 * total + 1, INF);
    ll now = 0;
    rep(i, N){
        rep(j, t[i]){
            ll t1 = now + j * 2;
            ll t2 = now + j * 2 + 1;
            chmin(mx[t1], v[i]);
            chmin(mx[t2], v[i]);
        }
        now += t[i] * 2;
        chmin(mx[now], v[i]);
    }
    mx[0] = 0;
    mx[total * 2] = 0;

    // for(ll i = 0; i <= total * 2; i++)cout << i * 0.5 << " : " << mx[i] << endl;

    rep(i, 2 * total + 1){
        chmin(mx[i + 1], mx[i] + 0.5);
    }
    rrep(i, 2 * total + 1){
        chmin(mx[i], mx[i + 1] + 0.5);
    }
    // for(ll i = 0; i <= total * 2; i++)cout << i * 0.5 << " : " << mx[i] << endl;
    double ans = 0;
    rep(i, 2 * total + 1){
        ans += (mx[i] + mx[i + 1]) * 0.25;
    }
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 512