akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;
int dp[(1 << 21)] = {};
int rel[21][21];
int n;

int matching(int pos, int mask) {
	if (pos == n) return 1;
	int &ans = dp[mask];
	if (ans != -1) return ans;

	ans = 0;
	for (int i = 0; i < n; i++) {
		if (!(mask & (1 << i)) and rel[pos][i]) {
			ans += matching(pos + 1, mask | (1 << i));
			ans %= mod;
		}
	}

	return ans;
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			cin >> rel[i][j];
	}

	memset(dp, -1, sizeof(dp));
	cout << matching(0, 0) << endl;

}
// Remember to clear the global containers

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 20004
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class UnionFindTree
{
    int n;
    vector<int> parent; // em[h
    vector<int> rank;   // ØÌ³ÌãÀ
    vector<int> num;    // O[vÌvf
    int find(int x){
        if(parent[x] == x)
            return x;
        return parent[x] = find(parent[x]);
    }
public:
    UnionFindTree(int n0){ // RXgN^
        n = n0;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int x, int y){ // xÆyÌO[vð¹
        if((x = find(x)) != (y = find(y))){
            if(rank[x] < rank[y]){
                parent[x] = y;
                num[y] += num[x];
            }else{
                parent[y] = x;
                if(rank[x] == rank[y])
                    ++ rank[x];
                num[x] += num[y];
            }
            -- n;
        }
    }
    bool same(int x, int y){ // xÆyÌO[vª¯¶©ð²×é
        return find(x) == find(y);
    }
    int getNum(){ // O[vÌðÔ·
        return n;
    }
    int getNum(int x){ // xÌO[vÌvfðÔ·
        return num[find(x)];
    }
};

int main()
{
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        vector<bitset<7> > bs(n, 0);
        vector<int> m(7, 0);
        for(int i=0; i<n; ++i){
            char a, b;
            cin >> a >> b;
            bs[i][a-'0'] = bs[i][b-'0'] = true;
            ++ m[a-'0'];
            ++ m[b-'0'];
        }

        UnionFindTree uft(n);
        for(int i=0; i<n; ++i){
            for(int j=0; j<i; ++j){
                if((bs[i] & bs[j]).any())
                    uft.unite(i, j);
            }
        }

        int odd = 0;
        for(int i=0; i<7; ++i){
            if(m[i] % 2 == 1)
                ++ odd;
        }

        if(uft.getNum() == 1 && odd <= 2)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
/*
bool good(int n, vector <int> ans) {
	if(n != ans.size()) return false;
	long long sum = 0;
	for(auto i : ans) {
		sum += i;
	}

}
*/
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	vector <int> ans;
	const int maxn = 30000;
	long long sum = 0;

	if(n == 3) {
		cout << "2 5 63" << endl;
		exit(0);
	}

	for(int i = 31; i <= maxn; i++) {
		if(ans.size() == n-2) break;
		if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
			ans.push_back(i);
			sum += i;
		}
	}
	int last = ans.back();
	for(int i = last + 1; i <= maxn; i++) {
		if((sum + i) % 2 == 1) continue; 
		if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
			ans.push_back(i);
			sum += i;
			break;
		}
	}
	sum %= 30;
	sum = 30 - sum;
	ans.push_back(sum);

	for(auto i : ans) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
#define EPS 1e-14

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// input
template <class T> inline T in_(){ T x; cin >> x; return x; }

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) obj.size()
#define sza(ary) (sizeof(ary) / sizeof(*ary))
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define cleAR(ary) memset((ary), 0, sizeof(ary))

// print util
#define print(x) cout << (x) << endl
#define printd(x, d) cout << fixed << setprecision(d) << (x) << endl
#define printv(v) REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]
#define printa(ary) REP(i, sza(ary)) cout << ary[i] << "\n "[i < sza(ary) - 1]
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

vi edge[2048];
bool visited[2048][2048];
int d[2048][2048];
int n, k;

int remove_num(int a, int b)
{
    int rnum = 0;
    FOR(i, 1, n + 1){
        if (k / 2 < d[a][i] && k / 2 < d[b][i]) rnum++;
    }
    return rnum;
}

