akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long MOD=1e9+7;
long long modpow(long long x,long long e){
	if(x==1||e==0) return 1;
	long long c=modpow(x,e/2);
	long long c1=(c*c)%MOD;
	if(e%2==0) return c1;
	else return (c1*x)%MOD;
}
long long fac[10000005], inv[10000005];
long long choose(long long n, long long k){
	if(k>n) return 0;
	if(k<0) return 0;
	long long ans=(fac[n]*inv[k])%MOD;
	ans=(ans*inv[n-k])%MOD;
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long n, m;
	cin>>n>>m;
	fac[0]=1;
	inv[0]=1;
	for(long long i=1;i<=1000000;i++){
		fac[i]=(fac[i-1]*i)%MOD;
		inv[i]=(inv[i-1]*modpow(i, MOD-2))%MOD;
	}
	long long ans=0;
	for(long long k=0;k<=n;k++){
		long long add=(fac[k]*choose(n, k))%MOD;
		add=(add*choose(m, k))%MOD;
		add=(add*choose(m-k, n-k))%MOD;
		add=(add*fac[n-k])%MOD;
		add=(add*choose(m-k, n-k))%MOD;
		add=(add*fac[n-k])%MOD;
		if(k%2==0) ans=(ans+add)%MOD;
		else ans=(ans-add)%MOD;
		//cout<<add<<endl;
	}
	ans=(ans+MOD)%MOD;
	cout<<ans;
}

Measured memory_bytes: 19268
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q , n = 0 ;
    cin >> q;
    int l[q] , r[q] , a[100005] = {0} , c[100005] = {0};
    for( int i = 0 ; i < q ; i++ ) cin >> l[i] >> r[i];
    for( int i = 2 ; i <= 100005 ; i++ ) {
        int b = 1;
        for ( int j = 2 ; j * j <= i ; j++ ) {
            if ( i % j == 0 ) b = 0;
        }
        for ( int j = 2 ; j * j <= ( i + 1 ) / 2 ; j++ ) {
            if ( ( ( i + 1 ) / 2 ) % j == 0 ) b = 0;
        }
        a[i] = b;
    }
    a[2]=0;
    for( int i = 1 ; i <= 100005 ; i++ ) {
        n += a[i];
        c[i] = n;
    }
    n = 0;
    for( int i = 0 ; i < q ; i++ ) {
        n = 0;
        n += c[r[i]] - c[l[i] - 1];
        cout << n << endl;
    }
}



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

using namespace std;

int main(){
  int x,n;
  int a[110];
  
  cin >> x >> n;
  
 for(int i=0;i<n;i++){
   
   cin >> a[i];
   
 }
  
 int ans = x;
 int res = x;
 int b[110];
  
  for(int i=0;i<110;i++){
    b[i]=0;
  }
  
  for(int i=0;i<n;i++){
    b[a[i]]++;
  }
  
  for(int i=x;i<110;i++){
    if(b[i]==0){
      ans = i;
      break;
    }
  }
  
  for(int i=x;i>-10;i--){
    if(b[i]==0){
      res = i;
      break;
    }
  }
   
  
  if(abs(res-x)==abs(ans-x)){
    cout << res << endl;
  }
  else if(abs(res-x)>abs(ans-x)){
    cout << ans << endl;
  }
  else{
    cout << res << endl;
  }
  
}

Measured memory_bytes: 3632
K = int(input())
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(S[K-1])

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int n, a, b, c, d;
	int i, j;
	int flg;
	char str[300000];
	
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	
	scanf("%s", str);
	
	flg = 1;
	
	if(c > d) {
		for(i = b - 1; i < d - 2; i++) {
			if( (str[i] == '.') && (str[i + 1] == '.') && (str[i + 2] == '.') ) {
				flg = 0;
			}
		}
		if( (str[b - 2] == '.') && (str[b - 1] == '.') && (str[b] == '.') ) {
			flg = 0;
		}
		if(flg) {
			if( (str[d - 2] == '#') || (str[d] == '#') ) {
				printf("No\n");
				return 0;
			}
			for(i = a - 1; i < c - 2; i++) {
				if( (str[i] == '#') && (str[i + 1] == '#') ) {
					printf("No\n");
					return 0;
				}
			}
			for(i = b - 1; i < d - 2; i++) {
				if( (str[i] == '#') && (str[i + 1] == '#') ) {
					printf("No\n");
					return 0;
				}
			}
		} else {
			for(i = a - 1; i < c - 2; i++) {
				if( (str[i] == '#') && (str[i + 1] == '#') ) {
					printf("No\n");
					return 0;
				}
			}
			for(i = b - 1; i < d - 2; i++) {
				if( (str[i] == '#') && (str[i + 1] == '#') ) {
					printf("No\n");
					return 0;
				}
			}
		}
	} else {
		for(i = a - 1; i < c - 2; i++) {
			if( (str[i] == '#') && (str[i + 1] == '#') ) {
				printf("No\n");
				return 0;
			}
		}
		
		for(i = b - 1; i < d - 2; i++) {
			if( (str[i] == '#') && (str[i + 1] == '#') ) {
				printf("No\n");
				return 0;
			}
		}
	}
	
	printf("Yes\n");
	
	return 0;
}

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

