akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
	int x, y;
	for(int i = 0; i < 3000; i++){
		cin >> x >> y;
		if(x*x + y*y > 0){
			if(x <= y){
				cout << x << " " << y << endl;
			}else{
				cout << y << " " << x << endl;
			}
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,ll>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5,MAXM=4005,Mod=1e9+7,Inv=Mod+1>>1;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,O,f[MAXM][MAXM],a[MAXN],b[MAXN],Fac[MAXN],iFac[MAXN];
inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),O=2000;
	Fac[0]=iFac[0]=1;Rep(i,1,8000)Fac[i]=1ll*Fac[i-1]*i%Mod,iFac[i]=Fp(Fac[i],Mod-2);
	Rep(i,1,n)a[i]=read(),b[i]=read(),f[O-a[i]][O-b[i]]++;
	Rep(i,0,4000)Rep(j,0,4000)f[i][j]=(0ll+(i?f[i-1][j]:0)+(j?f[i][j-1]:0)+f[i][j])%Mod;
	int ans=0;Rep(i,1,n)ans=(ans+f[O+a[i]][O+b[i]])%Mod,ans=(ans-1ll*Fac[a[i]+b[i]<<1]*iFac[a[i]<<1]%Mod*iFac[b[i]<<1]%Mod+Mod)%Mod;
	cout<<1ll*ans*Inv%Mod<<'\n';
	return 0;
}




Measured memory_bytes: 67828
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        String[] Str = scan.nextLine().split("");
        Integer[] S = new Integer[Str.length];

        for(int i=0; i<S.length; i++) {
            S[i] = Integer.parseInt(Str[i]);
        }

        int answer = 999;
        int absolute;
        for(int j=0; j<S.length-2; j++) {
            absolute = Math.abs(753 - (S[j]*100 + S[j+1]*10 + S[j+2]));
            if (absolute < answer) answer = absolute;
        }

        System.out.println(answer);
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n;
string x;
/******* define variable end *******/
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1)
			res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int solve() {
	cin >> n >> x;
	ll oc = 0;
	vl dp(n+1);
	dp[0] = 0;
	for(ll i = 1; i <= n; i++){
		ll octmp = 0;
		ll tmp = i;
		while(tmp > 0){
			octmp += tmp % 2;
			tmp /= 2;
		}
		if(octmp == 0){
			dp[i] = 0;
			continue;
		}
		dp[i] = dp[i % octmp]+1;
	}
	REP(i, n){
		if(x.substr(i, 1) == "1"){
			oc++;
		}
	}
	vll po(n, vl(3));
	REP(i, n){
		REP(j, 3){
			if(oc+j%3-1 == 0){
				po[i][j] = 0;
				continue;
			}
			po[i][j] = modpow(2, i, oc + j%3-1);
		}
	}
	vl number(3);
	REP(i, n){
		REP(j, 3){
			if(x.substr(i, 1) == "1"){
				number[j] += po[n-1-i][j];
			}
		}
	}
	for(ll i = 0; i <= n-1; i++){
		if(x.substr(i, 1) =="1"){
			if(oc-1 == 0){
				cout << dp[0] << endl;
				continue;
			}
			cout << dp[(oc-1 + number[0] - modpow(2, n-1-i, oc-1))%(oc-1)] + 1 << endl;
		}else{
			cout << dp[(number[2] + modpow(2, n-1-i, oc+1))%(oc+1)] + 1 << endl;
		}
	}
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 15948
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define I_L_T_S ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
const int N = 1e5 + 2;
const int mod = 1e9 + 7;

long long binpow(long long a, long long b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int32_t main(){
   I_L_T_S;
   int a , b;
   cin >> a >> b;
   cout << max({a + b , a - b , a*b });


  return 0;
}


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

count = 0;
for i in range(n):
    left = min(a[i], b[i])
    count += left
    a[i] -= left
    b[i] -= left

    right = min(a[i+1], b[i])
    count += right
    a[i+1] -= right
    b[i] -= right
    
print(count)

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

int main(){

    int n;
    cin >> n;
    vector<tuple<int, int, char, long long, string>> tup;
    for(int i = 0; i < n; ++i){
        int v, w;
        char t;
        long long d;
        string s;
        cin >> v >> w >> t >> d >> s;
        tup.emplace_back(v, w, t, d, s);
    }
    sort(tup.begin(), tup.end());

    for(const auto x : tup){
        cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x) << " " << get<3>(x) << " " << get<4>(x) << endl;
    }

    return 0;
}


Measured memory_bytes: 12296
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  int n; cin >> n;
  int x = 1, cnt = 0;

  rep(i, n) {
    int p; cin >> p;
    if (p != x) ++cnt;
    ++x;
  }

  if (cnt <= 2) cout << "YES\n";
  else cout << "NO\n";

  return (0);
}