signed main()
{
    n = in_<int>();
    k = in_<int>();
    REP(i, n - 1){
        int a = in_<int>(), b = in_<int>();
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    FOR(i, 1, n + 1){
        queue<pii> que;
        for (que.push(pii(i, 0)); sz(que); ){
            pii p = que.front(); que.pop();
            if (visited[i][p.fst]) continue;
            visited[i][p.fst] = true;
            d[i][p.fst] = p.sec;
            for (int j : edge[p.fst]) que.push(pii(j, p.sec + 1));
        }
    }

    int mini = n;
    FOR(i, 1, n + 1){
        FOR(j, 1, n + 1){
            if (k % 2 < d[i][j]) continue;
            // printf(" (%d,%d):%d", i, j, remove_num(i, j));
            mini = min(mini, remove_num(i, j));
        }
        // puts("");
    }
    print(mini);

    return 0;
}


Measured memory_bytes: 20352
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

typedef double db;
struct point {
	db x,y;
	point() {}
	point(db x,db y):x(x),y(y) {}
	void input() { scanf("%lf%lf",&x,&y); }
	void output() { printf("%.10f %.10f\n",x,y); }
	db len() { return sqrt(x*x+y*y); }
	db len2() { return x*x+y*y; }
};
point operator + (const point &a,const point &b) { return point(a.x+b.x,a.y+b.y);}
point operator - (const point &a,const point &b) { return point(a.x-b.x,a.y-b.y);}
point operator * (const point &a,const db &b) { return point(a.x*b,a.y*b);}
point operator / (const point &a,const db &b) { return point(a.x/b,a.y/b);}
db dot(const point &a,const point &b) { return a.x*b.x+a.y*b.y; }
db det(const point &a,const point &b) { return a.x*b.y-a.y*b.x; }
struct line {
	point a,b;
	line() {}
	line(point a,point b):a(a),b(b) {}
};
point projection(const line &a,const point &b) {
	return a.a+(a.b-a.a)*dot(a.b-a.a,b-a.a)/(a.b-a.a).len2();
}
int q;
int main() {
	point a,b;
	a.input(); b.input();
	line p(a,b);
	scanf("%d",&q);
	rep(i,0,q) {
		a.input();
		projection(p,a).output();
	}
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  bool flag = true;
  string s;
  cin >> s;
  int size = s.size();
  REP(i,size)if(s[i] != s[size-i-1])flag = false;
  string t = s.substr(0,(size-1)/2);
  int size2 = t.size();
  REP(i,size2)if(t[i] != t[size2 -i-1])flag = false;
  string u = s.substr((size+1)/2,(size - 1)/2);
  int size3 = u.size();
  REP(i,size3)if(u[i] != u[size3 - i - 1])flag = false;
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;



  return 0;
}


Measured memory_bytes: 256
int main()
{
  int h,w;
  int i,j;
  scanf("%d",&h);
  scanf("%d",&w);
  while(!((h==0) && (w==0))){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if ((i%2==0) && (j%2==0)){
          printf("#");
        }else if ((i%2==0) && (j%2==1)){
          printf(".");
        }else if ((i%2==1) && (j%2==0)){
          printf(".");
        }else if ((i%2==1) && (j%2==1)){
          printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
    scanf("%d",&h);
    scanf("%d",&w);
  }


  return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const double pi = 4 * atan(1.0);

int
main(int argc, const char *argv[])
{
    int a, b, C;
    cin >> a >> b >> C;
    double S, L, h;
    if (C == 90) {
        S = a * b / 2; 
        L = a + b + sqrt(a*a + b*b);
        h = b;
    } else if (C < 90) {
        h = b * sin(C / 180.0 * pi);
        S = a * h / 2;
        double x = b * cos(C / 180.0 * pi);
        L = a + b + sqrt(h * h + (a - x) * (a - x));
    } else {
        h = b * sin((180 - C) / 180.0 * pi);
        S = a * h / 2;
        double x = b * cos((180 - C) / 180.0 * pi);
        L = a + b + sqrt(h * h + (x + a) * (x + a));
    }
    printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);

    return 0;
}

Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n,cnt=9;
  int a=400;
  cin>>n;
  while(n>=a){
    a += 200;
    cnt--;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007;

int main()
{
	string p,t;
	cin>>p>>t;
	li n=t.length(),i,ans=0;
	fo(i,0,n)
	{
		if(t[i]==p[i])
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
LL A[1010][1010];
int n,Color[1010][1010];
int N,P[101010],T1[1010*1010],T2[1010*1010],n1,n2;
bool f[101010],vis[1010][1010];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void Pre(){
	for (int i=2;i<=100000;i++){
		if (!f[i]) P[++N]=i;
		for (int j=i+i;j<=100000;j+=i) f[j]=1;
	}
}
void Dfs(int x,int y,int c){
	Color[x][y]=c; vis[x][y]=1;
	for (int k=0;k<4;k++){
		int x1=x+dx[k],y1=y+dy[k];
		if (x1>=1&&x1<=n&&y1>=1&&y1<=n&&!vis[x1][y1])
			Dfs(x1,y1,1-c);
	}
}
void _Num(){
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)
		if (Color[i][j])
			T1[++n1]=i+j,T2[++n2]=i-j;
	sort(T1+1,T1+n1+1); sort(T2+1,T2+n2+1);
	n1=unique(T1+1,T1+n1+1)-T1-1;
	n2=unique(T2+1,T2+n2+1)-T2-1;
	
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)
		if (Color[i][j]){
			int p1=lower_bound(T1+1,T1+n1+1,i+j)-T1;
			int p2=lower_bound(T2+1,T2+n2+1,i-j)-T2;
			A[i][j]=(LL)P[p1]*(LL)P[n1+p2];
		}
}
LL gcd(LL a,LL b){
	if (!b) return a;
	return gcd(b,a%b);
}
LL Lcm(LL a,LL b){
	LL g=gcd(a,b);
	return (a/g)*b;
}
int main(){
	scanf("%d",&n);
	if (n==2){
		printf("4 7\n23 10"); return 0;
	}
	Pre(); Dfs(1,1,1); _Num();
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (!Color[i][j]){
		LL g=1;
		for (int k=0;k<4;k++){
			int x1=i+dx[k],y1=j+dy[k];
			if (x1>=1&&x1<=n&&y1>=1&&y1<=n)
				g=Lcm(g,A[x1][y1]);
		}
		A[i][j]=g+1;
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++) printf("%lld ",A[i][j]);
		printf("\n");
	}	
}

Measured memory_bytes: 28160
# 500 100 50 x

a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0

(a+1).times do |a_i|
  x_temp = x
  x_temp -= 500 * a_i
  break if x_temp < 0
  if x_temp == 0
    count += 1
    next
  end
  (b+1).times do |b_i|
    x_temp = x
    x_temp -= 500 * a_i
    x_temp -= 100 * b_i
    break if x_temp < 0
    if x_temp == 0
      count += 1
      next
    end
    (c+1).times do |c_i|
      x_temp = x
      x_temp -= 500 * a_i
      x_temp -= 100 * b_i
      x_temp -= 50 * c_i
      break if x_temp < 0
      if x_temp == 0
        count += 1
        next
      end
    end
  end
end

puts count


Measured memory_bytes: 14304
val modulo = 1000000007

val A = 0
val G = 1
val C = 2
val T = 3

fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    // dp[長さ][(2文字前)][(1文字前)][(現文字)]の領域を作成
    // 長さに対するループで前のインデックスを参照する都合上、長さ次元をn+1にする
    val dp = Array(n + 1, { it -> Array(4, { it -> Array(4, {it -> IntArray(4)})})})

    // 長さ3のケースを初期化
    // 2文字前に対するループ
    for (i in 0..3) {
        // 1文字前に対するループ
        for (j in 0..3) {
            // 追加する文字に対するループ
            for (k in 0..3) {
                if (i == A && j == G && k == C) continue
                if (i == A && j == C && k == G) continue
                if (i == G && j == A && k == C) continue
                dp[3][i][j][k] = 1
            }
        }
    }

    // 長さに対するループ
    for (i in 4..n) {
        // 3文字前に対するループ
        for (j in 0..3) {
            // 2文字前に対するループ
            for (k in 0..3) {
                // 1文字前に対するループ
                for (l in 0..3) {
                    // 追加する文字に対するループ
                    for (m in 0..3) {
                        if (k == A && l == G && m == C) continue
                        if (k == A && l == C && m == G) continue
                        if (k == G && l == A && m == C) continue
                        if (j == A && l == G && m == C) continue
                        if (j == A && k == G && m == C) continue
                        dp[i][k][l][m] = (dp[i][k][l][m] + dp[i - 1][j][k][l]) % modulo
                    }
                }
            }
        }
    }
    
    var ans = 0

    for (i in 0..3) {
        for (j in 0..3) {
            for (k in 0..3) {
                ans = (ans + dp[n][i][j][k]) % modulo
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31652
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

void inorder(Node x){
  if(x==NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node x){
  if(x==NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;
}


/* B
Node treeSearch(Node u, int k){

}*/

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
/*
void treeDelete(Node x){
Node y;
Node x;


}
*/

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n); //n=命令の数//

  for(i=0;i<n;i++){
    scanf("%s",com);
    /* Bにて
       if(com[0]=='f'){
       scanf("%d",&x);
       Node t=treeSearch(root,x);
       if(t!=NIL) printf("yes\n");
       else printf("no\n");
       }else */
    
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    /* Cにて
       else if(com[0]=='d'){
       scanf("%d",&x);
       treeDelete(treeSearch(root,x));
       }*/
  }
  return 0;
}



Measured memory_bytes: 25140
S = raw_input()

def pick_greedy(S):
    if S[0:5] == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                ret = 'dream'
            else:
                ret = 'dreamer'
        else:
            ret = 'dream'
    elif S[0:5] == 'erase':
        if S[5] == 'r':
            ret = 'eraser'
        else:
            ret = 'erase'
    else:
        ret = 'no'
    return ret

sol = 'YES'

while len(S) > 0:
    try:
        r = pick_greedy(S)
        if r == 'no':
            sol = 'NO'
            break
        else:
            if len(S) < len(r):
                sol = 'NO'
                break
            else:
                S = S[len(r):]
    except:
        sol = 'YES'
        break
        
print sol

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

const int Maxn = 2005, p = 1e9 + 7;
int S;
long long f[Maxn];
int main()
{
	scanf("%d", &S);
	f[0] = 1;
	for (int i = 3; i <= S; i++)
		for (int j = 0; j <= i - 3; j++)
			(f[i] += f[j]) %= p;
	printf("%lld", f[S]);
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
const int maxn=2003;
const int mod=924844033;
int n,K,m,Rem;
unsigned f[maxn][maxn][3],g[maxn];
int dp[maxn],Fac[maxn];
int main(){
	scanf("%d%d",&n,&K);
	m=n/(2*K)+1,Rem=n%(2*K);
	Fac[0]=1;
	for(int i=1;i<=n;i++)Fac[i]=Fac[i-1]*1ll*i%mod;
	dp[0]=1;
	int cnt=0;
	for(int i=1;i<=2*K;i++){
		int Lim=m-(Rem<i),Bot=i,Top=(Lim-1)*2*K+i;
		f[0][0][2]=1;
		for(int j=1;j<=Lim;j++){
			for(int k=0;k<=j;k++){
				f[j][k][0]=f[j][k][1]=0;
				if(j<Lim||Top+K<=n)f[j][k][0]=(f[j-1][k-1][0]+f[j-1][k-1][1]+f[j-1][k-1][2])%mod;
				if(j>1||Bot-K>=1)f[j][k][1]=(f[j-1][k-1][1]+f[j-1][k-1][2])%mod;
				f[j][k][2]=(f[j-1][k][0]+f[j-1][k][1]+f[j-1][k][2])%mod;
			}
		}
		for(int j=1;j<=Lim;j++)g[j]=(f[Lim][j][0]+f[Lim][j][1]+f[Lim][j][2])%mod;
		cnt+=Lim;
		for(int j=n;j>=0;j--){
			for(int k=1;k<=Lim&&k<=j;k++){
				dp[j]=(dp[j]+dp[j-k]*1ll*g[k])%mod;
			}
		}
	}
	int Ans=0;
	for(int i=0;i<=n;i++){
		Ans=(Ans+((i&1)?(mod-1ll):(1ll))*dp[i]%mod*Fac[n-i])%mod;
	}
	printf("%d\n",Ans);
	return 0;
}


Measured memory_bytes: 23168
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N,m,suma=0,cont=0;
	cin>>N;
	for(m=1;m*m<N;m++){
		if(N%m==0 && (N/m-1)!=m){
		suma+=(N/m)-1;
		}
	}
	if(suma==1) suma=0;
	cout<<suma<<endl;
}


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

int main() {
    long long int N, K, min1, tmp1, tmp2, tmp3;
    min1 = 1000000000000000001;
    cin >> N >> K;

    tmp1 = N / K;
    tmp2 = N - tmp1 * K;
    tmp3 = -1 * (N - (tmp1 + 1) * K);
    min1 = min(tmp2, tmp3);

    cout << min1 << endl;
    return 0;
}


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

int main() {
   int a,b,c;
  string s;
  cin>>a;
  b=0;
  bool t=0;
  vector<int> vec(a);
  for(int i=0;i<a;i++){
  	cin>>vec.at(i);
  }
  
  for(int i=0;i<a-1;i++){
  	for(int j=i+1;j<a;j++){
    b += vec.at(i)*vec.at(j);
    }
  }
  
  
  cout<<b<<endl;
  
  
  
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX_BUILD  4
#define MAX_FLOOR  3
#define MAX_ROOM  10

#define MIN_VISITOR 0
#define MAX_VISITOR 9

#define SEPARATOR "####################\n"

int main(void)
{
        int n, build, floor, room, visitor, domitory[MAX_BUILD][MAX_FLOOR][MAX_ROOM];
        int k, l, m;

        for(k=0; k < MAX_BUILD; k++)
                for(l=0; l < MAX_FLOOR; l++)
                        for(m=0; m < MAX_ROOM; m++)
                                domitory[k][l][m] = 0;

        scanf("%d", &n);

        for(int i=0; i < n; i++)
        {
                scanf("%d %d %d %d", &build, &floor, &room, &visitor);
                domitory[build-1][floor-1][room-1] += visitor;
        }

        for(k=0; k < MAX_BUILD; k++)
        {
                if(k != 0) printf(SEPARATOR);
                for(l=0; l < MAX_FLOOR; l++)
                {
                        for(m=0; m < MAX_ROOM; m++)
                        {
                                printf(" %d", domitory[k][l][m]);
                        }
                        printf("\n");
                }
        }

        return 0;
}


Measured memory_bytes: 2052
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    int r = scanner.nextInt();
    int s = scanner.nextInt();
    int p = scanner.nextInt();
    String t = scanner.next();
    char[] ts = t.toCharArray();
    int point = 0;

    for (int i = 0; i < k; i++) {
      char prev = '-';
      for (int j = 0; i + j * k < ts.length; j++) {
        if (ts[i + j * k] == 'r') {
          if (prev != 'p') {
            point += p;
            prev = 'p';
          } else {
            int nextIndex = i + j * k + k;
            if (nextIndex < ts.length) {
              if (ts[nextIndex] == 'r') {
                prev = 'r';
              } else if (ts[nextIndex] == 's') {
                prev = 's';
              } else {
                prev = 'r';
              }
            }
          }
        } else if (ts[i + j * k] == 'p') {
          if (prev != 's') {
            point += s;
            prev = 's';
          } else {
            if (i + j * k + k < ts.length) {
              if (ts[i + j * k + k] == 'r') {
                prev = 'r';
              } else if (ts[i + j * k + k] == 's') {
                prev = 'p';
              } else {
                prev = 'p';
              }
            }
          }
        } else {
          if (prev != 'r') {
            point += r;
            prev = 'r';
          } else {
            if (i + j * k + k < ts.length) {
              if (ts[i + j * k + k] == 'r') {
                prev = 's';
              } else if (ts[i + j * k + k] == 's') {
                prev = 's';
              } else {
                prev = 'p';
              }
            }
          }
        }
      }
    }
    System.out.println(point);
  }
}


Measured memory_bytes: 28636
import Data.List
import Data.Function

ceilDiv :: Integral a => a -> a -> a
ceilDiv t s = (t + s - 1) `div` s

solve :: [Int] -> [Int]
solve a = [n,r]
  where
    sa = sort a
    n  = last sa
    r  = let f i = abs (n `ceilDiv` 2 - i)
          in minimumBy (compare `on` f) $ init sa

main :: IO ()
main = do
    _ <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    mapM_ print $ solve a

Measured memory_bytes: 40572
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int H, W, K; cin >> H >> W >> K;
    vector<string> S(H); for (auto &s : S) cin >> s;
    string str;
    int first = 0;
    int id = 0;
    for (int i = 0; i < H; i++) {
        int cnt = 0;
        for (int j = 0; j < W; j++) { if (S[i][j] == '#') cnt++; }
        if (cnt == 0 && str.empty()) {
            first++;
        } else if (cnt == 0) {
            cout << str << '\n';
        } else {
            str = "";
            id++;
            int f = 0;
            for (int j = 0; j < W; j++) {
                if (S[i][j] == '#' && f == 0) f++;
                else if (S[i][j] == '#') id++;
                str += to_string(id) + ' ';
            }
            for (int j = 0; j < first; j++) cout << str << '\n';
            cout << str << '\n';
            first = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();

    let po = ['A','C','G','T'];
    let mut ans = 0;
    let mut now = 0;
    for i in 0..s.len() {
        let mut ok = false;
        for j in 0..4 {
            if s[i] == po[j] {
                ok = true;
            }
        }
        if ok {
            now += 1;
        } else {
            ans = std::cmp::max(ans, now);
            now = 0;
        }
    }
    ans = std::cmp::max(ans, now);
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    int n, x, i, j, k, ans=0;
    while(cin >> n >> x){
        if(n==0 && x==0) break;
        ans=0;
        for(i=1;i<=n-2;i++){
            for(j=i+1;j<=n-1;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        ans++;
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
fun main() {
    val a = readLine()!!.toInt() //500
    val b = readLine()!!.toInt() //100
    val c = readLine()!!.toInt() //50
    val x = readLine()!!.toInt()
    var cnt = 0

    for (i in 0..a) {
        for (j in 0..b) {
            for (k in 0..c) {
                val total = i * 500 + j * 100 + k * 50
                if (x == total) {
                    cnt++
                }
            }
        }
    }

    println(cnt)

}

Measured memory_bytes: 34516
#include <iostream>
#include <vector>
#include <algorithm>

struct Node {
    int id;
    int parent;
    int depth;
    std::vector<int> children;
};

std::vector<Node> nodes;

void set_depths(int id, int depth) {
    nodes[id].depth = depth;
    for (int child : nodes[id].children) {
        set_depths(child, depth + 1);
    }
}

int main() {
    int n;
    std::cin >> n;
    nodes.assign(n, {-1, -1, -1, {}});

    for (int i = 0; i < n; i++) {
        int id, k;
        std::cin >> id >> k;
        std::vector<int> C(k);
        for (int &c : C) {
            std::cin >> c;
            nodes[c].parent = id;
        }
        nodes[id].id = id;
        nodes[id].children = C;
    }

    Node root = *std::find_if(nodes.begin(), nodes.end(), [](Node node){return node.parent == -1;});
    set_depths(root.id, 0);

    for (Node& node : nodes) {
        std::cout << "node " << node.id;
        std::cout << ": parent = " << node.parent;
        std::cout << ", depth = " << node.depth;
        if (node.parent == -1) {
            std::cout << ", root, [";
        } else if (node.children.empty()) {
            std::cout << ", leaf, [";
        } else {
            std::cout << ", internal node, [";
        }
        for (int i = 0; i < node.children.size(); i ++) {
            if (i > 0) std::cout << ", ";
            std::cout << node.children[i];
        }
        std::cout << "]" << std::endl;
    }
}



Measured memory_bytes: 7444
fn main() {
  let _: usize = read();
  let mut vec: Vec<i64> = read_vec();
  
  vec.sort();
  let mut vec: Vec<i64> = vec.iter().scan(0, |a, &x| {*a+=x; Some(*a)}).collect();
  vec.reverse();
  
  let ans = 1 + vec.windows(2).take_while(|w| w[0]-w[1]<=w[1]*2).count();
  println!("{}", ans);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn read<T: std::str::FromStr>() -> T {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().parse::<T>().ok().unwrap()
}

Measured memory_bytes: 8444
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    int i;
    for (i = 0; i <= 1000; i++)
    {
        if(i * 8 / 100 == a && i / 10 == b)break;
    }
    
    if(i == 1001)printf("-1");
    else printf("%d",i);
}


Measured memory_bytes: 128
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

R, S, P = map(int, input().split())
T = input()
win = {"r": ["p", P], "s": ["r", R], "p": ["s", S]}

hands = []
tot = 0
for i, c in enumerate(T):
    if i >= K and win[c][0] == hands[i - K]:
        hands.append("anything")
        continue
    hands.append(win[c][0])
    tot += win[c][1]
        
print(tot)

Measured memory_bytes: 10052
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a<b&&b<c){cout<<"Yes"<<endl;}
else if (a<=c&&c<=b){cout<<"No"<<endl;}
else if (b<=a&&a<=c){cout<<"No"<<endl;}
else if (b<=c&&c<=a){cout<<"No"<<endl;}
else if (c<=a&&a<=b){cout<<"No"<<endl;}
else if (c<=b&&b<=a){cout<<"No"<<endl;}
else if (a<=c&&c<=b){cout<<"No"<<endl;}

	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)5e5 + 777;
vector<int> g[MAXN];
string dir;
int n, a[MAXN], in[MAXN];

void add_edge(int v, int u) {
	g[v].push_back(u);
	in[u] = 1;
}

int Q[MAXN], head = 0;

void solve() {
	cin >> dir;
	n = len(dir) + 1;

	for(int i = 0; i < n - 1; ++i) {
		if(dir[i] == '<') {
			add_edge(i, i + 1);
		} else {
			add_edge(i + 1, i);
		}
	}

	for(int v = 0; v < n; ++v) {
		if(!in[v]) {
			head = 0;
			Q[head++] = v;

			for(int j = 0; j < head; ++j) {
				int u = Q[j];

				for(auto& w: g[u]) {
					a[w] = max(a[w], a[u] + 1);
					Q[head++] = w;
				}
			}
		}
	}

	ll answ = 0;

	for(int v = 0; v < n; ++v) {
		DBG(v + 1); DBG(a[v]);
		answ += a[v];
	}

	for(int i = 0; i < n - 1; ++i) {
		int fl = 1;

		if(dir[i] == '<') {
			fl = (a[i] < a[i + 1]);	
		} else {
			fl = (a[i] > a[i + 1]);
		}

		if(!fl) {
			cout << "BAD: \n" << i + 1 << '\n';
			exit(-1);
		}
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 33948
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
string a [50], b[50] ;
int n , m ;
bool ok (int x , int y )
{
  for (int i = x , ro = 0 ; i - x < m ;ro++ , i++)
  {
    for (int j = y , col = 0 ; j - y < m ;col++ , j++)
    {
      if (a[i][j] != b[ro][col])return false ;
    }
  }
  return  true ;
}
int main ()
{
  cin >> n >> m ;
  for (int i =0 ; i < n ;i++)cin >> a[i];
  for (int i =0 ; i < m ;i++)cin >> b[i];

  for (int i =0 ; i + m <=  n ;i++)
  {
    for (int j =0 ; j + m <=  n ;j++)
    {
      if (ok(i , j ))
      {
        cout <<"Yes\n";
        return 0 ;
      }
    }
  }
  cout <<"No\n";
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
import numpy as np

if __name__ == "__main__":
    N = int(input())
    a = input().split()

    a = list(map(int, a))
    a = np.array(a)

    colors_flag = np.zeros(8)
    other = 0
    for rate in a:
        if(rate >= 3200):
            other += 1
        elif(colors_flag[int(rate/400)] == 1):
            continue
        else:
            colors_flag[int(rate/400)] = 1
    color_num = np.sum(colors_flag)
    print(int(color_num if color_num != 0 else 1), int(color_num + other))


Measured memory_bytes: 12428
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    int k,t;
    cin >> k >> t;
    vector<int> a(t);
    int amax = 0;
    rep(i,t){
        cin >> a[i];
        amax = max(amax,a[i]);
    }
    int ans = max(amax-1-(k-amax),0);
    cout << ans << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

string x;
int stock = 0, ans = 0;

signed main()
{
  cin >> x;
  int counter = 0;
  for(int i = 0; i < x.size(); i++){
    if(x[i] == 'S'){
      stock++;
    }
    else if(stock > 0){
      stock--;
      ans++;
    }
  }

  cout << x.size() - 2 * ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
  
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int S = Integer.parseInt(input);
        int h = S / 3600;
        int m = S % 3600 / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24340
x, y = map(int, input().split())
if x > y:
    if 0 > x:
        ans = x-y+2
    elif x == 0:
        ans = abs(y) + 1
    else:
        if 0 > y:
            ans = abs(abs(y)-x) + 1 
        elif y == 0:
            ans = x + 1
        else:
            ans = abs(x-y) + 2
elif x == y:
    ans = 0
else:
    if 0 > y:
        ans = y-x
    elif y == 0:
        ans = abs(x)
    else:
        if 0 > x:
            ans = abs(y-abs(x)) + 1
        elif x == 0:
            ans = y
        else:
            ans = y-x
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
int main()
{
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    int k;
    cin>>k;
    int ans=7;
    for(int i=1; i<=k; i++)
    {
        if(ans%k==0)
        {
            cout<<i;
            return 0;
        }
        ans=(ans*10+7)%k;
    }
    cout<<-1;
    return 0;
}


Measured memory_bytes: 3652
import math
b=int(input())
a=100
#n,k=map(int,input().split())
i=0
while True:
    i+=1
    a=int(a*1.01)
    if a>=b:
        print(i)
        exit()

#items=[int(i) for i in input().split()]

#items=[i for i in range(n+1)]



Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define maxn 2010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn];
char s[maxn];
int head[maxn],nxt[maxn*2],to[maxn*2],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
ll mn[maxn],mx[maxn];
int g[maxn];
int solve(int x,int las)
{
    mx[x]=mn[x]=0;g[x]=a[x];
    int p=0;
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        solve(to[i],x);
        g[x]+=g[to[i]];
        mx[x]+=mx[to[i]];
        if(mx[to[i]]>mx[p])  p=to[i];
    }
    if(mn[p]>mx[x]-mx[p])  mn[x]=mn[p]+mx[p]-mx[x]+g[x];
    else                   mn[x]=(mx[x]&1)+g[x];
    mx[x]+=g[x];
    if(!las)  mn[x]-=g[x],mx[x]-=g[x];
}
ll ans=0x3f3f3f3f3f3f3f3f;
int main()
{
    n=read();
    scanf("%s",s+1);for(int i=1;i<=n;i++)  a[i]=s[i]-'0';
    for(int i=1;i<n;i++)
    {
        int q=read(),w=read();
        add(q,w);add(w,q);
    }
    for(int i=1;i<=n;i++)
    {
        solve(i,0);
        if(!mn[i])  ans=min(ans,mx[i]/2);
    }
    if(ans==0x3f3f3f3f3f3f3f3f)  puts("-1");
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val (size, n) = {
    val n = in.next
    (n.size, n.toInt)
  }

  val candidates = ArrayBuffer[String]()
  def dfs(s: String): Unit = {
    Array("3", "5", "7").foreach{d =>
      val next = d + s
      if (next.size <= size) {
        candidates += next
        dfs(next)
      }
    }
  }

  dfs("")
  println(candidates.filter(c => c.toInt <= n && c.distinct.size == 3).size)
}

Measured memory_bytes: 41188
import java.io.IOException;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNextInt()) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = a + b;
			int count = 10;
			int result = 0;
			for (int i = 1; i < 8; i++) {
				if ((c - count) < 0) {
					result = i;
					break;
				}
				count = count * 10;
			}
			System.out.println(result);
		}

	}
}

Measured memory_bytes: 20400
#include<bits/stdc++.h>
using namespace std;
bool pal(string s)
{
    int i,l=s.size();
    string s1=s;
    for(i=0;i<l/2;i++)
        swap(s[i],s[l-1-i]);
    if(s1==s)
        return 1;
    return 0;

}
int main()
{
    string s;
    cin>>s;
    int i,n=s.size();
    string s1,s2;
    for(i=0;i<n/2;i++)
        s1+=s[i];
     for(i=((n+3)/2)-1;i<n;i++)
        s2+=s[i];
    if(pal(s)==1 && pal(s1)==1 && pal(s2)==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;


}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
template <typename T, typename E>
struct SegmentTree {
	typedef function<T(T, T)> F;
	typedef function<T(T, E)> G;
	int n;
	F f;
	G g;
	T d1;
	E d0;
	vector<T> dat;
	SegmentTree(){};
	SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) {
		init(n_);
		if (n_ == (int)v.size()) build(n_, v);
	}
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, d1);
	}
	void build(int n_, vector<T> v) {
		for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	void update(int k, E a) {
		k += n - 1;
		dat[k] = g(dat[k], a);
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	inline T query(int a, int b) {
		T vl = d1, vr = d1;
		for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) vl = f(vl, dat[(l++) - 1]);
			if (r & 1) vr = f(dat[(--r) - 1], vr);
		}
		return f(vl, vr);
	}
};
queue<int> idx[26];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	rep(i, n) idx[s[i] - 'a'].push(i);
	vector<int> v(n, 1);
	SegmentTree<int, int> rsq(
	    n, [](int a, int b) { return a + b; }, [](int a, int b) { return b; }, 0, v);
	string ans;
	rep(i, n) {
		rep(j, 26) {
			if (idx[j].empty()) continue;
			int now = idx[j].front(), cnt = rsq.query(0, now);
			if (cnt <= k) {
				idx[j].pop();
				k -= cnt;
				ans += (char)('a' + j);
				rsq.update(now, 0);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    string s;cin>>s;
    ll K;cin>>K;
    ll ans=0;
    bool ok=false;
    REP(i,s.size()-1){
        if(s[i]==s[i+1]){
            if(i==s.size()-2) ok=true;
            ans++;
            i++;
        }
    }
    if(s[0]!=s.back()||ok) ans*=K;
    else{
        ll tmp=1;
        s[0]='0';
        bool l=s.size()==1;
        REP(i,s.size()-1){
            if(s[i]==s[i+1]){
                if(i==s.size()-2) l=true;
                tmp++;
                i++;
            }
        }
        if(!l){
            tmp*=K-1;
            ans+=tmp;
        }
        else{
            ans=ans*((K+1)/2)+tmp*(K/2);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(){
  int s=0,a=0,i=0,n,m;
  string l;
  while(cin>>l){
    n = atoi(l.substr(0,l.find(",")).c_str());
    m = atoi(l.substr(l.find(",")+1).c_str());
    s+=n*m;
    a+=m;
    i++;
  }
  cout<<s<<endl<<(a+(i-1))/i<<endl;
  return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h);
  int ans = pow(10,9);
  for(int i=0;i+k-1<n;i++){
    int dif = h[i+k-1] - h[i];
    ans = min(ans,dif);
  }
  cout << ans << endl;
}

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


double dp[3000][3000];


double coins(int n, vector<double>& p){
    /*
    if(i < k || k < 0) return 0;
    if(i==1 && k==1) return p[0];
    if(i==1 && k==0) return(1-p[0]);
    
    if(dp[i][k] != 0) return dp[i][k];
    
    
    return dp[i][k] = (p[i-1]*coins(i-1,k-1,p) + (1-p[i-1])*coins(i-1,k,p));
    */
     
    double dp[n+1][n+1] = {};
    dp[1][0] = 1-p[0];
    dp[1][1] = p[0];
    
    for(int i = 2;i <= n; i++){
        dp[i][0] = (1-p[i-1])*dp[i-1][0];
        for(int j = 1; j <= i; j++){
            dp[i][j] = p[i-1]*dp[i-1][j-1] + (1-p[i-1])*dp[i-1][j];
        }
    }
    
    double sum = 0;
    for(int i = n/2 + 1 ; i <=n; i++) sum += dp[n][i];
    
    return sum;
}




int main(){
    int n; cin >> n;
    vector<double> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    
    /*
    double sum = 0;
    for(int j = n/2 + 1; j <= n; j++) sum += coins(n,j,p);
    cout << fixed << setprecision(10) << sum  << endl;
    */

    cout << fixed << setprecision(10) << coins(n,p);
    return 0;
}

Measured memory_bytes: 74100
from collections import deque, defaultdict

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

edge_dic = defaultdict(lambda: [])
reverse_edge_dic = defaultdict(lambda: [])

for _ in range(M):
    A, B, C = map(int, input().split())
    # if not A - 1 in edge_dic:
    #     edge_dic[A-1] = [[B-1, C-P]]
    # else:
    edge_dic[A-1].append([B-1, C-P])
    # if not B - 1 in reverse_edge_dic:
    #     reverse_edge_dic[B-1] = [[A-1, C-P]]
    # else:
    reverse_edge_dic[B-1].append([A-1, C-P])

# print(edge_dic)

INF = 10 ** 10

ans_array = [-INF] * N
ans_array[0] = 0

for i in range(N+1):
    change_flag = 0
    for key, value in edge_dic.items():
        for v in value:
            goal, cost = v
            if ans_array[goal] < ans_array[key] + cost:
                ans_array[goal] = ans_array[key] + cost
                change_flag = 1
    if change_flag == 0:
        break
else:
    forward_set = set()
    node_deque = deque()
    node_deque.append(0)
    forward_set.add(0)
    while len(node_deque):
        edge = node_deque.pop()
        for v in edge_dic[edge]:
            goal, cost = v
            if goal not in forward_set:
                forward_set.add(goal)
                node_deque.append(goal)

    backward_set = set()
    node_deque = deque()
    node_deque.append(N-1)
    backward_set.add(N-1)
    while len(node_deque):
        edge = node_deque.pop()
        for v in reverse_edge_dic[edge]:
            goal, cost = v
            if goal not in backward_set:
                backward_set.add(goal)
                node_deque.append(goal)
    can_use = forward_set & backward_set
    # print(forward_set, backward_set, can_use)

    new_edge_dic = {i: edge_dic[i] for i in can_use}

    ans_array = [-INF] * N
    ans_array[0] = 0
    for i in range(len(can_use)+1):
        change_flag = 0
        for key, value in new_edge_dic.items():
            for v in value:
                goal, cost = v
                if ans_array[goal] < ans_array[key] + cost:
                    ans_array[goal] = ans_array[key] + cost
                    change_flag = 1
        if change_flag == 0:
            break
    else:
        print(-1)
        exit()
    
ans = max(0, ans_array[N-1])
print(ans)


Measured memory_bytes: 58764