akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 505;
const ll LINF = 1e18 + 5;
int n, k, h[N];
ll dp[N][N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1;i<=n;i++) cin >> h[i];
 	for(int i=0;i<=n;i++)
 		for(int j=0;j<=i;j++)
 			dp[i][j] = LINF;
 	dp[0][0] = 0;
 	for(int i=1;i<=n;i++)
 		for(int j=1;j<=i;j++)
 			for(int t=j-1;t<i;t++)
 				dp[i][j] = min(dp[i][j],dp[t][j-1]+max(0,h[i]-h[t]));
 	ll ans = LINF;
 	for(int i=n-k;i<=n;i++)
 			ans = min(ans,dp[i][n-k]); 
  	cout << ans;
	return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 





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

  double ans = (double)(N - N / 2) / (double) N;
  cout << fixed << setprecision(10) << ans << endl;

}

Measured memory_bytes: 256
object Main {

    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val a = Array.fill(n)(sc.nextLong).sorted

        println(a.head + " " + a.last + " " + a.foldLeft(0L){ (acc, x) => acc+x })
    }
}



Measured memory_bytes: 61052
A, B, C, D = [int(x) for x in input().split()]

X = max(C, D)
Y = min(C, D)
remainder = 1
while(remainder != 0):
	remainder = X % Y
	X = Y
	Y = remainder
lcmCD = C * D // X

def f(x):
	return x - x // C - x // D + x // lcmCD

print(f(B) - f(A - 1))

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

long long m;

