akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
vector<ii> a;
int n ,m;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 0 ; i < m ; ++i){
        int u , v;cin >> u >> v;
        a.pb(mp(u,v));
    }
    for(int i = 0 ; i <= 10000 ; ++i){
        string s = to_string(i);
        if((int)s.size() != n)continue;
        bool ok = 1;
        for(auto c : a){
            if(s[c.first - 1] != '0' + c.second)ok = 0;
        }
        if(ok == 0)continue;
        return cout << i , 0;
    }
    cout << -1;
}


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

int main(void){
  ll N,A,B;
  cin >> N >> A >> B;
  if(A > B){
    cout << 0 << endl;
    return(0);
  }
  if(N == 1 && A != B){
    cout << 0 << endl;
    return(0);
  }
  if(N == 1 && A == B){
    cout << 1 << endl;
    return(0);
  }
  if(N == 2){
    cout << 1 << endl;
    return(0);
  }
  
  cout << (N-2)*(B-A)+1 << endl;
  return(0);
}

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

using namespace std;
typedef long long lint;


int main()
{
    int a, b, c;
    int v[99];
    cin >> v[1] >> v[2] >> v[3];
    sort(v+1, v+3+1);
    cout << v[3] * 10 + v[2] + v[1];


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    // 1からはじまる配列なので、全部1にする
    // 1要素かぶらせる形でk個分の区間でnを埋めてく
    // 配列aに関係なく、kの区間の数が答え
    // a / b の切り上げは、(a + (b - 1)) / b
    // 既に1が一個あるのでa = n - 1。重ねる分b = k - 1。
    int ans = (n - 1 + k - 2) / (k - 1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3824
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>
 
#define F1(x,y,z) for(int x=(y);x<(z);x++)
#define F2(x,y,z) for(int x=(y);x<=(z);x++)
#define F3(x,y,z) for(int x=(y);x>(z);x--)
#define F4(x,y,z) for(int x=(y);x>=(z);x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second
 
#define MAX 100005
#define AMAX 1025*1005
#define MOD 1000000007
 
#define f(c,d) ((1<<(c))*(d))
 
using namespace std;
 
LL n,x[MAX],s,ta,tb,tc;
 
int main(){
	scanf("%lld",&n);
	F1(a,0,n){
		scanf("%lld",x+a);
		s+=x[a];
	}
	ta=n*(n+1)/2;
	if(n==1)printf("YES\n");
	else if(s%ta)printf("NO\n");
	else{
		ta=s/ta;
		F1(a,0,n){
			tb=ta-(x[(a+1)%n]-x[a]);
			if(tb%n||tb<0)tc=LLONG_MIN;
			else tc+=tb/n;			
		}
		if(tc==ta)printf("YES\n");
		else printf("NO\n");
	}
	#ifdef LOCAL_PROJECT
	system("pause");
	#endif
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

pair<ll, ll> calc(ll d, ll c) {

	if (d == 0) return make_pair(c - 1, 0);

	pair<ll, ll> res = make_pair(0,0);
	
	ll tmp = 0;
	rep(i, c) {
		tmp = tmp * 10 + d;
		if (tmp > 9) {
			res.first++;
			tmp = tmp / 10 + tmp % 10;
		}
		if (tmp > 9) {
			res.first++;
			tmp = tmp / 10 + tmp % 10;
		}
	}
	res.second = tmp;

	return res;
}

void solve() {

	ll M;
	cin >> M;
	vector<pair<ll, ll>> vec;
	rep(i, M) {
		ll d, c;
		cin >> d >> c;
		vec.emplace_back(make_pair(d, c));
	}

	ll ans = 0;
	
	rep(i, M) {
		ll round = vec[i].second /9;
		if (vec[i].second %9 == 0) {
			round--;
		}
		ans += round * (vec[i].first + 9);
		ll ama = vec[i].second - round * 9;
		
		pair<ll, ll> res = calc(vec[i].first, ama);
		vec[i].first = res.second;
		ans += res.first;
	}
	
	//cout << ans << endl;

	ll tmp = 0;
	rep(i, M) {
		tmp = tmp*10 + vec[i].first;
		if (tmp > 9) {
			ans++;
			tmp = tmp / 10 + tmp % 10;
		}
		if (tmp > 9) {
			ans++;
			tmp = tmp / 10 + tmp % 10;
		}
	}
	/*
	rep(i, M) {
		cout << vec[i].first;
		//cout << ":";
		cout << vec[i].second;
		cout << endl;
	}
	*/
	cout << ans;
	
}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
// *start on @date: 2020-02-16 20:29 
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
const int inf  = 0x3f3f3f3f;



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

    int n;
    cin>>n;
    int f = 1;
    while (n--)
    {
        int tmp;
        
        cin>>tmp;
        if(tmp % 2== 0){
            if(!(tmp %5 == 0 || tmp %3 == 0)){
                f = 0;
            }
        }
    }
    if(f){
        cout<<"APPROVED"<<endl;
    }else
    {
        cout<<"DENIED"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) rep2(i,0,n)

using namespace std;
bool isPossible(int t, int x,int y){
    if(abs(x)+abs(y)<=t&&(x+y-t)%2==0) return 0;
    return 1;
}

main(){
    int n;
    cin>>n;
    int tt=0,xx=0,yy=0;
    rep(i,n){
        int t,x,y;
        scanf("%d %d %d",&t,&x,&y);
        if(isPossible((t-tt),(x-xx),(y-yy))){
            cout<<"No";
            return 0;
        }
        xx=x; yy=y; tt=t;
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

const ll mod=1e9+7;
const ll min_max = 1e12;

ll gcd(ll a, ll b){
    ll r;
    while((r =a%b)){
        a = b;
        b = r;
    }
    return b;
}

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

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

    // 素数である
    return true;
}


//単純な素数か素数じゃないかの問題ではない。
int main(){

  ll A;
  cin >> A;

  ll first = 1;
  ll second = 1;
  ll min = min_max + 1;

  if( A <= 1e6){
    for(int i = 1; i <= A ; i++ ){
      if(A % i == 0){
        if ( i + A / i <= min ){
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  }else {
    for(int i = 1; i < A / 100000 ; i++ ){
      if(A % i == 0){
        if ( i + A / i <= min ){
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  }

  ll ans = 0;

  if( first == 1 || second == 1 ){
    cout << A - 1 << endl;
  }else {
    cout << min - 2 << endl;
  }

  return 0;

}

Measured memory_bytes: 256
/* Author darklight13 -_- 
   IIT Patna 
*/
#define _CRT_SECURE_NO_DEPRECATE
#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;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;

int32_t main()
{
	SYNC
	int n,k; cin >> n >> k;
	vi dp(k+1,0);
	dp[0] = 0;
	vi v(n);
	for(int &x : v)	{
		cin >> x;
		dp[x] = 1;
	}
	for(int i = 1; i <= k; i++) {
		bool to_lose = false;
		for(auto x : v) {
			if(i - x < 0)	break;
			if(!dp[i-x])	to_lose = true;	
		}
		if(to_lose)	dp[i] = 1;
	}
	if(dp[k])	cout << "First";
	else		cout << "Second";
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define fo(x,a,b) for(register int x=a;x<=b;x++)
#define dfo(x,a,b) for(register int x=a;x>b;x--)
int min(int x,int y)
{
	return(x>y?y:x);
}
//using namespace std;
int n,a[1000001],ans;
int main ()
{	
	
	int k=0;
	fo(i,2,999999)
	{
		k++;
		a[k]=i;
		fo(j,2,sqrt(i))
		{
			if (i%j==0) {a[k--]=0;break;}
		}
		
	}
	scanf("%d",&n);
	printf("%d: ",n);
	fo(i,1,k)
	{
		while (n%a[i]==0)
		{
			if (n/a[i]>1) printf("%d ",a[i]);
			else printf("%d\n",a[i]);
			n/=a[i];
		}
	}
	if (n>1) printf("%d\n",n);
	
	return 0;
}




Measured memory_bytes: 3540
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	ll cnt = 0 ;
	bool ok = false ;
	for(int i=0;i<n;i++){
		ll a,b ;
		cin >> a >> b ;
		if(a==b) cnt++ ;
		else cnt = 0 ;
		ok |= (cnt>=3) ;
	}
	cout << (ok?"Yes":"No") << endl ;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    int total = 0;
    int sum = 0;

    for (int i = 0; i <= n; i++) {
      String k = String.valueOf(i);
      for (int j = 0; j < k.length(); j++) {
        String x = String.valueOf(k.charAt(j));
        int y = Integer.parseInt(x);
        total += y;
      }
      if (total >= a && total <= b) {
        sum += i;
      }
      total = 0;
    }

    System.out.println(sum);

  }

}


Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  ll A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  bool ok = false;
  rep(m, N) {
    if(C*(N-1-m)-D*m <= B-A && B-A <= -C*m+(N-1-m)*D) ok = true;
  }
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}


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

typedef long long STATES;

int main( void )
{
	STATES free_days[31], dp[51], goal_state, next;
	register int i, j;
	int n, answer, free_day, k;

	while ( scanf( "%d", &n ) == 1 && n )
	{
		memset( free_days, 0, sizeof(free_days) );
		memset( dp, 0, sizeof(dp) );

		goal_state = 0;
		for ( i = 0; i < n; i++ ) goal_state |= 1LL << i;

		for ( i = 0; i < n; i++ )
		{
			scanf( "%d", &k );
			for ( j = 0; j < k; j++ )
			{
				scanf( "%d", &free_day );
				free_days[free_day] |= 1LL << i;
			}
		}

		answer = -1;
		for ( i = 0; i < n; i++ ) dp[i] = 1LL << i;
		for ( i = 1; i <= 30; i++ )
		{
			next = 0;
			for ( j = 0; j < n; j++ ) if ( free_days[i] & 1LL << j ) next |= dp[j];
			if ( next == goal_state )
			{
				answer = i;
				break;
			}
			for ( j = 0; j < n; j++ ) if ( free_days[i] & 1LL << j ) dp[j] |= next;
		}

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

	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
#define pii pair<int,int>
using namespace std;



int main() {

	int n;

	cin >> n;
	cout << 48-n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

int N, A[1 << 18], B[1 << 18], C[1 << 18], cnt[1 << 18];
set<int> Set;
pair<int, int> v = make_pair(-1, -1);
RangeMin<long long> X;

void sousa(int pos, int val) {
	B[pos] = val;
	cnt[A[val]]--;
	X.update(A[val], -(1000000LL * cnt[A[val]] + 1LL * A[val]));
	Set.erase(val);
}

void sousa_reverse(int pos, int val) {
	B[pos] = 0;
	cnt[A[val]]++;
	X.update(A[val], -(1000000LL * cnt[A[val]] + 1LL * A[val]));
	Set.insert(val);
}

bool dfs(int pos) {
	if (pos == N + 1) {
		return true;
	}

	if (pos < N - 2) {
		long long V = X.query(1, N + 1); V *= -1;
		long long VA = V / 1000000, VB = V % 1000000;
		if (VA == (N - pos)) {
			sousa(pos, VB);
			bool I = dfs(pos + 1);
			if (I == true) return true;
			sousa_reverse(pos, VB);
			return false;
		}
	}

	int v = 0;
	while (true) {
		auto itr = Set.lower_bound(v);
		if (itr == Set.end()) break;
		if ((*itr) == A[B[pos - 1]]) {
			v = (*itr) + 1;
			continue;
		}

		int val = (*itr);

		v = val + 1;
		sousa(pos, val);
		bool I = dfs(pos + 1);
		if (I == true) return true;
		sousa_reverse(pos, val);
	}
	return false;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; cnt[A[i]]++; }
	for (int i = 1; i <= N; i++) Set.insert(i);
	X = RangeMin<long long>(N + 2);
	for (int i = 1; i <= N; i++) X.update(i, -(1000000LL * cnt[i] + 1LL * i));

	dfs(1);
	if (B[1] >= 1) {
		for (int i = 1; i <= N; i++) {
			if (i >= 2) cout << " ";
			cout << B[i];
		}
		cout << endl;
	}
	else {
		cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 2e5+10;

int A, B;

void solve()
{
	if(B==1) cout << 0 << endl;
	else{
		int has = A, ans = 1;
		while(has < B){
			has += A-1;
			ans++;
		}
		cout << ans << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> A >> B;
	solve();
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	ll n;
	cin>>n;
	string str;
	cin>>str;
	VL sr(n+1,0),sb(n+1,0),sg(n+1,0);
	fr(i,0,n)
	{
		if(str[i]=='R')
		{
			sr[i+1]=1;
		}
		else if(str[i]=='B')
		{
			sb[i+1]=1;
		}
		else
		{
			sg[i+1]=1;
		}
	}
	fr(i,1,n+1)
	{
		sb[i]+=sb[i-1];
		sg[i]+=sg[i-1];
		sr[i]+=sr[i-1];
	}
	ll ans=0;
	fr(i,0,n)
	{
		ll ct=0,tmp=0;
		fr(j,1,n+1)
		{
			ll x=i-j;
			ll y=i+j;
			if(x<0||y>=n)
			{
				break;
			}
			else
			{
				if(str[i]!=str[x]&&str[i]!=str[y]&&str[x]!=str[y])
				{
					ct++;
				}
			}
		}
		if(str[i]=='R')
		{
			ll x=sb[i+1];
			ll y=sg[n]-sg[i+1];
			tmp+=(x*y);
			x=sg[i+1];
			y=sb[n]-sb[i+1];
			tmp+=(x*y);
			tmp-=ct;
			ans+=tmp;
		}
		else if(str[i]=='B')
		{
			ll x=sr[i+1];
			ll y=sg[n]-sg[i+1];
			tmp+=(x*y);
			x=sg[i+1];
			y=sr[n]-sr[i+1];
			tmp+=(x*y);
			tmp-=ct;
			ans+=tmp;
		}
		else
		{
			ll x=sr[i+1];
			ll y=sb[n]-sb[i+1];
			tmp+=(x*y);
			x=sb[i+1];
			y=sr[n]-sr[i+1];
			tmp+=(x*y);
			tmp-=ct;
			ans+=tmp;
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 3756
// Date: 2020-04-04

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL f[N][10];
int main() {
    rep(i, 0, 9) f[1][i] = 1;
    rep(i, 2, N-1) rep(j, 0, 9) {
        if(j) f[i][j] += f[i-1][j-1];
        if(j < 9) f[i][j] += f[i-1][j+1];
        f[i][j] += f[i-1][j];
    }
    int x = 1, y = 1;
    LL k; cin >> k;
    while(1) {
        if(k > f[x][y]) {
            k -= f[x][y];
            if(y < 9) y++;
            else x++, y = 1;
        } else break;
    }
    string ans;
    while(1) {
        ans += (char)(y+'0');
        if(y && k <= f[x-1][y-1]) {
            x = x-1, y = y-1;
        } else {
            if(y) k -= f[x-1][y-1];
            if(k <= f[x-1][y]) {
                x = x-1, y = y;
            } else {
                k -= f[x-1][y];
                x = x-1, y = y+1;
            }
        }
        if(x <= 0 || k <= 0) break;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 8064
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

//func readLine(reader *bufio.Reader) string {
//	str, _, err := reader.ReadLine()
//	if err == io.EOF {
//		return ""
//	}
//	return string(str)
//}
func readLine() []string {
	reader := bufio.NewReaderSize(os.Stdin, 1)
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return []string{}
	}
	return strings.Split(string(str), " ")
}

func round(f float64) float64 {
	return math.Floor(f + .5)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	defer out.Flush()
	sc.Split(bufio.ScanWords)
	s := strings.Split(next(), "")
	t := strings.Split(next(), "")
	res := "No"
	if len(s)+1 != len(t) {
		fmt.Fprintln(out, res)
		return
	}
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			fmt.Fprintln(out, res)
			return
		}
	}
	res = "Yes"
	fmt.Fprintln(out, res)
}


Measured memory_bytes: 1760
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    if B%A==0:
        print(A+B)
    else:
        print(B-A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef  long long int  ll;
typedef long double ld;
/*
cin>>str;
getline(cin,str);
*/
/*
ifstream f("data.in");
ofstream g("data.out");
*/


///*******Define******///
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mid(s,e)   (s+(e-s)/2)
///******************///

///******Constants****///
const long long mod = 1e9+7;
const long long MODP = 998244353;
const long long mini = INT_MIN;
const long long maxi = 0x3f3f3f3f;
///********************///

///*****Utility*******///
inline ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
inline ll power(ll a, ll n, ll mod){ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
inline ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
inline ll lcm(ll a,ll b) { return ((a*b)/gcd(a,b)); }
inline ll modinverse(ll a,ll m) { ll m0 = m;ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t;t = y; y = x - q * y; x = t; }if (x < 0) x += m0; return x; }
///*******************///

///*******************///
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>PBDS;
#define p(i,n,vect) for(ll i=0;i<(ll)n;++i) {cout<<vect[i]<<" ";} cout<<"\n";
///******************///

///******Variable Declarations***///
ll D,N;
///******************************///

void solve()
{
    cin>>N>>D;
    ll cnt=0;
    while (N--)
    {
        ll X,Y;
        cin>>X>>Y;
        ll multi = X*X + Y*Y;
        if(  ceil(sqrt(multi*1.0)) <= D )
        {
            cnt++;
        }
    }
        cout<<cnt<<"\n";
    
}

signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   
    solve();
}
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*****END*****<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/

Measured memory_bytes: 3628
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){

  long long int N;
  std::string S;
  scanf("%lld", &N);
  std::cin >> S;

  long long int ans = 0;

  for(long long int i = 0; i < N-2; i++){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
      ans++;
    }
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
  
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int N;
    cin >> N;
    vector<int> C(N,0);
    vector<int> S(N,0);
    vector<int> F(N,1);
    for(int i=0;i<N-1;i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i=0;i<N-1;i++){
        int x=0;
        for(int j=i;j<N;j++){
            if(x<S[j]){
                x=S[j];
            }
            else if(x%F[j]!=0){
                x+=F[j]-x%F[j];
            }
            x+=C[j];
        }
        cout << x << endl;
    }
    cout << 0 << endl;
    return 0;
}



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

bool isOK(int index,int ch,vector<int> &vec){
  return (vec[index] >= ch); 
}

void nibutan(int ch ,vector<int> &vec){
  int ok=-1, ng=vec.size();
  while(ng-ok>1){
    int middle = (ok+ng)/2;
    if(isOK(middle,ch,vec)) ok=middle;
    else ng=middle;
  }
  vec.insert(vec.begin()+ng,ch);
  vec.pop_back();
  return;
}

int main(){
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<int> p(a),q(b),r(c);
  rep(i,a) cin>>p[i];
  rep(i,b) cin>>q[i];
  rep(i,c) cin>>r[i];
  sort(p.begin(),p.end(),greater<int>());
  sort(q.begin(),q.end(),greater<int>());
  sort(r.begin(),r.end(),greater<int>());
  p.erase(p.begin()+x,p.end());
  q.erase(q.begin()+y,q.end());
  for(auto d : r){
    if(d<=p[x-1] && d<=q[y-1]) break;
    if(p[x-1]<q[y-1]) nibutan(d,p);
    else nibutan(d,q);
  }
  ll ans=0;
  rep(i,x) ans+=p[i];
  rep(i,y) ans+=q[i];
  cout<<ans<<endl;
}



Measured memory_bytes: 4520
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    vector<int> s(n), t(m);
    for(int i=0; i<n; i++) cin>>s[i];
    for(int i=0; i<m; i++) cin>>t[i];

    vector<vector<ll>> dp(n+1, vector<ll>(m+1, 0));
    vector<vector<ll>> sum(n+1, vector<ll>(m+1, 0));

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = sum[i][j] + 1;
                dp[i+1][j+1] %= MOD;
            }
            
            sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1] + MOD;
            sum[i+1][j+1] %= MOD;
        }
    }

    ll ans = (sum[n][m] + 1) % MOD;

    cout << ans << endl;

    return 0;
}

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

int main() {
    long long h, w;
    cin >> h >> w;

    long long ans = 1LL<<60;
    for (long long i = 1; i <= h - 1; i++) {
        long long sa = w * i;
        long long sb = w % 2 == 0 ? (h - i) * (w / 2) : (h - i) * (w / 2 + 1);
        long long sc = (h - i) * (w / 2);
        long long s_mx = max({sa, sb, sc});
        long long s_mn = min({sa, sb, sc});
        ans = min(ans, s_mx - s_mn);

        sb = (h - i) % 2 == 0 ? ((h - i) / 2) * w : ((h - i) / 2 + 1) * w;
        sc = ((h - i) / 2) * w;
        s_mx = max({sa, sb, sc});
        s_mn = min({sa, sb, sc});
        ans = min(ans, s_mx - s_mn);
    }

    for (long long i = 1; i <= w - 1; i++) {
        long long sa = h * i;
        long long sb = h % 2 == 0 ? (w - i) * (h / 2) : (w - i) * (h / 2 + 1);
        long long sc = (w - i) * (h / 2);
        long long s_mx = max({sa, sb, sc});
        long long s_mn = min({sa, sb, sc});
        ans = min(ans, s_mx - s_mn);

        sb = (w - i) % 2 == 0 ? ((w - i) / 2) * h : ((w - i) / 2 + 1) * h;
        sc = ((w - i) / 2) * h;
        s_mx = max({sa, sb, sc});
        s_mn = min({sa, sb, sc});
        ans = min(ans, s_mx - s_mn);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

int n, q;
ll S[10000];
ll T[500];

int main() {
    // S: not always different
    cin >> n;

    // Sort and remove the same integer
    ll num = 0;
    rep(i, n) {
        ll x;
        cin >> x;

        // Skip if the same integer exists
        bool same = false;
        int insert = 0;
        rep(j, num) {
            if (x > S[j]) insert = j+1;
            if (x == S[j]) {same = true; break;}
        }
        if (same) continue;

        // Sort
        rreps(j, insert+1, num+1) {
            S[j] = S[j-1];
        }
        S[insert] = x;
        num++;
    }
    // T: different
    cin >> q;
    rep(i, q) cin >> T[i];

    ll cnt = 0;
    rep(i, q) {
        rep(j, num) {
            if (T[i] == S[j]) {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
	int num,i,size,len;
	double data[100];
	char str[128];

	while(gets(str) != NULL){
		i = 0;
		size = -1;
		memset(data,0,sizeof(data));
		len = strlen(str);
		while(i <= len){
			if(isdigit(str[i])){
				num = 0;
				while(isdigit(str[i])){
					num *= 10;
					num += str[i]-'0';
					i++;
				}
				size++;
				data[size] = num*1.0;
			}else if(str[i] == '+'){
				data[size-1] += data[size];
				data[size] = 0.0;
				size--;
			}else if(str[i] == '-'){
				if(i+1 <= len && isdigit(str[i+1])){
					i++;
					num = 0;
					while(isdigit(str[i])){
						num *= 10;
						num += str[i]-'0';
						i++;
					}
					size++;
					data[size] = num*(-1.0);
				}else{
					data[size-1] -= data[size];
					data[size] = 0.0;
					size--;
				}
			}else if(str[i] == '*'){
				data[size-1] *= data[size];
				data[size] = 0.0;
				size--;
			}else if(str[i] == '/'){
				data[size-1] /= data[size];
				data[size] = 0.0;
				size--;
			}
			i++;
		}
		printf("%f\n",data[0]);
	}

	return 0;
}

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

int main(){
  int N;cin>>N;
  int d[N+10];
  REP(i,N)cin>>d[i];
  sort(d,d+N,std::greater<int>());
  int cnt=1;
  for(int i=1;i<N;i++){
    if(d[i]!=d[i-1]){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

vector<vector<int>> g;
vector<int> tin, st, avail, cycle;

void dfs(int v) {
  if (!cycle.empty()) return;
  if (!avail[v]) return;
  tin[v] = st.size();
  st.push_back(v);
  for (int u : g[v]) {
    if (tin[u] == -1) {
      dfs(u);
    } else if (tin[u] < tin[v] && cycle.empty()) {
      for (int i = tin[u]; i < st.size(); ++i) {
        cycle.push_back(st[i]);
      }
    }
  }
  tin[v] = g.size() + 1;
  st.pop_back();
}

void solve(std::istream &in, std::ostream &out) {
  int n, m;
  in >> n >> m;
  g.resize(n);
  tin.assign(n, -1);
  st.reserve(n);
  avail.assign(n, 1);
  for (int i = 0, u, v; i < m; ++i) {
    in >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
  }
  for (int i = 0; i < n; ++i) {
    if (cycle.empty() && tin[i] == -1) {
      st.clear();
      dfs(i);
    }
  }
  if (cycle.empty()) {
    out << -1 << '\n';
    return;
  }



  while (true) {
    fill(avail.begin(), avail.end(), 0);
    for (int u : cycle) {
      avail[u] = 1;
    }
    int st = -1, ed = -1;
    for (int i = 0; i < cycle.size(); ++i) {
      int u = cycle[i];
      int j = cycle[(i + 1) % cycle.size()];
      for (int v : g[u]) {
        if (avail[v] && v != j) {
          st = v;
          ed = u;
        }
      }
    }
    if (st < 0) break;
    int i = 0;
    for (; cycle[i] != st; ++i);
    vector<int> tmp;
    for (; cycle[i % cycle.size()] != ed; ++i) {
      tmp.push_back(cycle[i % cycle.size()]);
    }
    tmp.push_back(ed);
    cycle = tmp;
  }
  vector<int> id(n), od(n);
  for (int u : cycle) {
    assert(avail[u]);
    for (int v : g[u]) {
      if (avail[v]) {
        od[u]++;
        id[v]++;
      }
    }
  }
  out << cycle.size() << '\n';
  for (int u : cycle) {
//    assert(id[u] == 1 && od[u] == 1);
    out << u + 1  << '\n';
  }
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	counter := make(map[int]int)
	for _, a := range as {
		counter[a]++
	}
	if l := len(counter); k >= l {
		fmt.Println(0)
	} else {
		num_changes := l - k
		nums := make([]int, 0)
		for _, v := range counter {
			nums = append(nums, v)
		}
		sort.Ints(nums)
		sum := 0
		for i := 0; i < num_changes; i++ {
			sum += nums[i]
		}
		fmt.Println(sum)
	}
}


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

using namespace std;

const int MAXN = 105 , MAXW = 1e5 + 5 ;
int n , w ;
long long sz[MAXN] , val[MAXN] ;
long long dp[MAXN][MAXW] ;

long long solve(int idx , int rem)
{
    if(idx == n)
        return 0 ;
    if(dp[idx][rem] != -1)
        return dp[idx][rem] ;
    dp[idx][rem] = solve(idx+1 , rem) ;
    if(rem >= sz[idx])
        dp[idx][rem] = max(dp[idx][rem] , solve(idx+1 , rem - sz[idx]) + val[idx]) ;
    return dp[idx][rem] ;
}

int main()
{
    memset(dp , -1 , sizeof(dp)) ;
    cin>>n>>w ;
    for(int i = 0 ; i < n ; ++i)
        cin>>sz[i]>>val[i] ;
    cout<<solve(0 , w) ;
    return 0 ;
}


Measured memory_bytes: 82304
using System;
using static System.Console;
using System.Collections.Generic;
using System.Collections;

namespace Grobal
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(ReadLine());
			bool b = false;
			for(int i = 1;i < 10;i++)
			{
				for(int j = i;j < 10;j++)
				{
					if (i * j == n) b = true;
				}
			}
			if (b) WriteLine("Yes");
			else WriteLine("No");
		}
    }
}

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

m = max(d/a, d/b, d/c)
m = int(m+1)
ans = 0
for i in range(m):
    for j in range(m):
        if((d - (i * a + j * b)) % c == 0 and i*a+j*b<=d):
            ans+=1
print(ans)

Measured memory_bytes: 41068
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

vector<long long> a;
vector<long long> b;

long long cnt = 0;

//最大公約数
long long gcd(long long x, long long y) {
	if (y) {
		cnt++;
		a.push_back(y);
		b.push_back(x / y);
		return gcd(y, x%y);
	}
	else {
		return x;
	}
}

int main() {
	long long N, K; cin >> N >> K;
	K = max(N - K, K);
	gcd(N, K);
	long long ans;
	if (cnt == 1) {
		ans = a[0] * 3;
	}
	else if (cnt == 2) {
		ans = 1 * a[0];
		ans += (2 * b[1])*a[1];
	}
	else {
		ans = 1 * a[0];
		ans += (2 * b[1] + 1)*a[1];
		for (long long i = 2; i < a.size() - 1; i++) {
			ans += 2 * b[i] * a[i];
			//dump(ans);
		}
		ans += (2 * b[a.size() - 1] - 1)*a[a.size() - 1];
		//dumpc(a);
		//dumpc(b);
	}
	//cout << cnt << endl;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Array.Sort(a);
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] % 2 == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
            }
            Console.WriteLine(a[0] * a[1]);
        }
    }
}


Measured memory_bytes: 3288
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}


/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

ll num_of_divisors(ll n)
{
	unordered_set<ll> st;
	for(ll i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			st.insert(i);
			st.insert(n/i);
		}
	}
	return st.size();
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll n;
	cin>>n;
	ll ans=0;
	f(i,1,n)
	{
		for(ll j=1;i*j<n;j++)
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


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


int main(){
  long long n,i,pid,qid,j;
  cin >> n;
  vector<long long> p(n),q(n);
  for(i=0;i<n;++i){
    cin >> p[i];
  }
  for(i=0;i<n;++i){
    cin >> q[i];
  }
  long long kai=1;
  for(i=1;i<=n;++i){
    kai=kai*i;
  }
  kai=kai/n;
  pid=kai*(p[0]-1);
  qid=kai*(q[0]-1);
  int ni=n;
  for(i=1;i<n;++i){
    long long nup=1;
    long long nuq=1;
    for(j=i+1;j<n;++j){
      if(p[i]>p[j]){
        nup++;
      }
      if(q[i]>q[j]){
        nuq++;
      }
    }
    ni=ni-1;
    kai=kai/ni;
    pid+=kai*(nup-1);
    qid+=kai*(nuq-1);

  }
  long long ans=abs(pid-qid);
  cout << ans << endl;
  return 0;


}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))

d = defaultdict(int)
for i in range(N):
  d[A[i]] += 1

S = [0]*(N+1)
for key, val in d.items():
  S[key] = (val * (val-1))//2

ans = sum(S)
for k in range(N):
  t = d[A[k]]*(d[A[k]]-1)//2
  add = (d[A[k]]-1)*(d[A[k]]-2)//2
  print(ans - t + add)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=0;
    a--;
    ll e=lcm(c,d);
    ans+=b-((b/c)+(b/d)-(b/e));
    ans-=a-((a/c)+(a/d)-(a/e));
    cout << ans<<endl;
    return 0;
}


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

int main() {
	int dp[3001] = {};
	pair<int, int> ab[3000];
	int n, t;
	cin >> n >> t;
	for(int i = 0; i < n; i++) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab, ab + n);
	for(auto& p: ab) {
		for(int j = t - 1; j >= 0; j--) {
			int c = min(j + p.first, t);
			dp[c] = max(dp[c], dp[j] + p.second);
		}
	}
	cout << dp[t] << endl;
}


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

int b[6][2] = { {0,1}, {0,1}, {0,2}, {0,2}, {1,2}, {1,2} };

int main(){
    vector<pair<int,int>> v;
    int x, y;

    for(int i = 0; i < 6; i++){
        cin >> x >> y;
        if(x > y)   swap(x, y);
        v.push_back({x, y});
    }

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

    bool judge = false;
    
    do{
        int a[3] = {v[0].first, v[0].second, v[2].second};
        bool inner = true;
        for(int i = 0; i < 6; i++){
            inner &= v[i].first == a[b[i][0]];
            inner &= v[i].second == a[b[i][1]];
        }
        if(inner)   judge = true;
    }while(next_permutation(v.begin(), v.end()));

    if(judge)   cout << "yes" << endl;
    else        cout << "no" << endl;

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

string ipt;
ll ptr;
ll getn() {
    ll ret = 0;
    while (ipt[ptr] != '/') {
        ret = ret * 10 + ipt[ptr]-'0';
        ptr++;
    }
    ptr++;
    return ret;
}

vector<ll> a,b;
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> ipt;
    ipt =ipt+ '/';
    a.emplace_back(getn()); 
    a.emplace_back(getn()); 
    a.emplace_back(getn());

    b.emplace_back(2019);
    b.emplace_back(4);
    b.emplace_back(30);

    debug(a);
    if (a <= b) {
        cout << "Heisei" << endl;
    }  else {
        cout << "TBD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256