akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut ans = 1000;
    let love = 753;
    for i in 0..s.len() - 2 {
        let mut sum = s[i] as i32 - '0' as i32;
        sum *= 10;
        sum += s[i + 1] as i32 - '0' as i32;
        sum *= 10;
        sum += s[i + 2] as i32 - '0' as i32;
        let mut d = sum - love;
        if d < 0 {
            d = -d;
        }
        ans = std::cmp::min(ans, d);
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N+1);
  A[0]=0;
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    A[i+1]=A[i]+p+1;
  }
  int j=0;
  for(int i=0;i<=N-K;i++)
    j=max(j,A[i+K]-A[i]);
  cout<<fixed<<setprecision(1)<<j/(long double)2<<endl;
}

Measured memory_bytes: 4816
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<vector>
#include<deque>
using namespace std;
#define re register int
inline int read(){
	int x=0,ff=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return x*ff;
}
inline bool ok(int x){
	if(x<2)return 0;
	if(x==2||x==3)return 1;
	if(x%6!=5&&x%6!=1)return 0;
	for(re j=5;j<=x/j;j+=6){
		if(x%j==0||x%(j+2)==0)return 0;
	}
	return 1;
}
int main(){
	int x=read();
	while(233){
		if(ok(x)){
			cout<<x<<endl;break;
		}
		x++;
	}
	return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll a=0,b=0;
	ll n;
	cin>>n;
	ll m=n/100;
	n%=100;
	if(1<=m&&m<=12)a=1;
	if(1<=n&&n<=12)b=1;
	string ans;
	if(a&&b)ans="AMBIGUOUS";
	if(!a&&b)ans="YYMM";
	if(a&&!b)ans="MMYY";
	if(!a&&!b)ans="NA";
	cout<<ans<<endl;
	return 0;
}


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

using ll = long long int;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;

#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
vector<pld> points;
ld sqrt_dist(pld a,pld b){
	return sqrt((a.f-b.f)*(a.f-b.f)+(a.s-b.s)*(a.s-b.s));
}
ld dist(pld a,pld b){
	return ((a.f-b.f)*(a.f-b.f)+(a.s-b.s)*(a.s-b.s));
}

pair<pld,ld> findCircle(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3) 
{ 
	ld x12 = x1 - x2; 
	ld x13 = x1 - x3; 

	ld y12 = y1 - y2; 
	ld y13 = y1 - y3; 

	ld y31 = y3 - y1; 
	ld y21 = y2 - y1; 

	ld x31 = x3 - x1; 
	ld x21 = x2 - x1; 
	ld sx13 = x1*x1 - x3*x3; 
	ld sy13 = y1*y1 - y3*y3; 
	ld sx21 = x2*x2 - x1*x1; 
	ld sy21 = y2*y2 - y1*y1; 
	ld f = ((sx13) * (x12) 
			+ (sy13) * (x12) 
			+ (sx21) * (x13) 
			+ (sy21) * (x13)) 
			/ (2 * ((y31) * (x12) - (y21) * (x13))); 
	ld g = ((sx13) * (y12) 
			+ (sy13) * (y12) 
			+ (sx21) * (y13) 
			+ (sy21) * (y13)) 
			/ (2 * ((x31) * (y12) - (x21) * (y13))); 
	ld c = -x1*x1 - y1*y1 - 2 * g * x1 - 2 * f * y1; 
	ld h = -g; 
	ld k = -f; 
	ld sqr_of_r = h * h + k * k - c;
	ld r = sqrt(sqr_of_r);
	return mp(mp(h,k),r); 
}
bool safe(pair<pld,ld> cur)
{
	for(ll i=0;i<sz(points);i++)
		if(dist(points[i],cur.f)-cur.s*cur.s>1e-7)
			return 0;
	return 1;
}
bool colin(ld x1, ld y1, ld x2,  
               ld y2, ld x3, ld y3) 
{ 
    ld a = x1 * (y2 - y3) +  
            x2 * (y3 - y1) +  
            x3 * (y1 - y2); 
    return a==0;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<fixed<<setprecision(18);
	ll n;
	cin>>n;
	pld a;
	for(ll i=0;i<n;i++)
	{
		cin>>a.f>>a.s;
		points.pb(a);
	}
	ld ans=2000;
	for(ll i=0;i<n;i++)
		for(ll j=i+1;j<n;j++)
		{
			pair<pld,ld> cur;
			cur.s=sqrt_dist(points[i],points[j])/2.0;
			cur.f=mp((points[i].f+points[j].f)/2.0,(points[i].s+points[j].s)/2.0);
			if(safe(cur))ans=min(ans,cur.s);
		}
	for(ll i=0;i<n;i++)
		for(ll j=i+1;j<n;j++)
			for(ll k=j+1;k<n;k++)
			{
				pair<pld,ld> cur=findCircle(points[i].f,points[i].s,points[j].f,points[j].s,points[k].f,points[k].s);
				if(safe(cur))ans=min(ans,cur.s);
			}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    ll cost[N];
    for(int i = 0; i < N; i++) cost[i] = INF;
    cost[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++)
            if(i + j < N) cost[i+j] = min(cost[i+j],cost[i]+abs(h[i] - h[i+j]));
    }
    cout << cost[N-1] << endl;
    return 0;
}


