akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define inf 1000000000
using namespace std;
int main()
{
    int n,b[200],ans=0,a[200];
    scanf("%d",&n);
    for(int i=1; i<=n-1; i++)
        scanf("%d",&a[i]);
    a[0]=inf;
    for(int i=1; i<=n-1; i++)
        b[i]=min(a[i-1],a[i]);
    b[n]=a[n-1];
    for(int i=1;i<=n;i++)
        ans+=b[i];
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
// all_of

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
int a[100000];

int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> a[i];
		a[i]--;
	}
	int sum = 0;
	REP(i, 0, N) {
		if (a[a[i]] == i) ++sum;
	}
	cout << sum / 2 << endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    int n;
    cin >> n;
    bool b1=true,b2=true;
    vector<string> w(n);
    rep(i,n)cin >> w[i];
    rep(i,n-1) if(*w[i+1].begin()!=*(w[i].end()-1))b1=false;
    rep(i,n-1){
        rep(j,n-i-1){
            if(w[i]==w[i+j+1])b2 =false;
        }
    }
    if(b1&&b2){

        cout << "Yes"<< endl;
    }else{
        cout << "No" << endl;
    }

}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const ll mod = 1000000007LL;

long long extgcd(long long a,long long b,long long& x,long long& y) {
  long long d = a;
  if(b != 0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
  else
    x = 1,y = 0;
  return d;
}

long long mod_inv(long long a,long long m) {
  long long x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

ll modmultiply(ll a,ll b,ll c) {
  ll x = 0,y = a%c; 
  while(b > 0) {
    if(b%2 == 1) x = (x+y)%c; 
    y = (y*2)%c;
    b /= 2; 
  }
  return x%c;
}


ll modpow(ll x, ll y, ll mod) {
  ll ret = 1;
  while(y) {
    if(y&1)
      ret = modmultiply(ret, x, mod);
    x = modmultiply(x, x, mod);
    y >>= 1;
  }
  return ret;
}



#define MAX 5010
int N;
string s;
ll dp[MAX][MAX];
ll dp2[310][310][310];

ll bf() {
  memset(dp2,0,sizeof dp2);
  dp2[0][0][0] = 1;
  rep(i,N) {
    rep(j,N+1) {
      rep(k,j+1) {
	if( j == k ) {
	  // 0 and 1
	  ( dp2[i+1][j+1][k+1] += dp2[i][j][k] ) %= mod;
	  ( dp2[i+1][j+1][k]   += dp2[i][j][k] ) %= mod;
	  // remove
	  ( dp2[i+1][max(0,j-1)][max(0,k-1)] += dp2[i][j][k] ) %= mod;
	} else {
	  // 0 and 1
	  ( dp2[i+1][j+1][k] += dp2[i][j][k] ) %= mod;
	  ( dp2[i+1][j+1][k] += dp2[i][j][k] ) %= mod;
	  // remove
	  assert( j-1 >= 0 );
	  ( dp2[i+1][j-1][k] += dp2[i][j][k] ) %= mod; // 1
	}
      }
    }
  }
  return dp2[N][(int)s.size()][(int)s.size()];
}

void compute() {
  dp[0][0] = 1;
  rep(i,N) {
    rep(j,N+1) {
      ( dp[i+1][j+1] += (dp[i][j]*2LL)%mod ) %= mod;
      ( dp[i+1][max(0,j-1)] += dp[i][j] ) %= mod;
    }
  }
  cout << ( dp[N][(int)s.size()] * mod_inv(modpow(2,(int)s.size(),mod),mod) ) % mod << endl;
}

int main() {
  cin >> N >> s;
  compute();
  //cout << "Ans : " << bf() << endl;
  return 0;
}


Measured memory_bytes: 197376
import sys
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

S = list(input().strip())
L = []
L.append(S[0])

index = 0
index_a = 1
while index_a < len(S):
    if L[index] != S[index_a]:
        L.append(S[index_a])
        index += 1
        index_a += 1
    else:
        c = "".join(S[index_a:index_a+2])
        if L[index] == c:
            L[index] += c
        else:
            L.append(c)
        index += 1
        index_a += 2

print(len(L))

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

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

using LL = long long;
using ordered_set = tree<LL, null_type, less<LL>,
		rb_tree_tag, tree_order_statistics_node_update
>;
const int N = 2e5 + 10;
LL a[N], pre[N], mod[N];

int main() {
#ifdef LOCAL_EXEC
	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

	int n; cin >> n;
	LL k; cin >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pre[i] = pre[i - 1] + a[i] - 1;
		mod[i] = ((pre[i] % k) + k) % k;
	}
	map<LL, int> f;
	LL ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i >= k) {
			f[mod[i - k]]--;
		}
		ans += f[mod[i]];
		f[mod[i]]++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 17408
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define inf 10000000000000000
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
const int N=200;
int a[3][N],dp[3][N];
int n;
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ************************/
   cin>>n;
   for(int i=0;i<2;i++)
   {
   	for(int j=0;j<n;j++)
   	{
   		cin>>a[i][j];
   		dp[i+1][j+1]=a[i][j];
   	}
   }
   for(int i=0;i<=2;i++)
   {
   	for(int j=0;j<=n;j++)
   	{
   		if(i==0||j==0)
   		{
   			dp[i][j]=0;
   		}
   		else if(i==1)
   		{
   			dp[i][j]=a[i-1][j-1]+dp[i][j-1];
   		}
   		else
   		{
   			dp[i][j]=a[i-1][j-1]+max(dp[i][j-1],dp[i-1][j]);
   		}
   	}
   }
   cout<<dp[2][n]<<endl;
}     	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,i,j,t,k;
ll a,b,c,d;
char A,C,X,Y,Z;
ll ans,MAX,MIN;
ll ax[2000500];
char cx[10000];
ll dx[12];
ll bx[2000500];
const int N = (1 << 20) + 10;

