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

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    int64_t m[2][3];
    for(int i = 0; i < 3; i++) {
        m[1][i] = 0;
    }
    for(int day = 0; day < N; day++) {
        for(int i = 0; i < 3; i++) {
            m[0][i] = m[1][i];
            m[1][i] = 0;
        }
        for(int i = 0; i < 3; i++) { // 今日やる活動
            int x;
            cin >> x;
            for(int j = 0; j < 3; j++) { // 昨日やった活動
                if(i == j) continue;
                m[1][i] = max(m[1][i], m[0][j] + x);
            }
        }
    }
    int64_t ans = 0;
    for(int i = 0; i < 3; i++) {
        ans = max(ans, m[1][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define REP1(i,n) for(int i=1;i<=(n);++i)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

int pref[100000];
int year[100000];
vector<int> sorted[100001];

void print(int v) {
}

int main() {
  int N, M;
  cin >> N >> M;
  REP(i, M) {
    int P, Y;
    cin >> P >> Y;
    pref[i] = P;
    year[i] = Y;
    sorted[P].push_back(Y);
  }
  REP1(i, N) {
    sort(sorted[i].begin(), sorted[i].end());
  }
  REP(i, M) {
    auto& v = sorted[pref[i]];
    int n = (lower_bound(v.begin(), v.end(), year[i]) - v.begin()) + 1;
    printf("%06d%06d\n", pref[i], n);
  }
}


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

vector<int> union_find_parent;
int union_find_init(int n);
int union_find_unite(int a,int b);
int union_find_root(int a);

vector<int> union_find2_parent;
int union_find2_init(int n);
int union_find2_unite(int a,int b);
int union_find2_root(int a);

int main()
{
	int n,k,l;
	cin >> n >> k >> l;

	union_find_init(n+1);
	union_find2_init(n+1);

	for (int i=0;i<k;++i)
	{
		int p,q;
		cin >> p >> q;
		union_find_unite(p,q);
	}
	for (int i=0;i<l;++i)
	{
		int r,s;
		cin >> r >> s;
		union_find2_unite(r,s);
	}

	map<pair<int,int>,int> mm;
	for (int i=1;i<=n;++i)
	{
		mm[make_pair(union_find_root(i),union_find2_root(i))]++;
	}

	for (int i=1;i<=n;++i)
	{
		if (i>1)
		{
			cout << " ";
		}
		cout << mm[make_pair(union_find_root(i),union_find2_root(i))];
	}
	cout << endl;
}



int union_find_init(int n)
{
	for (int i=0;i<n;++i)
	{
		union_find_parent.push_back(i);
	}
	return 0;
}

int union_find_unite(int a,int b)
{
	a=union_find_root(a);
	b=union_find_root(b);
	if (a!=b)
	{
		union_find_parent[a]=b;
	}
	return 0;
}

int union_find_root(int a)
{
	if (union_find_parent[a]==a)
	{
		return a;
	}
	else
	{
		return union_find_parent[a]=union_find_root(union_find_parent[a]);
	}
}

int union_find2_init(int n)
{
	for (int i=0;i<n;++i)
	{
		union_find2_parent.push_back(i);
	}
	return 0;
}

int union_find2_unite(int a,int b)
{
	a=union_find2_root(a);
	b=union_find2_root(b);
	if (a!=b)
	{
		union_find2_parent[a]=b;
	}
	return 0;
}

int union_find2_root(int a)
{
	if (union_find2_parent[a]==a)
	{
		return a;
	}
	else
	{
		return union_find2_parent[a]=union_find2_root(union_find2_parent[a]);
	}
}







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


int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    s[i] = (s[i]-'A'+n)%26+'A';
    cout << s[i];
  }  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,K,D;
    cin >> X >> K >> D;
    if(X<0) X *= -1;
    ll n = X/D;
    if(n>K){
        cout << X-K*D << "\n";
        return 0;
    }
    K -= n;
    ll res = X-n*D;
    cout << (K%2? abs(res-D):res) << "\n";
}

Measured memory_bytes: 3648
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n;
    scanf("%lld",&n);
        ll k = n / 10;
        ll ans = 0;
        ll digit = 10;
        while(digit <= n){
            ans += (ll) n / digit;
            digit *= 5;
        }
        printf("%lld", (n % 2 == 0 ? ans : 0));
    
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned int  ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 998244353
using namespace std;

ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
	        res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
} 

signed main(){
	FASTIO
	int n, q;
	cin >> n >> q;
	vector<int> a(n+1, 0), b(n+1, 0);
	int tot = (n - 2) * (n - 2);
	int h = n, w = n;
	while(q--){
		int t, x;
		cin >> t >> x;
		if(t == 1){
			if(x < w){
				rep(i, x, w){
					b[i] = h;
				}
				w = x;
			}
			tot -= b[x] - 2;
		}
		else{
			if(x < h){
				rep(i, x, h){
					a[i] = w;
				}
				h = x;
			}
			tot -= a[x] - 2;
		}
	}
	cout << tot;
    return 0;
}


