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

void call(int n)
{
  for (int i = 1; i <= n; ++i)
  {
    int x=i;
    if(x%3==0)
    {
      cout<<" "<<i;
    }
    else if(x%10==3)
    {
      cout<<" "<<i;
    }
    else
    {
      x/=10;
      while(x){
        if(x%10==3)
        {
          cout<<" "<<i;
          break;
        }
        x/=10;
      }
    }
  }
  cout<<endl;
}


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


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main{
	char[] s;
	char[] t;
	char[] tmp;
	char[] ans;

	public boolean judge() {
		if(s.length < t.length) {
			return false;
		}

		int size = s.length - t.length + 1;
		boolean f = false;

		for(int i = 0; i < size; i++) {
			tmp = (char[])s.clone();
			if(search(i)) {
				f = true;
				convert();
				update();
			}
		}

		return f;
	}

	public boolean search(int k) {
		int i = k;
		int j = 0;

		while(j < t.length) {
			if(s[i] == t[j]) {
				i++; j++;
				continue;
			}
			else if(s[i] != '?' && s[i] != t[j]) {
				return false;
			}
			else if(s[i] == '?') {
				tmp[i] = t[j];
			}
			i++; j++;
		}

		return true;
	}

	public void convert() {
		for(int i = 0; i < tmp.length; i++) {
			if(tmp[i] == '?') {
				tmp[i] = 'a';
			}
		}
	}

	public void update() {
		if(ans == null) {
			ans = tmp;
			return;
		}

		boolean f = false;
		for(int i = 0; i < ans.length; i++) {
			if(ans[i] > tmp[i]) {
				f = true;
			}
		}

		if(f) {
			ans = tmp;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		s = sc.next().toCharArray();
		t = sc.next().toCharArray();

		if(judge()) {
			System.out.println(ans);
		}
		else {
			System.out.println("UNRESTORABLE");
		}
	}

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


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y;
}a[200010];
priority_queue<int>q;
int n,m,ans,cnt,b[200010];
bool cmpx(aaa a,aaa b){
	return a.x<b.x;
}
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int i,l,r;
	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++)scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+m+1,cmpx);
	l=1;r=n;
	for(i=1;i<=m;i++){
		q.push(-a[i].y);
		if(l<=r&&l<=a[i].x)l++;
		 else{
		 	b[++cnt]=-q.top();q.pop();
		 }
	}
	sort(b+1,b+cnt+1,cmp);
	for(i=1;i<=cnt;i++){
		if(l<=r&&r>=b[i])r--;
		 else ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 3192
n = int(input())
a = b = ab = ans = 0
for i in range(n):
        s = input()
        if s[-1]=='A':
                if s[0]=='B': ab += 1
                else: a += 1
        elif s[0]=='B': b += 1
        ans += s.count("AB")

ans += max(0, ab - 1)
if a>0 and ab>0:
        ans += 1
        a -= 1
if b>0 and ab>0:
        ans += 1
        b -= 1
ans += min(a, b)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int a[5],i;
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i=0;i<5;i++)
    {
        if(a[i]==0)
        {
            cout<<i+1;
            break;
        }
    }
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    // ostr << p.first << ", " << p.second;
    ostr << "(" << p.first << ", " << p.second << ")";
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, m, q, ans = 0;
    cin >> n >> m >> q;

    vvll x(q, vll(4));
    REP(i,q) REP(j,4) cin >> x[i][j];
    REP(i,q){
        x[i][0]--;
        x[i][1]--;
    }
    sort(x);

    vll a(n, 1);
    while(1){
        ll tmp = 0;
        REP(i,q){
            if(a[x[i][1]]-a[x[i][0]]==x[i][2]) tmp += x[i][3];
            // dump(tmp);
            chmax(ans, tmp);
        }
        RREP(i,n){
            if(a[i]!=m){
                a[i]++;
                FOR(j,i+1,n-1) a[j]=a[i];
                break;
            }
        }
        // dump(a);
        if(a[0]==m) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int maximam(int a,int b,int c){
  if(a>=b&&a>=c) return a;
  else if(b>=a&&b>=c) return b;
  else return c;
}
int main(){
  int A,B;
  cin>>A>>B;
  int x=maximam(A+B,A-B,A*B);
  cout<<x<<endl;
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
ll n,ans;
int main() {
	cin>>n;
	rep1(i,1,n){
		if(i%3!=0&&i%5!=0&&i%15!=0)ans+=i;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
unittest
{
	assert( [ "2 3 -10", "1 2 3", "3 2 1", "1 2 2" ].parse.expand.solve == 1 );
	assert( [ "5 2 -4", "-2 5", "100 41", "100 40", "-3 0", "-6 -2", "18 -13" ].parse.expand.solve == 2 );
	assert( [ "3 3 0", "100 -100 0", "0 100 100", "100 100 100", "-100 100 100" ].parse.expand.solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nmc = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	auto ass = new long[][]( nmc[ 0 ], nmc[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	return tuple( nmc[ 2 ], bs, ass );
}

auto solve( long c, long[] bs, long[][] ass )
{
	auto ans = 0L;
	
	foreach( as; ass )
	{
		auto s = 0L;
		foreach( a, b; lockstep( as, bs ) )
		{
			s += a * b;
		}
		ans += ( 0 < s + c );
	}
	
	return ans;
}


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

int main() {
  int n; cin >> n;
  vector<int> h(n); REP(i, n) cin >> h[i];
  string ans = "Yes";
  
  if (n > 1) {
    vector<int> s(n-1); s[n-2] = h[n-1];
    for (int i = n-3; i >= 0; --i) s[i] = min(h[i+1], s[i+1]);
    
    REP(i, n-1) {
      if (h[i] > s[i] + 1) {
        ans = "No"; break;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	int h,w,i,j,weather[101][101],k;
	char sky[101][101];
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",sky[i]);
		for(j=0;j<w;j++){
				weather[i][j]=-1;
			}
	}
	for(i=0;i<h;i++){
		k=-1;
		for(j=0;j<w;j++){
			if(sky[i][j]=='c'){
				k=0;
			}
			else if(k>=0){
				k++;
			}
			weather[i][j]=k;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			printf("%d",weather[i][j]);
			if(j<w-1){
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}


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

// THINK: INT vs LONG LONG?

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

	int n, k;
	cin >> n >> k;
	vector<bool> dislikes(10);
	for (int i = 0; i < k; ++i) {
		int d;
		cin >> d;
		dislikes[d] = true;
	}
	for (int i = n; true; ++i) {
		bool good = 1;
		for (auto& c: to_string(i)) {
			good &= !dislikes[c - '0'];
		}
		if (good) {
			cout << i << '\n';
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int D;
	cin>>D;
	
	if(D==25)
	cout<<"Christmas"<<endl;
	else if(D==24)
	cout<<"Christmas Eve"<<endl;
	else if(D==23)
	cout<<"Christmas Eve Eve"<<endl;
	else
	cout<<"Christmas Eve Eve Eve"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int c[20],a[20][20],b[20];
int main(void)
{
    int n,m,x,bc,mn=1e9;
    bool d=false;
    cin >> n >> m >> x;
    for(int i=0;i<n;i++)
    {
        cin >> c[i];
        for(int j=0;j<m;j++)
            cin >> a[i][j];
    }
    for(int k=0; k<(1<<n); k++)
    {
        int cnt=0;
        bc=0;
        for(int j=0;j<m;j++)
            b[j]=0;
        for(int i=0; i<n; i++)
        {
            if(k>>i & 1)
            {
                bc+=c[i];
                for(int j=0;j<m;j++)
                    b[j]+=a[i][j];
            }
        }
        for(int j=0;j<m;j++)
            if(b[j]>=x)
                cnt++;
        if(cnt==m)
        {
            mn=min(mn,bc);
            d=true;
        }
    }
    if(d==false)
        cout << "-1";
    else
        cout << mn;
    return 0;
}

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


int main(void){
  int N;
  int Wi[N];

  scanf("%d",&N);//入力

  for(int i = 0; i < N; i ++) {
    scanf("%d",&Wi[i]);//入力
  }

  int counter = 0;
  int minimum = 0;
  for(int T = 0; T < N; T ++){
    int S1 = 0;
    for(int i = 0; i < T; i ++){
      S1 += Wi[i];
    }
    int S2 = 0;
    for(int i = T; i < N; i ++){
      S2 += Wi[i];
    }

    long int tmp = S2 - S1;
    if(tmp < 0) tmp = -1 * tmp;

    if(counter == 0 || tmp < minimum){
      minimum = tmp;
    }

    counter ++;
  }
  printf("%d\n", minimum);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
    char c[3];
    scanf("%c%c%c", &c[0], &c[1], &c[2]);
  	int flag = 0;
    for(int i = 0;i < 3;i++) {
      	if((c[i] - '0') == 7) flag = 1;
    }
  	printf(flag ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


vector<int> a, b, c, d;
int n, m, q;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        //cal score
        int now = 0;
        rep(i,q){
            if(A[b[i]]-A[a[i]] == c[i]){
                now += d[i];
            }
        }
        ans=max(ans, now);
        return ;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }

}

int main(){
    fast_io
    
    cin>>n>>m>>q;
    a = b = c = d = vector<int>(q);

    rep(i,q) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(vector<int>(1,1));
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}



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

int main() {
	// your code goes here
	int h,n;
	cin >> h;
	cin >> n;
	int temp=h;
	int arr[n];
	for(int i=0; i<n; i++)
	{
		cin >> arr[i];
		temp-=arr[i];
	}
	if(temp<=0)
	cout << "Yes" << " ";
	else
	cout << "No";
	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

signed main() {
  ll L,R,ans=2222;
  cin>>L>>R;
  if (L/2019 != R/2019) {
    ans = 0;
  } else {
    L %= 2019;
    R %= 2019;
    rep(i,L,R+1)
      rep(j,i+1,R+1)
        ans=min(ans, i*j%2019);
  }
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    int a,b;
    cin >>a>>b;
    cout <<max({a+b,a-b,a*b})<<endl;
    return 0;
}



Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
    n:usize,k:i64,
    a:[ [i64;n];n],
     }
    let mut mata = Matrix::new(a.clone());
    let matp = mata.pow(k as usize, MOD);
    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            ans = (ans + matp[i][j]) % MOD;
        }
    }
    println!("{}", ans);
}
const MOD: i64 = 1000000007;

struct Matrix {
    m: Vec<Vec<i64>>,
}
impl Matrix {
    fn new(v: Vec<Vec<i64>>) -> Matrix {
        Matrix { m: v }
    }
    fn set(&mut self, v: Vec<Vec<i64>>) {
        self.m = v.clone();
    }
    fn dot(&self, m: &Matrix, md: i64) -> Vec<Vec<i64>> {
        let a = self.m.len();
        let b = self.m[0].len();
        let c = m.m[0].len();
        let mut ret = vec![vec![0; c]; a];
        for i in 0..a {
            for j in 0..c {
                for k in 0..b {
                    ret[i][j] += (self.m[i][k] % md) * (m.m[k][j] % md) % md;
                }
            }
        }
        ret
    }
    fn pow(&mut self, k: usize, md: i64) -> Vec<Vec<i64>> {
        let n = self.m.len();
        let mut y = vec![vec![0; n]; n];
        for i in 0..n {
            y[i][i] = 1;
        }
        let mut z = self.m.clone();
        let mut k = k;
        while k > 0 {
            if k & 1 == 1 {
                y = Matrix::new(y).dot(&Matrix::new(z.clone()), md);
            }
            z = Matrix::new(z.clone()).dot(&Matrix::new(z.clone()), md);
            k >>= 1;
        }
        y
    }
}


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

int main(){
    ll h; cin>>h;
    ll enenum = 1;
    ll count = 0;

    do{
        count += enenum;
        h /= 2;
        enenum *= 2;
    }while(h != 0);

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    }
    else cout << n * 2 << endl;
}

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

typedef long long ll;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-f;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return f*x;
}

int main()
{
    int l, r, d;
    scanf("%d%d%d",&l,&r,&d);
    l--;
    l=l/d;
    r=r/d;
    printf("%d\n",r-l);
    return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

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

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

void func(int a, bool i){
    cout << a;
    if(a==100){
        i=1;
    }
    else if(a==0){
        return;
    }
    if(!i)
        func(a+1, i);
    else
        func(a-1, i);
}

int cnt[500000];

signed main(){   
    fast;
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    // if(n==1)
    int dp[n+1]={};
    dp[0]=0;
    // dp[1]=a[0];
    for(int i=1; i<n; i++){
        int r=INT_MAX;
        for(int j=1; j<=k && i-j>=0; j++){
            r = min(r, dp[i-j] + abs(a[i-j]-a[i]));
        }
        // cout << r << " ";
        dp[i]=r;
    }
    cout << dp[n-1];
} 

Measured memory_bytes: 5132
n=int(input())

n100 = 0
n10 = 0
n1 = 0


while 1:
    n100 = n//100
    n10 = (n-n100*100)//10
    n1 = (n-n100*100-n10*10)
    if (n100 == n10) and (n10==n1):
        print(n)        
        break
    if n>= 1000:
        break
    n+=1

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

int main()
{
  int n;
  cin >> n;
  int count = 0;
  for (int i=1;i<=n;i=i+2) {
    int yaku = 0;
    for(int j=1;j<=i;++j){
      if (i % j == 0) {
        ++yaku;
      }
     if (yaku == 8) count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  //  g++ -std=c++14 -o a a.cpp

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

vector<int> rs; // 巡回必要なもの全てRs
int Cs[201][201] = {0}; // 全パスの距離

int main() {

  int N, M, R;
  cin >> N >> M >> R;
  
  rep(i, R) {
    int r;
    cin >> r;
    rs.pb(r);
  }

  for (int i = 1; i <= N; i++) { 
    for (int j = 1; j <= N; j++) { 
      if (i != j) {
        Cs[i][j] = INF;
      }
    }
  } // fill

  rep(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    Cs[A][B] = C;
    Cs[B][A] = C;
  }

  // cout << "---------" << endl;
  // for (int i = 1; i <= N; i++) { 
  //   for (int j = 1; j <= N; j++) { 
  //     DEBUG(i);
  //     DEBUG(j);
  //     DEBUG(Cs[i][j]);
  //   }
  // }
  // cout << "---------" << endl;

  // 1. ワーシャルフロイドですべての頂点の対の最小距離を求める
  for (int k = 1; k <= N; k++) {
    for (int i = 1; i <= N; i++) { 
      for (int j = 1; j <= N; j++) { 
        if(Cs[i][k] != INF && Cs[k][j] != INF) { // オーバーフロー対策!!!!
          Cs[i][j] = min(Cs[i][j], Cs[i][k] + Cs[k][j]);
        }
      }
    }
  }

  // for (int i = 1; i <= N; i++) { 
  //   for (int j = 1; j <= N; j++) { 
  //     DEBUG(i);
  //     DEBUG(j);
  //     DEBUG(Cs[i][j]);
  //   }
  // }

  // 2. rsのすべての順列組み合わせを作り、最短距離を使ってそれぞれの全コストを求め、最短を出力
  vector<int> paths = rs;
  int min = INF;
  sort(all(paths)); // next_permutation は sortされている必要があった！
  do {
    int sum = 0;
    for (int i = 0; i < R - 1; i++) {
      int start = paths[i];
      int end = paths[i + 1];
      sum = sum + Cs[start][end];
      // cout << start << "->" << end << " ";
    }
    // cout << " : " << sum << endl;
    if (sum <= min) min = sum;
  } while (next_permutation(all(paths)));

  cout << min << endl;
}


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

int main()
{
  int n, m;
  while( cin >> n >> m, n && m ) {
    int sum1 = 0, sum2 = 0;
    int s1[100], s2[100];
    int a = 1e8, b = 1e8;
    
    for(int i=0; i<n; i++) cin >> s1[i], sum1 += s1[i];
    for(int i=0; i<m; i++) cin >> s2[i], sum2 += s2[i];

    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	if( (s1[i] - s2[j]) * 2 == sum1 - sum2 && a + b > s1[i] + s2[j] ) a = s1[i], b = s2[j];
      }
    }

    if( a == 1e8 ) cout << -1 << endl;
    else cout << a << " " << b << endl;
  }
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m;
vector<int>v[N];
int main()
{
    scanf("%d%d",&n,&m);
    int k;scanf("%d",&k);
    while(k--)
    {
        int x,y;scanf("%d%d",&x,&y);
        v[y].push_back(x);
    }
    v[1].push_back(n+1);
    for(int i=1;i<=m;i++) sort(v[i].begin(),v[i].end());
    int l=0,r=n+1;
    for(int i=1;i<=m;i++)
    {
        l++;
        if(l>=r) break;
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j]==l) l++;
            else if(v[i][j]>l)
            {
                r=min(r,v[i][j]);
                break;
            }
        }
    }
    printf("%d\n",r-1);
}


Measured memory_bytes: 8704
import operator


class SegmentTree:
    # http://tsutaj.hatenablog.com/entry/2017/03/29/204841
    def __init__(self, size, fn=operator.add, default=0):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        """
        # size 以上である最小の 2 冪
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._tree = [default for _ in range(self._size * 2 - 1)]
        self._fn = fn

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param int value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param int value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size


N, Q = list(map(int, input().split()))
com, X, Y = zip(*[input().split() for _ in range(Q)])
X = list(map(int, X))
Y = list(map(int, Y))

if __name__ == '__main__':
    st = SegmentTree(size=N + 1, fn=min, default=2 ** 31 - 1)
    for c, x, y in zip(com, X, Y):
        if c == '0':
            st.set(x, y)
        if c == '1':
            print(st.get(x, y + 1))



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

using namespace std;

int factor(int n){
    int out=1;
    for(int i=2;i<=n;++i){
        out *= i;
    }
    return out;
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> v(N);
    vector<string> S(factor(N));
    string SP, SQ;

    for(int i=0;i<N;++i){
        cin >> P[i];
        SP.push_back(P[i]);
    }
    for(int i=0;i<N;++i){
        cin >> Q[i];
        SQ.push_back(Q[i]);
    }

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

    int c=0;
    do{
        for(int i=0;i<N;++i){
            S[c].push_back(v[i]);
        }
        ++c;
    }while(next_permutation(v.begin(), v.end()));
    sort(S.begin(), S.end());
    int a, b;
    for(int i=0;i<factor(N);++i){
        if(S[i] == SP){
            a = i + 1;
        }
        if(S[i] == SQ){
            b = i + 1;
        }
    }
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 2432
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		boolean flg = Math.abs(A-N)>Math.abs(B-N);
		if(flg){
			out.println("B");
		}else{
			out.println("A");
		}
		out.flush();	
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	string s;
	cin>>s;
	rep(i,3){
		if(s[i] == '1'){
			s[i] = '9';
		}else{
			s[i] = '1';
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> ps(N);
    rep(i, N){
        cin >> ps[i];
    }
    sort(ps.begin(), ps.end());
    int ans = 0;
    rep(i, N){
        if(i == N - 1){
            ans += ps[i] / 2;
        }else{
            ans += ps[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h[1005];
int main()
{
    int n,t,a;
    scanf("%d",&n);
    scanf("%d%d",&t,&a);
    for(int i=0;i<n;i++) scanf("%d",&h[i]);
    int ans;
    double p;
    for(int i=0;i<n;i++)
    {
        double k=t*1.0-h[i]*0.006;
        if(i==0)
        {
            p=abs(a-k);
            ans=i+1;
        }
        else
        {
            double pp=abs(a-k);
            if(pp<p)
            {
                ans=i+1;
                p=pp;
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int K, N;
  rd(N);
  rd(K);
  if(N%K){
    wt_L(1);
    wt_L('\n');
  }
  else{
    wt_L(0);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// {
//   int N, K;
//   rd(N,K);
//   wt( if[N%K, 1, 0] );
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

template<int N, int MOD>
struct Comb {
	ll fact[N + 1], inv[N + 1];
	Comb() {
		fact[0] = inv[0] = inv[1] = 1;
		for (int i = 2; i <= N; i++) inv[i] = (MOD + ((ll)-inv[MOD%i] * (MOD / i)) % MOD) % MOD;
		REPS(i, N) {
			fact[i] = fact[i - 1] * i%MOD;
			inv[i] = inv[i] * inv[i - 1] % MOD;
		}
	}
	ll operator()(int n, int r) {
		if (n < 0 || r < 0 || r > n) return 0;
		ll res = inv[r] * inv[n - r];
		if (res >= MOD) res %= MOD;
		res *= fact[n];
		if (res >= MOD) res %= MOD;
		return res;
	}
};
Comb<300000, MOD> C;

const int INV2 = (MOD + 1) / 2;

int T, n, m;
int d[4002][4002], out[4002][4002];
int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	ll ans = 0;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		d[2000 - a][2000 - b] ++;
		out[2000 + a][2000 + b] ++;
		ans = ans + MOD - C(2*a + 2*b, 2*a);
	}
	REP(i, 4001)REP(j, 4001) {
		if (out[i][j]) {
			ans += (ll)d[i][j] * out[i][j] % MOD;
		}
		d[i + 1][j] = (d[i + 1][j] + d[i][j]) % MOD;
		d[i][j + 1] = (d[i][j + 1] + d[i][j]) % MOD;
	}
	cout << ans % MOD * INV2 % MOD << endl;
	return 0;
}


Measured memory_bytes: 90880
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AServalVsMonster solver = new AServalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class AServalVsMonster {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long h = s.nextLong(), a = s.nextLong();
            w.println((h - 1) / a + 1);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21332
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val S = "0" + in.next()

  def piyo(c: Char): Int = if(c == 'B') 1 else 0


  val MOD = 1e9.toInt + 7

  var ans = 1L
  var cnt = 0L
  breakable {
    for (i <- 1 to 2*N) {
      if (piyo(S(i)) == i % 2) {
        cnt += 1
      }
      else {
        if (cnt == 0) {
          ans = 0
          break
        }
        else {
          ans *= cnt
          ans %= MOD
          cnt -= 1
        }
      }
    }
  }
  if (cnt > 0)
    ans = 0

  val mc = new ModComb(N, MOD)
  ans *= mc.fact(N)
  ans %= MOD

  println(ans)
}

class ModComb(maxNum: Int, mod: Long) {

  private def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2)
    else
      (x * repeatSquares(x*x % mod, n/2)) % mod
  }

  val fact = new Array[Long](maxNum + 1)

  fact(0) = 1
  for (i <- 1 to maxNum)
    fact(i) = (i * fact(i-1)) % mod

  private val factInv = new Array[Long](maxNum + 1)

  factInv(maxNum) = repeatSquares(fact(maxNum), mod-2)
  for (i <- (1 to maxNum).reverse)
    factInv(i-1) = (i * factInv(i)) % mod


  // nCk
  def comb(n: Int, k: Int): Long = {
    val numer = fact(n)
    val denom = (factInv(n-k) * factInv(k)) % mod

    (numer * denom) % mod
  }

}



class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 31496
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var K = int.Parse(ReadLine());
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var A = raw[0];
            var B = raw[1];

            var ans = "NG";

            for (int i = A; i <= B; i++)
            {
                if (i % K == 0) ans = "OK";
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28144
import java.util.Scanner;

// 
class Main{
    final static int MOD = (int)Math.pow(10, 9) + 7;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];

        long sum = 0;	// n-1項までの合計
        long ans = 0;
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
            sum %= MOD;
        }
        
        for(int i = 0; i < N - 1; i++) {
        	sum -= a[i];
        	if(sum < 0) sum += MOD;
            ans += a[i] * sum;
            ans %= MOD;
        }
        
        System.out.println(ans % MOD);
    }

}


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

int main(){
  int x,y,n;cin>>x>>y>>n;
  int zx=0,zy=0;
  for(int i=0;i<n;i++){
    int s,t,a; cin>>s>>t>>a;
    if(a==1){
      if(zx<s) zx=s;
    }else if(a==2){
      if(x>s) x=s;
    }else if(a==3){
      if(zy<t) zy=t;
    }else{
      if(y>t) y=t;
    }
  }if(x-zx<=0 || y-zy<0){
    cout<<0<<endl;
  }else{
    cout<<(x-zx)*(y-zy)<<endl;
  }
}

Measured memory_bytes: 256
N,K=input().split()
D=input().split()
frag=0

while True:
    for s in D:
        if N.count(s)!=0:
            frag=1

        else:
            pass
    if frag==1:
        a=int(N)+1
        N=str(a)

    else:
        break

    frag=0

print(N)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << ((A == 7 && B == 5 && C == 5) || (A == 5 && B == 7 && C == 5) || (A == 5 && B == 5 && C == 7) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn solve(i: usize, c: usize, v: usize, n: usize, a: usize, xs: &Vec<usize>, dp: &mut Vec<Vec<Vec<i64>>>) -> i64 {
    if i == n {
        if c == 0 { 
            return if a == 0 { 1 } else { 0 };
        }
        return if v % c == 0 && v / c == a { 1 } else { 0 };
    }
    if dp[i][c][v] == -1 {
        dp[i][c][v] = solve(i+1, c, v, n, a, xs, dp) + solve(i+1, c+1, v + xs[i], n, a, xs, dp);
    }
    return dp[i][c][v];
}

fn main() {
    let (n, a) = get!(usize, usize);
    let xs = get!(String).split_whitespace().map(|t| t.parse::<usize>().unwrap()).collect::<Vec<_>>();
    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![-1; 50*n+1]; n+1]; n+1];
    println!("{}", solve(0, 0, 0, n, a, &xs, &mut dp));
}

Measured memory_bytes: 67836
#include<bits/stdc++.h>
#define re register
using namespace std;
template <typename T> inline void read(T &x)
{
	x=0;int f=1;char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;
}
template <typename T> inline void print(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+48);
}
const int maxn=5e5+5;
int nxt[maxn][27],ri[maxn][20];
char s[maxn];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	int dlen=len+1,slen=len-1;
	for(re int i=0;i<=dlen;++i)
		for(re int j=0;j<=26;++j)
			nxt[i][j]=dlen;
	for(re int i=0;i<=dlen;++i)
		for(re int j=0;j<=19;++j)
			ri[i][j]=dlen;
	for(re int i=slen;i>=0;--i)
	{
		int x=s[i+1]-'a';
		nxt[i][x]=i+1;
		for(re int j=x+1;j<=26;++j)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
		for(re int j=0;j<x;++j)
			nxt[i][j]=nxt[nxt[i][26]][j];	
	}
	for(re int j=0;j<=19;++j)
		for(re int i=slen;i>=0;--i)
			if(j==0) ri[i][j]=nxt[i][26];
			else ri[i][j]=ri[ri[i][j-1]][j-1];
	int q,l,r;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&l,&r);
		l--;
		for(re int j=19;j>=0;--j)
			if(ri[l][j]<=r) l=ri[l][j];
		if(l==r) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 92928
def main():
    n, k = list(map(int,input().split()))

    if n > k:
        print(0)
        return

    mod = int(1e9+7)
    ans = 1
    for i in range(0, n):
        ans = (ans * (k-i)) % mod

    print(ans)

if __name__ == '__main__':
    main()



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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    char X, Y;
    cin >> X >> Y;
    if(X > Y){
        cout << ">" << endl;
    }else if(X < Y){
        cout << "<" << endl;
    }else{
        cout << "=" << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using node = tuple<ll, ll>;
const int inf = numeric_limits<int>::max();

int main(void) {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll res = 0;

  ll num_a = min(a, k);
  res += num_a;
  k -= num_a;
  if (k == 0) {
    cout << res << endl;
    return 0;
  }

  ll num_b = min(b, k);
  k -= num_b;
  if (k == 0) {
    cout << res << endl;
    return 0;
  }

  ll num_c = min(c, k);
  res -= num_c;
  k -= num_c;
  assert(k == 0);
  cout << res << endl;
  return 0;
}


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

using namespace std;

struct UnionFind{

vector<int> d;

UnionFind(int n=0) : d(n,-1){};

int find(int x){
  if(d[x]<0) return x;
  return d[x] = find(d[x]);
}
bool unite(int x,int y){
  x = find(x);y = find(y);
  if(x == y) return false;
  if (d[x] > d[y] ) swap(x,y);
  d[x] += d[y];
  d[y] = x;
  return true;
}
bool same(int x,int y){return find(x) == find(y);}
bool size(int x){ return -d[find(x)];}

};

int main(){
  
  int n,m; cin >> n >> m;
  int a[m],b[m],cnt=0;

  
  for (int i = 0; i < m; ++i)
   {
     cin >> a[i] >> b[i];
     a[i]--;b[i]--;
   } 

  for (int i = 0; i < m; ++i)
  {
    UnionFind uf(n);
    for (int j = 0; j < m; ++j)
    {
      if(j!=i) uf.unite(a[j],b[j]);
      else continue;
    }

      if (!uf.same(a[i],b[i])){
        cnt++;
      }
    
  }
  cout << cnt;
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N, T;
	cin >> N >> T;

	int cmin = 1001;
	for( int i = 0; i < N; ++i ) {
		int c, t;
		cin >> c >> t;

		if( t <= T && c < cmin ) {
			cmin = c;
		}
	}

	if( cmin > 1000 ) {
		cout << "TLE\n";
	}
	else {
		cout << cmin << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                                              
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
  
#define push_back pb
#define PII pair<int,int>    
  
#define VS vector<string>    
#define VI vector<int>
#define ll long long int     
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {   
     ll h, w; cin >> h >> w; 
     //if(!(w%3 && h%3)) cout << 0 << endl;
     if(h<0);      
     else {        
         ll ans = INT_MAX;
         ll ar1=0, ar2=0, ar3=0;
         FOR(i,1,w) {
            ar1 = h*i;
            ar2 = (w-i)*(h/2);
            ar3 = (w-i)*((h/2)+1);
            if(h%2) ans = min(ans,max(abs(ar1-ar2),max(abs(ar2-ar3),abs(ar3-ar1))));
            else ans = min(ans,abs(ar1 - ar2));
//debug(ans);      
         }         
//debug(ans);
         
         FOR(i,1,h) {
            ar1 = w*i;
            ar2 = (h-i)*(w/2);
            ar3 = (h-i)*((w/2)+1);
            if(w%2) ans = min(ans,max(abs(ar1-ar2),max(abs(ar2-ar3),abs(ar3-ar1))));
            else ans = min(ans,abs(ar1 - ar2));
//debug(ans);
         }
//debug(ans);
        if(w > 2) {
         FOR(i,1,w-1) {
             ar1 = i*h;
             ar2 = ((w-i)/2)*h;
             ar3 = ((w-i)/2+1)*h;
             if((w-i)%2) ans = min(ans,max(abs(ar1-ar2),max(abs(ar2-ar3),abs(ar3-ar1))));
             else ans = min(ans,abs(ar1 - ar2));
         }
        }
//debug(ans);
        if(h > 2){
         FOR(i,1,h-1) {
             ar1 = i*w;
             ar2 = ((h-i)/2)*w;
             ar3 = ((h-i)/2+1)*w;
             if((h-i)%2) ans = min(ans,max(abs(ar1-ar2),max(abs(ar2-ar3),abs(ar3-ar1))));
             else ans = min(ans,abs(ar1 - ar2));
         }
        }
//debug(ans);
         cout << ans << endl;
     }
}

Measured memory_bytes: 256