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

using namespace std;

constexpr int MX = 1005;
constexpr int MXDIV = 10005;
bool white[MX][MX];
int accum[MX][MX];

int getNum(int xs, int ys, int xe, int ye){
  int sub1 = (xs == 0) ? 0 : accum[ye][xs-1];
  int sub2 = (ys == 0) ? 0 : accum[ys-1][xe];
  int add1 = (xs == 0 || ys == 0) ? 0 : accum[ys-1][xs-1];
  return accum[ye][xe] - sub1 - sub2 + add1; 
}

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  
  for(int i=0; i<H; i++){
    string s;
    cin >> s;
    for(int j=0; j<W; j++) white[i][j] = (s[j] == '1');
  }
  
  for(int i=0; i<H; i++){
    int sum = 0;
    for(int j=0; j<W; j++){
	  if(white[i][j]) ++sum;
      int addi = (i == 0) ? 0 : i-1;
      accum[i][j] = accum[addi][j] + sum;
    }
  }
  
  int count = MXDIV;
  int i, x, y;
  for(i=0; i<(1<<(H-1)); i++){
	vector<int> divPos;
	for(int j=0; j<H-1; j++){
      if (i & (1 << j)) divPos.emplace_back(j);
    }
    
    int lineNumX = 0;
    int posX     = -1;
    for(x=0; x<W; x++){
      int xs = posX+1;
      int xe = x;
      for(y=0; y<=divPos.size(); y++){
        int ys = (y == 0) ? 0 : divPos[y-1]+1;
        int ye = (y == divPos.size()) ? H-1 : divPos[y];
        int num = getNum(xs, ys, xe, ye);
        if (num > K) break;
      }
      
      if(y != divPos.size()+1){
		if(posX == x-1) {
		    break;
		}
        posX = xe-1;
        ++lineNumX;
        --x;
      }
    }
    
    if(x != W) continue;
    
    count = min(count, lineNumX+(int)divPos.size());
  }
  
  cout << count;
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
using namespace std;
int main(void){
  long N;
  cin >> N;
  long m[5]={};
  for(int i=0;i<N;i++){
      string c;
      cin >> c;
      switch(c[0]) {
        case 'M': m[0]++; break;
        case 'A': m[1]++; break;
        case 'R': m[2]++; break;
        case 'C': m[3]++; break;
        case 'H': m[4]++; break;
      }
  }
  long res=0;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
        for(int k=j+1;k<5;k++){
            res += m[i]*m[j]*m[k];
        }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

#define int64_t ll
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int j=1;j<=n;++j){
  ll num=j;
  for(int64_t i = 2; i * i <= num; i++) {
    while(num % i == 0) {
      ret[i]++;
      num /= i;
    }
  }
  if(num != 1) ret[num]++;
  }
  return ret;
}