bool cmp(ll x,ll y)
{
    return x>y;
}

int main()
{
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        ll sum=0;
        ans=0;
        scanf("%lld%lld",&n,&m);
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&ax[i]);
            sum+=ax[i];
        }
        sort(ax+1,ax+1+n,cmp);
        for(i=1;i<=m;i++)
            if(ax[i]*4*m<sum)
            {
                cout << "No" << endl;
                break;
            }
         if(i>m) cout << "Yes" <<endl;
    }
	return 0;
}

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

#define V_SUM_MAX 100000
#define N_MAX 100 
#define W_MAX 100000000000
  
// To store the states of DP 
ll dp[V_SUM_MAX + 1][N_MAX]; 
bool v[V_SUM_MAX + 1][N_MAX]; 
  
// Function to solve the recurrence relation 
ll solveDp(ll r, ll i, ll* w, ll* val, ll n) 
{ 
    // Base cases 
    if (r <= 0) 
        return 0; 
    if (i == n) 
        return W_MAX; 
    if (v[r][i]) 
        return dp[r][i]; 
  
    // Marking state as solved 
    v[r][i] = 1; 
  
    // Recurrence relation 
    dp[r][i] 
        = min(solveDp(r, i + 1, w, val, n), 
              w[i] + solveDp(r - val[i], 
                             i + 1, w, val, n)); 
    return dp[r][i]; 
} 
  
// Function to return the maximum weight 
ll maxWeight(ll* w, ll* val, ll n, ll c) 
{ 
  
    // Iterating through all possible values 
    // to find the the largest value that can 
    // be represented by the given weights 
    for (ll i = V_SUM_MAX; i >= 0; i--) { 
        if (solveDp(i, 0, w, val, n) <= c) { 
            return i; 
        } 
    } 
    return 0; 
} 

int main(){
  ll n, W;
  cin>>n>>W;
  ll w[n], v[n];
  for(ll i=0; i<n; i++){
    cin>>w[i]>>v[i];
  }
  cout<<maxWeight(w, v, n, W)<<"\n"; 
  
  return 0;
}


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

int x,y,z,n,m,mx;

int main() {
	scanf("%d%d",&x,&y);
	for (int a = 0; a < y; a++) {
		scanf("%d",&z);
		if (a == 0) m = z; else {
			int tmp = (z-n);
			if (tmp > mx) mx = tmp;
		}
		n = z;
	}
	int tmp = (x-n)+m;
	if (tmp > mx) mx = tmp;
	printf("%d\n",x-mx);
	return 0;
}

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

using ll = long long;
const int INF = 1e9+100;

const int MOD = 1e9+7;

ll dp[3000] = {0};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	dp[0] = 1;
	for (int i = 3; i <= n; i++){
		for (int j = 3; j <= i; j++){
			dp[i] += dp[i-j];
			dp[i] %= MOD;
		}
	}
	cout<<dp[n]<<'\n';
	return 0;
}

Measured memory_bytes: 3624
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(len(B)):
    if (A[i]-B[i]) >= 0:
        ans += B[i]
    elif (A[i]-B[i]) < 0:
        ans += A[i]
        c = B[i] - A[i]
        if (A[i+1]-c) >= 0:
            ans += c
            A[i+1] = A[i+1] - c
        elif (A[i+1]-c) < 0:
            ans += A[i+1]
            A[i+1] = 0

print(ans)

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

using ll=long long;

int main() {
  int N,K; cin >>N >>K;
  vector<int> h(N);
  rep(i,0,N) {cin >>h[i];}
  sort(h.begin(),h.end());
  vector<int> a;
  rep(i,0,N-K+1) {
    a.push_back(h[i+K-1]-h[i]);
  }
  cout <<*min_element(a.begin(),a.end()) <<endl;
  return 0;
}


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