Measured memory_bytes: 6348
/*input
6
1 2 3 2 2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int a[maxn];
int head=-1,tail=-1;
int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	int ans=0;
	REP(i,n){
		if(head==-1){
			head=tail=a[i];
			ans++;
		}
		else if(tail>head&&a[i]<tail){
			head=tail=a[i];
			ans++;
		}
		else if(head>tail&&a[i]>tail){
			head=tail=a[i];
			ans++;
		}
		else{
			tail=a[i];
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const long double pi=3.1415926535897932384626433832795028841971;
const int maxn=200010;
int cnt,n,a[maxn],st[maxn],top,len;
long double ans;
struct node
{
	int x,y;
}s,t,p[maxn];
bool cmp(node a,node b)
{	
	return a.x<b.x;
}
int main()
{
	scanf("%d%d%d%d%d",&s.x,&s.y,&t.x,&t.y,&n);
	if(s.x>t.x) swap(s,t); 
	for(int i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+n+1,cmp);
	cnt=0;
	for(int i=1;i<=n;i++)
		if((p[i].x>=s.x&&p[i].x<=t.x)&&((p[i].y>=s.y&&p[i].y<=t.y)||(p[i].y>=t.y&&p[i].y<=s.y))) a[++cnt]=p[i].y;
	if(s.y>t.y)
		for(int i=1;i<=cnt;i++)
			a[i]=-a[i];
	top=len=0;
	memset(st,0x3f,sizeof(st));
	for(int i=1;i<=cnt;i++)
	{
		int k=lower_bound(st+1,st+cnt+1,a[i])-st;
		st[k]=a[i];
		len=max(len,k);
	}
	/*for(int i=1;i<=cnt;i++)
		cout<<a[i]<<' ';
	cout<<endl;
	cout<<len<<endl;	*/
	ans=abs(s.x-t.x)+abs(s.y-t.y);
	ans*=100.0;
	ans+=(pi*5.0-20.0)*len;
	if(len==abs(t.y-s.y)+1||len==abs(t.x-s.x)+1) ans+=pi*5.0;
	printf("%.15Lf",ans);
	return 0;
} 
/*
2 5 2 3
3
3 2
5 3
2 4
2 3 3 6
3
1 1
2 4
3 5
*/

Measured memory_bytes: 3328
n, k = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j > n or i + j > k:
            continue
        a = v[:i] + v[n - j:]
        a.sort()

        l = 0
        while True:
            if l == i + j or a[l] >= 0 or i+j+l == k:
                break
            l += 1
        b = a[l:]
        ans = max(ans, sum(b))
print(ans)


