akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned long long ll;
set<ll> hash;
ll pb[300000];
int main(){
	int n,m;
	string s;
	cin >> n >> m >> s;
	ll b=1e9+7,invb=13499267949257065399ULL;
	pb[0]=1;
	rep(i,n) pb[i+1]=pb[i]*b;
	ll now=s[0];
	int l=0,r=0;
	rep(i,m){
		string t;
		cin >> t;
		if(t[0]=='R' && t[1]=='+'){
			r++;
			now=now*b+(s[r]);
		}
		if(t[0]=='R' && t[1]=='-'){
			now=(now-(s[r]))*invb;
			r--;
		}
		if(t[0]=='L' && t[1]=='+'){
			now-=(s[l])*pb[r-l];
			l++;
		}
		if(t[0]=='L' && t[1]=='-'){
			l--;
			now+=(s[l])*pb[r-l];
		}
		hash.insert(now);
	}
	cout << hash.size() << endl;
}

Measured memory_bytes: 17652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second
using ll = long long;
using P = pair<ll ,ll>;
//using Tu = tuple<ll, ll, ll>;
const ll INF = 1LL<<61LL;
const ll MOD = 1e9+7;
using Point = complex<double>;


using ld = long double;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

const double INFT = 1e15;
struct Dijkstra{
  typedef pair<int,double> pit;
  typedef pair<double,int> pti;
  vector<vector<pit>> G;
  vector<double> dist;
  int n;
  void init(int arg_n){
    n = arg_n;
    G.assign(n, vector<pit>(0));
  }
  void add_biedge(int fr, int to, double co){
    G[fr].pb(to, co);
    G[to].pb(fr, co);
  }
  void add_edge(int fr, int to, double co){
    G[fr].pb(to, co);
  }
  double dijkstra(int s, int t = -1){
    dist = vector<double>(n, INFT);
    dist[s] = 0;
    priority_queue<pti,vector<pti>,greater<pti>> que;
    que.emplace(0, s);
    while(!que.empty()){
      double d = que.top().fi;
      int p = que.top().se;
      que.pop();
      if(d > dist[p]){
        continue;
      }
      if(p == t){
        return d;
      }
      YYS(w, G[p]){
        int to = w.fi;
        double co = w.se;
        if(d + co < dist[to]){
          dist[to] = d + co;
          que.emplace(dist[to], to);
        }
      }
    }
    return INFT;
  }
};

int main(){
  ll xs,ys,xg,yg;
  cin >> xs >> ys >> xg >> yg;
  Point s(xs, ys);
  Point g(xg, yg);
  ll N;
  cin >> N;
  Dijkstra dij;
  dij.init(N+2);
  vector<pair<Point, ll> > c(N+2);
  for(int i=0;i<N;i++){
    ll x, y, r;
    cin >> x >> y >> r;
    c[i] = make_pair(Point(x, y), r);
  }
  c[N] = make_pair(s, 0);
  c[N+1] = make_pair(g, 0);
  for(int i=0;i<N+2;i++)
    for(int j=i+1;j<N+2;j++){
      dij.add_edge(i, j, max((double)0, abs(c[i].first - c[j].first) - c[i].second - c[j].second));
      dij.add_edge(j, i, max((double)0, abs(c[i].first - c[j].first) - c[i].second - c[j].second));
    }
  double ans = dij.dijkstra(N, N+1);
  printf("%.10f\n", ans);
}


Measured memory_bytes: 22512
#include <bits/stdc++.h>
using namespace std;
int main(void){
 
    string t;
    cin >> t;
    
    for(int i=0;i<t.size();i++) {
        if(t[i] == 'P' && t[i+1] == '?') {
            t[i+1] = 'D';
        }
        else if(t[i] == '?' && t[i+1] == 'D') {
            t[i] = 'P';
        }
        else if(t[i] == '?' && t[i+1] == '?') {
            t[i] = 'P';
            t[i+1] = 'D';
        }
    }
    
    for(int i=0;i<t.size();i++) {
        if(t[i] == '?') t[i] = 'D';
    }
    
    cout << t << endl;
    
    return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)




const int MAX = 5000000;
const ll MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	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 comb(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() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll N, M;
	cin >> N >> M;

	combinit();
	ll ans = comb(3*M+N-1,N-1);
	for (int K = 2 * M + 1; K <= 3 * M; K++) {
		ans -= (N * comb(3 * M - K + N - 2, N - 2))%MOD;
		ans += MOD;
		ans %= MOD;
	}

	for (int K = M + 1; K <= N; K++) {
		if ((3 * M - K) % 2)continue;
		ans -= (comb(N,K)*comb(N-1+((3*M-K)/2),N-1))%MOD;
		ans += MOD;
		ans %= MOD;
	}

	puts(ans % MOD);
	return 0;
}