template <typename T>
class BinaryIndexedTree
{
    vector<T> arr;
    T initial_value;
    long long size;
    function<T(T, T)> operation;

public:
    BinaryIndexedTree(const long long N, function<T(T, T)> func, T init)
    {
        set_size(N);
        set_initial_value(init);
        initialize_array();
        set_operation(func);
    }

    void set_size(const long long N)
    {
        this->size = N + 1;
    }

    void set_initial_value(const T init)
    {
        this->initial_value = init;
    }

    void initialize_array()
    {
        this->arr = vector<T>(size, initial_value);
    }

    void initialize_array(const T init)
    {
        set_initial_value(init);
        initialize_array();
    }

    void set_operation(const function<T(T, T)> func)
    {
        this->operation = func;
    }

    void update(long long idx, T value)
    {
        while (idx <= this->size)
        {
            this->arr[idx] = this->operation(this->arr[idx], value);
            idx += (idx & -idx);
        }
    }

    T query(long long idx)
    {
        T ret = this->initial_value;
        while (idx > 0)
        {
            ret = this->operation(ret, this->arr[idx]);
            idx -= (idx & -idx);
        }
        return ret;
    }
};

int main()
{
    long long N, D, A;
    cin >> N >> D >> A;

    BinaryIndexedTree<long long> bit(N * 3, [](long long a, long long b) { return a + b; }, 0);
    vector<pair<long long, long long>> xh(N);
    long long X, H;
    for (long long i = 0; i < N; i++)
    {
        cin >> X >> H;
        xh[i] = make_pair(X, H);
    }
    sort(xh.begin(), xh.end());
    vector<long long> idxs;
    for (int i = 0; i < N; i++)
    {
        idxs.push_back(xh[i].first);
        idxs.push_back(xh[i].first - D - 1);
        idxs.push_back(xh[i].first + D);
    }
    sort(idxs.begin(), idxs.end());
    unique(idxs.begin(), idxs.end());
    map<long long, long long> inv;
    for (long long i = 0; i < idxs.size(); i++)
    {
        inv[idxs[i]] = i;
    }

    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        long long minimum = inv[xh[i].first - D - 1];
        long long maximum = inv[xh[i].first + D];
        long long current = bit.query(maximum) - bit.query(minimum);
        if (current >= xh[i].second)
        {
            continue;
        }
        long long add = (xh[i].second - current) / A;
        if (add * A < xh[i].second - current)
        {
            add++;
        }
        ans += add;
        bit.update(maximum, A * add);
    }
    cout << ans << endl;
}


Measured memory_bytes: 52328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
const int ma=1000000000;
int main(){
    int a,b; cin >> a >> b;
    if(a<b){
        rep(i,b) cout << a;
    }
    else rep(i,a) cout << b;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
            for (int i = 0; i < line[2]; i++) {
                int index = i % 2;
                if (line[index] % 2 != 0) {
                    // クッキーが奇数なら、クッキーを食べる
                    line[index] -= 1;
                }
                // 半分を相手に渡す
                line[index] /= 2;
                line[(index + 1) % 2] += line[index];
            }

            Console.WriteLine(line[0] + " " + line[1]);
        }
    }
}


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

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

Measured memory_bytes: 256
def factorization(n):
    arr = []
    Cnt = 0
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            if i not in arr:
                Cnt += 1
                arr.append(i)

    if temp!=1 and temp not in arr:
        Cnt += 1
        arr.append(temp)

#    if arr==[]:
#        arr.append([n, 1])

    return Cnt


a, b=map(int,input().split())

if a < b:
    a, b = b, a
while a % b != 0:
    a, b = b, a % b
# print(b)
N = factorization(b)

print(N+1)  


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