int main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; t++) {
    int n, k;
    cin >> n >> k;
    int dist;
    int aida[n-1];
    int bfrD;
    for(int i = 0; i < n; i++) {
      int d;
      cin >> d;
      if(i == 0) dist = d;
      if(i+1 == n) dist = d - dist;

      if(i != 0) {
	aida[i-1] = d - bfrD;
      }

      bfrD = d;
    }
    
    if(k >= n) cout << 0 << endl;
    else {
      sort(aida, &aida[n-1]);
      for(int i = 0; i < k-1; i++) {
	dist -= aida[n-2-i];
      }
      
      cout << dist << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1256
import java.util.*;

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

		for(int i = 0; i < str.length(); i++){
			final char c = str.charAt(i);
			if('a' <= c && c <= 'z'){
				sb.append(String.valueOf(c).toUpperCase());
			} else if('A' <= c && c <= 'Z'){
				sb.append(String.valueOf(c).toLowerCase());
			} else {
				sb.append(String.valueOf(c));
			}
			
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 17260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N;
  cin >> N;
  vector<vector<ll>> F(N,vector<ll>(10));
  rep(i,N) rep(j,10) cin >> F[i][j];
  vector<vector<ll>> P(N,vector<ll>(11));
  rep(i,N) rep(j,11) cin >> P[i][j];



  ll ans = -(1e18);
  int state = 0b0000000001;

  for(;state<=0b1111111111;state++){
    vector<bool> v(10);
    rep(i,10){
      v[i] = (state>>i)%2;
    }
    ll preans = 0;
    vector<int> count(N);
    rep(i,N){
      rep(j,10){
        if(F[i][j] & v[j]) count[i]++;
      }
      preans += P[i][count[i]];
    }
    ans = max(ans, preans);
  }

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


Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int,input().split()))
a.sort()
s = set(a)

ac = collections.Counter(a)
ans = 0

for i in s:
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += ac[i] - i

print(ans)

Measured memory_bytes: 24308
#include <iostream>
#include <stack>

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

    int n;
    std::stack<long long int> s;

    while (std::cin >> n) {
        if (n) {
            s.push(n);
        }
        else {
            std::cout << s.top() << std::endl;
            s.pop();
        }
    }

    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

const int MAX = 100010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    int n;
    cin >> n;
    vector<int> b(n, -1);
    int fst, snd;
    for(int i = 0; i < n+1; i++){
        int a;
        cin >> a;
        a--;
        if(b[a] != -1) fst = b[a], snd = i;
        else b[a] = i;
    }
    
    COMinit();

    for(int i = 1; i <= n+1; i++){
        cout << (COM(n+1, i) - COM(n-snd+fst, i-1) + MOD) % MOD << '\n';
    }
}

Measured memory_bytes: 3968
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') { scanf("%d", &key); insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				scanf("%d", &key);
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