Measured memory_bytes: 41196
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int N;
    scanf("%d",&N);
    int L[N];
    long ans;

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

    sort(L,L+N);

    ans=0;
    for(int i=2; i<N; i++){
        for(int j=0; j<i-1; j++){
            int *kp;
            int k;
            kp=upper_bound( &L[j+1], &L[i], L[i]-L[j] );
            k = kp-L;
            ans+= i-k;
            //printf("i,j,k ans = %d,%d,%d, %ld\n",i,j,k,ans);
        }
    }

    printf("%ld\n", ans);

    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> mp(n+1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        mp.at(a).push_back(b);
        mp.at(b).push_back(a);
    }
    vector<int> lp(n+1);
    lp.at(1) = 1;
    queue<int> q;
    
    q.push(1);
    while(q.size()) {
        int x = q.front(); q.pop();
        for(int y : mp.at(x)){
            if(lp.at(y) == 0){
                lp.at(y) = x;
                q.push(y);
            }
        }
    }

    cout << "Yes" << endl;
    for(int i=2;i<=n;i++){
        cout << lp.at(i) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10216
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> Point;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

namespace std{
    bool operator<(const Point &a, const Point &b){
        return !equals(a.X, b.X) ? a.X < b.X : a.Y < b.Y;
    }

    bool cmp_y(const Point &a, const Point &b) {
        return !equals(a.Y, b.Y) ? a.Y < b.Y : a.X < b.X;
    }
}

double closestPair(vector<Point> &points, int l, int r){
    if(r - l <= 1) return 1e9;
    int mid = (l + r) / 2;
    double x = points[mid].X;
    double d = min(closestPair(points, l, mid), closestPair(points, mid, r));
    auto iti = points.begin();
    auto itl = iti + l;
    auto itm = iti + mid;
    auto itr = iti + r;

    inplace_merge(itl, itm, itr, cmp_y);

    vector<Point> nearLine;
    for(int i=l; i<r; i++){
        if(abs(points[i].X - x) >= d) continue;

        int sz = nearLine.size();
        for(int j=sz-1; j>=0; j--){
            double dx = points[i].X - nearLine[j].X;
            double dy = points[i].Y - nearLine[j].Y;
            if(dy >= d) break;
            d = min(d, sqrt(dx * dx + dy * dy));
        }

        nearLine.emplace_back(points[i]);
    }
    
    return d;
}

int main(){
    int n; cin>>n;
    vector<Point> points;
    for(int i=0; i<n; i++){
        double x, y; cin>>x>>y;
        points.emplace_back(x, y);
    }

    sort(points.begin(), points.end());

    printf("%.10f\n", closestPair(points, 0, n));
}


Measured memory_bytes: 7776
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define LL long long
int bit[114514];
int sum(int i){
	int s=0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

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

void reset(){
	memset(bit,0,sizeof(bit));
}


LL kai[114514];
void kai_set(){
	kai[0]=0;
	kai[1]=1;
	for(int i=2;i<114514;i++){
		kai[i]=kai[i-1]*i%1000000007;
	}
}

int main(){
	kai_set();
	int n;
	while(cin>>n,n){
		reset();
		int d[114514];
		for(int i=0;i<n;i++){
			d[i]=i+1;
		}
		int r;
		cin>>r;
		for(int i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			swap(d[a-1],d[b-1]);
		}
		LL ans=0;
		for(int i=0;i<n;i++){
			int t=d[i];
			add(t,1);
			if(t>1)t=sum(t-1);
			else t=0;
			ans+=kai[n-1-i]*(d[i]-1-t)%1000000007;
			ans%=1000000007;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 2900
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	vector<vector<int>> data(2, vector<int>(n));
	rep(i, 2) {
		rep(j, n) cin >> data[i][j];
	}
	int ans = 0;
	rep(i, n) { //data[0][i]で下に移動する
		int now = 0;
		rep(j, i + 1) { //data[0]行を移動
			now += data[0][j];
		}
		rep(j, n - i) { //data[1]行を移動
			now += data[1][j + i];
		}
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
// テーブルを作る前処理
const ll MAX = 300000;
const ll mod=1000000007;
ll 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;
    }
}
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  COMinit();
  ll n,k,ans=0;
  cin >> n >> k;
  r1(i, min(n,k+1)) {
    ll a=COM(n,i)%mod;
    a=a*(COM(n-1,i)%mod)%mod;
    ans=(ans+a)%mod;
  }
  cout << ans << endl;
}


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

int main()
{
	const int INF = 2147483647;
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	vector<int> veca(N);
	vector<int> vecb(N);
	vector<int> vecc(N);
	for (int i = 0; i < N; i++)
		cin >> veca[i] >> vecb[i] >> vecc[i];

	int ZaiMax = N * 10;
	vector<int> vecCB(ZaiMax +1, INF);
	vector<vector<int>> vecCAB(ZaiMax +1, vecCB);
	vector<vector<vector<int>>> dp(N+1, vecCAB);
	
	dp[0][0][0] = 0;

	for (int i = 0; i < N; i++) {
		for (int ca = 0; ca <= ZaiMax; ca++) {
			for (int cb = 0; cb <= ZaiMax; cb++) {
				if (dp[i][ca][cb] == INF)
					continue;
				dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
				dp[i + 1][ca + veca[i]][cb + vecb[i]] = min(dp[i + 1][ca + veca[i]][cb + vecb[i]], dp[i][ca][cb] + vecc[i]);
			}
		}
	}

	int res = INF;
	for (int ca = 1; ca <= ZaiMax; ca++) {
		for (int cb = 1; cb <= ZaiMax; cb++) {
			if (ca * Mb == cb * Ma)
				res = min(res, dp[N][ca][cb]);
		}
	}
	if (res == INF)
		res = -1;

	cout << res << endl;

	return 0;
}



Measured memory_bytes: 27264
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cmp::*;
use std::collections::*;

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let n: usize = readln();
    let mut xs: Vec<usize> = readln();
    xs.sort();

    if xs[0] == xs[n - 1] && xs[0] <= n / 2 {
        println!("Yes");
        return;
    }

    if xs[0] == xs[n - 1] && xs[0] == n - 1 {
        println!("Yes");
        return;
    }

    if xs[0] + 1 == xs[n - 2] && xs[n - 2] == xs[n - 1] {
        let mut freq = 0;
        for i in 0..n {
            if xs[i] == xs[0] {
                freq += 1;
            } else {
                break;
            }
        }
        if n - freq >= 2 * (xs[n - 1] - freq) && xs[n - 1] > freq {
            println!("Yes");
            return;
        }
    }

    println!("No");
}


fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_string()
}

fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

trait Read {
    fn read(s: &str) -> Self;
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	string s,t;
	string s2[51]={};
	cin>>s;
	cin>>t;

	int t2=0;
	if(s.size()>=t.size()){
		rep(i,s.size()-t.size()+1){
			int f=0;
			rep(k,i){
				if(s[k]=='?')s2[t2]+='a';
				else s2[t2]+=s[k];
			}
			rep(j,t.size()){
				if(s[i+j]!='?'&&s[i+j]!=t[j])f=1;
				else s2[t2]+=t[j];
			}
			for(int l=i+t.size(); l<s.size(); l++){
				if(s[l]=='?')s2[t2]+='a';
				else s2[t2]+=s[l];
			}
			if(f==1){
				f=0;
				s2[t2]={};
			}else t2++;
		}
	}
	if(t2==0){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	sort(s2, s2 + t2, greater<string>());
	cout<<s2[t2-1]<<endl;

	return 0;

}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		String s = in.next();
		System.out.println(solve(a - 1, b - 1, c - 1, d - 1, s));
		in.close();
	}

	private static String solve(int a, int b, int c, int d, String s) {
		if (c >= b)
			if (!canMove(a, Math.max(c, d), s))
				return "No";
			else {
				if (!canMove(a, c, s))
					return "No";
				if (!canMove(b, d, s))
					return "No";
			}
		if (c > d)
			if (!canPass(b - 1, d - 1, s))
				return "No";
		return "Yes";
	}

	private static boolean canPass(int a, int b, String s) {
		for (int i = a; i <= b; i++)
			if (s.charAt(i) == '.' && s.charAt(i + 1) == '.' && s.charAt(i + 2) == '.')
				return true;
		return false;
	}

	private static boolean canMove(int a, int b, String s) {
		for (int i = a; i < b; i++)
			if (s.charAt(i) == '#' && s.charAt(i + 1) == '#')
				return false;
		return true;
	}

}

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

