akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long i64;
const int N=500007,P=1e9+7;
int n;
struct edge{
	int to,nx,del;
}e[N];
int e0[N],ep=2,cn,cm,deg[N],fa[N],fr[N],ss[N],sp=0,col[N],ff[N];
i64 fac[N],fiv[N];
i64 pw(i64 a,i64 n){
	i64 v=1;
	for(;n;n>>=1,a=a*a%P)if(n&1)v=v*a%P;
	return v;
}
void ae(int a,int b){
	e[ep]=(edge){b,e0[a],0};e0[a]=ep++;++deg[b];
}
void del(int w){
	rec:
	deg[ss[++sp]=w]=0;
	for(int i=e0[w];i;i=e[i].nx)if(!e[i].del){
		e[i].del=e[i^1].del=1;
		int u=e[i].to;
		fa[w]=u;
		if(--deg[u]==1){w=u;goto rec;}
	}
}
struct num{
	i64 v;
	int sz;
	void add(const num&w){v+=w.v,sz=w.sz;}
	void ins(const num&w){v=v*w.v%P,sz+=w.sz;}
	void inc(){v=v*fac[sz]%P*fiv[sz+1]%P;++sz;}
	i64 val(){return v*fac[sz]%P;}
}v1[N],v2[N],v3[N],ans=(num){1,0};
void cal(){
	for(int i=1;i<=n*2;++i){
		ff[i]=fa[fa[i]]>i?fa[i]:0;
		v1[i]=v2[i]=(num){1,0};
		deg[i]=0;
	}
	for(int i=1;i<=n*2;++i)++deg[ff[i]];
	for(int i=1;i<=n*2;++i)if(!deg[i]){
		for(int w=i,f;deg[w]=-1,f=ff[w];w=f){
			v1[w].inc();
			v1[f].ins(v1[w]);
			if(--deg[f])break;
		}
	}
	for(int i=1;i<=n*2;++i)if(!ff[i]){
		int f=col[i];
		v1[i].inc();
		v2[f].ins(v1[i]);
	}
	for(int i=1;i<=n*2;++i)if(col[i]==i)v3[i].add(v2[i]);
}
int main(){
	scanf("%d",&n);
	for(int i=fac[0]=1;i<=n*2;++i)fac[i]=i*fac[i-1]%P;
	fiv[n*2]=pw(fac[n*2],P-2);
	for(int i=n*2;i;--i)fiv[i-1]=i*fiv[i]%P;
	for(int i=1,a,b;i<=n*2;++i){
		scanf("%d%d",&a,&b);
		b+=n;
		ae(a,b),ae(b,a);
	}
	for(int i=1;i<=n*2;++i)if(deg[i]==1)del(i);
	for(int i=1;i<=n*2;++i)if(deg[i]&&deg[i]!=2)return puts("0"),0;
	for(int i=1;i<=n*2;++i)if(deg[i]){
		int p=sp+1;
		del(i);
		ss[sp+1]=ss[p];
		for(int j=p;j<=sp;++j)fr[ss[j+1]]=ss[j];
		int w=ss[sp];
		col[w]=w;
	}
	for(int i=sp;i;--i){
		int w=ss[i];
		if(!col[w])col[w]=col[fa[w]];
	}
	cal();
	for(int i=1;i<=n*2;++i)if(fr[i])fa[i]=fr[i];
	cal();
	for(int i=1,tot=0;i<=n*2;++i)if(col[i]==i)ans.ins(v3[i]);
	printf("%lld\n",ans.val());
	return 0;
}

Measured memory_bytes: 41728
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt() - 1;

        int[] move = new int[n];
        Arrays.fill(move, -1);

        int cle = 1;
        int b = 0;
        int v = 0;
        int cnt = 0;

        while (move[v] == -1) {
            move[v] = cnt++;
            v = arr[v];
        }

        cle = cnt - move[v];
        b = move[v];

//        System.out.println(cle);
//        System.out.println(b);

        if (k < b) {
            int ans = arr[0];
            for (int i=1; i<k; i++) {
                int tmp = ans;
                ans = arr[tmp];
            }
            System.out.println(ans + 1);
        } else {
            long rem = (k - b) % cle;
            int u = 0;
            for (int i=0; i<b+rem; i++) {
                u = arr[u];
            }
            System.out.println(u + 1);
        }


    }


}


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