Measured memory_bytes: 117504
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	bool n = false, w = false, so = false, e = false;
	rep(i,s.size()){
		if(s[i] == 'N') n = true;
		if(s[i] == 'W') w = true;
		if(s[i] == 'S') so = true;
		if(s[i] == 'E') e = true;
	}
	if((n ^ so) || (w ^ e)) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<stdio.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>

using namespace std;

int main(){
    int X,t;
    cin >> X >> t;
    if(X-t < 0){
        cout << 0 << endl;
    }else{
        cout << X-t <<endl;
    }
   
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        s:chars,
    }
    let mut rlv = vec![];
    let mut sum = 0;
    for i in 0..s.len()-1 {
        if s[i] == 'R' &&  s[i+1] == 'L' {
            rlv.push(i);
        }
    }
    let mut ans = vec![0;s.len()];
    for i in 0..rlv.len() {
        let mut left = rlv[i];
        let mut right = left + 1;
        while left > 0 && s[left-1] == 'R' {
            left -= 1;
        }
        while right + 1 < s.len() && s[right + 1] == 'L' {
            right += 1;
        }
        let mut lv = 0;
        let mut rv = 0;
        for j in left..rlv[i] {
            if (rlv[i]-j) % 2 == 0 {
                lv += 1;
            } else {
                rv += 1;
            }
        }
        for j in rlv[i]..(right+1) {
            if (j-rlv[i]) % 2 == 0 {
                lv += 1;
            } else {
                rv += 1;
            }
        }
        ans[rlv[i]] = lv;
        ans[rlv[i] + 1] = rv;
    }
    for i in 0..s.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 6524
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<stdlib.h>
using namespace std;

int main(){
    int m,d,ans=0;
    cin >> m >> d;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            if(i==(j/10)*(j%10)&&(j/10)>1&&(j%10)>1)ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[100010][3] = {0};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int table[100010][3] = {0};
signed main()
{
    int n;
    cin >> n;
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> table[i][j];
        }
    }
    for (int i = 0; i < 3; i++)
    {
        table[0][i] = 0;
    }
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (j == k)
                    continue;
                chmax(dp[i][k], dp[i - 1][j] + table[i][k]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        chmax(ans, dp[n][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
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); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


int n;
int a[300005];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, 62) {
		int one = 0, zero = 0;
		rep(j, n) {
			if (a[j] >> i & (int)1)one++;
			else zero++;
		}
		ans += (1ll << i) % mod * one % mod * zero % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
int fx[]={0,0,1,-1};
int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=23;
int lvl[N][N];
char adj[N][N];
int n,m;
int bfs(pi st,pi ed)
{
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++)lvl[i][j]=inf;
    queue<pi>q;
    q.push(st);
    lvl[st.ff][st.ss]=0;
    while(!q.empty())
    {
        if(q.front()==ed)break;
        int x=q.front().ff,y=q.front().ss;
        q.pop();
        for(int k=0;k<4;k++)
        {
            int xx=x+fx[k];
            int yy=y+fy[k];
            if(xx>=0&&xx<n&&yy<m&&yy>=0){
                if(lvl[x][y]+1<lvl[xx][yy]&&adj[xx][yy]=='.')
                {
                    q.push({xx,yy});
                    lvl[xx][yy]=lvl[x][y]+1;
                }
            }
        }
    }
    return lvl[ed.ff][ed.ss];
}
int main()
{
    IOS;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)cin>>adj[i][j];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(adj[i][j]=='#')continue;
            for(int k=0;k<n;k++)
            {
                for(int l=0;l<m;l++)
                {
                    if(adj[k][l]=='.')
                    {
                        int temp=bfs({i,j},{k,l});
                        ans=max(ans,temp);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}








Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+23;
int bit[maxn<<2],n;
int o[maxn];
int l[maxn],r[maxn],p[maxn];
inline int lowbit(int x){
    return x&(-x);
}

void update(int i,int x){
    for(;i<=n;i+=lowbit(i)) bit[i]+=x;
}
int query(int i){
    int ans=0;
    for(;i;i-=lowbit(i)) ans+=bit[i];
    return ans;
}


void solve(){
    ll ans=0;
    scanf("%d",&n);
    vector<int> vis(n,0);
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&p[i],&l[i],&r[i]);
    }
    for(int i=0;i<n;i++) o[i]=i;
    sort(o,o+n,[&](int i,int j){
        return l[i]-r[i]>l[j]-r[j];
    });
    int cnt=0;
    set<int> s;
    for(int i=1;i<=n;i++) s.insert(i);
    for(int j=0;j<n;j++){
        int i=o[j];
        if(l[i]<=r[i]) break;
        auto it=s.upper_bound(p[i]);
        // printf("remove:%d\n",*it);
        if(it!=s.begin()) ans+=l[i],cnt++,s.erase(--it);
        else ans+=r[i];
        vis[i]=1;
    }
    // cout<<ans<<endl;
    s.clear();
    for(int i=cnt+1;i<=n;i++) s.insert(i);
    for(int j=n-1;j>=0;j--){
        int i=o[j];
        if(vis[i]) break;
        int to=p[i];
        auto it=s.upper_bound(to);
        if(it==s.end()) ans+=l[i];
        else{
            ans+=r[i];
            s.erase(it);
        }
    }
    printf("%lld\n",ans);
}

int main(){
    int T;cin>>T;
    while(T--) solve();  
}

Measured memory_bytes: 16448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		while (true) {
			String line = reader.readLine();
			if (line.equals("0 0 0 0")) {
				break;
			}
			int[] num = new int[4];
			StringTokenizer tokenizer = new StringTokenizer(line);
			for (int i = 0; i < 4; i++) {
				num[i] = Integer.parseInt(tokenizer.nextToken());
			}
			boolean flag = false;
			loop: for (int i = 0; i < 4; i++) {
				for (int j = i + 1; j < i + 4; j++) {
					for (int k = 0; k < 4; k++) {
						if (i == k || j % 4 == k) {
							continue;
						}
						for (int l = 0; l < 1; l++) {
							if (check(num[i], num[j % 4], num[k], num[6 - (i
									+ j % 4 + k)])) {
								flag = true;
								break loop;
							}
						}
					}

				}
			}
			if (!flag) {
				System.out.println(0);
			}
		}

	}

	private static boolean check(int a, int b, int c, int d) {
		char[] chs = { '+', '-', '*' };
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (cal(cal(cal(a, chs[i], b), chs[j], c), chs[k], d) == 10) {
						System.out.println(String.format(
								"(((%d %s %d) %s %d) %s %d)", a, chs[i], b,
								chs[j], c, chs[k], d));
						return true;
					} else if (cal(cal(a, chs[i], b), chs[j], cal(c, chs[k], d)) == 10) {
						System.out.println(String.format(
								"((%d %s %d) %s (%d %s %d))", a, chs[i], b,
								chs[j], c, chs[k], d));
						return true;
					}
				}
			}
		}
		return false;
	}

	private static int cal(int a, char c, int b) {
		switch (c) {
		case '+':
			return a + b;
		case '-':
			return a - b;
		default:
			return a * b;
		}
	}
}

