akhauriyash/Code-Regression huggingface dataset:
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
#define rep1(i,start,n) for(int i=start;i<n;++i)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define MP make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    string s;
    while(cin>>s)
    {
        stack<int>mystack;
       for(int i=0;i<s.size();i++)
        {
            if(!mystack.empty() && s[i]=='T' && mystack.top()=='S')
            {
                mystack.pop();
            }

            else
            {
                mystack.push(s[i]);
               // cout<<s[i]<<endl;
            }
        }
        cout<<mystack.size()<<endl;

    }
}




Measured memory_bytes: 1284
#include <stdio.h>
int f(int n){
    return n%2 ? 3*n+1 : n/2;
}
int main(void){
    int a[1000000], i=1, j;
    scanf("%d", &a[0]);
    while(1){
        a[i] = f(a[i-1]);
        for(j=0; j<i; j++)
            if(a[j] == a[i]){
                printf("%d\n", i+1);
                return 0;
            }
        i++;
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int MAX_N=1e2+10;
bool bbb[MAX_N], ccc[MAX_N][MAX_N];
int aaa[MAX_N];
bool fnd(int x,int n) {
    for(int j=1;j<=n;j++) {
        if (ccc[x][j]&&!bbb[j]) {
            bbb[j]=true;
            if (aaa[j]==0 || fnd(aaa[j],n)) {
                aaa[j]=x;
                return true;
            }
        }
    }
    return false;
}
int solve(int m, int n) {
    int ans=0;
    for (int i=1;i<=m;i++) {
        memset(bbb,false,sizeof(bbb));
        if (fnd(i, n)) ans++;
    }
    return ans;
}
int main() {
    int n,a,b,x[105],y[105];
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d%d",&x[i],&y[i]);
    }
    for (int i=1;i<=n;i++) {
        scanf("%d%d",&a,&b);
        for (int j=1;j<=n;j++) {
            if (x[j]<a&&y[j]<b)ccc[j][i]=true;
        }
    }
    printf("%d\n",solve(n,n));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
using namespace std;

double dp[305][305][305];
bool visited[305][305][305];
int n;

double solve(int i,int j,int k)
{
    if(i==0 and j == 0  and k == 0)
        return 0;
    if(i<0 or j<0 or k<0)
        return 0;
    if(visited[i][j][k])
        return dp[i][j][k];
    visited[i][j][k] = true;
    double den = i+j+k;
    return dp[i][j][k] = (n+i * solve(i-1, j, k) + j * solve(i+1, j-1, k) + k * solve(i, j+1,k-1))/den;
    return dp[i][j][k];
}

int32_t main()
{
    cin >> n;
    int a[n];
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    memset(visited,false,sizeof(visited));
    map<int,int> mp;
    for(auto it: a)
        mp[it]++;
    double ans = solve(mp[1],mp[2],mp[3]);
    cout << fixed << setprecision(10);
    cout << ans;
    return 0;
}


Measured memory_bytes: 140252
#include<iostream>

#include<cmath>

#include<string>

#include<iomanip>

using namespace std;

int main()

{

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

	if(a+b+c>=22)

{

	cout<<"bust";

	}

	else

	{cout<<"win";

		}

	

	

	return 0;

}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn make_tree(
    cur_idx: usize,
    parent_idx: usize,
    edges: &Vec<Vec<usize>>,
    tree: &mut Vec<Vec<usize>>,
    parent_dict: &mut HashMap<usize, usize>,
) {
    for child_idx in edges[cur_idx].iter() {
        if *child_idx == parent_idx {
            continue;
        }
        tree[cur_idx].push(*child_idx);
        parent_dict.insert(*child_idx, cur_idx);
        make_tree(*child_idx, cur_idx, edges, tree, parent_dict);
    }
}

fn topological_dfs(cur_idx: usize, tree: &Vec<Vec<usize>>, result: &mut Vec<usize>) {
    for child_idx in tree[cur_idx].iter() {
        result.push(*child_idx);
        topological_dfs(*child_idx, tree, result);
    }
}

fn get_depth_dfs(
    cur: usize,
    parent: usize,
    cur_depth: usize,
    depth: &mut Vec<usize>,
    tree: &Vec<Vec<usize>>,
) {
    depth[cur] = cur_depth;
    for &to in tree[cur].iter() {
        if to == parent {
            continue;
        }
        get_depth_dfs(to, cur, cur_depth + 1, depth, tree);
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, u, v) = (v[0], v[1] - 1, v[2] - 1);
    let mut edges: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut parent_dict: HashMap<usize, usize> = HashMap::new();
    let root = v;
    make_tree(root, n, &edges, &mut tree, &mut parent_dict);
    let mut topological_sorted_indexes = vec![root];
    topological_dfs(root, &tree, &mut topological_sorted_indexes);

    let mut depth = vec![0; n];
    get_depth_dfs(root, root, 0, &mut depth, &tree);
    // debug!(depth);

    let mut depth_children = vec![0; n];
    for &ti in topological_sorted_indexes.iter().rev() {
        depth_children[ti] = depth[ti];
        for &ci in tree[ti].iter() {
            depth_children[ti] = max(depth_children[ti], depth_children[ci]);
        }
    }

    let mut most_depth = depth_children[u];
    let mut cur = u;
    let mut dist = 0;
    loop {
        let parent = parent_dict[&cur];
        dist += 1;
        cur = parent;
        if dist >= depth[parent] {
            break;
        }
        most_depth = max(most_depth, depth_children[cur]);
    }
    println!("{}", most_depth - 1);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(all(a));
  int ans1 = a[n-1],ans2;
  double min=INF;
  rep(i,n){
    if(abs((double)ans1/2-a[i])<min){
      min = abs((double)ans1/2-a[i]);
      ans2 = a[i];
    }
  }
  cout << ans1 << " " << ans2 << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n;cin>>n;
	int m=n%10;
	if(m==2||m==4||m==5||m==7||m==9)
	cout<<"hon"<<"\n";
	if(m==0||m==1||m==6||m==8)
	cout<<"pon"<<"\n";
	if(m==3) cout<<"bon"<<"\n";
	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <cmath>
#include <vector>
typedef long long ll;

using namespace std;

int main(){
  int N;
  int A, B;
  cin >> N >> A >> B;

  vector<int> q_A, q_B, q_C;

  for (int i; i < N; i++) {
    int p;
    cin >> p;
    if (p <= A) q_A.push_back(p);
    else if (p > A && p <= B) q_B.push_back(p);
    else q_C.push_back(p);
  }
  int ans;
  ans = min(min(q_A.size(), q_B.size()), q_C.size());
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

bool isOK(ll a[], int index, ll key){
    if(a[index] > key) return true;
    else return false;
}

int binary_search(ll a[], int nax, ll key){
    int ng = -1;
    int ok =nax;
    while(abs(ok-ng) > 1){
        int mid = (ok + ng)/2;
        if(isOK(a,mid,key))ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
	int N,M,K; cin>>N>>M>>K;
	vector<int> A(N);
	vector<int> B(M);
	rep(i,N)cin>>A[i];
	rep(i,M)cin>>B[i];
	ll suma[200200] = {0};
	ll sumb[200200] = {0};
	rep(i,N)suma[i+1] = suma[i] + A[i];
	rep(i,M)sumb[i+1] = sumb[i] + B[i];
	// rep(i,N+1)cout<<suma[i]<<' ';
	// cout<<endl;
	// rep(i,M+1)cout<<sumb[i]<<' ';
	// cout<<endl;
	int ans = 0;
	rep(i,N+1){
		ll t = K-suma[i];
		if(t < 0)continue;
		int add = binary_search(sumb, M+1, t)-1;
		// printf("[anum, bnum, t] = [%d, %d, %lld]\n", i, add, t);
		ans = max(ans, i + add);
	}
	cout<<ans<<endl;
}

// int main(){
// 	int N,M,K; cin>>N>>M>>K;
// 	vector<int> A(N+1);
// 	vector<int> B(M+1);
// 	rep(i,N)cin>>A[i]; A[N] = inf;
// 	rep(i,M)cin>>B[i]; B[M] = inf+2;
// 	int ap = 0, bp = 0;
// 	int ans = 0;
// 	while(A[ap] <= K || B[bp] <= K){
// 		if(A[ap] < B[bp]){
// 			K -= A[ap];
// 			++ans;
// 			++ap;
// 		}else if(A[ap] > B[bp]){
// 			K -= B[bp];
// 			++ans;
// 			++bp;
// 		}else{
// 			cout<<"in"<<endl;
// 			int tap = ap;
// 			int tbp = bp;
// 			while(A[tap] == B[tap]){
// 				if(K < A[tap])break;
// 				K -= A[tap];
// 				++tap; ++tbp; ++ans;
// 				// cout<<tap<<' '<<tbp<<endl;
// 			}
// 			if(A[tap] > B[tbp]){
// 				bp = tbp;
// 			}else{
// 				ap = tap;
// 			}
// 		}
// 		// printf("[ap, bp, K, ans] = [%d, %d, %d, %d]\n", ap, bp, K, ans);
// 	}
// 	cout<<ans<<endl;
// }

// int main(){
// 	int N, M, K; cin>>N>>M>>K;
// 	queue<int> A;
// 	queue<int> B;
// 	int t;
// 	rep(i,N){
// 		cin>>t;
// 		A.push(t);
// 	}
// 	rep(i,M){
// 		cin>>t;
// 		B.push(t);
// 	}
// 	int ans = 0;
// 	while(K <= A.front() || K <= B.front()){
// 		++ans;
// 		if(A.front() < B.front()){
// 			K -= A.front();
// 			A.pop();
// 		}else{
// 			K -= B.front();
// 			B.pop();
// 		}
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

Measured memory_bytes: 8008
#include <bits/stdc++.h>
using namespace std;
struct range{
	int L,R;
};

int main() {
	// your code goes here
	int n,m;
	scanf("%d %d",&n,&m);
	//vector<range>ranges(m);
	int L, R, _start, _end;
	//range ans;
	bool posible = true;
	for(int i=0;i<m and posible; i++){
		scanf("%d %d",&L, &R);
		//printf("%d %d\n",ranges[i].L, ranges[i].R);
		if(i==0) {
			_start = L, _end = R;
		} 
		else{
			_start = max(_start , L) ;
			_end   = min(_end, R) ;
		}
		if(_start > _end) posible = false;
	}
	printf("%d\n", posible ? (_end - _start + 1) : 0);
	return 0;
}

Measured memory_bytes: 256
//けんちょんさんの写経
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	//入力、キューにまずは順に要素を追加する。
	int N ; 
	int Q ; //久遠たむ
	cin >> N >> Q;
	queue<pair<string,int>> que;
	rep(i,N){
		string name;
		int time;
		cin >> name >>time;
		que.push({name,time});
	}

	//ラウンドロビンスケジーリング
	int cur_time = 0;
	while(!que.empty()){
		auto cur =que.front();
		que.pop();

		//Q秒以上かかるとき、Q秒処理してまたキューに追加
		if(cur.second > Q){
			cur_time +=Q;
			cur.second -= Q;
			que.push(cur);
		}
		//Q秒以内に終了するときは、処理を終えてプログラムを出力する
		else{
			cur_time +=cur.second;
			cout<<cur.first<<" "<<cur_time<<endl;
		}
	}
}



Measured memory_bytes: 6328
#include <stdio.h>
#include <stdlib.h>
int num(){
    char s[11];
    int i, n;
    for(i=0; i<sizeof(s); i++){
        s[i] = getchar();
        if(s[i] == ' ' || s[i] == '\n'){
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}
int asc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}
int main(void){
    int n, i, j=1;
    int a[300001];
    long ans=0;
    
    n = num();
    for(i=0; i<n*3; i++){
        a[i] = num();
    }
    
    qsort(a, n*3, sizeof(int), asc);
    
    for(i=0; i<n; i++){
        ans += a[j];
        j+=2;
    }
    
    printf("%ld\n", ans);
    
    return 0;
}

Measured memory_bytes: 2556
#include <iostream>
using namespace std;
int gcd(int a, int b){
  while(true){
    if(a % b == 0){
      return b;
    }
    int tmp = a % b;
    a = b;b = tmp;
  }
  
}
int main(){
  int a,b;
  cin>>a>>b;
  cout << gcd(a,b) << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r;
    cin,r;
    print(r * r);
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a);i <= (b); i++)
#define ROF(i, a, b) for(int i = (a);i >= (b); i--)
const int N = 1e2 + 11;
int f[N][N];
char s[N][N];
int n, m;
int main(){
    cin>>n>>m;
    FOR(i, 1, n){
        scanf("%s", s[i] + 1);
    }   
    memset(f, 127, sizeof f);
    f[1][1] = s[1][1] == '#' ? 1 : 0;
    FOR(i, 1, n){
        FOR(j, 1 + (i == 1), m){
            if(s[i][j] == '.'){
                f[i][j] = min(f[i-1][j], f[i][j-1]);
            }
            else{
                f[i][j] = min(s[i][j-1] == '.' ? f[i][j-1] + 1 : f[i][j-1], s[i-1][j] == '.' ? f[i-1][j] + 1 : f[i-1][j]);
            }
        }
    }
    printf("%d\n", f[n][m]);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
//#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


string s;

int blen = 0;
int bans = 0;

int dp[21][1 << 20];
int tr[21][1 << 20];

void upd(int len, int ans) {
	if (len < blen)
		return;
	if (len > blen) {
		blen = len, bans = ans;
	}
	else if (len == blen && ans < bans) {
		bans = ans;
	}
}

int n, k;

int main() {
	cin >> n >> k;
	for (int i = 0; i <= n; ++i) {
		cin >> s;
		for (int j = 0; j < (1 << i); ++j) {
			if (s[j] == '1') {
				++dp[i][j];
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < (1 << i); ++j) {
			int x = (j >> (i - 1)) & 1;
			int ans = 0;
			while (ans < i && ((j >> (i - ans - 1)) & 1) == x)
				++ans;
			if (ans == i)
				tr[i][j] = -1;
			else
				tr[i][j] = ans;
		}
	for (int l = 0; l <= n; ++l) {
		for (int i = l + 1; i <= n; ++i) {
			int msk = (1 << (i - l)) - 1;
			for (int j = 0; j < (1 << i); ++j) {
				dp[l][j >> (i - l)] += dp[i][j];
				int x = tr[i - l][j & msk];
				if (x != -1) {
					dp[i - x][((j >> (i - l)) << (i - l - x)) + (j & ((1 << (i - l - x)) - 1))] += dp[i][j];
				}
			}
		}
		for (int i = 0; i < (1 << l); ++i)
			if (dp[l][i] >= k)
				upd(l, i);
	}
	for (int i = blen - 1; i >= 0; --i) {
		cout << ((bans >> i) & 1);
	}
	cout << "\n";
	return 0;
}




Measured memory_bytes: 93572
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int s;
  cin >> s;

  int u, l;
  u = s / 100;
  l = s % 100;

  bool yymm = false, mmyy = false;
  if(0 < l && l < 13) yymm = true;
  if(0 < u && u < 13) mmyy = true;

  string ans;
  if(yymm && mmyy)
    ans = "AMBIGUOUS";
  else if(yymm && !mmyy)
    ans = "YYMM";
  else if(!yymm && mmyy)
    ans = "MMYY";
  else
    ans = "NA";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d %d",$N,$K);
$S=strval(trim(fgets(STDIN)));
$length = strlen($S);
$array1 = [];
$array0 = [];

//1,0が何個連続するかの配列作成
while(substr($S,0,1) !== false){
  if(substr($S,0,1) === "1"){
    if(strpos($S,"0") === false){
      $array1[] = strlen($S);
      $array0[] = 0;
      break;
    }else{
      $S = substr($S,strpos($S,"0"),strlen($S)-1);
      $array1[] = $length-strlen($S);
      $length = strlen($S);
    }
  }else{
    $array1[] = 0;
  }
  if(substr($S,0,1) === "0"){
    if(strpos($S,"1") === false){
      $array0[] = strlen($S);
      break;
    }else{
      $S = substr($S,strpos($S,"1"),strlen($S)-1);
      $array0[] = $length-strlen($S);
      $length = strlen($S);
    }  
  }else{
    $array0[] = 0;
  }
}

$size = count($array1);
//配列の大きさを越える回数指示できれば全員逆立ちできる
if($K>=$size){
  $max = array_sum($array1)+array_sum($array0);
}else{
  $value = 0;
  $max = $array1[0]+$array0[0];
  //逆立ちの最大値を求める、初回以外尺取法
  //逆立ち～逆立ちなので、直立より逆立ちの方が足す回数が1多い
  for($i=0;$i<$size-$K+1;$i++){
    //初回のみ全計算
    //最後のみ次の値がないので次の値を足さないようにする
    if($i===$size-$K && $i===0){
      for($j=0;$j<$K;$j++){
        $value += $array1[$i+$j];
      }
    }elseif($i===0){
      for($j=0;$j<$K+1;$j++){
        $value += $array1[$i+$j];
      }
    }elseif($i===$size-$K){
      //何もしない
    //次の値を足す(尺の右側を進める)
    }else{
      $value += $array1[($K-1)+$i+1];
    }
    if($i===0){
      for($j=0;$j<$K;$j++){
        $value += $array0[$i+$j];
      }
    //現在の値を足す(尺の右側を進める)
    }else{
      $value += $array0[($K-1)+$i];
    }
    //最大値更新
    if($value > $max){
      $max = $value;
    }
    //現在の値を引く(尺の左側を進める)
    $value -= $array1[$i]+$array0[$i];
  }
}
echo $max;


Measured memory_bytes: 18956
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

//素因数分解
map<int64_t,int> prime_factor(int64_t n){
    map<int64_t,int>ret;
    for(int64_t i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

int main(){
    ll A,B;cin >> A >> B;
    auto pfa = prime_factor(A);
    auto pfb = prime_factor(B);
    ll res = 1;
    for(auto &p:pfa){
        if(pfb[p.first]>=1)res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#define ll long long
using namespace std;
#define INF 500000000
ll dp[10][50];ll N,C;
ll val[10][50];
ll cost[600][600];
ll pll[600][600];
ll f(ll mask,ll poscolor)
{
    if (mask==7)
        return 0;
    if (poscolor>C)
        return INF;


    if (dp[mask][poscolor]!=-1)
        return dp[mask][poscolor];
    ll res=INF;
    res=f(mask,poscolor+1);
    for(ll a=0;a<3;a++)
    {
        if ((mask&(1<<a))==0)
        {
            res=min(res,f((mask|(1<<a)),poscolor+1)+val[a][poscolor]);
        }
    }

    //cout<<mask<<" "<<poscolor<<" "<<res<<endl;
    return dp[mask][poscolor]=res;
}
int main()
{

    memset(dp,-1,sizeof dp);
    cin>>N>>C;
    for(ll a=1;a<=C;a++){
        for(ll b=1;b<=C;b++)
        {
            cin>>cost[a][b];
        }
    }
    for(ll a=1;a<=N;a++)
        for(ll b=1;b<=N;b++)
        cin>>pll[a][b];
    for(ll md=0;md<3;md++)
    {
        for(ll color=1;color<=C;color++)
            {
                ll tot=0;
                bool isvalid=false;
                for(ll a=1;a<=N;a++)
                {
                    for(ll b=1;b<=N;b++)
                    {
                        if ((a+b)%3==md)
                        {
                            //cout<<a<<" aca "<<b<<" "<<md<<endl;
                            isvalid=true;
                            tot+=cost[pll[a][b]][color];
                        }
                    }
                }
                val[md][color]=tot;

                //cout<<val[md][color]<<" ";
            }
            //cout<<endl;

    }
    //return 0;
    //cout<<C<<endl;
    cout<<f(0,1)<<endl;
}



Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int Inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+10;
int main(){
	int n;
	cin>>n;
	int Min=Inf;
	for(int i=1;i<=n/2;i++){
		int a=i,b=n-i;
		int sum=0;
		while(a){
			sum+=a%10;
			a/=10;
		}
		while(b){
			sum+=b%10;
			b/=10;
		}
		Min=min(Min,sum);
	}
	cout<<Min;
} 

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [0]*(H+2)
S[0] = '*'*(W+2)
S[H+1] = '*'*(W+2)
for h in range(1,H+1):
    S[h] = '*' + input() + '*'

left = [[0]*(W+1) for _ in range(H+1)]
right = [[0]*(W+1) for _ in range(H+1)]
up = [[0]*(W+1) for _ in range(H+1)]
down = [[0]*(W+1) for _ in range(H+1)]

for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w-1] in ['#','*'] or S[h][w]=='#':
            left[h][w] = 0
        else:
            left[h][w] = left[h][w-1]+1

for h in range(1,H+1):
    for w in range(W,0,-1):
        if S[h][w+1] in ['#','*'] or S[h][w]=='#':
            right[h][w] = 0
        else:
            right[h][w] = right[h][w+1]+1

for w in range(1,W+1):
    for h in range(1,H+1):
        if S[h-1][w] in ['#','*'] or S[h][w]=='#':
            up[h][w] = 0
        else:
            up[h][w] = up[h-1][w]+1

for w in range(1,W+1):
    for h in range(H,0,-1):
        if S[h+1][w] in ['#','*'] or S[h][w]=='#':
            down[h][w] = 0
        else:
            down[h][w] = down[h+1][w]+1
ans = 0
for h in range(1,H+1):
    for w in range(1,W+1):
        ans = max(ans,left[h][w]+right[h][w]+up[h][w]+down[h][w]+1)

print(ans)

Measured memory_bytes: 180612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,c = 0,sum = 0;
  cin >> N;
  string s[N];
  int t[N];
  for(int i = 0; i < N; i++){
    cin >> s[i];
    cin >> t[i];
    sum += t[i];
  }
  string X;
  cin >> X;
  for(int j = 0; j < N; j++){
    if(s[j] == X){
      c += t[j];
      break;
    }
    c += t[j];
  }
  cout << sum - c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long int lld;
typedef vector<lld> vll;
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define mod 1000000007
#define pi 3.1415926535
#define as 10+2
lld a,b,c,d,e,f,g,i,j,k,m,n=1,o,q=0,r=0,u,w,z,s,t,p=2,x,y,temp;
lld ans=0;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
vll v1,v2,v3,v4,v5,v6;
double f1,f2,f3,f4,f5,f6,h,l;
char c2,c3,c4,c5,c6;
map<lld,lld>m1,m2,m3,m4;
//p=2;
//void make1(lld);
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    t=1;
    //cin>>t;
    while(t--)
    {
        cin>>a>>b;//lld a1[n],b1[n],c1[n];
        map<lld,lld>m11;map<char,lld>m12;string s11[n];p=0;q=0;r=0;
        n=s1.size();
        //lld a[26]={0};
        cout<<max(p,a-2*b);
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

void dfs(const vector<vecint>& g, vecint& vd, int i, int p = -1, int d = 0) {
  vd[i] = d;
  for(auto&& to:g[i]) {
    if (to == p) continue;
    dfs(g, vd, to, i, d+1);
  }
}

int main()
{
  int n,u,v;
  cin>>n>>u>>v;
  --u;--v;
  vector<vecint> g(n);
  for(auto&& i:irange(0,n-1)) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vecint dt(n), da(n);
  dfs(g, dt, u);
  dfs(g, da, v);
  int mx = 0;
  for(auto&& i:irange(0,n)) {
    if (da[i] > dt[i]) mx = max(mx, da[i]);
  }
  cout<<mx-1<<endl;
  return 0;
}


Measured memory_bytes: 12928
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
 
int main() {
        int[] hs;
        string l;
        readln();
        while((l = readln()).length >= 2){
                int a, b, c;
                a = to!int(l.split()[0]), b = to!int(l.split()[1]), c = to!int(l.split()[2]);
                if(a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) printf("YES\n");
                else printf("NO\n");
                }
        return 0;
}

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

//binary_search(begin, end, valuetofind)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAX (int)(1e6)+1
#define MOD 1000000007

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;

wGraph g;
vector<bool> visitados;
vi colors;

void addAresta(int a, int b, int p){
    g[a].pb(mp(b,p));
    g[b].pb(mp(a,p));
}

void dfs(int v){

    if(!visitados[v]){
        visitados[v] = true;
        for(auto u:g[v]){
            if(visitados[u.f]) continue;
            if(u.s & 1){
                colors[u.f] = colors[v]^1;
            }else{
                colors[u.f] = colors[v];
            }
            dfs(u.f);
        }
    }

}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int n,a,b,p;
    cin>>n;
    g.resize(n);
    colors.resize(n,0);
    visitados.resize(n,false);

    rep(i,n-1){
        cin>>a>>b>>p;
        addAresta(a-1,b-1,p);
    }

    dfs(0);

    rep(i,n){
        cout<<colors[i]<<endl;
    }

    return 0;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

multiset<ll> group[100001];

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

	ll N, M;
	cin >> N >> M;

	vector<ll> X;
	ll tmp;
	rep(i, M) {
		cin >> tmp;
		X.push_back(tmp);
	}

	sort(ALL(X));

	vector<P> diff;
	rep(i, M-1) {
		diff.emplace_back(X[i] - X[i+1], i);
	}

	sort(ALL(diff));

	ll ans = 0;
	ll cnt = 0;
	multiset<ll> sep;
	if (diff.size() != 0) {
		rep(i, min(N - 1, M)) {
			sep.insert(diff[i].second);
		}
		sep.insert(M);

		auto itr = sep.begin();
		rep(i, M) {
			if (i <= *itr) {
				group[cnt].insert(X[i]);
			}
			else {
				cnt++;
				itr++;
				group[cnt].insert(X[i]);
			}
		}
	}
	else {
		cnt = 0;
		rep(i, M) {
			group[cnt].insert(X[i]);
		}
	}

	rep(i, cnt + 1) {
		ans += *group[i].rbegin() - *group[i].begin();
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 16624
n=int(input())
taro=0
hanako=0
for i in range(n):
    c=list(input().split())
    if(c[0] < c[1]):
        hanako+=3
    elif(c[0] > c[1]):
        taro+=3
    else:
        taro+=1
        hanako+=1
print("{0} {1}".format(taro,hanako))



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

//GCD
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int g = gcd(A, B);
  if (C%g == 0)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int n, m;
    scanf("%d %d", &n, &m);

    int mat[n][m];
    int v[m];

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

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

    int a[n];

    for (int i = 0; i < n; i++) {
        a[i] = 0;
        for (int j = 0; j < m; j++) {
            a[i] += mat[i][j] * v[j]; 
        }
    }

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

    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin >>n >> k;
  ll ans = 1;
  rep(i,n){
    ans*=k-(i>0);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
	int min = INT_MAX;
	string S, tmp;
	cin >> S;
	for (int i = 0; i < S.size() - 2; ++i) {
		tmp = S.substr(i, 3);
		if (abs(stoi(tmp) - 753) < min) min = abs(stoi(tmp) - 753);
	}
	cout << min;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int blue=0, red=0;
	string stack;
	cin >> stack;
	for(int i=0;stack[i]!='\0';i++)
	{
		if(stack[i]=='0')
			red++;
		else if(stack[i]=='1')
			blue++;
	}
	if(red>blue)
		cout << 2*blue << endl;
	else 
		cout << 2*red << endl;
	return 0;
}

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

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

const int maxn = 50050;

int main() {
	int N, R;
	scanf("%d%d", &N, &R);
	if (N >= 10)
		printf("%d\n", R);
	else
	{
		int ans = R + 100 * (10 - N);
		printf("%d\n", ans);
	}
}

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

using namespace std;

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


int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int s = A + B + C + D;
  s -= min(min(A, B), min(C, D));
  cout << s + max(E, F) << "\n";
  return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};



int main(){
	int n; cin>> n;
	map<int,int> tab;
	
	
	bool ok = true;
	for( int i = 0; i < n; i++){
		int x; cin>> x;
		if(tab[x] == 0){
			tab[x] += 1;
		}
		else
			ok = false;
			
	}
	if(ok)
		cout<<"YES";
	else
		cout<<"NO";
	
	return 0;
}













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

const int N = 1e5 + 10;
int n , a[N];

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]++;
		if(x > 1) a[x-1]++;
		a[x+1]++;
	}
	
	int mx = 0;
	for(int i=0;i<N;i++)
	{
		mx = max(mx , a[i]);
	}
	cout << mx << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int gcd(int,int);
int main(){
	int x,y;
	int c=0;
	cin>>x>>y;
	gcd(x,y);
	return 0;
}
int gcd(int x,int y){
	if(x==0||y==0)
		return 0;
	while(x!=y){
		if(x>y){
			x=x-y;
		}
		else{
			y=y-x;
		}
	}
	cout<<x<<endl;
	return x;
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    String ans;

    if (a + b == 15) {
      ans = "+";
    } else if (a * b == 15) {
      ans = "*";
    } else {
      ans = "x";
    }

    System.out.println(ans);
  }
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	set<long long> a;
	long long b,ma=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>b;
		a.insert(b);
		ma=max(ma,b);
	}
	if (n==2)
	{
		cout<<ma<<" "<<*a.begin()<<endl;
		return 0;
	}
	auto i=a.lower_bound(ma/2LL+1LL);
	if (*i==ma)
	{
		--i;
	}
	long long ans=*i;
	--i;
	if (abs(ma/2LL-ans)>abs(ma/2LL-*i))
	{
		ans=*i;
	}
	cout<<ma<<" "<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
from collections import Counter
from itertools import tee

N = int(input())
D = list(map(int, input().split(" ")))
R = 998244353


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def is_leap(distance):
    cc = Counter(distance)
    for x, y in pairwise(sorted(cc.keys())):
        if y - x > 1:
            return True
    else:
        return False


if D[0] > 0:
    """頂点1が根ではない"""
    print(0)
elif not all(D[1:]):
    """連結グラフではない"""
    print(0)
elif is_leap(D):
    print(0)
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e)
    print(ans % R)


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

const int maxn=22222;
const int maxm=1111111;
const int inf=1000000000;

int g[maxn],to[maxm],np[maxm],cp;
int n,u,v,now,source,sink;
int sum,cap[maxm],a[maxn];
int d[maxn],p[maxn],cur[maxn],cnt[maxn];

void add_edge(int x,int y,int z){
	cap[cp]=z;to[cp]=y;np[cp]=g[x];g[x]=cp++;cap[cp]=0;to[cp]=x;np[cp]=g[y];g[y]=cp++;
}

void init(){
	cp=2; memset(g,0,sizeof(g));
}
int maxflow(){
	sum=0;
	for(u=1;u<=n;u++)cur[u]=g[u]; a[u=source]=inf; memset(d,0,sizeof(int)*(n+1)); memset(cnt,0,sizeof(int)*(n+1)); cnt[0]=n;
	while(d[source]<n)
	{
		for(now=cur[u];now;now=np[now])if(cap[now]&&d[v=to[now]]+1==d[u])break; cur[u]=now;
		if(now)
		{
			p[v]=now; a[v]=cap[now]; if(a[v]>a[u])a[v]=a[u];
			if((u=v)==sink)
			{
				do{cap[p[u]]-=a[sink]; cap[p[u]^1]+=a[sink]; u=to[p[u]^1];}while(u!=source);
				sum+=a[sink]; a[source]=inf;
			}
		}
		else
		{
			if(--cnt[d[u]]==0)break; d[u]=n; cur[u]=g[u];
			for(now=g[u];now;now=np[now]) if(cap[now] && d[u]>d[to[now]]+1) d[u]=d[to[now]]+1;
			cnt[d[u]]++;
			if(u!=source)u=to[p[u]^1];
		}
	}
	return sum;
}

int N,M;
char ss[111][111];
bool input(){
	scanf("%d%d",&N,&M);
	for(int i=0; i<N; i++){
		scanf("%s",ss[i]);
		for(int j=0; j<M; j++)
		if(ss[i][j] == 'X' && (i==0 || i==N-1 || j==0 || j==M-1))
			return false;
	}
	return true;
}
const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
int v_in(int x,int y){
	return (x*M+y)*2+1;
}
int v_out(int x,int y){
	return (x*M+y)*2+2;
}

int main(){
	if(!input()){
		puts("-1");
		return 0;
	}

	init();
	source = N*M*2+1;
	n = sink = source+1;
	for(int i=0; i<N; i++)
		for(int j=0; j<M; j++){
			if(ss[i][j] == 'X')
				add_edge(source, v_out(i,j), inf);
			else{
				add_edge(v_in(i,j), v_out(i,j), 1);
				if(i==0 || i==N-1 || j==0 || j==M-1){
					add_edge(v_out(i,j), sink, inf);
				}
			}
			for(int k=0; k<4; k++){
				int i2 = i+dx[k], j2 = j+dy[k];
				if(i2>=0 && i2<N && j2>=0 && j2<M)
					add_edge(v_out(i,j),v_in(i2,j2),inf);
			}
		}
	printf("%d\n",maxflow());
	return 0;
}

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

using namespace std;

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

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

    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < static_cast<int>(s[i].size()) - 1; j++) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
                res++;
            }
        }
    }

    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 0; i < n; i++) {
        if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') {
            c1++;
        } else if (s[i][0] == 'B' && s[i][s[i].size() - 1] != 'A') {
            c2++;
        } else if (s[i][0] != 'B' && s[i][s[i].size() - 1] == 'A') {
            c3++;
        }
    }

    res += (c1 == 0 ? (c2 < c3 ? c2 : c3) : (c2 + c3 > 0 ? c1 + (c2 < c3 ? c2 : c3) : c1 - 1));
    cout << res << endl;
}


