akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			int a = scan.nextInt();
			list.add(a);
		}

		for(int i = n - 1; i >= 0; i--){
			if(i != 0){
				System.out.printf("%d ", list.get(i));
			} else{
				System.out.printf("%d\n", list.get(i));
			}
		}
	}
}

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

int main() {
    int N; cin >> N;
    using P = pair<int, int>;
    vector<P> ans;
    rep(i, 1, N + 1) {
        int a; cin >> a;
        ans.push_back({a, i});
    }
    sort(ans.begin(), ans.end());
    rep(i, 0, N) cout << ans[i].second << " ";
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            input = input.Replace(","," ");
            Console.WriteLine(input);
        }
    }
}


Measured memory_bytes: 13140
use std::io::stdin;


fn main() {
    let min = |a, b| if a < b { a } else { b };

    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut ais = String::new();
    stdin().read_line(&mut ais).unwrap();
    let mut ais: Vec<usize> = ais.trim().split_whitespace().flat_map(str::parse).collect();
    ais.reverse();

    let mut bis = String::new();
    stdin().read_line(&mut bis).unwrap();
    let mut bis: Vec<usize> = bis.trim().split_whitespace().flat_map(str::parse).collect();
    bis.reverse();
    bis.push(0);

    let mut result = 0;
    for i in 0..n {
        for j in 0..2 {
            let d = min(ais[i + j], bis[i]);
            ais[i + j] -= d;
            bis[i] -= d;
            result += d;
        }
    }
    println!("{}", result);
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (b < a)
	{
		a = b;
		return 1;
	}
	return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];

	char ans[h][w] = {};
	rep(i, h){
		rep(j, w){
			if (s[i][j] == '#'){
				cout << '#';
				continue;
			}

			int cnt = 0;
			rep(k, 8){
				int x = j + dx[k];
				int y = i + dy[k];

				if (x < 0 || w <= x) continue;
				if (y < 0 || h <= y) continue;
				if (s[y][x] == '.') continue;
				cnt++;
			}
			cout << cnt;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 105;
const ll LINF = 1e18 + 5;
int col[N], n;
string t;
bool check(int x)
{
	cout << '?';
	for(int i=x;i<=x+n-1;i++)
		cout << ' ' << i;
	cout << '\n';
	fflush(stdout);
	cin >> t;
	return (t=="Red");
}
void solve(int l,int r,vector<int> s)
{
	for(int i=l;i<=r;i++)
	{
		cout << '?';
		cout << ' ' << i;
		for(int j : s) cout << ' ' << j;
		cout << '\n';
		fflush(stdout);
		cin >> t;
		col[i] = (t=="Red");
	}
}
int main()
{
 	cin >> n;
 	int l = 1, r = n + 1, p = -1;
 	bool lcol = check(l), pcol = 0;
 	while(l<=r)
 	{
 		int mid = (l+r) >> 1;
 		bool midcol = check(mid);
 		if(midcol==lcol) l = mid + 1, p = mid, pcol = lcol;
 		else r = mid - 1;
 	}
 	vector <int> s1, s2;
 	for(int i=p+1;i<=p+n-1;i++) s1.pb(i);
 	for(int i=1;i<=p-1;i++) s2.pb(i);
 	for(int i=p+n+1;i<=2*n;i++) s2.pb(i);
 	if(pcol) col[p] = 1, col[p+n] = 0;
 	else col[p] = 0, col[p+n] = 1;
 	solve(p+1,p+n-1,s2);
 	solve(1,p-1,s1);
 	solve(p+n+1,2*n,s1);
 	cout << "! ";
 	for(int i=1;i<=2*n;i++)
 	{
		if(col[i]) cout << 'R';
		else cout << 'B';
 	}
 	cout << '\n';
 	fflush(stdout);
	return 0;
}


Measured memory_bytes: 724
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    ll res = 0;
    rep(i, n)
    {
        cin >> a[i];
    }

    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            if (a[i] > x)
            {
                res += a[i] - x;
                a[i] = x;
            }
        }
        else
        {
            if (a[i] + a[i - 1] > x)
            {
                int rm = a[i] + a[i - 1] - x;
                res += rm;
                rm -= a[i];
                a[i] = abs(rm);
                if (rm > 0)
                {
                    rm -= a[i - 1];
                    a[i - 1] = abs(rm);
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3784
from collections import defaultdict
import sys
sys.setrecursionlimit(1 << 25)  # 再起上限引き上げ

G = defaultdict(lambda: [])

#load data
N,M = map(int,input().split())
color = {key:0 for key in range(N)}
#graphをdefaultdictで保持することにする
for _ in range(M):
    s,t = map(int,input().split())
    G[s-1].append(t-1)
    G[t-1].append(s-1)
#print(G)
#隣接リストを基にたどり着ける友達をグループ化する。
def dfs(node:int, co:int):
    #終了条件、既に訪問済みなら訪問しない
    if color[node] != 0:
        return
    #処理
    color[node] = co
    for n in G[node]:
        dfs(n,co)

    return

#全てのnodeを開始点としてdfsで色分けしてみる
c = 1
for node in G.keys():
    dfs(node,c)
    c += 1

ans_list = [0]*(N)
for i in range(N):
    ans_list[color[i]] += 1

ans_list[0] = 0
if M == 0:
    print(1)
else:
    print(max(ans_list))


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

int R, C;
const int MAX_R = 11;
const int MAX_C = 10001;
bool G[MAX_R][MAX_C];
int S[MAX_C];

void make() {
  for(int j = 0; j < C; ++j) {
    S[j] = 0;
    for(int i = 0; i < R; ++i) {
      if(G[i][j]) S[j] |= (1<<i);
    }
  }
}

int solve() {
  make();
  int res = 0;
  for(int bit = 0; bit < (1<<R); ++bit) {
    int cnt = 0;
    for(int j = 0; j < C; ++j) {
      int nb = bit ^ S[j];
      int tmp = 0;
      for(int i = 0; i < R; ++i) {
	if(nb & (1<<i)) ++tmp;
      }
      cnt += max(tmp, R-tmp);
    }
    res = max(res, cnt);
  }
  return res;
}

int main() {
  while(cin >> R >> C && R | C) {
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
	cin >> G[i][j];
	G[i][j] = !G[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

int dist(int x1, int y1, int x2, int y2)
{
    return abs(x1-x2) + abs(y1-y2);
}

int main()
{
    int n;
    bool ok = true;
    cin >> n;
    vector<int> t(n+1),x(n+1),y(n+1);
    t.at(0)=0;
    x.at(0)=0;
    y.at(0)=0;
    for(int i = 1; i <= n; i++)
    {
        cin >> t.at(i) >> x.at(i)>>y.at(i);
    }

    
    for(int i = 0; i < n; i++)
    {
        int d = dist(x.at(i),y.at(i),x.at(i+1),y.at(i+1));
        int tdiff = t.at(i+1)-t.at(i);
        if(tdiff >= d && (tdiff - d)%2==0)
        {
            continue;
        }
        else
        {
            ok = false;
            break;
        }
    }
    

    if(ok)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1000003;
function abmod(){for(var a=arguments,r=a[0],i=1;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}
var fac=[1,1];
function fSet(n){for(var i=2;i<=n;)fac[i]=abmod(fac[i-1],i++);}
function modinv(a){for(var b=mod,u=1,v=0,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function nPrmod(n,r){return abmod(fac[n],modinv(fac[(n-r+mod)%mod]));}
function powmod(a,n){for(var r=1;n;a=abmod(a,a),n>>=1)if(n&1)r=abmod(a,r);return r;}

console.log(main());
function main(){
  var q = o.a();
  var ans = Array(q).fill(0);
  fSet(mod);
  for(var i = 0; i < q; i++){
    var t = o.l(), x = t[0], d = t[1], n = t[2];
    if(x === 0)continue;
    if(d === 0){
      ans[i] = powmod(x,n);
    }else{
      if(n >= mod)continue;
      var u = (mod-x)/d;
      var g = exgcd(mod,d);
      var u = ((mod-x)*g[1]%mod+mod)%mod;
      if(u < n)continue;
      var a = ((mod-abmod(x,modinv(d)))%mod+mod)%mod;
      var p = nPrmod(a,n);
      var m = powmod(mod-d,n);
      ans[i] = abmod(p,m);
    }
  }
  return ans.join("\n");
}

function exgcd(x,y){
  var r0 = x, r1 = y, a0 = 1, a1 = 0, b0 = 0, b1 = 1;
  while(r1){
    var q1 = r0 / r1 | 0;
    var r2 = r0 % r1;
    var a2 = a0 - q1*a1;
    var b2 = b0 - q1*b1
    r0 = r1, r1 = r2;
    a0 = a1, a1 = a2;
    b0 = b1, b1 = b2;
  }
  return [a0,b0,r0];
}

Measured memory_bytes: 62584
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))
 
 
using namespace std;
 
 
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;
typedef unordered_set<int> ui;

int N;

int main(){
	std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>N;
	vi A(N), B(N), C(N);
	long long ans = 0;
	vL med(N+1,0);
	for(int i=0;i<N;++i) cin>>A[i];
	for(int i=0;i<N;++i) cin>>B[i];
	for(int i=0;i<N;++i) cin>>C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	
	int i = 0, j = 0;
	while(j <N){
		while(i<N && A[i]<B[j]) ++i;
		med[j+1] = i + med[j];
		++j;
	}
	i = j = 0;
	while(j<N){
		while(i<N && B[i]<C[j]) ++i;
		ans += med[i];
		++j;
	} 
	cout<<ans<<endl;
	return 0;
}












Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  4 21:06:52 2020

@author: liang
"""

N, M = map(int,input().split())
A = list(map(int,input().split()))
sum_A = sum(A)
level = sum_A/(4*M)
catch = 0


for a in A:
    if a >= level:
        catch += 1

if catch >= M:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 3060
N, K = map(int, input().split())

A = list(map(int, input().split()))

mod = 1000000007

# K = 2のときの初期値が必要
B = A * 2
syokiti_A = 0
syokiti_B = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            syokiti_A += 1

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if A[i] > A[j]:
            syokiti_B += 1

ans = (syokiti_A * K) % mod + (syokiti_B * K * (K-1) // 2) % mod
print(int(ans) % mod)


Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        if((num/10 == 9)||(num%10 ==9)){
            System.out.print("Yes");
        }else{
            System.out.print("No");
        }
	}
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int sum = 0;
        for(int i = 0;i < n.length(); i++){
            char ch = n.charAt(i);
            sum += Character.getNumericValue(ch);
        }
        if(sum % 9 == 0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 40456
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;
#define mod 1000000007

lol ans;
int n;
map<char, int> mp;

void init() {
    mp.clear();
    ans = 1;
}

int main() {
    init();

    cin >> n;
    for (int i = 0; i < n; i++) {
        char c; cin >> c;
        mp[c] ++;
    }
    for (auto i : mp) {
        ans = ans * (i.second + 1);
        ans = ans % mod;
    }
    cout << ans - 1 << '\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
al = [chr(i) for i in range(65, 91)]

ss = []
for i in range(len(s)):
	if n + ord(s[i]) - 65 < 26:
		ss.append(al[n + ord(s[i]) - 65])
	else:
		ss.append(al[n + ord(s[i]) - 91])
print("".join(map(str,ss)))

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


int main(){
    int A,B;
    cin >> A >> B;
    int count = 0;

    if(B == 1){
        cout << 0 << endl;
        return 0;
    }


    while(1){
        if(count==0){
            B = B-A;
            count++;
        }else{
            B = B-(A-1);
            count++;
        }
        if (B <= 0) break;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
S = list(input())

N = len(S)
P = [str(i%2) for i in range(N)]
Q = [str((i+1)%2) for i in range(N)]

PC = 0
QC = 0
for i in range(N):
    if P[i] != S[i]:
        PC += 1
    else:
        QC += 1

print(min(PC,QC))


Measured memory_bytes: 56460
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.close();

		if (t.substring(0, t.length() - 1).equals(s)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define LL long long
using namespace std;
const int N = 2e5 +10 ;
int n,q;
LL a[N] ;
LL sum = 0 ;
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ; cout.tie(0) ;
   // freopen("ch.inp","r",stdin) ;
    cin >> n ;
    FOR(i,1,n) cin >> a[i] , sum^= a[i];
    FOR(i,1,n) cout << (sum ^ a[i]) <<" ";


}


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

int main() {
  
  ll A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  ll d = abs(A-B);

  if (V <= W) {
    cout << "NO" << endl;
  }
  else if (d <= (V-W)*T) {
    cout << "YES" << endl;
  }
  else  cout << "NO" << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

void range_determine(int a, int b, int c){
    if (a < b && b < c)
        printf("Yes\n");
    else
        printf("No\n");
}

int main(void){
    int a = 0;
    int b = 0;
    int c = 0;
    scanf("%d %d %d", &a, &b, &c);
    range_determine(a, b, c);

    return 0;
}



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

 int f(vector <int>& h){
    int n = h.size();
    vector <int> dp(n);

    dp[1] = abs(h[1]-h[0]);

    for(int i=2 ; i<n ; i++){
       int a = abs(h[i]-h[i-1]) + dp[i-1]; 
       int b = abs(h[i]-h[i-2]) + dp[i-2];
       dp[i] = min(a,b);
    }
        return dp[n-1];
 }

int32_t main() {
   int n; cin>>n; 
   vector <int> h(n);
   for(int i=0 ; i<n ; i++) cin>>h[i];
   cout<<f(h);
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

// S....M....E
// R...RL...LR
func searchRange(text *string, start, limit int) (int, int, int) {
	middle := -1

	for i := start; i < limit; i++ {
		if (*text)[i] != 'R' {
			middle = i
			break
		}
	}

	end := limit

	for i := middle; i < limit; i++ {
		if (*text)[i] != 'L' {
			end = i
			break
		}
	}

	return start, middle, end
}

func answer() {
	var text string
	fmt.Scan(&text)
	limit := len(text)

	start := 0
	middle := 0
	end := 0
	firstPrinted := false

	for end < limit {
		start, middle, end = searchRange(&text, start, limit)
		len1 := middle - start
		len2 := end - middle

		for i := start; i < middle-1; i++ {
			if firstPrinted {
				fmt.Print(" ")
			}
			fmt.Print("0")
			firstPrinted = true
		}

		count1 := (len1+1)/2 + len2/2
		count2 := len1/2 + (len2+1)/2

		if firstPrinted {
			fmt.Print(" ")
		}
		fmt.Printf("%v %v", count1, count2)
		firstPrinted = true

		for i := middle + 1; i < end; i++ {
			if firstPrinted {
				fmt.Print(" ")
			}
			fmt.Print("0")
			firstPrinted = true
		}
		start = end
		firstPrinted = true
	}
	fmt.Println()
}

func main() {
	answer()
}


Measured memory_bytes: 4736
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    struct Connection
    {
        public List<int> list;
        public Connection(int index)
        {
            list = new List<int>();
        }
    }

    static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x=>Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var a = new int[M];
        var b = new int[M];
        for (int i=0;i<M;++i)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            a[i] = ab[0];
            b[i] = ab[1];
        }

        var ans = 0L;
        for (int i = 0; i < M; ++i)
        {
            var connection = new Connection[N];
            for (int j = 0; j < N; ++j) connection[j] = new Connection(j);
            for (int j = 0; j < M; ++j)
            {
                if (i == j) continue;
                connection[a[j]-1].list.Add(b[j]-1);
                connection[b[j] - 1].list.Add(a[j] - 1);
            }
            var hashSet = new HashSet<int>();
            Dfs(hashSet, connection, i == 0 ? 1 : 0);
            if (hashSet.Count() != N) ans++;
        }
        Console.WriteLine(ans);
    }
    static void Dfs(HashSet<int> hashSet,Connection[] connection,int index)
    {
        hashSet.Add(index);
        foreach (var l in connection[index].list)
        {
            if (!hashSet.Contains(l)) Dfs(hashSet,connection,l);
        }
    }
}


Measured memory_bytes: 13524
s = input()
n = len(s)

ans = 0

cb_cnt = 0
state = 0
# state 0 = なんにもない状態
for i in range(n)[::-1]:
    # なんでもない状態→Cの状態のみに以降
    if state == 0:
        if s[i] == "C":
            cb_cnt = 1
            state = 1
            continue
    # Cが入ってきている時→CBの状態のみに移行
    elif state == 1:
        if s[i] == "B":
            state = 2
            continue
        elif s[i] == "C":
            cb_cnt = 1
            continue
    # CBCB ... Bのとき
    elif state == 2:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            state = 3
            continue
    # CBCB...A になったとき
    elif state == 3:
        if s[i] == "C":
            state = 1
            cb_cnt += 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            continue
    cb_cnt = 0
    state = 0
print(ans)

Measured memory_bytes: 41440
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
ll a[60];
int main() {
    int n;
    ll sum=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    while(1) {
	int x=0;
	for(int i=1;i<=n;i++)
	    if(a[i]>a[x]) x=i;
	if(a[x]<n) break;
	ll s=a[x]/n;sum+=s;
	for(int i=1;i<=n;i++)
	    if(i^x) a[i]+=s;
	a[x]-=s*n;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  int ret = 0;
  while(N != 0) {
    N /= K;
    ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin>>a[i];
    }

    for(int i=0;i<5;i++){
        if(a[i]==0){
            cout<<i+1<<"\n";
        }
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int s_int(string s){
	return atoi(s.c_str());
}
int main(){
	cout << fixed << setprecision(10);
	int r = 0, l = 0;
	int n;
	string s;
	cin >> n >> s;
	int now = 0;
	rep(i,n){
		if(s[i]=='('){
			now++;
		}else{
			if(now > 0) now--;
			else if(now <= 0){
				l++;
			}
		}
	}
	rep(i,l) cout << "(";
	cout << s;
	rep(i,now) cout << ")";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#define ll long long 
#define pb push_back
#define INF (ll)1e18
#define IINF (int)1e9 
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
#define MOD 1000000000 + 7
#define F first 
#define S second
#define sp << " " << 
/*rrrohan*/ 
using namespace std; 
 
/*less than or equal to -> l + r + 1*/
 
/*class dsu{
private: 
	vector <int> r,p; 
public: 
	dsu(int n){
		p.resize(n+1);
		r.resize(n+1);  
		for(int i = 0; i < n+1; i++){
			p[i] = i; 
			r[i] = 0; 
		}
	}
	int findset(int i){
		return (p[i] == i) ? i : (p[i] = findset(p[i])); 
	}
	bool issameset(int a, int b){
		return findset(a) == findset(b); 
	}
	void unionset(int i, int j){
		if(!issameset(i,j)){
			int x = findset(i), y = findset(j); 
			if(r[x] > r[y]){
				p[y]  = x; 
			}else{
				p[x] = y; 
				if(r[x] == r[y]){
					r[y]++; 
				}
			}
		}
	}
};
*/ 


int main(){
	int n; 
	cin >> n; 
	int ans = 0; 
	pair <int,int> arr[n]; 
	for(int i = 0; i < n; i++){
		cin >> arr[i].F; 
	} 
	for(int i = 0; i < n; i++){
		cin >> arr[i].S; 
	}
	for(int i = 0; i < n; i++){
		ans += max(0, arr[i].F - arr[i].S); 
	}
	cout << ans; 
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var a = Math.Min(K, A);
		A -= a;
		K -= a;
		var b = Math.Min(K, B);
		B -= b;
		K -= b;
		Console.WriteLine("{0} {1}", A, B);
		
		
	}
	long A, B, K;
	public Sol(){
		var d = rla();
		A = d[0]; B = d[1]; K = d[2];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;      cin>>n;
  int a[n];
  for(auto i=0;i<n;++i){
    cin>>a[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  dp[2]=abs(a[2]-a[0]);
  for(auto i=3;i<n;++i){
      dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt n;
    cin >> n;
    cout << pow (2, floor (log2 (n))) << endl;
    return 0;
}


Measured memory_bytes: 256
n,m = list(map(int, input().split(" ")))

A = list(map(int, input().split(" ")))
bc = []
for _ in range(m):
  b,c = list(map(int, input().split(" ")))
  bc.append((b,c))

count = 0
bc = sorted(bc,key=lambda x:x[1],reverse = True)
big_list = []
for b,c in bc:
  big_list += [c for _ in range(b)]
  count += b
  if count >= n:
    break
print(sum( sorted((A+big_list),reverse=True)[:n] ))

Measured memory_bytes: 26732
#include <stdio.h>
typedef long long ll;
ll min(ll x,ll y){
  return (x>y)?y:x;
}

ll quotient(ll x,ll y){
  ll z = x%y;
  return z;
}

int main(void){
  ll N,K;
  scanf("%lld",&N);
  scanf("%lld",&K);
  printf("%lld",min(quotient(N,K),K-quotient(N,K)));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    int n,k,p;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> k >> p;
        cout << (k%p==0?p:k%p) << endl;
        //if(i!=n-1)cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];

  bool ok = true;
  set<string> s;
  rep(i, n){
    if(s.count(w[i])){
      ok = false;
      break;
    }
    s.insert(w[i]);
  }
  rep(i, n-1){
    if(w[i][w[i].size()-1] != w[i+1][0]){
      ok = false;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,x;
    cin>>a>>b>>x;
    if(x>a)
    {
        if(a+b>=x)
        {
            cout<<"YES";
        }
        else if(a+b<x)
        {
            cout<<"NO";
        }

    }
    else if(x<a)
    {
        cout<<"NO";
    }
    else if(x==a)
    {
        cout<<"YES";
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
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; }



#define rep(n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
const int MOD = 1000000007;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;

int main() {
	
	int N, W;
	cin >> N >> W;
	vl w(N), v(N);
	rep(N) { cin >> w[i] >> v[i]; }
	vll dp(N + 1, vl(100011,LINF));
	dp[0][0] = 0;
	rep(N) {
		for (int j = 0; j <= 100011; j++) {
			dp[i + 1][j] = dp[i][j];
			if (j - v[i] >= 0)chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
		}
	}
	int ma = 0;
	for(int i=0;i<100011;i++) {
		if(dp[N][i]<=W)
		chmax(ma, i);
	}

	cout << ma << endl;
	return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int check = 0;
  
  for(int i=2; i<101; i++){
    if(A %i == 0 &&  B %i == 0){
      check = 1;
    }
    if((A %i==0 && B %i == 0 && C %i == 0)){
      check = 2;
      break;
    }
  }
  
  string ans = "YES";
  
 if(check == 1){
   ans = "NO";
 }
 if(A == 1){
   ans = "YES";
 }
 if(B == 1){
   ans = "NO";
 }
  
 cout << ans << endl;  
    
}  

Measured memory_bytes: 256
from collections import deque
# N = int(input())
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
MOD = 10 ** 9 + 7
A_p = []
A_n = []
for a in A:
  if a >= 0:
    A_p.append(a)
  else:
    A_n.append(-a)

A_p.sort(reverse=True)
A_n.sort(reverse=True)
A_p = deque(A_p)
A_n = deque(A_n)

p_top = 0
n_top = 0
ans_p = deque([])
ans_n = deque([])
for i in range(K):
  if len(A_p) > 0 and len(A_n) > 0 and A_p[0] >= A_n[0]:
    ans_p.append(A_p.popleft())
  elif len(A_n) > 0:
    ans_n.append(A_n.popleft())
  elif len(A_p) > 0:
    ans_p.append(A_p.popleft())
if len(ans_n) % 2 == 1:
  if len(ans_p) > 0 and len(ans_n) > 0 and len(A_p) > 0 and len(A_n) > 0 and ans_p[-1] * A_p[0] >= ans_n[-1] * A_n[0]:
    ans_n.pop()
    ans_p.append(A_p.popleft())
  elif len(ans_p) > 0 and len(A_n) > 0:
    ans_p.pop()
    ans_n.append(A_n.popleft())
  elif len(ans_n) > 0 and len(A_p) > 0:
    ans_n.pop()
    ans_p.append(A_p.popleft())
ans = 1
for a in ans_p:
  ans = (a * ans) % MOD
for a in ans_n:
  ans = (-a * ans) % MOD
if ans != 0 and len(ans_n) % 2 == 1:
  ans = 1
  A_abs = [abs(a) for a in A]
  A_abs.sort()
  for i in range(K):
    ans = (ans * A_abs[i]) % MOD
  ans = (-ans) % MOD
print(ans)




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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

map<vi , int> memo[2];

int was = INF;

int rec(vi a , int optype , int d){
	if(d > was) return 1e6;
	SORT(a);
	if(a[0] == a[2]){
		was = min(was , d);
		return 0;
	}
	if(memo[optype].find(a) != memo[optype].end()) return memo[optype][a];
	int res = 0;
	if(optype == 0){
		if(a[2] - a[0] == 1 && a[1] - a[0] == 1){
			res = 1;
		}else{
			++a[0];
			++a[1];
			res = min(rec(a , 0, d + 1), rec(a , 1 , d + 1));
			--a[0];
			--a[1];
		}
	}else{
		res = 1e6;
		if(a[2] - a[0] != 1){
			a[0] += 2;
			res = min(res , min(rec(a , 0, d + 1) , rec(a , 1 , d + 1)));
			a[0] -= 2;
		}
		if(a[2] - a[1] > 1){
			a[1] += 2;
			res = min(res , min(rec(a , 0, d + 1) , rec(a , 1 , d + 1)));
			a[1] -= 2;
		}
	}
	memo[optype][a] = 1 + res;
	return 1 + res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int a , b , c;
	cin >> a >> b >> c;

	vi v = {a , b , c};
	
	auto ans = min(rec(v , 0 , 0) , rec(v , 1 , 0));
	
	cout << ans << nl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



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

    while(1){
        double m = sqrt(n);
        if(m == (double)((ll)m)){
            P(n);
            break;
        }
        n--;
    }
	return  0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <unistd.h>

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

  std::vector<std::uint64_t> a;
  a.resize(n);

  for(auto&& ai : a)
    std::cin >> ai;
  
  if(n == 2) {
      std::cout << std::max(a[0], a[1]) << ' ' << std::min(a[0], a[1]) << std::endl;
      return 0;
  }
  const std::uint64_t m = *std::max_element(std::cbegin(a), std::cend(a));
  const double target = m / 2;
    
  std::sort(std::begin(a), std::end(a));
  const auto cit = std::lower_bound(std::cbegin(a), std::cend(a), target);
  const uint64_t closest = abs(*cit - target) > abs(*(cit - 1) - target) ? *(cit - 1) : *cit;

  std::cout << m << ' ' << closest << std::endl;
}

Measured memory_bytes: 1024
a,b,c,d,e,f = map(int,input().split())


from itertools import product
water = set()

for i,j in product(range(f//(a*100)+2),range(f//(100*b)+2)):
  n = a*i+b*j
  if n <= f:
    water.add(n)

water = sorted(water)

salt = set()

for i,j in product(range(f//c+2),range(f//d+2)):
  n = c*i+d*j
  if n <= f:
    salt.add(n)

salt = sorted(salt)

from bisect import bisect_left



bs,bw = 0,min(a,b)
for s in salt:
  w = s/e
  i = bisect_left(water,w)
  if i >= len(water):
    break
  w = water[i]
  if 100*w + s > f:
    break
  if bs*w < bw*s:
    bs,bw = s,w

print(bs+100*bw,bs)


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

int main(void)
{
	char r[5],a[5];
	int hit = 0,blow = 0,i,j;
	while (1)
	{
		scanf("%s %s",r,a);
		if (strlen(r) == 1)
		{
			return 0;
		}
		for (i = 0; i < 4; i++)
		{
			for (j = 0; j < 4; j++)
			{
				if (r[i] == a[j])
				{
					if (i == j)
					{
						hit++;
					}
					else
					{
						blow++;
					}
				}
			}
		}
		printf("%d %d\n", hit,blow);
		hit = 0;
		blow = 0;
	}
	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <vector>

using namespace std;


class Solution{

private:
    const long long MOD = 1e9 + 7;
    vector<long long> fac, inv_fac;

public:
    int ways(int H, int W, int A, int B){

        init(2 * max(H, W));

        long long res = 0ll;
        for(int j = B + 1; j <= W; j ++) {
            long long a = C(H - A + j - 2, j - 1);
            long long b = C(W - j + 1 + A - 2, A - 1);
            res += a * b % MOD;
            res %= MOD;
        }
        return res;
    }

private:
    void init(int N){

        fac = {1ll, 1ll};
        for(int i = 2; i <= N; i ++)
            fac.push_back(fac.back() * i % MOD);

        inv_fac = {1ll, 1ll};
        for(int i = 2; i <= N; i ++)
            inv_fac.push_back(mypow(fac[i], MOD - 2));
    }

    long long mypow(int x, int k){

        if(k == 0) return 1ll;

        long long t = mypow(x, k / 2);
        long long res = t * t % MOD;
        if(k % 2) res = res * x % MOD;
        return res;
    }

    long long C(int n, int k){
        return fac[n] * inv_fac[k] % MOD * inv_fac[n - k] % MOD;
    }
};

int main() {

//    cout << Solution().ways(2, 3, 1, 1) << endl;
//    // 2
//
//    cout << Solution().ways(10, 7, 3, 4) << endl;
//    // 3570
//
//    cout << Solution().ways(100000, 100000, 99999, 99999) << endl;
//    // 1

    int H, W, A, B;
    scanf("%d%d%d%d", &H, &W, &A, &B);
    printf("%d\n", Solution().ways(H, W, A, B));

    return 0;
}


Measured memory_bytes: 7564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll =int long long;
map <int ,int> mpa,mpb;

int main (void){
  int X;
  cin >> X;
  int ans=1;
  int b;
  for(int b=32;b>1;b--){
    int c=b;
    while(X>b){
      c*=b;
      if(c>X)break;
      ans=max(ans,c);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char s[105];
int main(){
	int q=1e+9,p=1e+9;
	scanf("%s",s);
	for(int i=0;i<strlen(s);++i){
		if(s[i]=='C'){
			for(int j=i+1;j<strlen(s);++j){
				if(s[j]=='F'){
					printf("Yes");
					return 0;
				}
			}
			printf("No");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	while(1){
		int N; cin >> N;
		if(!N) break;
		int ans = 0;
		for(int i=1; i<N; i++){
			int sum = i;
			for(int j=i+1; j<N; j++){
				sum += j;
				if(sum == N) {
					ans++;
					break;
				} else if(sum > N) break;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3004
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[10][2][2][2][2][2];

int main(){
  string s; cin >> s;
  int n=s.size();
  dp[0][0][0][0][0][0]=1;
  rep(i,n)rep(a,2)rep(b,2)rep(c,2)rep(f,2)rep(j,2){
    rep(d,10){
      int nd=s[i]-'0';
      int nj=j;
      if(j==0){
        if(d>nd) continue;
        if(d<nd) nj=1;
      }
      int nf=f;
      if(d!=0&&d!=3&&d!=5&&d!=7) continue;
      if(f==1&&d==0) continue;
      if(f==0&&d!=0) nf=1;
      int na=a,nb=b,nc=c;
      if(a==0&&d==3) na=1;
      if(b==0&&d==5) nb=1;
      if(c==0&&d==7) nc=1;
      dp[i+1][na][nb][nc][nf][nj]+=dp[i][a][b][c][f][j];
    }
  }
  cout << dp[n][1][1][1][1][0]+dp[n][1][1][1][1][1]+dp[n][1][1][1][0][0]+dp[n][1][1][1][0][1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  vi nums;
  int now = 1;
  int cnt = 0;
  // 1-0-1-0-1の形の配列を作る
  // 0番目の区間が0なら、(1,0)が先頭に追加される
  // 0番目の区間が1なら、そのまま数えられる
  rep(i,n) {
    if (s[i] == (char)('0' + now)) cnt++;
    else {
      nums.pb(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  // 最後の区間がまだ、ついていないので付け加える
  if (cnt != 0) nums.pb(cnt);
  // numsのサイズが偶数の場合、1-0-1-0の形になってしまっているので、
  // 後ろに(1,0)を追加して、1-0-1-0-1の形にする
  if (nums.size()%2 == 0) nums.pb(0);

  // k = 1: 1-0-1 -> 1-1-1
  //                 |   |
  //                 l   l+2*k
  // k = 2: 1-0-1-0-1 -> 1-1-1-1-1
  //                     |       |
  //                     l       l+2*k
  int add = 2*k + 1;
  int ans = 0;
  for (int i = 0; i < nums.size(); i+=2) {
    int tmp = 0;

    int left = i;
    int right = min(i+add, (int)nums.size());
    for (int j = left; j < right; ++j) {
      tmp += nums[j];
    }
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

pi a[3003];
int dp[3003][3003];

signed main()
{
	IO_OP;
	
	int n, t;
	cin >> n >> t;
	for(int i=0;i<n;i++)
		cin >> a[i].F >> a[i].S;
	sort(a, a+n);
	for(int i=0;i<=t;i++) if(i >= a[0].F)
		dp[0][i] = a[0].S;
	for(int i=1;i<n;i++) {
		for(int j=0;j<=t;j++) {
			dp[i][j] = dp[i-1][j];
			if(j >= a[i].F) {
				dp[i][j] = max(dp[i][j], a[i].S + dp[i-1][j-a[i].F]);
			}
		}
	}
	int mx = a[0].S;
	for(int i=1;i<=n;i++)
		mx = max(mx, a[i].S + dp[i-1][t-1]);
	cout << mx << endl;
}





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

ll f(ll h){
    if(h==1) return 1;
    return (2*f(h/2)+1);
}

int main(){
    ll h;
    cin >>h;
    cout << f(h) <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 100005;
int n, dep[N], sz[N], pa[N], col[N], fuck, idx, mx;
VI to[N];

void dfs(int x, int fa){
	pa[x] = fa;
	sz[x] = 1;
	dep[x] = dep[fa] + 1;
	RVC(i, to[x]) if (to[x][i] != fa){
		dfs(to[x][i], x);
		sz[x] += sz[to[x][i]];
	}
}


int main(){
	scanf("%d", &n);
	REP(i, 2, n){
		int u, v;
		scanf("%d%d", &u, &v);
		to[u].pb(v);
		to[v].pb(u);
	}
	dfs(1, 0);
	mx = dep[n] / 2 - 1;
	int u = n;
	REP(i, 1, mx) u = pa[u];
	int ws = sz[u] - 1, bs = n - sz[u] - 1;
	if (bs == 0) puts("Snuke");
	else{
		if (bs > ws) puts("Fennec");
		else puts("Snuke");
	}
	return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll X;
    cin >> X;
    ll tmp = 100;
    for(int i = 1; ; i++){
        tmp += tmp/100;
        if(tmp >= X){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<time.h>
#include<math.h>
#include<cstring>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define gcd __gcd
using namespace std;
typedef long long ll;
int a,b,c,ans,N,M,T,t,q[1007][1007];
int main(){
	int H,W,A,B;
	scanf("%d%d%d%d",&H,&W,&A,&B);
	rep(i,1,B) rep(j,1,A) q[i][j]=1;
	rep(i,B+1,H) rep(j,A+1,W) q[i][j]=1;
	rep(i,1,H){
		rep(j,1,W) printf("%d",q[i][j]);
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 5120