akhauriyash/Code-Regression huggingface dataset:
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	string S;
	cin >> S;
	int ans = 0;
	int count = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
			count++;
			chmax(ans, count);
		}
		else {
			count = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
print(" ".join(list(map(str,A))))
for i in range(1,N):
    v= A[i]
    j= i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(" ".join(list(map(str,A))))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


int main(void){
cout<<fixed<<setprecision(14);
//cin.tie(0); ios::sync_with_stdio(false);

string S;cin>>S;
  S[3]='8';
  cout<<S<<endl;
  
}



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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n,wei;
    int maxv=-1;
    int v[105]={};
    int w[105]={};
    cin>>n>>wei;
    REP(i,n)cin>>v[i]>>w[i];

    int mat[105][10005];
    REP(i,105)REP(j,10005)mat[i][j]=-(1<<30);
    mat[0][0]=0;
    REP(i,n)REP(j,wei+1){
        if(j<w[i])mat[i+1][j]=mat[i][j];
        else mat[i+1][j] = max(mat[i][j], mat[i][j-w[i]]+v[i]);
        if(maxv<mat[i+1][j])maxv=mat[i+1][j];
    }
    cout<<maxv<<endl;
    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    ll dp[40];
    while(cin>>n){
        if(n==0)break;
        
        rep(i,40)dp[i] = 0;
        dp[0]=1;
        rep(i,35){
            dp[i+1]+=dp[i];
            dp[i+2]+=dp[i];
            dp[i+3]+=dp[i];
        }
        ll ans = dp[n];
        ans = ceil(ans/3650.0);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int a[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int i,j,X,K,Q;
    cin>>X>>K;
    for(i=1; i<=K; i++)
        cin>>a[i];
    int L,R=X;
    int cnt=0,k=0,s=-1,x=0,ans,num;
    int t,A;
    cin>>Q;
    for(i=1; i<=Q; i++)
    {
        cin>>t>>A;
        while(k<K&&a[k+1]<=t)
        {
            ans=s*(a[k+1]-cnt);
            L=max(0,min(X,L+ans));
            R=max(0,min(X,R+ans));
            cnt=a[k+1];
            s=-s;
            x+=ans;
            k++;
        }
        num=t-cnt;
        A=max(L,min(R,A+x));
        A=max(0,min(X,A+s*num));
        cout<<A<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, N: int):
    x = min(B-1, N)
    print(math.floor(A*x/B) - A*math.floor(x/B))
    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: 9196
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int maxx = -1;

  for (int i = 0; i < n; i++) {
    if ((char)s[i] == 'I') {
      x++;
    } else if ((char)s[i] == 'D') {
      x--;
    }
    if (x > maxx) {
      maxx = x;
    }
  }
  cout << max(0, maxx) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, m;
llint s[2005], t[2005];
llint dp[2005][2005];
llint sum[2005][2005];

int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> s[i];
	for(int i = 1; i <= m; i++) cin >> t[i];
	
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i] == t[j]){
				dp[i][j] = sum[i-1][j-1] + 1;
				dp[i][j] %= mod;
			}
			sum[i][j] = sum[i-1][j] + sum[i][j-1] + mod - sum[i-1][j-1] + dp[i][j];
			sum[i][j] %= mod;
		}
	}
	cout << sum[n][m]+1 << endl;
	
	return 0;
}

Measured memory_bytes: 62848
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        Solve();
        Out.Flush();
    }
    //ここにプログラムを入力
    static void Solve()
    {
        int N = int.Parse(ReadLine());
        var A = new int[N];
        var B = new int[N];
        for (int i = 0; i < N; i++)
        {
            var r = ReadLine().Split();
            A[i] = int.Parse(r[0]);
            B[i] = int.Parse(r[1]);
        }
        Array.Sort(A);
        Array.Sort(B);
        if (N % 2 == 0)
        {
            WriteLine((B[N/2]+B[N/2-1])-(A[N/2]+A[N/2-1])+1);
        }
        else
        {
            WriteLine(B[N/2]-A[N/2]+1);
        }

    }
}


Measured memory_bytes: 47512
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, q, com, s, t, x;