//ここから
void solve(){
  int n;
  cin>>n;
  map<ll,int>mp=prime_factor(n);
  ll a=0,b=0,c=0,d=0,e=0;
  for(auto x:mp){
    if(x.second>=2)++a;
    if(x.second>=4)++b;
    if(x.second>=14)++c;
    if(x.second>=24)++d;
    if(x.second>=74)++e;
  }
  ll ans=(b*(b-1))/2*(a-2);//3*5*5
  ans+=c*(b-1);//15*5
  ans+=d*(a-1);//25*3
  ans+=e;//75
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	//cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<double> p(N);
    REP(i, N) cin >> p.at(i);

    double sum = 0.0;
    REP(i, K) sum += (p[i] + 1.0) / 2.0;

    double ans = sum;
    REP(i, N - K) {
        sum -= (p[i] + 1.0) / 2.0;
        sum += (p[i + K] + 1.0) / 2.0;
        chmax(ans, sum);
    }

    cout << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 200010;
const int mod = 1e9 + 7;

int n;
vector <int> adjlist[maxn];
int fac[maxn];
map <int,int> mp;
int dp[maxn],sz[maxn],ans[maxn];

int expo(int x, int exp) {
	int res = 1, base = x;
	while (exp) {
		if (exp & 1) res = (res * base) % mod;
		base = (base*base) % mod;
		exp >>= 1;
	}
	return res;
}

int inv(int x) {
	if (mp.find(x) != mp.end()) return mp[x];
	else return mp[x] = expo(x,mod-2);
}


int choose(int N, int k) {
	return fac[N] * inv(fac[k]*fac[N - k] % mod) % mod;
}

void dfsf(int x, int p) {
	sz[x] = dp[x] = 1;
	for (auto i : adjlist[x]) {
		if (i == p) continue;
		dfsf(i,x);
		sz[x] += sz[i];
		dp[x] *= dp[i] * choose(sz[x]-1,sz[i]) % mod;
		dp[x] %= mod;
		//cout << sz[x] << " " << sz[i] << "\n";
		//cout << choose(sz[x] -1, sz[i]) << "\n";
		//cout << i << " " << dp[x] << "\n";
	}
}

void reroot(int x, int p) {
	for (auto i: adjlist[x]) {
		if (i == p) continue;
		ans[i] = ans[x] * inv(dp[i] * choose(n-1,sz[i]) % mod) % mod * choose(n-1,n - sz[i]) % mod;
		ans[i] *= dp[i];
		ans[i] %= mod;
		reroot(i,x);
	}
}

int32_t main() {
	//FAST
	cin >> n;
	for (int i =0;i<n-1;i++) {
		int a,b; cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	
	fac[0] = 1;
	for (int i =1;i<maxn;i++) {
		fac[i] = fac[i-1] * i % mod;
	}
	
	dfsf(1,-1);
	ans[1] = dp[1];
	reroot(1,-1);
	
	for (int i =1;i<=n;i++) cout << ans[i] << "\n";
	
}









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

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=1e5+10,P=1e9+7;

char s[4],p[4];



int n;


int main(){
	n=rd();
	ll ans=1ll*n*(n-1)/2;
	cout<<ans<<endl;
}








Measured memory_bytes: 256
package main
import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  flag := 1
  
  l := make([]int, n)
  for i:=0; i<n; i++ {
    fmt.Scan(&l[i])
  }
  
  var temp int
  for i:=0; i<n; i++ {
    if l[i] != i+1 {
      for j:=0; j<n; j++ {
        if l[j] == i+1 {
          temp = l[i]
          l[i] = l[j]
          l[j] = temp
        }
      }
      break
    }
  }
  for i:=0; i<n; i++ {
    if l[i] != i+1 {
      flag = 0
    }
  }
  if flag == 1 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, A, B;

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

  cin >> N >> A >> B;

  cout << min(A, B) << ' ' << max(0, A+B-N) << endl;
  return 0;
}


Measured memory_bytes: 888
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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 long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];





int main(){
  int a,b;
  cin>>a>>b;
  if(a>=10){
      cout<<b<<endl;
  }
  else{
      cout<<b+100*(10-a)<<endl;
  }
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	vector<int> nPrimes;
	vector<bool> isPrime;
	vector<int> inputs;
	int maxN, sqrtMax, n;

	maxN = 0;
	while(scanf("%d", &n) != EOF) {
		if(n > maxN)	maxN = n;
		inputs.push_back(n);
	}

	sqrtMax = sqrt(maxN-1) + 1;

	isPrime.resize(maxN, true);
	nPrimes.resize(maxN, 0);

	isPrime[0] = false;

	for(int i=2; i<=sqrtMax; ++i) {
		if(isPrime[i-1] == false)	continue;
		for(int j=2*i; j<=maxN; j+=i) {
			isPrime[j-1] = false;
		}
	}
	for(int i=1; i<maxN; ++i) {
		if(isPrime[i])	nPrimes[i] = nPrimes[i-1] + 1;
		else	nPrimes[i] = nPrimes[i-1];
	}

	for(auto it=inputs.begin(); it!=inputs.end(); ++it) {
		printf("%d\n", nPrimes[(*it)-1]);
	}
}

Measured memory_bytes: 6296
g = []

for i in range(3):
    g.append(list(map(int, input().split())))

