akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=~0u>>2;
int n,m,sum[1<<15],dp[1<<15][15],G[15][15];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int cost(int x,int y){return sum[x|y]-sum[x]-sum[y];}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();m=read();
	for(int i=1;i<=m;++i){
		int x=read(),y=read(),z=read();
		x--;y--;
		G[x][y]=G[y][x]=z;
	}
	for(int i=1;i<(1<<n);++i){
		for(int j=0;j<n;++j) if(i&(1<<j)){
			for(int k=j+1;k<n;++k) if(i&(1<<k)) sum[i]+=G[j][k];
		}
	}
	for(int i=1;i<(1<<n);++i) for(int j=0;j<n;++j) dp[i][j]=INF;
	dp[1][0]=0;
	for(int i=1;i<(1<<n);++i){
		for(int j=0;j<n;++j) if(dp[i][j]!=INF){
			for(int k=0;k<n;++k) if(!(i&(1<<k))&&G[j][k]) dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],dp[i][j]+cost(i^(1<<j),1<<k));
			for(int k=((1<<n)-1)&(~i);k>0;k=(k-1)&(~i)) dp[i|k][j]=min(dp[i|k][j],dp[i][j]+cost(i^(1<<j),k));
		}
	}
	printf("%d",dp[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 2304
l,r = [int(i) for i in input().split()]
if(r//2019>l//2019):print(0)
else:
  r=r%2019
  l=l%2019
  if(r<=l):
    print(0)
  else:
    m=10**10
    for i in range(l,r):
      for j in range(i+1,r+1):
        m=min(m,(i*j)%2019)
    print(m)


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

int main(){
	int N;
	cin >> N;
	int numyaku=0;
	int total=0;
	int judge;
	for(int i=1;i<=N;i=i+2){
		for(int j=1;j<=i;j++){
			judge=i%j;
			if(judge==0)numyaku++;
		}
		if(numyaku==8)total++;
		numyaku=0;

	}
	cout << total;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    
    for (int button_i = 0; button_i < n; button_i++) {
        int ne;
        cin >> ne;
        ne--;
        b.at(button_i) = ne;
    }
    
    int x = 0;
    for (int count = 0;; count++) {
        if (x == 1) {  
            cout << count << endl;
            break;
        }

        if (count >= n) {
            cout << -1 << endl;
            break;
        }
        
        x = b.at(x);
    }
}

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

int dp[4];
int tmp[4];
const int inf = 1<<29;

int main() {
    int n,p,t;
    while(cin>>n, n) {
        int pos = 0,time = 0;
        int ans = inf,ng = -1;
        dp[0] = 0;
        dp[1] = dp[2] = dp[3] = inf;

        for(int i=0; i<n; ++i) {
            tmp[0] = tmp[1] = tmp[2] = tmp[3] = inf;
            cin>>p>>t;

            for(int k=0; k<4; ++k) {
                if(dp[k] == inf) continue;
                if(k != 3)
                    if((abs(pos-p)*(k+1)) <= t-time) {
                        int c = dp[k] + abs(pos-p);
                        tmp[k+1] = min(tmp[k+1], c);
                    }

                if(k != 0)
                    if(pos*(k+1)+p <= t-time)
                        tmp[1] = min(tmp[1], dp[k]+pos+p);
            }

            bool ok = false;
            for(int k=0; k<4; ++k) {
                dp[k] = tmp[k];
                if(dp[k] != inf) ok = true;
            }

            if(!ok && ng == -1) {
                ng = i+1;
            }

            pos = p;
            time = t;
        }

        for(int k=0; k<4; ++k) ans = min(ans, dp[k]+pos);
        if(ans == inf) cout<<"NG "<<ng<<endl;
        else cout<<"OK "<<ans<<endl;

    }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

struct MyStruct{int from, to, cost;};

MyStruct D[1003];
long long int G[103][103];
using namespace std;
int main() {
	long long int N, M;
	cin >> N >> M;
	long long int a, b, c;
	for (int i = 0; i < 102; i++) {
		for (int j = 0; j < 102; j++) {
			G[i][j] = 100000000;
		}
	}
	for (int i = 0; i < 103; i++) {
		G[i][i] = 0;
	}

	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		G[a][b] = c;
		G[b][a] = c;
		D[i].from = a;
		D[i].to = b;
		D[i].cost = c;
	}
	
	
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				
				
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
			}
		}
	}

	int Y = 0;
	for (int j = 0; j < M; j++) {
		for (int i = 1; i <= N; i++) {
			if (i!=D[j].to) {
				if (G[i][D[j].to] == D[j].cost + G[i][D[j].from]) {
					Y++;
					
					goto go;;
				}
			}

		}
	go:;
	}
	
	cout << M-Y  << endl;
	return 0;
}