const int INF = (1LL << 31) - 1;
const int sqrtN = 512;
struct SqrtDecomposition {
	int N, K;
	vector<int> data;
	vector<int> bucketMin;
	vector<bool> lazyFlag;
	vector<int> lazyUpdate;
	SqrtDecomposition(int n) : N(n) {
		K = (N + sqrtN - 1) / sqrtN;
		data.assign(K * sqrtN, INF);
		bucketMin.assign(K, INF);
		lazyFlag.assign(K, false);
		lazyUpdate.assign(K, 0);
	}
	void eval(int k) {
		if (lazyFlag[k]) {
			lazyFlag[k] = false;
			for (int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
				data[i] = lazyUpdate[k];
			}
		}
	}
	// [s, t)
	void update(int s, int t, int x) {
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= s || t <= l)
				continue;
			if (s <= l && r <= t) {
				bucketMin[k] = x;
				lazyFlag[k] = true;
				lazyUpdate[k] = x;
			}
			else {
				eval(k);
				for (int i = max(s, l); i < min(t, r); ++i) {
					data[i] = x;
				}
				int& minVal = bucketMin[k] = INF;
				for (int i = l; i < r; ++i) {
					minVal = min(minVal, data[i]);
				}
			}
		}
	}
	// [s, t)
	int find(int s, int t) {
		int minVal = INF;
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= s || t <= l)
				continue;
			if (s <= l && r <= t) {
				minVal = min(minVal, bucketMin[k]);
			}
			else {
				eval(k);
				for (int i = max(s, l); i < min(t, r); ++i) {
					minVal = min(minVal, data[i]);
				}
			}
		}
		return minVal;
	}
};

int main() {
	cin >> n >> q;
	SqrtDecomposition rmqRuq(n);
	rep(i, q) {
		cin >> com;
		if (com == 0) {
			cin >> s >> t >> x;
			rmqRuq.update(s, t + 1, x);
		}
		else {
			cin >> s >> t;
			cout << rmqRuq.find(s, t + 1) << endl;
		}
	}
	return 0;
}


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

int H, W;
int wall;
int M[102][102];
bool visited[102][102];

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

bool isInField(int x, int y) {
  return 0<=x&&x<=W+1 && 0<=y&&y<=H+1;
}

void dfs(int x, int y){

  if(visited[y][x]) return;
  visited[y][x] = true;

  for(int i=0; i<6; i++) {
    int nx = x+dx[y%2][i], ny = y+dy[y%2][i];
    if(isInField(nx, ny)) {
      if(M[ny][nx]) wall ++;
      else dfs(nx, ny);
    }
  }
}

int main(){

  fill(M[0], M[102], 0);
  fill(visited[0], visited[102], false);

  cin >> W >> H;

  for(int i=1; i<=H; i++) {
    for(int j=1; j<=W; j++) {
      cin >> M[i][j];
    }
  }
  
  wall = 0; dfs(0, 0);
  cout << wall << endl;
  
  return 0;
}

Measured memory_bytes: 1456
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;

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


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

    
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    dsu d(n);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        d.merge(a[i],b[i]);
    }
    int ans=0;
    rep(i,n-1){
        if(!d.same(0,i+1)){
            ans++;
            d.merge(0,i+1);
        }
    }
    cout<<ans<<endl;






}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    if a == b {
        println!("{}", 2 * a);
    } else {
        let max = std::cmp::max(a, b);
        println!("{}", 2 * max - 1);
    }
}


Measured memory_bytes: 4352
n, k = gets.split(' ').map(&:to_i)
arr = gets.split(' ').map(&:to_i)
 
ds = [0]
(1...n).each do |i|
  m = nil
  [0, i-k].max.upto(i-1) do |j|
    tmp = ds[j] + (arr[j] - arr[i]).abs
    m = tmp if !(m && m < tmp)
  end
  ds << m
end

puts ds[-1]

##備忘として他の方のコードを提出させていただきます

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

int n,m,ac,pena;
int a[110000][2];