for i in range(1,3):
    offset = g[i][0] - g[0][0]
    if not ((g[i][1] - g[0][1] == offset) and (g[i][2] - g[0][2] == offset)):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
	ll n;
	cin>>n;
	if(n%2==1) cout<<0;
	else{
		ll c=0;
		n/=2;
		while(n>0){
			c+=n/5;
			n/=5;
		}
		cout<<c<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
int T,n,m;
ll a[maxn];
int gcd(int a,int b)
{
    return b>0?gcd(b,a%b):a;
}
int main() {
	ll x,y,z,w;
	cin>>x>>y>>z>>w;
	ll sum = z+w;
	z = max(z,w);
	w = sum-z;
	ll t = z*w/gcd(z,w);
	ll x1 = x/z,x2=x/w,x3=x/t;
	ll y1 = y/z,y2=y/w,y3=y/t;
	if(x%z==0)
		x1--;
	if(x%w==0)
		x2--;
	if(x%t==0)
		x3--;
	cout<<y-x+1-(y1-x1)-(y2-x2)+(y3-x3)<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
line = input()

R_ = line.count("R")
W_ = line.count("W")

final_line = "R" * R_ + "W" * W_

dic = {"W":0, "R":0}

for idx, c in enumerate(line):
    if c != final_line[idx]:
        dic[c] += 1
        
print(max(dic.values()))

Measured memory_bytes: 9552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(snip_i, n) cin >> a.at(snip_i);
  int ans = 0;
  while(1){
    n -= k;
    if(ans == 0)k--;
    ans++;
    if(n <= 0) break;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int inf = (int) (1e9);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> res(n);
  vector<vector<int>> distf(n, vector<int>(n, inf));
  for(int i = 0; i < n; ++i) {
    minpq<pair<int, int>> Q;
    vector<int> dist(n);
    fill(dist.begin(), dist.end(), inf);
    Q.push({0, i});
    dist[i] = 0;
    while(!Q.empty()) {
      int u = Q.top().second;
      int c = Q.top().first;
      Q.pop();
      if(dist[u] < c) {
        continue;
      }
      if(u + 1 < n) {
        if(dist[u + 1] > dist[u] + 1) {
          dist[u + 1] = dist[u] + 1;
          Q.push({dist[u + 1], u + 1});
        }
      }
      if(u - 1 >= 0) {
        if(dist[u - 1] > dist[u] + 1) {
          dist[u - 1] = dist[u] + 1;
          Q.push({dist[u - 1], u - 1});
        }
      }
      if(u == x) {
        if(dist[y] > dist[u] + 1) {
          dist[y] = dist[u] + 1;
          Q.push({dist[y], y});
        }
      }
      if(u == y) {
        if(dist[x] > dist[u] + 1) {
          dist[x] = dist[u] + 1;
          Q.push({dist[x], x});
        }
      }
    }
    for(int j = 0; j < n; ++j) {
      distf[i][j] = min(distf[i][j], dist[j]);
      distf[j][i] = distf[i][j];
    }
  }
  int f = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      res[distf[i][j]]++;
    }
  }
  for(int ex: res) {
    if(f) cout << ex << '\n';
    f = 1;
  }
  return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define ll long long
const ll MAX=1e2+10;
const ll modn=1e9+7;
using namespace std;


void solve() {
    int n,m;
    int ji=0;
    cin>>n>>m;
    while(n--){
        int a,b;
        cin>>a>>b;
        if(sqrt(1.0*a*a+1.0*b*b)<=m){
            ji++;
        }
    }
    cout<<ji;


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

Measured memory_bytes: 3648
#include <stdio.h>

int len(char a[]){
	int i=0;
	while(a[i]!='\0') i++;
	return i;
}

int max(int a,int b){
	if(a>b) return a;
	else return b;
}

int main(void) {
	char s[3010], t[3010];
	scanf("%s%s",s,t);
	int H = len(s);
	int W = len(t);
	int dp[H+1][W+1];
	for(int i=0;i<H+1;i++){ 
	for(int j=0;j<W+1;j++){
		dp[i][j] = 0;
	}
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1;
			else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
		}
	}
	/*for(int i=0;i<H+1;i++){
		for(int j=0;j<W+1;j++){
			printf(" %3d",dp[i][j]);
		}
		printf("\n");
	}*/
	//printf("%d",dp[H][W]);
	
	int X = H, Y = W;
	char ans[3010];
	for(int i=0;i<3010;i++) ans[i] = '\0';
	while(dp[X][Y]!=0){
		while(X!=0&&dp[X][Y]==dp[X-1][Y]) X--;
		while(Y!=0&&dp[X][Y]==dp[X][Y-1]) Y--;
		X--; Y--;
		ans[len(ans)] = s[X];
	}
	char ANS[3010];
	for(int i=0;i<3010;i++) ANS[i] = '\0';
	for(int i=0;i<len(ans);i++){
		ANS[i] = ans[dp[H][W]-i-1];
	}
	printf("%s",ANS);
	return 0;
}

Measured memory_bytes: 35328
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

int direction[90];
bool change[90];


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

    vector<long long> stock_price(N+1);
    for(int i=1; i<=N; ++i){
        cin >> stock_price[i];
    }

    long long money = 1000;

    for(int i=2; i<=N; ++i){
        if(stock_price[i-1] < stock_price[i]){
            long long amari = money%stock_price[i-1];
            money += abs(stock_price[i-1] - stock_price[i]) * (money / stock_price[i-1]);
            // money += amari;
        }
    }
    cout << money << endl;
}


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		
		String next = "";
		if(s.equals("Sunny")) next = "Cloudy";
		else
		if(s.equals("Cloudy")) next = "Rainy";
		else
		if(s.equals("Rainy")) next = "Sunny";
		
		System.out.println(next);		
		in.close();
	}
}

Measured memory_bytes: 20048
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}