Measured memory_bytes: 18412
def c_takahashi_information(C):
    a = [min(C[0]), min(C[1]), min(C[2])]
    tmp = [[C[i][j] - a[i] for j in range(3)] for i in range(3)]
    b = list(map(list, set(map(tuple, tmp))))
    for bb in b:
        f = True
        for i in range(3):
            for j in range(3):
                if a[i] + bb[j] != C[i][j]:
                    f = False
                    break
            if not f:
                break
        if f:

            return 'Yes'
    return 'No'
  
C = [[int(i) for i in input().split()] for j in range(3)]
print(c_takahashi_information(C))

Measured memory_bytes: 38384
# coding: utf-8

(n,k) = [int(i) for i in input().rstrip().split(" ")]

class Result:
    def __init__(self, win, lose):
        self.win = win
        self.lose = lose
        self.total = win + lose


dic = {}

def getAns(num:int):
    if num >= k:
        return Result(1, 0)
    if num in dic:
        return dic[num]
    r = getAns(num*2)
    ret = Result(r.win, r.lose + r.total)
    dic[num] = ret
    return ret


result_list = [getAns(i) for i in range(1, n + 1)]
max_total = max([i.total for i in result_list])
total = max_total * len(result_list)
win_total = sum([i.win * (max_total/i.total) for i in result_list])
print(win_total/total)


Measured memory_bytes: 23516
#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+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  ll a,b,n,x,y=0;
  cin >> a >> b >> n;
  if(n<b) x=n;
  else x=n-n%b-1;
  y=floor(a*x/b)-a*floor(x/b);
  cout << y << endl;
}

Measured memory_bytes: 3620
def main():
    _ = input()
    s = input()
    if len(s) % 2 != 0:
        print("No")
    else:
        mid = int(len(s) / 2)
        if s[0:mid] == s[mid:]:
            print("Yes")
        else:
            print("No")
   

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))

cnt_1, cnt_2 = 0, 0
for v in a:
    if v % 2 == 1:
        cnt_1 += 1
    elif v % 4 == 0:
        cnt_2 += 1

if cnt_1 + cnt_2 == n and cnt_1 - cnt_2 == 1:
    print('Yes')
elif cnt_1 <= cnt_2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 85340
#include <cstdio>
#include <algorithm>

const int MAX_N = 100;

int N, K;
int x[MAX_N];