main()
{
        cin>>n>>m;
        rep(i,m)
        {
                int k;
                string s;
                cin>>k>>s;
                if(s=="WA" && a[k-1][0]!=-1)
                {
                        a[k-1][1]++;
                }
                if(s=="AC")
                {
                        a[k-1][0]=-1;
                }
        }
        for(auto it : a)
        {
                if(it[0]==-1)
                {
                        ac++;
                        pena+=it[1];
                }
        }
        cout<<ac<<endl<<pena<<endl;
}


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

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

    ll ans = 0;
    queue<ll> a;
    for(ll i = 1; i < 10; i++){
        a.push(i);
    }

    for(int i = 0; i < k; i++){
        ll p = a.front();
        ans = p;
        a.pop();
        ll m = p % 10;
        p *= 10;

        if(m != 0){
            m--;
            p += m;
            a.push(p);
            p -= m;
            m++;
        }

        p += m;
        a.push(p);
        p -= m;

        if(m != 9){
            m++;
            p += m;
            a.push(p);
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cmath>

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
class P{
public:
	int n;
	string s;
	int index;
	bool operator<(P x){
		return n < x.n;
	}
};

int main(){
	int n;string str;
	P A[36],B[36];
	cin >> n;
	REP(i,n){
		cin >> str;
		A[i].s=str;
		A[i].n=str[1];
		A[i].index=i;
		B[i] = A[i];
	}
	REP(i,n){
		for(int j=n-1;j>i;j--){
			if(A[j] < A[j-1]) swap(A[j],A[j-1]);
		}
	}
	REP(i,n){
		int minj=i;
		for(int j=i+1;j<n;j++){
			if(B[j] < B[minj])minj=j;
		}
		swap(B[i],B[minj]);
	}
	bool a=true,b=true;
	REP(i,n-1){
		if(A[i].n==A[i+1].n && A[i].index > A[i+1].index) a=false;
		if(B[i].n==A[i+1].n && B[i].index > B[i+1].index) b=false;
	}
	cout << A[0].s;
	REP(i,n-1){
		cout << " " << A[i+1].s;
	}
	cout << endl << (a?"Stable":"Not Stable") << endl;
	cout << B[0].s;
	REP(i,n-1){
		cout << " " << B[i+1].s;
	}
	cout << endl << (b?"Stable":"Not stable") << endl;
	return 0;
}

Measured memory_bytes: 3124
N, M = map(int, input().split())
H = list(map(int, input().split()))
roots = [list(map(int, input().split())) for _ in range(M)]
observatories = [1] * N
for root in roots:
    a = root[0] - 1
    b = root[1] - 1
    if H[a] < H[b]:
        observatories[a] = 0
    elif H[a] > H[b]:
        observatories[b] = 0
    else:
        observatories[a], observatories[b] = 0, 0
print(observatories.count(1))


Measured memory_bytes: 32004
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

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

int main(){
  ll N,ans=0;
  cin>>N;
  COMinit();
  ll cnt[N];
  REP(i,N) cnt[i]=0;
  
  for(ll i=(N+1)/2; i<=N-1; ++i){
    cnt[i]=fac[i]*fac[i-1];
    cnt[i]%=MOD;
    cnt[i]*=finv[2*i-N];
    cnt[i]%=MOD;
    ans+=(cnt[i]-cnt[i-1])*i;
    ans%=MOD;
  }
  
  if(ans<0) ans+=MOD;
  co(ans);
  return 0;
}

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

const int N = 1e5+5;

int n;
int arr[N];
long op1, op2;
long sum1, sum2;

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", arr+i);
    sum1 += arr[i], sum2 += arr[i];
    if(i & 1) {
      if(sum1 <= 0) op1 += abs(sum1)+1, sum1 = 1;
      if(sum2 >= 0) op2 += abs(sum2)+1, sum2 = -1;
    } else {
      if(sum1 >= 0) op1 += abs(sum1)+1, sum1 = -1;
      if(sum2 <= 0) op2 += abs(sum2)+1, sum2 = 1;
    }
  }
  printf("%lld\n", min(op1, op2));
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int q;
    cin >> q;
    priority_queue<ll> ql;
    priority_queue<ll, vector<ll>, greater<ll>> qr;
    ll bsum = 0;
    ll qlsum = 0;
    ll qrsum = 0;
    for(int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        if(x == 1)
        {
            int a, b;
            cin >> a >> b;
            bsum += b;
            if(!ql.empty() && ql.top() >= a)
            {
                ql.push(a);
                qlsum += a;
                if(ql.size() > qr.size()+1)
                {
                    int tmp = ql.top();
                    ql.pop();
                    qr.push(tmp);
                    qlsum -= tmp;
                    qrsum += tmp;
                }
            }
            else
            {
                qr.push(a);
                qrsum += a;
                if(qr.size() > ql.size()+1)
                {
                    int tmp = qr.top();
                    qr.pop();
                    ql.push(tmp);
                    qrsum -= tmp;
                    qlsum += tmp;
                }
            }
        }
        if(x == 2)
        {
            int cand = 0;
            if(ql.size() == qr.size() || ql.size() > qr.size())
            {
                cand = ql.top();
            }
            else
            {
                cand = qr.top();
            }
            ll ans = 0;
            ans += cand * ql.size() - qlsum;
            ans += qrsum - cand * qr.size();
            cout << cand << " " << ans + bsum << endl;
        }
    }
}