// binary search 二分探索
int main() {
  int n, q;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  cin >> q;
  vector<int> t(q);
  rep(i, q) cin >> t[i];

  int ans = 0;
  rep(i, q) {
    int st = 0;
    int en = n - 1;

    while (en >= st) {
      int mid = (en + st) / 2;
      if (s[mid] == t[i]) {
        ans++;
        break;
      }
      if (s[mid] > t[i])
        en = mid - 1;
      else
        st = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define EPS 1e-8

int main() {
    int N; cin >> N;
    while (N--) {
        double xa, ya, ra, xb, yb, rb;
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        double d = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
        if (ra + rb < d) {
            cout << 0 << endl;
            continue;
        } 
        if (ra > rb) {
            if (ra - rb > d) {
                cout << 2 << endl;
                continue;
            } else {
                cout << 1 << endl;
                continue;
            }
        } else {
            if (rb - ra > d) {
                cout << -2 << endl;
                continue;
            } else {
                cout << 1 << endl;
                continue;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
static const int inf = 1ll<<60;
typedef pair<int,int> pii;

int N;
int A[100010];
int ans;
signed main(){
    cin>>N;
    for(int i=0;i<N;++i)cin>>A[i];
    for(int i=0;i<N;++i){
        int temp=0;
        temp=A[i]/2;
        if(A[i]%2==1&&A[i+1]!=0){
           temp++;
           A[i+1]--;
        }
        /*if(temp<min(A[i],A[i+1])){
            temp=min(A[i],A[i+1]);
            A[i+1]-=temp;
        }*/
        ans+=temp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	int S;
	int h;
	int m;
	int s;
	scanf("%d", &S);
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;

class Main{
    static int dp(int[] arr){
        int n = arr.length;
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(arr[0]-arr[1]);
        for(int i=2;i<n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]),dp[i-2]+Math.abs(arr[i]-arr[i-2]));

        }
        return dp[n-1];
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = scan.nextInt();
        }
        scan.close();
        System.out.println(dp(arr));
        
    }
}

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

int main()
{
  	int i,n;
  cin>>n;
  vector<int> a(n),b(n+1,0);
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    b[a[i]]++;
  }
  for(i=1;i<=n;i++)
    cout<<b[i]<<'\n';
  return 0;
}

Measured memory_bytes: 4844
import math
import sys

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

N = int(input())
ans = factorization(N)
x = len(ans)
time = 0
count = 2
s = 1

if ans[0][0] == 1 :
    print(0)
    sys.exit()

for i in range(x) :
    while ans[i][1] >= s :
        time += 1
        s += count
        count += 1
    s = 1
    count = 2

print(time)





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

signed main(){
  int a, v, b, w, t; cin >> a >> v >> b >> w >> t;
  int dis = abs(b - a), spd = v - w;
  if(spd <= 0) puts("NO");
  else if((dis - 1) / spd + 1 <= t) puts("YES");
  else puts("NO");
}

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

int main() {
	int r, g, b;
	std::cin>> r >> g >> b;
	int a = g*10+b;
	if(a % 4) {
		std::cout << "NO" << std::endl;
	}else{
		std::cout << "YES" << std::endl;
	}

	return 0;
}


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

int main() {
	int q, a, b;
	string str, operation, p;
	cin >> str;
	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> operation;
		if (operation == "print") {
			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (operation == "replace") {
			cin >> a >> b >> p;
			str.replace(a, b - a + 1, p);
		}
		else if (operation == "reverse") {
			cin >> a >> b;

			string tmp = str.substr(a, b - a + 1);
			int n = tmp.size();

				for (int i = 0; i < n; i++) {
					str[a + i] = tmp[n - 1 - i];
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
P dp[105][50005];
int p[100],n;
void Max(P &a,P b){a=max(a,b);}
int main(){
  while(cin>>n&&n){
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)cin>>p[i];
    dp[0][0] = P(0,0);
    for(int i=0;i<n;i++){
      for(int j=0;j<500*n;j++){
        if(dp[i][j]==P(-1,-1)) continue;
        int nf=dp[i][j].first,ns=dp[i][j].second-p[i];
        Max(dp[i+1][j],dp[i][j]);
        if(p[i]%1000==0) {if(j>=500)Max(dp[i+1][j-500],P(nf+1,ns));}
        else if(p[i]%1000<500) Max(dp[i+1][j+500-p[i]%500],P(nf+1,ns));
        else if(p[i]%500<=j) Max(dp[i+1][j-p[i]%500],P(nf+1,ns));
        else Max(dp[i+1][j+500-p[i]%500],P(nf,ns)); 
      }
    }
    P ans(0,0);
    for(int i=0;i<500*n;i++) Max(ans,dp[n][i]);
    cout<<ans.first<<" "<<-ans.second<<endl;
  }  
  return 0;
}

Measured memory_bytes: 44032
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var n = int.Parse(str[0]);
            var a = int.Parse(str[1]);
            var b = int.Parse(str[2]);

            List<int> list = new List<int>();
            list.Add(a);
            list.Add(b);

            Console.Write(list.Min()+" ");

            var x = a + b;
            if(x<n)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(Math.Abs(n-x));
            }
            

        }
    }
}


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

#define INF 1000000005


using namespace std;

int n, k;
int tab[1000000][3];
int dp[1000000][3];
int main(){
    
    cin >> n;
    
    
	for(int i = 0; i < n; i++){
		cin >> tab[i][0] >> tab[i][1] >> tab[i][2];
	}
    
    
	for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = max(dp[i - 1][(j + 1) % 3] + tab[i][(j + 1) % 3], dp[i - 1][(j + 2) % 3] + tab[i][(j + 2) % 3]);
        }
        
    }
    /*
    for(int i = 0; i < n; i++){
        cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << "\n";
    }*/
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

}


Measured memory_bytes: 5504
package main

import "fmt"

func main() {
	// Code for B - Template Matching
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	A := make([]string, N)
	B := make([]string, M)

	for i := 0; i < N; i++ {
		fmt.Scanf("%s", &A[i])
	}

	for i := 0; i < M; i++ {
		fmt.Scanf("%s", &B[i])
	}

	var flag1, flag2 int
	for i := 0; i < (N - M + 1); i++ {
		for j := 0; j < (N - M + 1); j++ {
			flag1 = 0
			for k := 0; k < M; k++ {

				if A[i+k][j:j+M] != B[k][0:M] {
					flag1 = 1
				}
			}
			if flag1 == 0 {
				flag2 = 1
				break
			}
		}
	}

	if flag2 == 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


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

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

  if (a < b) swap(a, b);
  vector<int> vec;
  for (int i = 1; i < b+1; i++) {
    if (a%i==0 && b%i==0) vec.push_back(i);
  }
  cout << vec[vec.size()-k] << endl;
  return 0;
}

Measured memory_bytes: 256
import copy

A = input().split()
B = int(A[1])
C = int(A[2])
A = int(A[0])
K = int(input())

def dfs(L, k, ans):
    if k >= K:
        ans[0] = max(ans[0], sum(L))
        return
    for i in range(3):
        L_ = copy.deepcopy(L)
        L_[i] *= 2
        dfs(L_, k + 1, ans)

ans = [0]
dfs([A, B, C], 0, ans)
print(ans[0])


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    string s;
    cin >> s;
    if(s[1] == 'B')
    {
        cout << "ARC\n";
    }
    else
    {
        cout << "ABC\n";
    }
    
    return 0;
}

