akhauriyash/Code-Regression huggingface dataset:
(defun read-revlist (&optional (N (read)))
  (do ((i N (1- i))
       (l nil (cons (read) l)))
      ((= i 0) l)))

(let ((N (read))
      (M (read))
      (-C (- (read))) )
  (let ((B (read-revlist M))
	(result 0) )
    (dotimes (x N)
      (if (< -C (eval (cons '+ (mapcar #'* B (read-revlist M)))))
	  (setf result (1+ result)) ))
    (princ result) ))

Measured memory_bytes: 6504
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int cnt = 0;
		for(int a = 0; a<= A; a++){
			for(int b = 0; b<=B; b++){
				for(int c = 0; c<=C; c++){
					if(500*a+100*b+50*c==X){
						cnt++;
					}
				}
			}
		}
		int 	ans = cnt;
		System.out.println(ans);
	}
}

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

int N;
vll A;
ll left_cum[100001], right_cum[100001];

int main(){
  cin>>N;
  for (int i=0;i<N;++i){ll a;cin>>a;A.push_back(a);}

  left_cum[0]=A[0];right_cum[N-1]=A[N-1];
  for (int i=1;i<N;++i){
    left_cum[i]=__gcd(left_cum[i-1], A[i]);
    right_cum[N-i-1]=__gcd(right_cum[N-i], A[N-i-1]);
  }

  ll ans=max(left_cum[N-2], right_cum[1]);
  if(N==2){cout << ans << endl;return 0;}
  for (int i=1;i<N-1;++i){
    ll tmp=__gcd(left_cum[i-1], right_cum[i+1]);
    ans=max(ans, tmp);
  }

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

Measured memory_bytes: 2676
import java.util.Scanner;

public class Main {
	private static final String _1 = "1";

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		StringBuilder sb = new StringBuilder();
		do {
			sb.setLength(0);
			int[] point = new int[m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (_1.equals(in.next())) {
						point[j] += 1;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				int cp = n - i;
				for (int j = 0; j < m; j++) {
					if (point[j] == cp) {
						sb.append(' ');
						sb.append(j + 1);
					}
				}
			}
			System.out.println(sb.substring(1));
			n = in.nextInt();
			m = in.nextInt();
		} while (n != 0 || m != 0);
		in.close();
	}
}

Measured memory_bytes: 68700
#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7
typedef long long ll; 
 
 int main(){
  ios_base::sync_with_stdio(false); 
  ll n,s=1000,c=0,c1=0,i,j,k;
   cin>>n;
   ll a[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   if(is_sorted(a,a+n)){
     for(i=0;i<n-1;i++){
       if(s<a[i]) break;
     c+=s/a[i];
       s=s-c*a[i];
     }
     s+=c*a[n-1];
     cout<<s;
   }
   else if(is_sorted(a,a+n,greater<ll>()))
      cout<<s;
   else{
    for(i=0;i<n-1;i++){
     if(a[i]<a[i+1]&&s>a[i]){
       c+=s/a[i];
       s=s-c*a[i];
     }
      else if(a[i]>a[i+1]&&c!=0) {
        s=s+c*a[i];
        c=0;
      }
      else{c1=0;
      for(j=i+1;j<n-1;j++){
      if(a[j]>a[j+1]) {c1=1;k=j;break;}
      }
        if(c1==1&&c!=0&&k==i){
          s=s+c*a[i];
        c=0;
        }
      }
    }
     s=s+c*a[n-1];
     cout<<s;
   }
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>


int main(int argc, char const *argv[])
{
	int m,f,r;
	while(1){
		scanf("%d %d %d\n",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1)break;
		if(m == -1 || f == -1)printf("F\n");
		else if(m + f >=80)printf("A\n");
		else if(m + f >=65)printf("B\n");
		else if(m + f >=50)printf("C\n");
		else if(m + f >= 30){
			if(r >=50)printf("C\n");
			else printf("D\n");
		}else
		printf("F\n");
	}
	return 0;
}


Measured memory_bytes: 2572
#include<iostream>
#include<istream>
#include<string>
using namespace std;

int main(void) {
	string s;
	string p;
	int length_s,length_p;

		getline(cin, s);
		getline(cin, p);
		s = s + s;

		length_s = s.size();
		length_p = p.size();

		for (int t = 0; t <= length_s-length_p-1; t++) {
			if (s[t] == p[0]) {
				for (int u = 0; u <= length_p-1; u++) {
					if (s[t + u] != p[u]) {
						break;
					}
					if ((s[t + u] == p[u])&&(u==length_p-1)) {
						cout << "Yes" << "\n";
						goto end;
					}
				}
			}
		}
		cout << "No" << "\n";
		end:
	return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int a,b,c,k;
  int sum=0;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k<<endl;
    return 0;
  }else{
    sum+=a;
    k-=a;
    if(b>=k){
      cout<<sum<<endl;
      return 0;
    }else{
      k-=b;
      cout<<sum-k<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int g[100][100];

int solve(vi& vec)
{
    int res = 0;
    rep(i,len(vec)){
        int cri = INF;
        rep(j,len(vec)){
            if(j != i){
                cmn(cri,g[vec[i]][vec[j]]);
            }
        }
        res += cri;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        g[a-1][b-1] = g[b-1][a-1] = c;
    }
    int ans = 0;
    srep(i,2,min(n+1,15)){
        vi vec;
        rep(j,n){
            int cnt = 0;
            rep(k,n){
                if(g[j][k] > 0){
                    cnt++;
                }
            }
            if(cnt >= i-1){
                vec.pb(j);
            }
        }
        if(len(vec) >= i){
            vector<bool> v(len(vec),false);
            fill(v.end() - i, v.end(), true);
            do{
                vi ch;
                rep(j,len(v)){
                    if(v[j]){
                        ch.pb(vec[j]);
                    }
                }
                cmx(ans,solve(ch));
            }while(next_permutation(all(v)));
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3268
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

#define BTCRATE 380000.0

int main(){
	
	int A, B, K;
	int max;
	vector<int> val;
	
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &K);
	
	max = (A > B) ? A : B;
	
	for(int i=1; i<=max; i++){
		if(A%i == 0 && B%i == 0){
			val.push_back(i);
		}
	}
	
	printf("%d\n", val[val.size() - K]);
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    string ans = "";
    while(N) {
        N--;
        ans += (char)('a' + (N % 26));
        N /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


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

long long gcd(long long a, long long b) {
    if (a % b) return gcd(b, a % b);
    else return b;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; long long m; cin >> n >> m;
    vector<long long> a(n);
    set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int x = 0; long long u = a[i];
        while (u % 2 == 0) x++, u /= 2;
        s.insert(x);
    }
    if (s.size() != 1) {
        cout << 0 << "\n";
    } else {
        long long x = 1;
        for (int i = 0; i < n; i++) {
            x = x / gcd(x, a[i] / 2) * (a[i] / 2);
            if (x > m) break;
        }
        cout << m / x - m / (2*x) << "\n";
    }
    return 0;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int H, W;
int sx, sy;
int gx, gy;
string b[1010];
struct edge { int to, cost; };
vector<edge> g[1010101];
int d[1010101];

void dijkstra(int s) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+(H*W), INF);
    d[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<int, int> p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge e : g[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }
}

int dr[] = { 1, 0, -1, 0 };
int dc[] = { 0, 1, 0, -1 };

int main() {
    cin >> H >> W;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--; sx--;
    gy--; gx--;
    rep(i, H) cin >> b[i];

    rep(r, H) rep(c, W) {

        if (b[r][c] == '.') {
            rep(d, 4) {
                int nr = r + dr[d], nc = c + dc[d];
                if (0 <= nr and nr < H and 0 <= nc and nc < W and b[nr][nc] == '.') {
                    g[r * W + c].push_back((edge){nr * W + nc, 0});
                }
            }

            for (int r2 = max(0, r - 2); r2 < min(H, r + 3); ++r2) {
                for (int c2 = max(0, c - 2); c2 < min(W, c + 3); ++c2) {
                    if (b[r2][c2] == '.') {
                        g[r * W + c].push_back((edge){r2 * W + c2, 1});
                    }
                }
            }
        }

    }

    dijkstra(sy * W + sx);
    cout << (d[gy * W + gx] == INF ? -1 : d[gy * W + gx]) << endl;
}


Measured memory_bytes: 122152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define M 1000'000'007ll
typedef vector<vector<ll> > Matrix;
typedef vector<ll> vec;
Matrix operator*(const Matrix &m1, const Matrix &m2) {
    size_t n = m1.size();
    Matrix res(n, vec(n));
    rep(i, n) rep(j, n) rep(k, n) {
        res.at(i).at(j) += m1.at(i).at(k) * m2.at(k).at(j);
        res.at(i).at(j) %= M;
    }
    return res;
}
vec operator*(const Matrix &m, const vec &v) {
    vec res(v.size());
    rep(i, v.size()) rep(j, m.at(0).size()) {
        res.at(i) += m.at(i).at(j) * v.at(j);
        res.at(i) %= M;
    }
    return res;
}
Matrix E(size_t n) {
    Matrix res(n, vec(n));
    rep(i, n) res.at(i).at(i) = 1;
    return res;
}
Matrix pow(const Matrix &a, long long n) {
    Matrix b = a;
    Matrix res = E(a.size());
    while (n > 0) {
        if (n & 1)
            res = res * b;
        b = b * b;
        n >>= 1ll;
    }
    return res;
}

ll n, k;

int main() {
    cin >> n >> k;
    Matrix m = E(n);
    rep(i, n) rep(j, n) cin >> m[i][j];
    m = pow(m, k);
    vec v1 = vec(n, 1);
    vec a = m * v1;
    cout << accumulate(all(a), 0ll) % M << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a=0;
	cin>>n;
		int b;
	while(n>0)
	{
		b=n%10;
		if(b==2)
			a++;
		n=n/10;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int cnt=0,n=s.size();
    for(auto ch:s)if(ch=='1') cnt++;
    cout<<2*min(cnt,n-cnt)<<endl;
}


Measured memory_bytes: 3680
from functools import lru_cache

N, M = map(int, input().split())

@lru_cache(maxsize=None)
def mod_inv(x):
  x1, y1, z1 = 1, 0, x
  x2, y2, z2 = 0, 1, M
  while z1 != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1%M

def gen_Y(i):
  # sC2/1, (s-2)C2/2, (s-4)C2/3  ...
  s = 3*(N-i)
  r = s*(s-1)>>1
  d_r = (s<<1)-3
  for j in range(1, N-i+1):
    yield r * mod_inv(j)
    r -= d_r
    d_r -= 4

def gen_X():
  # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3  ...
  a = N
  b = 3*N - 1
  for i in range(1, N+1):
    yield a * b * (b-1) * mod_inv(i)
    a -= 1
    b -= 3

def acc_mulmod(it, init=1):
  x = init
  yield x
  for y in it:
    x = x*y % M
    yield x

ans = sum(sum(acc_mulmod(gen_Y(i), A)) for i, A in enumerate(acc_mulmod(gen_X())))%M

print(ans)


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

int main() {
	int n, k;
	long long ans = 1;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		if (i == 0)ans *= k;
		else ans *= (k - 1);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans = n;
    while(1){
        int lim = min(ans-1, (int)sqrt(ans)+1);
        bool isprime = true;
        for(int i = 2; i <= lim; i++){
            if(ans % i == 0) isprime = false;
        }
        if(isprime) break;
        ans++;
    }

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

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

int main(){
  int n, x;
  int result;

  while(true){
    cin >> n >> x;
    result = 0;
    if(n==0 && x==0){
      return 0;
    }else{
      for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
          for(int k=j+1; k<n; k++){
            if((i+1)+(j+1)+(k+1) == x){
              //cout << i+1 << "+" << j+1 << "+" << k+1 << "=" << x << endl; 
              result ++;
            }
          }
        }
      }
    }
    cout << result << endl;
  }
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,s) for(int i=s;i>=0;--i)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;
ll n, m, a = 0, A[10101];
void calc() {
	int i, j, MAX = 200;
	for (i = 1; i <= MAX; i++) A[i] = 1;
	for (j = 2; j <= MAX; j++) {
		for (i = j; i <= MAX; i += j) A[i]++;
	}
}
int main() {
	cin >> n;
	calc();
	for (int i = 1; i <= n; i += 2) {
		if (A[i] == 8) a++;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long int
#define pi 3.1415926535897932
using namespace std;
int main()
{
	
	LL n;
	cin>>n;
	LL a[n][3],dp[n+1][4];
	for(LL i=0; i<n ;i++)
	{
		for(LL j=0; j<3; j++)
		cin>>a[i][j];
		
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(LL i=1; i<=n; i++)
	{
		dp[i][0]=a[i][0]+max({dp[i-1][1],dp[i-1][2]});
		dp[i][1]=a[i][1]+max({dp[i-1][0],dp[i-1][2]});
		dp[i][2]=a[i][2]+max({dp[i-1][0],dp[i-1][1]});
	}
	LL ans=max({dp[n-1][0],dp[n-1][2],dp[n-1][1]});
	cout<<ans<<"\n";
		
	
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x,a,b;
    cin >> x >> a >> b;
    if(b<=a){
      cout << "delicious" << endl;
    }
    else if (x>=(b-a)){
    	cout << "safe" << endl;
    }
    else{
    	cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <string>

typedef long long ll;



using namespace std;
int main()
{
	int a[6];
	for (int i = 0; i < 6; i++)
	{
		cin >> a[i];
	}
 	
	for (int i = 0; i < 5; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			if (i == j)
				continue;

			if (abs(a[i] - a[j]) > a[5])
			{
				cout << ":(";
				return 0;
			}
		}
	}

	
	cout << "Yay!";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

ll d = 1e9 + 7;

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    vector <vector <ll>> dp(n+1, vector<ll>(k+2, 0));
    REP(i, k+2){
        if (i>0){
            dp[0][i] = 1;
        }
    }
    for(int i=1; i<n+1; i++){
        for(int j=1; j<k+2; j++){
            ll low_idx = max(ll(0), j-as[i-1]-1);
            dp[i][j] = (d + dp[i][j-1] + dp[i-1][j] - dp[i-1][low_idx]) % d;
        }
    }
    cout << (d + dp[n][k+1] - dp[n][k]) % d << endl;
    return 0;
}

Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int cnt = 0;
    int n = sc.nextInt();
    for(int i = 0; i < n; i++){
      int d1 = sc.nextInt();
      int d2 = sc.nextInt();
      if(d1 == d2) {
        cnt++;
      } else {
        cnt = 0;
      }
      if(cnt >= 3){
        System.out.println("Yes");
        return;
      }
    }
    sc.close();
    System.out.println("No");
  }
}

Measured memory_bytes: 36032
import java.io.*;
import java.util.*;
class Main{
  static Node root = null;
  static StringBuilder bl = new StringBuilder();
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    String [] s = new String[2];
    for(int i = 0; i<n; i++){
      
      s = br.readLine().split("\\s+");
      
      if(s[0].charAt(0) == 'i'){
        
        Insert( Integer.parseInt(s[1]));
        
      }else if(s[0].charAt(0) == 'p'){
        
        inorder(root);
        bl.append("\n");
        preorder(root);
        bl.append("\n");
        
      }else if(s[0].charAt(0) == 'd'){
        delete(find(root, Integer.parseInt(s[1])));
        
      }else{
        
        if( find(root, Integer.parseInt(s[1])) == null){
          bl.append("no\n");
        }else{
          bl.append("yes\n");
        }
        
      }
    }
    System.out.print(bl);
  }
  
  static void Insert (int k){
    Node y = null;
    Node x = root;
    Node z = new Node();
    z.key = k;
    z.left = null;
    z.right = null;
    
    while(x != null){
      y = x;
      if(z.key < x.key){
        x = x.left;
      }else{
        x = x.right;
      }
    }
    z.parent = y;
    
    if( y == null){
      root = z;
    }else if( z.key < y.key){
      y.left = z;
    }else{
      y.right = z;
    }
  }
  
  static Node find(Node u, int k){
    while( u != null){
      if(k == u.key){
        return u;
      }
      if(k<u.key){
        u = u.left;
      }else{
        u = u.right;
      }
    }
    return null;
  }
  
  static void delete(Node u){
    Node y;
    Node x;
    if(u.left == null || u.right == null){
      y = u;
    }else{
      y = getSuccessor(u);
    }
    
    if(y.left != null){
      x = y.left;
    }else{
      x = y.right;
    }
    
    if( x != null){
      x.parent = y.parent;
    }
    
    if(y.parent == null){
      root = x;
    }else{
      if( y == y.parent.left){
        y.parent.left = x;
      }else{
        y.parent.right = x;
      }
      
      if( y !=u){
        u.key = y.key;
      }
    }
    
  }
  
  static Node getSuccessor(Node u){
    if(u.right != null){
      return getMinimum(u.right);
    }
    Node y = u.parent;
    while(y != null && u == y.right){
      u = y;
      y = y.parent;
    }
    return y;
  }
  
  static Node getMinimum(Node u){
    while(u.left !=null){
      u = u.left;
    }
    return u;
  }
  
  static void preorder(Node u){
    if( u == null) return;
    bl.append(" ").append(u.key);
    preorder(u.left);
    preorder(u.right);
  }
  
  static void inorder(Node u){
    if(u == null) return;
    inorder(u.left);
    bl.append(" ").append(u.key);
    inorder(u.right);
  }
  
}

class Node{
  int key;
  Node parent = null;
  Node right;
  Node left;
  Node(){};
}


Measured memory_bytes: 204800
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
int dp[55][55][3000];
signed main(){
  int n,m;cin>>n>>m;
  dp[0][0][0]=1;
  rep(i,n){
    rep(j,n+1){
      rep(k,m+1){
        (dp[i+1][j+1][k+2*j+2]+=dp[i][j][k])%=MOD;
        (dp[i+1][j][k+2*j]+=(2*j+1)*dp[i][j][k])%=MOD;
        if(j>0)(dp[i+1][j-1][k+2*j-2]+=j*j*dp[i][j][k])%=MOD;
      }
    }
  }
  cout<<dp[n][0][m]<<endl;      
  return 0;
}


Measured memory_bytes: 64500
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;

int n,m;
string s[maxn];
int c[maxn][maxn];
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

void dfs(int x, int y, int cc){
  c[x][y] = cc;
  for(int i=0;i<4;i++){
    int nx = x + dir[i][0];
    int ny = y + dir[i][1];
    if(nx<0||ny<0||nx>=n||ny>=m||s[nx][ny]=='#'||c[nx][ny]!=-1)continue;
    dfs(nx, ny,cc);
  }
}

unordered_set<int>st[maxn * maxn];
int d[maxn * maxn];
int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif

  cin>>n>>m;
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  sx--,sy--,tx--,ty--;
  for(int i=0;i<n;i++)cin>>s[i];
  memset(c, -1, sizeof(c));
  int cur = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++){
      if(s[i][j]=='#'||c[i][j]!=-1)continue;
      dfs(i,j,cur++);
    }
  if(c[sx][sy]==c[tx][ty]){
    cout<<0<<endl;
    return 0;
  }
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++){
      if(s[i][j]=='#')continue;
      for(int p=-2;p<=2;p++)
        for(int q=-2;q<=2;q++){
          int x = i + p;
          int y = j + q;
          if(x<0||x>=n||y<0||y>=m||s[x][y]=='#'||c[i][j]==c[x][y])continue;
          st[c[i][j]].insert(c[x][y]);
          st[c[x][y]].insert(c[i][j]);
        }
    }
  memset(d, -1,sizeof(d));
    d[c[sx][sy]] = 0;
    queue<int>q;
    q.push(c[sx][sy]);
    while(!q.empty()){
      int x = q.front();
      q.pop();
      for(auto y: st[x]){
        if(d[y]==-1||d[y]>d[x]+1){
          d[y] = d[x] + 1;
          q.push(y);
        }
      }
    }
    cout<<d[c[tx][ty]]<<endl;
  return 0;
}


Measured memory_bytes: 86340
n = int(input())
a = 10**9 +7
b = pow(10,n,a) + pow(8,n,a) - 2 * pow(9,n,a)
if b >= 0:
    print(b)
elif a+b >=0:
    print(a+b)
else:
    print(a+a+b)

Measured memory_bytes: 9064
#include <stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	long long hasil=0;
	for (int i=1;i<=N;i++){
		if(i%3==0&&i%5==0){
			continue;
		}else if(i%3==0){
			continue;
		}else if(i%5==0){
			continue;
		}else {
			hasil += i;
		}
	}
	printf("%lld",hasil);
return 0;
}

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

int main() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  p(a+b+c-max({a,b,c})+(max({a,b,c})*pow(2,k)));
}


Measured memory_bytes: 256
#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;
int main() {
	int n;
	string s;
	string kl = "", kr = "";
	cin >> n >> s;
	int l = 0, r = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') {
			l++;
		}
		else {
			if (l != 0) {
				l--;
			}
			else {
				r++;
			}
		}
	}
	for (int j = 0; j < l; j++) {
		kr += ")";
	}
	for (int j = 0; j < r; j++) {
		kl += "(";
	}
	l = 0, r = 0;
	cout << kl << s << kr << endl;
}

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

vector <int> D;
bool two;
bool check( int d ) {
    if ( d >= 10 ) {
        bool ok = true;
        for ( int i = 1; i < 10; i++ ) {
            if ( D[i] > 0 ) {
                ok = false;
            }
        }
        return two && ok;
    }
    if ( d+2 < 10 && D[d] > 0 && D[d+1] > 0 && D[d+2] > 0 ) {
        D[d]--;
        D[d+1]--;
        D[d+2]--;
        if ( check(d) ) return true;
        D[d]++;
        D[d+1]++;
        D[d+2]++;
    }
    if ( D[d] >= 3 ) {
        D[d] -= 3;
        if ( check(d) ) return true;
        D[d] += 3;
    }
    if ( !two && D[d] >= 2 ) {
        D[d] -= 2;
        two = true;
        if ( check(d) ) return true;
        two = false;
        D[d] += 2;
    }
    return check(d+1);
}

int main() {
    string line;
    while ( cin >> line ) {
        D = vector <int>(10,0);
        for ( string ::iterator it = line.begin(); it != line.end(); ++it ) {
            D[*it-'0']++;
        }

        vector <int> T;
        vector <int> backup = D;
        for ( int i = 1; i < 10; i++ ) {
            D = backup;
            D[i]++;
            two = false;
            bool ok = true;
            for ( int j = 1; j < 10; j++ ) {
                if ( D[j] > 4 ) ok = false;
            }
            if ( ok && check( 1 ) ) T.push_back( i );
            D[i]--;
        }

        for ( vector <int> ::iterator it = T.begin(); it != T.end(); ++it ) {
            cout << *it;
            if ( it + 1 != T.end() ) cout << " ";
        }
        if ( T.empty() ) cout << 0;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 0
c11, c12,c13=[int(i) for i in input().split()]
c21, c22,c23=[int(i) for i in input().split()]
c31, c32,c33=[int(i) for i in input().split()]

ans=0
for a1 in range(c11+1):
    b1=c11-a1
    b2=c12-a1
    b3=c13-a1
    a2=c21-b1
    a3=c31-b1
    
    if c22==a2+b2 and c23==a2+b3 and c32==a3+b2 and c33==a3+b3:
        print("Yes")
        ans=1
        break

if ans==0:
    print("No")

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

int main(){
    ll a,b,c; cin >>a>>b>>c;
    if((c-a-b)*(c-a-b)>4*a*b && c-a-b>0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list
n = 100000
prime_list = set(eratosthenes(n))
a = []
for i in range(n):
    if i in prime_list and (i+1) // 2 in prime_list:
        a.append(1)
    else:
        a.append(0)
a = list(accumulate(a))
q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(a[r]-a[l-1])

Measured memory_bytes: 13576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
double n,k;
cin >> n >> k;
double ans = 0;
for(double i = 1; i <= n; i++){
  double t = i;
  double cnt = 0;
  while(t < k){
    t*=2;
    cnt++;
  }
  ans += 1/n*pow(0.5,cnt);
}
printf("%.10f\n",ans);
} 

Measured memory_bytes: 4108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)


class unionFind:
    parent = []
    count = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.count = [1 for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            self.count[y] += self.count[x]
            self.count[x] = self.count[y]
            return

    def getCount(self, x):
        self.count[x] = self.count[self.root(x)]
        return(self.count[x])


N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]

CD = [tuple(map(int, input().split())) for i in range(K)]

G = unionFind(N)
for a, b in AB:
    G.unite(a, b)

for i in range(N):
    G.root(i)

ans = [G.getCount(i) - 1 for i in range(N)]
# print(ans)
# print(G.count)
for a, b in AB:
    ans[a-1] -= 1
    ans[b-1] -= 1

for c, d in CD:
    if G.same(c, d):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(*ans)


Measured memory_bytes: 66900
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n;
	cin>>n;
	vector<ll> pos(120);
	vector<ll> neg(120);
	ll flag=0;
	for(ll i=0;i<120;i++) {
		pos[i] = (ll)pow(i+1,5);
		neg[i] = -(ll)pow(i+1,5);
		if(n==pos[i])
		{	
			cout<<i+1<<" "<<0<<endl;
			flag=1;
			break;
		}
	}
	if(flag==0)
	{
		for(ll i=0;i<120;i++) {
			for(ll j=0;j<120;j++) {
				if(pos[i]+neg[j]==n)
				{	
					cout<<i+1<<" "<<(j+1)<<endl;
					flag=1;
					break;
				}
				if(pos[i]-neg[j]==n)
				{	
					cout<<i+1<<" "<<-(j+1)<<endl;
					flag=1;
					break;
				}
			}
			if(flag==1)
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 3952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


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

  int D,G; cin>>D>>G;
  vector<int> problem_counts(D);
  vector<int> bonuses(D);
  for(int i=0; i<D; i++) {
    int p,c; cin>>p>>c;
    problem_counts[i] = p;
    bonuses[i] = c;
  }

  ll ans = INF;
  for(int bit=0; bit < (1 << D); bit++) {
    ll score = 0, solves = 0;
    int noncomplete_number = 0;
    for(int i=0; i<D; i++) {
      if(1 & bit>>i) { // i番目の問題を全完するパターン
        score += (i + 1) * 100 * problem_counts[i] + bonuses[i];
        solves += problem_counts[i];
      } else { // i番目の問題を中途半端に解くパターン(後で計算する)
        noncomplete_number = i;
      }
    }

    for(int i=0; i<problem_counts[noncomplete_number] && score < G; i++) {
      // score < G という条件を追加することで、0完パターンもここで網羅される。
      score += 100 * (noncomplete_number + 1);
      solves++;
    }

    if(score >= G) {
      ans = min(ans, solves);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(ll i=a;i<b;i++)
#define bFor(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
int main(){
  ll H,W,x,ans=0;
  cin>>H>>W;
  mat v(10,vec(10));
  rep(i,10){
    rep(j,10){
      cin>>v[i][j];
    }
  }
  rep(k,10){
    rep(i,10){
      rep(j,10){
        v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
      }
    }
  }
  rep(i,H){
    rep(i,W){
      cin>>x;
      if(x>=0){
        ans+=v[x][1];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#from collections import *
from itertools import *
#from bisect import *
#from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
#import math

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Zlst=set([i for i in range(N)])
if N==1:
    print(0)
    exit()
count=-1
for lst in combinations(range(N),N//2+N%2):
    odds=[[A[i],i] if i%2==0 else [B[i],i] for i in lst]
    even=[[B[i],i] if i%2==0 else [A[i],i] for i in list(Zlst-set(lst))]
    oddsst=sorted(odds,key=lambda  x:x[0])
    evenst=sorted(even,key=lambda  x:x[0])

    temp=oddsst[0][0]
    lst=[oddsst[0][1]]
    for i in range(1,N):
        if i%2==1:
            ntemp=evenst[i//2]
        else:
            ntemp=oddsst[i//2]
        if temp>ntemp[0]:
            flag=0
            break
        else:
            flag=1
            temp=ntemp[0]
            lst.append(ntemp[1])

    if flag:
        if count==-1:
            count=10**10
        tempcount=0
        while flag:
            flag=0
            for i in range(len(lst)-1):
                if lst[i]>lst[i+1]:
                    lst[i],lst[i+1]=lst[i+1],lst[i]
                    tempcount+=1
                    flag=1
        count=min(count,tempcount)


print(count)


Measured memory_bytes: 67672
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % MOD;
        fact[i] = (fact[i-1] + fs) % MOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(2*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            s.push_back(s[i] + 1);
            s.push_back(s[i+R] + 1);
            word[s[i]] ^= word[s[i+R]];
            word[s[i+R]] ^= word[s[i]];
            word[s[i]] ^= word[s[i+R]];
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ans =(ans + word[s[i]] * (fact[N - s[i] - 1] - fact[N - s[i+1] - 1] + MOD)) % MOD;
            int dif = s[i+1] - s[i];
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << ans % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2792
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll a, b, c;
    cin >> a >> b >> c;

    ll t = c - a - b;

    if (t <= 0) {
        cout << "No" << endl;
    } else {
        if (t * t > 4 * a * b) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////



ll N, A[20], B[20];
ll ab[20][3];
ll dp[1 << 19][20];

ll i, j,k;
int main(){
    scanf("%lld",&N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        scanf("%lld", &B[i]);
    }
    fornum(i,0,N){
        if(i%2==0){
            ab[i][0] = A[i];
            ab[i][1] = B[i];
        }else{
            ab[i][0] = B[i];
            ab[i][1] = A[i];
        }
    }
    fornum(i,0,1<<N){
        fornum(j,0,N+1){
            dp[i][j] = 1e9;
        }
    }
    dp[0][N] = 0;

    fornum(i,0,1<<N){
        ll a = __builtin_popcountll(i) % 2;
        //printf("\n%lld : ", i);
        fornum(j,0,N+1){
            ll d = 0;
            fornum(k,0,N){
                if(i&(1<<k))
                    continue;
                if(ab[j][a^1]<=ab[k][a]){
                    ll c = i | (1 << k);
                    dp[c][k] = min(dp[c][k], dp[i][j] + d);
                }
                ++d;
            }
            //printf("%lld,%lld ", j, dp[i][j]);
        }
    }
    ll ans = 1e9;
    fornum(i,0,N){
        ans = min(dp[(1 << N)-1][i], ans);
    }
    
    printf("%lld", ans == 1e9 ? -1 : ans);

    return 0;
}

Measured memory_bytes: 43264
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	scanf("%d", &N);
	vi a(N);
	rep(i, N)
		scanf("%d", &a[i]);
	sort(all(a));
	int M;
	scanf("%d", &M);
	vi b(M); vector<ll> c(M);
	rep(i, M)
		scanf("%d", &b[i]);
	rep(i, M)
		scanf("%lld", &c[i]);
	vector<ll> sum(N+1, 0);
	rep(i, N)
		sum[i+1] = sum[i] + a[i];
	rep(i, M) {
		int k = upper_bound(all(a), b[i]) - a.begin();
		bool ans = sum[k] >= c[i];
		puts(ans ? "Yes" : "No");
	}
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> c(n), v(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
    
    int ans = 0;
    rep(i, n)
        if (v[i]-c[i] > 0)
            ans += v[i]-c[i];
    
    cout << ans << endl;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	int N,M;
  cin >> N >> M;
  vector<vector<int>> a(N + 1);
  froop1(0,M){
    int b,c;
    cin >> b >> c;
    a.at(b).push_back(c);
  }
  
  int sw = 0,s1 = a.at(1).size();
  froop1(0,s1){
    int current = a.at(1).at(i),s = a.at(current).size();
    for(int j = 0;j < s;j++){
      if(a.at(current).at(j) == N){
        sw = 1;
      }
    }
  }
  if(sw == 1){
	cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }

return 0;
}

Measured memory_bytes: 11368
#include <bits/stdc++.h>
using namespace std;
int n,k,v[101],h[101];

int main(){
	cin >> n >> k;
	k++;
	for(int i = 0 ; i < k ; i += 1){
		h[i] = -100000;
	}
	for(int i = 0 ; i < n ; i += 1){
		cin >> h[k-1];
		if(i){
			v[k-1] = 2000000000;
			for(int j = 0 ; j < k-1 ; j += 1){
				v[k-1] = min(v[k-1],v[j]+abs(h[k-1]-h[j]));
			}
		}
		for(int j = 0 ; j < k-1 ; j += 1){
			v[j] = v[j+1];
			h[j] = h[j+1];
		}
	}
	cout << v[k-1] << endl;
}

Measured memory_bytes: 256
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{ n: i32 }
    let a = ((n as f64) / 1.08).ceil() as i32;
    let b = (((n + 1) as f64) / 1.08).ceil() as i32;
    for i in a..b {
        if ((i as f64) * 1.08).floor() as i32 == n {
            println!("{:?}", i);
            return;
        }
    }
    println!(":(");
}


Measured memory_bytes: 4352
n,m = map(int, input().split())
bk = []
for i in range(m):
    bk.append(int(input()))

p = [0]*(n+1)
for i in bk:
    p[i] = -100
if n == 1 and m == 0:
    print(1)
elif n == 1 and m == 1:
    print(0)
else:
    p[0] = 1
    if 1 in bk:
        p[1] = 0
    else:
        p[1] = 1
    for i in range(n-1):
        if p[i+2] < 0:
            p[i+2] = 0
        else:
            p[i+2] = p[i]+p[i+1]
            if p[i+2] >= 1000000007:
                p[i+2] -= 1000000007

    print(p[n])

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

int main() {
    int N; cin >> N; 
    vector<int> a(N-1);
    map<int, int> MAP;
    for (int i = 0; i < a.size(); i++) {
        int a; cin >> a; a--;
        MAP[a] ++;
    }
    for (int i = 0; i < N; i++) {
        cout << MAP[i] << endl;
    }
}

Measured memory_bytes: 13504
#include<stdio.h>
int main(void){
    int n,i,x;
    scanf("%d\n",&n);
    for(i=1;i<=n;i++){
        x=i;
        if(x%3==0){
            printf(" %d",i);
            continue;
        }
        if(x%10==3){
            printf(" %d",i);
            continue;
        }
        for(;;){
            x/=10;
            if(x==0)break;
            if(x%10==3){
            printf(" %d",i);
            break;
        }
     }
    }
        printf("\n");
    return 0;
}


Measured memory_bytes: 2100