using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;

    string s;
    getline(cin, s);
    getline(cin, s);
    int AC[N] = { 0 };
    int found = 0;
    for(int i = 1; i < N; i++)
    {
        if (s[i] == 'C' && s[i - 1] == 'A')
        {
            found++;
        }

        AC[i] = found;
    }
    
    int left, right;
    for (int q = 0; q < Q; q++)
    {   
        cin >> left >> right;
        
        cout << AC[right - 1] - AC[left - 1] << "\n";
    }
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}
int n;
int a[N],b[N]={0};
int main(){
	//freopen("in.txt","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
  for (int i = n; i >= 1; --i) {
    b[i] = a[i];
    for (int j = i * 2; j <= n; j += i)
      b[i] ^= b[j];
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) if (b[i] == 1) cnt++;
  printf("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
    if (b[i] == 1) printf("%d ", i);
}

Measured memory_bytes: 5888
/*B - Greedy Takahashi*/

#include <bits/stdc++.h>

using namespace std;
using Long = long long;

int main(){
	
	Long A, B, K;

	cin >> A >> B >> K;

	if(K >= A){
		K -= A;
		A = 0;
	}
	else{
		A -= K;
		K = 0;
	}

	if(K >= B){
		K -= B;
		B = 0;
	}
	else{
		B -= K;
	}

	cout << A << ' ' <<B;

	return 0;
}

Measured memory_bytes: 256
n=list(map(int,input().split()))
n.sort()
a=n[0]
b=n[1]
c=n[2]
if (a+c)%2==1:
  if (a+b)%2==1:
    print(1+(c-b)//2+(c+1-a)//2)
  else:
    print((c-(b+1))//2+(c-(a+1))//2+1)
else:
  if (a+b)%2==0:
    print((c-b)//2+(c-a)//2)
  else:
    print((c-a)//2+(c+1-b)//2+1)

Measured memory_bytes: 3064
num = int(input()) #標準入力
if num % 7 == 0:print("thu") #numを7で割った余りが0なら"thu"を出力する
if num % 7 == 1:print("fri") #numを7で割った余りが1なら"fri"を出力する
if num % 7 == 2:print("sat") #numを7で割った余りが2なら"sat"を出力する
if num % 7 == 3:print("sun") #numを7で割った余りが3なら"sun"を出力する
if num % 7 == 4:print("mon") #numを7で割った余りが4なら"mon"を出力する
if num % 7 == 5:print("tue") #numを7で割った余りが5なら"tue"を出力する
if num % 7 == 6:print("wed") #numを7で割った余りが6なら"wed"を出力する


Measured memory_bytes: 5592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int n; cin >> n;
    vector<ld> v(n);
    rep(i,0,n) cin >> v[i];

    std::priority_queue<
      ld,                // 要素の型はint
      std::vector<ld>,   // 内部コンテナはstd::vector (デフォルトのまま)
      std::greater<ld>     // 昇順 (デフォルトはstd::less<T>)
    > que;
    rep(i,0,n) que.push(v[i]);

    for(int i=1;i<=n-1;i++){
        ld first = que.top();
        que.pop();
        ld second = que.top();
        que.pop();
        que.push((first+second)/2);
    }

    ld ans = que.top();
    cout << ans << endl;
    return 0;
}


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

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int N;
			string[] s1 = Console.ReadLine().Split(' ');
			N = int.Parse(s1[0]);
			string[] s2 = Console.ReadLine().Split(' ');
			int[] a = new int[N];
			for (int i = 0; i < N; i++)
			{
				a[i] = int.Parse(s2[i]);
			}
			int min = int.MaxValue;
			int count = 0;
			int profit = 0;
			for (int i = 1; i < N; i++)
			{
				if (min > a[i - 1])
				{
					min = a[i - 1];
				}
				if (profit < a[i] - min)
				{
					profit = a[i] - min;
					count = 0;
				}
				if (profit == a[i] - min)
				{
					count++;
				}
			}
			Console.WriteLine(count);

		}

	}
}


Measured memory_bytes: 12120
#include <iostream>
#include <vector>

using namespace std;

long long gcd(long long a, long long b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int twonum = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;

		int tmp = a[i], tmpcnt = 0;
		while (tmp % 2 == 0) {
			tmp /= 2;
			tmpcnt++;
		}
		if (twonum != -1 && twonum != tmpcnt) {
			cout << 0 << endl;
			return 0;
		}
		twonum = tmpcnt;
	}

	long long l = 1;
	for (int i = 0; i < n; i++) {
		l = lcm(l, a[i]);
		if (l > m) {
			cout << 0 << endl;
			return 0;
		}
	}

	

	// l*1, l*3, l*5...と取っていき、Mを超えるまで続く。
	long long cnt = m / l;

	cout << (cnt + 1) / 2 << endl;


	return 0;

}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll l,r,d;
    cin>>l>>r>>d;
    cout<<(r/d-(l+d-1)/d+1)<<'\n';
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

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