int main(){

  scanf("%d", &N);
  scanf("%d", &K);
  for(int i = 0; i < N; i++)
    scanf("%d", x + i);

  int ans=0;

  for(int i = 0; i < N; i++){

    int dis = (K - x[i]);
    ans += std::min(x[i], dis);

  }

printf("%d\n", ans * 2);

return 0;

}


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

typedef long long ll;

int main(){
    ll x, y;
    cin >> x >> y;
    ll A = x;
    ll cnt = 0;
    while(A <= y){
        A = pow(2LL, cnt+1) * x;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::{input, marker::{Isize1, Usize1, Bytes, Chars}};

#[proconio::fastout]
fn main() {
    input!(
        core: Chars,
        n: usize,
    );
    let mut s = VecDeque::with_capacity(core.len() + n);
    for c in core { s.push_back(c); }
    let mut rev = 0;
    for _ in 0..n {
        input!(mode: u8);
        if mode == 1 { rev = 1 - rev; }
        else {
            input!(lr: u8, c: char,);
            if (lr - 1) ^ rev == 0 { s.push_front(c); }
            else { s.push_back(c); }
        }
    }
    if rev == 0 { for c in s.into_iter() { print!("{}", c); } }
    else { for c in s.into_iter().rev() { print!("{}", c); } }
}


Measured memory_bytes: 4660
#include<set>
#include<string>
#include<iostream>
#include <algorithm>
int main(void) {
	std::ios_base::sync_with_stdio(false);
	int n;
	std::cin >> n;
	std::set<std::string>DICTIONARY;
	std::string COMMAND;std::string WORD;
	for (int i = 0; i < n; ++i) {
		std::cin >> COMMAND>>WORD;
		if (COMMAND == "insert") {
			
			DICTIONARY.insert(WORD);
		}
		else if (COMMAND == "find") {
			//if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) != DICTIONARY.end())
			if (DICTIONARY.find( WORD) != DICTIONARY.end())
			{
				std::cout << "yes" << std::endl;
			}
			else { std::cout << "no" << std::endl; }
		}
	}
	//	system("pause");
	return 0;
}

Measured memory_bytes: 29776
K, A, B = map(int, input().split())

if B - A <= 2:
    print(1 + K)
elif A + 1 > K:
    print(1 + K)
else:
    rest = K - A + 1
    b = (rest // 2) * (B - A) + rest % 2 + A
    print(max(1 + K, b))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int A[300000];

int main() {
	
	int n;
	cin >> n;
	
	int maxi = -1;
	int id;
	
	for(int i = 0; i < n; i++){
		cin >> A[i];
		if(maxi < A[i]){
			maxi = A[i];
			id = i;
		}
	}
	
	int mini = 1000000001;
	int ans1 = A[0];
	
	for(int i = 0; i < n; i++){
		if(i == id){
			continue;
		}
		if(maxi % 2 == 0){
			if(abs(maxi/ 2 - A[i]) < mini){
				mini = abs(maxi / 2 - A[i]);
				ans1 = A[i];
			}
		}else{
			if(min(abs(maxi / 2 - A[i]), abs(maxi / 2 + 1 - A[i])) < mini){
				mini = min(abs(maxi / 2 - A[i]), abs(maxi / 2 + 1 - A[i]));
				ans1 = A[i];
			}
		}
	}
	
	cout << maxi << " " << ans1 << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long x, y;

int main(){
	cin >> x >> y;
	if(x == 0){
		if(y == 0){
			cout << 0 << endl;
		}else if(y > 0){
			cout << y << endl;
		}else{
			cout << 1 + abs(y) << endl;
		}
		return 0;
	}
	if(y == 0){
		if(x > 0){
			cout << 1 + abs(x) << endl;
		}else{
			cout << abs(x) << endl;
		}
		return 0;
	}




	if(x <= y){
		if(x>= 0 && y >= 0){
			cout << y - x << endl;
		}else if(x<= 0 && y <= 0){
			cout << y - x << endl;
		}else if(abs(x) <= abs(y)){
			cout << 1 + y - abs(x) << endl;
		}else{
			cout << 1 + abs(x) - abs(y)  << endl;
		}
	}else{
		if(x>= 0 && y >= 0){
			cout << 2 + x - y << endl;
		}else if(x<= 0 && y <= 0){
			cout << 2 + x - y << endl;
		}else if(abs(y) <= abs(x)){
			cout << 1 + abs(x) - abs(y) << endl;
		}else{
			cout << 1 + abs(y) - abs(x)  << endl;
		}
	}
}



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

int main() {
	long num[3];
	cin >> num[0] >> num[1];
	
	if(num[0]>=num[1]){
		num[2]=num[1];
	}
	else{
		num[2]=num[0];
		num[0]=num[1];
	}
	
	long x;
	cin >>x;
	
	if(num[0]>=x){num[1]=x;}
	else{num[1]=num[0]; num[0]=x;}
	

if(num[0]%2==0 || num[1]%2==0 || num[2]%2==0){cout << 0 << endl;}
else{cout << num[1]*num[2] << endl;}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 63-A

int main(void)
{
	int i, j, C=0;
	char S[26];
	scanf("%s", S);
	for (i = 0; i < 26; i++)
	{
		for (j = i+1; j < strlen(S); j++)
		{
			if (S[i] == S[j])
			{
				C = 5;
			}
		}
	}
	if (C == 5)
		printf("no");
	else if(C==0)
		printf("yes");
	return 0;
}

Measured memory_bytes: 128
ABCD = list(input())
lst = [int(i) for i in ABCD]

#print (lst)

def judge(x):
    if lst[0]+lst[1]+lst[2]+lst[3]==7:
        return '+ + +'
    elif lst[0]+lst[1]+lst[2]-lst[3]==7:
        return '+ + -'
    elif lst[0]+lst[1]-lst[2]+lst[3]==7:
        return '+ - +'
    elif lst[0]+lst[1]-lst[2]-lst[3]==7:
        return '+ - -'
    elif lst[0]-lst[1]+lst[2]+lst[3]==7:
        return '- + +'
    elif lst[0]-lst[1]+lst[2]-lst[3]==7:
        return '- + -'
    elif lst[0]-lst[1]-lst[2]+lst[3]==7:
        return '- - +'
    elif lst[0]+lst[1]-lst[2]-lst[3]==7:
        return '- - -'

#print(judge(lst))
lst2 = list(judge(lst).split())
#print (lst2)
ans = str(lst[0])+lst2[0]+str(lst[1])+lst2[1]+str(lst[2])+lst2[2]+str(lst[3])+'=7'

print (ans)

Measured memory_bytes: 3064
I=lambda:map(int,input().split());
n,q=I();r=[0]*n;e=[[]for _ in range(n)];y=[0]+[1]*n;s=[0]
for _ in range(n-1):a,b=I();e[a-1]+=b-1,;e[b-1]+=a-1,;
for _ in range(q):p,x=I();r[p-1]+=x;
while s:
  u=s.pop();v=r[u];
  for c in e[u]:
    if y[c]:y[c]=0;r[c]+=v;s+=c,;
print(*r)

Measured memory_bytes: 55828
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <string>
using namespace std;

using ll = long long int;
vector<int> dp[55][55];
string board[55];
int t;
int d[55][55];
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int h, w, m;
int gx, gy;

void dfs(int x, int y) {
	if (x == gx && y == gy) return;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 > nx || w <= nx || 0 > ny || h <= ny || board[ny][nx] == '#') continue;
		if (d[ny][nx] > d[y][x] + 1) {
			d[ny][nx] = d[y][x] + 1;
			dfs(nx, ny);
		}
	}
}

int main() {
	cin >> h >> w >> m;
	for (int i = 0; i < h; ++i) cin >> board[i];
	vector<int> a(h*w), b(h*w), c(h*w);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) cin >> a[i*w + j];
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) cin >> b[i*w + j];
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) cin >> c[i*w + j];
	}
	vector<int> x(m), y(m);
	for (int i = 0; i < m; ++i) {
		cin >> y[i] >> x[i];
	}

	t = 0;
	for (int i = 1; i < m; ++i) {
		//cout << "i:" << i << endl;
		// i-1 -> i
		gx = x[i], gy = y[i];
		for (int j = 0; j < h; ++j) {
			for (int k = 0; k < w; ++k) {
				d[j][k] = 1 << 30;
			}
		}
		d[y[i - 1]][x[i - 1]] = 0;
		dfs(x[i - 1], y[i - 1]);

		vector<pair<int, int>> path;
		int ax = x[i], ay = y[i];
		if (i == m - 1) path.push_back({ ax, ay });
		// cout << "ax" << x[i-1] << " " << y[i-1] << endl;
		while (ax != x[i - 1] || ay != y[i - 1]) {
			//cout << ax << "," << ay << endl;
			for (int j = 0; j < 4; ++j) {
				int nx = ax + dx[j], ny = ay + dy[j];
				// cout << nx << " " << ny << " " << dx[j] << " " << dy[j] << endl;
				if (0 > nx || w <= nx || 0 > ny || h <= ny) continue;
				// cout << d[ny][nx] << endl;
				if (d[ny][nx] == d[ay][ax] - 1) {
					ax = nx, ay = ny;
					break;
				}
			}
			path.push_back({ ax, ay });
		}
		// path.push_back({ x[i - 1], y[i - 1] });
		reverse(path.begin(), path.end());
		//cout << "-----" << endl;

		for (auto j : path) {
			//cout << j.first << "," << j.second << endl;
			dp[j.second][j.first].push_back(t);
			t++;
		}
		//cout << endl;
	}

	int ret = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			//for (auto k : dp[i][j]) cout << k << " ";
			//cout << endl;
			for (int k = 0; k < (int)dp[i][j].size() - 1; ++k) {
				int vl = b[i*w + j] + c[i*w + j];
				int vr = a[i*w + j] * (dp[i][j][k + 1] - dp[i][j][k]);
				ret += min(vl, vr);
			}
			if (dp[i][j].size()) {
				ret += b[i*w + j] + c[i*w + j];
			}
			//cout << ret << endl;
		}
	}

	cout << ret << endl;
}


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

