akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int n;

ll aok[100010];
ll tak[100010];
ll low[100010];
ll high[100010];

int main(){
    int i,j,k,l;
    
    cin >> n;
    
    for (i=0;i<n;i++){
        scanf("%lld",tak+i);
        if (i == 0 || tak[i-1]!=tak[i]){
            low [i] = tak[i];
            high[i] = tak[i];
        }else{
            low [i] = 1ll;
            high[i] = tak[i];
        }
    }
    for (i=0;i<n;i++){
        scanf("%lld",aok+i);
    }
    for (i=n-1;0<=i;i--){
        if (i == n-1 || aok[i+1]!=aok[i]){
            low [i] = max(low [i],aok[i]);
            high[i] = min(high[i],aok[i]);
        }else{
            low [i] = max(low [i],1ll);
            high[i] = min(high[i],aok[i]);
        }
    }
    ll result = 1ll;
    for (i=0;i<n;i++){
        if (high[i] < low[i]){cout<<"0"<<endl;return 0;}
        result=(result * (high[i]-low[i]+1ll))%E107;
    }
    cout << result << endl;
    
    return 0;
}

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

int calcu(int a, int b, char op)
{
    switch (op){
        case '+':
            return(a+b);
        case '-':
            return(a-b);
        case '*':
            return(a*b);
        case '/':
            if(b == 0)
                return(-1);
            return(a/b);
    }
}