Measured memory_bytes: 3828
N = int(input())
h = list(map(int, input().split()))
accumulated_cost = list(float('inf') for i in range(N))

def chmin(x, y):
    if x > y:
        accumulated_cost[i] = y

for i in range(N):
    if i == 0:
        accumulated_cost[i] = 0
    elif i == 1:
        accumulated_cost[i] = abs(h[i] - h[0])
    else:
        chmin(accumulated_cost[i], accumulated_cost[i-1] + abs(h[i] - h[i-1]))
        chmin(accumulated_cost[i], accumulated_cost[i-2] + abs(h[i] - h[i-2]))

print(accumulated_cost[N-1])


Measured memory_bytes: 13784
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <map>


int prepare(vi &shita, vi &ue, const string &s, int N)
{
    int pop = 0;
    for (size_t i = 0; i < s.size(); i++)
        pop += (s[i] - '0');

    if (pop == 1)
        for (int i = 0; i <= N; i++)
            shita[i] = 0;

    int k_ue = 1, k_shita = 1;
    int m_ue = 0, m_shita = 0;

    size_t i = N;
    while (i-- > 0)
    {
        int ii = s[i] - '0';
        if (pop > 1)
        {
            shita[i] = k_shita;
            k_shita = (k_shita * 2) % (pop - 1);
            m_shita = (m_shita + ii * shita[i]) % (pop - 1);
        }
        
        ue[i] = k_ue;
        k_ue = (k_ue * 2) % (pop + 1);
        m_ue = (m_ue + ii * ue[i]) % (pop + 1);
    }

    shita[N] = m_shita;
    ue[N] = m_ue;
    return pop;
}

int main()
{
    int N;
    string X;
    io >> N >> X;

    vi s(N+1), u(N+1);
    int pop = prepare(s, u, X, N);

    vi aans(N);

    for (int i = 0; i < N; i++)
    {
        int ans, mm;
        if (X[i] == '0')
        {
            int mod = pop + 1;
            ans = 1;
            mm = (u[N] + u[i]) % mod;
        }
        else if (pop == 1)
        {
            ans = 0;
            mm = 0;
        }
        else
        {
            int mod = pop - 1;
            ans = 1;
            mm = (s[N] - s[i] + mod) % mod;
        }

        while (mm > 0)
        {
            mm = mm % __builtin_popcount(mm);
            ++ans;
        }
        io << ans << BR;
    }
    
}

Measured memory_bytes: 6088
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 + 3000;
ll memo[MAXN][MAXN][2];
int N;
int arr[MAXN];