void solve()
{
	string s, t;
	cin >> s >> t;
	if(s.find(t) != string::npos){
		rep(i, sz(s)) if(s[i] == '?') s[i] = 'a';
		cotu << s;
		return;
	}
	for(int i = sz(s) - sz(t); i >= 0; --i){
		string p = s.substr(i, sz(t));
		bool bad = 0;
		for(int j = 0; j < sz(p); ++j){
			if(t[j] != p[j] && p[j] != '?') bad = 1;
		}
		if(bad) continue;
		else{
			for(int j = 0; j < sz(s); ++j){
				if(j >= i && j <= i + sz(t) - 1) s[j] = t[j - i];
				else if(s[j] == '?') s[j] = 'a';
				cout << s[j];
			}
			return;
		}
	}
	cout << "UNRESTORABLE";
} 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3632
function Main(input) {
  var N = parseInt(input[0], 10);
  var A = input.slice(1).map(a => parseInt(a, 10));
  var orgA = A.map(a => a);

  var sortedA = A.sort((a, b) => b - a);

  for (var i = 0; i < N; i++) {
    if (orgA[i] === sortedA[0]) {
      console.log(sortedA[1]);
    } else {
      console.log(sortedA[0]);
    }
  }

}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 62064
#![allow(non_snake_case)]

#[allow(unused_macros)]
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)*} };}
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        x: usize,
        y: usize,
    }

    println!("{}", x + y / 2);
}

Measured memory_bytes: 4352
using System;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] s = Console.ReadLine().Split(' ');
		int[] n = new int[N];
		for(int i = 0; i < N; i++)
		{
			n[i] = int.Parse(s[i]);
		}

		int sum1 = 0;
		int sum2 = 0;

		Array.Sort(n);
		Array.Reverse(n);

		for (int i = 0; i < N; i++)
		{
			if (i % 2 == 0) sum1 += n[i];
			else sum2 += n[i];
		}

		Console.WriteLine(sum1 - sum2);
	}
}

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

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

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<char> > map(h+2, vector<char>(w+2, '.'));
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			cin >> map[i][j];
		}
	}
	
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(map[i][j] == '#'){
				cout << "#";
				continue;
			}
			int count = 0;
			for(int k=0; k<8; k++){
				if(map[i+dy[k]][j+dx[k]] == '#'){
					count++;
				}
			}
			cout << count;
		}
		cout << endl;
	}
			
	return 0;
}

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


int main(){
  int n;
  int mx = 0;
  double a = 0;
  cin >> n;

  vector<double> v(n);

  rep(i,n){
    cin >> v[i];
  }
  sort(v.begin(),v.end());

  rep(i,n-1){
    v[i+1] = (double)(v[i] + v[i+1])/2;
  }

  cout << fixed;
  cout << setprecision(6) << v[n-1] << endl;


  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
all_w = s.count('W')
all_e = s.count('E')
left_w = 0
right_e = all_e
ans = left_w + right_e
for i in range(n):
    if s[i] == 'E':
        right_e -= 1
    ans = min(ans, left_w + right_e)
    if s[i] == 'W':
        left_w += 1
print(ans)

Measured memory_bytes: 3668
N,x=gets.split.map(&:to_i)
if x==1 || x==2*N-1
    puts "No"
else
    puts "Yes"
    buffer=(1..(x-2)).to_a+((x+2)..(2*N-1)).to_a
    puts buffer[0...(N-2)]+[x+1,x,x-1]+buffer[(N-2)...(2*N-3)]
end

Measured memory_bytes: 7292
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Placing Marbles
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int cnt = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '1') cnt++;
  printf("%d\n", cnt);
  return 0;
}


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

int main()
{
    int A, B;
    int tmp;
    int remaind;
    int sum = 0;

    cin >> A >> B;

    for (int i = A; i <= B; i++){
            tmp = i;
            int reverse = 0;
            while (tmp != 0){
                remaind = tmp % 10;
            
                reverse = reverse * 10 + remaind;
            
                tmp /= 10;
            }
            if (reverse == i){
                sum++;
            }
    }
    cout << sum << endl;
    return (0);
}


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

int n, a[100010], ans = 0;
bool b[100010];

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

Measured memory_bytes: 768
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
arr = inputs[1].sort

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p arr
end

costs = []
for i in 0..arr.length-2 do
  costs << arr[i+1] - arr[i]
end

costs.sort!

pd costs

val = 0
(costs.length - nn + 1).times do |j|
  val += costs[j]
end

puts val


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

int main()
{
    ll sum = 0;
    ll a, b, x; cin>>a>>b>>x;
    if(a == 0) cout << b/x + 1 << endl;
    else cout << b/x - (a-1) / x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  int a,b;
  cin >> a >> b;
  int cnt=0;
  int x=1;
  while(x < b){
    x=x-1+a;
	++cnt;  
  }
  OUT(cnt);
}