long long solve(long long x, int p)
{
    long long ans = 0, cnt = 0;
    while(x >= p)
    {
        cnt++;
        ans += (x / p);
        x /= p;
    }
    return ans;
}

int main()
{
    long long x;
    cin >> x;
    if(x & 1) return puts("0"), 0;
    cout << min(solve(x, 2), solve((x + 1) / 2, 5)) << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    char c;
    cin >> c;

    string ans;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    {
        ans = "vowel";
    }
    else
    {
        ans = "consonant";
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
import numpy as np

N,M = map(int,input().split())
OK = np.zeros(N, dtype = int)
NG = np.zeros(N, dtype = int)
for i in range(M):
    p,s = map(str,input().split())
    p = int(p)
    if s == 'AC':
        s = 1
        OK[p-1]=1
    else:
        if OK[p-1]==0:
            NG[p-1]+=1
    
cOK = sum(OK)
cNG = sum(NG[OK==1])

print(cOK, cNG)

Measured memory_bytes: 15784
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  int r, g, b, n; cin >> r >> g >> b >> n;

  int ans = 0;
  for (int i = 0; i < 3001; ++i){
    for (int j = 0; j < 3001; ++j){
      if ((n - (r * i + g * j)) == 0) ++ans;
      else if ((n - (r * i + g * j)) % b == 0 && (n - (r * i + g * j)) >= 0) {++ans;}     
    }
  }

  print(ans);

  return 0;
}

Measured memory_bytes: 256
# ワーシャルフロイド
def warshall_floyd(n, d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])


H, W = map(int, input().split())

N = 10
d = [None] * N
for i in range(N):
    d[i] = list(map(int, input().split()))
warshall_floyd(N, d)

m = [d[i][1] for i in range(N)]

result = 0
for i in range(H):
    for j in map(int, input().split()):
        if j == -1:
            continue
        result += m[j]
print(result)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int cnt4=0,cnt2=0,cnt=0;
	rep(i,n){
		int a;
		cin >> a;
		if(a%4==0) cnt4++;
		else if(a%2==0) cnt2++;
		else cnt++;
	}
	if((cnt4+1==cnt && cnt2==0) || cnt4>=cnt) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    string s; cin>>s;
    int g=0,p=0,same=-1;
    rep(i,s.size()){
        if(s.at(i)=='g') g++;
        else p++;
        if(g==p) same=i;
    }
    p=0;
    for(int i=same+1; i<s.size(); i++){
        if(s.at(i)=='p') p++;
    }
    cout<<(s.size()-same-1)/2-p;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,x,y;