Measured memory_bytes: 3572
data class Bingo(val value: Int, var isOn: Boolean)
fun main (args:Array<String>){
    var bingoList: MutableList<Bingo> = arrayListOf()

    bingoList.addAll(readLine()!!.split(" ").map { Bingo(it.toInt(), false) })
    bingoList.addAll(readLine()!!.split(" ").map { Bingo(it.toInt(), false) })
    bingoList.addAll(readLine()!!.split(" ").map { Bingo(it.toInt(), false) })

    val N = readLine()!!.toInt()
    for (i in 1..N) {
        val A = readLine()!!.toInt()
        bingoList.filter { it.value == A }.forEach { it.isOn = true }
    }

    // 横
    for (i in 1..3) {
        val startNo = (i - 1) * 3
        if (bingoList[startNo].isOn && bingoList[startNo + 1].isOn && bingoList[startNo + 2].isOn) {
            print("Yes")
            return;
        }
    }
    // 縦
    for (i in 1..3) {
        val startNo = i - 1
        if (bingoList[startNo].isOn && bingoList[startNo + 3].isOn && bingoList[startNo + 6].isOn) {
            print("Yes")
            return;
        }
    }
    if (bingoList[0].isOn && bingoList[4].isOn && bingoList[8].isOn) {
        print("Yes")
        return;
    }
    if (bingoList[2].isOn && bingoList[4].isOn && bingoList[6].isOn) {
        print("Yes")
        return;
    }
    print("No")
}


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