Measured memory_bytes: 3660
#include <stdio.h>
int main(){
    int a,b,c,tmp;
    int data[4];
    for(int i=0;i<4;i++){
        scanf("%d",&data[i]);
    }
    for(int i=0;i<3;i++){
        for(int m=0;m<3-i-1;m++){
            if(data[m]>data[m+1]){
                tmp=data[m+1];
                data[m+1]=data[m];
                data[m]=tmp;
            }
        }
    }
    for(int m=0;m<data[3];m++)
    data[2]=data[2]*2;
    printf("%d\n",data[0]+data[1]+data[2]);
}


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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> a(m);
  for(int i=0;i<m;++i) cin >> a[i];
  int l=0,r=0;
  for(auto i:a){
    if(i<x) l++;
    if(x<i) r++;
  }
  cout << min(l,r) << endl;

  return 0;
}

Measured memory_bytes: 256
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int A, B;
	char S[12];
	int ngflg = 0;
	scanf("%d%d", &A, &B);
	scanf("%s", &S);
	//printf("%s", S);

	if (strlen(S) != A + B + 1) {
		ngflg = 1;
	}
	if (ngflg == 0) {
		for (int i = 0; i < strlen(S); i++) {
			if (i != A && S[i] == '-') {
				ngflg = 1;
			}
			if (i == A && S[i] != '-') {
				ngflg = 1;
			}
		}
	}
	if (ngflg == 0) {
		puts("Yes");
	}
	else {
		puts("No");
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: usize
    }
    // all, pat
    let mut v: Vec<(usize, usize)> = vec![(1, 1)];
    for i in 0..n {
        let (iall, ipat) = v[i];
        let all = 3 + 2 * iall;
        let pat = 1 + 2 * ipat;
        v.push((all, pat));
    }
    let mut sum = 0;
    let mut queue: Vec<(usize, usize)> = vec![(n, x)];
    while let Some((level, eat)) = queue.pop() {
        if level == 0 && eat == 1 {
            sum += 1;
            continue;
        }
        if eat <= level {
            // sum += 0;
            continue;
        }
        let (all, pat) = v[level];
        if eat == all {
            sum += pat;
            continue;
        }
        let mid = all / 2;
        match eat.cmp(&(mid + 1)) {
            std::cmp::Ordering::Less => {
                queue.push((level - 1, eat - 1));
            },
            std::cmp::Ordering::Equal => {
                let (_, pat) = v[level - 1];
                sum += pat + 1;
            },
            std::cmp::Ordering::Greater => {
                let (_, pat) = v[level - 1];
                sum += pat + 1;
                queue.push((level - 1, eat - mid - 1));
            }
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        sc.nextLine();
        int map[][] = new int[2][N];
        int sum[][] = new int[2][N];
        for (int i = 0; i < 2; i++) {
        	for (int j = 0; j < N; j++) {
        		
        		map[i][j] = sc.nextInt();
        		
        		if (j == 0) {
        			sum[i][j] = map[i][j];
        		} else {
        			sum[i][j] = sum[i][j - 1] + map[i][j];
        		}
        	}
        	sc.nextLine();
        }
        
        int ans = 0;
        
        for (int start = N; start > 0; start--) {
        	int candies = 0;
        	if (start == 1) {
        		candies = sum[0][start - 1] + (sum[1][N - 1]);
        	} else {
            	candies = sum[0][start - 1] + (sum[1][N - 1] - sum[1][start - 2]);
        	}
        	if (ans < candies) {
        		ans = candies;
        	}
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, 0, n) cin >> h[i];

    int dp[n];
    dp[0] = 0;
    rep(i, 1, n) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        int j = 2;
        while(i - j >= 0 && j <= k) {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            j++;
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    ll a,b,k;
    cin >> a >> b >> k;
    
    ll ansA, ansB;
    
    if(a >= k)
    {
        ansA = a - k;
        ansB = b;
    }
    else
    {
        ansA = 0;
        ansB = max(0LL, b - (k - a));
    }
    
    cout << ansA << ' ' << ansB << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,W;
    cin>>N>>W;

    vector<vector <long long> > dp (N+1,vector<long long>(W+1,0));

    for (int i =0;i<N;i++){
        int w,v;
        cin>>w>>v;
        for (long long weight=0;weight <W+1;weight++){
            if (weight-w >=0){
                dp[i+1][weight] = max(dp[i+1][weight],dp[i][weight-w]+v);

            }

            dp[i+1][weight] = max(dp[i+1][weight],dp[i][weight]);


        }
    }

    std::vector<long long>::iterator a=max_element(dp.at(N).begin(),dp.at(N).end());
    size_t a_index = std::distance(dp.at(N).begin(),a);
    cout<<dp[N][a_index]<<endl;


}

Measured memory_bytes: 80256
import sys


def solve(A: int, B: int, N: int):

    if N >= B:
        x = B - 1
    else:
        x = N

    m = (A*x // B) - A * (x // B)

    print(m)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8960
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    int cnt = 0;
    rep(i, N) {
        int tmp; cin >> tmp;
        if (cnt == 0) A[cnt++] = tmp;
        else {
            if (A[cnt - 1] == tmp) continue;
            else A[cnt++] = tmp;
        }
    }
    //rep(i, cnt) cout << A[i] << " ";
    int ans = 0;
    int k = 0;
    while(k < cnt) {
        ans++;
        if(A[k] < A[k + 1]) while(k < cnt && A[k] < A[k + 1]) k++;
        else if(A[k] > A[k + 1]) while(k < cnt && A[k] > A[k + 1]) k++;
        k++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n;
char s[N];
signed main()
{
	int cnt=0;ll ans=0;
	scanf("%s",s+1);n=strlen(s+1);
	for (int i=1;i<=n;i++)
	if (s[i]=='A') cnt++;
	else if (s[i]=='B')
	{
		if (s[i+1]=='C') i++,ans+=cnt;
		else cnt=0;
	}
	else cnt=0;
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//AAABCBCBC
//AABCABCBC
//ABCABCABC
//ABCABCBCA
//ABCBCABCA
//BCABCABCA
//BCBCABCAA
//BCBCBCAAA

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	map<vector<int>,int> mp;
	ll ans=0;
	rep(i,n){
		vector<int> vec(26,0);
		string s;cin>>s;
		rep(i,10) vec[s[i]-'a']++;
		ans+=mp[vec];
		mp[vec]++;
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 18944
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

ll lucas(ll n){
  vector<ll> ness(87);
  rep(i,87){
    if(i == 0){
      ness.at(i) = 2;
    }
    else if(i == 1){
      ness.at(i) = 1;
    }
    else{
      ness.at(i) = ness.at(i-1) + ness.at(i-2);
    }
  }
  return ness.at(n);  
}

int main() {
  ll N;
  cin >> N;
  cout << lucas(N) << endl;
}
  
  


Measured memory_bytes: 256
n=int(input()) 
a=list(map(int,input().split())); 
ans=1; 

x=10**18 
flag=0;
for i in a:
	if i==0:
		flag=1
		break

for i in a:
	ans=ans*i
	if ans>x:
		break
if flag==1:
	ans=0
if ans>x :
	print(-1) 
else:
	print(ans)

Measured memory_bytes: 21784
s=input()
cs=[]
cnt=1
pre=s[0]
for si in s[1:]:
  if si==pre:
    cnt+=1
  else:
    cs.append(cnt)
    pre=si
    cnt=1
cs.append(cnt)
n=len(s)
ans1=n
merge=0
no_merge=n
for i in range(len(cs)):
  merge+=cs[i]
  no_merge-=cs[i]
  tmp=max(merge,no_merge)
  ans1=min(ans1,tmp)
cs.reverse()
ans2=n
merge=0
no_merge=n
for i in range(len(cs)):
  merge+=cs[i]
  no_merge-=cs[i]
  tmp=max(merge,no_merge)
  ans2=min(ans2,tmp)
print(max(ans1,ans2))



Measured memory_bytes: 9496
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}

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

    bool ok = true;
    map<string, int> m;
    char moji;
    for (int ii = 0; ii < N; ++ii) {
        string w;
        cin >> w;
        if (ii > 0) {
            if (m[w] || w[0] != moji) {
                ok = false;
                break;
            }
        }
        m[w] = 1;
        moji = w[w.size() - 1];
    }
    if (ok) {
        cout << "Yes" << "\n";
    }
    else {
        cout << "No" << "\n";
    }
    return 0;
}

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

int check(int val) {
	int ret = 0;
	while (val) {
		ret += val % 10;
		val /= 10;
	}
	return ret;
}

int main() {
	int a, n, m; cin >> a >> n >> m;

	int cnt = 0;
	for (int i = 1; i <= 1000; ++i) {
		int tmp = i + a;
		int calc = pow(tmp, n);

		if (calc > m) break;
		if (i == check(calc)) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3276
/* EVERYTHING STARTS AS NOTHING ! :) */
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long
#define null NULL
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main (){
	int n , m;
	cin >> n >> m ;
	cout << (n*(n-1)/2) + (m*(m-1)/2) ;
	return 0 ;
}
		

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       		ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl 			"\n"

typedef long long int  ll;


int main()
{
	FAST;
	int temp;
	cin >> temp;

	int first = temp/100;
	int second = temp %100;

	if(first >= 1 && first <= 12)
	{
		if(second >= 1 && second <= 12)
			cout << "AMBIGUOUS";
		else
			cout << "MMYY";
	} 
	else 
	{
		if(second >= 1 && second <= 12)
				cout << "YYMM";
		else
			cout << "NA";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    // k 番目のノードについて遅延評価を行う
    void eval(int k, int l, int r) {

    // 遅延配列が空でない場合、自ノード及び子ノードへの
    // 値の伝播が起こる
        if(lazy[k] != 0) {
            node[k] += lazy[k];

        // 最下段かどうかのチェックをしよう
        // 子ノードは親ノードの 1/2 の範囲であるため、
        // 伝播させるときは半分にする
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }

        // 伝播が終わったので、自ノードの遅延配列を空にする
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;

    // k 番目のノードに対して遅延評価を行う
        eval(k, l, r);

    // 範囲外なら何もしない
        if(b <= l || r <= a) return;
    
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }

    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;

    // 関数が呼び出されたらまず評価！
        eval(k, l, r);

        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }

};



int main() {
    //cout.precision(10);
    int n, m;
    cin >> n >> m;
    priority_queue<i_i, vector<i_i>, greater<i_i> > que;
    for(int i = 1; i <= n; i++){
        int l, r;
        cin >> l >> r;
        que.emplace(r - l + 1, l);
    }
    vector<ll> v(m + 2);
    LazySegmentTree seg(v);
    int ans[300500];
    for(int i = 0; i <= m; i++){
        ans[i] = 0;
    }
    int ok = n;
    for(int i = 1; i <= m; i++){
        while(!que.empty()){
            i_i now = que.top();
            if(now.first >= i) break;
            int l = now.second;
            int r = now.first + now.second;
            //cout << 
            seg.add(l, r, 1);
            que.pop();
            ok--;
        }
        ans[i] = ok;
        for(int j = i; j <= m; j += i){
            ans[i] += seg.getsum(j, j + 1);
        }
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 10348
#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<pair<string,char>> solve(int n) {
    if (n == 1) return {{"a", 'a'}};
    vector<pair<string, char>> res, tmp = solve(n - 1);
    for (const pair<string, char> &s:tmp) {
        for (char c = 'a'; c <= s.second + 1; c++) {
            res.push_back({s.first + c, max(c, s.second)});
        }
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<pair<string, char>> res = solve(n);
    for (const pair<string, char> &s:res) cout << s.first << "\n";
    return 0;
}

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

int main() {

  int A,B,C,i,n=0,m=0;
  cin >> A >> B;
  
  while(B%2==0){
    n++;
    B/=2;
  }
  
  for(i=1;i<A;i++){
    cin >> C;
      while(C%2==0){
        m++;
        C/=2;
      }
        if(m<=n)n=m;
    m=0;
  }
    
  cout << n << endl;
}

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

using namespace std;

int main(){
    int x, y, s;
    while(cin >> x >> y >> s && !(x == 0 && y == 0 && s == 0) ) {
        int ans = INT_MIN;
        for(int i = 1; i <= s; i++) {
            for(int j = i; j <= s; j++) {
                int a = i * (100+x) / 100 ;
                int b = j * (100+x) / 100 ;
                if(a + b != s) continue;
                int c = i * (100+y) / 100 ;
                int d = j * (100+y) / 100 ;
                ans = max(ans, c + d);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	    int n;

	    cin >> n;

	    long long *a = new long long[n];

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

	    long long total = 1;

	    for(int i=0; i<n; ++i){
	    	if (a[i] == 0){
	    		total = 0;
	    		break;
	    	}
	    	if (total == -1){
	    	   continue;
	    	}
	    	if (((log10(total)) + (log10(a[i]))) >= 18){
	    		if (total * a[i] != 1000000000000000000){
	    			total = -1;
	    			continue;
	    		}
	    	}
	    	total *= a[i];
	    	if (total <= 1000000000000000000){
	    		continue;
	    	}
	    	else{
	    		total = -1;
	    	}
	    }


	    cout << total << endl;

	    return 0;
}


Measured memory_bytes: 4276
#include <stdio.h>

int main(){
    long long a,b,c;
    scanf("%lld %lld %lld", &a, &b, &c);
    
    long long max = (a >= b ? a : b) >= c ? (a >= b ? a : b) : c;
    long long mm  = a + b + c - max;
    if(max == mm){
        printf("Yes");
    }else{
        printf("No");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll INF=1000000000000;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N,0);
    vector<ll> b(N,0);
    vector<ll> c(N,0);
    vector<ll> maxA(N,0);
    vector<ll> maxB(N,0);
    vector<ll> maxC(N,0);
    for(ll i=0;i<N;i++){
        cin>>a[i]>>b[i]>>c[i]
    ;}
    maxA[0]=a[0];
    maxB[0]=b[0];
    maxC[0]=c[0];
    for(ll i=1;i<N;i++){
        maxA[i]=max(maxB[i-1]+a[i],maxC[i-1]+a[i]);
        maxB[i]=max(maxA[i-1]+b[i],maxC[i-1]+b[i]);
        maxC[i]=max(maxA[i-1]+c[i],maxB[i-1]+c[i]);
    ;}
    cout<<max(max(maxA[N-1],maxB[N-1]),maxC[N-1])<<endl;
return 0;
}


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

int main()
{
	int n, p;
	cin >> n >> p;
	int a[2] = {0};
	while (n--)
	{
		int x; cin >> x;
		a[x & 1]++;
	}
	cout << (1LL << a[0]) * (a[1] == 0 ? (p ? 0 : 1) : 1LL << (a[1] - 1)) << "\n";
}


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

main(){
  int N[4];
  for(int ii=0;ii<4;ii++){
    cin >> N[ii];
  }
  sort(N,N+4);
  if(N[0]==1&&N[1]==4&&N[2]==7&&N[3]==9)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define repd(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
const ll INFL = (1ll << 62) - 1;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//_____________________________________Templates_________________________________________//

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

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k;
//vvll dp(400, vll(400));
string S;
vll cost(1 << 16);
int a,b,c;
int h,w;
vvi v;
vi u;
int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(n);
  u = vi(n);
  rep(i,n){
    int a;IN(a);
    if(a%2 == 0){
      if(a % 3 == 0 || a % 5 == 0){
        continue;
      }
      else {
        OUT("DENIED");
        return 0;
      }
    }
  }
  OUT("APPROVED");
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>
#include <vector>


int main() {
    size_t N;
    scanf("%zu", &N);

    std::vector<int> a(N);
    for (size_t i=0; i<N; ++i)
        scanf("%d", &a[i]);

    std::sort(a.begin(), a.end());

    printf("%d\n", a.back()-a.front());
    return 0;
}



Measured memory_bytes: 256
class Dice:
    val=[]
    def __init__(self, lst):
        self.val.append(lst[0])
        self.val.append(lst[1])
        self.val.append(lst[2])
        self.val.append(lst[3])
        self.val.append(lst[4])
        self.val.append(lst[5])

    def rotate(self,dir):
        if dir=="N":
            tmp=self.val[0]
            self.val[0]=self.val[1]
            self.val[1]=self.val[5]
            self.val[5]=self.val[4]
            self.val[4]=tmp
        if dir=="E":
            tmp=self.val[0]
            self.val[0]=self.val[3]
            self.val[3]=self.val[5]
            self.val[5]=self.val[2]
            self.val[2]=tmp
        if dir=="S":
            tmp=self.val[0]
            self.val[0]=self.val[4]
            self.val[4]=self.val[5]
            self.val[5]=self.val[1]
            self.val[1]=tmp
        if dir=="W":
            tmp=self.val[0]
            self.val[0]=self.val[2]
            self.val[2]=self.val[5]
            self.val[5]=self.val[3]
            self.val[3]=tmp


x = list(map(int,input().split()))
char = list(input())
#print(char)

D = Dice(x)

for word in char:
    D.rotate(word)

print(D.val[0])



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

N, s, t = map(int, input().split())
s -= 1
t -= 1
to = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

def dfs(dist, v, d=0, p=-1):
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(dist, u, d+1, v)

def calcDist(s):
    dist = [0] * N
    dfs(dist, s)
    return dist

distS = calcDist(s)
distT = calcDist(t)

mx = 0
for i in range(N):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(ll i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))
ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}


void solve()
{
    ll n,W;
    cin>>n>>W;
    vll w(n+1,0), v(n+1,0);
    srep(i,1,n)
    cin>>w[i]>>v[i];

    ll dp[n+1][W+1];
    set0(dp);

    for(int i=1;i<=n;i++)
    {
        for(int j=1; j<=W ; j++)
        {
            if(w[i]<=j)
            {
                dp[i][j] = max(dp[i-1][j], v[i]+dp[i-1][j-w[i]]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout<<dp[n][W];


}

int main()
{
    fastio;
    /*int t;
    cin>>t;
    
    rep(i,t)
    {*/
        solve();
        cout<<"\n";
    //}
    return 0;
}

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

int main(){
  const string wl = "....................................................................................................";
  const string bl = "####################################################################################################";
  string Grid[100];
  for(int i=0; i<50; i++)Grid[i] = bl;
  for(int i=50; i<100; i++)Grid[i] = wl;
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  int gyou, retu;
  gyou = 1;
  retu = 0;
  while(a>0){
    Grid[gyou][retu] = '.';
    a--;
    retu += 2;
    if(retu>=100){
      retu = 0;
      gyou += 2;
    }
  }
  gyou = 51;
  retu = 0;
  while(b>0){
    Grid[gyou][retu] = '#';
    b--;
    retu += 2;
    if(retu>=100){
      retu = 0;
      gyou += 2;
    }
  }
  cout << 100 << ' ' << 100 << endl;
  for(int i=0; i<100; i++){
    cout << Grid[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    static long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int res = m;
        long ans = 1;
        for (int i = 2; i * i <= res; i++) {
            int cnt = 0;
            while (res % i == 0) {
                cnt++;
                res /= i;
            }
            ans *= calcComb(cnt + n - 1, n - 1);
            ans %= MOD;
        }
        if (res != 1) {
            ans *= calcComb(n, 1);
            ans %= MOD;
        }
        System.out.println(ans);
    }
    public static long calcComb(int n, int k) {
        if (k > n - k) {
            return calcComb(n, n - k);
        }
        long ansMul = 1;
        long ansDiv = 1;
        for (int i = 0; i < k; i++) {
            ansMul *= (long) (n - i);
            ansDiv *= (long) (i + 1);
            ansMul %= MOD;
            ansDiv %= MOD;
        }
        long ans = ansMul * pow(ansDiv, MOD - 2);
        ans %= MOD;
        return ans;
    }
    public static long pow(long x, long n) {
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans = ans * x % MOD;
            }
            x = x * x % MOD;
            n >>= 1;
        }
        return ans;
    }
}


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

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

    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for(int64_t i=0; i<N; i++){
        int64_t buf;
        std::cin >> buf;
        A.push_back(buf);
    }

    std::sort(A.begin(), A.end());

    if(A.front()==0){
        std::cout << 0;
        return 0;
    }

    const int64_t INF=std::pow(10, 18);
    int64_t ans=1;
    for(int64_t i=0; i<N; i++){
        if(ans<=(INF/A.at(i))){
            ans = ans * A.at(i);
        }else{
            std::cout << -1;
            return 0;
        }
    }

    std::cout << ans;
    return 0;
}


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

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

  int ans = 0;
  for (int i = 1; i < 33; i++) {
    for (int j = 2; j < 11; j++) {
      if (pow(i, j) <= n && pow(i, j) > ans) {
        ans = pow(i, j);
      }
    }
  }
  cout << ans << endl;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int N, W;
int value[110], weight[110];
int dp[110][10010];

void print() {
   rep (i, 0, N+1) {
      rep (j, 0, W+1) {
         printf("%3d", dp[i][j]);
      }
      puts("");
   }
}

int main() {
   cin >> N >> W;
   rep (i, 0, N) {
      cin >> value[i] >> weight[i];
   }

   rep (i, 0, N) {
      rep (j, 0, W+1) {
         if (weight[i] <= j) {
            dp[i+1][j] = 
               max(dp[i][j-weight[i]] + value[i], dp[i][j]);
         } else {
            dp[i+1][j] = dp[i][j];
         }
      }
   }

   cout << dp[N][W] << endl;

   return 0;
}


Measured memory_bytes: 7008
n = int(input())
result = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(n):
  s = input()
  result[s] = result[s] + 1

print('AC x {}'.format(result['AC']))
print('WA x {}'.format(result['WA']))
print('TLE x {}'.format(result['TLE']))
print('RE x {}'.format(result['RE']))

Measured memory_bytes: 9144
a = int(input())
b =[a]
n=1
for i in range(1000000):
  if a%2 == 0 :
    a=a/2
  else:
    a=3*a+1
  n+=1
  b.append(a)
  if b.count(a)==2:
    print(n)
    break


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

const int mod = 1e9+7;

int main(){ 
  int N, M;
  cin >> N >> M;
  vector<int> a(M), dp(N+4, 0);
  REP(i, M){
    cin >> a[i];
  }
  dp[0] = 1;
  int idx = 0;
  REP(i, N){
    if(idx < M && a[idx] == i){
      idx++;
    }
    else{
      dp[i+1] += dp[i];
      dp[i+2] += dp[i];
      dp[i+1] %= mod;
      dp[i+2] %= mod;
    }
  }
  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a,b,c,d;cin>>a>>b;cin>>c>>d;cout<<c-a<<endl;
}


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

long long ct(long long a, long long b, long long c){
  long long ct1 = (a % c == 0) ? a / c : (a + c) / c, ct2 = b / c;
  return ct2 - ct1 + 1;
}

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long lcm = (c * d) / (long long)__gcd(c, d);
  long long ans = ct(a, b, c) + ct(a, b, d) - ct(a, b, lcm);
  cout << b - a + 1 - ans << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {
  lli A,B,T;
  
  cin >> A >> B >> T;
  
  COUT(B * ((T) / A));
  
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N;
    int sum;
    int i,j;
    
    scanf("%d %d",&N,&sum);
    
    for(i=0;i<N+1;i++){
        for(j=0;j<N-i+1;j++){
            if(sum==10000*i+5000*j+1000*(N-i-j)){
                printf("%d %d %d",i,j,N-i-j);
                return 0;
            }
        }
    }
    
    printf("-1 -1 -1");
    
    return 0;
}

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

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

const int INF = 1000000007;

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

	if(b % a == 0) cout<< a + b <<endl;
	else cout<< b - a <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n;cin >> n;
    vector<LL> x(n),y(n);
    map<P,int> ma;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        ma[mp(x[i],y[i])]++;
    }
    vector<P> v;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if(i==j) continue;
            v.pb(mp(x[i]-x[j],y[i]-y[j]));
        }
    }
    LL ans = n;
    for (int i = 0; i < v.size(); i++) {
        P p = v[i];
        LL tmp = n;
        for (int j = 0; j < n; j++) {
            if(ma[mp(x[j]+p.fs,y[j]+p.sc)]) tmp--;
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096