long long power(long long x, long long y) 
{ 
    if (y == 0) 
        return 1; 
    long long p = power(x, y/2) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 

int main()
{
	long long n;
	cin>>n;
	
	long long x;
	cin>>x>>m;
	
	int arr[m+1]={0};
	
	arr[x]=1;
	
	vector<int> ans={-1,x};
	
	long long cycle_start=-1;
	long long cycle_len;
	
	for(int i=2;i<=n;i++)
	{
		long long next_val=power(ans.back(),2);
		ans.push_back(next_val);
		
		if(arr[next_val]==0)
			arr[next_val]=i;
		else
		{
			cycle_start=arr[next_val];
			cycle_len=i-arr[next_val];
			
			break;
		}
	} 
	
	long long sum=0;
	
	if(cycle_start==-1)
	{
		for(int i=1;i<=n;i++)
		{
			sum+=ans[i];	
		}
	}	
	else
	{
		for(int i=1;i<cycle_start;i++)
		{
			sum+=ans[i];
		}
		
		long long rem=(n-cycle_start+1);
		
		long long num_times=rem/cycle_len;
		long long reminder=rem%cycle_len;
		
		long long t_sum=0;
		
		for(int i=cycle_start;i<cycle_start+cycle_len;i++)
		{
			t_sum+=ans[i];	
		}
		
		t_sum*=num_times;
		sum+=t_sum;
		
		for(int i=cycle_start;i<cycle_start+reminder;i++)
		{
			sum+=ans[i];
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  string t;
  cin >> t;
  string pd = t, d = t;
  int len = t.size();

  // bool ok = false;
  // for (int i = 0; i < len; ++i) {
  //   if (t[i] == 'P') {
  //     ok = true;
  //   } else if (t[i] == '?') {
  //     if (ok) {
  //       t[i] = 'D';
  //       ok = false;
  //     } else {
  //       t[i] = 'P';
  //       ok = true;
  //     }
  //   } else {
  //     ok = false;
  //   }
  //   cout << t[i];
  // }
  // cout << '\n';

  for (int i = 0; i < len; ++i) {
    if (t[i] == '?') {
      t[i] = 'D';
    }
    cout << t[i];
  }
  cout << '\n';

  return 0;
}


Measured memory_bytes: 3964
#include<stdio.h>

int main(){
	int genap,ganjil;
	scanf("%d %d", &genap, &ganjil);
	int tempGenap=0, tempGanjil=0;
	if(genap>1){
		for(int i=genap-1;i>=1;i--){
		tempGenap+=i;
		}
	}
	if(ganjil>1){
		for(int i=ganjil-1;i>=1;i--){
		tempGanjil+=i;
		}
	}
	printf("%d\n", tempGenap+tempGanjil);
	return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

double p, e, t;

double solve(int k, double l, double r) {
	double c = (l+r)/2.0;
	if(k==0) {
		return (t-e <= c && c <= t+e) ? 1.0 : 0.0;
	}
	if(t-e <= r && l <= t+e) return 1.0;
	if(l < t-e || t+e < r) return 0.0;

	if(c >= t) {
		return (1.0-p)*solve(k-1, c, r) + p*solve(k-1, l, c);
	} else {
		return (1.0-p)*solve(k-1, l, c) + p*solve(k-1, c, r);
	}
}

int main() {
	int k, r, l;
	cin >> k >> r >> l;
	cin >> p >> e >> t;
	double res = solve(k, l, r);
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}

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

struct node {
	int num;
	int value;
	bool operator < (const node & P){
		if(value !=  P.value){
			return value < P.value;
		}
		return true;
	}
};
vector<node> v;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		node nd;
		nd.num = i;
		cin>>nd.value;
		v.push_back(nd);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		if(!i)cout<<v[i].num;
		else cout<<" "<<v[i].num;
	}
} 

Measured memory_bytes: 1780
while True:
    N = int(input())
    if N == 0:
        break
    effies = {}
    for _ in range(N):
        L, P, A, B, C, D, E, F, S, M = map(str, input().split())
        P = int(P)
        A = int(A)
        B = int(B)
        C = int(C)
        D = int(D)
        E = int(E)
        F = int(F)
        S = int(S)
        M = int(M)

        spend_time = A + B + C + (D+E) * M
        earn_amount = (F*M*S)-P
        effi = earn_amount/spend_time
        effies[L] = effi

    effies = sorted(effies.items(), key=lambda x :(-x[1], x[0]))
    for i in range(len(effies)):
        print(effies[i][0])
    print("#")


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    string s;
    cin >> s;
    int ans = 0;
    vector<int>n(s.size(),0);
    for(int i=0; i<s.size();i++){
        if(s.at(i) == 'A' || s.at(i) == 'T'||s.at(i) == 'C'||s.at(i) == 'G'){
            n.at(i) = 1;
        }
    }
    int cnt = 0;
    for(int i= 0;i<s.size();i++){
        if(n.at(i) == 1){
            cnt++;
            ans = max(ans,cnt);
        }else{
            cnt = 0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N,*X=map(int,open(0).read().split())
M,g,q,r=10**9+7,1,[1,1],0
for i in range(1,N):
 r,g=(r+q[-1]*(X[-1]-X[i-1]))%M,g*i%M
 q+=[M//(-~i)*-q[M%(-~i)]%M]
print(r*g%M)

Measured memory_bytes: 69672
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;


vector<int> solve(int diff, int useless) {
    int bit = (1 << __builtin_ctz(diff));
    vector<int> aa, bb;
    if (diff == bit) {
        vector<int> uu;
        int cur = useless;
        while (cur) {
            int o = (1 << __builtin_ctz(cur));
            cur ^= o;
            uu.push_back(o);
        }
        for (int i = 1; i < (1 << (uu.size() + 1)); ++i) {
            int q = __builtin_ctz(i);
            if (q == uu.size()) {
                aa.push_back(bit);
            } else {
                aa.push_back(uu[q]);
            }
        }
        return aa;
    } else {
        int z = (1 << __builtin_ctz(diff ^ bit));
        int d2 = diff ^ bit ^ z;
        aa = solve(diff ^ bit ^ z, useless ^ z);
        bb = solve(z, useless ^ diff ^ bit ^ z);
        aa.push_back(bit);
        for (auto u: bb) {
            aa.push_back(u);
        }
        return aa;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    if (__builtin_popcount(a ^ b) % 2 == 0) {
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    vector<int> v;
    int st = 0, useless = 0;
    for (int i = (1 << (n - 1)); i; i >>= 1) {
        if (((a ^ b) & i) == 0) {
            useless ^= i;
        } else {
            st ^= i;
        }
    }
    auto x = solve(st, useless);
    int cur = a;
    vector<int> ans;
    ans.push_back(cur);
    for (auto p: x) {
        cur ^= p;
        ans.push_back(cur);
    }
    set<int> s;
    if (ans.size() != (1 << n)) {
        throw;
    }
    for (int i = 0; i < ans.size(); ++i) {
        if (i && __builtin_popcount(ans[i] ^ ans[i - 1]) != 1) {
            throw;
        }
        if (s.count(ans[i])) {
            throw;
        }
        s.insert(ans[i]);
    }
    for (int i = 0; i < ans.size(); ++i) {
        if (i) {
            cout << " ";
        }
        cout << ans[i];
    }
    if (ans[0] != a || ans.back() != b) {
        throw;
    }
    cout << "\n";
}

Measured memory_bytes: 8244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=2010;
int n,s[maxn];
ll dp[maxn][maxn*2],ans,C[maxn][maxn*2];
char S[maxn];
int main() {
	scanf("%s",S+1); n=strlen(S+1);
	for (int i=0;i<=n;i++) {
		C[i][0]=C[i][i]=1;
		for (int j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	for (int i=1;i<=n;i++) s[i]=s[i-1]+S[i]-'0';
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	for (int j=0;j<=s[i];j++) {
		if (2*i-s[i]<i-j) continue;
		dp[i][j]=dp[i-1][j];
		if (j) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
		if (i==n) ans=(ans+dp[i][j]*C[n][s[n]-j])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


inline void transpose(vector<string> &a) {

    int n = a.size();
    if (n == 0) return;
    int m = a[0].size();
    vector<string> b(m, string(n, ' '));
    fori (i, n) fori (j, m) b[j][i] = a[i][j];
    a = b;
}


template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    fori (i, SZ(a))
        out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
    return out;
}

void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#define cerr cout
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

const ll M = 1e9 + 7;

vvl operator * (const vvl &a, const vvl &b) {
    int n = a.size();
    vvl ret(n, vl(n, 0));
    fori (i, n) fori (j, n) fori (k, n) ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M;
    return ret;
}


vvl mat_pow(vvl a, ll p) {
    int n = a.size();
    vvl ret(n, vl(n, 0));
    fori (i, n) ret[i][i] = 1;
    while (p) {
        if (p & 1) ret = ret * a;
        a = a * a;
        p >>= 1;
    }
    return ret;
}

void smain() {
    ll n, m;
    cin >> n >> m;
    vvl a(n, vl(n, 0));
    fori (i, n) fori (j, n) cin >> a[i][j];
    a = mat_pow(a, m);
    ll ans = 0;
    fori (i, n)fori(j,n) ans =(ans + a[i][j]) % M;
    cout << ans;

}

Measured memory_bytes: 384
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine(p[0] + p[1] >= p[2] ? "Yes" : "No");

		Console.Out.Flush();
	}
}


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

int main()
{
	string weather[3] = {"Sunny", "Cloudy", "Rainy"};

	string today;
	cin >> today;

	for (int i = 0; i < 3; i++)
	{
		if (today == weather[i])
		{
			int id = i + 1;
			if (id >= 3)
				id = 0;
			string tomorrow = weather[id];
			cout << tomorrow;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n;
    std::vector<i64> p2(55);
    p2[0] = 1;
    for (int i = 1; i <= 50; i++) p2[i] = p2[i - 1] * 2;
    std::vector<std::vector<int>> g(n), edges(n, std::vector<int>(n, -1));
    for (int i = 1; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
        edges[a][b] = edges[b][a] = i;
    }
    std::cin >> m;

    std::vector<i64> path;
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        std::vector<int> prev(n, -1);
        std::deque<int> q { u };
        while (!q.empty()) {
            int v = q.front();
            q.pop_front();
            for (int to : g[v]) {
                if (to == u || prev[to] >= 0) continue;
                prev[to] = v;
                q.push_back(to);
            }
        }

        i64 b = 0;
        int curr = v;
        while (true) {
            int p = prev[curr];
            if (p == -1) break;
            b |= 1ll << edges[p][curr];
            curr = p;
        }

        path.push_back(b);
    }

    i64 ret = 0;
    for (int i = 0; i < (1 << m); i++) {
        int pc = __builtin_popcount(i);
        i64 b = 0;
        for (int j = 0; j < m; j++) if (i & (1 << j)) b |= path[j];
        int cc = n - 1 - __builtin_popcountll(b);
        i64 d = p2[cc];
        if (pc % 2) ret -= d;
        else ret += d;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char a,b,c,d;
int main(){
	scanf("%c%c%c%c",&a,&b,&c,&d);
	puts(a==b||b==c||c==d?"Bad":"Good");

}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && b != c) {
		cout << "Yes" << endl;
	}
	else if (b == c && c != a) {
		cout << "Yes" << endl;
	}
	else if (c == a && a != b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << '\n';
            return 0;
        }
    }
    cout << "Good" << '\n';
}


Measured memory_bytes: 256
import math

def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k = [int(i) for i in input().split()]
for i in range(1,k+1):
    if i-1 > n-k:
        print(0)
    else:
        print(cmb(k-1,i-1)*cmb(n-k+1,i) % (10**9+7))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int grid[100005][5];
int dp[100005][5];
int solve(int current, int n, int last)
{
	if (current == n)
		return 0;
	if (dp[current][last])
		return dp[current][last];
	if (last == -1)
		return max(grid[current][0] + solve(current + 1, n, 0), max(grid[current][1] + solve(current + 1, n, 1), grid[current][2] + solve(current + 1, n ,2)));
	int res;
	if (last == 0)
		res = max(grid[current][1] + solve(current + 1, n, 1), grid[current][2] + solve(current + 1, n, 2));
	else if (last == 1)
		res = max(grid[current][0] + solve(current + 1, n, 0), grid[current][2] + solve(current + 1, n, 2));
	else
		res = max(grid[current][0] + solve(current + 1, n, 0), grid[current][1] + solve(current + 1, n , 1));
	return dp[current][last] = res;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> grid[i][j];
	cout << solve(0, n, -1) << '\n';
	return 0;
}

Measured memory_bytes: 10368
#include <stdio.h>

int n, In1[25];

int judge(int i, int In2)
{
  if( In2 == 0 )return 1;
  if( i >= n )return 0;
  int res = judge( i+1, In2 ) || judge( i+1, In2 - In1[i]);
  return res;
}

int main()
{
  int i,m,In2;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&In1[i]);
  scanf("%d",&m);
  for(i=0;i<m;i++)
  {
    scanf("%d",&In2);
    if( judge(0,In2) ) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  repi(i,1,10){
    if(n%i==0 && n/i < 10){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
def dp_all(dp):
  length = len(dp)
  for i in range(length):
    print(dp[i])

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

v = []
w = []

for i in range(N):
  v_dash,w_dash = map(int,input().split())
  v.append(v_dash)
  w.append(w_dash)

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
  for j in range(W+1):
    if w[i] > j:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

print(dp[N][W])



Measured memory_bytes: 25940
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


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

    int res = 0;
    while (true) {
        if (*max_element(ALL(h)) == 0) break;

        int i = 0;
        while (i < N) {
            if (h[i] == 0) ++i;
            else {
                ++res;
                while (i < N && h[i] > 0) {
                    --h[i];
                    ++i;
                }
            }
        }
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let c: usize = iter.next().unwrap().parse().unwrap();

    let mut v = [a,b,c];
    v.sort();
    println!("{}", v[2] * 10 + v[1] + v[0]);

}


Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, C;
  while(cin>>R>>C,R||C) {
    vector<vector<int> > v(R, vector<int>(C, 0));
    FOR(i,0,R) FOR(j,0,C) cin >> v[i][j];
    int ans = 0;
    FOR(i,0,1<<R) {
      bool ura[10]; CLR(ura);
      FOR(j,0,R) {
        if((i>>j)&1) {
          ura[j] = true;
        }
      }
      int cnt = 0;
      FOR(j,0,C) {
        int cnt2 = 0;
        FOR(k,0,R) {
          cnt2 += v[k][j] == ura[k];
        }
        cnt += max(cnt2, R - cnt2);
      }
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3412
def 解():
    sS = input().rstrip()
#   dsS = set()
#   for s in sS:
#       if s not in dsS:
#           dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
#   for s in sorted(list(dsS)):
    for s in sorted(set(sS)):
        d = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        d.add(sS[i:i+j])
            aS = sorted(d)
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    d.add(sS[i:i+j])
            aS = sorted(d)
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()


Measured memory_bytes: 3064
N, K = map(int, input().split())
S = list(map(int,list(input())))
A = []
B = []
if S[0] == 1:
  A.append(0)
  B.append(1)
else:
  A.extend([0,1])
  B.extend([0,0])
  
for i in range(1,N):
  if S[i] == S[i-1]:
    if S[i] == 0:
      A[-1] += 1
    else:
      B[-1] += 1
  else:
    if S[i] == 0:
      A.append(1)
      B.append(0)
    else:
      A.append(0)
      B.append(1)
if B[-1] == 0:
  A.append(0)
  B.append(0)

M = len(A)
tmp = sum(A[0:2*K+1]) + sum(B[0:2*K+1])
ans = tmp
for i in range(2,M-2*K,2):
  tmp -= A[i-1] + B[i-2]
  tmp += A[i+2*K-1] + B[i+2*K]
  ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 6700
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int dp[30][512810];
int dbl[512810][30];
string s;int n;
int cal(int i,int j,int ne){
	if(dp[i][j]>ne){
		dp[i][j]=ne;return 1;
	}
	return 0;
}
int main()
{
	int q,x,y,inf=512810;
	cin>>s;
	n=s.size();
	//memset(dp,-1,sizeof(dp));memset(dbl,-1,sizeof(dbl));
	rep(i,30) rep(j,inf-10) dp[i][j]=dbl[j][i]=inf;
	for(int j=n-1;j>=0;j--){
		rep(k,2){
			int f=0;
			rep(i,27){
				if(s[j]==('a'+i)){
					f|=cal(i,j,j+1);//dp[i][j]=j+1;
				}
				if(i>0 && dp[i-1][j]<inf){
					f|=cal(i,j,dp[i-1][dp[i-1][j]]);//dp[i][j]=min(dp[i-1][dp[i-1][j]],dp[i][j]);
				}
				if(i<26 && dp[26][j]<inf){
					f|=cal(i,j,dp[i][dp[26][j]]);//dp[i][j]=min(dp[i][dp[26][j]],dp[i][j]);
				}
				//if(dp[i][j+1]>=0) cout<<i<<' '<<j+1<<' '<<dp[i][j+1]<<endl;
			}
			//if(f<1) break;
		}
	}
	rep(i,n+10){
		dbl[i][0]=dp[26][i];
		//if(i<=n) cout<<i<<' '<<dp[26][i]<<endl;
	}
	rep(i,26) rep(j,n+10){
		if(dbl[j][i]<inf) dbl[j][i+1]=dbl[dbl[j][i]][i];
		//if(i<4 && j<=n) cout<<i<<' '<<j<<' '<<dbl[j][i]<<endl;
	}
	cin>>q;
	rep(i,q){
		cin>>x>>y;x--;
		for(int i=22;i>=0;i--){
			if(dbl[x][i]<=y) x=dbl[x][i];
			//cout<<x<<endl;
		}
		if(y==x) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 121476
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i], --a[i];

    vector<vector<int>> nxt(70, vector<int>(n));
    rep(i,n) nxt[0][i] = a[i];
    for (int i = 1; i < 70; ++i) {
        rep(j,n) {
            nxt[i][j] = nxt[i-1][nxt[i-1][j]];
        }
    }

    string x;
    while (k>0) {
        x.push_back((k%2)+'0');
        k/=2;
    }

    int cur = 0;
    rep(i,x.length()) {
        if (x[i]=='1') cur = nxt[i][cur];
    }
    cout << cur+1 << '\n';
    return 0;
}

Measured memory_bytes: 59760
#include<bits/stdc++.h>
using namespace std;
long long n,d;
int main(){
	cin>>n>>d;
	long long x,y;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		if(x*x+y*y<=d*d){
			ans++;
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3632
n,d=map(int,input().split())
x=[[0]*d]*n
for i in range(n):
  xnow=[int(n) for n in input().split()]
  x[i]=xnow
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    len2=0
    for z in range(d):
        len2+=(x[i][z]-x[j][z])**2
    for c in range(130):
      if c**2==len2:
        ans+=1
        break
      elif c**2>len2:
        break
      else:
        continue
print (ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n[4],i;
	char c;
	for(i=0;i<4;i++){
		scanf("%c",&c);
		n[i]=c-'0';
	}
	if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3]))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	return 0;
}

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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {

            String[] str=Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            int count=0;

            for (int i = a; i <= b; i++)
            {
                if (c % i == 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);


        }
    }
}

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

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

    string target;
    vector<string> targets;

    for (int i = 0; i < n; ++i) {
        cin >> target;
        sort(target.begin(), target.end());
        targets.push_back(target);
    }
    // TODO: map使ってやってみる。

    sort(targets.begin(), targets.end());
    long long sum_count = 0;
    long long count = 1;
    for (int i = 1; i <= n; ++i) {
        if (i == n) {
            sum_count += count * (count - 1) / 2;
            break;
        }
        if (targets[i] == targets[i - 1]) {
            ++count;
            continue;
        }
        sum_count += count * (count - 1) / 2;
        count = 1;
    }

    cout << sum_count << endl;

    return 0;
}

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

int main()
{

        string s;
        cin >> s;

        int length = s.length();
        int n = length / 2;
        int count = 0;
        for (int i = 0; i < n; ++i) {

                if (s[i] != s[length-1-i]) {
                        count++;

                }
        }
        cout << count << endl;










}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> T(N);
	vector<long long> A(N);
	long long res1=1;
	long long res2 = 1;
	for (int i = 0; i < N; i++) {
		cin >> T[i] >> A[i];
		long long a= max( ( (res1 - 1) / T[i]) + 1, ((res2 - 1) / A[i]) + 1);
		res1 = a*T[i];
		res2 = a*A[i];
		
	}
	cout << res1+res2 << endl;
	return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    string s; cin >> s;

    int ans1 = 0, ans2 = 0;
    REP( i, s.size() ){
        if( i % 2 == 0 ){
            if( s[i] == '0' ) ans1++;
            else ans2++;
        }else{
            if( s[i] == '0' ) ans2++;
            else ans1++;
        }
    }

    cout << min( ans1, ans2 ) << endl;
}


Measured memory_bytes: 512
require "set"
k = gets.chomp.to_i

# 7, 77, 777, ... の一般項を a_n とおくと
# k * m = a_n (mは自然数) となるような最小のnを見つけたい
# 式変形すると m = a_n / k
# 左辺は自然数なので, 右辺も自然数になる必要がある
# つまり a_n が k で割り切れるような最小のnを見つけたい
# そのようなnが存在しないときもあることに注意
# (a_nは2や5の倍数ではないので, kも2や5の倍数になりえない)

set = Set.new
a_n = 0
n = 0
while true do
  n += 1
  a_n = (a_n * 10 + 7) % k
  break if a_n == 0
  if set.include?(a_n)
    puts "-1"
    exit
  else
    set << a_n
  end
end
puts n


Measured memory_bytes: 51396
# coding: utf-8
n = int(input())
data = [input() for i in range(n)]
txt = [2501] * 26
for i in range(n):
    for j in range(26):
        txt[j] = min(txt[j], data[i].count(chr(97 + j)))

for i in range(26):
    print(chr(97 + i) * txt[i], end='')
print()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(c==b)
	{
		printf("1");
	}
	else if(b>c)
	{
		printf("0");
	}
	else if(a==1)
	{
		printf("0");
	}
	else
	{
		printf("%lld",(c-b)*(a-2)+1);
	}
}

Measured memory_bytes: 256
// noobie_corleone
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
//vector<int> adj[200010];
//vector<int> value(200010),par(200010),vis(200010,0),fi(200010,0),g(200010,0),col(200010,-1);
int myrandom (int i) { return std::rand()%i;}

int main()
{
	ll n,W;
	cin>>n>>W;
	vector<ll> w(n+1),v(n+1);
	ll sum=0;
	fr(i,1,n+1){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	vector<vector<ll>> dp(n+1 , vector<ll> (sum+1,0));
	fr(i,1,sum+1)
		dp[0][i]=inf;
	fr(i,1,n+1)
	{
		fr(j,1,sum+1)
		{
			dp[i][j]=inf;
			dp[i][j]=dp[i-1][j];
			if(j >= v[i])
				dp[i][j]=min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
		}
	}
	ll ans=0;
	for(ll i = 0; i <= sum; i++){
        if(dp[n][i] <= W){
            ans = i;
        }
	}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
ll n,m,q,maxi;
ll a[51],b[51],c[51],d[51];


void search(vector<ll> &v)
{

	if(v.size()==n)
	{
		ll ans = 0;
		for(ll i=0;i<q;i++)	{if((v[b[i]]-v[a[i]])==c[i])	ans+=d[i];}
		maxi=max(maxi,ans);
		// cout<<ans<<endl;
		return ;
	}

	ll s=1;
	if(v.size())	s=v.back();

	for(ll i=s;i<=m;i++)
	{
		v.pb(i);
		search(v);
		v.pop_back();
	}

}


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll i;
		cin>>n>>m>>q;
		
		for(i=0;i<q;i++)	{cin>>a[i]>>b[i]>>c[i]>>d[i];a[i]--;b[i]--;}

		vector<ll> v;
		search(v);
		cout<<maxi;
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 3784
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();
LL GCD(LL a, LL b);
int main(){
    ULL N,K;
    ULL min = 10e18+1;
    cin >> N >> K;
    while(min > N){
        min = N;
        if( N > K ){
            N = N % K;
        }else
        {
            N = K - N;
        }

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

LL GCD(LL a, LL b){
   
    return b;
}

void process(){
    
}

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

signed main()
{
  cout << fixed << setprecision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  double sum = 0;
  for (int i = 0; i < n; ++i) {
    double a;
    cin >> a;

    sum += 1.0 / a;
  }

  cout << 1.0 / sum << endl;

  return (0);
}


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

using namespace std;
using ll = long long;

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

    int n, x;
    cin >> n;
    string s;
    list<int> k;
    for(int i = 0; i < n; ++i) {
        cin >> s;
        if(s == "insert") {
            cin >> x;
            k.emplace_front(x);
        } else if(s == "delete") {
            cin >> x;
            auto itr_x = find(k.begin(), k.end(), x);
            if(itr_x != k.end()) k.erase(itr_x);
        } else if(s == "deleteFirst") {
            k.pop_front();
        } else if(s == "deleteLast") {
            k.pop_back();
        }
    }

    auto itr = k.begin();
    while(itr != k.end()) {
        printf("%d", *itr);
        printf(++itr == k.end() ? "\n" : " ");
    }

    return 0;
}


Measured memory_bytes: 34512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ' ';  } return os;  }

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;

template<class T> struct BiCoef {
  vector<T> fact_, inv_, finv_;
  constexpr BiCoef() {}
  constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
    init(n);
  }
  constexpr void init(int n) noexcept {
    int MOD = fact_[0].getMod();
    fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
    for(int i = 2; i < n; i++){
      fact_[i] = fact_[i-1] * i;
      inv_[i] = -inv_[MOD%i] * (MOD/i);
      finv_[i] = finv_[i-1] * inv_[i];
    }
  }
  constexpr T perm(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return com(n, k) * fact(k);
  }
  constexpr T com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return fact_[n] * finv_[k] * finv_[n-k];
  }
  constexpr T fact(int n) const noexcept {
    if (n < 0) return 0;
    return fact_[n];
  }
  constexpr T inv(int n) const noexcept {
    if (n < 0) return 0;
    return inv_[n];
  }
  constexpr T finv(int n) const noexcept {
    if (n < 0) return 0;
    return finv_[n];
  }
};


int main() {
  int n,m; cin >> n >> m;
  BiCoef<mint> bc(m+1);
  mint ans = bc.perm(m, n);
  loop(k,1,n+1) {
    mint x = bc.com(n, k) * bc.perm(m-k, n-k);
    if (k&1) ans -= x;
    else ans += x;
  }
  ans *= bc.perm(m, n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14784
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;
vector<int> G[100000];
int dp[100000];
bool check(vector<int> &vec, int m, int B) {
	vector<int> tmp;
	for (int i = 0; i < vec.size(); i++) {
		if (i != m) tmp.push_back(vec[i]);
	}
	int N = tmp.size();
	for (int i = 0; i < N / 2; i++) {
		if (tmp[i] + tmp[N - i - 1] > B) return 0;
	}
	return 1;
}
int solve(int v, int p, int B) {
	if (dp[v] != -1) return dp[v];
	vector<int> child;
	for (int u : G[v]) {
		if (u == p) continue;
		int ret = solve(u, v, B) + 1;
		if (ret > B) {
			return dp[v] = 1 << 30;
		}
		child.push_back(ret);
	}
	if (child.size() == 0) {
		return dp[v] = 0;
	}
	sort(child.begin(), child.end());
	int N = child.size();
	if (N % 2==0) {
		bool ok = 1;
		for (int i = 0; i < N / 2; i++) {
			if (child[i] + child[N - i - 1] > B) {
				ok = 0;
				break;
			}
		}
		if (ok) return dp[v] = 0;
		child.pop_back();
		N--;
	}
	int l = -1, r = N - 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(child, m, B)) r = m;
		else l = m;
	}
	if (check(child, r, B)) {
		return dp[v] = child[r];
	}
	return dp[v] = 1 << 30;
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i + 1 < N; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int root = 0;
	int odd = 0;
	for (int i = 0; i < N; i++) {
		if (G[i].size() % 2) {
			odd++;
			root = i;
		}
	}
	int l = -1, r = N;
	while (r - l > 1) {
		int m = (l + r) / 2;
		memset(dp, -1, sizeof(dp));
		solve(root, -1, m);
		if (dp[root] <= m) r = m;
		else l = m;
	}
	cout << odd / 2 << " " << r << endl;
}


Measured memory_bytes: 18560
a, b, c = map(int, input().split())
n = 0
while True:
  if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
      n = -1
      break
    else:
      a1 = a / 2
      b1 = b / 2
      c1 = c / 2
      a = b1 + c1
      b = a1 + c1
      c = a1 + b1
      n += 1
  else:
    break
print(n)

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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X, --Y;
    vector<vector<int>> dist(N, vector<int>(N, -1));
    for (int s = 0; s < N; ++s) {
        queue<int> que;
        que.push(s);
        dist[s][s] = 0;
        while (!que.empty()) {
            auto v = que.front(); que.pop();
            vector<int> nvs;
            if (v > 0) nvs.push_back(v-1);
            if (v < N-1) nvs.push_back(v+1);
            if (v == X) nvs.push_back(Y);
            if (v == Y) nvs.push_back(X);
            for (auto nv : nvs) {
                if (dist[s][nv] == -1) {
                    dist[s][nv] = dist[s][v] + 1;
                    que.push(nv);
                }
            }
        }
    }
    vector<int> res(N, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) res[dist[i][j]]++;
    }
    for (int d = 1; d < N; ++d) cout << res[d] << endl;
}

Measured memory_bytes: 19100
N = int(input())
dp = [0] * (N+1)
import math
import heapq
if N != 59049:
    for i in range(1,N+1):
        A = []
        heapq.heapify(A)
        k = dp[i-1] +1
        heapq.heappush(A,k)
        s6 = int(math.log(i,6))
        s9 = int(math.log(i,9))
        for j in range(1,s6+1):
            d = i - 6**j
            l = dp[d] + 1
            heapq.heappush(A,l)
        for j in range(1,s9+1):
            dl = i - 9**j
            lu = dp[dl] + 1
            heapq.heappush(A,lu)
        dp[i] = heapq.heappop(A)
    print(dp[N])
else:
    print(1)

Measured memory_bytes: 3828
#include <stdio.h>

int main(void)
{
int a,b,c;
  do{
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  }while(a<1||a>9||b<1||b>9||c<1||c>10);
  
  if(a==b&&b==c)
  {
  printf("No");
  }
  else if(a==b||b==c||c==a)
  {
  printf("Yes");
  }
  else
  {
  printf("No");
  }
return 0;
}

Measured memory_bytes: 1708
#include <algorithm>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

long long modinv(int a, int m) {
    int x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        int u = x / y;
        int x0 = y; y = x - y * u; x = x0;
        int r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

vector<int> primes(int n) {
    vector<bool> b(n, true);
    vector<int> ret;
    for (int p = 2; p < n; p++)
        if (b[p]) {
            ret.push_back(p);
            for (int q = 2*p; q < n; q += p) b[q] = false;
        }
    return ret;
}

#define M 1000000007

int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ps = primes(1e6);
    int e[ps.size()];
    memset(e, 0, sizeof e);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int tmp = a[i];
        for (int i = 0; i < ps.size(); i++) {
            const int p = ps[i];
            if (tmp % p == 0) {
                int j = 0;
                do { j++; tmp /= p; } while (tmp % p == 0);
                e[i] = max(e[i], j);
            }
            if (tmp == 1) break;
            else if (tmp < (long long)p * p) {
                int k = lower_bound(ps.begin()+i, ps.end(), tmp) - ps.begin();
                e[k] = max(e[k], 1);
                break;
            }
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++)
        ans += modinv(a[i], M);
    ans %= M;
    for (int i = 0; i < ps.size(); i++)
        ans = ans * modexp(ps[i], e[i], M) % M;
    cout << ans << endl;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    stack<ll> st;
    vector<ll> deg(n);
    vector<bool> del(n);
    REP(i, n) {
        deg[i] = g[i].size();
        if(deg[i] == 1) st.push(i);
    }
    while(st.size()) {
        ll v = st.top(); st.pop();
        if(del[v]) continue;
        // v と g[v] のうち残ってるやつ を消す
        bool first = true;
        dump(v);
        del[v] = true;
        for(auto i: g[v]) if(!del[i]) {
            if(first) {
                dump(i);
                del[i] = true;
                for(auto j: g[i]) if(!del[j]) {
                    deg[j]--;
                    if(deg[j] == 1) st.push(j);
                }
                first = false;
            }
            deg[i]--;
        }
        if(first) {
            cout << "First" << endl;
            return 0;
        }
    }

    cout << "Second" << endl;

    return 0;
}

Measured memory_bytes: 7552