int main()
{
    int a,b;
    char op;
    while(true){
        cin >> a >> op >> b;
        if(op == '?')
            break;
        cout << calcu(a,b,op) << '\n';
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

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

bool eqpair(P a, P b){
    if(a.first == b.first && a.second == b.second){
        return true;
    }else{
        return false;
    }
}

int main(){
    long int h, w, n;
    cin >> h >> w >> n;
    vector<P> p;
    rep(i, n){
        long int a, b;
        cin >> a >> b;
        for (long int j = -1; j <= 1; j++){
            for (long int k = -1; k <= 1; k++){
                if ((1 < a - j && a - j < h && 1 < b - k && b - k < w)){
                    p.push_back(P(a-j,b-k));
                }
            }
        }
    }
    sort(p.begin(), p.end());
    long int ans[10];
    fill(ans, ans + 10, 0);
    long int sm = 0;
    long int num;
    if(p.size() > 0){
        num = 1;
    }else{
        num = 0;
    }
    
    for (int i = 0; i < (long int)(p.size() - 1); i++){
        if (eqpair(p[i], p[i+1])){
            num++;
        }else{
            if(num < 10){
                ans[num]++;
            }
            sm++;
            num = 1;
        }
    }
    if(num > 0){
        if(num < 10){
            ans[num]++;
        }
        sm++;
    }

    ans[0] = (h - 2) * (w - 2) - sm;
    rep(i, 10){
        cout << ans[i] << endl;
    }
}


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

using namespace std;

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

    while(T--) {
        int N;
        string s;
        cin >> N >> s;

        vector<int> subcnt(N+1, 0);

        for(int i = 0; i < 2*N; ++i) 
            if(s[i] == 'Y') subcnt[(i+1)/2] |= 0x01;
        for(int i = 2*N; i < 4*N; ++i) 
            if(s[i] == 'Y') subcnt[(i+1)/2-N] |= 0x02;

        int cost = N;
        int pos = 0;
        while(subcnt[pos] == 0) ++pos;
        if(subcnt[pos] & 0x02) cost += 2;
        else cost += 1;

        int lastpat = subcnt[pos];
        for(++pos; pos < N+1; ++pos) {
            if(subcnt[pos] & 0x01) cost += 1;
            if(subcnt[pos] & 0x02) cost += 1;
            if(subcnt[pos]) lastpat = subcnt[pos];
        }
        cost += 1;

        if(lastpat & 0x01) cost -= 1;
        if(lastpat == 0) cost = N;

        cout << cost << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>

using namespace std;

int main(){
    string s;
    cin >> s; 
    vector<string> result;
    while(s != "-") {
        // cout << "s: " << s << endl;
        int num;
        cin >> num;
        vector<int> data(num);
        for(int i = 0; i < num; i++) {
            cin >> data.at(i);
        }
        for(auto x: data){
            string pop = s.substr(0, x);
            // cout << "pop: " << pop << " s: " << s << endl;
            s.erase(0,x);
            s += pop;
        }
        result.push_back(s);
        s = "";
        cin >> s; 
    }
    for(auto x: result){
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>

int kyori(int x1,int y1,int x2,int y2){
    int po1=x1-x2;
    if(po1<0)po1*=-1;
    int po2=y1-y2;
    if(po2<0)po2*=-1;
    return po1+po2;
}

int main(void){
    int N;
    scanf("%d",&N);
    int x=0;
    int y=0;
    int t=0;
    for(int i=0;i<N;i++){
        int X,Y,T;
        scanf("%d %d %d",&T,&X,&Y);
        if(kyori(x,y,X,Y)>T-t||(T-t-kyori(x,y,X,Y))%2==1){printf("No");return 0;}
        else {
            x=X;
            y=Y;
            t=T;
        }
    }
    printf("Yes");
    return 0;
}


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

int  main()
{
	int n; cin >> n;
	int a,b;
	switch (n)
	{
		case 1:
			cout << "Hello World\n";
			break;
		case 2:
			cin >> a >> b; cout << a+b << endl;
			break;
	}
	return (0);
}


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

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()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (an, bn, cn, k) = (v[0], v[1], v[2], v[3]);
    let mut a = read_vec::<i64>();
    let b = read_vec::<i64>();
    let c = read_vec::<i64>();

    let mut a = a.into_iter().map(|x| -x).collect::<Vec<_>>();
    a.sort();
    let mut bc = Vec::new();
    for i in 0..bn {
        for j in 0..cn {
            bc.push(-b[i] - c[j]);
        }
    }
    bc.sort();
    let mut ans = a[0] + bc[0];

    let mut disp_count = 0;

    loop {
        // search ans
        let mut count_ans = 0;
        for ai in 0..a.len() {
            let li = bc.lower_bound(&(ans - a[ai]));
            let ui = bc.upper_bound(&(ans - a[ai]));
            count_ans += ui - li;
        }
        for i in 0..count_ans {
            println!("{0}", -ans);
            disp_count += 1;
            if disp_count == k {
                return;
            }
        }
        // search next ans
        let mut temp_ans = 0;
        for ai in 0..a.len() {
            let ui = bc.upper_bound(&(ans - a[ai]));
            if ui == bc.len() {
                continue;
            }
            temp_ans = min(a[ai] + bc[ui], temp_ans);
        }
        ans = temp_ans;
    }
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
    fn upper_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


Measured memory_bytes: 15608
n  = int(input())
a  = list(map(int,input().split()))
a = a[::-1]
b  = list(map(int,input().split()))
b = b[::-1]
c  = 0

for i in range(n):
	if a[i]<=b[i]:
		c+=a[i]
		if a[i]+a[i+1]>=b[i]:
			a[i+1]-=b[i]-a[i]
			c+=b[i]-a[i]
		else:
			c+=a[i+1]
			a[i+1]=0
	else:
		c+=b[i]

print(c)

Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

bool graph[8][8], visited[8] = {true};

int dfs(ll v, ll n){
	bool all_visited = true;
    rep(i, n){
		if(visited[i] == false)
			all_visited = false;
	}
	if(all_visited){
		return 1;
	}
	ll ret = 0;
	rep(i, n){
		if(graph[v][i] == false) continue;
		if(visited[i]) continue;

		visited[i] = true;
		ret += dfs(i, n);
		visited[i] = false;
	}
	return ret;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        a = n % 11;
        if(a == 0){
            print(n / 11 * 2);
        }else if(a <= 6){
            print(n / 11 * 2 + 1);
        }else{
            print(n / 11 * 2 + 2);
        }
    }
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
ans=0
maze=[input()for i in range(h)]
for i in range(2**h):
    for j in range(2**w):
        tate={c for c in range(h)if (i>>c)%2 }
        yoko={c for c in range(w)if (j>>c)%2 }
        cnt=0
        for x in range(h):
            if x in tate:continue
            for y in range(w):
                if y in yoko:continue
                cnt+=int(maze[x][y]=="#")
        if cnt==k:ans+=1
print(ans)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int N;
      cin >> N;
      vector<int> oic (N);
      for(int i = 0;i < N;i++){
          cin >> oic[i];
      }

      LL ans = 0;
      for(int i = 0;i < N;i++){
          for(int j = 0;j < N;j++){
              if(i != j){
                  ans += oic[i] * oic[j];
              }
          }
      }
      cout << ans/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	ll ans = 0;
	ll b = 0;
	string s;
	cin>>s;
	REP(i, s.length())
	{
		if(s[i]=='B')
			b++;
		else
			ans+=b;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3744
N=int(input())
a=list(map(int, input().split()))
for i in range(N):
    a[i]=a[i]*2
b=[0 for i in range(N)]
sum1=0
for i in range(N-1):
    if i%2==0:
        sum1+=a[i]
    else:
        sum1+=a[i]*(-1)
ans=(sum1+a[N-1])/2
b[0]=ans
for i in range(N-1):
    b[i+1]=a[i]-b[i]
for i in range(N):
    print(int(b[i]), end=" ")

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int ans = 0;
  for(int i=0; i<N; i+=2){
    ans += a.at(i);
  }
  for(int i=1; i<N; i+=2){
    ans -= a.at(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int i;
	unsigned long long K;
	string S;
	cin >> S >> K;
	for (i = 0;i <= S.size() - 1;i++) {
		if (S[i] == '1') {
			if (i+1 == K) {
				cout << 1 << endl;
				return 0;
			}
		}
		else {
			cout << S[i] << endl;
			return 0;
		}
	}
}

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

typedef long long ll;

int main() {
    int n; cin >> n;
    
    for(int bit=0; bit < (1<<n); bit++){
        cout << bit <<":";
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                cout <<" "<< i;
            }
        }
        cout << endl;
    }

}



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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 2e5 + 10;
int T;

int n;
LL k;

const int mod = 1e9 + 7;

const int MAX = 300;  //上限
//注意矩阵下标以0开始
struct MAT
{
    int r, c;
    LL d[MAX][MAX];

    MAT(int size)  //初始为单位矩阵
    {
        r = c = size;
        clr(d, 0);
        for (int i = 0; i < size; i++) d[i][i] = 1;
    }
    MAT(int _r, int _c)  //初始为全零矩阵
    {
        r = _r, c = _c;
        clr(d, 0);
    }

    friend MAT operator+(const MAT& m1, const MAT& m2);
    friend MAT operator*(const MAT& m1, const MAT& m2);
};

MAT operator+(const MAT& m1, const MAT& m2)
{
    MAT ret(m1.r, m2.c);

    for (int i = 0; i < m1.r; i++)
        for (int j = 0; j < m1.c; j++) ret.d[i][j] = (m1.d[i][j] + m2.d[i][j]) % mod;
    return ret;
}

MAT operator*(const MAT& m1, const MAT& m2)
{
    MAT ret(m1.r, m2.c);
    for (int i = 0; i < m1.r; i++)
        for (int j = 0; j < m1.c; j++)
            if (m1.d[i][j])
                for (int k = 0; k != m2.c; k++)
                    if (m2.d[j][k]) ret.d[i][k] = (ret.d[i][k] + (m1.d[i][j] * m2.d[j][k])) % mod;
    return ret;
}

MAT pow(MAT& a, LL p)
{
    MAT t = a, ans(a.r);
    for (; p; p >>= 1)
    {
        if (p & 1) ans = ans * t;
        t = t * t;
    }
    return ans;
}

MAT sum(MAT& a, LL p)
{
    int r = a.r;
    MAT t(2 * r), ret(r);
    for (int i = 0; i < r; i++)
        for (int j = 0; j < r; j++) t.d[i][j] = t.d[i][j + r] = a.d[i][j];
    t = pow(t, p);

    for (int i = 0; i < r; i++)
        for (int j = 0; j < r; j++) ret.d[i][j] = t.d[i][j + r];
    return ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n >> k)
    {
        MAT a(n, n);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                cin >> a.d[i][j];
            }
        MAT b = pow(a, k);
        LL ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                ans = (ans + b.d[i][j]) % mod;
            }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6444
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    int i;
    cin>>n;
    cin>>k;
    int x = 1;
    for(i = 0; i < n; i++)
    {
        if(k >= x)
        {
            x *= 2;
        }
        else
        {
            x += k;
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

k = sum(b) - sum(a)
m = [(max(a[i], b[i])+(a[i]<b[i] and (b[i]-a[i])%2==1)) for i in range(n)]
if k>=0 and sum(a)+2*k>=sum(m) and sum(b)+k>=sum(m):
    ans = "Yes"
else:
    ans = "No"
print(ans)

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

using namespace std;

int a[55] = {
  11, 31, 41, 61, 71, 
  101, 131, 151, 181, 191, 
  211, 241, 251, 271, 281, 
  311, 331, 401, 421, 431, 
  461, 491, 521, 541, 571, 
  601, 631, 641, 661, 691, 
  701, 751, 811, 821, 911, 
  941, 971, 1021, 1031, 1051, 
  1061, 1091, 1151, 1171, 1181, 
  1201, 1231, 1291, 1301, 1321, 
  1361, 1381, 1451, 1471, 1481
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cout << a[i] << (i == n - 1 ? '\n' : ' ');
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
const int maxn=1000000;
using namespace std;
 /*#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
    #endif*/
int main()

{ 
#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
    #endif  
   int n;
   cin>>n;
   ll l[n];
   for(int i=0;i<n;i++)
   {
   	cin>>l[i];
   }
   int cnt=0;
   for(int i=0;i<n;i++)
   {
   	  for(int j=0;j<n;j++)
   	  {
   	  	  for(int k=0;k<n;k++)
   	  	  {
   	  	  	   if((l[i]!=l[j])and(l[i]!=l[k])and(l[k]!=l[j]))
   	  	  	   {
   	  	  	   	    ll a,b,c;
   	  	  	   	    a=l[i];
   	  	  	   	    b=l[j];
   	  	  	   	    c=l[k];
   	  	  	   	    if((a+b>c)and(a+c>b)and(b+c>a))cnt++;
				}
			}
		 }
   }
   cout<<cnt/6<<endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b,c,d,ans,m,n,p;

    scanf("%llu %llu %llu %llu",&a,&b,&c,&d);
    m=c;
    n=d;
    while(m!=n)
    {
        if(m > n)
            m -= n;
        else
            n -= m;
    }
    p=(c*d)/m;

    ans=(b-a+1)-((b/c)+(b/d)-(b/p)-((a-1)/c)-((a-1)/d)+((a-1)/p));

    printf("%llu",ans);

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,tot;
const int N=5010,mod=1e9+7;
int head[N],to[N<<1],nt[N<<1],siz[N],f[N],dp[N][N],t[N];
void add(int f,int t)
{
	to[++tot]=t;nt[tot]=head[f];head[f]=tot;
}
void dfs(int x,int fa)
{
	siz[x]=1;dp[x][1]=1;
	for(int i=head[x];i;i=nt[i])
		if(to[i]!=fa)
		{
			dfs(to[i],x);
			for(int j=0;j<=siz[x];++j)t[j]=dp[x][j],dp[x][j]=0;
			for(int j=0;j<=siz[x];++j)
				for(int k=0;k<=siz[to[i]];++k)
					dp[x][j+k]=((LL)dp[x][j+k]+(LL)t[j]*dp[to[i]][k])%mod;				
			siz[x]+=siz[to[i]];
		}
	for(int i=0;i<=siz[x];++i)
		dp[x][0]=((LL)dp[x][0]-(LL)dp[x][i]*f[i])%mod;
}
signed main()
{
	cin>>n;
	for(int i=1,x,y;i<n;++i)
		scanf("%d%d",&x,&y),add(x,y),add(y,x);
	f[0]=1;
	for(int i=2;i<=n;i+=2)f[i]=(LL)f[i-2]*(i-1)%mod;
	dfs(1,0);
	cout<<(mod-dp[1][0])%mod;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  int64_t M=0,A=0,R=0,C=0,H=0;
  for(int i=0;i<N;++i){
    cin>>S.at(i); 
    if(S.at(i).at(0)=='M'){++M;}
    if(S.at(i).at(0)=='A'){++A;}
    if(S.at(i).at(0)=='R'){++R;}
    if(S.at(i).at(0)=='C'){++C;}
    if(S.at(i).at(0)=='H'){++H;}
  }

  int64_t sum=M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;
  cout<<sum<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> w.at(i);
        sum += w.at(i);
    }
    
    int s = 0;
    int ans = 100000;
    for (int i = 0; i < n - 1; i++)
    {
        s += w.at(i);
        sum -= w.at(i);

        ans = min(ans, abs(s - sum));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    A, B, C, X, Y = map(int, input().split())
    C *= 2
    ans = 0
    if A + B >= C:
        if X > Y:
            ans = C * Y + min(A, C) * (X - Y)
        else:
            ans = C * X + min(B, C) * (Y - X)
    else:
        if X > Y:
            ans = min(A, C) * (X - Y) + A * Y + B * Y
        else:
            ans = A * X + B * X + min(B, C) * (Y - X)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int N,i;
	long sum;
	cin >> N;
	int a[N];
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N, greater<int>());
	sum = 0;
	if (N % 2 == 0) {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2 - 1; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i - 2];
		}
	}
	else {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2 - 1; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i - 2];
		}
		if (a[(N - 1) / 2] - a[(N + 1) / 2] > a[(N - 3) / 2] - a[(N - 1) / 2]) {
			sum += a[(N - 1) / 2] - a[(N + 1) / 2];
		}
		else {
			sum += a[(N - 3) / 2] - a[(N - 1) / 2];
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }
 
template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cout.precision(15);
    int n,k;
    cin >> n >> k;
    vector<long double> a(n);
    cin >> a;

    for(int i = 0;i<n;i++){
        a[i] = (a[i] + 1) / 2;
    }
    vector<long double> v(n+1,0);
    for(int i = 0;i<n;i++) v[i+1] += v[i] + a[i];

    long double max_total = 0;
    for(int i = 0;i + k <= n;i++){
        long double now = v[i + k] - v[i];
        max_total = max(max_total, now);
    }
    cout << max_total << endl;
}

Measured memory_bytes: 9628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<char, char>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//

int simulate(const string &s, const vector<P> &td, int pos) {
    for (auto c : td) {
        if (s[pos] != c.first) continue;
        if (c.second == 'L') --pos;
        else ++pos;
        if (pos < 0) return -1; // 左に落ちる
        if (pos >= s.size()) return 1; // 右に落ちる
    }
    return 0;
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, Q; string s; cin >> N >> Q >> s;
    vector<P> td(Q);
    for (int i = 0; i < Q; ++i){
        cin >> td[i].first >> td[i].second;
    }

    // 左側の境目
    int low = -1, high = N;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        if (simulate(s, td, mid) == -1) low = mid;
        else high = mid;
    }
    int left_fall = high;

    // 右側の境目
    low = -1, high = N;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        if (simulate(s, td, mid) == 1) high = mid;
        else low = mid;
    }
    int right_fall = N-1-low;

    cout << N - (left_fall + right_fall) << endl;

    return 0;
}


Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		int N = S.length();
		int ans = 0;
		char[] S2A = new char[N];
		S2A[0] = S.charAt(0);
		if (N == 1) {
			ans = 0;
		} else {
			for (int i = 1; i < N; i++) {
				S2A[i] = S.charAt(i);
				if(func(S2A[i], S2A[i-1])) {
					ans++;
					if(S2A[i-1] == '0') {
						S2A[i] = '1';
					}else {
						S2A[i] = '0';
					}
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}

	public static boolean func(char c, char pre) {
		char cs;
		if (pre == '0') {
			cs = '1';
		} else {
			cs = '0';
		}
		if (c != cs) {
			c = cs;
			return true;
		}
		return false;
	}
}


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

int main() {
  int N; cin >> N;
  string s; cin >> s;
  vector<string> tmp = { "SS", "SW", "WS", "WW" };
  for (int i = 0; i < 4; i++) {
    string t = tmp.at(i);
    for (int j = 1; j < N-1; j++) {
      if (t.at(j) == 'S' && s.at(j) == 'o') {
        if (t.at(j-1) == 'S') t += 'S';
        else t += 'W';
      }
      else if (t.at(j) == 'S' && s.at(j) == 'x') {
        if (t.at(j-1) == 'S') t += 'W';
        else t += 'S';
      }
      else if (t.at(j) == 'W' && s.at(j) == 'o') {
        if (t.at(j-1) == 'S') t += 'W';
        else t += 'S';
      }
      else if (t.at(j) == 'W' && s.at(j) == 'x') {
        if (t.at(j-1) == 'S') t += 'S';
        else t += 'W';
      }
    }
    bool ok = true;
    if (t.at(N-1) == 'S' && s.at(N-1) == 'o') {
      if (t.at(N-2) != t.at(0)) ok = false;
    }
    else if (t.at(N-1) == 'S' && s.at(N-1) == 'x') {
      if (t.at(N-2) == t.at(0)) ok = false;
    }
    else if (t.at(N-1) == 'W' && s.at(N-1) == 'o') {
      if (t.at(N-2) == t.at(0)) ok = false;
    }
    else if (t.at(N-1) == 'W' && s.at(N-1) == 'x') {
      if (t.at(N-2) != t.at(0)) ok = false;
    }

    if (t.at(0) == 'S' && s.at(0) == 'o') {
      if (t.at(N-1) != t.at(1)) ok = false;
    }
    else if (t.at(0) == 'S' && s.at(0) == 'x') {
      if (t.at(N-1) == t.at(1)) ok = false;
    }
    else if (t.at(0) == 'W' && s.at(0) == 'o') {
      if (t.at(N-1) == t.at(1)) ok = false;
    }
    else if (t.at(0) == 'W' && s.at(0) == 'x') {
      if (t.at(N-1) != t.at(1)) ok = false;
    }

    if (ok) { cout << t << endl; return 0; }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s;
    cin >> s;
    bool fla = false;
    
    for(int i = 0;i < s.size();i++){
        if(s.at(i) == '7')
            fla = true;
    }

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

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
//#define int long long

long double L;
signed main(){
    cin >> L;
    long double ans = L/3;
    ans = ans * ans * ans;
    printf("%.10Lf\n",ans);
}

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

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  string a, b, c;
  cin>>a>>b>>c;
  int cnt = 0;
  REP(i,n) {
    vector<int> p(26);
    p[a[i] - 'a']++;
    p[b[i] - 'a']++;
    p[c[i] - 'a']++;
    int mx = 0;
    REP(j,26) mx = max(mx, p[j]);
    cnt += 3 - mx;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXN 110
#define LL long long
#define P 1000000007
using namespace std;

LL nfib,fib[MAXN];
vector< pair<LL,LL> > S[MAXN];
LL n1,n2;
int nl,cnt,dep;

void init(){
	nfib=90;
	fib[0]=1;
	fib[1]=1;
	for(int i=2;i<=nfib;i++) fib[i]=fib[i-1]+fib[i-2];
	S[1].push_back(make_pair(1,2)); S[1].push_back(make_pair(2,4));
	for(int i=2;i<=nfib;i++){
		for(int j=0;j<S[i-1].size();j++){
			LL x1=S[i-1][j].first,x2=S[i-1][j].second;
			while(x2<fib[i+2]){
				S[i].push_back(make_pair(x2,x1+x2));
				x2+=x1;
			}
		}
	}
}

int gao1(LL X,LL Y){
	if(X==1 && Y==1) return 1;
	int now=1;
	while(fib[now]<=X && fib[now+1]<=Y) now++;
	return --now;
}

pair<LL,LL> trans(int step,LL x1,LL x2){
	LL k1=(step>=2?fib[step-2]:0);
	LL k2=(step>=1?fib[step-1]:0);
	LL k3=(step>=1?fib[step-1]:0);
	LL k4=fib[step];
	if(!step) k1=1;
	return make_pair(k1*x1+k3*x2,k2*x1+k4*x2);
}

LL gao(LL X,LL Y){
	if(fib[nl]>X || fib[nl+1]>Y) return 0;
	LL res=0;
	for(int i=0;i<S[nl].size();i++){
		LL x1=S[nl][i].first,x2=S[nl][i].second;
		if(x1<=X && x2<=Y) res+=(Y-x2)/x1+1;
	}
	return res;
}

void query(LL X,LL Y){
	if(X>Y) swap(X,Y);
	nl=gao1(X,Y);
	printf("%lld ",nl);
	if(nl==1){
		printf("%lld\n",X*Y%P);
		return;
	}
	LL ans2=(gao(X,X)+gao(X,Y))%P;
	printf("%lld\n",ans2);
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	init();
	int m;
	scanf("%d",&m);
	while(m--){
		LL X,Y;
		scanf("%lld%lld",&X,&Y);
		query(X,Y);
	}
}


Measured memory_bytes: 6144
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


s = input()

ans = []

for i in range(len(s)):
    if s[i] != "B":
        ans.append(s[i])
    else:
        if (len(ans) > 0):
            ans = ans[:-1]

for i in range(len(ans)):
    print(ans[i], end="")




Measured memory_bytes: 8928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    long long int a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)
        cout<<(b-a)/2<<endl;
    else if((b-a)==1)
        {
            if((b-1)<=(n-a))
            cout<<(b-1)<<endl;
            else
                cout<<(n-a)<<endl;
        }
        else
        {
            if((b-1)<=(n-a)){
                long long int p=a-1;
                long long int c=b-a;
                long long int d=(c-1)/2;
                cout<<(p+d+1);
                }
            else{
                long long int e=n-b;
                long long int f=a+e+1;
                long long int g=(n-f)/2;
                cout<<(g+e+1);}
        }
}


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

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

        int n = scan.nextInt();

        long[] tall = new long[n];
        Map<Long, Long> map = new HashMap<>();
        for (int x = 0; x < n; x++) {
            tall[x] = scan.nextInt();
            map.put(x + tall[x], map.getOrDefault(x + tall[x], (long) 0) + 1);
        }

        long count = 0;
        for (int y = 0; y < n; y++) {
            count += map.getOrDefault(y - tall[y], (long) 0);
        }
      
        System.out.println(count);
    }
}

Measured memory_bytes: 72576
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> a(n+1);
  REP(i, n+1) cin >> a[i];
  vector<int> b(n);
  REP(i, n) cin >> b[i];

  int sum = 0; // 倒したモンスターの数
  REP(i, n) {
    if(a[i]) {
      if (b[i] >= a[i]) {
        b[i] -= a[i];
        sum += a[i];
        a[i] = 0;
      }
      else {
        sum += b[i];
        a[i] -= b[i];
        b[i] = 0;
      }
    }
    if(b[i]) {
      if (b[i] >= a[i+1]) {
        b[i] -= a[i+1];
        sum += a[i+1];
        a[i+1] = 0;
      }
      else {
        sum += b[i];
        a[i+1] -= b[i];
        b[i] = 0;
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i;
    char A[11],B[11],C[11];

    scanf("%s%s%s",A,B,C);
    int ae=strlen(A);
    int be=strlen(B);
    if(A[ae-1] == B[0] && B[be-1] == C[0])
    printf("YES\n");
    else
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return kai(n - 1)*n;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n, a[100005], cnt;
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > a[i - 1])cnt += a[i] - a[i - 1];
		else cnt += a[i - 1] - a[i];
	}
	cnt += abs(a[n]);
	for (int i = 1; i <= n; i++) {
		int cntt = cnt;
		if (a[i] > a[i - 1])cntt -= a[i] - a[i - 1];
		else cntt -= a[i - 1] - a[i];
		if (a[i + 1] > a[i])cntt -= a[i + 1] - a[i];
		else cntt -= a[i] - a[i + 1];
		if (a[i - 1] > a[i + 1])cntt += a[i - 1] - a[i + 1];
		else cntt += a[i + 1] - a[i - 1];
		cout << cntt << endl;
	}
	endre;
}


Measured memory_bytes: 2048
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
R, S, P = mapint()
T = list(input())

ans = 0
for i in range(N):
    t = T[i]
    if i<K:
        if t=='r':
            ans += P
        elif t=='s':
            ans += R
        else:
            ans += S
    else:
        if T[i-K]==T[i]:
            T[i] = '0'
            continue
        else:
            if t=='r':
                ans += P
            elif t=='s':
                ans += R
            else:
                ans += S  
print(ans)

Measured memory_bytes: 78304
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

int abs(int x){
	if(x<0) return x*-1;
	else return x;
}

int main(){
	int n,k;
	while(cin >> n >> k){
		if(n==0&&k==0) break;
		vector<int> card(k);
		for(int i=0; i<k; ++i){
			cin >> card[i];
		}
		sort(card.begin(),card.end());
		vector<int> d(n+1);
		for(int i=0; i<k; ++i){
			d[card[i]]=1;
		}
		/*
		for(int i=0; i<=n; ++i){
			cout << d[i] << "\n";
		}
		*/
		int ans=0;
		int cnt=0;
		if(d[0]==0){
			for(int i=1; i<=n; ++i){
				if(d[i]==1){
					++cnt;
				} else {
					ans=max(ans,cnt);
					cnt=0;
				}
			}
		} else {
			int tmp=0;
			for(int i=1; i<=n; ++i){
				if(d[i]==1){
					++cnt;
				} else {
					ans=max(ans,tmp+cnt);
					tmp=cnt+1;
					cnt=0;
				}
			}
			ans=max(ans,tmp+cnt);
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 1796
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]"):
    ret = 0
    for i, v in enumerate(a):
        if i % 2 == 0 and v % 2:
            ret += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

int H,W;
vector<string> fi;

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

int main(void){
  cin >> H >> W;
  fi.resize(H);
  for(int i = 0; i < H; ++i) cin >> fi[i];
  
  // 多点をスタートとして扱う
  vector<vector<int> > dist(H, vector<int>(W,-1));
  using pint = pair<int, int>;
  queue<pint> que;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(fi[i][j] == '#'){
        dist[i][j] = 0;
        que.push(pint(i, j));
      }
    }
  }
  
  // BFS
  while(!que.empty()){
   auto cur = que.front();
    que.pop();
    for(int dir = 0; dir < 4; ++dir){
     	int nx = cur.first + dx[dir];
    	int ny = cur.second + dy[dir];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(dist[nx][ny] == -1){
         dist[nx][ny] = dist[cur.first][cur.second] + 1;
         que.push(pint(nx,ny));
      }
    }
  }
  int res = 0;
  for(int i = 0; i < H; ++i){
   	for(int j = 0; j < W; ++j){
     	res = max(res, dist[i][j]); 
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 13456
#include <iostream>

struct Phi {
	Phi(const int &p = 0) :prime(p), exp(0) {};
	int prime, exp;
	void operator++() { ++exp; }
	int get_phi() { return (prime - 1) * exponent(prime, exp - 1); }
	int exponent(const int &p, const int &e) {
		if (e == 0) {
			return 1;
		}
		else if (e == 1) {
			return p;
		}
		else {
			auto temp = exponent(p, e / 2);
			return temp * temp * exponent(p, e % 2);
		}
	}
};
int phi(int n, int p) {
	if (n == 1) {
		return 1;
	}else if (n % p == 0) {
		Phi ph(p);
		while ((n % p) == 0) {
			++ph;
			n = n / p;
		}
		return phi(n, p + 2) * ph.get_phi();
	}
	else {
		while (n % p != 0)p += 2;
		return phi(n, p);
	}
}
int phi2(int n) {
	if ((n & 1) == 0) {
		Phi ph(2);
		while ((n & 1) == 0) {
			++ph;
			n = n >> 1;
		}
		return phi(n, 3) * ph.get_phi();
	}
	else {
		return phi(n, 3);
	}
}
int main() {
	int n;
	std::cin >> n;
	std::cout << phi2(n) << std::endl;
}

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

int main(void)
{
    int n;
    char s[51];
    int count = 0;

    scanf("%d", &n);
    scanf("%s", s);

    int len = strlen(s);

    for (int i = 0; i < len-2; i++){
        if(s[i] == 'A'&& s[i+1] == 'B' && s[i+2] == 'C')
        count++;
    }

    printf("%d", count);

    return 0;


}

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

using namespace std;

main(){
    int n;
    scanf("%d",&n);
    int sum = 0;
    int a,b;
    while(n--){
        scanf("%d %d",&a,&b);
        sum += abs(b-a) + 1;
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 256
fn main() {
    let mut sc = cin();
    while sc.read() {
        let n = sc.next();
        let m = sc.next();
        let ss = sc.mat::<i32>(n, 2);
        let cs = sc.mat::<i32>(m, 2);
        for s in ss {
            let near = cs.iter().min_by_key(
                |a| (a[0] - s[0]).abs() + (a[1] - s[1]).abs()
            ).unwrap();
            let ans = cs.iter().position(|x| x == near).unwrap() + 1;
            println!("{}", ans);
        }
    }
}

#[allow(dead_code)]
fn cin() -> Scanner<std::io::Stdin> {
    Scanner::new(std::io::stdin())
}

#[allow(dead_code)]
pub struct Scanner<T> {
    buf: Vec<u8>,
    len: usize,
    idx: usize,
    next: Option<String>,
    reader: T,
}

#[allow(dead_code)]
impl<Reader: std::io::Read> Scanner<Reader> {
    fn new(r: Reader) -> Scanner<Reader> {
        Scanner {
            buf: vec![0; 8192],
            len: 0,
            idx: 0,
            next: None,
            reader: r,
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        self.wrapped::<T>().unwrap()
    }

    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn mat<T: std::str::FromStr>(&mut self, r: usize, c: usize) -> Vec<Vec<T>> {
        (0..r).map(|_| self.vec(c)).collect()
    }

    fn vec_char(&mut self) -> Vec<char> {
        self.read();
        self.next.take().unwrap().chars().collect()
    }

    fn mat_char(&mut self, r: usize) -> Vec<Vec<char>> {
        (0..r).map(|_| self.vec_char()).collect()
    }

    fn wrapped<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.read();
        self.next.take().and_then(|s| s.parse::<T>().ok())
    }

    fn read(&mut self) -> bool {
        if self.next.is_some() {
            return true;
        }
        let mut s = String::with_capacity(16);
        while let Some(c) = self.get_char() {
            if !c.is_whitespace() {
                s.push(c);
            } else if !s.is_empty() {
                break;
            }
        }
        self.next = if !s.is_empty() { Some(s) } else { None };
        self.next.is_some()
    }

    fn get_char(&mut self) -> Option<char> {
        if self.idx == self.len {
            match self.reader.read(&mut self.buf[..]) {
                Ok(l) if l > 0 => {
                    self.idx = 0;
                    self.len = l;
                }
                _ => return None,
            }
        }
        self.idx += 1;
        Some(self.buf[self.idx - 1] as char)
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double ans = 0.0;
		for(int i = 0; i < n; ++i){
			int a = sc.nextInt();
			double tmp = 1.0 / (double)a;
			ans += tmp;
		}
		sc.close();
		ans = 1.0 / ans;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))
#define all(vec) vec.begin(), vec.end()

#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n;
    cin >> n;
    vector<int> vec(n);
    els(vec) {
        cin >> el;
    }
    sort(all(vec));
    int mid = n / 2;
    cout << vec[mid] - vec[mid - 1] << endl;
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 640
#include <stdio.h>

#define max 100000

int main()
{
    int A, B, M, i, j, k, rei[max], dens[max], ans1[max], ans2, test1=max, test2=max, min, min2;
    int proA[max], proB[max], ticket[max];
    
    scanf("%d %d %d", &A, &B, &M);
    
    for(i=0; i<A; i++){
        scanf("%d", &proA[i]);
    }
    for(j=0; j<B; j++){
        scanf("%d", &proB[j]);
    }
    
    for (k=0; k<M; k++) {
        scanf("%d %d %d", &rei[k], &dens[k], &ticket[k]);
    }
    
    for(i=0; i<M; i++){
        ans1[i] = proA[rei[i]-1]+proB[dens[i]-1]-ticket[i];
    }
    
    test1=ans1[0];
     for(i=1; i<M; i++){
         if(test1>ans1[i]){
        test1 = ans1[i];
         }
    }
    
    min=proA[0];
   for(i=1; i<A; i++){
       if(min>proA[i]){
      min = proA[i];
       }
  }
 
    min2=proB[0];
     for(i=1; i<B; i++){
         if(min2>proB[i]){
        min2 = proB[i];
         }
    }

            
    test2=min+min2;
    
    if(test1<test2)
        printf("%d", test1);
    else
        printf("%d", test2);
    
    return 0;
}


Measured memory_bytes: 2560