Measured memory_bytes: 256
let mcm p n =
  let m = Array.make_matrix (n + 1) (n + 1) max_int in
  let rec init i =
    if i <= n then begin
      m.(i).(i) <- 0;
      init (i + 1)
    end in
  init 1;
  let rec doit = function
    | (l, _) when l > n -> m.(1).(n)
    | (l, i) when i > n - l + 1 -> doit (l + 1, 1)
    | (l, i) ->
      let j = i + l - 1 in
      let rec aux k =
        if k < j then begin
          m.(i).(j) <- min m.(i).(j) (m.(i).(k) + m.(k+1).(j) + p.(i-1)*p.(k)*p.(j));
          aux (k + 1)
        end in
      aux i;
      doit (l, i + 1) in
  doit (2, 1)


let () =
  let n = read_int () in
  let p = Array.make (n + 1) 0 in
  let rec read i =
    if i < n then begin
      let (r, c) = Scanf.scanf "%d %d\n" (fun r c -> (r, c)) in
      p.(i) <- r; p.(i+1) <- c;
      read (i + 1)
    end in
  read 0;
  Printf.printf "%d\n" (mcm p n)

Measured memory_bytes: 2652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int d,g; cin >> d >> g;
  vi p(d),c(d);
  rep(i,d) cin >> p[i] >> c[i];
  
  int ans = INF;
  
  rep(i,1 << d){
    int tans = 0;
    int now_score = 0;
    rep(j,d){
      if(i &(1 << j)){
        tans += p[j];
        now_score += 100*(j+1)*p[j] + c[j];
      }
      int now_pos = d-1;
      while(1){
        if(i &(1 << now_pos)){now_pos--; continue;}
        rep(k,p[now_pos]){
          if(now_score + k*(now_pos+1)*100 >= g)
            ans = min(ans,k + tans);
        }
        break;
      }
      if(now_score >= g)
        ans = min(ans,tans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Weight
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			List<Integer> l = new ArrayList<Integer>();
			for(int i=0;i<10;i++){
				if((a&1<<i)!=0)l.add(1<<i);
			}
			boolean h = true;
			for(int i:l){
				if(!h)System.out.print(" ");
				h = false;
				System.out.print(i);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
loop do
arr = gets.split.map(&:to_i)
h = arr[0]
w = arr[1]
if h != 0 || w != 0 then

for j in 1..(w-1)
print "#"
end

puts "#"

for i in 2..(h-1)
print "#"
for j in 2..(w-1)
print "."
end
puts "#"
end

for j in 1..(w-1)
print "#"
end

puts "#"
puts ""


else
exit

end

end


Measured memory_bytes: 6876
#include <iostream>
#include <map>

using namespace std;

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

int main(){
  
  while (1){
    int w, h;
    char mp[20][30];
    const int diff[] = {1, 0, -1, 0, 1, 1, -1, -1, 1};
    map<string, int> spells;
    string input, ans="";
    
    cin >> h >> w;
    if (w==0 && h==0){
      break;
    }
    
    REP(j, h){
      cin >> input;
      REP(k, w){
        mp[j][k] = input[k];
      }
    }
    
    REP(j0, h){
      REP(k0, w){
        REP(i,8){
//          printf("(%d, %d) i=%d\n", j0, k0, i);
          string str = "";
          int j=j0, k=k0;
          while(1){
//            printf("(%d, %d)\n", j, k);
            str += mp[j][k];
            spells[str]++;
            if (spells[str]>1){
              if (ans.length() < str.length() || (ans.length()==str.length() && ans > str)){
                ans = str;
              }
            }
            j = (j+diff[i]+h)%h;
            k = (k+diff[i+1]+w)%w;
            if (j==j0 && k==k0){
              break;
            }
          }
//          cout << str << endl;
        
        }
      }
    }
    
    if (ans.length()<2){
      cout << 0 << endl;
    }else{
      cout << ans << endl;
    }
    
    
  }
}


Measured memory_bytes: 37836
#include<stdio.h>

int main(){
  int a[5];
  int i;

  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<5;i++){
    int j;
    for(j=0;j<4-i;j++){
      if(a[j]<a[j+1]){
	int tmp=a[j];
	a[j]=a[j+1];
	a[j+1]=tmp;
      }
    }
  }

  for(i=0;i<5;i++){
    printf("%d",a[i]);
    if(i==4){
      printf("\n");
    }
    else{
      printf(" ");
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>

using namespace std;

int main() {

	int n;
	cin >> n;

	string a, b, c;
	cin >> a >> b >> c;

	int ans = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && a[i] == c[i]) {

		}
		else if (a[i] == b[i]) {
			ans++;
		}
		else if (a[i] == c[i]) {
			ans++;
		}
		else if (b[i] == c[i]) {
			ans++;
		}
		else {
			ans += 2;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int a;
	cin >> a;
  	if(a%2==0){
		cout << a << endl;
    }else{
		cout << 2*a << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<pii> vp;
vector<int> vu, vd;
vector<bool> used;
signed main(){
    int n;
    cin >> n;
    used.resize(n);
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        vp.pb({a, b});
    }
    vu.resize(n);iota(all(vu), 0);
    vd.resize(n);iota(all(vd), 0);
    sort(all(vu), [](int a, int b){ return vp[a].ff > vp[b].ff; });
    sort(all(vd), [](int a, int b){ return vp[a].ss < vp[b].ss; });
    lld ans1 = 0, ans2 = 0;
    int curpos = 0, vui = 0, vdi = 0;
    for(int i = 0; i < n; i++){
        auto& v = i%2?vu:vd;
        auto& vi = i%2?vui:vdi;
        while(used[v[vi]])vi++;
        used[v[vi]] = true;
        if(curpos < vp[v[vi]].ff){
            ans1 += vp[v[vi]].ff - curpos;
            curpos = vp[v[vi]].ff;
        }
        else if(curpos > vp[v[vi]].ss){
            ans1 += curpos - vp[v[vi]].ss;
            curpos = vp[v[vi]].ss;
        }
    }
    ans1+= abs(curpos);
    curpos = 0, vdi = 0, vui = 0;
    for(int i = 0; i < n; i++){
        auto& v = i%2?vd:vu;
        auto& vi = i%2?vdi:vui;
        while(!used[v[vi]])vi++;
        used[v[vi]] = false;
        if(curpos < vp[v[vi]].ff){
            ans2 += vp[v[vi]].ff - curpos;
            curpos = vp[v[vi]].ff;
        }
        else if(curpos > vp[v[vi]].ss){
            ans2 += curpos - vp[v[vi]].ss;
            curpos = vp[v[vi]].ss;
        }
    }
    ans2+= abs(curpos);
    cout << max(ans1, ans2) << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[1005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    ll ans = 0;
    REP(i, K) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n, a[202020];
i64 d[202020];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		d[i+1] = d[i]+a[i];
	}
	sort(d,d+n+1);
	d[n+1] = LINF;
	
	i64 cnt = 0;
	for(i64 i = 0; i < n; i++){
		i64 pos = upper_bound(d,d+n+2, d[i])-d-1;
		cnt += (pos-i)*(pos-i+1)/2;
		i = pos;
	}
	cout << cnt << endl;
}

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


Measured memory_bytes: 3456
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	long long N,ans=0; cin >> N;
	if(N%2==0) {
		N /= 2;
		while (N) {
			ans += N / 5;
			N /= 5;
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int p[100002], sz[100002];
vector<int> g1[100002], g2[100002];
int root(int a){
    return p[a] == a?a:(p[a]=root(p[a]));
}
void merge(int a, int b){
    a = root(a), b = root(b);
    if(a != b){
        p[a] = b;
        sz[b] += sz[a];
    }
}
int main(){
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    for(int i=1;i<=n;i++) p[i] = i, sz[i] = 1;
    for(int i=1;i<=m;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        merge(a, b);
        g1[a].emplace_back(b);
        g1[b].emplace_back(a);
    }

    for(int i=1;i<=k;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g2[a].emplace_back(b);
        g2[b].emplace_back(a);
    }

    for(int i=1;i<=n;i++){
        int r = root(i);
        long long ans = (sz[r]-1);

        set<int> cnt;
        for(int j=0;j<g1[i].size();j++){
            cnt.insert(g1[i][j]);
        }
        for(int j=0;j<g2[i].size();j++){
            if(root(g2[i][j]) == root(i)) cnt.insert(g2[i][j]);
        }

        ans -= cnt.size();

        printf("%lld ", ans);
    }
}

Measured memory_bytes: 17912
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;

int main() {

	int n;
	cin >> n;
	int two_cnt = 0;
	int ans = 1;

	for (int i = 1; i < n + 1; i++) {
		int num = i;
		int cnt = 0;
		while (num % 2 == 0) {
			num = num / 2;
			cnt++;
		}
		if (cnt > two_cnt) {
			two_cnt = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
	
	return 0;
	
}



Measured memory_bytes: 256
a = input()

oomozi = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
komozi = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

if a in oomozi:
    print("A")
elif a in komozi:
    print("a")

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

using namespace std;

# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPD(i, a, b) for(int i = a; i >= b; -- i)

const int N = 3e5 + 3, INF = 1e9;

# define gc getchar
inline int rd() {
	char ch = gc(); int ret = 0, sgn = 1;
	while(ch < '0' || ch > '9') { 
		if(ch == '-') sgn = -1;
		ch = gc();
	}
	while(ch >= '0' && ch <= '9') 
		ret = ret * 10 + ch - '0', ch = gc();
	return ret * sgn;
}

struct node {
	int tg, mx;
} tr[N << 2];

# define pii pair<int, int>
# define fir first
# define sec second
# define mkp make_pair

int n, w, h, ans, m;
pii su[N], sd[N];
pii a[N];

# define u tr[x]
# define ls (x << 1)
# define rs (x << 1 | 1)
# define urs tr[rs]
# define uls tr[ls]

inline void modi(int ql, int qr, int v, int x = 1, int l = 0, int r = m) {
	if(qr < ql) return ;
	// printf("[%d %d] %d %d\n", l, r, ql, qr); 
	if(ql <= l && qr >= r) {
		if(u.mx == -INF) u.mx = 0;
		u.tg += v, u.mx += v;
		return ;
	}
	int mid = l + r >> 1;
	if(ql <= mid) modi(ql, qr, v, ls, l, mid);
	if(qr > mid) modi(ql, qr, v, rs, mid + 1, r);
	u.mx = max(uls.mx, urs.mx) + u.tg;
}

void build(int x, int l, int r) {
	u.mx = -INF, u.tg = 0;
	if(l == r) return ;
	int mid = l + r >> 1;
	build(ls, l, mid), build(rs, mid + 1, r);
}

# undef u 
# undef ls 
# undef rs 
# undef urs 
# undef uls 

int dis[N], au[N], ad[N];
void solve() {
	REP(i, 1, n) dis[i] = a[i].fir;
	dis[n + 1] = w;
	sort(dis, dis + n + 2);
	m = unique(dis, dis + n + 2) - dis - 1;
	build(1, 0, m);
	// cout << m << " ?? " << endl;
	REP(i, 0, m) ad[i] = 0, au[i] = h;
	REP(i, 1, n) {
		a[i].fir = lower_bound(dis, dis + m + 1, a[i].fir) - dis;
		if(a[i].sec <= h / 2)
			ad[a[i].fir] = max(a[i].sec, ad[a[i].fir]);
		else au[a[i].fir] = min(a[i].sec, au[a[i].fir]);
	}

	int tu = 0, td = 0;
	modi(0, 0, h);
	REP(i, 1, m) {
		// modi(i - 1, i - 1, h);
		ans = max(ans, tr[1].mx + dis[i]);
		
		modi(su[tu].fir, i - 1, au[i] - h);
		while(tu && su[tu].sec >= au[i]) {
			modi(su[tu - 1].fir, su[tu].fir - 1, au[i] - su[tu].sec);
			-- tu;
		}
		su[++ tu] = mkp(i, au[i]);

		modi(sd[td].fir, i - 1, -ad[i]);
		while(td && sd[td].sec <= ad[i]) {
			modi(sd[td - 1].fir, sd[td].fir - 1, sd[td].sec - ad[i]);
			-- td;
		}
		sd[++ td] = mkp(i, ad[i]);

		modi(i, i, h - dis[i]);
	}	

}

int main() {
	w = rd(), h = rd(), n = rd();
	// ++ n;
	REP(i, 1, n) {
		int x = rd(), y = rd();
		a[i] = mkp(x, y);
	}
	// a[1] = mkp(0, 0), a[++ n] = mkp(w, h);
	solve();		
	swap(w, h);
	REP(i, 1, n) a[i].fir = dis[a[i].fir];
	REP(i, 1, n) swap(a[i].fir, a[i].sec);

	solve();

	printf("%d\n", ans << 1);

	return 0;
}

Measured memory_bytes: 18944
#include <iostream>

using namespace std;

int main() {
    int n, a, b, c, m;
    cin >> n;
    if (n == 2) {
        cin >> a >> b;
        c = b;
    } else {
        cin >> a >> b >> c;
    }
    m = min(a, min(b, c));
    for (int i = 1; i <= m; ++i) {
        if (a % i == 0 && b % i == 0 && c % i == 0) {
            cout << i << endl;
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<string> w(n);
    set<string> se;
    rep(i, n)
    {
        cin >> w[i];
        se.insert(w[i]);
    }

    if (n != se.size())
    {
        cout << "No" << '\n';
        return (0);
    }

    char c = w[0].back();
    rep(i, n - 1)
    {
        if (w[i + 1].front() != c)
        {
            cout << "No" << '\n';
            return (0);
        }
        c = w[i + 1].back();
    }

    cout << "Yes" << '\n';
    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

  int A,B;
  Scd2(A,B);
  
  int a[3333] = {};
  
  char s[4][10] = {
    "...","...","###","###"
  };
  char t[4][10] = {
    ".#.","...","#.#","###"
  };
  
  int i = 0;
  a[i++] = 1;
  while(--B){
    a[i++] = 0;
  }
  while( i % 33 ) a[i++] = 1;
  a[i++] = 3;
  while(--A){
    a[i++] = 2;
  }
  while( i % 33 ) a[i++] = 3;
  
  printf("%d %d\n",i/11, 99 );
  Rep(j,i/33){
    Rep(k,3){
      Rep(l,33){
  	  	printf( "%s", k % 2 ? t[a[j*33+l]] : s[a[j*33l]] );
      }
      printf("%c",10);
    }
  }

  return 0;
  
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char S[50];
    int i,N;
    int count = 0;
    
    scanf("%d",&N);
    scanf("%s",S);
    for(i = 0 ; i <= N-3; i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C'){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a%3==0||b%3==0||(a+b)%3==0){
        cout << "Possible\n";
    }else{
        cout << "Impossible\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    string S, T;
    cin >> S >> T;

    char s1 = S[0];
    char s2 = S[1];
    char s3 = S[2];
    char t1 = T[0];
    char t2 = T[1];
    char t3 = T[2];

    int a = 0;
    int b = 0;
    int c = 0;

    if (s1 == t1){
        a = 1;
    }
    if(s2 == t2){
        b = 1;
    }
    if(s3 == t3){
        c = 1;
    }
    cout << (a + b + c) << endl;
}

/*
CSS
CSR
2

SSR
SSR
3

RRR
SSS
0
*/

Measured memory_bytes: 256
n=gets.to_i
v=gets.chomp.split.map(&:to_i)
v1=[]
v2=[]

h1 = Hash.new(0)
h2 = Hash.new(0)
v.each_with_index do |w, i|
    if i%2==0
        v1 << w
        h1[w] += 1
    else
        v2 << w
        h2[w] += 1
    end
end

hh1 = h1.to_a.sort {|a,b| a[1] <=> b[1]}.reverse
hh2 = h2.to_a.sort {|a,b| a[1] <=> b[1]}.reverse

#p hh1
#p hh2
hh1 += [nil,0]
hh2 += [nil,0]

# 最頻値の数が同じ
if hh1[0][1] == hh2[0][1]
    # 最頻値の値も同じ
    if hh1[0][0] == hh2[0][0]
        # 最頻値の数がn/2（つまり全て同じ数値）
        if hh1[0][1] == n/2
            puts n/2
        else 
            puts n - hh1[0][1] - [hh1[1][1], hh2[1][1]].max
        end
    else
        puts n - 2 * hh1[0][1]
    end
else
    if hh1[0][0] == hh2[0][0]
        puts n - hh1[0][1] - [hh1[1][1], hh2[1][1]].max
    else
        puts n - hh1[0][1] - hh2[0][1]
    end
end


Measured memory_bytes: 22852
import java.util.Scanner;

	public class Main {
	       public static void main(String[] args){
					Scanner sc = new Scanner(System.in);
					double a = sc.nextDouble();
					double b = sc.nextDouble();
					double x = 0;
					if(1 <= a && b <= 100) {x = (a + b)/2;}
					x = Math.ceil(x);
					System.out.println((int)x);
	       }}

Measured memory_bytes: 23124
class Node
  attr_reader :id, :siblings
  attr_accessor :state, :started_at, :finished_at

  def initialize(id)
    @id = id
    @siblings = []
    @state = :white
    @started_at = nil
    @finished_at = nil
  end

  def <<(sibling)
    @siblings << sibling
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  temp = Hash.new {|hash, id| hash[id] = Node.new(id) }

  n.times do
    id, _, *sibling_ids = gets.chomp.split.map(&:to_i)

    node = temp[id]

    sibling_ids.each do |sibling_id|
      node << temp[sibling_id]
    end
  end

  nodes = temp.values.sort_by {|node| node.id }

  time = 0

  nodes.each do |node|
    next unless node.state == :white

    stack = [node]

    node.state = :gray

    time += 1
    node.started_at = time

    until stack.empty?
      current = stack.last
      sibling = current.siblings.sort_by(&:id).find {|s| s.state == :white && s.id != current.id }

      if sibling
        sibling.state = :gray
        time += 1
        sibling.started_at = time
        stack << sibling
      else
        stack.pop
        current.state = :black
        time += 1
        current.finished_at = time
      end
    end
  end

  nodes.each do |node|
    puts [node.id, node.started_at, node.finished_at].join(' ')
  end
end

Measured memory_bytes: 8896