int main() {
    int n;
    cin >> n;
    int k = -1;
    for (int i = 2; ; ++i) {
        if (i * (long long)(i - 1) / 2 == n) {
            k = i;
            break;
        }
        else if (i * (long long)(i - 1) / 2 > n) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    cout << k << "\n";
    vector<vector<int>> edges(k, vector<int>(k));
    int c = 0;
    for (int i = 0; i < k; ++i) {
        for (int j = i + 1; j < k; ++j) {
            ++c;
            edges[i][j] = c;
            edges[j][i] = c;
        }
    }
    for (int i = 0; i < k; ++i) {
        cout << k - 1;
        for (int j = 0; j < k; ++j) {
            if (i == j) continue;
            cout << " " << edges[i][j];
        }
        cout << "\n";
    }
    return 0;
}


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

using namespace std;

const int CMax = 100002;

int a, b, c;

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

    if (a == b) cout << c << endl;
    if (a == c) cout << b << endl;
    if (c == b) cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int s;
    cin >> s;
    set<int> st;
    int a = s;
    while (st.count(a) == 0) {
        st.insert(a);
        if (a % 2 == 0)
            a /= 2;
        else
            a = 3 * a + 1;
    }
    std::cout << st.size() + 1 << '\n';

    return 0;
}

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

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

    string o, e;
    cin >> o >> e;

    for (int i=0; i<o.size(); i++) {
        cout << o[i];
        if (i < e.size()) cout << e[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int x,y;
    x=s.length();
    y=t.length();
    if(x+1==y){
        if(s.compare(0,x,t,0,x)==0){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    else{
        cout<<"No";
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

ll n, m, x;
vll c;
vvll a;

ll ans = INF;

void dfs(int index, ll price, vll mature) {
  if (price > ans) {
    return;
  }
  if (index >= n) {
    rep(i, m) {
      if (mature[i] < x) {
        return;
      }
    }
    chmin(ans, price);
    return;
  }

  dfs(index + 1, price, mature);

  price += c[index];
  rep(i, m) {
    mature[i] += a[index][i];
  }
  dfs(index + 1, price, mature);
}

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

  cin >> n >> m >> x;

  c.resize(n);
  a = vvll(n, vll(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) {
      cin >> a[i][j];
    }
  }
  vll mature(m);
  dfs(0, 0, mature);

  if (ans == INF) {
    ans = -1;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;
constexpr ll MOD = 1e9 + 7;


int main() {
    string S;
    cin >> S;

    cout << static_cast<char>(S[0] + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int mod=pow(10,9)+7;
int dp[22][(1<<22)+9];
vector<vector<int>>adj;
int solve(int n,int idx,int mask){
  if(mask==(1<<n)-1)
    return 1;
  if(idx==n)return 0;
  if(dp[idx][mask]!=-1)return dp[idx][mask];
  int new_mask;
  int ans=0;
  for(int i=0;i<(int)adj[idx].size();i++){
    int j=adj[idx][i];
    if(mask &(1<<j))continue;
    new_mask=mask;
    new_mask |=(1<<j);
    ans+=solve(n,idx+1,new_mask);
    ans%=mod;
  }
  dp[idx][mask]=ans;
  return dp[idx][mask];
}
int main(){
  int n;
  cin>>n;
  int arr[n][n];
  adj.resize(n+1);
  //i-->man j-->woman
  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
      cin>>arr[i][j];
      if(arr[i][j]==1)adj[i].push_back(j);
    }
  }
  memset(dp,-1,sizeof(dp));
  int idx=0;
  int mask=0;
  int ans=solve(n,idx,mask);
  cout<<ans<<endl;
}

Measured memory_bytes: 364052
# include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+3;
int cnt=0, id=0, Next[maxn],in[maxn],out[maxn];
int fa[maxn][20], len[maxn];
struct node
{
    int v, next;
}edge[maxn<<1];
void add_edge(int u, int v)
{
    edge[cnt] = {v, Next[u]};
    Next[u] = cnt++;
    edge[cnt] = {u, Next[v]};
    Next[v] = cnt++;
}
 
void dfs(int cur, int pre, int d)
{
    fa[cur][0] = pre;
    len[cur] = d;
    for(int i=1; i<20; ++i)
        fa[cur][i] = fa[fa[cur][i-1]][i-1];
    in[cur] = ++id;
    for(int i=Next[cur]; i!=-1; i=edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        dfs(v, cur, d+1);
    }
    out[cur] = id;
}
int main()
{
    int n, a, b;
    scanf("%d",&n);
    memset(Next, -1, sizeof(Next));
    for(int i=1; i<n; ++i)
    {
        scanf("%d%d",&a,&b);
        add_edge(a, b);
    }
    dfs(1, 0, 0);
    int tmp=(len[n]-1)/2, now=n;
    for(int i=0; i<20; ++i)
        if(tmp>>i&1) now = fa[now][i];
    int bl = n-(out[now]-in[now]+1)-len[n]/2-1;
    int wh = out[now]-in[now]+1-tmp-1;
    if(len[n]&1)
    {
        if(bl <= wh) puts("Snuke");
        else puts("Fennec");
    }
    else
    {
        if(wh <= bl) puts("Fennec");
        else puts("Snuke");
    }
    return 0;
}


Measured memory_bytes: 15872
#!/usr/bin/env python3
from collections import deque


H, W = [int(str) for str in input().strip().split()]
A = [list(input().strip()) for _ in range(H)]


def bfs(starts):
    moves = ((1, 0), (0, 1), (-1, 0), (0, -1))
    dists = [[-1] * W for _ in range(H)]
    max_dist = 0
    que = deque()
    for start in starts:
        dists[start[0]][start[1]] = 0
        que.append(start)
    while len(que):
        ch, cw = que.popleft()
        for dh, dw in moves:
            nh, nw = ch + dh, cw + dw
            if (    0 <= nh < H 
                and 0 <= nw < W 
                and dists[nh][nw] == -1):
                dists[nh][nw] = dists[ch][cw] + 1
                que.append((nh, nw))
                max_dist = max(max_dist, dists[nh][nw])
    return max_dist


def solve():
    starts = ((i, j) for i in range(H) for j in range(W) if A[i][j] == '#')
    print(bfs(starts))


solve()


Measured memory_bytes: 121820
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=2010;
int n,m,tot,vis[maxn],X[maxn],Y[maxn];
int head[maxn*2],to[maxn*2],nxt[maxn*2];
queue<int> q;
vector<int> s;
queue<pair<int,int> > Q;
int in[maxn],d[maxn];
int S,pos[maxn];
int dy[maxn],e[maxn],top;
void add(int x,int y) {
	in[y]++;
	tot++;
	nxt[tot]=head[x];
	head[x]=tot;
	to[tot]=y;
}
bool dfs(int u) {
	if (vis[u]) {
		tot=0;
		for (int i=dy[u];i<=top;i++)
			d[++tot]=e[i];
		return 1;
	}
	e[++top]=u; vis[u]=1; dy[u]=top;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (dfs(v)) return 1;
	}
	top--; vis[u]=0;
	return 0;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m); int x,y,xx,yy,flag;
	for (int i=1;i<=m;i++) {
		read(X[i]); read(Y[i]);
		add(X[i],Y[i]);
	}
	tot=0;
	for (int i=1;i<=n;i++)
		if (!in[i]) q.push(i);
	while (!q.empty()) {
		int u=q.front(); q.pop();
		for (int i=head[u],v;i;i=nxt[i]) {
			v=to[i];
			in[v]--;
			if (!in[v]) q.push(v);
		}
	}
	for (int i=1;i<=n;i++)
		if (in[i]) {
			S=i; if (!dfs(i)) continue;
			//printf("%d\n",tot);
			memset(vis,0,sizeof(vis));
			for (int j=1;j<=tot;j++) {
				//printf("%d\n",d[j]);
				pos[d[j]]=j; vis[d[j]]=1;
			}
			for (int j=1;j<=m;j++)
			if (vis[X[j]]&&vis[Y[j]]) Q.push(make_pair(X[j],Y[j]));
			while (!Q.empty()) {
				xx=Q.front().first;
				yy=Q.front().second; Q.pop();
				if (!vis[xx]||!vis[yy]) continue;
				x=pos[xx]; y=pos[yy];
				if (y-x==1||(x==tot&&y==1)) continue;
				if (x-y==1) {
					printf("2\n%d\n%d\n",xx,yy);
					return 0;
				}
				if (x>y) {
					memset(vis,0,sizeof(vis));
					for (int k=y;k<=x;k++) vis[d[k]]=1;
					continue;
				}
				for (int k=x+1;k<y;k++)
					vis[d[k]]=0;
			}
			for (int j=1;j<=n;j++)
				if (vis[j]) s.push_back(j);
			printf("%d\n",s.size());
			for (int j=0;j<s.size();j++)
				printf("%d\n",s[j]);
			return 0;
		}
	/*for (int i=1;i<=tot;i++) {
		for (int j=0;j<s[i].size();j++) V[s[i][j]]=1;
		for (int j=1;j<=m;j++)
			if (V[X[j]]&&V[Y[j]]) c1[Y[j]]++,c2[X[j]]++;
		printf("%d\n",i);
		flag=1;
		for (int j=0;j<s[i].size();j++)
			if (V[s[i][j]]) {
				if (c1[s[i][j]]!=1||c2[s[i][j]]!=1) { flag=0; break; }
			}
		printf("%d\n",s[i].size());
			for (int j=0;j<s[i].size();j++)
				printf("%d\n",s[i][j]);
		if (flag) {
			printf("%d\n",s[i].size());
			for (int j=0;j<s[i].size();j++)
				printf("%d\n",s[i][j]);
			return 0;
		}
		for (int j=0;j<s[i].size();j++)
			V[s[i][j]]=0,c1[s[i][j]]=0,c2[s[i][j]]=0;
	}*/
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 384
N = int(input())

def f(N):
    ll = list(str(N))
    min_num = sum([int(i) for i in ll])
    return min_num

min_num = f(N-1) + f(1)

if N % 2 == 0:
    for i in range(1, int(N/2)):
        counter = N-i
        sum_num = f(i) + f(counter)
        if min_num > sum_num:
            min_num = sum_num

else:
    for i in range(1, int((N+1)/2)):
        counter = N-i
        sum_num = f(i) + f(counter)
        if min_num > sum_num:
            min_num = sum_num

print(min_num)



Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto ans = new long[](N);
    ans[] = -1;
    foreach (_; 0 .. M)
    {
        long S, C;
        scan(S, C);
        if (ans[S - 1] != -1 && ans[S - 1] != C)
        {
            writeln(-1);
            return;
        }
        ans[S - 1] = C;
    }
    if (ans[0] == 0)
    {
        writeln(N == 1 ? 0 : -1);
        return;
    }
    if (N == 1)
    {
        writeln(max(ans[0], 0));
        return;
    }
    ans[0] = max(ans[0], 1);
    foreach (i; 1 .. N)
        if (ans[i] == -1)
        {
            ans[i] = 0;
        }
    ans.map!text().join().writeln();
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {


        // 名前取得
        Scanner sc = new Scanner(System.in);
        // Input取得
        do {
            int e = sc.nextInt();
            if (e == 0) {
                break;
            }
            int m = e;
            int ans = 0;

            int x = 0;
            for (int z = 0; z * z * z < e + 1; z++) {
                for (int y = 0; y < Math.sqrt(e) + 1; y++) {
                    x = e - ((y * y) + (z * z * z));
                    if (x < 0) {
                        break;
                    }
                    int temp_m = x + y + z;
                    m = Math.min(temp_m, m);
                }
            }




            System.out.println(m);

        } while (true);
    }
}


Measured memory_bytes: 34136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long a = scanner.nextLong();
			long b = scanner.nextLong();
			long x = scanner.nextLong();
			System.out.println((0 == a) ? b / x + 1 : b / x - (a - 1) / x);
		}
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define req(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define qer(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=10000000000000000;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main(){
    int n,num=0,max=0;cin>>n;
  	rep(i,0,n){
      	int x,y;cin>>x>>y;
        if(x==y)num++;else num=0;
        if(num>max)max=num;
    }
    cout<<((max>=3)?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3624
//https://atcoder.jp/contests/arc074/tasks/arc074_b
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_3N 300005
#define MAX_N 100005
ll a[MAX_3N];

int main() {
	int N;
	cin >> N;
	for(int i=0;i<3*N;i++){
		cin >> a[i];
	}
	priority_queue<ll,vector<ll>,greater<ll> > qf;
	priority_queue<ll> qb;
	ll sumf[MAX_N];
	ll sumb[MAX_N];
	sumf[0]=0; sumb[0]=0;
	for(int i=0;i<N;i++){
		sumf[0] += a[i];
		qf.push(a[i]);
		sumb[0] += a[2*N+i];
		qb.push(a[2*N+i]);
	}
	for(int i=0;i<N;i++){
		qf.push(a[N+i]);
		ll minf = qf.top();
		qf.pop();
		sumf[i+1] = sumf[i] + a[N+i] - minf;
		qb.push(a[2*N-1-i]);
		ll maxb = qb.top();
		qb.pop();
		sumb[i+1] = sumb[i] + a[2*N-1-i] - maxb;
	}
	ll smax = sumf[0]-sumb[N];
	for(int i=1;i<N+1;i++){
		ll score = sumf[i]-sumb[N-i];
		if (score>smax){
			smax = score;
		}
	}
	cout << smax << endl;
    return 0;
}



Measured memory_bytes: 5996
'use strict';
const x = require('fs').readFileSync('/dev/stdin', 'utf8');
const num = Number(x);

for (let i = 3; i <= num; i++){
  if ((i%3===0)||(i%10===3)) {
    process.stdout.write(' ');
    process.stdout.write(''+i);
  } else if ((''+i).match(/3/)) {
    process.stdout.write(' ');
    process.stdout.write(''+i);
  }
}
console.log();



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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size

const ll MAXN = 13;
const ll MASMASK = (1<<12) + 1;
const ll MAXM = 1e3 + 10;
ll a[MAXM];
ll cost[MAXM];
ll n,m;
const ll INF = 1e15;
ll dp[MAXM][MASMASK];

ll rec(ll id, ll mask){
    if(id==m+1){
        if(mask==(1<<n)-1)return 0;
        else
            return INF;
    }
    
    if(dp[id][mask]!=-1)
        return dp[id][mask];
    ll ans = INF;
    ans=min(ans,rec(id+1,mask));
    ans=min(ans,rec(id+1,mask|a[id])+cost[id]);
    dp[id][mask] =ans;
    return dp[id][mask];
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll i,j;
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;

    for(i=1;i<=m;i++){
        ll aa,b;
        cin>>aa>>b;
        cost[i]=aa;
        for(j=0;j<b;j++){
            ll x;
            cin>>x;
            a[i]|=(1<<(x-1));
        }
    }
    
    ll ans=rec(1,0);
    if(ans>=INF)cout<<"-1\n";
    else
        cout<<ans<<"\n";

    return 0;  
}

Measured memory_bytes: 32768
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int n, p; cin >> n >> p;
    int flg = 0;
    rep(i, n) {int a; cin >> a; if (a % 2 != 0) flg = 1;}
    if (flg == 0) {
        if (p == 0) cout << (ll)pow(2, n) << endl;
        else cout << 0 << endl;
    } else {
        cout << (ll)pow(2, n - 1) << endl;
    }
}


Measured memory_bytes: 256