Measured memory_bytes: 768
inpl = lambda: list(map(int,input().split()))
X, Y, A, B, C = inpl()
N = [A, B, C]
P = []
T = []
for n in range(3):
    P=inpl()
    for i in range(N[n]):
        T.append((P[i],n))
T.sort(reverse=True)
M = [X, Y, A+B+C]
ans = 0
cur = [0,0,0]
k = 0
i = 0
while i < X+Y:
    v, c = T[k]
    if cur[c] < M[c]:
        ans += v
        cur[c] += 1
        i += 1
        k += 1
    else:
        k += 1
print(ans)


Measured memory_bytes: 119908
from itertools import permutations
N, M = list(map(int, input().split()))
edges = []

for i in range(M):
    a, b = list(map(int, input().split()))
    edges.append([a-1, b-1])

mat = [[0]*N for _ in range(N)]

for s, g in edges:
    mat[s][g] = 1
    mat[g][s] = 1


P = permutations(range(N))
ans = 0
for route in P:
    if route[0] != 0:
        continue
    else:
        vis = 0
        for s, g in zip(route, route[1:]):
            if mat[s][g] == 1:
                vis += 1
                if vis == N-1:
                    ans += 1
                continue
            else:
                break
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define Set(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
template <typename T> inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
template <typename T>inline void upd(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
template <typename T>inline void dec(T&x,int y){x-=y;if(x <  0) x+=mod;return;}
template <typename T,typename S>inline T fpow(T x,S k){T ret=1;for(;k;k>>=1,x=1ll*x*x%mod) if(k&1) ret=1ll*ret*x%mod;return ret;}
priority_queue<int> Q;
int a[N];



int main()
{
	int n;
	init(n);
	for(int i=1;i<=n;++i) init(a[i]);
	
	sort(a+1,a+1+n);ll ans=0;
	int l=a[1],r=a[1];
	int head=2,tail=n;
	
	while(head<=tail){
		int x=a[head];
		int ans1=abs(l-x),ans2=abs(r-x);
		x=a[tail];
		int ans3=abs(l-x),ans4=abs(r-x);
		
		if(ans1>=ans2&&ans1>=ans3&&ans1>=ans4) ans+=ans1,l=a[head++];
		else if(ans2>=ans1&&ans2>=ans3&&ans2>=ans4) ans+=ans2,r=a[head++];
		else if(ans3>=ans1&&ans3>=ans2&&ans3>=ans4) ans+=ans3,l=a[tail--];
		else if(ans4>=ans1&&ans4>=ans2&&ans4>=ans3) ans+=ans4,r=a[tail--];
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
        ll x;
        cin>>x;
        ll res=0, mod=x%11;
        res+=(x/11)*2;
        if(mod>0){
                mod-=6;
                res++;
        }
        if(mod>0){
                res++;
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
def p(i):
    answer.append(i+ 1)
    if i == 0 or i == len(a)-1:
        a.pop(i)
        return
    a.pop(i)
    a[i - 1] += a[i]
    a.pop(i)
    # print(a)

n = int(input())
a = [int(i) for i in input().split()[:]]

odd_max = 0
even_max = 0
for i in range(n):
    if a[i] > 0:
        if i % 2 == 0:
            odd_max += a[i]
        else:
            even_max +=a[i]

answer = []

if odd_max == even_max == 0:
    max = -1000000001
    ind = 0
    for i in range(n):
        if a[i] > max:
            max = a[i]
            ind = i
    print(a[ind])
    print(n-1)
    for i in range(n - 1, ind, -1):
        print(i+1)
    for i in range(ind):
        print(1)
    quit()



# print(odd_max,even_max)
neg = []
flag = 0
if odd_max < even_max: flag = 1
for i in range(n-1,-1,-1):
    if a[i] < 0 and i % 2 == flag:
        neg.append(i)
# print(neg)

for i in range(len(neg)):
    p(neg[i])
k = len(a)
if 1 in answer: flag = 1-flag
for i in range(k-1,-1,-1):
    if i % 2 != flag:
        p(i)

print(max(odd_max,even_max))
print(len(answer))
for i in range(len(answer)):
    print(answer[i])

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
        public static void main(String[] args) throws Exception {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st;
                PrintWriter pw = new PrintWriter(System.out);

                int a = Integer.parseInt(br.readLine());
                int b = Integer.parseInt(br.readLine());
                int x = 1^2^3;
                x^=a;
                x^=b;
                pw.println(x);


                pw.flush();
                pw.close();
        }
}


Measured memory_bytes: 21332
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
char st[1005];
int main(){
    scanf("%s",st);
    for(int i=0;i<4;i++)putchar(st[i]);
    putchar(' ');
    for(int i=4;i<12;i++)putchar(st[i]);
    putchar('\n');
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  ll ans = 0;
  vector<int> a(n), b(n), c(n);
  for(auto &i:a) cin >> i;
  for(auto &i:b) cin >> i;
  for(auto &i:c) cin >> i;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  for(int i = 0; i < n; i++){
    auto it_a = lower_bound(a.begin(), a.end(), b[i]);
    auto it_c = upper_bound(c.begin(), c.end(), b[i]);
    ans += 1LL * (it_a - a.begin()) * (c.end() - it_c);
  }
  cout << ans << endl;
  // end-----------------------------------------------
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=0;

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int a; cin >> a;
    cout << a+a*a+a*a*a << '\n';
}

Measured memory_bytes: 3572
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    C = input()

    r = 0
    cnt = []
    for c in C:
        if c == "R":
            r += 1
        cnt.append(r)
    cnt.append(cnt[-1])

    if not r or r == len(C):
        print(0)
        return

    ans = float("inf")
    for i in range(1, N):
        ans = min(ans, max(i - cnt[i - 1], cnt[-1] - cnt[i]))
    print(ans)


main()


Measured memory_bytes: 17348
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
q=int(input())
ans=0
for key,value in dic.items():
  ans+=key*value
for i in range(q):
  b,c=map(int,input().split())
  if b in dic:
    if c in dic:
      dic[c]+=dic[b]
      ans+=dic[b]*(c-b)
    else:
      dic[c]=dic[b]
      ans+=dic[b]*(c-b)
    dic[b]=0
  print(ans)

Measured memory_bytes: 20676
# -*- coding: utf-8 -*-
import fractions
 
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
y=[]
 
i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()
 
y=list(set(y))
m=len(y)
z=y[0]
i=0
while i < m:
    z=fractions.gcd(z,y[i])
    i+=1
 
print(z)

Measured memory_bytes: 16292
N = int(input())
H = list(map(int, input().split()))
res = "Yes"
lenH = len(H)
val = 0
for i in range(lenH):
  if val <= H[i]-1:
    val = H[i]-1
  elif val <= H[i]:
    val = H[i]
  else:
    res = "No"
    break
print(res)


Measured memory_bytes: 14396