Measured memory_bytes: 384
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int[] a = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1,
				4, 1, 51 };

		int K = sc.nextInt();

		sc.close();

		out.println(a[K - 1]);

	}

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


Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
using namespace std;
const int N = 200005;
typedef long long ll;
int a[N];
int b[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
   }
   sort(a+1,a+1+n);
    int mid=n/2;
    for(int i=1;i<=n;i++){
        if(b[i]<=a[mid])
        printf("%d\n",a[mid+1]);
        else
        printf("%d\n",a[mid]);
    }
}

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

int main()
{
    ios::sync_with_stdio(false);
    int n, t, c, x, menor = 1001, pos = 1001;
    cin >> n >> t;

    while (n--)
    {
        cin >> c >> x;
        if (x <= t && c < menor)
        {
            menor = c;
            pos = x;
        }
    }

    if (pos <= t)
    {
        cout << menor << endl;
    }
    else
    {
        cout << "TLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int N;
	scanf ("%d", &N);
	
	int firstdigit = N / 100;
	int seconddigit = (N % 100) / 10;
	int thirddigit = N % 10;
	
	if (firstdigit == 7 || seconddigit == 7 || thirddigit == 7){
		printf ("Yes");
	}
	else {
		printf ("No");
	}
	return 0;
}

Measured memory_bytes: 1712
<?php
list($n, $k) = ints();
$a = ints();
$f = ints();
sort($a);
rsort($f);
$max = 0;
for ($i = 0; $i < $n; ++$i)
    $max = max($max, $a[$i] * $f[$i]);
// 二分探索
$ok = $max;
$ng = -1;
while (abs($ok - $ng) > 1) {
    $mid = intdiv($ok + $ng, 2);
    // 各完食時間を mid 以下にするためには i を最低何回修行させるかカウント
    $cnt = 0;
    for ($i = 0; $i < $n; ++$i) {
        // a * f <= mid, a <= mid / f
        $cnt += max(0, $a[$i] - intdiv($mid, $f[$i]));
    }
    if ($cnt <= $k) $ok = $mid;
    else $ng = $mid;
}
echo $ok;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 44156
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[200020];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    priority_queue<long long> que;
    que.push(a[n - 1]);
    long long ans = 0;
    for (int i = n - 2; i >= 0; i--) {
        ans += que.top();
        que.pop();
        que.push(a[i]);
        que.push(a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6812
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 20;
int sz[maxn], maz[maxn][maxn], p[maxn], bir[maxn];
bool on[maxn];

int main(){
	int n,m;
	cin>>n>>m; 
	for (int i=1;i<=m;i++){
		cin>>sz[i];
		for (int j=1;j<=sz[i];j++) {
			cin>>maz[i][j];
			maz[i][j]--;
		}
	}
	for (int i=1;i<=m;i++) cin>>p[i];
	
	bir[0] = 1;
	for (int i=1;i<=12;i++) bir[i] = bir[i-1] << 1;
	
	int ans = 0;
	for (int st=0;st<bir[n];st++){
//		cout<<"st = "<<st<<endl;
		for (int i=0;i<n;i++) on[i] = !!(st & bir[i] );
//		for (int i=0;i<n;i++) cout<<on[i]<<" ";cout<<endl;
		
				
		bool flag = true;
		for (int i=1;i<=m;i++){
			int now = 0;
			for (int j=1;j<=sz[i];j++) if (on[maz[i][j]]) now ^= 1;
//			cout<<"now = "<<now<<"\tp[i] = "<<p[i]<<endl; 
			if (now != p[i]) {flag = false;break;}
		}
		if (flag) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php
$p='';
while(1){
  list($a,$o,$b)=explode(' ',trim(fgets(STDIN)));
  if($o=='?'){break;}
  switch($o){
    case '+':$p.=$a+$b;break;
    case '-':$p.=$a-$b;break;
    case '*':$p.=$a*$b;break;
    case '/':$p.=floor($a/$b);break;
  }
  $p.=PHP_EOL;
}
print $p;

Measured memory_bytes: 15416
#include <bits/stdc++.h>
using namespace std;
int n,m,x,y,cnt;
int pot[100005];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        pot[x]^=1,pot[y]^=1;
    }
    for(int i=1;i<=n;i++,cnt+=pot[i])
    {
        if(pot[i]&&cnt) {puts("NO");return 0;}
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

int main() {
    using namespace std;
    int n;
    string s;
    cin >> n >> s;
    string out;
    out = "";
    char next;
    // cout << s.size();
    for (int i=0; i < s.size(); i++){
        // cout << s[i] + n;
        next = s[i] + n;
        if (next > 'Z') next = s[i] + n - 26;
        out += next;
        // cout << out;
    }
    cout << out;
}

Measured memory_bytes: 3624
#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 bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();

    vector<vll> dp(n+1, vll(4));
    dp[0][0] = 1;

    string T = "ABC";
    rep(i, n){
        char c = in[i];

        rrep(j, 4){
            ll cur = dp[i][j];
            if(cur == 0LL) continue;

            // stay
            dp[i + 1][j] = MUL(cur, c == '?' ? 3LL:1LL);
            if(j == 3) continue;

            // go forward
            if(c == T[j] or c == '?'){
                ll& nxt = dp[i + 1][j + 1];
                nxt = ADD(nxt, cur);
            }
        }
    }

    cout << dp[n].back() << endl;

    return 0;
}


Measured memory_bytes: 7376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

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

void solve(int ca){
    int N;
    string S;
    cin>>N>>S;
    ll ans=0;
    vector<int> red(N+1,0),green(N+1,0),blue(N+1,0);
    for (int i = 0; i < N; ++i) {
        red[i+1]=red[i]+((S[i]=='R')? 1:0);
        green[i+1]=green[i]+((S[i]=='G')? 1:0);
        blue[i+1]=blue[i]+((S[i]=='B')? 1:0);
    }

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if(S[i]==S[j]) continue;
            if(S[i]!='R'&&S[j]!='R'){
                ans+=red[N]-red[j+1];
                if(j+j-i<N&&S[2*j-i]=='R') ans--;
            }
            if(S[i]!='G'&&S[j]!='G'){
                ans+=green[N]-green[j+1];
                if(j+j-i<N&&S[2*j-i]=='G') ans--;
            }
            if(S[i]!='B'&&S[j]!='B'){
                ans+=blue[N]-blue[j+1];
                if(j+j-i<N&&S[2*j-i]=='B') ans--;
            }
        }
    }
    cout<<ans<<"\n";
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,k,c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> l,r;
  rep(i,n)if(s[i]=='o'){
    l.emplace_back(i);
    if(l.size()==k) break;
    i += c;
  }
  for(int i=n-1; i>=0; i--) if(s[i]=='o'){
    r.emplace_back(i);
    if(r.size()==k) break;
    i -= c;
  }
  sort(r.begin(),r.end());
  rep(i,k){
    if(l[i]==r[i]){
      cout << l[i]+1 << endl;
    }
  }
  return 0;
}

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

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

  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }

  int pre = -999;
  for(int i = 0; i < N; i++){
    if(pre <=  H[i] - 1){
      pre = H[i] - 1;
    }else if(pre <= H[i]){
      pre = H[i];
    }else{
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
 
  return 0;
}

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

using namespace std;

typedef long long ll;

ll pow_mod(ll x,ll k,int MOD) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

inline int gcd(int x,int y) {
  return (x%y==0)?y:gcd(y,x%y);
}

inline ll lcm(int x,int y) {
  return (ll)x/gcd(x,y)*y;
}

int getphi(int n) {
  int s=n,t=n;
  for(int i=2;i*i<=t;i++)
    if (n%i==0) {
    	s=s/i*(i-1);
    	while (n%i==0) n/=i;
	}
  if (n>1) s=s/n*(n-1);
  return s;
}

void exgcd(ll a,ll b,ll &x,ll &y) {
  if (!b) {
  	x=1;y=0;
  }
  else {
  	exgcd(b,a%b,y,x);
  	y-=(a/b)*x;
  }
}

ll getinv(ll x,ll MOD) {
  ll t1,t2;
  exgcd(x,MOD,t1,t2);
  return (t1%MOD+MOD)%MOD;
}

ll excrt(int n,int m,ll x,ll y) {
  ll v=lcm(n,m);
  int d=gcd(n,m);
  n/=d;m/=d;
  ll ans=((y-x)/d%m+m)*getinv(n,m)%m;
  return (ans*n*d+x)%v;
}

ll solve(int a,int n) {
  if (n==1) return 1;
  int m=getphi(n);
  ll x=solve(a,gcd(n,m)),y=pow_mod(a,x,n);
  x%=m;
  ll ans=excrt(m,n,x,y);
  if (ans<=m) ans+=lcm(n,m);
  return ans;
}

int main() {
  int cases;
  scanf("%d",&cases);
  for(;cases;cases--) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	printf("%lld\n",solve(x,y));
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for( int i=0; i<N; i++ ){
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  
  int old = d.at(0);
  int num = 1;
  for( int i=1; i<N; i++ ){
    if( old != d.at(i) ){
      num++;
    }
    old = d.at(i);
  }
  
  cout << num << endl;
}


Measured memory_bytes: 3620
use std::collections::*;
use std::io;
use std::io::prelude::*;

fn main() {
    let t_cases = 1usize;
    // (0..t_cases).for_each(|_| solvea()); // run every test case
    // (0..t_cases).for_each(|_| solveb());
    (0..t_cases).for_each(|_| solvec());

}

// solve every test case
fn solvea(){
    let mut buf  = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().to_owned().parse::<f64>().unwrap();
    println!("{}",2f64*3.14159265*n);
}

fn solveb(){
    let mut buf  = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf.trim().split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect::<Vec<_>>();
    let (n,_) = (a[0],a[1]);
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<_>>()
                .iter()
                .sum::<i32>();
    if a<=n{
        println!("{}",n-a);
    }else{
        println!("{}",-1);
    }
}

fn solvec(){
    let mut buf  = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().to_owned().parse::<usize>().unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf.trim().split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect::<Vec<_>>();
    let mut dp = vec![0i32;n];
    for i in 0..(n-1){
        dp[(a[i]-1) as usize]+=1;
    }
    for item in dp{
        println!("{}",item);
    }
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn=1e6+10;
int main(){
	fast;
	ll t,n,h=0; cin>>n;
	vector<int> arr(n);
	for(auto &it:arr)cin>>it;
	for(auto i=0;i+1<n;++i){
		if(arr[i+1]<arr[i]){
			h+=abs(arr[i+1]-arr[i]);
			arr[i+1]=arr[i];
		}
	}
	cout<<h<<'\n';
	return 0;
}
//prime func
//subset production
//factorization
 
//Trees
//Graphs(dfs,bfs,shortes path etc.)
//DP-Recursion

Measured memory_bytes: 3960
#include <iostream>
#include <cstring>
#include <stdio.h>

using namespace std;

int main() {
    char ch;
    int counter[26] = {};

    //loop
    while (cin >> ch){
        ch = tolower(ch);
        if(isalpha(ch)) {
            counter[ch - 'a']++;
        }
    }
    for (int i = 0; i < 26 ; ++i) {
        printf("%c : %d\n", i+'a',counter[i]);

    }
    return 0;
}

Measured memory_bytes: 1128
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    char prev = ' ';
    for(int i = 0; i < s.length(); i++){
        if(i == 0){
            prev = s[i];
            continue;
        }
        if(s[i] == prev){
            cnt++;
            if(prev == '0') prev = '1';
            else prev = '0';
        }else{
            prev = s[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

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


using namespace std;

int main() {
	int n;
	cin >> n;
	long long* a, * b, * c;
	a = new long long[n];
	b = new long long[n];
	c = new long long[n];
	for (int j = 0;j < n;j++) {
		cin >> a[j];
	}
	for (int j = 0;j < n;j++) {
		cin >> b[j];
	}
	for (int j = 0;j < n;j++) {
		cin >> c[j];
	}
	long long count = 0;
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	for (int i = 0;i < n;i++) {
		count += (lower_bound(a, a + n, b[i]) - a) * (n - (lower_bound(c, c + n, b[i] + 1) - c));
	}
	cout << count << "\n";
}




Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine((input[0] - 1) * (input[1] - 1));
        }
    }
}

Measured memory_bytes: 13268
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	string x, y;
	for (int i = 0; i < b; ++i) {
		x += a + '0';
	}
	for (int i = 0; i < a; ++i) {
		y += b + '0';
	}
	if (x < y) cout << x;
	else cout << y;
	return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int n;
	char s;
	bool y = false;
	scanf("%d", &n);
	rep(i, n){
		scanf("%c", &s);
		if (s == 'Y') {
			printf("Four\n");
			y = true;
			break;
		}
	}
	if (!y)printf("Three\n");

	return 0;
}


Measured memory_bytes: 128
inf = 10**18
A,B,C,K = map(int,input().split(" "))
if K % 2 == 1:
	if (B-A) > inf:
		print("Unfair")
	else:
		print(B-A)
else:
	if (A-B) > inf:
		print("Unfair")
	else:
		print(A-B)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;

const int N = 1e6+69;

ll n,x,y,k,m,a,b,ans,R,P,S;

char c;
string s,t;

char A[N],C[N];


int main(){

	cin>>n>>k;
	cin>>R>>S>>P;
	for(int i=1;i<=n;i++){
		cin>>C[i];

		if(i<=k){
			if(C[i]=='r') ans += P, A[i] = 'p';
			if(C[i]=='p') ans += S, A[i] = 's';
			if(C[i]=='s') ans += R, A[i] = 'r'; 
			continue; 
		}

		if(C[i]=='r'){
			if(A[i-k]!='p') ans += P, A[i] = 'p';
		}
		if(C[i]=='p'){
			if(A[i-k]!='s') ans += S, A[i] = 's';
		}
		if(C[i]=='s'){
			if(A[i-k]!='r') ans += R, A[i] = 'r';
		}
	}

	cout<<ans<<endl;
	
}

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

//cin.tie(0);
//ios::sync_with_stdio(false);

int main() {
  char a1,a2,a3,a4;
  cin >> a1 >> a2 >> a3 >> a4;
  if (a1==a2 || a2 == a3 || a3 == a4) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
}

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

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

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

    int Sn = 0;
    int n  = N;
    while (n > 0) {
        Sn += n % 10;
        n /= 10;
    }

    if (N % Sn == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main(){
    int a,b;
    int t[102];
    memset(t,0,sizeof(t));
    while(cin>>a>>b){
        if(a!=0){
            t[a]++;
            t[b]++;
        }
        else{
            if(t[1]%2&&t[2]%2){
                for(int i=3;i<101;i++)
                    if(t[i]%2){
                        cout<<"NG"<<endl;
                        goto n;
                    }
                cout<<"OK"<<endl;
            }
            else
                cout<<"NG"<<endl;
        n: memset(t,0,sizeof(t));
        }
    }
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  char c=s[0];
  int ans=0;
  for(int i=1;i<n;i++){
    if(c!=s[i]){
      ans++;
      c=s[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3752
#include<cstdio>
#include<algorithm>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c<'0'||c>'9');
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
}

int a[100000];
int main()
{
	int n,c,k,t,i,f,s;read(n),read(c),read(k);
	if(c==1)return printf("%d\n",n),0;
	for(i=0;i<n;i++)read(a[i]);
	std::sort(a,a+n);

	s=t=1,f=*a;
	for(i=1;i<n;i++)
		if(a[i]-f>k||++t>c)s++,t=1,f=a[i];
	printf("%d\n",s);
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			double r = Double.parseDouble(input);
			double men = r * r * Math.PI;
			double en = 2 * r * Math.PI;
			System.out.println(String.format("%.6f", men) + " " + String.format("%.6f", en));

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16924
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
int hw[305*305][2];
int ans[305*305];
int main()
{
	int h, w, d, Q, L, R;
	scanf("%d%d%d", &h, &w, &d);
	memset(hw, 0, sizeof(hw));
	for (int i = 1;i <= h;i++)
	{
		for (int p = 1;p <= w;p++)
		{
			int n;
			scanf("%d", &n);
			hw[n][0] = i;
			hw[n][1] = p;
		}
	}

	memset(ans, 0, sizeof(ans));
	for (int i = d+1;i <= h*w;i++)
			ans[i] = ans[i-d] + abs(hw[i-d][0] - hw[i][0]) + abs(hw[i-d][1] - hw[i][1]);

	scanf("%d", &Q);
	for (int i = 0;i < Q;i++)
	{
		scanf("%d%d", &L, &R);
		printf("%d\n", ans[R]-ans[L]);
	}
	return 0;
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int Member = sc.nextInt();
    int Point =  sc.nextInt();
    int Times = sc.nextInt();
    int Answers[] = new int[Times];
    int Member_Point[]=new int[Member];
    
    for(int i=0;i<Member;i++){
    	Member_Point[i]=Point-Times;
    }
    for(int i=0;i<Times;i++){
        Answers[i]=sc.nextInt();
    }
    for(int i=0;i<Times;i++){
        Member_Point[Answers[i]-1]+=1;
    }
   for(int i=0;i<Member;i++){
    	if(Member_Point[i]<=0){
      	System.out.println("No");
        }else{
        	System.out.println("Yes");
        } 
    }
  }
}

  

Measured memory_bytes: 81764
def main():
    """
    1 <= i <= N
    p_1 ... p_n
    p_i != p_j
    2 <= N <= 10^5

    p_i != i にする
    最悪、sort(reverse) + αすれば終わりそう
    -> N^2(10^5^2 -> 10^10 NG)

    xx: 12(xx) -> 21(oo)
    xo: 132(xoo) -> 312(ooo)
    ox:
      oは飛ばしてxから始める
    """
    N = int(input())
    p = map(int, input().split())
    n_swap = 0

    p_same = [i == _p for i, _p in enumerate(p, 1)]
    # enumerateでは複製になるのでrangeで回しながら更新
    for i in range(N - 1):
        same = p_same[i]
        if same:
            n_swap += 1
            p_same[i] = p_same[i + 1] = False

    if p_same[-1]:
        n_swap += 1
    print(n_swap)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10680
n, k = map(int, input().split())
a = list(map(int, input().split()))

roopStart = -1
roopCount = 0
firstMove = 0
now = 0
trace = [0] * n

for i in range(2 * n):
    if trace[now] == 1 and roopStart == -1:
        roopStart = now

    if trace[now] == 2:
        break

    if roopStart != -1:
        roopCount += 1
    else:
        firstMove += 1

    trace[now] += 1
    now = a[now] - 1

firstMove -= roopCount

now = 0
if k < firstMove:
    for i in range(k):
        now = a[now] - 1
    print(now + 1)
else:
    for i in range(firstMove):
        now = a[now] - 1

    k -= firstMove
    k %= roopCount
    for i in range(k):
        now = a[now] - 1
    print(now + 1)


Measured memory_bytes: 32252
import math
n = int(input())
num = 0
tmp = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        tmp = math.gcd(i,j) 
        for k in range(1,n+1):
            num += math.gcd(tmp, k)
            tmp == 0
print(num)


Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>

using namespace std;

typedef complex<double> P;

struct Triangle{
    double qr,rp,pq;
};

struct Point{
    double x,y,z;
};

#define EPS (0.05)
#define EQ(a,b) (abs((a)-(b))<EPS)

int main(){

    int t;
    cin>>t;
    while(t--){
        Point p[100];
        int n;
        Triangle org;
        cin>>org.qr>>org.rp>>org.pq;
        cin>>n;
        for(int i = 0; i < n; i++)
            cin>>p[i].x>>p[i].y>>p[i].z;
        // ツ三ツ点ツ選ツづアツづ堕環篠猟チツェツッツク
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    if(i==j||j==k||k==i)
                        continue;
                    // ツ選ツづアツつセツ点ツづ三ツ陛督づーツ催ャツづゥ
                    double pq=sqrt(pow(p[i].x-p[j].x,2)+pow(p[i].y-p[j].y,2)+pow(p[i].z-p[j].z,2));
                    double qr=sqrt(pow(p[j].x-p[k].x,2)+pow(p[j].y-p[k].y,2)+pow(p[j].z-p[k].z,2));
                    double rp=sqrt(pow(p[k].x-p[i].x,2)+pow(p[k].y-p[i].y,2)+pow(p[k].z-p[i].z,2));
                    // ツ三ツ陛督づ個氾、ツ猟ヲツづーツ確ツ認
                    double pqPer=pq/org.pq;
                    double qrPer=qr/org.qr;
                    double rpPer=rp/org.rp;
                    // match
                    if(EQ(pqPer,qrPer)&&EQ(qrPer,rpPer))
                        cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int, input().split()))
import collections
k=list(collections.Counter(a).items())
x=[k[i][0] for i in range(len(k)) if k[i][1]>=2]
y=[k[i][0] for i in range(len(k)) if k[i][1]>=4]
x.sort()
y.sort()
if len(x)>1 and len(y)>1:
    print(max(x[-1]*x[-2], y[-1]**2))
elif len(x)>1:
    print(x[-1]*x[-2])
else:
    print(0)

Measured memory_bytes: 21412
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    YORN((100 * r + 10 * g + b) % 4 == 0);
    return 0;
}

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


int main(){
    int N,count=0,ans=0;
    cin >> N;
    for (int i = 105; i <= N; i++){
        for(int j=1; j<=i; j++){
            if(i%j==0){
                count++;
            }
        }
        if(count==8 && i%2==1){
            ans++;
        }
        count=0;
        
    }
    cout << ans << endl;
    

}


Measured memory_bytes: 256
from sys import stdin
import collections

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
A = collections.Counter(A)
for i in range(M):
    B, C = [int(x) for x in stdin.readline().rstrip().split()]
    A[C] += B 
A = dict(A)
A = dict(sorted(A.items()))

S = 0
j = -1

A_key = list(A.keys())
A_value = list(A.values())

while True:
    if A_value[j] < N:
        S += A_value[j] * A_key[j]
        N -= A_value[j]
        j -= 1
    else:
        S += N * A_key[j]
        break
print(S)

Measured memory_bytes: 63812
class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        n:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x]>self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
#================================================
N,Q=map(int,input().split())
U=Union_Find(N)

X=[]
for _ in range(Q):
    t,u,v=map(int,input().split())
    if t==0:
        U.union(u,v)
    else:
        X.append(1*U.same(u,v))

print("\n".join(map(str,X)))

Measured memory_bytes: 88052
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    ll n, h;
    cin >> n >> h;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(),greater<ll>());
    ll a_max = a.back();
    ll cnt = 0;
    rep(i,n) {
        if(b[i] <= a_max) break;
        if(h <= 0) break;
        cnt++;
        h -= b[i];
    }
    if (h>0) cnt += (h+a_max-1)/a_max;
    /*
    while(h>0) {
        cnt++;
        h-=a_max;
    }*/
    cout << cnt << endl;
}

Measured memory_bytes: 1792
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
#print(T)
cnt = 0
for x in T:
    for q in S:
        #print(str(x) + " " + str(q))
        if x==q:
            cnt += 1
            break
            
print(cnt)


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

namespace Tenka1BC2019_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            var flag1 = a < c && c < b;
            var flag2 = b < c && c < a;
            Console.WriteLine(flag1 || flag2 ? "Yes" : "No");
        }
    }
}


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

