akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
struct coord {
    double x;
    double y;
};

coord rotate(coord p){
    double nx = p.x/2 - p.y*sqrt(3)/2;
    double ny = p.x*sqrt(3)/2 + p.y/2;
    return coord {nx, ny};
}

vector<coord> koch(coord a, coord b){
    auto vec = vector<coord>();
    coord p1 = coord {(a.x*2+b.x)/3, (a.y*2+b.y)/3};
    coord p2 = coord {(a.x+2*b.x)/3, (a.y+2*b.y)/3};
    coord v = coord {p2.x-p1.x, p2.y-p1.y};
    coord nv = rotate(v);
    coord p3 = coord {p1.x+nv.x, p1.y+nv.y};
    vec.push_back(a);
    vec.push_back(p1);
    vec.push_back(p3);
    vec.push_back(p2);
    vec.push_back(b);
    return vec;
}

vector<coord> koch(vector<coord>& vec, int d){
    if(!d){
        return vec;
    }
    auto ret = vector<coord>();
    for(auto it = vec.begin(); it != vec.end()-1; ++it){
        auto vs = koch(*it, *(it+1));
        if(it == vec.begin()){
            ret.insert(ret.end(), vs.begin(), vs.end());
        } else {
            ret.insert(ret.end(), vs.begin()+1, vs.end());
        }
    }
    return koch(ret, d-1);
}

int main(){
    int n;
    cin >> n;
    vector<coord> vs {coord {0.0, 0.0}, coord {100.0, 0.0}};
    auto vec = koch(vs, n);
    for(auto it = vec.begin(); it != vec.end(); ++it){
        printf("%f %f\n", it->x, it->y);
    }
}

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

#define all(x) (x).begin(), (x).end()
using lli = long long int;
template <typename T>
vector<T> read_vector(int n) {
  vector<T> result(n);
  for (auto& a : result) cin >> a;
  return result;
}
template <typename T>
vector<T> read_vector() {
  int n;
  cin >> n;
  return read_vector<T>(n);
}

int main() {
  ios_base::sync_with_stdio(false);
  auto v = read_vector<int>();
  bool valid = v[0] == 0;
  for (int i = 1; i < v.size(); ++i) valid &= v[i] <= v[i - 1] + 1;
  if (!valid) {
    cout << -1;
    return 0;
  }
  lli cost = 0;
  int prev = 0;
  reverse(all(v));
  for (auto a : v) {
    prev = max(0, prev - 1);
    if (a < prev) {
      cout << -1;
      return 0;
    } else if (a > prev) {
      cost += a;
    }
    prev = a;
  }
  cout << cost;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int X;
    vector<int> li;
    cin>>X;
    int index=2;
    while(true){
        bool can=true;
        rep(i, li.size()){
            if(index%li[i]==0){
                can=false;
                break;
            }
            if(li[i]*li[i]>index) break;
        }
        if(can==true){
            li.push_back(index);
            if(index>=X){
                cout<<index<<endl;
                return 0;
            }
        }
        index++;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<string,int> M;
  
  int q;
  cin>>q;

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      string key;
      int x;
      cin>>key>>x;
      M[key] = x;
    }
    
    if(cmd == 1){
      string key;
      cin>>key;
      if(!M.count(key)) cout<<0<<endl;
      else cout<<M[key]<<endl;
    }
    
    if(cmd == 2){
      string key;
      cin>>key;
      M.erase(key);
    }

    if(cmd == 3){
      string l,r;
      cin>>l>>r;
      auto start = M.lower_bound(l);
      auto last = M.upper_bound(r);
      assert(l <= r);
      for(auto it=start; it != last; it++) cout<<it->first<<" "<<it->second<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 25932
#include<bits/stdc++.h>
using namespace std;
int n;
float a[100];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  }
sort(a,a+n);
for(int i=1;i<=n-1;i++)
{
	a[i]=(a[i]+a[i-1])/2.0;
}
cout<<a[n-1];
return 0;
}

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

using namespace std;
int MOD = 1000000007;

int main(){
  int n,k;
  cin >> n >> k;
  int ret = 0;
  while( n > 0 ){
    n = n / k;
    ret++;
  }
  cout << ret << endl;
  return 0;
}


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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};

using D=double;
using P=complex<D>;


ll N,K;
vector<P> A;
vector<D> dist;
const D INF=1e15;
const P err={0,0};
D ans=INF;


inline D cost(P a){
  for(int i=0;i<N;i++){
    dist[i]=abs(A[i]-a);
  }
  sort(dist.begin(),dist.end(),greater<D>());
  D ret=0;
  for(int i=0;i<K;i++){
    ret+=dist[i];
  }
  //if(ret<ans) cout<<a<<endl;
  chmin(ans,ret);
  return ret;
}