Measured memory_bytes: 33864
#include <iostream>
using namespace std;
int main (void) {
    string S;

    cin >> S;

    int d[4] = {0};
    for (int i = 0, len = S.length(); i < len; i++) {
        if (S[i] == 'N') {
            d[0] = 1;
        } else if (S[i] == 'W') {
            d[1] = 1;
        } else if (S[i] == 'S') {
            d[2] = 1;
        } else {
            d[3] = 1;
        }
    }

    if ((d[0] && !d[1] && d[2] && !d[3]) || (!d[0] && d[1] && !d[2] && d[3]) || (d[0] && d[1] && d[2] && d[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		int count = 1;
		for (int i = 1; i < n; i++) {
			String s1 = s.substring(i - 1, i);
			String s2 = s.substring(i, i + 1);
			if (!s1.equals(s2)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

int main() {
		int N, M;
		cin >> N >> M;
		int k[M];
		vector<int> s[M];
		for (int i = 0; i < M; i++) {
				cin >> k[i];
				for (int j = 0; j < k[i]; j++) {
						int t;
						cin >> t;
						t--;
						s[i].push_back(t);
				}
		}

		int p[M];
		for (int i = 0; i < M; i++) cin >> p[i];

		vector<int> l(M, 0);
		int ans = 0;
		for (int sw = 0; sw < (1<<N); sw++) {
				bool flg = true;
				for (int i = 0; i < M; i++) {
						int l = 0;
						for (int j = 0; j < k[i]; j++) {
								if (sw & (1<<s[i][j])) {
										l++;
										l %= 2;
								}
						}

						if (l != p[i]) {
								flg = false;
								break;
						}
				}
				if(flg) ans++;
		}

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{

  int n,k;
  int box=1;
  cin >> n >> k;

  for( int i=0;i<n;i++ ){
    if( box*2 >= box+k ){
      box=box+k;
    }else{
      box=box*2;
    }
  }
  cout << box << endl;
  return(0);
}


Measured memory_bytes: 256
import sys
N = int(input())
sm = 0
li = []
for i in range(N):
    s = int(input())
    sm += s
    if s%10 != 0:
        li.append(s)
if sm%10 == 0:
    if li == []:
        print(0)
        sys.exit()
    else:
        li = sorted(li)
        sm -= li[0]
print(sm)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int R, G;

int main() {
    scanf("%d", &R);
    scanf("%d", &G);

    printf("%d\n", (G * 2) - R);
}


Measured memory_bytes: 256
import itertools
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for bit_y in range(2 ** h):
    for bit_x in range(2 ** w):
        block = 0
        for y in range(h):
            for x in range(w):
                # c[y][x]が元から#じゃない、y,xが赤に塗り替える対象の行と列に選ばれているならカウントしない
                if bit_y >> y & 1 or bit_x >> x & 1 or c[y][x] != '#':
                    continue
                block += 1
        if block == k:
            ans += 1

print(ans)

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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
#define y second
#define point pair<int,int>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
vector<ll> a;

ll meme[2][3000][3000];
ll solve(int turn, int i, int j){
     if(i > j)
        return 0;

    ll &ret = meme[turn][i][j];
    if(ret != -1)
        return ret;

    if(turn){
        ll ch1 = solve(!turn, i + 1, j) - a[i];
        ll ch2 = solve(!turn, i, j - 1) - a[j];

        return ret = min(ch1, ch2);
    }
    else{
        ll ch1 = solve(!turn, i + 1, j) + a[i];
        ll ch2 = solve(!turn, i, j - 1) + a[j];

        return ret = max(ch1, ch2);
    }
}

int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    int n; cin>>n;
    a = vector<ll> (n);

    clr(meme, -1);

    for(int i = 0; i < n; i++)
        cin>>a[i];

    cout<<solve(0, 0, n - 1);
}


Measured memory_bytes: 141056
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

int main() {
	string s, t;
	VS ans;
	cin >> s >> t;
	int hcnt = 0,beg=-1,ac=0;
	bool jud ;

	for(int i=0;i+t.size()<=s.size();i++){
		jud = true;
		string st = s;
		for (int j = 0; j < t.size(); j++) {
			if (st[i + j] == '?') {
				st[i + j] = t[j];
			} else if (st[i + j] != t[j]) {
				jud = false;
			}
		}
		if (jud) {
			replace(all(st), '?', 'a');
			ans.push_back(st);
		}
	}

	if (ans.size() > 0) {
		sort(all(ans));
		cout << ans[0] << endl;
	} else {
		cout << "UNRESTORABLE" << endl;
	}
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    string s; cin>>s;
    vector<ll> e(n+1,0),w(n+1,0);
    rep(i,n){
        if(s[i]=='E') ++e[i];
        else ++w[i];
        e[i+1]+=e[i];
        w[i+1]+=w[i];
    }
    ll ans=INF;
    rep(i,n){
        if(i==0) ans=e[n]-e[1];
        else ans=min(ans,w[i-1]+e[n]-e[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8244
#include<stdio.h>
int main()
{
	int i,j,n,q,c=0;
	int S[10000],T[10000];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(j=0;j<q;j++)
	{
		scanf("%d",&T[j]);
		for(i=0;i<n;i++)
		{
			if(S[i]==T[j])
			{
				c++;
				break;
			}
		}
	}
	printf("%d\n",c);
	return 0;
}
				


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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	fastio
	int n;
	cin >> n;
	int a[n], b[n];
	for(auto &x : a) cin >> x;
	for(int i = 0;i < n;i++){
		b[i] = a[i];
		if(i!=0) b[i] += b[i-1];
	}
	int dp[n][n];
	memset(dp,0,sizeof dp);
	for(int i = 1;i < n;i++)
		for(int j = 0;j+i < n;j++){
			int l = j, r = j+i;
			dp[l][r] = 1e18;
			for(int k = l;k < r;k++){
				dp[l][r] = min(dp[l][r],dp[l][k]+dp[k+1][r]+ b[r]-(l==0 ? 0 : b[l-1]));
			}
		}
	cout << dp[0][n-1] << "\n";
}

Measured memory_bytes: 4744
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
struct FastIO
{
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }
    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }
};
#define pc(x) *(wb++) = x
int par[500001];
int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    int N, Q;
    io.read(N);
    io.read(Q);
    for (int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (int i = 0; i < Q; i++)
    {
        int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c)){
              pc('1');
              pc(' ');
            }
            else{
              pc('0');
              pc(' ');
            }
        if (a == 0)
            unite(b, c);
    }
    return 0;
}


Measured memory_bytes: 7236
from sys import stdin
input = stdin.readline

n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0 for _ in range(n)]
for i in range(n):
    for j in range(i+1, n):
        ans[min([abs(i-j), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1])] += 1
for i in range(1, n):
    print(ans[i])

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

using namespace std;

int main(){
  int N,W; cin >> N >> W;
  int v[N+1],w[N+1];
  for(int i=1;i<=N;i++){
    cin >> v[i] >> w[i];
  }
  int dp[N+1][W+1];
  for(int i=0;i<=W;i++) dp[0][i]=0;
  for(int i=1;i<=N;i++) dp[i][0]=0;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=W;j++){
      if(w[i]<=j){
        dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
      }else{
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 7012
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
k = []
a = []
for i in range(n):
    l  = list(map(int, input().split()))
    k.append(l[0])
    a.append(l[1:])

ans = [0]*(m+1)

for i in range(n):
    for j in range(len(a[i])):
        ans[a[i][j]] +=1

print(ans.count(n))


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

ll cl(ll a, ll b)
{
    return (a + (b - 1)) / b;
}

int main()
{
    ll n;
    cin >> n;

    ll t, a;
    cin >> t >> a;
    rep(i, n - 1)
    {
        ll T, A;
        cin >> T >> A;
        ll m = max(cl(t, T), cl(a, A));
        t = T * m, a = A * m;
    }
    OP((ll)(t + a));
    return 0;
}

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

void __print(int x) {cerr << x;};void __print(long x) {cerr << x;};void __print(long long x) {cerr << x;};void __print(unsigned x) {cerr << x;};void __print(unsigned long x) {cerr << x;};void __print(unsigned long long x) {cerr << x;};void __print(float x) {cerr << x;};void __print(double x) {cerr << x;};void __print(long double x) {cerr << x;};void __print(char x) {cerr << '\'' << x << '\'';};void __print(const char *x) {cerr << '\"' << x << '\"';};void __print(const string &x) {cerr << '\"' << x << '\"';};void __print(bool x) {cerr << (x ? "true" : "false");}

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl             '\n'
#define pb              push_back
#define all(x)          x.begin(),x.end()
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int string_to_int(string s){int ans = 0;int p=1;for(int i=s.size()-1;i>=0;i--){ans += (s[i]-'0')*p;p *= 10;}return ans;}

//DEBUGGING-LINES
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr <<'}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int n; cin >> n;
	int k = n%1000;
	if(k){
		cout << (n/1000)*1000+1000-n;
	}else{
		cout << 0 << endl;
	}
}

int32_t main()
{
	t_c_c();
	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);
    printf("%s\n", (C>=A&&C<=B)?"Yes":"No");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
n = int(input())
A = list(map(int,input().split()))
B = [0]*n

for a in A:
    B[a-1] += 1

total = 0
for b in B:
    if b > 1:
        total += b*(b-1)//2 

C = [0]*n
for i,b in enumerate(B):
    if b == 2:
        C[i] = total - 1
    elif b > 2:
         C[i] = total + (b-1)*(b-2)//2 - (b)*(b-1)//2 
    else:
        C[i] = total

for a in A:
    print(C[a-1])

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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                for(int i = 0; i < 3; i++)
                {
                    if (line[i * 3] != 's' && line[i * 3] == line[i * 3 + 1] && line[i * 3] == line[i * 3 + 2])
                    {
                        Console.WriteLine(line[i * 3]);
                        goto next;
                    }
                    if (line[i] != 's' && line[i] == line[i + 3] && line[i] == line[i + 6])
                    {
                        Console.WriteLine(line[i]);
                        goto next;
                    }
                }

                if (line[4] != 's' &&
                        (line[4] == line[0] && line[4] == line[8] ||
                        line[4] == line[2] && line[4] == line[6]
                        ))
                {
                    Console.WriteLine(line[4]);
                    goto next;
                }

                Console.WriteLine("d");
                next:
                ;
            }
        }
    }
}

Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
map<int, int> M;
int main() {
  int N,ans=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int d;
    cin >> d;
    if(M[d]==0){
      ans++, M[d]++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = in.nextInt();
            }

            Arrays.sort(d);

            int count = 1;
            for (int i = 1; i < N; i++) {
                if (d[i - 1] < d[i]) {
                    count++;
                }
            }

            System.out.println(count);
        }
    }
}