int main(){
    
    int N,n,a,b,c,p;
    int sum=0;
    cin>> n >> a >> b;
    for(int i=1;i<=n;++i){
      N = i;
      for(int j=0;j<5;++j){
      	p = N%10;
        N = N/10;
        c += p;  
      }
        if(c>=a&&c<=b){
   			sum += i;
        }
        c = 0;
    }
    cout << sum <<endl;
}

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

int main(){
	int a;
	cin >> a;
	int arr[a];
	for(int i=0;i<a;i++)cin >> arr[i];
	int sum = 0;
	for(int i=0;i<a-1;i++){
		for(int j=i+1; j <a ; j++){
			int mul = arr[i] * arr[j];
			sum += mul;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main(){int i;
  string s;
  cin>>s;
  if(s[1]=='B'){
    s[1]='R';
  }
  else{s[1]='B';
  }
  for(i=0;i<s.size();i++){
    cout<<s[i];
  }
}

Measured memory_bytes: 3612
n,m=map(int,input().split())
l=[]
for i in range(m):
    L=list(map(int,input().split()))
    l.append(L)
L=1
R=n
for i in range(m):
    if L<l[i][0]:
        L=l[i][0]
    if R>l[i][1]:
        R=l[i][1]
if L>R:
    print(0)
else:
    print(R-L+1)

Measured memory_bytes: 27344
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a;
    cin >> a;
    if (a == 25) {
        cout << "Christmas" << endl;
    }
    if (a == 24) {
        cout << "Christmas Eve" << endl;
    }
    if (a == 23) {
        cout << "Christmas Eve Eve" << endl;
    }
    if (a == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
    int n;cin>>n;
    vector<int>ans(n,0);
    vector<pair<int,int>>a(n+1);
    REP(i,n){
        int z;cin>>z;
        a[i]={z,-i};
    }
    a[n]={0,-INF};
    sort(a.rbegin(),a.rend());
    int MI=INF;
    REP(i,n){
        chmin(MI,-a[i].second);
        ans[MI]+=(a[i].first-a[i+1].first)*(i+1);
        a[i].first-=a[i+1].first;
    }
    REP(i,n)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int a,b,r;
    cin >> a >> b >> r;
    if(!a&&!b) return 0;
    int range[64]={};
    REP(i,r*4+1) REP(j,r*4+1)
      if(i*i+j*j<=16*r*r) range[i]++;
    vector<vector<int> >figx;
    figx.assign(10000,vector<int>());
    REP(i,a){
      int xa,ya;
      scanf("%d%d",&xa,&ya);
      figx[xa].push_back(ya);
    }
    REP(i,10000) SORT(figx[i]);
    int answer=0;
    REP(bul,b){
      int xb,yb;
      scanf("%d%d",&xb,&yb);
      FOR(dx,max(-r*4,-xb),min(r*4+1,10000-xb)){
	int sec=range[abs(dx)];
	int nx=xb+dx;
	if(sec)
	  answer+= upper_bound(figx[nx].begin(),figx[nx].end(),yb+sec-1)-lower_bound(figx[nx].begin(),figx[nx].end(),yb-sec+1);
      }
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 1912
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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 S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

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

  if( N == 1 ) {
    std::cout << "Hello World" << std::endl;
  }
  else {
    ll A, B;
    std::cin >> A >> B;

    std::cout << A+B << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define console
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define siz(x) ((int)(x).size())
#define full(v) v.begin(), v.end()
#ifndef console
ifstream fin("data.in");
ofstream fout("data.out");
#else
#define fin cin
#define fout cout
#endif
#define MAX(x, y) ((a) > (b) ? (a) : (b))
#define usain_bolt() (ios_base::sync_with_stdio(false), \
                      fin.tie(NULL), fout.tie(NULL))
const long long oo = 0x3f3f3f3f;
const double PI = acos(-1);

const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef long long ll;
typedef unsigned int ui;


int main()
{
    usain_bolt();
    int a, b;
    fin >> a >> b;
    fout << a * b;
#ifndef console
    fin.close(), fout.close();
#else
#undef fin cin
#undef fout cout
#endif // console
    return 0;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int p[N], c[N];

int main()
{
	cin >> n >> m;
	m /= 100;
	
	for (int i = 0; i < n; i ++ )
	{
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
	
	int res = 0x3f3f3f3f;
	for (int t = 0; t < (1 << n); t ++ )
	{
		int cnt = 0, s = m;
		for (int i = 0; i < n; i ++ )
			if ((t >> i) & 1)
			{
				s -= p[i] * (i + 1) + c[i];
				cnt += p[i];
			}
			
		for (int i = n - 1; i >= 0; i -- )
			if (s > 0 && !((t >> i) & 1))
			{
				int c = min(s / (i + 1), p[i] - 1);
				cnt += c;
				s -= c * (i + 1);
			}
		
		if (s <= 0) res = min(res, cnt);
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
def dobfac(num):
    count = 0
    i = 5
    if num % 2:
        print(0)
    else:
        while num / i > 0:
            count += num // i // 2
            i *= 5
        print(count)

if __name__ == "__main__":
    import sys
    in_str = []
    for line in sys.stdin:
        in_str.append(line)
    dobfac(int(in_str[0]))

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
   int n, a, ma = 0, mi = 1000;
   cin >> n;
   for(int i = 0; i < n; i++){
      cin >> a;
      ma = max(ma, a);
      mi = min(mi, a);
   }

   cout << ma - mi << endl;
}

Measured memory_bytes: 3592
/**
 *    author:  erekle
 *    created: 19.09.2020 14:17:48
**/
#include <bits/stdc++.h>

using namespace std;

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define swap2(x,y) x=x^y; y=x^y; x=x^y;

int main() {
	fastIO
	
	int n, q; cin >> n >> q;

	long long blacks = (n-2LL) * (n-2LL);
	set< pair< pair<int, int>, int > > ladderH, ladderV; // horizontal and vertical

	ladderH.insert({{1,n},n});
	ladderV.insert({{1,n},n});
		
	while (q--) {
		int type, x; cin >> type >> x;
		if (type == 1) {
			auto it = ladderH.lower_bound({{x+1,0},0});
			assert(it != ladderH.begin());
			--it;
			int endPos = it->second - 1;
			blacks -= endPos - 1;

			auto topmost = *ladderV.begin();
			if (topmost.second < x) continue;

			ladderV.erase(ladderV.begin());
			ladderV.insert({{1,endPos},x});
			if (topmost.first.second > endPos) {
				topmost.first.first = endPos + 1;
				ladderV.insert(topmost);
			}
		} else {
			auto it = ladderV.lower_bound({{x+1,0},0});
			assert(it != ladderV.begin());
			--it;
			int endPos = it->second - 1;
			blacks -= endPos - 1;

			auto topmost = *ladderH.begin();
			if (topmost.second < x) continue;

			ladderH.erase(ladderH.begin());
			ladderH.insert({{1,endPos},x});
			if (topmost.first.second > endPos) {
				topmost.first.first = endPos + 1;
				ladderH.insert(topmost);
			}
		}
	}
	cout << blacks << endl;
	return 0;
}


Measured memory_bytes: 9844
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};

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

    int test=1;
    ///scanf("%d",&test);
    for(int cs=1; cs<=test; ++cs) {
       string s;
       cin>>s;
       cout<<s[0]<<s[1]<<s[2];
    }
    return 0;
}



Measured memory_bytes: 3592
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
T = input()
sl = len(S)
tl = len(T)

def f(idx):
    if idx + tl > sl:
        return False
    for i in range(tl):
        if S[idx + i] != '?' and S[idx + i] != T[i]:
            return False

    ret = [''] * sl
    for i in range(sl):
        ret[i] = T[i - idx] if idx <= i < idx + tl else S[i] if S[i] != '?' else 'a'

    return "".join(ret)

def solve():
    for i in range(sl, -1, -1):
        if f(i):
            print(f(i))
            return

    print("UNRESTORABLE")

solve()

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
const int mod = 1e9 + 7;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
using Point = complex<double>;
double dot(Point a, Point b) {return real(conj(a) * b);}
double cross(Point a, Point b) {return imag(conj(a) * b);}
const double eps = 1e-10;
int main() {
    double a, b; char ch;
    vector<pair<double, double> > v;
    while (cin >> a >> ch >> b) {
        v.push_back({a, b});
    }
    //sort(v.begin(), v.end());
    //vector<pair<double, double> > line;
    /*
    rrep(i, 1, v.size()) {
        line.push_back({v[0].first - v[i].first, v[0].second - v[i].second});
    }
     */
    double sum = 0;
    rrep(i, 1, v.size() - 1) {
        sum += abs(cross(Point(v[0].first - v[i].first, v[0].second - v[i].second), Point(v[0].first - v[i + 1].first, v[0].second - v[i + 1].second)));
    }
    cout << sum / 2 << endl;
}



Measured memory_bytes: 3240
import java.util.*;
import java.io.*;

class Main{

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

        int N = sc.nextInt();
        
        int[] old = {0,0,0};
        int[] curr = {0,0,0};

        for(int i = 0; i < N; i++){
            old[0] = curr[0];
            old[1] = curr[1];
            old[2] = curr[2];

            curr[0] = Math.max( old[1], old[2] ) + sc.nextInt();
            curr[1] = Math.max( old[0], old[2] ) + sc.nextInt();
            curr[2] = Math.max( old[1], old[0] ) + sc.nextInt();
        }
    
        System.out.println( Math.max( curr[0], Math.max(curr[1], curr[2]) ) );

        sc.close();
    }
}


Measured memory_bytes: 88692
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define max(a,b) a>b?a:b
int dp[101][10001];
int main() {
	int w[200], v[200];
	int i, j, n, W;
	fscanf(stdin, "%d%d", &n, &W);
	for (i = 1; i <= n; i++) fscanf(stdin, "%d%d", v + i, w + i);
	for (i = 1; i <= n; i++)
		for (j = 0; j <= W; j++) {
			if (w[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
		}
	P(d, dp[n][W]);
	return 0;
}

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

int main() {
  string S; cin >> S;
  
  int ans = 0;
  
  if(S.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  
  rep(i, S.size()) {
    if(S[i] == S[i-1]) {
      if(S[i] == '1') S[i] = '0';
      else S[i] = '1';
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    long long int n,i,j,sum=0;
    scanf ("%lld",&n);
    for (i=1;i<=n;i++)
    {
        j=n/i;
        sum=sum+(j*(j+1)*i)/2;
    }
    printf ("%lld",sum);
    return 0;

}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N,K;
vi h;
void solve(){
    cin>>N>>K;
    int ans=0;
    rep(i,N){int a; cin>>a; (a>=K)?(++ans):0;}
    cout<<ans<<endl;
    return;
}

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

    solve();
    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+9;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL my_pow(LL x, LL y){
	LL a=1;
	REP(i,y){
		a *= x;
		a %= MOD;
	}
	return a % MOD;
}
void Main()
{
	int n; cin >> n;
	vector<string> s(n);
	VI t(n);
	REP(i,n){
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;

	LL result = 0;
	int type = 0;
	REP(i,n){
		if(type == 0){
			if(s[i] == x){
				type = 1;
			}

		}
		else{
			result += t[i];
		}
	}

	cout << result << endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N, M;
	cin >> N >> M;
	
	int ans = 0;
	vector<string>s(N);
	cin >> s;
	vector<pair<int, int>>koma;
	REP(i, N) REP(j, M) {
		if(s[i][j] == 'o') {
			koma.emplace_back(i, j);
			ans -= i + j;
		}
	}
	mcf_graph<int, int>g(N * M + 2 + koma.size());
	int S = N * M + koma.size(), T = N * M + 1 + koma.size();
	auto f = [&](int y, int x, int idx) {
		vector<vector<int>>dp(N, vector<int>(M));
		dp[y][x] = 1;
		REP(i, N) {
			REP(j, M) {
				if(i && s[i - 1][j] != '#')dp[i][j] |= dp[i - 1][j];
				if(j && s[i][j - 1] != '#')dp[i][j] |= dp[i][j - 1];
			}
		}
		REP(i, N) REP(j, M) {
			if(dp[i][j]) g.add_edge(N * M + idx, i * M + j, 1, INF - i - j);
		}
	};
	REP(i, koma.size()) {
		g.add_edge(S, N * M + i, 1, 0);
		f(koma[i].first, koma[i].second, i);
	}
	REP(i, N) {
		REP(j, M) {
			if(s[i][j] != '#') {
				g.add_edge(i * M + j, T, 1, 0);
			}
		}
	}
	auto cost = g.flow(S, T);
	out(INF * koma.size() - cost.second + ans);
}

Measured memory_bytes: 8716
a = gets.chomp.split(' ').map(&:to_s)
s = []
ans = 0
(a.size).times do |i|
  if a[i] =~ /\d+/
    s.push(a[i].to_i)
  else
    tmp = s.pop(2)
    res =
      a[i] == '+' ? tmp[0] + tmp[1] :
      a[i] == '-' ? tmp[0] - tmp[1] :
      tmp[0] * tmp[1]
    s.push(res)
  end
end
puts s.pop

Measured memory_bytes: 8664
# C - XYZ Triplets
from collections import Counter


def main():
    N = int(input())
    calc = lambda x, y, z: x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    lim = int(N ** 0.5) + 1
    cnt = Counter(
        calc(i, j, k)
        for i in range(1, lim + 1)
        for j in range(1, lim + 1)
        for k in range(1, lim + 1)
    )
    res = [cnt[i] for i in range(1, N + 1)]
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 12452