ll dp(int i, int j, bool t) {
    if(i > j) return 0LL;
    ll& ans = memo[i][j][t];
    if(ans == -1) {
        if(t) {
            ans = max(arr[i] + dp(1 + i, j, !t), arr[j] + dp(i, j - 1, !t));
        } else {
            ans = min(dp(1 + i, j, !t) - arr[i], dp(i, j - 1, !t) - arr[j]);
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    foi(i,0,N) {
        cin >> arr[i];
    }
    memset(memo, -1, sizeof memo);
    cout << dp(0, N - 1, true) << '\n';
    return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int x,y;
	cin>>x>>y;
	if((y-(2*x))%2!=0||((4*x)-y)%2!=0||(y-(2*x))<0||((4*x)-y)<0){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
	return 0;
}

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

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) {
    cin >> x.at(i);
  }
  int64_t sum = 0;
  int64_t minsum = 10000000000000;
  
  for (int i = 1; i < 101; i++) {
    rep(j, n) {
      sum += (x.at(j) - i) * (x.at(j) - i);
    }
    if (minsum > sum) {
      minsum = sum;
    }
    sum = 0;
  }
  cout << minsum << endl;
    
  
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char number[1001];
  int sum,i;

  while(1){
    sum = 0;
    scanf("%s",number);

    if(number[0]=='0') break;
      
    for(i=0; number[i]!='\0'; i++)
      sum += number[i] - '0';

    printf("%d\n",sum);
  }
  
  return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char LF    = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int K, S; cin >> K >> S;
  int ans{};
  for(int X = 0; X <= K; ++X)
  {
    for(int Y = 0; Y <= K; ++Y)
    {
      if(X + Y > S)
        continue;
      auto Z = S - (X + Y);
      if(0 <= Z && Z <= K)
      {
        ++ans;
      }
    }
  }

  cout << ans << LF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
C = [None] * N

for n in range(N):
    a, b = map(int, input().split())
    C[n] = (a, b)

C.sort()
m = 0
res = 0

for c in C:
    buy = min(c[1], M-m)
    m += buy
    res += c[0] * buy
    if m == M:
        break

print(res)


Measured memory_bytes: 16980
from collections import deque

def bfs():
    q = deque()
    st = [1, 1]
    go = [h, w]
    q.append(st)
    d[1][1] = 1
    v = [1, -1]
    while q:
        u = q.popleft()
        x, y = u[0], u[1]
        for i in range(2):
            if s[x + v[i]][y] == "." and d[x + v[i]][y] == 0:
                q.append([x + v[i], y])
                d[x + v[i]][y] = d[x][y] + 1
        for i in range(2):
            if s[x][y + v[i]] == "." and d[x][y + v[i]] == 0:
                q.append([x, y + v[i]])
                d[x][y + v[i]] = d[x][y] + 1
    c = 0
    for i in s:
        for j in i:
            if j == ".":
                c += 1
    if d[h][w] == 0:
        return -1
    return c - d[h][w]

h, w = map(int, input().split())
s = [["#"] + list(input()) + ["#"] for _ in range(h)]
t = ["#" for _ in range(w + 2)]
s.append(t)
s.insert(0, t)
d = [[0 for _ in range(w + 2)] for _ in range(h + 2)]
print(bfs())

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        
        
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = input[0];
            int Y = input[1];
            int Z = input[2];
            int K = input[3];
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var b = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Array.Sort(a);
            Array.Reverse(a);
            Array.Sort(b);
            Array.Reverse(b);
            Array.Sort(c);
            Array.Reverse(c);

            List<long> ans = new List<long>();
            for(var i = 0; i < X; i++)
            {
                for(var j = 0; j < Y; j++)
                {
                    for(var k = 0; k < Z; k++)
                    {
                        if ((i + 1) * (j + 1) * (k + 1) <= K)
                        {
                            ans.Add(a[i] + b[j] + c[k]);

                        }
                        else { break; }
                    }
                }
            }

            ans.Sort();
            ans.Reverse();

            for(var i = 0; i < K; i++)
            {
                Console.WriteLine(ans[i]);
            }

            //Console.Out.Flush();

        }

        
    }

    public class Calculation
    {

    }

    public class Graph
    {
        
    }
}




Measured memory_bytes: 15584
MOD = pow(10, 9) + 7
s = input()
n = len(s)
dp = [[0 for _ in range(4)] for _ in range(n + 1)]

dp[0][0] = 1
for i in range(n):
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][1]
    dp[i+1][2] = dp[i][2]
    dp[i+1][3] = dp[i][3]
    if s[i] == 'A':
        dp[i+1][1] += dp[i][0]
    elif s[i] == 'B':
        dp[i+1][2] += dp[i][1]
    elif s[i] == 'C':
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][0] = dp[i][0] * 3
        dp[i+1][1] = dp[i][1] * 3
        dp[i+1][2] = dp[i][2] * 3
        dp[i+1][3] = dp[i][3] * 3
        dp[i+1][1] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][3] += dp[i][2]
    dp[i+1][0] %= MOD
    dp[i+1][1] %= MOD
    dp[i+1][2] %= MOD
    dp[i+1][3] %= MOD

print(dp[n][3])


Measured memory_bytes: 27596
from collections import deque