Measured memory_bytes: 27228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> A(N + 1), B(N);
	for(i = 0; i <= N; i++){
		scanf("%lld", &A[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &B[i]);
	}
	int ans = 0;
	for(i = 0; i < N; i++){
		if(A[i] < B[i]){
			ans += A[i];
			B[i] -= A[i];
		}
		else{
			ans += B[i];
			B[i] = 0;
		}
		if(A[i + 1] < B[i]){
			ans += A[i + 1];
			A[i + 1] = 0;
		}
		else{
			ans += B[i];
			A[i + 1] -= B[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    string s;cin>>s;
    
    if(s.substr(0,4)=="YAKI")cout<<"Yes";
    else cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int h[100005];
int dp[100005];

int main()
{
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n;i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 1024
def main():
    s = list(input())
    a=[]
    b=[]
    c=[]
    for i in range(5):
        a+=s[i]
    for i in range(7):
        b+=s[i+6]
    for i in range(5):
        c+=s[i+14]
    
    a=''.join(a)
    b=''.join(b)
    c=''.join(c)
    
    print(a,b,c)
        
main()

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
    #include <bits/stdc++.h>
    #define ll  long long
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define vi vector<int>
    #define br cout <<"\n";
    #define all(x)  (x).begin(),(x).end()
    #define tr(c,i) for(auto i : c)
    #define pii pair< int,int >
    #define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
    #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
    #define er(x) cout << x << " "
    #define err(x,y) cout << x << " "<<y
    const int M = 200005;
    using namespace std;
    clock_t time_p=clock();
    void dem()
    {
        time_p=clock()-time_p;
        cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
    }
    using namespace std ;
    const int MAX =  1000 * 1000 + 10;
    const int dx[] = { 1, -1 , 0 , 0  };
    const int dy [] = { 0 ,0 , 1 , -1  };
    const int MOD = 1000 * 1000 * 1000 + 9 ;
    int main (){
    int n ;
    cin >> n ;
    vector<int> v ( n );
    for ( int & x : v ) cin >> x ;

    sort ( all ( v  ) ) ;

    ll cnt = 0 ;
    for ( int i = n - 1 ; i >= 1 ; -- i  ){
    int left = 0 , right = i - 1 ;
    while ( left < right ){

        if (v[left] + v[ right ] > v [ i ] )
     {
         cnt += right - left  ;
        --right ;
    }
        else
            ++left ;
    }

    }
    cout <<cnt ;

    return 0 ;
    }



Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;


int main() {
  int A, B, H, M;
  cin>>A>>B>>H>>M;
  double Hdeg, Mdeg, deg;
  Hdeg= H*30 +M*(0.5);
  Mdeg=(M/5)*30 + (M%5)*6;
  deg=Hdeg>Mdeg?(Hdeg-Mdeg):(Mdeg-Hdeg);
  deg=deg*((double) M_PI/180);
  double d2= A*A + B*B -2*A*B*cos(deg);
  double d=sqrt(d2);
  printf("%0.20lf", d);
}

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

int main()
{
  int d; cin >> d;
  printf("Christmas");
  rep(i, 25-d)
    cout << " Eve";
  cout << endl;
}

Measured memory_bytes: 256
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
#define wis(x) "[" << #x << " : " << x << "] " << 
typedef long long ll;

const int MAXN = 2e5 + 10, MOD = 1e9 + 7, INF = 1e9 + 5;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	double n;
	cin >> n;
	double tmp = ceil(n / 1000) * 1000;
	cout << tmp - n << '\n';
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()

using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll rui[1111110][60];
ll ruii[1110];
ll bitsu[60];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,kk;cin>>n>>kk;
  for(ll i=0;i<n;i++){
    ll a;cin>>a;
    ruii[i+1]+=ruii[i]+a;
  }
  vi ans;
  for(ll i=1;i<=n;i++){
    for(ll j=1;j<=i;j++){
      ll num=ruii[i]-ruii[j-1];
      ans.pb(num);
      for(ll k=0;k<=50;k++)
	if(BITLE(k)&num)bitsu[k]++;
    }
  }
  ll anss=0;
  for(ll i=50;i>=0;i--){
    vi hog;
    if(bitsu[i]>=kk){
      for(ll j=0;j<ans.size();j++){
	if(BITLE(i)&ans[j])hog.pb(ans[j]);
	else {
	  for(ll k=0;k<=50;k++)
	    if(BITLE(k)&ans[j])
	      bitsu[k]--;
	}
      }
      anss+=BITLE(i);
      ans.clear();
      for(ll j=0;j<hog.size();j++)ans.pb(hog[j]);
    }
  }

  cout<<anss<<endl;
  return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>
using namespace std;
int T,N,K,X[100000+10],A[100000+10];
int sum(int *,int );
int max(int , int );
int main()
{
    cin>>T;
    for(int t=0; t<T; t++)
    {
        cin>>N>>K;
        for(int i=0;i<N;i++)cin>>X[i];
        for(int i=0;i+1<N;i++)A[i]=X[i+1]-X[i];
        sort(A,A+N-1);
        cout<<sum(A,max(0,N-1-(K-1)))<<endl;
    }
    return 0;
}
int sum (int A[],int n)
{
    int sum=0;
    for(int i=0;i<n;i++)
        sum+=A[i];
    return sum;
}
int max(int a,int b)
{
    if(a>b)return a;
    else return b;
}



Measured memory_bytes: 3804
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	int kotae = getint();
	rep1(i, N - 1) {
		kotae = __gcd(getint(), kotae);
	}
	printf("%d", kotae);

	Would you please return 0;
}

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

using namespace std;

struct UnionFind {
    vector<int> par;// par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
    UnionFind(int N): par(N) {
        for (int i = 0; i < N; i++) par[i] = i; // 初期では親は自分自身
    }
  
    void init(int N) {
        par.resize(N);
        for (int i = 0; i < N; i++) par[i] = i; // 初期では親は自分自身
    }
  
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
        //return par[x];
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
  
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならfalseを返す
        int rx = root(x);
        int ry = root(y);
        return rx != ry;
    }
};

int main() {
    float N, M;
    cin >> N >> M;
  
    vector<vector<float>> data(M, vector<float>(2));//input　　
    float ans;
    ans = 0;
  
    for(int i = 0; i < M; i++) {
        float a, b;
        cin >> a >> b;
        data[i][0] = a;
        data[i][1] = b;
    }
  
    UnionFind tree(N + 1);
      
    for (int i = 0; i < M; i++) {
      tree.init(N + 1);//毎回ツリーを初期化
      //cout << i << endl;
      for (int j = 0; j < M; j++) {
        if (i!= j){
          //cout << i <<  j << endl;
          tree.unite(data.at(j).at(0), data.at(j).at(1));
        }
      }
      //cout << i << tree.same(data.at(i).at(0), data.at(i).at(1)) << endl;
      if (tree.same(data.at(i).at(0), data.at(i).at(1))){
        ans += 1;
        //cout << ans << endl;
      }
      
    }
    //ans = 1225;
    cout << ans << endl;
  
    return 0;
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=305;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,K,Mod,f[N][N],C[N][N],sum[N][N];
int mod(int x){return x>=Mod?x-Mod:x;}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();K=read();Mod=read();
	for(int i=0;i<N;i++){
		C[i][0]=1;
		for(int j=1;j<N;j++){
			C[i][j]=mod(C[i-1][j-1]+C[i-1][j]);
		}
	}
	for(int i=0;i<=K;i++){f[1][i]=1;sum[1][i]=K-i+1;}
	for(int i=2;i<=n+1;i++){
		for(int j=0;j<=K;j++){
			for(int k=1;k<i;k++){
				f[i][j]=mod(f[i][j]+1ll*C[i-2][k-1]*f[i-k][j]%Mod*sum[k][j+1]%Mod);
			}
		}
		for(int j=K;j>=0;j--)sum[i][j]=mod(sum[i][j+1]+f[i][j]);
	}
	printf("%d",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 4244
#abc147-c:dfs
def dfs(i,evid,honest):
    #evid:正直者と仮定した人の発現
    #honest:正直者の番号

    global ans
    if i==n:
        count = len(honest)

        #発言に矛盾がないか調べる
        for i in range(1,n+1):

            if i in honest:
                if [i,0] in evid:
                    count=0
            else:
                if [i,1] in evid:
                    count=0

        ans=max(ans,count)

    else:
        dfs(i+1,evid+l[i],honest+[i+1])
        #正直者と仮定する
        dfs(i+1,evid,honest)
        #不親切な人

n=int(input())
l=[]
for i in range(n):
    a=int(input())
    b=[list(map(int,input().split())) for i in range(a)]
    l+=[b]

ans=0
dfs(0,[],[])
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A < 6) {
        cout << 0 << endl;
    } else if (A < 13) {
        cout << B / 2 << endl;
    } else {
        cout << B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){
	double a,b,c,d,e,f;
	double x,y;
	
	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
		
		x = (b*f - c*e) / (b*d - a*e);
		y = (a*f - c*d) / (a*e - b*d);
		
		x = round(x*1000) / 1000;
		y = round(y*1000) / 1000;
		
		if(x == -0.0){
			x = 0.0;
		}
		if(y == -0.0){
			y = 0.0;
		}
		
		printf("%.3f %.3f\n", x,y);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
    int n;
  double cnt=0;
  double c;
  cin >>n;
    for(int i=1; i<=n; i++){
        if(i%2==1){
          cnt++;
        }
    } 
  c=cnt/n;
    cout << c <<endl;
return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    unsigned long N,P;

    cin>>N>>P;



    long double n,m,k;
    k=1.0/N;

    n=pow(P,k);
    m=floor(n);

    for (unsigned long i=m+1;1<=i;--i){

        long z;
        z=pow(i,N);

        if(P%z==0){
            cout<<i<<endl;
            break;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int h, w;
	cin >> h >> w;
	vector<string> vec(h);
	for(int i = 0; i<h; i++){
		cin >> vec[i];
	}
	for(int j=0; j < w+2; j++){
		cout << '#';
	}
	cout << endl;
	for(int i=0; i<h; i++){
		cout << '#' << vec[i] << '#' << endl;
	}
	for(int j=0; j<w+2; j++){
		cout << '#';
	}
}

Measured memory_bytes: 3608
import java.lang.Math
import kotlin.comparisons.*

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val (n, m) = read().split().toInt()
    val sub = mutableMapOf<Int, MutableList<String>>()
    for (i in 1..m) {
        val (p, s) = read().split()
        val pi = p.toInt()

        if (!sub.containsKey(pi)) sub.put(pi, mutableListOf(s))
        else sub[pi]!!.add(s)
    }

    var ac = 0
    var wa = 0
    for (key in sub.keys) {
        val idx = sub[key]!!.indexOf("AC")
        if (idx != -1) {
            ac++
            wa += idx
        }
        // var idx = -1
        // for (i in 0 until sub[key]!!.size) {
        //     if (sub[key]!![i] == "AC") {
        //         idx = i
        //         ac++
        //         wa +=
        //         break
        //     }
        // }
    }

    println("$ac $wa")
}

fun read(): String = readLine()!!
fun CharSequence.split(): List<String> = this.split(" ")
fun Iterable<String>.toInt(): List<Int> = this.map{it.toInt()}
fun Iterable<String>.toLong(): List<Long> = this.map{it.toLong()}


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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    cout << min((n + h - 1) / h, (n + w - 1) / w);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
//ここではダブリングで実装している
vector<int> SuffixArray(string S){
    int N = (int)S.size();
    vector<int> rank(N + 1), temp(N + 1), sa(N + 1);
    for(int i = 0; i <= N; i++){
        sa[i] = i;
        rank[i] = i < N ? (int)S[i] : -1;
    }
    for(int k = 1; k <= N; k *= 2){//ダブリング開始
        auto comp = [&](int i, int j){
            if(rank[i] != rank[j]) return rank[i] < rank[j];
            else{
                int ni = i + k <= N ? rank[i + k] : -1;
                int nj = j + k <= N ? rank[j + k] : -1;//ダブリングで後ろに付け加えたもの同士の比較
                return ni < nj;
            }
        };
        sort(sa.begin(), sa.end(), comp);
        temp[sa[0]] = 0;
        for(int i = 1; i <= N; i++){
            temp[sa[i]] = temp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);//あっても ==の場合の時のfalseなので必ずソートされている
        }
        swap(temp, rank);
    }
    return sa;
}
bool judge(string S, string T, vector<int> sa){//SにTが含まれているか
    int left = 0, right = S.size();//二分探索で判定
    int Tlen = T.size();
    while(right - left > 1){
        int mid = (right + left) / 2;
        if(S.compare(sa[mid], Tlen, T) < 0) left = mid;
        else right = mid;
    }
    return S.compare(sa[right], Tlen, T) == 0;
}

vector<int> LCP(string S, vector<int> sa){
    int N = (int)S.size();
    vector<int> rank(N + 1), lcp(N + 1, 0);
    for(int i = 0; i <= N; i++) rank[sa[i]] = i;
    int h = 0;
    lcp[0] = 0;
    for(int i = 0; i < N; i++){
        if(rank[i] == 0) continue;
        int j = sa[rank[i] - 1];
        if(h > 0) h--;
        while(i + h < N && j + h < N){
            if(S[i + h] != S[j + h]) break;
            h++;
        }
        lcp[rank[i] - 1] = h;
    }
    return lcp;
}

int main(){
    string S;
    cin >> S;
    vector<int> sa = SuffixArray(S);
    vector<int> lcp = LCP(S, sa);
    long long N = S.size();
    cout << N * (N + 1) / 2 - accumulate(lcp.begin(), lcp.end(), 0LL) << endl;
}

Measured memory_bytes: 11980
n=int(input())
A=[int(input().replace(' ',''),2)for _ in[0]*n]
p=[0]*2**n
p[0]=1
for I in range(2**n-1):
 a=A[bin(I).count('1')]&~I
 for j in range(n):
  if a&1<<j:p[I|1<<j]+=p[I];p[I|1<<j]%=10**9+7
print(p[-1])

Measured memory_bytes: 58844
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  int a,b,x;
  cin >> a >> b;
  
  x = a + b + 1;
  
  cout << x/2 << endl;

 return 0;
}

Measured memory_bytes: 256
#include <iostream>

long long int pow2(long long int x) {
    return x * x;
}

int main() {
    long long int a, b;
    std::cin >> a >> b;

    long long int num = pow2(a) - pow2(b);
    long long int den = 2 * (a - b);

    if(num % den != 0) {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
    else
    {
        std::cout << (num/den) << std::endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 200200;
const long long Q = 101;
const long long mod = 1e9 + 7;
const long long block = 250;

using namespace std;

int n;
long long ans;
map < long long, int > d;

void solve()
{
        cin >> n;
        long long s = 0;
        d[s]++;
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                s += x;
                ans += d[s];
                d[s]++;
        }
        cout << ans << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("maze.in");
        //fout("maze.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 12800