#define F first
#define S second
using pt=pair<D,P>;

const vector<P> V={{1,0},{0,1},{-1,0},{0,-1}};

void cul(P a,int num,D dis){
  //dis=cost(a);

  //cout<<dis<<endl;
  //dis=dis*dis;
  //chmax(dis,1.0);

  for(int i=0;i<num;i++){
    for(int j=0;j<5;j++){
      pt mi={cost(a),a};
      for(auto &v:V){
        D c=cost(a+v*dis);
        if(c<mi.F){
          mi.F=c;
          mi.S=a+v*dis;
        }
      }
      a=mi.S;
    }
    dis/=2.0;
  }
}

const D dis=500;
const int num=50;

mt19937 MT;

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

  auto start=clock();

  cin>>N>>K;
  A.resize(N);
  dist.resize(N);
  for(auto &I:A){
    D x,y;
    cin>>x>>y;
    I={x,y};
  }
  vector<P> B=A;
  P mid=err;
  for(auto &I:A){
    cul(I,num,dis);
    mid+=I;
  }
  mid/=N;
  cul(mid,num,dis);

  while((double)(clock()-start)/CLOCKS_PER_SEC<1.9){
    mid=err;
    shuffle(B.begin(),B.end(),MT);
    int sz=MT()%N+1;
    for(int i=0;i<sz;i++){mid+=B[i];}
    mid/=sz;
    cul(mid,num,dis);
  }

  cout<<fixed<<setprecision(12)<<ans<<endl;

  return 0;
}



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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;

	if (s.size() == 1) { cout << s << endl;return 0; }

	ll ans = 0;
	rep(i, 1 << s.size()-1) {

		ll j = s[0]-'0', k = 0;

		rep(h, s.size() - 1) {

			if ((i / (int)pow(2, h)) % 2) {
				j = j * 10 + (s[h + 1] - '0');
			}
			else{
				k += j;
				j = s[h + 1] - '0';

			}
		}

		k += j;
		ans += k;
	}


	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	
	public static final int[][] move_dir= new int[][]{{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break; 
			}
			
			int[] x_pos = new int[N];
			int[] y_pos = new int[N];
			
			int x_min = 0, y_min = 0, x_max = 0, y_max = 0;
			
			for(int i = 1; i < N; i++){
				final int pos = sc.nextInt();
				final int d = sc.nextInt();
				
				x_pos[i] = x_pos[pos] + move_dir[d][0];
				y_pos[i] = y_pos[pos] + move_dir[d][1];
				
				x_min = Math.min(x_min, x_pos[i]);
				x_max = Math.max(x_max, x_pos[i]);
				y_min = Math.min(y_min, y_pos[i]);
				y_max = Math.max(y_max, y_pos[i]);
			}
			
			System.out.println((x_max - x_min + 1) + " " + (y_max - y_min + 1));
		}
		
		sc.close();
	}

}

Measured memory_bytes: 34800
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

#define N 8
int a[N],n;
void printQueen(int q[N]) {
	int i, j, b[N][N] = { 0 };
	for (i = 0; i < N; i++) b[i][q[i]]=1;
	for (i = 0; i < N; i++,puts(""))
		for (j = 0; j < N; j++) fprintf(stdout, "%c", b[i][j] == 1 ? 'Q' : '.');
}

void cheak(int queen[N])
{
	int i,cnt=0;
	for (i = 0; i < N; i++) 
		if (queen[i] == a[i])cnt++;
	if (cnt == n) printQueen(queen);
}

void changeBoard(int board[N][N], int i, int j, int d)
{
	int k;

	for (k = 0; k < N; k++) {
		board[i][k] += d;
		board[k][j] += d;
	}
	if (i > j) {
		for (k = 0; k < N - (i - j); k++) {
			board[k + (i - j)][k] += d; 
		}
	}
	else {
		for (k = 0; k < N - (j - i); k++) {
			board[k][k + (j - i)] += d;
		}
	}
	if (i + j < N) {
		for (k = 0; k <= i + j; k++) {
			board[i + j - k][k] += d;
		}
	}
	else {
		for (k = i + j - N + 1; k < N; k++) {
			board[i + j - k][k] += d;
		}
	}
}

void setQueen(int queen[N], int board[N][N], int i)
{
	int j;

	if (i == N) { 
		cheak(queen);
		return;
	}

	for (j = 0; j < N; j++) {
		if (board[i][j] == 0) {
			queen[i] = j;
			changeBoard(board, i, j, +1);
			setQueen(queen, board, i + 1);
			changeBoard(board, i, j, -1);
		}
	}
}

