akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int n; cin >> n;
	int a, b; cin >> a >> b;
	int ans = 0;
	rep1(i, n) {
		string s = to_string(i);
		int sum = 0;
		rep(j, s.size()) {
			sum += s[j] - '0';
		}
		if (a <= sum && sum <= b)ans += i;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


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

typedef long long lli;
const int MAXH = 21;
const int MAXW = 21;
const lli mod = 100000LL;
const string C = "JOI";

int H, W;
char G[MAXH][MAXW];
map<int,lli> dp[2];

int main() {
  lli all = 1;
  cin >> H >> W;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> G[i][j];
      if(G[i][j] == '?') {
        all = (all * 3) % mod;
      }
    }
  }
  dp[0][0] = 1;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      bool p = (i*W+j)%2;
      dp[!p].clear();
      for(map<int,lli>::iterator it = dp[p].begin();
          it != dp[p].end(); ++it) {
        int b = it->first;
        for(int k = 0; k < 3; ++k) {
          if(G[i][j] == '?' || G[i][j] == C[k]) {
            int nb = b & ~(1<<j);
            if(C[k] == 'J') {
              nb &= ~(1<<(j-1));
              if(j+1 != W) nb |= (1<<j);
              dp[!p][nb] = (dp[!p][nb] + dp[p][b]) % mod;
            } else if(C[k] == 'O') {
              dp[!p][nb] = (dp[!p][nb] + dp[p][b]) % mod;
            } else if(C[k] == 'I') {
              if(!(b & (1<<j))) {
                nb &= ~(1<<(j-1));
                dp[!p][nb] = (dp[!p][nb] + dp[p][b]) % mod;
              }
            }
          }
        }
      }
    }
  }
  lli sum = 0;
  for(map<int,lli>::iterator it = dp[H*W%2].begin();
      it != dp[H*W%2].end(); ++it) {
    sum = (sum + it->second) % mod;
  }
  cout << (all - sum + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 2828
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 200000;

int main() {
	int N, i;
	int X[MAX], Y[MAX];
	scanf("%d", &N);
	for(i = 0; i < MAX; i++){
		X[i] = 0;
	}
	for(i = 0; i < N; i++){
		scanf("%d", &X[i]);
		Y[i] = X[i];
	}
	sort(X, X + N);
	for(i = 0; i < N; i++){
		if(Y[i] <= X[(N / 2) - 1]) printf("%d\n", X[(N / 2)]);
		else printf("%d\n", X[(N / 2) - 1]);
	}

	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int N, K;
   cin >> N >> K;
   int thre = N / 2 + N % 2;
   if (K <= thre) cout << "YES" << endl;
   else cout << "NO" << endl;
   return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	a, b, c := false, false, false
	for _, r := range S {
		switch r {
		case 'a': a = true
		case 'b': b = true
		case 'c': c = true
		}
	}

	if a && b && c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  int n,r;
  cin>>n>>r;
  if(n<10) r+=(100*(10-n));
  cout<<r<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int isprime(int n){
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0)return 0;
  }
  return 1;
}
int main(){
  int v;
  while(scanf("%d", &v) != EOF) {
    if(v == 0){
      break;
    }
    while(1){
      if(isprime(v) == 1 && isprime(v - 2) == 1){
        printf("%d %d\n", v - 2, v);
        break;
      }else{
        v--;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N;
    cin>>N;
    long long A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    long long ans=A[0];
    long long count=0;
    for(int i=1;i<N;i++){
        if(ans/1000000000*A[i]/1000000000>1){
            cout<<-1<<endl;
            return 0;
        }
        ans*=A[i];
        if(ans>1000000000000000000){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    ll cnt = 0;
    for(int i = n-1; i >= 0; i--){
        (a[i] += cnt) %= b[i];
        if(a[i] > 0)cnt += b[i] - a[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H,vector<char>(W));
    vector<vector<int>> dist(H,vector<int>(W));
    rep(i,H){
        rep(j,W){
            cin >> s.at(i).at(j);
        }
    }
    if (s.at(0).at(0)=='#') {
        dist.at(0).at(0) = 1;
    } else {
        dist.at(0).at(0) = 0;
    }
    rep(i,H){
        if(i==0) continue;
        if(s.at(i).at(0)=='#'&&s.at(i-1).at(0)=='.') {
            dist.at(i).at(0)=dist.at(i-1).at(0)+1;
        } else {
            dist.at(i).at(0)=dist.at(i-1).at(0);
        }
    }
    rep(j,W){
        if(j==0) continue;
        if(s.at(0).at(j)=='#'&&s.at(0).at(j-1)=='.') {
            dist.at(0).at(j)=dist.at(0).at(j-1)+1;
        } else {
            dist.at(0).at(j)=dist.at(0).at(j-1);
        }
    }
    rep(i,H){
        rep(j,W){
            if (i==0||j==0) {
                continue;
            }
            int celldist = 10000;
            if(s.at(i).at(j)=='#') {
                if(s.at(i-1).at(j)=='#') {
                    celldist = dist.at(i-1).at(j);
                }
                if(s.at(i).at(j-1)=='#') {
                    celldist = min(celldist,dist.at(i).at(j-1));
                }
                if(s.at(i-1).at(j)=='.') {
                    celldist = min(celldist,dist.at(i-1).at(j)+1);
                }
                if(s.at(i).at(j-1)=='.') {
                    celldist = min(celldist,dist.at(i).at(j-1)+1);
                }
            }
            if(s.at(i).at(j)=='.') {
                if(s.at(i-1).at(j)=='#') {
                    celldist = dist.at(i-1).at(j);
                }
                if(s.at(i).at(j-1)=='#') {
                    celldist = min(celldist,dist.at(i).at(j-1));
                }
                if(s.at(i-1).at(j)=='.') {
                    celldist = min(celldist,dist.at(i-1).at(j));
                }
                if(s.at(i).at(j-1)=='.') {
                    celldist = min(celldist,dist.at(i).at(j-1));
                }
            }
            dist.at(i).at(j) = celldist;
        }
    }
    cout << dist.at(H-1).at(W-1) << endl;
    // rep(i,H){
    //     rep(j,W){
    //         cout << dist.at(i).at(j);
    //     }
    //     cout << endl;
    // }
}

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

int main() { 
  int a;
  int b;
  int c;
  cin >> a >> b >> c;
  if( a < c){
    if( c < b){
      cout<< "Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
     if( c > b){
      cout<< "Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int a, b;
	cin >> a >> b;
	for (size_t i = 0; i < 100000; i++)
	{
		int x, y;
		x = i * 0.08, y = i * 0.1;
		if (x == a && y == b)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    v_int a(n), b(n);
    v_int cnt(200005);

    irep(i, n) {
        cin >> a[i];    
        b[i] = a[i];
    }
    sort(b.rbegin(), b.rend());
    int mx1 = b[0];
    int mx2 = b[1];
    
    irep(i, n) {
        if(a[i] == mx1) {
            cout << mx2 << endl;
        } else {
            cout << mx1 << endl;
        }
    }

    return 0;
} /*atcoder*/


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i=0; i<N; i++){
    cin >> H[i];
  }
  vector<vector<int>> G(N);
  for (int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    G[--a].push_back(--b);
    G[b].push_back(a);
  }
  
  int ans = 0;
  for (int i=0; i<N; i++){
    bool good = true;
    for (int n:G[i]){
      if(H[i]<=H[n]) {good = false; break;}
    }
    if(good) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8748
# -*- coding: utf-8 -*-


def main():
    """Function."""
    s = str(input())

    alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
             "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
             "w", "x", "y", "z"]
    base = set()
    for dum in alpha:
        base.add(dum)

    check = set()
    for i in range(len(s)):
        check.add(s[i])

    dum = base - check

    if dum == set():
        print("None")
    else:
        print(min(list(dum)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
from math import*
import sys
n = int(input())
listtt = []
string=input()
lastChar = string[-1]
listtt.append(string)
k=n-1
while(k) :
    k-=1
    string = input()
    if (string[0]!=lastChar):
       print("No")
       sys.exit()
    else :
       lastChar=string[-1]
       listtt.append(string)
for i in listtt :
    if listtt.count(i) > 1 :
        print ("No")
        sys.exit()
print ("Yes")


Measured memory_bytes: 3064
object Main extends App {
    val n: Int = io.StdIn.readLine().toInt
    var arr: Array[Int] = io.StdIn.readLine().split(' ').map(_.toInt)

    var count = 0
    for (i <- 0 until n - 1) {
      if (arr(i) == i + 1) {
        val temp = arr(i)
        arr(i) = arr(i + 1)
        arr(i + 1) = temp
        count = count + 1
      }
    }
    if(arr(n - 1) == n) count = count + 1
    println(count)
}


Measured memory_bytes: 40072
import sys
readline = sys.stdin.readline

R, G, B = map(int, readline().split())
K = int(readline())
ans = 'No'
for i in range(3**K):
    r, g, b = R, G, B
    for _ in range(K):
        if i%3 == 0:
            r *= 2
        elif i%3 == 1:
            g *= 2
        else:
            b *= 2
        i //= 3
    if b > g > r:
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 65392
#include<iostream>
using namespace std;
using uint = unsigned int;

int main() {
	string S;
	cin >> S;
	
	if (S == "Sunny") {
		cout << "Cloudy";
	} else if (S == "Cloudy") {
		cout << "Rainy ";
	} else {
		cout << "Sunny ";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 999999999
const int mod = 1000000007;
ll cnt = 0;
 
int main(){
 ll n;  cin >> n;
 int a[n+2],b[n];
 a[0] = 0;
 a[n+1] = 0;
 for(int i=1;i<=n;i++){
     cin >> a[i];   
 }
 ll all=0;
 for(int i=0;i<=n;i++){
     b[i] =abs( a[i+1] -a[i] );
     all+=b[i];
 }

 for(int i=1;i<=n;i++){
     cout << all - b[i-1] - b[i] + abs(a[i-1]-a[i+1]) << endl;
 }




}

Measured memory_bytes: 2048
D, G = map(int, input().split())
scores = []
for i in range(D):
    p, c = map(int, input().split())
    scores.append((p, c))

ans = 10 ** 9
for i in range(1 << D):
    score = 0
    solved = 0
    for j in range(D):
        p, c = scores[j]
        if i & (1 << j):
            solved += p
            score += p * 100 * (j + 1) + c
        else:
            k = j

    if score >= G:
        ans = min(ans, solved)
        continue

    p, c = scores[k]
    for j in range(p):
        solved += 1
        score += 100 * (k + 1)
        if score >= G:
            ans = min(ans, solved)
            break

print(ans)


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

int main(){
    int D;
    while(cin>>D,D){
        int N,M,K,S,sum=0;
        vector<int> s(1,0);
        cin>>N>>M;
        for(int i=1;i<N;i++){
            cin>>S;
            s.push_back(S);
        }
        sort(s.begin(),s.end());
        for(int i=0;i<M;i++){
            int l,r;
            cin>>K;
            vector<int>::iterator itr = lower_bound(s.begin(),s.end(),K);
            if(itr==s.begin()) l = min(s.back()-K,K+D-s.back());
            else l = K-*(itr-1);
            if(itr==s.end()) r = min(K-s.front(),s.front()+D-K);
            else r = *itr-K;
            //printf(" %d\n",min(l,r));
            sum += min(l,r);
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 1712
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n,k = map(int, input().split())

ans = k * (k-1)**(n-1)

print(ans)


Measured memory_bytes: 9096
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(int argc, const char * argv[]) {
    int array[MAX];
    int n = 0;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> array[i];
    }
    
    int m_min = array[0];
    int m_max = -2000000000;
    
    
    for (int i = 1; i < n; i++) {
        m_max = max(m_max, array[i] - m_min);
        m_min = min(m_min, array[i]);
    }
    cout << m_max << endl;
    return 0;
}



Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


#define MAX 100005
#define NIL -1

struct Node
{
	int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	int i, c;
	
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if (T[u].p == NIL) cout << "root, ";
	else if (T[u].l == NIL) cout << "leaf, ";
	else cout << "internal node, ";
	
	cout << "[";
	
	for (i=0, c=T[u].l; c!=NIL; i++, c=T[c].r)
	{
		if (i) cout << ", ";
		cout << c;
	}
	
	cout << "]" << endl;
}

int rec(int u, int p)
{
	D[u] = p;
	if (T[u].r != NIL) rec(T[u].r, p);
	if (T[u].l != NIL) rec(T[u].l, p + 1);
}


int main()
{
	int i, j, d, v, c, l, r;
	
	cin >> n;
	REP(n) T[i].p = T[i].l = T[i].r = NIL;
	
	rep(i, n)
	{
		cin >> v >> d;
		rep(j, d)
		{
			cin >> c;
			if (j == 0) T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	
	REP(n) if (T[i].p == NIL) r = i;
	
	rec(r, 0);
	
	REP(n) print(i);
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 5844
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
#define g(a,b) g[h[a]+h[(1<<n)-1^b]]
using namespace std;
int n,m,x[20][20],f[40000][20],g[15000000],h[40000];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l,u,w;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	  {
	   scanf("%d%d%d",&j,&k,&l);
	   j--;
	   k--;
	   x[j][k]=x[k][j]=l;
	  }
	for(i=0;i<(1<<n);i++)
	  h[i]=h[i>>1]*3+(i&1);
	for(i=1;i<(1<<n);i++)
	  for(j=(i-1&i);j;j=(j-1&i))
	    {
		 k=i-j;
		 for(l=0;!(k&(1<<l));l++);
		 if(k==(1<<l))
		   {
		    for(w=0,u=0;u<n;u++)
		      if(j&(1<<u))
		        w+=x[u][l];
		   }
		 else
		   w=g(j,1<<l)+g(j,k^(1<<l));
		 g(j,k)=w;
		}
	for(i=0;i<(1<<n);i++)
	  for(j=0;j<n;j++)
	    f[i][j]=1e9;
	f[1][0]=0;
	for(i=2;i<(1<<n);i++)
	  for(j=0;j<n;j++)
	    if(i&(1<<j))
	      {
	       for(k=0;k<n;k++)
	         if(i&(1<<k) && x[j][k])
	           f[i][j]=min(f[i][j],f[i^(1<<j)][k]+g(i^(1<<j)^(1<<k),1<<j));
	       for(k=(i^(1<<j));k;k=(k-1&(i^(1<<j))))
	         f[i][j]=min(f[i][j],f[i^k][j]+g(i^k^(1<<j),k));
		  }
	printf("%d\n",f[(1<<n)-1][n-1]);
	return 0;
}


Measured memory_bytes: 61696
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> a(3*N+1);
    for(int i = 1; i <= 3*N;i++) cin >> a[i];
    priority_queue<ll,vector<ll>,greater<ll>> lpq;
    priority_queue<ll> rpq;
    
    vector<ll> suml(3*N+2,0),sumr(3*N+2,0);
    for(int i = 1; i <= N;i++){
        lpq.push(a[i]); suml[i] += suml[i-1] + a[i];
    }
    for(int i = 3*N; i > 2*N;i--){
        rpq.push(a[i]); sumr[i] += sumr[i+1] + a[i];
    }
    
    for(int i  = N+1; i<= 2*N;i++){
        ll lv = lpq.top();
        if(lv < a[i]){
            suml[i] = suml[i-1] + a[i] - lv;
            lpq.pop(); lpq.push(a[i]);
        }else{
            suml[i] = suml[i-1];
        }
    }
    for(int i = 2*N; i > N;i--){
        ll rv = rpq.top();
        if(rv > a[i]){
            sumr[i] = sumr[i+1] + a[i] - rv;
            rpq.pop(); rpq.push(a[i]);
        }else{
            sumr[i] = sumr[i+1];
        }
    }
    ll res = -(LINF);
    for(int i = N; i <= 2*N;i++){
        res = max(res,suml[i] - sumr[i+1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 9588
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
   
  // static Scanner sc = new Scanner(System.in);
  
    private final static int mod = (int) (1e9 + 7);
    private final static int N = (int) (1e6);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 int W = sc.nextInt();
	 int[] wt = new int[n];
	 int[] v = new int[n];
	 for(int i=0;i<n;++i) {
		 wt[i] = sc.nextInt();
		 v[i] = sc.nextInt();
	 }
	 long[][] dp = new long[n+1][W+1];
	 for(int i=1;i<=n;++i) {
		 for(int w = 1;w<=W;++w) {
			 if(wt[i-1] <= w) {
				 dp[i][w] = Math.max(dp[i-1][w], v[i-1] + dp[i-1][w-wt[i-1]]);
			 }else dp[i][w] = dp[i-1][w];
			 
		 }
	 }
	 
	 out.print(dp[n][W]);
	 out.close();
    
	}

	
}

Measured memory_bytes: 128468
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    vector<bool> canR(N + K, false), canS(N + K, false), canP(N + K, false);
    int count = 0;
    rep(i, 0, N){
        
        if (T.at(i) == 'r'){
            if (i >= K){
                if (T.at(i - K) == 'r'){
                    if(canR.at(i)){
                        count += P;
                    }
                    else{
                        canR.at(i + K) = true;
                    }
                }
                else{
                    count += P;
                }
            }
            else{
                count += P;
            }
        }
        if (T.at(i) == 's'){
            if (i >= K){
                if (T.at(i - K) == 's'){
                    if(canS.at(i)){
                        count += R;
                    }
                    else{
                        canS.at(i + K) = true;
                    }
                }
                else{
                    count += R;
                }
            }
            else{
                count += R;
            }
        }
        if (T.at(i) == 'p'){
            if (i >= K){
                if (T.at(i - K) == 'p'){
                    if(canP.at(i)){
                        count += S;
                    }
                    else{
                        canP.at(i + K) = true;
                    }
                }
                else{
                    count += S;
                }
            }
            else{
                count += S;
            }
        }
        //cout << i + 1 << " " << count << endl;
    }
    cout << count << endl;
}

Measured memory_bytes: 512
program sample
implicit none
integer(8)X,k,i
integer(8) A,B,A1,B1
read(*,*)X
A1=0
B1=0
do A=-150,150
do B=-150,150
if (A**5-B**5==X) then
A1=A
B1=B
end if
end do
end do
write(*,*) A1,B1
stop
end program sample

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

using namespace std;

int main() {
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    map<int, int> mp;
    mp[3] = 2;
    mp[2] = 1;
    mp[1] = 0;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        set<char> st;
        st.insert(A[i]);
        st.insert(B[i]);
        st.insert(C[i]);
        ans += mp[st.size()];
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define mo 1000000007
using namespace std;
int main(){
        ll n,c;
        cin>>n>>c;
        ll weight[n+1]={0};
        ll value[n+1]={0};
        for(ll i=1; i<=n;i++){
                cin>>weight[i]>>value[i];
        }
        ll dp[n+1][c+1];
        memset(dp,0,sizeof(ll)*(n+1)*(c+1));
        for(ll i=1; i<=n;i++){
            for(ll j=1; j<=c;j++){
                dp[i][j]=dp[i-1][j];
                if((j-weight[i])>=0){
                    dp[i][j] = max(dp[i-1][j], value[i]+dp[i-1][j-weight[i]]);
                }
            }
        }
        cout<<dp[n][c]<<endl;
}


Measured memory_bytes: 79104
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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

int main(){
	init();
	ll N;cin>>N;
	ll ans=1;
	for(int i=0;i<N;i++){
		ll t;cin>>t;
		ans=lcm(ans,t);
	}
	cout<<ans<<endl;
//	cout<<gcd(1000000000000000000,2);
}


Measured memory_bytes: 256
line = gets.split(' ').map(&:to_f)

a = line[0]
b = line[1]
x = line[2]
PI = Math.atan(1) * 4

if x > (a ** 2) * b / 2 then
  tan = 2 * ((a ** 2) * b - x) / (a ** 3)
  print (Math.atan(tan) * 180 / PI)
else
  tan = a * (b ** 2) / (2 * x)
  print (Math.atan(tan) * 180 / PI)
end

Measured memory_bytes: 3836
#include <iostream>

int main()
{
  int N, a[100000], next = 1, count = 0;
  std::cin >> N;
  
  for(int i = 0; i < N; i++)
  {
    std::cin >> a[i];
  }
  
  for(int i = 0; i < N && next != 2; i++)
  {
    next = a[next - 1];
    count++;
  }

  if(next != 2)
  {
    count = -1;
  }
  
  std::cout << count;
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll n;
	string s;
	cin >> n >> s;
	if (s.size() % 2 != 0) {
		cout << "No" << endl;
		exit(0);
	}
	string a1 = s.substr(0, s.size() / 2);
	string a2 = s.substr(s.size() / 2, s.size() / 2);
	//cout << a1 << endl;
	//cout << a2 << endl;
	if (a1 == a2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using namespace std;

int main(){
  int K,X; cin >> K >> X;
  if(K*500 >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
lst = input().split(' ')
for v in lst:
  good = False
  if int(v) % 2 != 0:
    good = True
  elif int(v) % 3 != 0 and int(v) % 5 != 0:
    print('DENIED')
    break
  else:
    good = True
if good:
  print('APPROVED')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c,d;
    cin>>a>>b;
    if(a.length()+1==b.length())
    {
        c=a+b[b.length()-1];
        if(c==b)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;




}


Measured memory_bytes: 3600
#!/usr/bin/ruby
$c=0
def merge(a,left,mid,right)
	n1=mid-left
	n2=right-mid
	l=a[left,n1]
	r=a[mid,n2]
	l<<9999999999
	r<<9999999999
	i=0
	j=0
	left.step(right-1){|k|
		$c+=1
		if l[i]<=r[j]
			a[k]=l[i]
			i=i+1
		else
			a[k]=r[j]
			j=j+1
		end
	}
end

def mergesort(a,left,right)
	if left+1<right
		mid=(left+right)/2
		mergesort(a,left,mid)
		mergesort(a,mid,right)
		merge(a,left,mid,right)
	end
end

n=gets.to_i
a=gets.split.map(&:to_i)
mergesort(a,0,a.length)
puts a*' '
p $c

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

using namespace std;

typedef long long int ll;

const int mod = 1e9 + 7;

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

  int n, m;
  cin >> n >> m;
  vector < int > a (n + 1), b (m + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= m; j++) cin >> b[j];
  sort(a.begin() + 1, a.end());
  sort(b.begin() + 1, b.end());

  ll ans = 1;
  int p = n, q = m;
  for (int val = n * m, filled = 0; val > 0; val--, filled++) {
    if (a[p] == val && b[q] == val) {
      p--;
      q--;
    } else if (a[p] == val) {
      ans = (ans * (m - q)) % mod;
      p--;
    } else if (b[q] == val) {
      ans = (ans * (n - p)) % mod;
      q--;
    } else {
      ans = (ans * ((n - p) * (m - q) - filled)) % mod;
    }
  }

  cout << ans << '\n';
}


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

int main() {
  long n, ans = 0;
  string s;
  cin >> n >> s;
  for(int i = 2; i < n; i++) {
    if (s.at(i) == 'C') {
      if (s.at(i - 1) == 'B') {
        if (s.at(i - 2) == 'A') {
          ans++;
        }
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[100],b[100],c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        b[i]=a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            c++;
        }
    }
    if(c==0 || c==2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3724
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const double EPS = 1e-10;
bool equals(double a, double b) {
	return fabs(a - b) < EPS;
}
struct Point {
	double x, y;
	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point rhs) {
		return Point(x + rhs.x, y + rhs.y);
	}
	Point operator - (Point rhs) {
		return Point(x - rhs.x, y - rhs.y);
	}
	Point operator * (double k) {
		return Point(k * x, k * y);
	}
	bool operator < (const Point& rhs) const {
		return x != rhs.x ? x < rhs.x : y < rhs.y;
	}
	bool operator == (const Point& rhs) const {
		return equals(x, rhs.x) && equals(y, rhs.y);
	}
	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}
};
typedef Point Vector;
struct Segment {
	Point p1, p2;
	Segment(Point p1 = Point(), Point p2 = Point()) :p1(p1), p2(p2) {}
};
typedef Segment Line;
struct Circle {
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0) :c(c), r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}
bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0);
}
bool isOrthogonal(Segment a, Segment b) {
	return isOrthogonal(Vector(a.p2.x - a.p1.x, a.p2.y - a.p1.y), Vector(b.p2.x - b.p1.x, b.p2.y - b.p1.y));
}
bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0);
}
bool isParallel(Segment a, Segment b) {
	return isParallel(Vector(a.p2.x - a.p1.x, a.p2.y - a.p1.y), Vector(b.p2.x - b.p1.x, b.p2.y - b.p1.y));
}
Point project(Point p, Segment s) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + (base * r);
}
Point reflect(Point p, Segment s) {
	return p + (project(p, s) - p) * 2;
} 
int main() {
    int q;
	double x1, y1, x2, y2;
	scanf("%lf%lf%lf%lf%d", &x1, &y1, &x2, &y2, &q);
	Segment s = Segment(Point(x1, y1), Point(x2, y2));
	while (q--) {
		scanf("%lf%lf", &x1, &y1);
		Point ans = reflect(Point(x1, y1), s);
		printf("%.010lf %.010lf\n", ans.x, ans.y);
	}
	return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <algorithm>

using namespace std;

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

int main() {

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

    int A[N];
    REP(i, N){
        scanf("%d", &A[i]);
    }

    sort(A, A + N, greater<int>());

    int ans = 0;

    REP(i, N){
        if (i % 2 == 0) {
            ans += A[i];
        } else {
            ans -= A[i];
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






int main()
{
	int a[5];
	int b[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	sort(a, a+5);
	for (int i = 0; i < 5; i++) {
		b[i] = a[4 - i];
	}
	for (int i = 0; i < 4; i++) {
		cout << b[i] << " ";
	}
	cout << b[4] << endl;
}

Measured memory_bytes: 1176
S = list(input())
N = len(S)
S0 = S[:(N - 1) // 2]
S1 = S[(N + 1) // 2:]
if S0 == S0[::-1] and S1 == S1[::-1] and S == S[::-1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long K = sc.nextLong();
    if(K <= A) {
      System.out.print(A-K + " " + B);
    } else if (K > A && K <= A + B) {
      System.out.print(0 + " " + (B - (K - A)));
    } else if (K >= A + B) {
      System.out.print(0 + " " + 0);
    }
  }
}

Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int GCD(int m, int n)
{
	int a, b, r;
	a = (m > n) ? m : n;
	b = m + n - a;
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);

	int minNum, minIdx;
	minNum = INT_MAX;
	minIdx = 0;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		if (A[i] < minNum)
		{
			minNum = A[i];
			minIdx = i;
		}
	}

	if (N == 2)
		cout << max(A[0], A[1]) << endl;
	else
	{
		int minGCD = INT_MAX,minGCDIDX = 0;
		for (int i = 0; i < N; ++i)
		{
			int gcd = GCD(minNum, A[i]);

			if (gcd < minGCD)
			{
				minGCD = gcd;
				minGCDIDX = i;
			}
		}

		int gcd1 = A[(minIdx % 2) + 1], gcd2 = A[(minGCDIDX % 2) + 1];

		for (int i = 0; i < N; ++i)
		{
			if (i != minIdx)
				gcd1 = GCD(gcd1, A[i]);
			if (i != minGCDIDX)
				gcd2 = GCD(gcd2, A[i]);
		}
		cout << max(gcd1,gcd2) << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int N, M;
//頂点数が多すぎるので隣接行列は使えない.代わりに隣接リストを使う
//Gは1と隣接,HはNと隣接
vector<int> G, H;
int main() {
	cin >> N >> M;
	rep(i, M) {
		int s, t;
		cin >> s >> t;
		if (s == 1) G.push_back(t);
		if (t == 1) G.push_back(s);
		if (s == N) H.push_back(t);
		if (t == N) H.push_back(s);
	}
	sort(G.begin(), G.end());
	sort(H.begin(), H.end());
	//1とN以外の点を経由してNに着けるかをチェック
	bool vis = false;
	for (int v = 2;v <= N - 1;v++) {
			bool st = false, ed = false;
			if (binary_search(G.begin(), G.end(), v))st = true;
			if (binary_search(H.begin(), H.end(), v))ed = true;
			if (st&&ed) vis = true;
	}
	if (vis) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 1276
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N;

int main(){
  cin >> N;

  ll ans = 0;
  for(ll i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      ll m = N / i - 1;
      if(m != 0 && N / m == i) {
        ans += m;
      }
    }
  }

  cout << ans << endl;


  return 0;
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#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++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

V<ll> divisor(ll n){
    V<ll> ret;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}

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

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    ll  A,B;
    int ans=0;
    cin>>A>>B;
    ll gcd_ab=gcd(A,B);
    V<ll> ab=divisor(gcd_ab);
    sort(All(ab));
    REP(i,ab.size()){
        //cout<<ab[i]<<" ";
        if(ab[i]==1)ans++;
        if(IsPrime(ab[i])){
            ans++;//cout<<"1"<<endl;
        }//else cout<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

class Point {
public:
	double x;
	double y;
};

Point pointStack[101];
const double esp = 1e-10;

bool cmpPoint(Point p1, Point p2) {
	if (fabs(p1.y-p2.y) > esp) {
		return p1.y < p2.y;
	}
	else {
		return p1.x < p2.x;
	}
}

bool cmpAngle(Point p1, Point p2) {
	double k1, k2;

	k1 = atan2(p1.y - pointStack[0].y, p1.x - pointStack[0].x);
	k2 = atan2(p2.y - pointStack[0].y, p2.x - pointStack[0].x);
	if (fabs(k1-k2) > esp) {
		return k1 < k2;
	}
	else {
		if (p1.x > 0 || p2.x > 0) {
			return p1.x < p2.x;
		}
		return p1.x > p2.x;
	}
}

double Cross(Point p0, Point p1, Point p2) {
	double result;

	result = (p2.x - p0.x) * (p1.y - p0.y) - (p1.x - p0.x) * (p2.y - p0.y);
	if (fabs(result) < esp) {
		return 0;
	}
	else if (result > esp) {
		return 1;
	}
	else {
		return -1;
	}
}

int main(void) {
	int n, i, top;
	Point pointSet[101];
	char c;

	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}

		memset(pointSet, 0, sizeof(pointSet));
		memset(pointStack, 0, sizeof(pointStack));	
		for (i = 0; i < n; i++) {
			cin >> pointSet[i].x >> c >> pointSet[i].y;
		}

		sort(pointSet, pointSet + n, cmpPoint);
		pointStack[0] = pointSet[0];

		sort(pointSet + 1, pointSet + n, cmpAngle);
		pointStack[1] = pointSet[1];
		pointStack[2] = pointSet[2];
		pointSet[n] = pointSet[0];

		top = 2;
		for (i = 3; i <= n; i++) {
			while (top > 1 && (Cross(pointStack[top - 1], pointStack[top], pointSet[i]) >= 0)) {
				top--;
			}
			pointStack[++top] = pointSet[i];
		}

		cout <<n - top << endl;
	}


	return 0;
}




Measured memory_bytes: 3476
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,BY[MAX][MAX];
int color[MAX],discover[MAX],finish[MAX],time;

void dfs_visit(int);
void dfs();

int main(){
    int i,j,u,k,v;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++) BY[i][j]=0;
    }
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        u--;
        for(j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            BY[u][v]=1;
        }
    }
    dfs();

    return 0;
}

void dfs_visit(int u){
    int i;
    color[u]=GRAY;
    discover[u]=++time;
    for(i=0;i<n;i++){
        if(BY[u][i]==0) continue;
        if(color[i]==WHITE) dfs_visit(i);
    }
    color[u]=BLACK;
    finish[u]=++time;
}
void dfs(){
    int i;
    for(i=0;i<n;i++) color[i]=WHITE;
    time=0;

    for(i=0;i<n;i++){
        if(color[i]==WHITE) dfs_visit(i);
    }
    for(i=0;i<n;i++){
        printf("%d %d %d\n",i+1,discover[i],finish[i]);
    }
}



Measured memory_bytes: 2052
import sys
x,y=map(int, input().split())
if x==2 or y==2:
  print('No')
  sys.exit()

a=[4,6,9,11]
if (x in a) and (y in a):
  print('Yes')
elif (x not in a) and (y not in a):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
class Unionfind:
    def __init__(self, n):
        self.d = []
        for _ in range(n):
            self.d.append(-1)
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] = self.d[x] + self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.d[self.find(x)]

n, m, k = map(int, input().split())
dame = [set() for _ in range(n)]
uf = Unionfind(n)

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    dame[a].add(b)
    dame[b].add(a)
    uf.unite(a, b)

for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if not uf.same(c, d):
        continue
    dame[c].add(d)
    dame[d].add(c)

for i in range(n):
    mem = uf.size(i) - 1
    mem -= len(dame[i])
    print(mem, end= " ")
print()


Measured memory_bytes: 62180
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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 argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, k;
  cin >> n >> k;
  // ll n, m, k;
  // cin >> n >> m >> k;
  
  ans = min(n, n % k);
  ans = min(ans, abs(ans - k));

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



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0,cnt=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='g'){
            if(!cnt)++cnt;
            else{
                cnt--;
                ans++;
            }
        }else{
            if(!cnt){
                cnt++;
                ans--;
            }else cnt--;

        }
    }cout<<ans<<'\n';


return 0;}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);
    int num = 1;
    
    while(n){
        if(num * 2 > num + k){
            break;
        }
        num *= 2;
        n--;
    }
    
    while(n){
        num+=k;
        n--;
    }
    
    printf("%d\n", num);
    
    return 0;
}


Measured memory_bytes: 1728