int main() {
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k) cout<<s<<endl;
    else{
        string c=s.substr(0,k);
        cout<<c<<"..."<<endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << (x) << endl
using namespace std;

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

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const Double PI  = 3.141592653589793238463;
const Int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

Double solve(Int n){
    Double m = (n + 1) / 2;
    return m / n;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    Int n;
    cin >> n;
    cout << solve(n) << "\n";

    return 0;
}


Measured memory_bytes: 256
#Colorful Leaderboard
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
b = sorted (a//400)
cnt = 0
for i in range(len(b)):
    if b[i]  < 8:
        None
    else:
        b[i]+=i
        cnt+=1
c = len(list(set(b)))

print(str(max([1,c-cnt])) + " " + str(c))

Measured memory_bytes: 12508
N, M = map(int, input().split())
cnt = [1 for _ in range(N)] #市の申請順を管理する
l = []

for i in range(M):
    p, y = map(int, input().split())
    l.append([p, y, i])

l = sorted(l, key=lambda x:x[1])

for i in range(M):
    p = l[i][0] #県
    x = str(cnt[p-1]) #市ができた順位
    cnt[p-1] += 1

    str_p = str(p)
    while len(str_p) != 6:
        str_p = "0" + str_p

    while len(x) != 6:
        x = "0" + x
    
    l[i][0] = str_p
    l[i][1] = x

l = sorted(l, key=lambda x:x[2])

for i, j, _ in l:
    print(i+j)

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

int main(){
  while(1){
    int H, W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if((i + j) %2 == 0) cout<<"#";
        else cout<<".";
      }
      cout<<endl;
    }
    
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

int a[3000][3000];
int X[1000010], Y[1000010];
int dp[3000][3000];

vector<int> prime;

void PrimeTable(int N){
    prime = vector<int>(N+1, 1);
    prime[0] = 0;
    prime[1] = 0;

    for(int i=2; i*i<=N; ++i){
        if(prime[i]){
            for(int j=2; i*j<=N; ++j){
                prime[i*j] = 0;
            }
        }
    }
}

void build(){
    int now = 1, dir = 0, diff = 1;
    int x=1500, y=1500;
    a[1500][1500] = 1;
    X[1] = 1500, Y[1] = 1500;
    while(now <= 1000000){
        switch(dir){
        case 0:
            FOR(dx, 1, diff+1){
                a[y][x+dx] = ++now;
                X[now] = x+dx;
                Y[now] = y;
            }
            x = x+diff;
            break;
        case 1:
            FOR(dy, 1, diff+1){
                a[y-dy][x] = ++now;
                X[now] = x;
                Y[now] = y-dy;
            }
            y = y-diff;
            break;
        case 2:
            FOR(dx, 1, diff+1){
                a[y][x-dx] = ++now;
                X[now] = x-dx;
                Y[now] = y;
            }
            x = x-diff;
            break;
        case 3:
            FOR(dy, 1, diff+1){
                a[y+dy][x] = ++now;
                X[now] = x;
                Y[now] = y+dy;
            }
            y = y+diff;
            break;
        }
        if(dir%2) diff++;
        dir = (dir+1)%4;
    }
}

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

    build();
    int m, n;
    PrimeTable(1000010);
    cin >> m >> n;
    while(!(m==0&&n==0)){
        REP(i,3000)REP(j, 3000) dp[i][j]=-INF;
        int sy = Y[n], sx = X[n];
        dp[sy][sx] = prime[n];
        int sf = 1;
        P ans = mp(prime[n], prime[n] ? n : 0);
        bool f=true;
        for(int y=sy; f; y++){
            f = false;
            FOR(x, sx-sf, sx+sf+1){
                if(a[y+1][x] <= 0 || a[y+1][x] > m) continue;
                f = true;
                dp[y+1][x] = max({dp[y][x-1], dp[y][x], dp[y][x+1]})+prime[a[y+1][x]];
                if(ans.fi < dp[y+1][x]){
                    ans.fi = dp[y+1][x];
                    ans.se = a[y+1][x];
                }else if(ans.fi == dp[y+1][x]){
                    if(prime[a[y+1][x]]) chmax(ans.se, a[y+1][x]);
                }
            }
            sf++;
        }
        cout << ans.fi << " " << ans.se << "\n";
        cin >> m >> n;
    }

    return 0;
}


Measured memory_bytes: 57800
#include<bits/stdc++.h>
using namespace std;
#define sz 300005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io;
    int n,cnt=0;
    cin>>n;
    int a[n+5];
    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=1;i<n-1;i++){
        if((a[i]>a[i-1] && a[i]<a[i+1]) || (a[i]<a[i-1] && a[i]>a[i+1])) cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}





Measured memory_bytes: 256
# define
a = [0] * int(1e5 + 100)
# functions
def _gcd(a, b):
    if a % b == 0 : return b
    if b % a == 0 : return a
    while a != 1 and b != 1:
        if a > b: a %= b
        else : b %= a
        if a % b == 0: return b
        if b % a == 0: return a
# main

n, m = (int(s) for s in input().split())

inp = input().split()
for i in range(1, n + 1) :
    a[i] = int(inp[i - 1])

flag = False
lcm = a[1]

for i in range(2, n + 1) :
    gcd = _gcd(lcm, a[i])
    lcm = int(lcm * a[i] / gcd)
    if(lcm > 2 * m):
        flag = True
        break

for i in range (1, n + 1):
    if int(lcm / a[i]) % 2 == 0 : flag = True

if flag : print(0)
else : print(int( (m - int(lcm / 2)) / lcm ) + 1)


Measured memory_bytes: 15012
package main

import (
	"fmt"
)

