akhauriyash/Code-Regression huggingface dataset:
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,m;cin>>n>>m;
    vl x(n),y(n),z(n);
    rep(i,n)cin>>x[i]>>y[i]>>z[i];

    ll ans=0;
    rep(i,1<<3){
        ll sig1=i&1?1:-1;
        ll sig2=i>>1&1?1:-1;
        ll sig3=i>>2&1?1:-1;
        vl cakes;
        rep(j,n){
            ll tmp=sig1*x[j]+sig2*y[j]+sig3*z[j];
            cakes.push_back(tmp);
        }
        sort(all(cakes),greater<>());
        ll sum=0;
        rep(j,m)sum+=cakes[j];
        chmax(ans,sum);
    }
    cout<<ans<<endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
vector<string> Split(char c,string s){
  vector<string> res(0);
  string str = "";
  rep(i,s.size()){
    if(s[i] == c){
      res.push_back(str);
      str.clear();
    }
    else{
      str += s[i];
    }
  }
  res.push_back(str);
  return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n&&n){
    string str;
    char k;
    map<string,ll> m;
    vector<pair<ll,string>> vps;
    cin.ignore();
    rep(i,n){
      getline(cin,str);
      auto vs = Split(' ',str);
      rep(j,vs.size()){
        m[vs[j]]--;
      }
    }
    cin >> k;
    for(auto n : m){
      vps.push_back(make_pair(n.se,n.fi));
    }
    sort(all(vps));
    string ans ="";
    ll cnt = 0;
    rep(i,vps.size()){
      if(cnt > 4) break;
      if(vps[i].se[0] == k){
        ++cnt;
        if(ans.size()){
          ans += " ";
        }
        ans += vps[i].se;
      }
    }
    if(ans.size())
      cout << ans << endl;
    else
      cout << "NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3184
import itertools
n = int(input())
p = [int(i)-1 for i in input().split()]
q = [int(i)-1 for i in input().split()]
m = sorted(p)
a = 0
b = 0
cnt = 1
#print(p,q)
for i in itertools.permutations(m, n):
  #print(list(i))
  if list(i) == p:
    a += cnt
  if list(i) == q:
    b += cnt
  if a!=0 and b!=0:
    break
  else:
    cnt += 1
    
print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;


const ll MOD = 1e9+7;

struct DICE{
    ll num[6];
    ll top;
    ll north,south,west,east;

    DICE(){
        top = 0;
        south = 1;
        east = 2;
        west = 3;
        north = 4;
    }

};


int main(){
    DICE d1,d2;
    ll roopcnt = 0;

    rep(i,0,6){
        cin >> d1.num[i];
    }
    rep(i,0,6){
        cin >> d2.num[i];
    }


    srand(time(NULL));
    while(roopcnt++ <= 1e6){
        ll rnd = rand() % 4;
        ll tmp;
        switch(rnd){
            case 0:
                tmp = d1.south;
                d1.south = 5 - d1.top;
                d1.north = d1.top;
                d1.top = tmp;
                break;
            case 1:
                tmp = d1.west;
                d1.west = 5 - d1.top;
                d1.east = d1.top;
                d1.top = tmp;
                break;
            case 2:
                tmp = d1.north;
                d1.north = 5 - d1.top;
                d1.south = d1.top;
                d1.top = tmp;
                break;
            case 3:
                tmp = d1.east;
                d1.east = 5 - d1.top;
                d1.west = d1.top;
                d1.top = tmp;
                break;
        }

        if(d1.num[d1.east] == d2.num[d2.east] && d1.num[d1.north] == d2.num[d2.north] && d1.num[d1.south] == d2.num[d2.south]){
            if(d1.num[d1.west] == d2.num[d2.west] && d1.num[d1.top] == d2.num[d2.top] && d1.num[5-d1.top] == d2.num[5-d2.top]){
                cout << "Yes" << endl;
                break;
            }
        }

        if(roopcnt > 1e6){
            cout << "No" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3132
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <ctime>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=3010, Mod=998244353;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
void print(int x) {if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
signed main()
{
	int a,b,d;
	char c;
	cin>>a>>b>>c>>d;
	int tt=b*100+d;
	a=a*tt;
	cout<<a/100<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,pos=0;
#define Maxn 100010
struct Data{
	int l,r;
}data[Maxn];
bool cmp(Data z1,Data z2){return z1.r<z2.r;}

int l1[Maxn],r1[Maxn],l2[Maxn],r2[Maxn];

int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;++i)scanf("%d%d",&data[i].l,&data[i].r);
	sort(data+1,data+n+1,cmp);
    for(register int i=1;i<=n;++i)
        if(data[i].l>data[pos].l)pos=i;
    int res=0,ans=0;
    for(int i=1;i<=n;++i)
        if(i!=pos&&i!=1)res=max(res,data[i].r-data[i].l+1);
    if(res)ans=max(ans,res+max(0,data[1].r-data[pos].l+1));
    l1[0]=1;r1[0]=1000000000;
    for(int i=1;i<=n;++i){
    	l1[i]=max(l1[i-1],data[i].l);
    	r1[i]=min(r1[i-1],data[i].r);
	}
	l2[n+1]=1;r2[n+1]=1000000000;
	for(int i=n;i>=1;--i){
		l2[i]=max(l2[i+1],data[i].l);
		r2[i]=min(r2[i+1],data[i].r);
	}
	for(int i=pos;i>=2;--i){
		int tmp=0;
		if(r2[i]>=l2[i])tmp+=r2[i]-l2[i]+1;
		if(r1[i-1]>=l1[i-1])tmp+=r1[i-1]-l1[i-1]+1;
		ans=max(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 2560
N=int(input())
S=input()

arr=[]
num=0
for i in range(N-1):
	if S[i+1]=='E':
		num=num+1

arr.append(num)

for i in range(N-1):
	if S[i]=='W':
		if S[i+1]=='E':
			arr.append(arr[-1])
		else:
			arr.append(arr[-1]+1)
	elif S[i+1]=='E':
		arr.append(arr[-1]-1)
	else:
		arr.append(arr[-1])

print(min(arr))


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

int main(void) {
    string N;

    cin >> N;
    if(N[1] - N[2]) {
        cout << "No\n";
    } else {
        if((!(N[0] - N[1])) || (!(N[2]-N[3]))) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long p[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%lld",p+i);
	long long ret=0;
	std::sort(p,p+a);
	reverse(p,p+a);
	for(int i=0;i<a;i++){
		ret=(ret+d2*p[i]%mod*(1+i*d2%mod))%mod;
	}
	ret=ret*pw(2,a*2)%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N; cin >> N;
    vector<ll> a(3*N);
    rep(i, 3*N) cin >> a[i];

    vector<ll> left(2*N, 0), right(2*N, 0);

    priority_queue<ll, vector<ll>, greater<ll>> lpq;
    ll lmax = 0;
    rep(i, N) { lpq.push(a[i]); lmax += a[i]; }
    left[N-1] = lmax;
    repr(i, N, 2*N){
        lmax += a[i];
        lpq.push(a[i]);
        lmax -= lpq.top();
        lpq.pop();
        left[i] = lmax;
    }

    priority_queue<ll> rpq;
    ll rmin = 0;
    repr(i, 2*N, 3*N) { rpq.push(a[i]); rmin += a[i]; }
    right[2*N-1] = rmin;
    reprrev(i, N, 2*N){
        rmin += a[i];
        rpq.push(a[i]);
        rmin -= rpq.top();
        rpq.pop();
        right[i-1] = rmin;
    }

    ll ans = -1e15;
    repr(i, N-1, 2*N) chmax(ans, left[i]-right[i]);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 8052
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007

int n, m;
int s[2000];
int t[2000];

int dp[2001][2001];


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

	cin >> n >> m;
	rep(i, n)cin >> s[i];
	rep(i, m)cin >> t[i];

	long long ans = 1;
	dp[0][0] = 1;
	rep(i, n) {
		int d = 0;
		rep(j,m) {
			(d += dp[i][j]) %= MOD;

			if (s[i] == t[j]) {
				(dp[i + 1][j + 1] += d) %= MOD;
				ans += d;
			}
			(dp[i + 1][j] += dp[i][j]) %= MOD;
		}
	}


	cout << ans % MOD << endl;

	return 0;
}

Measured memory_bytes: 15872
program MAIN
  implicit none
  integer :: money
  read (*,*) money
  
  
  print *, hisHappiness(money)
  stop
  contains
  
  integer function hisHappiness(value)
    implicit none
    integer :: value, happy500, happy5
    happy500 = value / 500 * 1000
    happy5 = mod(value, 500) / 5 * 5
    hisHappiness = happy500 + happy5
    return
  end function hisHappiness
  
end program MAIN

Measured memory_bytes: 768
//-----------------------
// author : xyqkoala
// time : 2020-07-01
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	string s;
	string t;
	getline(cin,s);
	getline(cin,t);
	int n = s.size();
	int res = 0;
	for(int i=0;i<n;i++){
		if(s[i] != t[i]) res++;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3800
use proconio::input;
use proconio::marker::Usize1;
use std::collections::{VecDeque, BinaryHeap};
use std::cmp::Reverse;

fn main()
{
    input! {
    n:usize,
    m:usize,
    edge:[(Usize1,Usize1,i64);m],
    }

    let mut node = vec![vec![]; n];
    for (i, &(a, b, c)) in edge.iter().enumerate() {
        node[a].push((b, c, i));
        node[b].push((a, c, i));
    }

    let inf = 1i64 << 60;
    let mut used = vec![false; m];
    for i in 0..n {
        let mut dist = vec![inf; n];
        dist[i] = 0;
        let mut q = BinaryHeap::new();
        q.push(Reverse((0, i)));
        while let Some(Reverse((cost, idx))) = q.pop() {
            if dist[idx] < cost {
                continue;
            }
            for &(nxt, c, _) in node[idx].iter() {
                let cst = c + cost;
                if dist[nxt] <= cst {
                    continue;
                }
                dist[nxt] = cst;
                q.push(Reverse((cst, nxt)));
            }
        }

        for j in (i + 1)..n {
            let mut q = VecDeque::new();
            q.push_back(j);
            while let Some(idx) = q.pop_front() {
                for &(nxt, cst, index) in node[idx].iter() {
                    if dist[idx] != dist[nxt] + cst {
                        continue;
                    }
                    q.push_back(nxt);
                    used[index] = true;
                }
            }
        }
    }

    let ans = used.into_iter().filter(|&n| !n).count();
    println!("{}", ans);
}

Measured memory_bytes: 2316
// Date: 2020-02-28

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 4000 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int dp[N][N], pos[N][2], val[N][2], B[N][N], W[N][N], n;

int main() {
    scanf("%d", &n);
    rep(i, 1, 2*n) {
        char op[2];
        scanf("%s%d", op, &val[i][0]);
        if(op[0] == 'B') pos[val[i][0]][0] = i, val[i][1] = 0;
        else pos[val[i][0]][1] = i, val[i][1] = 1;
    }
    rep(i, 2, 2*n) {
        rep(j, 1, n) B[i][j] = B[i-1][j], W[i][j] = W[i-1][j];
        if(!val[i-1][1]) B[i][val[i-1][0]]++;
        else W[i][val[i-1][0]]++;
    }
    rep(i, 2, 2*n) {
        for(int j = n-1; j >= 1; --j) {
            B[i][j] += B[i][j+1];
            W[i][j] += W[i][j+1];
        }
    }
    mem(dp, 0x3f);
    dp[0][0] = 0;
    rep(i, 0, n) rep(j, 0, n) {
        int p1 = pos[i+1][0], p2 = pos[j+1][1];
        chkmin(dp[i+1][j], dp[i][j] + B[p1][i+2] + W[p1][j+1]);
        chkmin(dp[i][j+1], dp[i][j] + B[p2][i+1] + W[p2][j+2]);
    }
    printf("%d\n", dp[n][n]);

    return 0;
}

Measured memory_bytes: 188288
num_of_bills, sum = gets.split.map &:to_i
bills = [10000, 5000, 1000]

for count_10k in 0 .. num_of_bills
  for count_5k in 0 .. num_of_bills - count_10k
    if count_10k * 10000 + count_5k * 5000 + (num_of_bills - count_5k - count_10k) * 1000 == sum
      puts [count_10k, count_5k, num_of_bills - count_5k - count_10k].join(" ")
      exit
    end
  end
end

puts "-1 -1 -1"


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int A[200000];
    int i, j;
    int N, K;

int main() {
  cin >> N >> K;
  rep0(i, N) cin >> A[i];
 
  int ng = 0, ok = 1e9 + 1;
  while (ok - ng > 1) {
    int m = (ok + ng) / 2;
    int cnt = 0;
    rep0(i, N) { cnt += (A[i] - 1) / m ; }
    if (cnt <= K)
      ok = m;
    else
      ng = m;
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int LCS(string s,string t,int x,int y)
{
    ll lcs[x+1][y+1],i,j;
    for(i=0;i<=x;i++)
    {
        for(j=0;j<=y;j++)
        {
            if(i==0||j==0)
            {
                lcs[i][j]=0;
            }
            else if(s[i-1]==t[j-1])
            {
                lcs[i][j]=1+lcs[i-1][j-1];
            }
            else{
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
            }
        }
    }
   int index= lcs[x][y];
  // cout<<index<<endl;
   char cnt[index];
   cnt[index]='\0';
   i=x;
   j=y;
  // index-=1;
   while(i>0&&j>0)
   {
       if(s[i-1]==t[j-1])
          {
              cnt[index-1]=s[i-1];
           i--;j--;   index--;
          }
          else if(lcs[i-1][j]>lcs[i][j-1])
            {
                i--;
            }
            else{
                j--;
            }
   }
   cout<<cnt;
}
int main()
{
    ll n,i,j,cnt=1,k,w,a,b;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	string s,t;
	cin>>s>>t;
	ll x,y;
	x=s.size();
	y=t.size();
	//cout<<x<<" "<<y<<endl;
	//ll lcs[x+1][y+1];
	LCS(s,t,x,y);
	    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int x=0;
    bool f=true;
    while(a>0 && c>0){
        //cerr << a << " " << c << endl;
        if(x%2!=0){
            a -= d;
        }else{
            c -= b;
        }
        if(a<=0){
            cout << "No" << endl;
            break;
        }
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }
        x++;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){

	int a,b;

	scanf("%d %d",&a,&b);
	if(a>b)
		printf("a > b\n");
	else if(a<b)
		printf("a < b\n");
	else if(a==b)
		printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
package main

import (
	"fmt"
	"math"
)

func distance(x, y []int, d int) float64 {
	distance := 0
	for i := 0; i < d; i++ {
		z := x[i] - y[i]
		distance += z * z
	}
	return math.Sqrt(float64(distance))
}

func main() {
	var n, d int
	fmt.Scan(&n, &d)

	coordinates := make([][]int, n)
	for i := 0; i < n; i++ {
		coordinates[i] = make([]int, d)
		for j := 0; j < d; j++ {
			fmt.Scan(&coordinates[i][j])
		}
	}

	count := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			d := distance(coordinates[i], coordinates[j], d)
			if fmt.Sprint(d) == fmt.Sprint(int(d)) {
				count++
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        String S = scan.next();
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < S.length(); i++) {
            sb.append("x");
        }

        os.println(sb.toString());
    }
}

Measured memory_bytes: 23380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	static class Graph {
		public void graph (InputReader ir) {
			
			// 頂点数入力
			int n = ir.nextInt();
			
			// グラフ
			int[][] data = new int[n][n];
			
			for (int i = 0; i < n; i++) {
				int u = ir.nextInt();
				int k = ir.nextInt();
				u--;
				for (int j = 0; j < k; j++) {
					int a = ir.nextInt();
					a--;
					data[u][a] = 1;
				}
			}
			
			StringBuilder sb = new StringBuilder ();
			
			for (int i = 0; i < n; i++) {
	            for (int j = 0; j < n; j++) {
	                if(j != 0) sb.append(" ");
	                sb.append(data[i][j]);
	            }
	            sb.append("\n");
	        }
			
			System.out.print(sb);
			
		}
	}

	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader (inputStream);
		Graph obj = new Graph ();
		obj.graph (in);
	}
}



Measured memory_bytes: 25772
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			
			int ans = 0;
			int[] h = new int[n+1];
			int[] w = new int[m+1];
			for(int i=1;i<=n;i++) h[i] = h[i-1] + sc.nextInt();
			int[] len = new int[h[n]+1];
			for(int i=1;i<=n;i++){
				for(int j=i-1;j>=0;j--) len[h[i]-h[j]]++;
			}
			int p;
			for(int i=1;i<=m;i++){
				w[i] = w[i-1] + sc.nextInt();
				for(int j=i-1;j>=0;j--){
					p = w[i]-w[j];
					if(p<=h[n] && len[p]>0) ans += len[p];
				}
			}
			System.out.println(ans);
		}	
	}	
}

Measured memory_bytes: 60768
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	A := sc.NextIntArray()

	sort.Ints(A)
	fmt.Println(A[2] - A[0])
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		//int array[] = new int [N];
		int tmp1 = sc.nextInt();
		int count = 0;
		int check1 = 0;
		int check2 = 0;
		int last = 0;
		int first = 0;
		int flag = 0;
		//int check1 = new int[3];
		//int check2 = new int[3];
		for(int i = 0; i < N-1; i++) {
			int tmp2 = sc.nextInt();
			if(tmp1 > tmp2 ) {
				count++;
				if(flag == 0) {
					check1 = tmp2;
					first = tmp1;
					flag++;
				}
				check2 = tmp1;
				last = tmp2;
				if(count>=3) {
					break;
				}
			}
			tmp1 = tmp2;
		}

		if(count==1 || count>=3) {
			System.out.println("NO");
		}else if(check1<=last && count!=0) {
			System.out.println("NO");
		}else if(check2>=first && count!=0) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}



	}

}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int ans = 0,len;
    string s, tmp1, tmp2;
    cin >> s;
    while (s.size() != 0){
        s.pop_back();
        len = s.size();
        if (len % 2 != 0) continue;
        tmp1 = s.substr(0, len / 2);
        tmp2 = s.substr(len / 2);
        if (tmp1 == tmp2) ans = max(ans, len);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int cnt = 0;
int m = 1;
int G[1000000] = {0};
void showA(int A[], int N) {
	int i;
	for (i = 0; i < N; ++i) {
		printf("%d ", A[i]);
	}
	printf("\n");
	return;
}


void inSertSort(int A[], int n, int g) {
	int i, j, v;
	
//	printf("g = %d\n", g);
	for (i = g ; i < n; ++i) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return;
}

void shellSort(int A[] , int n) {
	int i;
	//int G[1000000] = {0};
	//int m = 1;
	G[0] = 1;
	for (i = 0; (3 * G[i] + 1) < n  ; ++i) {
		G[i + 1] = 3 * G[i] + 1;
		++m;
	}
	//printf("m = %d\n", m);
	for (i = m - 1 ; i >= 0; --i) {
		inSertSort(A, n, G[i]);
	}
	
	return;
}


int main(void) {
	int n, i;
	int A[1000000] = {0};
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
//	showA(A, n);
	shellSort(A, n);
//	showA(A, n);
	printf("%d\n", m);
	for (i = m -1 ; i >= 0; --i) {
		if (i != 0) {
			printf("%d ", G[i]);
		} else {
			printf("%d\n", G[i]);
		}
	}
	printf("%d\n", cnt);
	for (i = 0; i < n; ++i) {
		printf("%d\n", A[i]);
	}
			
	return 0;
}

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

int main(void)
{
    string s;
    while(cin>>s)
    {
        int ans=0;
        int dp[3];
        dp[0]=s[0]=='R'?1:0;
        ans=max(ans,dp[0]);
        for(int i=1;i<3;++i)
        {
            if(s[i]=='R') dp[i]=dp[i-1]+1;
            else dp[i]=0;
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  map<char, ll> mp;
  rep(i, 4) {
    char c;
    cin >> c;
    mp[c]++;
  }
  bool ans = true;
  if(mp.size() != 2) false;
  for(auto v : mp) {
    if(v.second != 2) ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int n,A[20];
int solve(int count,int num)
{
	if(num==0)	
	return 1;
	if(count>n||num<0)
	return 0;
	if(solve(count+1,num-A[count])||solve(count+1,num))
	return 1;
	return 0;
}

int main(int argc, char *argv[])
{
	int q,m,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&m);
		if(solve(0,m))
		printf("yes\n");
		else
		printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2076
m,d = map(int,input().split())

ans = 0

for j in range(1,m+1):
        for i in range(1,d+1):
                if i >= 10:
                        k = str(i)
                        a = int(k[0])
                        b = int(k[1])
                        if a >= 2 and b >= 2 and a*b == j:
                                ans += 1

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {

    int n;
    cin>>n;
    set<int> s;
    int sum=0;
    for(int i=1;i<5*1e3;i++){
        sum+=i;
        s.insert(i);
        if(sum==n)break;
        else if(sum>n){
            s.erase(sum-n);
            break;
        }
    }
    irep(i,s)fin(*i);
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] S = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.ReadLine();
            int[] T = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int cnt = 0;

            foreach (var t in T)
            {
                foreach (var s in S)
                {
                    if (s == t)
                    {
                        cnt++;
                        break;
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

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

typedef long long ll;
typedef pair<string,int> P;

ll A, B, MOD;
ll n;
ll bit[1000000];

ll sum(int i){
  ll res = 0;
  while(i > 0){
    res += bit[i];
    res %= MOD;
    i -= i & -i;
  }
  return res;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    bit[i] %= MOD;
    i += i & -i;
  }
}

string itos(ll x){
  stringstream ss;
  ss << x;
  return ss.str();
}

int main(){
  while(cin >> A >> B >> MOD, A || B || MOD){
    vector<P> v;
    for(ll i = A; i <= B; i++){
      v.push_back(P(itos(i), i - A + 1));
    }
    sort(v.begin(), v.end());

    n = B - A + 1;
    memset(bit, 0, sizeof(bit));

    for(int i = 0; i < v.size(); i++){
      ll tmp = sum(v[i].second);
      add(v[i].second, tmp + 1);
    }

    cout << sum(n) << endl;
  }
}

Measured memory_bytes: 15244
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n, m = nm()
lis = [[] for _ in range(m)]
k = [0 for _ in range(m)]
for i in range(m):
    tmp = nl()
    k[i] = tmp[0]
    lis[i] = tmp[1:]
p = nl()
ans = 0
for i in range(2 ** n):
    bit = bin(i)[2:].zfill(n)
    ccnt = 0
    for j in range(m):
        cnt = 0
        for ll in lis[j]:
            if bit[ll - 1] == '1':
                cnt += 1
        if cnt % 2 == p[j]:
            ccnt += 1
    if ccnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T, typename ...Ts>
vector<T> fusion(vector<T> bs,Ts... ts){
  auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);};
  initializer_list<int>{(void(append(ts)),0)...};
  return bs;
}


// longest common prefix of s and s[i:n]
vector<int> zalgorithm(vector<int> s){
  int n=s.size();
  vector<int> as(n,0);
  as[0]=n;
  int i=1,j=0;
  while(i<n){
    while(i+j<n&&s[j]==s[i+j]) j++;
    as[i]=j;
    if(j==0){
      i++;
      continue;
    }
    int k=1;
    while(i+k<n&&k+as[k]<j) as[i+k]=as[k],k++;
    i+=k;
    j-=k;
  }
  return as;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n),bs(n);
  for(int i=0;i<n;i++) cin>>as[i];
  for(int i=0;i<n;i++) cin>>bs[i];

  vector<int> cs(n),ds(n);
  for(int i=0;i<n;i++){
    cs[i]=as[i]^as[(i+1)%n];
    ds[i]=bs[i]^bs[(i+1)%n];
  }

  vector<int> ss=fusion(ds,cs,cs);
  auto zs=zalgorithm(ss);
  for(int i=0;i<n;i++)
    if(zs[n+i]>=n) cout<<i<<" "<<(as[i]^bs[0])<<endl;

  return 0;
}


Measured memory_bytes: 12156
import math

divider = 1000000007

n, m = map(int, input().split())
diff = abs(n - m)

if diff == 0:
    print(2 * math.factorial(n) * math.factorial(m) % divider)
elif diff == 1:
    print(math.factorial(n) * math.factorial(m) % divider)
else:
    print(0)

Measured memory_bytes: 5176
from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque([1])
    while len(dq) > 0:
        v = dq.popleft()
        for c in G[v]:
            if d[c] < 0:
                d[c] = d[v] + 1
                dq.append(c)
    for i, x in enumerate(d[1:], start=1):
        print(i, x)
G = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
bfs()

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

typedef long long ll;

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

int main() {
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    for (int i=K;i<=N+1;i++){
        ans += (1LL*i*(N-i+1) + 1) % MOD;
        ans %= MOD;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h> 
 int n,y,m,d,i,total;
 void year(void){
   if(y%3==0){
      total+=(999-y)/3*590;
   }else if(y%3==1){
      total+=(997-y)/3*590+395;
   }else if(y%3 ==2){
     total+=(998-y)/3*590+200;
   }
}
void month(void){
   if(y%3!=0){
    if(m%2==0){
     total+=(10-m)/2*39;
    }else{
     total+=(9-m)/2*39+19;
    }
   }else{
     total+=(10-m)*20;
   }
}
void day(void){
  if(y%3!=0){
    if(m%2==0){
       total+=20-d;
      }else{
          total+=21-d;
     }
   }else{
       total+=21-d;
   }
}
int main(void){

  scanf("%d",&n);
    for(i=0;i<n;i++){
         total=0;
         scanf("%d %d %d",&y,&m,&d);
         year();
         month(); 
         day();
         printf("%d\n",total);
     }
   return 0;
}

    

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 2500
#define INF 1152921504606846976

struct Edge {
    i64 from, to, cost;
    Edge () {}
    Edge (i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};

vector<i64> stog[MAX_N];
vector<i64> gtos[MAX_N];
vector<bool> reachable(MAX_N, false);
vector<bool> reachable_rev(MAX_N, false);

void dfs(i64 u) {
    for (i64 v : stog[u]) {
        if (reachable[v]) continue;
        reachable[v] = true;
        dfs(v);
    }
}
void rdfs(i64 u) {
    for (i64 v : gtos[u]) {
        if (reachable_rev[v]) continue;
        reachable_rev[v] = true;
        rdfs(v);
    }
}

int main() {
    i64 N, M, F; cin >> N >> M >> F;
    vector<Edge> es;

    REP(i, M) {
        i64 u, v, c; cin >> u >> v >> c;
        u--, v--;
        es.emplace_back(u, v, F - c);
        stog[u].pb(v);
        gtos[v].pb(u);
    }

    reachable[0] = true;
    reachable_rev[N - 1] = true;
    dfs(0);
    rdfs(N - 1);

    vector<i64> d(N, INF);
    d[0] = 0;
    bool update = true;
    i64 step = 0;
    while (update) {
        update = false;
        for (Edge &e : es) {
            i64 nd = d[e.from] + e.cost;
            if (!(reachable[e.to] && reachable_rev[e.to])) continue;
            if (!(reachable[e.from] && reachable_rev[e.from])) continue;
            if (chmin(d[e.to], nd)) update = true;
        }
        step++;
        if (step > N) {
            cout << -1 << endl;
            return 0;
        }
    }
    i64 ans = max(0L, -1 * d[N - 1]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n, W;    cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(n+1, vector<ll>(n*1000+1, LINF));
    dp[0][0] = 0;
    rep(i, n){
        for(ll j=0; j<=n*1000; j++){
            dp[i+1][j] = dp[i][j];
            if(v[i]<=j) dp[i+1][j] = min(dp[i][j-v[i]]+w[i], dp[i+1][j]);
        }
    }
    ll res=0;
    rep(i, n*1000+1) if(dp[n][i]<=W){
        res = i;
        //cout << i << ' ' << dp[n][i] << endl;
    }
    cout << res << endl;

}


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

using namespace std;

int main() {

  string a;

  int cou;

  cin >> a ;

  if(a[0]=='1'){

   cou++;
  }
if(a[1]=='1'){
  

    cou++;
  
    }

  if(a[2]=='1'){

    cou++;


    }

  
cout<<cou<<endl;
  

  
 

}


Measured memory_bytes: 3552
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int ans=0;
    long int N;

    cin >> N;

    cout << (N-1) * N / 2 << endl;

    return 0;
}


Measured memory_bytes: 256