int main(){
  ll ans=0;
  cin >> n >> x>>y;
  x--;
  y--;
  vi a(n),b(n);


  REP(i,n-1){

    if (i<x){
      for(ll j=i+1;j<n;j++){
        ll leg=0;
        if (j<=x)leg=j-i;
        if (j>=y)leg=x-i+(j-y)+1;
        if ((j>x)&(j<y)){
          leg=min(j-i,x-i+1+(y-j));
        }
        a[leg]++;
        //cout<<leg<<" "<<i<<" "<<j<<endl;
      }
    }

    if ((i>=x)&(i<=y)){
      for(ll j=i+1;j<n;j++){
        ll leg=0;
        if (j>=y){
          leg=min(j-i,j-y+1+(i-x));
        }

        if (j<y){
          leg=min(j-i,i-x+1+y-j  );
        }

        a[leg]++;
        //cout<<leg<<" "<<i<<" "<<j<<endl;
      }
    }

    if (i>y){
      for(ll j=i+1;j<n;j++){
        ll leg=0;
        leg=j-i;
        a[leg]++;
        //cout<<leg<<" "<<i<<" "<<j<<endl;
      }
    }
    




  }



  REP(i,n-1){
    cout<<a[i+1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int X, Y;
inline int dis(int x, int y)
{
	return x <= y ? y - x : 2100000000;
}
int main()
{
	scanf("%d%d", &X, &Y);
	printf("%d\n", std::min(std::min(dis(X, Y), dis(-X, -Y) + 2), std::min(dis(X, -Y), dis(-X, Y)) + 1));
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i=0; i<n; ++i)cin >> w[i];

  vector<int> psum(n);//あるnまでの和を入れる

  psum[0] = w[0];//初期値

  for(int i=1;i<n; ++i){
    psum[i] = psum[i-1]+w[i];
  }

  int min = abs(psum[n-1] - psum[0] - psum[0]);

  for(int i =1; i < n; ++i){
    int temp = abs(psum[n-1] - psum[i] - psum[i]);
    if(min > temp)min = temp;
  }

  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
def NumToAlph(n):
    num=n%26
    if num==0:
        num=26
    if num==1:
        return 'A'
    elif num==2:
        return 'B'
    elif num==3:
        return 'C'
    elif num==4:
        return 'D'
    elif num==5:
        return 'E'
    elif num==6:
        return 'F'
    elif num==7:
        return 'G'
    elif num==8:
        return 'H'
    elif num==9:
        return 'I'
    elif num==10:
        return 'J'
    elif num==11:
        return 'K'
    elif num==12:
        return 'L'
    elif num==13:
        return 'M'
    elif num==14:
        return 'N'
    elif num==15:
        return 'O'
    elif num==16:
        return 'P'
    elif num==17:
        return 'Q'
    elif num==18:
        return 'R'
    elif num==19:
        return 'S'
    elif num==20:
        return 'T'
    elif num==21:
        return 'U'
    elif num==22:
        return 'V'
    elif num ==23:
        return 'W'
    elif num ==24:
        return 'X'
    elif num==25:
        return 'Y'
    else:
        return 'Z'

def AlphToNum(alph):
    if alph=='A':
        return 1
    elif alph=='B':
        return 2
    elif alph=='C':
        return 3
    elif alph=='D':
        return 4
    elif alph=='E':
        return 5
    elif alph=='F':
        return 6
    elif alph=='G':
        return 7
    elif alph=='H':
        return 8
    elif alph=='I':
        return 9
    elif alph=='J':
        return 10
    elif alph=='K':
        return 11
    elif alph=='L':
        return 12
    elif alph=='M':
        return 13
    elif alph=='N':
        return 14
    elif alph=='O':
        return 15
    elif alph=='P':
        return 16
    elif alph=='Q':
        return 17
    elif alph=='R':
        return 18
    elif alph=='S':
        return 19
    elif alph=='T':
        return 20
    elif alph=='U':
        return 21
    elif alph=='V':
        return 22
    elif alph=='W':
        return 23
    elif alph=='X':
        return 24
    elif alph=='Y':
        return 25
    else:
        return 26
        
N=int(input())
S=str(input())
T=''
for c in range(len(S)):
    T=T+NumToAlph(AlphToNum(S[c])+N)
print(str(T))

Measured memory_bytes: 3192
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let arr = scan_array ~sep:' ' Int.of_string

let memo = Array.make_matrix n n None

let rec solve i j t =
  match memo.(i).(j)with
  | Some v ->  v
  | None ->
    if t then
      if i = j then (arr.(i), 0)
      else
        let v = let (x0, y0) = solve (succ i) j false  in
          let (x1, y1) =  solve i (pred j) false in
          if x0 +arr.(i) -y0 > x1 + arr.(j) - y1 then (x0+arr.(i), y0)
          else (x1+arr.(j), y1)
        in
        memo.(i).(j) <- Some v; v
    else
    if i = j then (0, arr.(i))
    else
      let v = let (x0, y0) = solve (succ i) j true in
        let (x1, y1) = solve i (pred j) true in
        if x0 - y0 - arr.(i) < x1 - y1 - arr.(j) then
          (x0, y0+arr.(i))
        else
          (x1, y1+arr.(j)) in
      memo.(i).(j) <- Some v; v

let () =
  solve 0 (pred n) true
  |> (fun (x, y) -> Printf.printf "%d\n" @@ x-y)


Measured memory_bytes: 251704
#include <stdio.h>

int main()
{
    int n;
    int i, j;
    
    scanf("%d", &n);
    while (n != 0) {
        int ice[10] = {};
        int c;
        
        for (i = 0; i < n; i++) {
            scanf("%d", &c);
            ice[c]++;
        }

        for (i = 0; i < 10; i++) {
            if (ice[i] == 0) {
                printf("-\n");
            } else {
                for (j = 0; j < ice[i]; j++) {
                    putchar('*');
                }
                putchar('\n');
            }
        }

        scanf("%d", &n);
    }

    return 0;
}



Measured memory_bytes: 2528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int h,w,m;
    cin>>h>>w>>m;
    map<pair<int,int>,int> mp;
    vector<ll> ch(h,0);
    vector<ll> cw(w,0);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        mp[{a,b}]++;
        ch[a]++;
        cw[b]++;
    }
    ll mx=0;
    vector<int> x;
    rep(i,h) mx=max(mx,ch[i]);
    rep(i,h){
        if(ch[i]==mx) x.push_back(i);
    } 
    ll my=0;
    vector<int> y;
    rep(i,w) my=max(my,cw[i]);
    rep(i,w){
        if(cw[i]==my) y.push_back(i);
    } 

    //cout<<mx<<" "<<my<<endl;
    
    for(auto eh : x){
        for(auto ew : y){
            if(mp[{eh,ew}]==0){
                cout<<mx+my<<endl;
                return 0;
            }
        }
    }

    cout<<mx+my-1<<endl;
}

Measured memory_bytes: 30904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (1<<18);
typedef pair<int,int> ii;
int n;
int v[N],w[N];
ll dp[512][100005];
vector<ii> V;
int q;
int main(){
    scanf("%d",&n);
    int _n = 0;
    int CUR = n;
    while (CUR) { CUR /= 2; _n++; }
    for (int i = 1; i <= n; i++){
        scanf("%d%d",&v[i],&w[i]);
    }
    int U = (1<<((_n+1)/2));
    for (int i = 1; i < U; i++){
        int P = i/2;
        for (int j = 0; j <= 100000; j++){
            if (j >= w[i]) dp[i][j] = max(dp[P][j],dp[P][j-w[i]]+v[i]);
            else dp[i][j] = dp[P][j];
        }
        for (int j = 1; j <= 100000; j++){
            dp[i][j] = max(dp[i][j],dp[i][j-1]);
        }
    }
    scanf("%d",&q);
    for (int Q = 1; Q <= q; Q++){
        int x,L;
        scanf("%d%d",&x,&L);
        if (x < U){
            printf("%lld\n",dp[x][L]);
        }
        else{
            V.clear();
            while (x >= U){
                V.push_back({v[x],w[x]});
                x >>= 1;
            }
            int nn = (int)V.size();
            ll ans = 0;
            for (int mask = 0; mask < (1<<nn); mask++){
                ll tW = 0, tV = 0;
                for (int i = 0; i < nn; i++){
                    if (mask>>i & 1){ tW += V[i].second, tV += V[i].first; }
                }
                if (tW > L) continue;
                ans = max(ans,tV + dp[x][L-tW]);
            }
            printf("%lld\n",ans);
        }
    }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const long long MOD=(long long)1e9 + 7;

// Problem Specific Parameter:

int main() {
  long long N, M; cin >> N >> M;
  if(abs(N-M) >= 2) cout << 0 << endl;
  else {
    if(abs(N-M) == 1) {
      long long sum = 1;
      for(long long i = 1; i <= N; ++i) {
        sum = sum % MOD * i;
      }
      sum %= MOD;
      long long tsum = 1;
      for(long long i = 1; i <= M; ++i) {
        tsum = tsum % MOD * i;
      }
      tsum %= MOD;
      cout << (sum * tsum) % MOD << endl;
    } else if(N == M) {
      long long sum = 1;
      for(long long i = 1; i <= N; ++i) {
        sum = sum % MOD *i;
      }
      sum %= MOD;
      cout << 2 * sum % MOD * sum % MOD << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>           // printf(), scanf()
#include <cmath>            // sqrt(), sin(), cos(), atan2(), acos()
#include <algorithm>        // swap()
#include <utility>          // pair

using namespace std;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }
};

typedef Point Vector;

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

typedef pair<Point, Point> P;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
abs(Vector a)
{
	return sqrt(norm(a));
}

double
arg(Vector p)
{
	return atan2(p.y, p.x);
}

Vector
polar(double a, double r)
{
	return Point(cos(r) * a, sin(r) * a);
}

P
getCrossPoints(Circle c1, Circle c2)
{
	double d = abs(c1.c - c2.c);
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}

int
main(int argc, char** argv)
{
	Circle c1, c2;

	scanf("%lf %lf %lf", &c1.c.x, &c1.c.y, &c1.r);
	scanf("%lf %lf %lf", &c2.c.x, &c2.c.y, &c2.r);

	P p = getCrossPoints(c1, c2);
	if (p.first.x != p.second.x)
	{
		if (p.first.x > p.second.x)
			swap(p.first, p.second);
	}
	else if (p.first.y > p.second.y)
			swap(p.first, p.second);

	printf("%.8f %.8f %.8f %.8f\n", p.first.x, p.first.y, p.second.x, p.second.y);
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans=0;
    ll now=a[0];
    rep(i,n-1){
        if(now<a[i+1]) now=a[i+1];
        else ans+=(now-a[i+1]);
    }
    cout << ans << endl;
return 0;
}

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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)

int cnt[4];
string arr[4] = {"AC", "WA", "TLE", "RE"};

int f(char ch){
    if(ch == 'A') return 0;
    else if(ch == 'W') return 1;
    else if(ch == 'T') return 2;
    else return 3;
}

void solve(){
    
    int n; cin >> n;
    memset(cnt, 0, sizeof(cnt));
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        char ch = s[0];
        cnt[f(ch)]++;
    }
    for(int i : {0,1,2,3}){
        cout << arr[i] << " x " << cnt[i] << '\n';
    }
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
// 	precompute();
	for(int i = 1; i <= t; i++){
	   // cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
fun main(args: Array<String>) {
    while (true) {
        val datasetNum = readLine()!!.toInt()
        if (datasetNum == 0) {
            break
        }
        val dataset = readLine()!!.split(" ").map(String::toDouble)
        val mean = dataset.sum() / datasetNum
        val variance = dataset.map { Math.pow((it - mean), 2.0) }.sum() / datasetNum
        println("${Math.sqrt(variance)}")
    }
}



Measured memory_bytes: 32664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll n;
    cin >> n;

    ll temp = n / 1000;
    ll result = (temp+1) * 1000 - n;

    if(result == 1000){
        cout << 0;
    }
    else{
        cout << result;
    }
}

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

typedef long long ll;
const int maxn=505;

int cnt[maxn];
int vis[maxn];
void init(){
    for(int i=2;i<=200;i++){
        for(int j=i+1;j<=200;j++){
            for(int k=j+1;k<=200;k++){
                int temp=i*j*k;
                if(temp%2==1&&temp<=200){
                    cout<<temp<<endl;
                }
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
//    init();
    while(cin>>n){
        if(n<105)cout<<0<<endl;
        else if(n>=105&&n<135) cout<<1<<endl;
        else if(n>=135&&n<165) cout<<2<<endl;
        else if(n>=165&&n<189) cout<<3<<endl;
        else if(n>=189&&n<195) cout<<4<<endl;
        else cout<<5<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L, R; cin >> L >> R;
    ll ans = 2018LL;

    for(ll k = 1; 2019LL * k <= R; k++)
    {
        if(L <= 2019LL * k and 2019LL * k <= R)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    for(ll i = L; i < R; i++)
    {
        for(ll j = i + 1; j <= R; j++)
        {
            ll k = i * j % 2019LL;
            ans = min(ans, k);
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
using namespace std;
#define INFTY (1<<21)
int target;
string source;
vector<vector<string> > ans;
int diff;

void update(vector<int> c ){
    vector<string> s;
    for ( int i = 0; i < c.size()-1; i++ ){
	s.push_back(source.substr(c[i], c[i+1]-c[i]));
    }
    int sum = 0;
    for ( int i = 0; i < s.size(); i++ ) sum += atoi(s[i].c_str());

    if ( sum > target ) return;

    if ( target - sum == diff ){
	ans.push_back(s);
    } else if ( target - sum < diff ){
	diff = target - sum;
	ans.clear();
	ans.push_back(s);
    }
}

void rec(int pos, vector<int> c){
    if ( pos == source.size() ){
	c.push_back(pos);
	update(c);
	return;
    }
    rec(pos+1, c);
    c.push_back(pos);
    rec(pos+1, c);
    c.pop_back();
}

void compute(){
    vector<int> c;
    c.push_back(0);
    diff = INFTY;
    ans.clear();
    rec(1, c);

    if ( diff == INFTY ) cout << "error" << endl;
    else if ( ans.size() > 1 ) cout << "rejected" << endl;    
    else { 
	cout << target - diff;
	for ( int i = 0; i < ans[0].size(); i++ ) cout << " " << ans[0][i];
	cout << endl;
    }
}

main(){
    while( cin >> target >> source){
	if ( target == 0 && source == "0" ) break;
	compute();
    }
}

Measured memory_bytes: 0
def d_binomial_coefficients(N, A):
    max_a = max(A)  # comb(n,r)のnをこの値以外にする理由はない
    half = max_a / 2  # この値に最も近い整数をcomb(n,r)のrとする
    r = -1
    tmp = float('inf')  # halfとの差の絶対値
    for e in A:
        if e == max_a:
            continue  # nと同じものを選んではいけない
        diff = abs(e - half)
        if diff < tmp:  # n/2により近い整数を発見したなら、更新する
            r = e
            tmp = diff
    ans = '{} {}'.format(max_a, r)
    return ans
N = int(input())
A = [int(i) for i in input().split()]
print(d_binomial_coefficients(N, A))

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll n;
    cin >> n;
    cout << n * (n-1) / 2 << endl;
}


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

int main(){
    int n; cin >> n;
    int cnt, num=0;
    for(int i = 1; i <= n; ++i){
        cnt = 0;
        if(i % 2 == 1){
            for(int j = 1; j <= i; ++j){
                if(i % j == 0){
                    cnt++;
                }
            }
        }
        if(cnt == 8){
            num ++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
## main

loop do
  n, m, h, k = gets.strip.split(' ').map{|s| s.to_i}
  break if (n | m | h | k) == 0

  si = n.times.map{gets.strip.to_i}
  #p si

  hlines = []

  m.times do
    a, b = gets.strip.split(' ').map{|s| s.to_i}
    hlines << [a - 1, b]
  end
  #p hall

  hlines.sort!{|a, b| a[1] <=> b[1]}
  #p hlines

  is = (0...n).to_a

  for hl in hlines
    a = hl[0]
    hl[2] = is[a]
    hl[3] = is[a + 1]

    tmp = is[a]; is[a] = is[a + 1]; is[a + 1] = tmp
  end

  si0 = si.clone

  for hl in hlines.reverse
    a = hl[0]
    hl[4] = si0[a]
    hl[5] = si0[a + 1]

    tmp = si0[a]; si0[a] = si0[a + 1]; si0[a + 1] = tmp
  end

  min_sum = sum = (0...k).inject(0){|sum, i| sum + si0[i]}

  for hl in hlines
    a, b, i0, i1, s0, s1 = hl

    if i0 < k && i1 >= k
      sum0 = sum - s1 + s0
      min_sum = sum0 if min_sum > sum0
    elsif i1 < k && i0 >= k
      sum0 = sum - s0 + s1
      min_sum = sum0 if min_sum > sum0
    end
  end

  puts min_sum
end

Measured memory_bytes: 30896
#include <bits/stdc++.h>
using namespace std;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long n,m,i,j,a,b,c,d,ans=0;
	string s,s1;
	cin>>s;
	map<string,int>mp;
	for(i=0;i<s.length();i++)
	    {
	        s1=s[i];
	        mp[s1]++;
	        if(mp[s1]>1)
	        {
	            cout<<"no";
	            return 0;
	        }
	    }
	cout<<"yes";
	}
}

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

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

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		boolean[] num=new boolean[1000001];
		if(n==2){
			System.out.println(1);
			return;
		}
		long ans=2;
		for(long i=2; i*i<=n; i++){
			if(n%i==0){
				long tmp=n;
				while(tmp%i==0){
					tmp/=i;
				}
				if(tmp%i==1){
					num[(int)i]=true;
				}
			}
		}
		for(long i=2; i*i<=n-1; i++){
			if((n-1)%i==0){
				num[(int)i]=true;
				if(i*i!=n-1){
					ans++;
				}
			}
		}
		for(int i=2; i<1000001; i++){
			if(num[i]){
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25300
N, M, X = list(map(int,input().split()))
A = list(map(int,input().split()))

ans_tmp1 = 0
ans_tmp2 = 0

for j in range(M):
    if A[j] > X and N > A[j]:
        ans_tmp1 += 1
    elif A[j] > N:
        break
    elif A[j] < X:
        ans_tmp2 += 1 

ans = min(ans_tmp1,ans_tmp2)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int count = 0;
    while(a >= b)
    {
        b *= 2;
        count++;
    }
    while(b >= c)
    {
        c *= 2;
        count++;
    }
    if(count <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int M,D;
    cin>>M>>D;
    int ans=0;
    REP(m,1,M){
        REP(d,1,D){
            if(d/10>=2&&d%10>=2&&(d/10)*(d%10)==m)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc105/tasks/abc105_c

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)

#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int target;
    cin >> target;

    if (target == 0) {
        cout << "0" << endl;
        return 0;
    }
    vector<bool> bo;

    for (int i = 0; i < 40 && target != 0; i++) {
        if (target % 2 != 0) {
            bo.push_back(true);
            // cout << "1";
            if (i % 2 == 0) {
                target--;
            } else {
                target++;
            }
        } else {
            bo.push_back(false);
            // cout << "0";
        }
        target /= 2;
    }
    // 逆順にする
    reverse(ALL(bo));
    for (const auto &e : bo) {
        cout << e;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            long len = S.length();
            long count = S.chars().filter(c -> c == 'x').count();
            out.println(8 <= (15 - len) + (len - count) ? "YES" : "NO");
        }

    }
}



Measured memory_bytes: 28628
/*input
1 30
3 5 10 30
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  100005
void solve()
{
	lld cnt=0;
	lld n,m;
	cin >> n >> m;
  	if(m%n==0)
    {	
      cout << m+n << endl;
    }
  	else
    {	
      cout << m-n << endl;
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

vector<ll> data;
ll digit = 0;

void dfs(ll n, ll now) {
  if (n > digit) {
    return;
  }

  data.pb(now);
  dfs(n+1, pow(10, n) * 3 + now);
  dfs(n+1, pow(10, n) * 5 + now);
  dfs(n+1, pow(10, n) * 7 + now);
}

int main() {
  ll n;
  cin >> n;
  ll cpy = n;
  while (cpy > 0) {
    cpy /= 10;
    digit++;
  }

  dfs(1,3);
  dfs(1,5);
  dfs(1,7);
  ll res = 0;
  for (auto itr : data) {
    bool a,b,c; a = b = c = false;
    ll cp = itr;
    while (cp > 0) {
      ll t = cp % 10;
      cp /= 10;
      if (t == 3) a = true;
      if (t == 5) b = true;
      if (t == 7) c = true;
    }
    if (a and b and c) {
      if (itr <= n) {res++;}
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 640
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

alias Mint = ModInt!(10^^9+7);

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto X = s[1];
    auto A = readln.split.map!(to!int).array;
    A.sort!"a > b";

    auto dp = new Mint[][](N+1, 10^^5+1);
    dp[0][X] = Mint(1);

    foreach (i; 0..N) {
        foreach (j; 0..10^^5+1) {
            dp[i+1][j%A[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j] * Mint(N-i-1);
        }
    }

    iota(10^^5+1).map!(i => Mint(i) * dp[N][i]).sum.writeln;
}

// This implementation of ModInt references https://github.com/yosupo06/dunkelheit/blob/master/source/dkh/modint.d

// Manually verified on: https://yukicoder.me/problems/no/117
// Manually verified on: https://atcoder.jp/contests/cpsco2019-s3/tasks/cpsco2019_s3_f

struct ModInt(uint mod) {
    import std.conv : to;

    uint n;

    this(int n) {
        this.n = (n % mod + mod) % mod;
    }

    this(long n) {
        this.n = (n % mod + mod) % mod;
    }

    private this(uint n) {
        this.n = n;
    }

    string toString() const {
        return to!string(this.n);
    }

    private uint normilize(uint n) const {
        return n < mod ? n : n - mod;
    }

    private ModInt pow(uint n, long x) const {
        long ret = 1;
        long a = n;
        while (x) {
            if (x & 1) ret = ret * a % mod;
            a = a * a % mod;
            x >>= 1;
        }
        return ModInt(to!ulong(ret));
    }

    ModInt opBinary(string op : "+")(ModInt rhs) const {
        return ModInt(normilize(n + rhs.n));
    }

    ModInt opBinary(string op : "-")(ModInt rhs) const {
        return ModInt(normilize(n + mod - rhs.n));
    }

    ModInt opBinary(string op : "*")(ModInt rhs) const {
        return ModInt(to!uint(to!long(n) * rhs.n % mod));
    }

    ModInt opBinary(string op : "/")(ModInt rhs) const {
        return this * pow(rhs.n, mod-2);
    }

    ModInt opBinary(string op : "^^")(ModInt rhs) const {
        return pow(this.n, rhs.n);
    }

    ModInt opBinary(string op, T)(T rhs) const {
        ModInt mod_rhs = ModInt(rhs);
        return opBinary!op(mod_rhs);
    }

    ModInt opOpAssign(string op)(ModInt rhs) {
        return mixin ("this=this"~op~"rhs");
    }
}


Measured memory_bytes: 80636