func pow(n int) int64 {
	m := int64(n)
	return m * m * m * m * m
}

func f(a, b int) int64 {
	return pow(a) - pow(b)
}

func main() {
	var x int64
	fmt.Scan(&x)

	var maxInd int
	for maxInd = 1; f(maxInd, maxInd-1) <= x; maxInd++ {
	}
	for a := -maxInd; a < maxInd; a++ {
		for b := -maxInd; b < maxInd; b++ {
			if f(a, b) == x {
				fmt.Println(a, b)
				return
			}
		}
	}
}


Measured memory_bytes: 1752
A, B, C, D = map(int, input().split(' '))

def gcd(a, b):
  if(a==0):
    return b  
  c = b%a  
  return gcd(c,a)

def lsm(a, b):
  return a * b // gcd(a, b)

result= B//C+B//D-B//lsm(C,D) -((A-1)//C+(A-1)//D-(A-1)//lsm(C,D))
print(B-A+1-result)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>

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

using namespace std;

int cut[10000];
int memo[2][5010][2];

int main(){
  int n;
  const int MAX = 10000 * 10000 * 2;
  scanf("%d", &n);
  REP(i, n - 1) scanf("%d", cut + i + 1);

  REP(i,2) REP(j,5001) REP(k,2) memo[i][j][k] = MAX;
  memo[0][0][0] = 0;

  REP(i, n){
    REP(j, n / 2 + 1){
      memo[(i + 1) % 2][j + 1][0] = min(memo[i % 2][j][0], memo[i % 2][j][1] + cut[i]);
      memo[(i + 1) % 2][j    ][1] = min(memo[i % 2][j][1], memo[i % 2][j][0] + cut[i]);
    }
    memo[(i + 1) % 2][0][0] = MAX;
  }

  printf("%d\n", min(memo[n % 2][n / 2][0], memo[n % 2][n / 2][1]));

  return 0;
}

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

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

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

    long long ans = 0;
    long long now = A[0];
    for(int i = 1; i < n; i++){
        if(now > A[i]) {
            ans += now - A[i];
        } else {
            now = A[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
int n,v,l[200005],b,e;
int main(){
    cin>>n;
    b=ceil((double)(n+1)/2);
    e=(n%2==0)?(-1):(1);
    for(int i=1;i<=n;i++)
{
        cin>>v;
        l[b]=v;
        b+=i*e;
        e*=-1;
    }
    for(int i=1;i<=n;i++)
    cout<<l[i]<<" ";
    return 0;
}

Measured memory_bytes: 2944
mod = 10**9+7

def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (X+Y)//3
    if X < n or Y < n or X > 2*n or Y > 2*n:
        print(0)
    else:
        k = min(X-n, Y-n)
        R = [0] * (k+1)
        for i in range(1,k+1):
            R[i] = Pow(i, mod-2)
        cmb = [0]*(k+1)
        cmb[0] = 1
        for i in range(k):
            cmb[i+1] = ((cmb[i]*(n-i))%mod)*R[i+1]%mod
        print(cmb[k])

Measured memory_bytes: 58204
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 3000;
double dp[N][N], P[N];
bool check[N][N];
int n;


double f(int i, int j){
    if(i == n)return j > n/2;
    double &ans  = dp[i][j];
    if(check[i][j])return ans;
    check[i][j] = true;
    ans += f(i+1, j)*(1-P[i]);
    ans += f(i+1, j+1)*P[i];
    return ans;
}


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

  cout << fixed << setprecision(10);
  cin >> n;
  int a, b;
  char c;
  forn(i, 0, n){
    cin >> P[i];
  }
  double ans = f(0, 0);
  cout << ans << endl;
  


}





Measured memory_bytes: 58768
#include<stdio.h>
#include<string.h>
 
int main(){
  char W[10],T[1000];
  int i,count=0;
 
  scanf("%s",W);
  while(1){
    scanf("%s",T);
    if(strcmp(T,"END_OF_TEXT")==0)break;
 
    for(i=0;i<strlen(T);i++)
      if(T[i] >= 'A' && T[i] <= 'Z')T[i] += 32;
 
    if(strcmp(T,W)==0)count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 548
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    for i in range(0,a-2):
      for j in range(i+1,a-1):
        if 2*j-i<a and moji[i]!=moji[j] and moji[j]!=moji[2*j-i] and moji[2*j-i]!=moji[i]:
          res-=1
    print(res)


Measured memory_bytes: 9304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long llong;


int main() {
    llong N;
    cin >> N;

    map<string, llong> m;
    for(llong i=0; i<N; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if(m.find(s)!=m.end()) {
            ++m[s]; 
        }
        else m[s] = 1;
    }

    llong cnt = 0;
    for(auto it = m.begin(); it != m.end(); ++it) {
        llong n = it->second;
        if(n>1) {
            // nC2の計算
            cnt += (n * (n-1) / 2);
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 11136
#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 a[n];
  rep(i,n) cin >> a[i];

  int ans = 1001001001;
  for(int i=-100;i<=100;i++){
    int temp = 0;
    rep(j,n) temp += (i-a[j])*(i-a[j]);
    ans = min(ans,temp);
  }
   cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3604
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();

        int[] a = new int[n];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt() - x;
        }

        System.out.println(Math.abs(gcd(a)));

    }

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

    static int gcd(int[] a){
        int result = 0;
        for(int i : a){
            result = gcd(result, i);
        }
        return result;
    }
}


Measured memory_bytes: 51540
#include<iostream>
#include<cstring>
using namespace std;
int num[10];
int fun(char op) {
	int tmp = num[1];
	switch(op) {
		case 'N':
			num[1] = num[2];
			num[2] = num[6];
			num[6] = num[5];
			num[5] = tmp;
			break;
		case 'W':
			num[1] = num[3];
			num[3] = num[6];
			num[6] = num[4];
			num[4] = tmp;
			break;
		case 'E':
			num[1] = num[4];
			num[4] = num[6];
			num[6] = num[3];
			num[3] = tmp;
			break;
		case 'S':
			num[1] = num[5];
			num[5] = num[6];
			num[6] = num[2];
			num[2] = tmp;
			break;
	}
	return 0;
}

int main() {
	//freopen("in","r",stdin);
	for(int i=1;i<=6;i++)
		cin>>num[i];

	char tmp[1000]; cin>>tmp; int ans = 1;
	for(int i=0;i<strlen(tmp);i++) 
		fun(tmp[i]);
	
	cout<<num[1]<<endl;
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, k;
	double prob = 0;
	cin>> n>>k;
	if(n<k){
		for(int i=1;i<=n;i++){
			int l =k;
			int cnt = 0;
			int j=i;
			while(j<l){
				j *= 2;
				cnt++;
			}
			prob += pow(2, -cnt);
		}
	}else{
		prob += (n-k+1);
		for(int i=1; i<=k-1;i++){
			int l =k;
			int cnt = 0;
			int j=i;
			while(j<l){
				j *= 2;
				cnt++;
			}
			prob += pow(2, -cnt);
		}
	}
	prob /= n;
	printf("%.11lf\n", prob);
}

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    string s;
    cin >> s;
	
  	int a[3] = {};
    a[s[0]-'a']++;
  	a[s[1]-'a']++;
	a[s[2]-'a']++;
  	if(a[0]==1 && a[1]==1 && a[2]==1)
    	cout << "Yes" << endl;
	else
      	cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
using namespace std;

class AChangingACharacter {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n,k;
        string s;
        cin >> n >> k >> s;
        s[k - 1] = tolower(s[k - 1]);
        cout << s << endl;
	}
};


int main() {
	AChangingACharacter solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  rep(i,n){
    rep(j,d) cin >> x[i][j];
  }

  int cnt=0;
  rep(i,n){
    rep(j,n){
      int r2 = 0;
      rep(k,d) r2 += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      
      for(int s = 1;s<=10000;s++){
	if(s*s==r2) cnt++;
      }
    }
  }  
  cnt /= 2;
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3616
import math


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


x = int(input())
ans = float('inf')

for i in range(x, 100004):
    if is_prime(i):
        print(i)
        break

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

signed main(void)
{
	int n;
	cin >> n;
	int a[n];
	map<long long, long long> mp;
	long long sum[n], cnt;

	rep(i, n) 
	{
		cin >> a[i];
		sum[i] = a[i];
	}
	rep(i, n - 1) sum[i + 1] += sum[i];
	rep(i, n) mp[sum[i]]++;
	cnt = 0;
	for(auto p : mp)
	{
		auto k = p.first;
		auto v = p.second;
		if (k == 0)
		{
			cnt += v;
		}
		cnt += v * (v - 1) / 2;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N;
  string S;
  cin >> N >> S;
  map<char, ll> dict; // 各文字の出現回数
  for (int i=0; i<N; i++) {
    if (dict.count(S[i])) dict[S[i]]++;
    else dict[S[i]] = 1;
  }
  ll res = 1;
  for (auto p: dict) {
    auto value = p.second;
    res *= value+1;
    res %= MOD;
  }
  if (res==0) cout << 1000000006 << endl;
  else cout << res-1 << endl;
}

Measured memory_bytes: 512
/*
ID: kiwio
LANG: C++14
TASK: 
*/

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

int n, num, x[200005], yay, dist, nd, ans, ind;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(NULL);/*
#ifndef turtle
	ofstream cout (".out");
	ifstream cin (".in");
#endif*/
	cin >> num;
	for (int i=1; i<=num; i++) {
		cin >> x[i];
		n=max(n, x[i]);
		if (x[i]==n) {
			ind=i;
		}
	}
	cout << n << " ";
	dist=1000000000;
	for (int i=1; i<=num; i++) {
		if (i!=ind) {
			if (abs(n/2-x[i])<dist and x[i]<=n) {
				dist=abs(n/2-x[i]);
				nd=x[i];
			}
		}
	}
	cout << nd;

 }

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b , c , d , e , f;
  cin >> a >> b >> c >> d;
  e = a + b;
  f = c + d;
  if (e > f) {
    cout << "Left" << endl;
  }
  else if (e == f) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, k, x, cnt;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> n >> k;
    for ( int i = 0; i < n; i++ ) {
        cin >> x;
        if ( x >= k ) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000;
int N, K;
ll a[MAX_N+1];
ll sum[MAX_N+1];
bool used[MAX_N*(MAX_N+1)/2];

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

  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> a[i];

  for (int i = 1; i <= N; ++i) sum[i] = sum[i-1] + a[i];

  vector<ll> vec;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < i; ++j) {
      vec.push_back(sum[i]-sum[j]);
    }
  }

  sort(all(vec));
  reverse(all(vec));

  ll ma = vec[0], ans = 0;
  int bitsize = 0;
  while ((1ll<<bitsize) <= ma) ++bitsize;
  memset(used, true, sizeof(used));

  for (int i = bitsize-1; i >= 0; --i) {
    int k = 0;
    vector<int> unused;
    for (int j = 0; j < vec.size(); ++j) {
      if (used[j] && (vec[j]>>i) & 1) {
        ++k;
      } else {
        if (used[j]) unused.push_back(j);
      }
    }

    if (K <= k) {
      ans += (1ll<<i);
      for (int j = 0; j < unused.size(); ++j) used[unused[j]] = false;
    }

  }


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



Measured memory_bytes: 8812
//	C++ (Clang3.8.0)
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
	int x, ans = 0;
	
	cin >> x;
	
	ans += (x/500)*1000;
	x %= 500;
	
	ans += (x/5)*5;
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#define nmax 100001

using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");

int nr_nod,nr_m;
vector<int> mat[nmax];

long long dist_max[nmax];
int viz[nmax];

void dfs(int x)
{
    viz[x]=1;
    for(int i=0; i<mat[x].size(); i++)
        {
            int val=mat[x][i];
            if(!viz[val]) dfs(val);
            dist_max[x]=max(1+dist_max[val],dist_max[x]);
        }
}

int main()
{
    cin>>nr_nod>>nr_m;
    for(int i=1; i<=nr_m; i++)
        {
            int x,y;
            cin>>x>>y;
            mat[x].push_back(y);
        }

    for(int i=1; i<=nr_nod; i++)
        {
            if(!viz[i])
                dfs(i);
        }

    long long sol=0;
    for(int i=1; i<=nr_nod; i++)
        {
            if(dist_max[i]>sol) sol=dist_max[i];
            fout<<dist_max[i]<<" ";
        }

    cout<<sol;

    return 0;
}


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

int main() {
  int64_t a, b;
  cin >> a >> b;
  if (b - a >= 2019) {
    a %= 2019;
    b = 2019;
  } else {
    a %= 2019;
    b %= 2019;
  }
  int ans = 2019;
  for (int i = a; i <= b; i++) {
    for (int j = i+1; j <= b; j++) {
      if ((i*j)%2019 < ans) {
        ans = (i*j)%2019;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

const int MOD = 1000000007;

ll mod_pow(ll a, ll b, ll p) {
    if (b == 0) return 1;
    if (b & 1) return (a * mod_pow(a, b - 1, p)) % p;
    ll t = mod_pow(a, b / 2, p);
    return (t * t) % p;
}

ll comb(ll n, ll r, ll p) {
    ll tn = 1, tr = 1;
    for (int i = n; i > n - r; i--) {
        tn *= i;
        tn %= p;
    }
    for (int i = r; i > 0; i--) {
        tr *= i;
        tr %= p;
    }
    return tn * mod_pow(tr, p - 2, p) % p;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = mod_pow(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD);
    while (ans < 0) ans += MOD;
    cout << ans << endl;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

LL digit(LL x, LL d) {
    if(x == 0)
        return 1;
    LL res = 0;
    for(;0 < x;) {
        x /= d;
        res++;
    }
    return res;
}

LL s(LL x) {
    LL res = 0;
    for(;x != 0;x /= 10) {
        res += x%10;
    }
    return res;
}

int main() {
    LL K;
    cin >> K;

    FOR(i, 1, min<LL>(10, K + 1)) {
        cout << i << endl;
    }
    K -= min<LL>(9, K);

    LL N = 10;
    REP(i, K) {
        double t = 1e18;
        LL d = digit(N, 10);
        LL res = N;
        REP(j, d) {
            LL x = N;
            LL p = pow(10, j + 1);
            x /= p;
            x += 1;
            x *= p;
            x -= 1;
            if((double)x/s(x) < t) {
                res = x;
                t = (double)x/s(x);
            }
        }
        cout << res << endl;
        N = res + 1;
    }
    return 0;
}



Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
     Scanner sc = new Scanner(System.in);
     //多角形の包含関係
     int contains(Point2D[] plist,Point2D p){
    	boolean isin = false;
    	int n = plist.length;
    	for(int i = 0;i < n;i++){
    		Point2D a = sub(plist[i],p);
    		Point2D b = sub(plist[(i+1) % n ], p);
    		if(a.getY() > b.getY()){
    			Point2D temp = (Point2D) a.clone();a = b;
    			b = temp;
    		}
    		if(a.getY() <= 0 && 0 < b.getY()){
    			if(cross(a,b) < 0) isin =! isin;
    		}
    		if(cross(a,b) == 0 && dot(a,b) <= 0)return 0;
    	}
    	return isin ? 1 : -1;
     }
     //点と点の差
     Point2D sub(Point2D p1,Point2D p2){
    	 return new Point2D.Double(p1.getX()-p2.getX(),p1.getY()-p2.getY());
     }
     //内積
     double dot(Point2D p1,Point2D p2){
    	 return p1.getX()*p2.getX()+p1.getY()*p2.getY();
     }
     //外積
     double cross(Point2D p1,Point2D p2){
    	 return p1.getX()*p2.getY()-p1.getY()*p2.getX();
     }
     void doIt() { 
    	 while(sc.hasNext()){
    		 Point2D xy[] = new Point2D.Double [3];
    		 for(int i = 0;i < 3;i++){
    			 xy[i] = new Point2D.Double(sc.nextDouble(),sc.nextDouble());
    		 }
    		 Point2D xyp = new Point2D.Double(sc.nextDouble(),sc.nextDouble());
    		 if(contains(xy,xyp) == 1){
    			 System.out.println("YES");
    		 }else{
    			 System.out.println("NO");
    		 }
    	 }
     }
	public static void main(String[] args) {
          // TODO Auto-generated method stub
          new Main().doIt();
     }

}

Measured memory_bytes: 23672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
int n, a[N], b[N], v[N], v1[N], p1[N], p2[N];
ll ans = (ll)(1e60);
int main() {
  read(n);
  rep (i, 1, n)
    read(a[i]), read(b[i]);
  ll tmp = 0;
  rep (i, 1, n) tmp += a[i];
  ans = min(ans, tmp);
  tmp = 0;
  rep (i, 1, n) tmp += b[i];
  ans = min(ans, tmp);
  tmp = 0;
  rep (i, 1, n) v[i] = min(a[i], b[i]);
  rep (i, 1, n) v1[i] = max(a[i], b[i]);
  rep (i, 1, n) tmp += v[i];
  rep (i, 1, n) p1[i] = i;
  sort(p1 + 1, p1 + n + 1, [=](int a,int b) -> bool {
      return v[a] > v[b];
    });
  rep (i, 1, n) p2[i] = i;
  sort(p2 + 1, p2 + n + 1, [=](int a,int b) -> bool {
      return v1[a] < v1[b];
    });
  rep (i, 1, n) {
    if (p2[i] == p1[i]) {
      if (i > 1) break;
      ans = min(ans, tmp + v1[p2[i]] - v[p1[i+1]]);
      ans = min(ans, tmp + v1[p2[i+1]] - v[p1[i]]);
      break;
    }
    tmp += v1[p2[i]] - v[p1[i]];
    ans = min(ans, tmp);
    if (v1[p2[i]] - v[p1[i]] >= 0) break;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int turn = 0;
    while(true) {
        if(!turn) {
            c -= b;
            if(c <= 0) return cout << "Yes", 0;
        }else {
            a -= d;
            if(a <= 0) return cout << "No", 0;
        }

        turn = !turn;
    }
}








Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int cnt = 0;
        for (int j = i+1; j < s.size(); j++) {
            if (s[i] == s[j]) cnt++;
        }
        if (cnt > 0) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      char s;
      cin >> s;
      //int a = s.at(6);
      //cout << a << endl;
      if(s=='A') cout << 'T' << endl;
      else if(s=='T') cout << 'A' << endl;
      else if(s=='C') cout << 'G' << endl;
      else cout << 'C' << endl;
      return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    string n;
    int ans=0;
    
    cin >>n;
    
    cout<<solve(n[0]=='7'||n[1]=='7'||n[2]=='7')<<endl;
}

Measured memory_bytes: 3624