void findSolution()
{
	int queen[N];
	int board[N][N];

	memset(board, 0, sizeof(board));
	setQueen(queen, board, 0);
}
int main()
{
	int i=0, h,w;
	memset(a, -1, sizeof(a));
	fscanf(stdin, "%d", &n);
	while (i<n) fscanf(stdin, "%d%d", &h, &w), a[h] = w,i++;
	findSolution();
	return 0;
}

Measured memory_bytes: 592
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

n, m, r = map(int,input().split()) #n:頂点数　m:辺の数 r:訪れる町の数
R = list(map(int,input().split()))

d = np.array([[float("inf") for i in range(n)] for i in range(n)])
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    x, y, z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
wa = floyd_warshall(d)

# 訪れる町の順番を順列で用意
from itertools import permutations
ptn = permutations(R)

ans = 10**19
for p in ptn:
  cost = 0
  roots = [(j-1, i-1) for i, j in zip(p, p[1:])]
  for i, j in roots:
    cost += wa[i][j]
  ans = min(ans, cost)
  
print(int(ans))

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n;

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

	cin>>n;
	int m=n;
	int sum=0;
	while (n>0) {
		sum+=n%10;
		n/=10;
	}
	if(m%sum==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}


Measured memory_bytes: 3608
fn main() {
    let mut n = String::new();
    let mut s = String::new();
    std::io::stdin().read_line(&mut n).ok();
    std::io::stdin().read_line(&mut s).ok();
    let mut v: Vec<u32> =
        s.trim().split_whitespace().map(|n| n.parse().unwrap()).collect();
    let mut c = 0;
    loop {
        if v.iter().any(|n| n % 2 != 0) { break; }
        c += 1;
        v = v.iter().map(|n| n / 2).collect();
    }
    println!("{}", c);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,p,q,r;

int main(){
	while(scanf("%d",&n),n){
		scanf("%d",&m);
		scanf("%d%d%d",&p,&q,&r);
		vector<P> *z=new vector<P>;
		z->push_back(P(1,n));
		for(int i=0;i<m;i++){
			int x[3]={0,0,n};
			scanf("%d%d",&x[0],&x[1]);
			vector<P> *b=new vector<P>;
			vector<P> c[3]; int count=0,cx=1;
			int j=0;
			while(cx<=n)
				if(cx+(z->at(j).second)-(z->at(j).first)<=x[count]){ c[count].push_back(z->at(j)); cx+=(z->at(j).second)-(z->at(j).first)+1; j++;}
				else{ if(cx!=x[count]+1) c[count].push_back(P(z->at(j).first,z->at(j).first+x[count]-cx)); z->at(j).first+=x[count]-cx+1; cx=x[count]+1; count++;}
			for(j=2;j>=0;j--)
				for(int k=0;k<c[j].size();k++) b->push_back(c[j][k]);
			delete z;
			z=b;
		}
		int res=0,count=1;
		for(int i=0;i<z->size();i++){
			P pp=z->at(i); int c1=count+pp.second-pp.first;
			if(count>=p&&q>=c1) ;
			else if(count<=p&&p<=c1) pp.first+=p-count;
			else if(count<=q&&q<=c1) pp.second-=c1-q;
			else { count=c1+1; continue;}
			count=c1+1;
			if(r>=pp.second) res+=pp.second-pp.first+1;
			else if(r>=pp.first) res+=r-pp.first+1;
		}
		printf("%d\n",res);
	}
}

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

bool alph[26];
int main()
{
    string S, ans = "";
    cin >> S;
    int N = S.size();
    char c = S[0];
    for (int i = 0; i < N; i++)
    {
        int c1 = int(S[i] - 'a');
        alph[c1] = true;
    }
    if (N < 26)
    {
        rep(i, 26)
        {
            if (alph[i] == true)
                continue;
            else
            {
                ans = S + char(i + 'a');
                cout << ans << endl;
                return 0;
            }
        }
    }
    else
    {
        if (S == "zyxwvutsrqponmlkjihgfedcba")
        {
            cout << -1 << endl;
        }
        else
        {
            int i;
            for (i = 25; i > 0; i--)
            {
                alph[int(S[i] - 'a')] = false;
                if (S[i] > S[i - 1])
                    break;
            }
            //            cout << -1 << endl;
            rep(j, i - 1) cout << S[j];
            rep(k, 26)
            {
                if (alph[k] == false && S[i - 1] < char(k + 'a'))
                {
                    cout << char(k + 'a') << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
n = gets.to_i
e = gets.split.map(&:to_i)
n.times{ |i|
  puts e.join(" ")
  break if (i == (n-1))
  i.downto(0){ |j|
    e.insert(j,e.slice!(j+1)) if (e[j] > e[j+1])
  }
}

Measured memory_bytes: 8860
#include <stdio.h>
#include <string.h>

#define M 1000003

class Dict {
    int A[M];

  public:
    int h1(int x) {
        return x % M;
    }
    int h2(int x) {
        return h1(x);
    }
    int insert(int x) {
        int idx = h1(x);
        for (int i = 0; i < M; i++) {
            if (A[idx] == 0) {
                A[idx] = x;
                return idx;
            }
            idx += h2(x);
            idx %= M;
        }
        return -1;
    }
    int find(int x) {
        int idx = h1(x);
        for (int i = 0; i < M; i++) {
            if (A[idx] == 0) {
                break;
            }
            if (A[idx] == x) {
                return idx;
            }
            idx += h2(x);
            idx %= M;
        }
        return -1;
    }
};

int str2int(const char s[]) {
    int cnt = 0;
    for (int i = 0; i < strlen(s); i++) {
        cnt *= 4;
        if (s[i] == 'A') {
            cnt += 1;
        } else if (s[i] == 'C') {
            cnt += 2;
        } else if (s[i] == 'T') {
            cnt += 3;
        } else {
            cnt += 4;
        }
    }
    return cnt;
}

int main() {
    int n;
    char cmd[10], s[20];
    Dict D;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %s", cmd, s);
        int x = str2int(s);
        if (cmd[0] == 'i') {
            D.insert(x);
        } else {
            if (D.find(x) != -1) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 6456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			long n = long.Parse(Console.ReadLine());
			List<long> v = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
			long[] odd = new long[100001];
			long[] even = new long[100001];
			for (int i = 0; i < n; i+=2) {
				odd[v[i]]++;
				even[v[i + 1]]++;
			}

			var oo = odd.ToList();
			var ee = even.ToList();
			long maxo = oo.Max();
			long maxe = ee.Max();
			int indexo = oo.IndexOf(maxo);
			int indexe = ee.IndexOf(maxe);
			if (indexo == indexe) {
				oo.Sort();
				ee.Sort();
				if (oo[oo.Count - 2] > ee[oo.Count - 2]) {
					maxo = oo[oo.Count - 2];
				} else {
					maxe = ee[oo.Count - 2];
				}
			}

			long ans = n - maxo - maxe;
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 23776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int Mx = 0, mx = W, My = 0, my = H;
  vector<int> x(N), y(N), a(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> a.at(i);
    if (a.at(i) == 1) Mx = max(x.at(i), Mx);
    if (a.at(i) == 2) mx = min(x.at(i), mx);
    if (a.at(i) == 3) My = max(y.at(i), My);
    if (a.at(i) == 4) my = min(y.at(i), my);
  }
  
  int wide = max(0, mx - Mx), height = max(0, my - My);
  cout << wide * height << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n, k;
ll a[2002];
ll inv[2002];
const ll mod = 1e9 + 7;
int main()
{
        cin >> n >> k;
        ll ans = 0;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                inv[i] = 0;
                for(ll j=1;j<i;j++) {
                        if(a[j] > a[i]) inv[i]++;
                }
                inv[i] = (inv[i] * k)%mod;
                ans += inv[i];
                ans %= mod;
        }
        //return 0;
        ll yo = 0;
        for(ll i=1;i<=n;i++){
                for(ll j=1;j<=n;j++) {
                        if(a[j] > a[i]) yo++;
                }
                yo %= mod;
        }
        ll boss = (k*(k-1))/2;
        boss %= mod;
        //cout << "OK\n\n";
        if(k > 1){
                cout << ((boss * yo)%mod + ans)%mod << endl;
        }else cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  for (int i = 0; i * 7 <= n; i++) {
    if ((n - i * 7) % 4 == 0) {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin

X = list(map(int, (stdin.readline().strip().split())))[0]
count=0
while(True):
    num=0
    if X//500>=1:
        num=X//500
        X-=500*num
        count+=1000*num
        continue
    if X//5>=1:
        num=X//5
        X -= 5 * num
        count += 5*num
    else:break
print(count)

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

int main(void)
{
  
  int N ,M;
  cin >> N >> M;
  int A[N];
  long double V =0.0;
  for(int i=0; i<N;i++)
  {
    cin >>A[i];
    V += A[i];
  }
  
  std::sort(A, A+N, std::greater<>());
  
#if 0  
  for(int i=0; i<N;i++)
  {
    cout << A[i] << ' ';
  }  
  cout <<endl;
    cout << A[M-1];
  cout <<endl;
    cout << V/4/M;
#endif
      
  if(A[M-1] < V/(4*M))
  {
    cout << "No";
  }else{
    cout << "Yes";
  }
  
 return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int maxn=2e5+10;
int f[maxn];
int ans[maxn];
int a[maxn];
int sum[maxn];
int find1(int x)
{
    if(f[x]==x)
    {
        return x;
    }
    else
    {
        f[x]=find1(f[x]);
        return f[x];
    }

}
void add(int x,int y)
{
    int t1,t2;
    t1=find1(x);
    t2=find1(y);
    f[t2]=t1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        f[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        add(x,y);
        a[x]++;a[y]++;//x的直接朋友，y的直接朋友
    }
    for(int i=1;i<=n;i++)
    {

        sum[find1(i)]++; //find1改成f[i] 会WA
    }

    for(int i=1;i<=n;i++)
    {
        ans[i]=sum[f[i]]-1-a[i];
    }
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        if(f[x]==f[y])
        {
            ans[x]--;ans[y]--;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
            cout<<" ";
        cout<<ans[i];
    }
    cout<<'\n';







}


Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<list>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
using namespace std;
#define REP(i,m,n) for(int i = (m); i < (n);i++)
#define rep(i,n) REP(i,0,n)

class State {
public:
	vector<int> visited;
	int visitedCount;
	int current;
	
	State(int _n,int _start){
		visited.resize(_n,0);
		current = _start;
		visitedCount = 0;
	}
	void Visit(int _next) {
		visited[_next] = 1;
		visitedCount++;
	}
	bool OK() {
		return visitedCount == visited.size();
	}
};

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> graph;
	graph.resize(n*n,0);
	rep(i,m) {
		int from,to;
		cin >> from >> to;
		graph.at((from-1)*n+(to-1)) = 1;
		graph.at((to-1)*n+(from-1)) = 1;
	}
	int start = 0;
	int result = 0;
	stack<State> status;
	rep(i,n) {
		if(graph.at(start*n+i) != 1) continue;
		State st(n,i);
		st.Visit(0);
		st.Visit(i);
		status.push(st);
	}
	while(!status.empty()) {
		State cur = status.top(); status.pop();
		if(cur.OK()) {
			result++;
			continue;
		}
		rep(i,n) {
			if(!(graph.at(cur.current*n+i)==1 && cur.visited[i] != 1))continue;
			State ne = cur;
			ne.Visit(i);
			ne.current = i;
			status.push(ne);
		}
	}
	cout << result << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>

bool is_palindrome(const std::string& str) {
	for (auto i = 0; i < str.size(); ++i) {
		if (str[i] != str[str.size() - i - 1]) return false;
	}
	return true;
}
int main() {
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	std::string str; std::cin >> str;
	if (is_palindrome(str) && is_palindrome(str.substr(0, str.size() / 2)) && is_palindrome(str.substr(str.size() / 2 + 1))) {
		std::cout << "Yes\n";
	}
	else {
		std::cout << "No\n";
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(),x = sc.nextInt();
		int[] l = new int[n+1];
		for(int i = 1;i <= n;i++) {
			l[i] = sc.nextInt();
		}
		
		int value = 0,cnt = 1,d = 0;
		for(int i = 2;i <= n+1;i ++) {
			value = d + l[i-1];
			d = value;
			if(value > x) break;
			cnt++;
		}
		System.out.println(cnt);
	}
	
}

Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define in(n) cin>>n>>
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int a,b,c;
    
    cin >> a >> b >> c;
    
    if(a == b){
    
        cout << c << endl;
    }else if (b==c){
        
        cout << a << endl;
        
    }else{
        
        cout << b << endl;
        
    }
    
    
    

return 0;}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]
A.sort(reverse=True)

S = []
for _ in range(M):
  b, c = [int(x) for x in input().split()]
  S.append((c, b))

S.sort(reverse=True)

total = 0
count = 0

while count < N and len(S) > 0:
  if A[0] > S[0][0]:
    a = A.pop(0)
    total += a
    count += 1
  else:
    c = S.pop(0)
    if c[1] < N - count:
      total += c[0] * c[1]
      count += c[1]
    else:
      total += c[0] * (N - count)
      count = N
if len(S) == 0:
  total += sum(A[:N-count])
print(total)

Measured memory_bytes: 20912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

ll goch(ll a){
    for (ll i = 0; i*i*i*i*i <= a; i++) {
        if (i*i*i*i*i == a) {
            return i;
        }
    }
    return -1;
}


int main() {
    IN(int, n);
    IN(ll, k);
    vi a(n);
    cin >> a;
    vi tochaku;
    vi reached(n,-1);
    reached[0] = 0;
    int memo;
    tochaku.emplace_back(1);
    REPS(i, n){
        int now =a[tochaku[i-1]-1];
        if (reached[now-1] != -1) {
            memo = reached[now-1];
            break;
        }
        tochaku.emplace_back(now);
        reached[now-1] = i;
    }
    
    if (k<=memo) {
        COUT(tochaku[k]);
    }else{
        int aja = (k-memo) % (tochaku.size()-memo);
        COUT(tochaku[aja+memo]);
    }
}


Measured memory_bytes: 5828
def test():
    s = list(input())
    l = len(s)-1
    ans = 0

    for i in range(2**l):
        op = [""]*l
        for j in range(l):
            if (i>>j)&1:
                op[j] = "+"
        res = ""
        for n,k in zip(s,op+[""]):
            if len(k) == 1:
                res += n+k
            else:
                res += n + ""
        ans += eval(res)
    print(ans)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main(void){
	int i, j, k, n, x[100], y[100], z[100];
	double L1=0.0, L2=0.0, L3=0.0, Li=0.0;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%d", &x[i]);
	}
	for(i=0; i<n; i++){
		scanf("%d", &y[i]);
	}
	
	for(i=0; i<n; i++){
		L1 += abs(x[i]-y[i]);
		L2 += (x[i]-y[i])*(x[i]-y[i]);
		L3 += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
		z[i] = abs(x[i]-y[i]);
	}
	
	for(i=0; i<n; i++){
		if(z[i] >= Li) Li = z[i]*1.0;
	}
	
	L2 = sqrt(L2);
	L3 = pow(L3, 1.0 / 3.0);
	
	printf("%f\n%f\n%f\n%f\n", L1, L2, L3, Li);
	
return 0;
}

Measured memory_bytes: 676
import java.util.Scanner;

public class Main{
   public static void main(String[] a){
      Scanner scn = new Scanner(System.in);
      int d = scn.nextInt();
      int b = scn.nextInt();
      int c = scn.nextInt();
      if(c>b&&b>d){
         System.out.println("Yes");
      }else{
         System.out.println("No");
      }
   }
}

Measured memory_bytes: 26204
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def scorei(ti, i, last, minus):
        k = [i for i in last]
        mi = minus-(i+1-last[ti])*c[ti]
        v = s[i][ti]-mi
        mi += sum_
        k[ti] = i+1
        return v, k, mi

    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    t = []
    last = [0]*n
    for i in range(d):
        m = c[0]+(i+1-last[0])*s[i][0]
        argmax = 0
        for ti in range(1,n):
            k = c[ti]+(i+1-last[ti])*s[i][ti]
            if m < k:
                m = k
                argmax = ti
        t.append(argmax+1)
        last[argmax] = i+1
    v = score(t)
    i = 0
    while time.time() < 1.5+start:
        nt = [i for i in t]
        r = random.random()
        if r > 0.5:
            if nt[i] < n:
                nt[i] += 1
        else:
            if nt[i] > 1:
                nt[i] -= 1
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 84412
#include <stdio.h>

int main()
{
  int x[101] = {0};
  int n;
  int i = 0, max;

  while(scanf("%d", &n) != EOF)
    x[n]++;

  max = 0;

  for(i = 1; i < 101; i++) {
    if(max < x[i])
      max = x[i];
  }

  for(i = 1; i < 101; i++) {
    if(max == x[i])
      printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}

bool is_prime(int k, int i) {
    if(k == 2) return true;
    if(k <= i) return true;
    else {
        if(k % i == 0) return false;
        else return is_prime(k, i + 1);
    }
}


int main() {
    int a, p;
    cin >> a >> p;
    int sum = 3 * a + p;
    cout << sum /2 << endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
ll N,M,T;
ll POW[21],dp[21][1000],table[1000][2];
 
 
int main(){
    for(int i = 0; i < 21; i++)POW[i] = pow(2,i);
 
    for(int i = 0; i < 21; i++){
        for(int k = 0; k < 1000; k++)dp[i][k] = -1;
    }
 
    scanf("%lld %lld %lld",&N,&M,&T);
 
    ll tmp;
    for(int loop = 0; loop < N; loop++){
        scanf("%lld",&tmp);
        dp[0][tmp%T] = max(dp[0][tmp%T],tmp); //余り毎に最大値を求める
    }
 
    //ダブリング
    for(int i = 0; POW[i+1] <= M;i++){
        for(int a = 0; a < T; a++){
            if(dp[i][a] == -1)continue;
            for(int b = 0; b < T; b++){
                if(dp[i][b] == -1)continue;
                dp[i+1][(a+b)%T] = max(dp[i+1][(a+b)%T],dp[i][a]+dp[i][b]);
            }
        }
    }
 
    int CURRENT = 0,NEXT = 1;
    for(int i = 0; i < T; i++)table[i][CURRENT] = -1;
    ll rest = M;
 
    bool FIRST = true;
    //
    for(int i = 20; i >= 0; i--){
        if(rest < POW[i])continue;
        rest -= POW[i];
 
        if(FIRST){ //初めての場合
            for(int b = 0; b < T; b++){ //dpのループ
                if(dp[i][b] == -1)continue;
 
                table[b][CURRENT] = dp[i][b];
            }
            FIRST = false;
            continue;
        }
 
        for(int k = 0; k < T; k++){
            table[k][NEXT] = -1;
        }
 
        for(int a = 0; a < T; a++){
            if(table[a][CURRENT] == -1)continue;
            for(int b = 0; b < T; b++){
                if(dp[i][b] == -1)continue;
 
                table[(a+b)%T][NEXT] = max(table[(a+b)%T][NEXT],table[a][CURRENT]+dp[i][b]);
            }
        }
        swap(CURRENT,NEXT);
    }
 
    //右から左に情報を伝える
    for(int i = T-2; i >= 0; i--){
        table[i][CURRENT] = max(table[i+1][CURRENT],table[i][CURRENT]);
    }
 
    int Q;
    scanf("%d",&Q);
 
    ll A,B;
 
    for(int loop = 0; loop < Q; loop++){
        scanf("%lld %lld",&A,&B);
 
        if(table[A][CURRENT] != -1 && table[A][CURRENT]/T >= B){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
 
    return 0;
}


Measured memory_bytes: 3508
fun main(args:Array<String>){
  val (n,k) = readLine()!!.split(" ").map{it.toInt()}
  val rl = readLine()!!
  var happy = 0
  for(i in 1 until n){
    if(rl[i]==rl[i-1])happy++
  }
  println(Math.min(n-1,happy+2*k))
}

Measured memory_bytes: 37872
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    auto l = readln.chomp.split.map!(to!int).array;

    int a = l[0], b = l[1], x = l[2];

    for (int i = 0; i <= b; ++i) {
        if (a + i == x) {
            writeln("YES");
            return;
        }
    }

    writeln("NO");

    return;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S = to_string(N);
  int f = 0;
  for (int i = 0; i < S.size(); i++) f += S[i] - '0';
  cout << (N % f == 0 ? "Yes" : "No");
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n,r,q):
    if r==0:
        return 1

    return ((n*combination(n-1,r-1,q)%q)*modinv(r,q))%q

def _input():
    return list(map(int, input().split()))

def main():
    i=_input()
    x,y=i[0],i[1]
    if 2*y>=x and 2*x>=y and (2*y-x)%3==0 and (2*x-y)%3==0:
        n=(2*y-x)//3
        m=(2*x-y)//3
        print(int(combination(n+m,min(m,n),1000000007)))
    else:
        print(0)

if __name__ == "__main__":
    main()

Measured memory_bytes: 300148
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
using namespace std;

int main(){
    // あとで消す
    //std::ifstream in("cin4.txt");
    //std::cin.rdbuf(in.rdbuf());

    // N 桁数
    // M 条件の個数
    int N,M,si,ci;
    cin >> N >> M;

    vector<int> arr(N+1,-1);

    for(int i=0;i<M;i++){
        cin >> si >> ci;

        // 確定済みで被っていたらダメ
        if(arr[si]>=0 && arr[si]!=ci){
            cout << -1 <<endl;
            return 0;
        }
        arr[si]=ci;
    }

    // 先頭が0に確定してしまっているとき
    if(arr[1]==0){
        // 1桁指定ならOKだが、2桁3桁ならアウト
        if(N==1){
            cout << 0 << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    // 先頭が確定していないなら, 1桁のとき0,その他のとき1
    if(arr[1]<0){
        if(N==1){
            arr[1]=0;
        }else{
            arr[1]=1;
        }
    }

    for(int i=1;i<=N;i++){
        // 確定していないなら0で埋めてやる
        cout << (arr[i]<0? 0 : arr[i]) ;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	Sd, T := nextLine(), nextLine()
	S := "UNRESTORABLE"
	for i := 0; i <= len(Sd)-len(T); i++ {
		if Sd[i] == T[0] || Sd[i] == '?' {
			ok := true
			for j := 0; j < len(T); j++ {
				if Sd[i+j] != T[j] && Sd[i+j] != '?' {
					ok = false
					break
				}
			}
			if ok {
				S = Sd[:i] + T + Sd[i+len(T):]
			}
		}
	}
	S = strings.Replace(S, "?", "a", -1)
	fmt.Println(S)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll rem = N % (A + B);
    ll ans = A * (ll)(N / (A+B));
    ans += min(rem, A);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Monad
import Control.Applicative ((<$>))
import Data.Maybe (fromJust)
import qualified Data.Sequence as S
import Data.Sequence (ViewL(..), (|>), viewl)
import qualified Data.ByteString.Char8 as BC


type ProcessName = BC.ByteString

data Scheduler = Sch {
               _t :: Int, -- current time
               _q :: Int, -- quantum
               _que :: S.Seq (ProcessName, Int)
}

runScheduler :: Scheduler -> [(ProcessName, Int)]
runScheduler s@(Sch {..})
    | S.null _que = []
    | cPTime <= _q = (cPName, _t + cPTime)
                        : runScheduler (s{_que = re, _t = _t + cPTime})
    | otherwise = runScheduler (
            s{_que = re |> (cPName, cPTime- _q), _t = _t + _q}
            )
    where
        ((cPName, cPTime) :< re) = viewl _que

parseLine :: BC.ByteString -> (ProcessName,Int)
parseLine l = let (n:t:_) = BC.words l
                  in (n, fst . fromJust . BC.readInt $ t)

main = do
    (n:q:_) <- map read . words <$> getLine
    replicateM n (parseLine <$> BC.getLine) >>=
        mapM_ (\(s,t) -> BC.putStrLn . BC.unwords $ [s, BC.pack . show $ t])
        . runScheduler . Sch 0 q . S.fromList

Measured memory_bytes: 21608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author indy256
 */

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int n;
    in >> n;

    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        in >> a[i];
    }

    int mod = 1000'000'007;
    int res = 0;
    vector<int> bits(60);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 60; ++j) {
            int cnt = bits[j];
            if (a[i] & (1LL << j))
                cnt = i - cnt;
            res = (res + (1LL << j) % mod * cnt) % mod;
        }

        for (int j = 0; j < 60; ++j)
            if (a[i] & (1LL << j))
                ++bits[j];
    }

    out << res << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


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

#define REP(n) for (int i = 0; i < n; i++)

int main()
{
    int n, m, sum = 0;
    cin >> n >> m;
    REP(m)
    {
        int t;
        cin >> t;
        sum += t;
    }

    if (sum > n)
    {
        cout << "-1";
    }
    else
    {
        cout << n - sum;
    }

    return 0;
}

Measured memory_bytes: 3624
import sys

sys.setrecursionlimit(110000)


def inpl():
    return list(map(int, input().split()))


class UnionFind:
    def __init__(self, N):
        # par = parent
        self.par = [i for i in range(N)]
        self.N = N
        self.hop = {i: -1 for i in range(N)}
        self.adj = [[] for i in range(N)]
        return

    def root(self, x):
        if self.par[x] == x:
            return (x)
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self, x, y):
        return (self.root(x) == self.root(y))

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return False

        self.par[x] = min(x, y)
        self.par[y] = min(x, y)
        return True

    def find_root(self):
        for i in range(self.N):
            if i == self.root(i):
                return i
        return

    def dfs(self, i):
        for nh in self.adj[i]:
            if self.hop[nh] != -1:
                continue
            else:
                self.hop[nh] = self.hop[i] + 1
                self.dfs(nh)
        return


N = int(input())
uf = UnionFind(N)
AB = [[0, 0] for i in range(N - 1)]

for i in range(N - 1):
    a, b = inpl()
    a -= 1
    b -= 1
    AB[i][0] = a
    AB[i][1] = b
    uf.adj[a].append(b)
    uf.adj[b].append(a)

C = inpl()

for a, b in AB:
    uf.union(a, b)

root_num = uf.find_root()
uf.hop[root_num] = 0
uf.dfs(root_num)

dic2 = sorted(uf.hop.items(), key=lambda x: x[1], reverse=True)

ans = [0 for i in range(N)]
for i, k in enumerate(dic2):
    ans[k[0]] = i

C.sort()

print(sum(C[:-1]))
for i in range(N):
    if i != 0:
        print(" ", end="")
    print(C[ans[i]], end="")
print("")


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

int main(){
	int n,k;
  	cin>>n>>k;
  	int now = 1;
  	for(int i =0;i<n;i++){
    	if (2*now > now+k)
          now = now+k;
		else
          now = now *2;
      	
    }
  	cout<<now<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 200;

int N;
int a[MAX_N], b[MAX_N];

void solve()
{
	memset(a, 0x3f, sizeof(a));
	for(int i=0;i<N-1;++i){
		a[i]=min(a[i],b[i]);
		a[i+1]=min(a[i+1], b[i]);
	}
	int ans = 0;
	for(int i=0;i<N;++i) ans+=a[i];
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N-1;++i)cin >> b[i];
	solve();
	return 0;
}


Measured memory_bytes: 256