H,W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 0
dyx = [(1,0), (0,1),(-1,0), (0,-1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        dist = [[0 for _ in range(W)] for _ in range(H)] 
        visited = [[False for _ in range(W)] for _ in range(H)]
        visited[i][j] = True
        q = deque()
        q.append((i,j))
        while q:
            y,x = q.popleft()
            for dy,dx in dyx:
                ny, nx = y+dy, x+dx
                if not 0 <= nx < W: continue
                if not 0 <= ny < H: continue
                if visited[ny][nx]: continue
                if S[ny][nx] == '#': continue
                q.append((ny, nx))
                dist[ny][nx] = dist[y][x] + 1
                visited[ny][nx] = True

        """
        for i in range(H):
            ans = max(ans, max(dist[i]))
        """
        ans = max(ans, max(max(row) for row in dist))

            

print(ans)

Measured memory_bytes: 47964
#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)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;

int N;

// remark[i]:= 人iの発言をvector<pii>で表現
// 例：remark[3]:= {(0,1), (4,0), (2,1)}
vector<vector<pii>> remark;

int main()
{
cin >> N;
remark.resize(N);
rep(i,N) {
    int A;
    cin >> A;
    remark[i].resize(A);
    rep(j,A) {
        int x,y;
        cin >> x >> y;
        --x; // 0-index化
        remark[i][j] = {x, y};
    }
}

int ans = 0;
    for (int bit = 0; bit < (1<<N); ++bit) {
        bool ok = true;
        int cnt = 0;
        // N人全員の発言の整合性を確認し、ひとつでも矛盾があればok = falseにする
        for (int i = 0; i < N; ++i) {
             if ( !(bit & (1<<i))) continue;
            // 人iが正直者であるときのみ発言内容をチェックする
            cnt++;
            // remark[i]にpair型で発言内容が入っている
            for(auto p : remark[i]) {
                // p.firstさんが正直者かつp.secondが0ならその発言は誤り
                if(bit & (1 << p.first) && p.second == 0) ok = false;
                // p.firstさんが不親切かつp.secondが1ならその発言は誤り
                if(!(bit & (1 << p.first)) && p.second == 1) ok = false;
            }
        }
        // ok = trueなら整合性がとれているので答えの候補になる
        if(ok) ans = max(ans, cnt);
    }
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
def calc_mp(C, candidates, n, ans):
    for i in range(len(candidates)):
        candidates2 = [c for c in candidates]
        c = candidates[i]
        del candidates2[i]
        a = C[n][c]
        if c != 1:
            a += calc_mp(C, candidates2, c, ans)
        ans = min(a, ans)
    return ans

def main():
    H, W = map(int, input().split())
    C = [0]*10
    for i in range(10):
        C[i] = list(map(int, input().split()))
    A = [0]*H
    for i in range(H):
        A[i] = list(map(int, input().split()))
    # print(H, W, C, A)

    MPs = [0]*10
    for i in range(10):
        if i != 1:
            candidates = [j for j in range(10)]
            del(candidates[i])
            MPs[i] = calc_mp(C, candidates, i, 1000)
    # print(MPs)
    ans = 0
    for h in range(H):
        for w in range(W):
            a = A[h][w]
            if a != -1:
                ans += MPs[a]
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#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++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    int n = N-1;
    while(n>=0){
        cout << A[n] << " ";
        n -= 2;
    }
    if(n== -2) n = 1;
    else n = 0;
    while(n<=N-1){
        cout << A[n] << " ";
        n += 2;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll X,Y;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>X>>Y;
	ll ans;
	if(Y==-1 || X%Y==0){
		ans=-1;
	}else{
		ans=X;
	}
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n,m,a[30]={0},b[30]={0};

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

	vector<int> v(n-1);
	for(int i = 0; i < n-1; i++)
	{
		v[i] = i+2;
	}

	int sol = 0;

	do {

		int cnt = 0;
        for(int i = 0; i < m; i++)
        {
        	if (a[i] == 1 && b[i] == v[0])
        	{
        		cnt++;
        	}
        	for(int j = 0; j < n-1; j++)
        	{
        		if(j != n-2)
        		{
        			if ((a[i] == v[j] && b[i] == v[j+1]) || ( b[i] == v[j] && a[i] == v[j+1]))
        			{
        				cnt++;
        			}
        		}
        	}
        }

        if (cnt == n-1)
        {
        	sol++;
        }
    } while( next_permutation(v.begin(), v.end()) );

    printf("%d\n", sol);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int x;
  cin >> x;
  int ans = 1;
  FOR(i, 2, 33)
  {
    int y = i * i;
    if (y > x)
      break;
    while (y <= x)
    {
      y = y * i;
    }
    y /= i;
    ans = max(ans, y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    int n, m, k;
    int max_1 = 0, max_2 = 0;
    cin >> n;
    vector<int> a(n);

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

    if (a[0] > a[1])
    {
        max_1 = 0;
        max_2 = 1;
    }
    else
    {
        max_1 = 1;
        max_2 = 0;
    }

    for (int i = 2; i < n; i++)
    {
        if (a[i] > a[max_1])
        {
            max_2 = max_1;
            max_1 = i;
        }
        else if (a[i] > a[max_2])
        {
            max_2 = i;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (i == max_1)
            cout << a[max_2] << endl;
        else
            cout << a[max_1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int A, B;
	char op;
	cin >> A >> op >> B;

	if(op=='+'){
		cout << A + B << endl;
	}else{
		cout << A - B << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val YES = "Yes"
const val NO = "No"
fun solve(N: Long, A: Long){
    println(if(N%500 <= A) YES else NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = sc.next().toLong()
    solve(N, A)
}



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

int main() {
  int n,c=0,x=0,mm=0,p=-1,q=-1;;
  //n=s.length();
  string s;
  cin>>s;
   n=s.length();
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='A' &&p<0)
    {
         p=i;
    }
    if(s[n-1-i]=='Z' && q<0)
    {
      q=n-1-i;
     // cout<<"h"<<endl;
    }
  }

  //cout<<"p "<<p<<" "<<q<<endl;
  cout<<abs(q-p+1)<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    ll ans = 0;
    rep(i, n){
        ll in;
        cin >> in;
        ans += in-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)
if N < 3:
    print("0")
else:
    cnt = 0
    row_A = 0 #Aの連続する個数
    target = "BC"
    index = 0
    lim = N-2
    while index <= lim:
        if S[index] == "A":
            row_A += 1
            index += 1
        elif S[index:index+2] == target: # BCに出会う
            index += 2
            cnt += row_A #置換を行う
        elif S[index+1] == "A": #BA, CAに出会う
            row_A = 1
            index += 2
        else: #BB, CB, CC これらは "壁"になる
            row_A = 0
            index += 2
    print(str(cnt))

Measured memory_bytes: 40304
#include<stdio.h>
main(){ 
int i,n,m; for(i=1;;i++){ 
scanf("%d %d",&n,&m); 
if(n==0 && m==0)break; 
if(n>m)printf("%d %d\n",m,n); 
else printf("%d %d\n",n,m); } 
return 0; 
} 




 



Measured memory_bytes: 1976
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
using ll = long long;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

string toStr(int num) {
  num--;
  switch (num) {
    case 0:
      return "a";
    case 1:
      return "b";
    case 2:
      return "c";
    case 3:
      return "d";
    case 4:
      return "e";
    case 5:
      return "f";
    case 6:
      return "g";
    case 7:
      return "h";
    case 8:
      return "i";
    case 9:
      return "j";
    case 10:
      return "k";
    case 11:
      return "l";
    case 12:
      return "m";
    case 13:
      return "n";
    case 14:
      return "o";
    case 15:
      return "p";
    case 16:
      return "q";
    case 17:
      return "r";
    case 18:
      return "s";
    case 19:
      return "t";
    case 20:
      return "u";
    case 21:
      return "v";
    case 22:
      return "w";
    case 23:
      return "x";
    case 24:
      return "y";
    case 25:
      return "z";

    default:
      return "";
  }
}

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

  ll num;
  cin >> num;

  vector<ll> vec;

  string str = to_string(num);

  while (1) {
    num--;
    // cout << num << endl;
    vec.push_back((num % 26));
    num /= 26;
    if (num <= 0) break;
  }

  reverse(vec.begin(), vec.end());

  for (auto a : vec) {
    cout << (char)('a' + a);
  }
}

Measured memory_bytes: 3708