int main(){
    int M, N;
    cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    rep(i, 0, N) cin >> A.at(i);
    rep(i, 0, M) cin >> B.at(i);
    rep(i, 0, N - M + 1){
        rep(j, 0, N - M + 1){
            int k = 0;
            while(B.at(k) == A.at(i + k).substr(j, M)){
                k++;
                if (k == M){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

struct st{
    int h,w;
};

int main(){
    int n,w,h;
    while(cin>>n>>w>>h&&(n||w||h)){
        vector<int> p(n),s(n);
        rep(i,n)cin>>p[i]>>s[i];
        
        vector<st> cake;
        cake.pb(st{h,w});
        
        rep(i,n){
            st t = cake[p[i]-1];
            cake.erase(cake.begin()+(p[i]-1));
            int l = s[i];
            l %= t.h+t.w;
            
            if(l<t.w){
                int a = t.w-l;
                int b = l;
                cake.pb(st{t.h,min(a,b)});
                cake.pb(st{t.h,max(a,b)});
            }else if(l>t.w){
                l-=t.w;
                int a = t.h-l;
                int b = l;
                cake.pb(st{min(a,b),t.w});
                cake.pb(st{max(a,b),t.w});
            }
        }
        vector<int> ss;
        rep(i,cake.size())ss.pb(cake[i].h*cake[i].w);
        
        sort(all(ss));
        rep(i,ss.size()){
            if(i)cout<<" ";
            cout<<ss[i];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;

int read();
int M(int x) { return x >= mod ? x - mod : x; }
int fsp(int bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = 1ll * rt * bs % mod;
        bs = 1ll * bs * bs % mod, p >>= 1;
    }
    return rt;
}
int C2(int x) { return x * (x - 1) / 2; }
int fac[10004], caf[10004];
int C(int x, int y) { return 1ll * fac[x] * caf[y] % mod * caf[x - y] % mod; }
void init() {
    int lim = 10000;
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    caf[lim] = fsp(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}

int rtt[20004], O[20004], ny;
void getrtt(int w, int len) {
    for (int i = 1; i < len; ++i) rtt[i] = rtt[i >> 1] >> 1 | ((i & 1) << w);
    for (int l = 2; l <= len; l <<= 1) O[l] = fsp(3, (mod - 1) / l);
    ny = fsp(len, mod - 2);
}

struct Poly {
    int x[20004];
    int &operator[](int p) { return x[p]; }
    void ntt(int len) {
        for (int i = 1; i < len; ++i)
            if (rtt[i] > i) swap(x[rtt[i]], x[i]);
        for (int l = 2; l <= len; l <<= 1) {
            for (int i = 0, m = l >> 1; i < len; i += l) {
                for (int j = i, tO = 1, t; j < i + m; ++j) {
                    t = 1ll * tO * x[j + m] % mod, tO = 1ll * tO * O[l] % mod;
                    x[j + m] = M(x[j] - t + mod), x[j] = M(x[j] + t);
                }
            }
        }
    }
    void idft(int len) {
        ntt(len), reverse(x + 1, x + len);
        for (int i = 0; i < len; ++i) x[i] = 1ll * x[i] * ny % mod;
    }
} f, g, tf;

int n, m;
int main() {
    n = read(), m = read();
    init();
    int w = 1, len = 2;
    while (len < 2 * n + 1) len <<= 1, ++w;
    for (int i = 1; i <= n; ++i) g[i] = caf[i + 2];
    getrtt(w - 1, len), g.ntt(len);
    tf[0] = f[0] = 1;
    for (int i = 1; i <= m; ++i) {
        f.ntt(len);
        for (int j = 0; j < len; ++j) f[j] = 1ll * f[j] * g[j] % mod;
        f.idft(len);
        for (int j = 0; j <= n; ++j) {
            tf[j] = M(1ll * f[j] * fac[j + 2] % mod +
                      1ll * tf[j] * (1 + j + C2(j)) % mod);
            f[j] = 1ll * tf[j] * caf[j] % mod;
        }
        for (int j = n + 1; j < len; ++j) f[j] = 0;
    }
    int res = 0;
    for (int i = 0; i <= n; ++i) res = M(res + 1ll * C(n, i) * tf[i] % mod);
    printf("%d\n", res);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
int n,A[100010],B[100010],m;
vector<int> G[100010];
priority_queue<int> Q;
long long ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&A[i],&B[i]);
		if(m>=A[i])G[m-A[i]].push_back(B[i]);
	}
	for(int i=m;i>=0;i--){
		for(int j=0;j<G[i].size();j++)Q.push(G[i][j]);
		if(!Q.empty())ans+=Q.top(),Q.pop();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6400
//グローバル変数定義
var N = 0;
var A = 0;
var B = 0;
var C = 0;
var T = [];	//N本の竹の長さを配列BBに格納する

function FullSearch(){

  var LastMP = Infinity;

  //最大8本の竹を4つのグループに分けるループ処理
  for(var a=0 ; a<4 ; a++){
    for(var b=0 ; b<4 ; b++){
      for(var c=0 ; c<4 ; c++){
        for(var d=0 ; d<4 ; d++){
          for(var e=0 ; e<4 ; e++){
            for(var f=0 ; f<4 ; f++){
              for(var g=0 ; g<4 ; g++){
                for(var h=0 ; h<4 ; h++){
                  //計算処理
                  var memo = [a,b,c,d,e,f,g,h];
                  var ans0 = 0; //何にも使わない
                  var ansA = 0; //A用回答
                  var cntA = 0; //A用カウンタ
                  var ansB = 0; //B用回答
                  var cntB = 0; //B用カウンタ
                  var ansC = 0; //C用回答
                  var cntC = 0; //C用カウンタ
                  for(var i=0 ; i<N ; i++){
                    if( memo[i]==1 ){
                      ansA += T[i];
                      cntA += 1;
                    } else if (memo[i]==2){
                      ansB += T[i];
                      cntB += 1;
                    } else if (memo[i]==3){
                      ansC += T[i];
                      cntC += 1;
                    } else {
                      //何にも使わない＝何もしない
                    }
                  }
                  //A～Cのどれにも竹が割りあたっていない場合はスキップ
                  if(cntA*cntB*cntC > 0){
                    
                    //console.log(memo,ansA,ansB,ansC);
                    
                    //使用MP計算処理
                    var MP = 0;
                    //A用
                    MP += Math.abs(ansA-A);
                    MP += 10 * ( cntA -1 );
                    //B用
                    MP += Math.abs(ansB-B);
                    MP += 10 * ( cntB -1 );
                    //C用
                    MP += Math.abs(ansC-C);
                    MP += 10 * ( cntC -1 );
                    //MPの記録
                    if( LastMP > MP ){
                      LastMP = MP;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return LastMP;
}
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  N = Number.parseInt(inputStr[0]);
  A = Number.parseInt(inputStr[1]);
  B = Number.parseInt(inputStr[2]);
  C = Number.parseInt(inputStr[3]);
  //N本の竹の長さを配列BBに格納する
  for( var i=0 ; i<N ; i++ ){
    T.push(Number.parseInt(input[i+1].split(" ")));
  }
  console.log(FullSearch());
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
	long long int n,k,ans=INT_MAX;
  cin >> n >> k;
  long long int x[n];
  for (int i=0;i<n;i++)cin >> x[i];
  for (int i=0;i<n-k+1;i++){
    ans=min(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
    ans=min(ans,abs(x[k+i-1])+abs(x[i+k-1]-x[i]));
  }
  cout << ans <<endl;
}


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

using namespace std;

int main()
{

    int N;
    cin >> N;
    bool ada  = false;
    for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i * j == N){
				cout << "Yes" << endl;
				return 0;
			}
		}
    }

    if(!ada){
		cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int number_of_elements = sc.nextInt();
      	int intArray[] = new int[number_of_elements];
      	int index = 0;
      	while(sc.hasNextInt()){
          intArray[index] = sc.nextInt();
          index++;
        }
      int dpArray[] = new int[intArray.length];
      int cost = 0;
      dpArray[0]=0;
      dpArray[1]=Math.abs(intArray[1]-intArray[0]);
      for(int i =2 ;i<dpArray.length;i++){
      	dpArray[i]=Math.min(dpArray[i-2]+Math.abs(intArray[i]-intArray[i-2]),dpArray[i-1]+Math.abs(intArray[i]-intArray[i-1]));
      }
      System.out.println(dpArray[dpArray.length-1]);
	}
}


Measured memory_bytes: 52116
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

string s;

void init()
{
}

void solve()
{
    int ans1 = 0, ans2 = 0;
    REP(i, s.size()) s[i] -= '0';
    string s1(s), s2(s);
    FOR(i, 1, s1.size()){
        if(s1[i] == s1[i-1]){
            s1[i] = 1 - s1[i];
            ans1++;
        }
    }
    REPR(i, s2.size()-2){
        if(s2[i] == s2[i+1]){
            s2[i] = 1 - s2[i];
            ans2++;
        }
    }
    cout << min(ans1, ans2) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 592
import java.util.Scanner;
public class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    
    if(s * t >= d){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
    }
}

Measured memory_bytes: 27068
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   int ans = 0;
   rep(i, 0, s.size()) {
      int j = s.size() - 1 - i;
      if (s[i] != s[j] && i < j) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = 2*pi*r;
        System.out.printf("%f %f", area, length);
        sc.close();
    }
}


Measured memory_bytes: 28288
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n ; cin >>n;
  vector<ll> a(n);
  rep(i,n)  cin >>a[i];
  deque<ll> dq;
  ll key=0;
  rep(i,n){
    if(key%2==0) dq.push_back(a[i]);
    else dq.push_front(a[i]);
    key++;
  }
  if(key%2==1) reverse(all(dq));
  rep(i,n-1) cout <<dq[i]<<" ";
  cout <<dq[n-1]<<endl;
}

Measured memory_bytes: 5376