Measured memory_bytes: 4380
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		if (n < 10) {
			System.out.println(0);
			return;
		}

		Eratosthenes e = new Eratosthenes(n);
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 2; i <= n; i++) {
			Map<Integer, Integer> soinsu = e.bunkai(i);
			for (Integer key : soinsu.keySet()) {
				map.put(key, ntz(map.get(key)) + soinsu.get(key));
			}
		}

		int c2 = 0;
		int c4 = 0;
		int c14 = 0;
		int c24 = 0;
		int c74 = 0;
		for (int v : map.values()) {
			if (v >= 2) c2++;
			if (v >= 4) c4++;
			if (v >= 14) c14++;
			if (v >= 24) c24++;
			if (v >= 74) c74++;
		}

		int ans = 0;
		ans += c74;
		ans += c24 * (c2 - 1);
		ans += c14 * (c4 - 1);
		ans += c4 * (c4 - 1) / 2 * (c2 - 2);
		System.out.println(ans);
	}

	static int ntz(Integer o) {
		return o == null ? 0 : o;
	}

	static class Eratosthenes {
		int[] div;

		public Eratosthenes(int n) {
			div = new int[n + 1];
			div[0] = -1;
			div[1] = -1;
			int end = (int) Math.sqrt(n) + 1;
			for (int i = 2; i <= end; i++) {
				if (div[i] == 0) {
					div[i] = i;
					for (int j = i * i; j <= n; j+=i) {
						if (div[j] == 0) div[j] = i;
					}
				}
			}
			for (int i = end + 1; i <= n; i++) {
				if (div[i] == 0) div[i] = i;
			}
		}

		public Map<Integer, Integer> bunkai(int x) {
			Map<Integer, Integer> soinsu = new HashMap<>();
			while (x > 1) {
				Integer d = div[x];
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				x /= d;
			}
			return soinsu;
		}
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    ll n,d;
    cin>>n>>d;
    if(n%(2*d+1)==0){
        cout<<n/(2*d+1);
    }else{
        cout<<n/(2*d+1)+1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[3][3];
	int c, b;
	int bingo[3][3] = {0};

	
	for(int i = 0;i < 3;i++){
		for(int j = 0; j < 3;j++){
			scanf("%d", &a[i][j]);
		}
	}
	scanf("%d", &c);
	printf("\n");
	for(int z =0;z < c;z++){
		scanf("%d", &b);
		for(int i = 0; i < 3;i++){
			for(int j = 0;j <3;j++){
				if(a[i][j] == b){
					bingo[i][j] = 1;
				}
			}
		}
	}
	
	if(bingo[0][0]+bingo[1][1]+bingo[2][2]==3||bingo[0][2]+bingo[1][1]+bingo[2][0]==3){
		printf("Yes");
		return 0;
	}for(int i = 0; i < 3;i++){
	if(bingo[i][0]+bingo[i][1]+bingo[i][2]==3||bingo[0][i]+bingo[1][i]+bingo[2][i]== 3){
		printf("Yes");
		return 0;
	}
}
printf("No");
return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

mint dp[101][4][4][4];

int main() {
  int N = si();
  dp[0][3][3][3] = 1;
  REP(i,N) REP(j,4) REP(k,4) REP(l,4) REP(m,4) {
    if (k==0&&l==1&&m==2) continue;
    if (k==1&&l==0&&m==2) continue;
    if (k==0&&l==2&&m==1) continue;
    if (j==0&&k==1&&m==2) continue;
    if (j==0&&l==1&&m==2) continue;
    dp[i+1][k][l][m] += dp[i][j][k][l];
  }
  mint ans = 0;
  REP(j,4) REP(k,4) REP(l,4) ans += dp[N][j][k][l];
  pi(ans.n); br();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

int n, m; 
vector<int> g[100100], h[100100];
int depth[100100], cnt[100100];

void dfs(int v, int d, int p) {
    depth[v] = d;
    for(auto& nv: g[v]) {
        if(nv == p) continue;
        if(depth[nv] != -1 && depth[nv] <= d + 1) {
            h[nv].push_back(v);
            cnt[nv] ++;
        }
        if(depth[nv] == -1) dfs(nv, d + 1, v);
    }
    if(p == -1) return;
    if(cnt[v] % 2 == 0) {
        cnt[p] ++;
        h[p].push_back(v);
    } else {
        cnt[v] ++;
        h[v].push_back(p);
    }
}

void solve() {
	cin >> n >> m;
    if(m & 1) {
        cout << -1 << endl;
        return;
    }
    rep(i, m) {
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, 100100) {
        depth[i] = -1;
        cnt[i] = 0;
    }
    dfs(0, 0, -1);
    rep(v, n) {
        for(auto nv: h[v]) {
            cout << v + 1 << " " << nv + 1 << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


Measured memory_bytes: 17792
#include <iostream>
using namespace std;
 
int main() {
    while(true){
        int n,m;
        cin>>n>>m;
         
        if(n==0 && m==0){
            break;
        }
         
        int a[10000],b[10000];
        bool friends[501],finish[501];
        for(int i=0;i<m;i++){
            cin>>a[i]>>b[i];
        }
        for(int i=0;i<=n;i++){
            friends[i]=false;
            finish[i]=false;
        }
         
        for(int i=0;i<m;i++){
            if(a[i]==1){
                friends[b[i]]=true;
                finish[b[i]]=true;
            } else if(b[i]==1){
                friends[a[i]]=true;
                finish[a[i]]=true;
            }
        }
         
        for(int i=2;i<=n;i++){
            if(friends[i]){
                for(int j=0;j<m;j++){
                    if(a[j]==i){
                        finish[b[j]]=true;
                    } else if(b[j]==i){
                        finish[a[j]]=true;
                    }
                }
            }
        }
         
        int ans=0;
        for(int i=2;i<=n;i++){
            if(finish[i]){
                ans++;
            }
        }
         
        cout<<ans<<endl;
    }
    return 0;
}

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

int a[N],b[N],c[N];

int main(){

  int n; cin >> n;
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];

  sort(a,a+n);
  sort(c,c+n);
  ll ans = 0;
  REP(i,n){
    ll A = lower_bound(a,a+n,b[i]) - a;
    ll C = n - (upper_bound(c,c+n,b[i]) - c);
    ans += A * C;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int W, a, b;cin>>W>>a>>b;
    if(a>b+W){
        cout<<abs(a-(b+W))<<endl;
    }else if(a+W<b){
        cout<<abs(b-(a+W))<<endl;
    }else{
        cout<<0<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, n, t, S = 0, A = 0, C = 0, D = 0;

	for (;;) {
		scanf("%d %d %d\n", &a, &b, &c);
		if (a < b) {t = a; a = b; b = t;}
		if (a < c) {t = a; a = c; c = t;}
		if (a >= b + c) break;
		S++;
		if      (a * a <  b * b + c * c) A++;
		else if (a * a == b * b + c * c) C++;
		else if (a * a >  b * b + c * c) D++;
	}
	printf("%d %d %d %d\n", S, C, A, D);
}



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

int main(){
    int n,m,ac=0,wa=0;
    cin >> n >> m;
    vector<int>v(100010);
    for (int i = 0; i < m; i++){
        int x;
        string s;
        cin >> x >> s;
        if (s == "AC"){
            if (v.at(x)>=1) continue;           
            wa -= v.at(x);
            v.at(x) = 100010;
            ac++;
        }else{
            v.at(x)--;
        }
    }
    cout << ac <<" "<< wa << "\n";
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		double ave = Double.MAX_VALUE;
		double temp;
		int n = 0;
		for (int i = 1; i <= N; i++) {
			temp = Math.abs(T - sc.nextInt() * 0.006 - A);
			if (temp < ave) {
				ave = temp;
				n = i;
			}
		}
		// 出力
		System.out.println(n);
	}
}

Measured memory_bytes: 24148
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int, input().split()))

n_P = []

for i in range(1, 100):
    if i not in P:
        n_P.append(i)

n_P.append(0)
n_P.append(101)

n_P.sort()
INF = 10 ** 9
diff = INF
ans = INF

for p in n_P:
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p

print(ans)


Measured memory_bytes: 9224
#include<iostream>
#include<string>
#include<cmath>
#include<unordered_map>
using namespace std;
unordered_map<string, int> tree[2], ans;

void dfs(string &s, int &i, string &pos, int id){
  i++;
  if(s[i] == '('){
    pos += "1";
    dfs(s, i, pos, id);
    pos = pos.substr(0, pos.length() - 1);
  }
  i+=2;
  int cnt = 0;
  while(s[i] != ']')i++, cnt++;
  string tmp = s.substr(i - cnt, cnt);
  tree[id][pos] = atoi(tmp.c_str());
  i+=2;
  if(s[i] == '('){
    pos += "0";
    dfs(s, i, pos, id);
    pos = pos.substr(0, pos.length() - 1);
  }
  i++;
}

void PrintAnswer(string &pos){
  std::cout << "(";
  if(ans.find(pos + "1") != ans.end()){
    pos += "1";
    PrintAnswer(pos);
    pos = pos.substr(0, pos.length() - 1);
  }
  std::cout << ")[" << ans[pos] << "](";
  if(ans.find(pos + "0") != ans.end()){
    pos += "0";
    PrintAnswer(pos);
    pos = pos.substr(0, pos.length() - 1);
  }
  std::cout << ")";
}

int main(){
  string a, b;
  std::cin >> a >> b;
  string p = "";
  int i = 0;
  dfs(a, i, p, 0);
  p = "";
  i = 0;
  dfs(b, i, p, 1);
  for (auto i:tree[0]){
    if(tree[1].find(i.first) != tree[1].end()){
      ans[i.first] = i.second + tree[1][i.first];
    }
  }
  p = "";
  PrintAnswer(p);
  std::cout << std::endl;
  return 0;
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9, mxp = (1 << 9), maxn = (1 << 18);



void solve(int ci)
{
    ic(x)
    ic(y)
    if(y - 2 * x < 0 || (y - 2 * x) & 1)
    {
        cout << "No";
        return;
    }
    int b = (y - 2 * x) / 2;
    int a = x - b;
    if(a >= 0) cout << "Yes";
    else cout << "No";
}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>

using namespace std;

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

  if( abs(a - b) % 2 == 1 ){
    cout << "IMPOSSIBLE" << endl;
  }else{
    if(a > b) cout << abs(a - b) / 2 + b << endl;
    else cout << abs(a - b) / 2 + a << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := scanInt()
	a := make([]int, 3)
	for i := 0; i < n; i++ {
		num := scanInt()
		switch {
		case num%4 == 0:
			a[2]++
		case num%2 == 0:
			a[1]++
		default:
			a[0]++
		}
	}
	if a[1] != 0 {
		a[1] = 1
	}
	// fmt.Println(a)
	if a[2]+1 >= a[0]+a[1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
	return
}

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}
func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	var i, j int
	for {
		for i = n - 2; i >= 0; i-- {
			if nums[i] < nums[i+1] {
				break
			}
		}
		if i < 0 {
			return
		}
		for j = n - 1; ; j-- {
			if nums[j] > nums[i] {
				break
			}
		}
		nums[i], nums[j] = nums[j], nums[i]
		for k, l := i+1, n-1; k < l; {
			nums[k], nums[l] = nums[l], nums[k]
			k++
			l--
		}
		*ret = append(*ret, makeCopy(nums))
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}

func pow(n, m int) int {
	ret := 1
	for i := 0; i < m; i++ {
		ret *= n
	}
	return ret
}

func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}
func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func eratosthenes(n int) []int {
	search := make([]bool, n+1)
	ans := []int{}
	for i := 2; i < n+1; i++ {
		search[i] = true
	}
	for i := 2; i*i < n+1; i++ {
		for j := 2; i*j < n+1; j++ {
			search[i*j] = false
		}
	}
	for i := 2; i < n; i++ {
		if search[i] {
			ans = append(ans, i)
		}
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 3336
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
inline double sq(double x){ return x*x; }
typedef pair<double, int> P;
int main(){
  int n;
  while(cin>>n,n){
    double x[100],y[100],z[100],r[100];
    REP(i,n)cin>>x[i]>>y[i]>>z[i]>>r[i];
    double d[100][100];
    REP(i,n)REP(j,n){
      d[i][j] = sqrt(sq(x[i]-x[j]) + sq(y[i]-y[j]) + sq(z[i]-z[j])) - (r[i] + r[j]);
      d[i][j] = max(0.0, d[i][j]);
    }
    priority_queue<P> que;
    que.push(P(0,0));
    bool used[100] = {};
    double ans = 0;
    while(!que.empty()){
      P p = que.top(); que.pop();
      p.first *= -1;
      if(used[p.second]) continue;
      used[p.second] = true;
      ans += p.first;
      REP(i,n)if(!used[i]){
        que.push(P(-d[p.second][i], i));
      }
    }
    printf("%.3lf\n",ans);
  }
}


Measured memory_bytes: 3268
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
using ll = long long;

int main() {
    ll n,m,r;
    cin >> n >> m >> r;
    vector<ll> rl(r);
    for(auto &rrl:rl) cin>>rrl;
    vector<vector<int>> rg(n,vector<int>(n,999999999));
    for (int i=0;i<m;i++) {
        int a,b,c;
        cin >>a>>b>>c;
        rg[a-1][b-1] = c;
        rg[b-1][a-1] = c;
    }
    for (int k=0;k<n;k++)
        for (int i=0;i<n;i++)
            for (int j=0;j<n;j++) rg[i][j]=min(rg[i][j],rg[i][k]+rg[k][j]);
    vector<int> v(r);
    iota(v.begin(), v.end(), 0);
    ll gmin = 999999999;
    do {
        ll g=0;
        for (int i=0;i<v.size()-1;i++) g+=rg[rl[v[i]]-1][rl[v[i+1]]-1];
        gmin = min(gmin,g);
    } while( next_permutation(v.begin(), v.end()));
    cout << gmin << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll K;
    cin >> K;
    int N = 50;
    cout << N << endl;
    ll mod = K % N;
    ll mul = K / N;
    ll A[N];
    for(int i = 0; i < N; i++){
        A[i] = i;
    }
    for (int i = 0; i < N; ++i) {
        A[i] += 1 * mul;
    }
    for (int i = 0; i < mod; ++i) {
        for (int j = 0; j < N; ++j) {
            if(i == j){
                A[j] += N;
            }else{
                A[j]--;
            }
        }
    }
    for (int i = 0; i < N; ++i) {
        cout << A[i] << " ";
    }
    cout << endl;

}


Measured memory_bytes: 256
m,n=map(int,input().split())
hozon=[]
for i in range(n):
    hozon.append(0)
for _ in range(m):
    x = input()
    gyou = list(map(int,x.split()))
    print(x+" {0}".format(sum(gyou)))
    for num in range(n):
        hozon[num] += gyou[num]

print(" ".join(map(str,hozon))+" {0}".format(sum(hozon)))

Measured memory_bytes: 7620
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    int ten = 1;
    int nine = 1;
    int eight = 1;
    while (n--) {
        ten *= 10;
        nine *= 9;
        eight *= 8;
        ten %= MOD;
        nine %= MOD;
        eight %= MOD;
    }
    ll ans = ten + eight - nine - nine;
    ans %= MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3580
class Node
  attr_reader :id, :siblings
  attr_accessor :gid

  def initialize(id)
    @id = id
    @siblings = []
    @gid = nil
  end

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

if $PROGRAM_NAME == __FILE__
  n, m = gets.chomp.split.map(&:to_i)

  nodes = Array.new(n)

  m.times do
    id1, id2 = gets.chomp.split.map(&:to_i)
    nodes[id1] ||= Node.new(id1)
    nodes[id2] ||= Node.new(id2)
    nodes[id1] << nodes[id2]
    nodes[id2] << nodes[id1]
  end

  gid = 0

  nodes.each do |node|
    next unless node
    next if node.gid

    gid += 1

    node.gid = gid

    queue = [node]

    until queue.empty?
      current = queue.shift

      current.siblings.each do |sibling|
        next if sibling.gid
        sibling.gid = gid
        queue << sibling
      end
    end
  end

  q = gets.to_i

  q.times do
    id1, id2 = gets.chomp.split.map(&:to_i)
    node1 = nodes[id1]
    node2 = nodes[id2]

    puts node1 && node2 && node1.gid == node2.gid ? 'yes' : 'no'
  end
end

Measured memory_bytes: 23580
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]

f0 = []
f1 = []
for i in XY:
    f0.append(i[0]-i[1])
    f1.append(i[0]+i[1])#左がf0右がf1

print(max(max(f0)-min(f0),max(f1)-min(f1)))


Measured memory_bytes: 61468
n = int(input())
if n < 1000:
    print(1000 - n)
else:
    n = str(n)
    firt = n[0]
    firt = int(firt)
    firt = str(firt)
    length = len(n) - 1
    leng = "0" * length
    fill = firt + leng
    fill = int(fill)
    res = int(n) - fill
    if res == 0: print(res)
    else:
        print(1000 - res)

Measured memory_bytes: 9196
S=input()
S=list(reversed(S))

m=2019
cnt=[0 for i in range(m)]

len_S=len(S)
x=1
tot=0
ans=0

for i in range(len(S)):
    cnt[tot]+=1
    tot+=(ord(S[i])-ord('0'))*x
    tot %= m
    ans+=cnt[tot]
    x=x*10%m

print(ans)

Measured memory_bytes: 10516
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int vec[n];
  ll score[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
    vec[i]--;
  }
  int check=0;
  for(int i=0;i<n;i++){
    cin>>score[i];
    if(score[i]<=0){
      check++;
    }
  }
  if(check==n){
    sort(score,score+n);
    cout<<score[n-1]<<endl;
    return 0;
  }
  ll ans=0;
  
  for(int i=0;i<n;i++){
    ll scoreb=0,now=i,count=0;
    scoreb+=score[vec[i]];
    now=vec[i];
    count++;
    if(now==i){
      if(scoreb<=0){
        ans=max(ans,score[i]);
      }
      else{
        ans=max(ans,score[i]*k);
      }
      continue;
    }
    while(now!=i&&count<k){
      ans=max(ans,scoreb);
      scoreb+=score[vec[now]];
      now=vec[now];
      count++;
      ans=max(ans,scoreb);
    }
    if(count==k){
      continue;
    }
    ans=max(ans,scoreb);
    if(scoreb>0){
      scoreb=scoreb*((k/count)-1);
      count=k%count +count;
      for(int j=0;j<count;j++){
        ans=max(ans,scoreb);
        scoreb+=score[vec[now]];
        now=vec[now];
        ans=max(ans,scoreb);
      }
      ans=max(ans,scoreb);
      continue;
    }
    if(scoreb<=0){
      scoreb=0,now=i;
      for(int j=0;j<count+100;j++){
        ans=max(ans,scoreb);
        scoreb+=score[vec[now]];
        now=vec[now];
        ans=max(ans,scoreb);
      }
      ans=max(ans,scoreb);
      continue;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<bool>flag(n);
	rep(i, n) {
		cin >> a[i];
		flag[i] = true;
		a[i]--;
	}
	int i2 = 0;
	int ans = 0;
	rep(i, n*2) {
		if (i2 == 1) {
			cout << ans << endl;
			return 0;
		}
		if (ans >= n) {
			cout << -1 << endl;
			return 0;
		}
		i2 = a[i2];
		ans++;
	}
	return 0;
}


Measured memory_bytes: 640
import math
import sys 
input = sys.stdin.readline

N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)

for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod


kaijou = 1
for i in range(1,N):
    kaijou *= i
    kaijou %= mod #これをしないとkaijouが発散


ans=0
x=0

def pow_a(a,n): #(modを取るように改良)
    if n==0:
        return 1
    
    K = 1
    while n>1:
        if n%2 != 0:
            K *= a
            K %= mod
        a *= a
        a %= mod
        n //= 2

    return K*a

for i in range(N-1):
    y = pow_a(i+1,mod-2) #i+1の逆元
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)


Measured memory_bytes: 58608
// Problem Code: abc177_c

#include <iostream>
#include <vector>

using namespace std;

int get_sum(int N, vector<int>& A) {
	int mod, sum, inner_sum;
	mod = 1e9 + 7;
	sum = inner_sum = 0;
	
	for (int i = 0; i < N; i++)
		inner_sum = (inner_sum + A[i]) % mod;
	
	for (int i = 0; i < N; i++) {
		inner_sum = (inner_sum - A[i] + mod) % mod;
		sum = (sum + (long long) inner_sum * A[i]) % mod;
	}
	
	return sum;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << get_sum(N, A);
	return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m[4],p[4]={10,50,100,500},x[4],y[4],k,i=0,q,j;
	while(true){
		cin>>n;if(!n){break;}
		if(i){
			cout<<endl;
		}
		i++;
		k=0;
		cin>>m[0]>>m[1]>>m[2]>>m[3];
		for(j=3;j>=0;j--){
			k+=m[j]*p[j];
		}
		q=k-n;
		for(int j=3;j>=0;j--){
			x[j]=q/p[j];
			q-=x[j]*p[j];
			y[j]=max(0,m[j]-x[j]);
		}
		for(int j=0;j<4;j++){
			if(y[j]){printf("%d %d\n",p[j],y[j]);}
		}
	}
}

Measured memory_bytes: 1176
import java.util.Scanner;

class Main{
	public static void main(String[] args){

		int[] hills = new int[10];
		Scanner stdIn = new Scanner(System.in);

		for( int i=0; i<10; i++ ){
			hills[i] = stdIn.nextInt();
		}

		for( int i=0; i<9; i++ ){
			for( int j=i+1; j<10; j++ ){
				if( hills[i] < hills[j] ) {
					int tmp = hills[i];
					hills[i] = hills[j];
					hills[j] = tmp;
				}
			}
		}

		for( int i=0; i<3; i++ ){
			System.out.println(hills[i]);
		}
	}
}

Measured memory_bytes: 26056
function main(input) {
  const n = parseInt(input[0]);
  const a = input[1].trim().split(" ").map(i => parseInt(i));

  let cnt = 0;

  for(let i=0;i<n;i=i+2){
    if(a[i]%2===1){
      cnt++;
    }
  }
  console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 29692
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    string S;
    map<char,long long> mp;

    for(int i=0;i<N;i++){
        cin >> S;
        mp[S[0]]++;
    }

    string march = "MARCH";
    long long res = 0;
    for(int i = 0;i<3;i++){
        for(int k = i+1;k<4;k++){
            for(int l = k+1;l<5;l++){
                res += mp[march[i]] * mp[march[k]] * mp[march[l]];
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
a,b,k = map(int,input().split())
num = []
x = 0
for i in range(1,a+1):
    x = 0
    if a%i == 0:
        x = i
        if b%i == 0:
            num.append(x)
        else:
            x = 0
    else:
        x = 0
print(num[-k])


Measured memory_bytes: 2940
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Comparator;

public class Main {
	class Edge{
		int p, q;
		double cost;
		Edge(int p, int q, double cost){
			this.p = p; this.q = q;
			this.cost = cost;
		}
	}
	int[] par;
//	union-findの木の初期化
	void unionfindInit(int n){
		for(int i = 0;i < n;i++) {
			par[i] = i;
		}
	}
//	木の根を求める
	int unionfindRoot(int x) {
		if(par[x]==x) {
			return x;
		}
		else {
			return par[x] = unionfindRoot(par[x]);
		}
	}
//	xとyが同じ集合に属するか否か
	boolean unionfindSame(int x, int y) {
		return unionfindRoot(x) == unionfindRoot(y);
	}
	
//	xとyの属する集合を併合
	void unionfinUnite(int x, int y) {
		x = unionfindRoot(x);
		y = unionfindRoot(y);
		if (x == y) return;
		par[x]=y;
	}
	void run(){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		par = new int[N+1];
		int M = scan.nextInt();
		int coordinate[][] = new int[N+1][2];
		int p, q;
		double hen1, hen2;
		double[] hypotenuse = new double[M]; //パイル間の距離
		PriorityQueue<Edge> edge = new PriorityQueue<Edge>(new Comparator<Edge>() {
			@Override
			public int compare(Edge e1, Edge e2) {
				if(e2.cost > e1.cost) {
					return 1;
				}
				else if(e2.cost < e1.cost){
					return -1;
				}
				return 0;
			}
		});
		Edge tmp = new Edge(0,0,0);
//		釘の座標情報
		for(int i=1; i< N+1;i++) {
			coordinate[i][0] = scan.nextInt();;
			coordinate[i][1] = scan.nextInt();;
		}
//		フェンスの情報
		unionfindInit(N+1);
		for(int i=0; i < M; i++) {
			p = scan.nextInt();
			q = scan.nextInt();
			hen1 = Math.abs(coordinate[p][0] - coordinate[q][0]);
			hen2 = Math.abs(coordinate[p][1] - coordinate[q][1]);
			hypotenuse[i] = Math.sqrt(hen1*hen1+hen2*hen2);
			edge.offer(new Edge(p, q, hypotenuse[i]));
		}
//		System.out.println("mainasu: " + mainasu_sum);
		double sum=0;
		for(int i = 0; i < M; i++) {
			tmp = edge.poll();
			if(!unionfindSame(tmp.p, tmp.q)) unionfinUnite(tmp.p, tmp.q);
			else {
				sum += tmp.cost;
//				System.out.println("tmp: " + tmp.cost);
			}
		}
		System.out.println(sum);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 68408
n = int(input())
m = list(map(int,input().split()))
f = True
for i in m:
  if i % 2 == 0:
    if (i % 3 == 0 ) or (i % 5 == 0 ):
      f = True
    else:
      print('DENIED')
      exit()

print('APPROVED')



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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));

    if (y <= 2019 && m <= 4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    string s;
    int a_b = 0, b_f = 0, b = 0, cnt = 0;
    bool f = 1;
    for(int i=0; i<N; i++){
        cin >> s;
        if(s[0]=='B' && s[s.size()-1]=='A'){
            b++;
        }else if(s[0]=='B'){
            b_f++;
        }else if(s[s.size()-1]=='A'){
            a_b++;
        }
        for(int j=0; j<s.size()-1; j++){
            if(s[j]=='A'&&s[j+1]=='B'){
                j++;
                cnt++;
            }
        }
    }
    cnt += b;
    if(b_f + a_b){
        cnt += min(a_b, b_f);
    }else if(b){
        cnt--;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3580
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int n = sc.nextInt();
        Deque<Character> deq = new ArrayDeque<>();
        for (int i = 0; i < s.length; i++) {
            deq.addFirst(s[i]);
        }
        boolean flg = false;
        for (int i = 0; i < n; i++) {
            int t = sc.nextInt();
            if(t == 1) {
                if(flg) {
                    flg = false;
                } else {
                    flg = true;
                }
            } else if(t == 2) {
                int f = sc.nextInt();
                char c = sc.next().charAt(0);
                if(flg && f == 1) {
                    deq.addFirst(c);
                } else if(!flg && f == 1) {
                    deq.addLast(c);
                } else if(flg && f == 2) {
                    deq.addLast(c);
                } else if(!flg && f == 2) {
                    deq.addFirst(c);
                }
            }
        }
        if(!flg) {
            while(!deq.isEmpty()) {
                System.out.print(deq.pollLast());
            }
        } else {
            while(!deq.isEmpty()) {
                System.out.print(deq.pollFirst());
            }
        }
    }
}


Measured memory_bytes: 67540
#include<bits/stdc++.h>
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 sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int n, m;

void dfs(int now, int s, int g, const vii &tree, vb &seen) {
  seen[now] = true;
  for(int next : tree[now]) {
    if(now == s && next == g) continue;
    if(seen[next]) continue;
    dfs(next, s, g, tree, seen);
  }
}

bool can(int s, int g, const vii &tree) {
  vb seen(n);
  dfs(s, s, g, tree, seen);
  return !seen[g];
}

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

  cin >> n >> m;
  vii tree(n);
  vi a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    tree[a[i]].push_back(b[i]);
    tree[b[i]].push_back(a[i]);
  }
  int ans = 0;
  rep(i,m) {
    ans += can(a[i], b[i], tree);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
X,Y = map(int,input().split())
if Y < X:
    X,Y = Y,X

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = result * int(numerator[k]) % (1e9+7)

    return result


if 2 * X < Y or X > 2 * Y or (X+Y)%3 != 0:
    print(0)
else:
    D = 1e9+7
    M = (X+Y)//3
    m = (2*X-Y)//3
    n=(2*Y-X)//3 
    res = cmb(M,m) % D
    """for i in range(M, M-m,-1):
        res *= i 
    for i in range(1,m+1):
        res //= i """
    print(int(res))


Measured memory_bytes: 46032
n,x,y = map(int, input().split())

kyori=[0]*10**7

import itertools
for seq in itertools.combinations(range(1,n+1),2):
    kyori_niten=seq[1]-seq[0]
    kyori_niten=min(kyori_niten,abs(x-seq[0])+abs(y-seq[1])+1)

    kyori[kyori_niten]+=1

for i in range(1,n):
    print(kyori[i])

Measured memory_bytes: 151744
H, W, N = map(int, input().split())
Sr, Sc = map(int, input().split())
Taka = input()
Aoki = input()

mincol = 1
maxcol = W
ans = True
for i in range(N-1, -1, -1):
    if Aoki[i] == "R" and mincol > 1:
        mincol -= 1
    if Aoki[i] == "L" and maxcol < W:
        maxcol += 1

    # print((mincol, maxcol))

    if Taka[i] == "L":
        mincol += 1
    if Taka[i] == "R":
        maxcol -= 1
    # print((mincol, maxcol))
    if mincol > maxcol:
        ans = False
        break
if Sc < mincol or Sc > maxcol:
    ans = False

# print("-------------")

minrow = 1
maxrow = H
for i in range(N-1, -1, -1):
    if Aoki[i] == "D" and minrow > 1:
        minrow -= 1
    if Aoki[i] == "U" and maxrow < H:
        maxrow += 1
    # print((minrow, maxrow))

    if Taka[i] == "U":
        minrow += 1
    if Taka[i] == "D":
        maxrow -= 1
    # print((minrow, maxrow))
    if minrow > maxrow:
        ans = False
        break

if Sr < minrow or Sr > maxrow:
    ans = False

if ans:
    print("YES")
else:
    print("NO")


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

using namespace std;

typedef long long llint;

int main() {
  llint a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2) {
    cout << -a + b << endl;
  } else {
    cout << a - b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
while True:
    n,m,a=map(int,input().split())
    if n==0:break
    l=[list(map(int,input().split())) for _ in range(m)]
    l.sort(reverse=True)
    for l2 in l:
        if l2[1]==a:
            a=l2[2]
            continue
        elif l2[2]==a:
            a=l2[1]
    print(a)



Measured memory_bytes: 5884
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;



class segment_tree {
private:
	ll num;
	vector<ll> dat;

	// TODO: change operator and its identity
	static const ll INI = 0;
	ll op(ll a, ll b) {
		return max(a, b);
	}

public:
	segment_tree(ll n_) {
		num = 1;
		while (num < n_) num *= 2;
		dat = vector<ll>(2 * num, INI);
	}

	// update the k-th value (0-indexed) to a
	void update(ll k, ll a) {
		k += num - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}

	// get the value of the range [a, b)
	// k: the index of the node  
	// [left, right): the range corresponds to the k-th node
	// call like getval(a, b)
	ll getval(ll a, ll b, ll k = 0, ll left = 0, ll right = -1) {
		if (right < 0) right = num;
		if (right <= a || b <= left) return INI;
		if (a <= left && right <= b) return dat[k];
		ll vleft = getval(a, b, 2 * k + 1, left, left + (right - left) / 2);
		ll vright = getval(a, b, 2 * k + 2, left + (right - left) / 2, right);
		return op(vleft, vright);
	}
};


ll h[200005];
ll a[200005];

int main() {
	ll N; cin >> N;
	for (ll i = 0; i < N; i++) cin >> h[i], h[i]--;
	for (ll i = 0; i < N; i++) cin >> a[i];
	segment_tree seg(N);
	for (ll i = 0; i < N; i++) {
		ll t = seg.getval(0, h[i]);
		seg.update(h[i], t + a[i]);
	}
	cout << seg.getval(0, N) << endl;
	return 0;
}

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

namespace ConsoleApp65 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int A = st[0];
            int B = st[1];

            string S = Console.ReadLine();

            char[] S_ = S.ToCharArray();

            if (S_[A] == '-' && S_.Where(x => x == '-').Count() == 1) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		if (t < 600)
 			out.println(8);
 		else if (t < 800)
 			out.println(7);
 		else if (t < 1000)
 			out.println(6);
 		else if (t < 1200)
 	 		out.println(5);
 	 	else if (t < 1400)
 	 		out.println(4);
 	 	else if (t < 1600)
 	 		out.println(3);
 	 	else if (t < 1800)
 	 		out.println(2);
 	 	else if (t < 2000)
 	 		out.println(1);
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25412
count = 0


def merge(A, left, mid, right):
    L = A[left:mid] + [float('INF')]
    R = A[mid:right] + [float('INF')]
    i = 0
    j = 0
    # 右と左比べて小さい方をとってくる
    for k in range(left, right):
        global count
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


n = int(input())
A = list(map(int, input().split()))
mergeSort(A, 0, len(A))
print(*A)
print(count)



Measured memory_bytes: 63692