akhauriyash/Code-Regression huggingface dataset:
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll test = 1, H, W, M;
set <int> h[N], w[N];

void solve(){
	cin >> H >> W >> M;
	for(int i = 1; i <= M; i++){
		int hi, wi; cin >> hi >> wi;
		h[hi].insert(wi);
		w[wi].insert(hi);
	}
	int mxh = 0, mxw = 0;
	vll hv, wv;
	for(int i = 1; i <= H; i++) mxh = max(mxh,(int)h[i].size());
	for(int i = 1; i <= H; i++) if(h[i].size() == mxh) hv.pb(i);
	for(int i = 1; i <= W; i++) mxw = max(mxw,(int)w[i].size());
	for(int i = 1; i <= W; i++) if(w[i].size() == mxw) wv.pb(i);
	int f = 1;
	for(auto it : hv){
		if(f == 0) break;
		for(auto it1 : wv){
			if(f == 0) break;
			if(h[it].find(it1) == h[it].end()) f = 0;
		}
	}
	deb1(mxh+mxw-f)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 67740
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<int> h(n);
    rep(i,0,n) cin >> h[i];
    V<int> dp(n, INT_MAX);
    dp[n-1] = 0;
    rep(i,n-1,0) {
        rep(j,1,k+1) {
            if (i+j >= n) break;
            dp[i] = min(dp[i], dp[i+j]+abs(h[i]-h[i+j]));
        }
    } 
    cout << dp[0] << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <deque>

using namespace std;
int main() {

	int n;
	vector<int> ar;
	cin >> n;
	int input,i=0;

	for (i; i < n * 2; i++) {
		cin >> input;
		ar.push_back(input);
	}
	sort(ar.rbegin(),ar.rend());
	int ans = 0;
	for (i = 0; i < n*2; i += 2) {
		ans += min(ar[i], ar[i + 1]);
	}
	printf("%d", ans);
	cin >> ans;
	return 0;
}

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

int n,m,x,y,cnt=0;
int father[100005],v[100005];

int find(int x)
{
	if (x!=father[x])  father[x]=find(father[x]);
	return father[x];
}

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)  father[i]=i;
	for (int i=1;i<=m;i++)
	{
		cin>>x>>y;
		father[find(y)]=find(x);
	}
	for (int i=1;i<=n;i++)  father[i]=find(father[i]);
	for (int i=1;i<=n;i++)  v[find(i)]++;
	for (int i=1;i<=n;i++)
	{
		if (v[i])  cnt++;
	}
	cout<<cnt-1<<endl;
	
	return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n, a, b;
string s;

int main() {
    cin >> n >> a >> b >> s;

    int cntb = 0; int passed = 0;

    FORN(i, n) {
        if (s[i] == 'a') {
            if (passed < a + b) {
                printf("Yes\n");
                passed++;
            }
            else {
                printf("No\n");
            }
        }
        else if (s[i] == 'b') {
            if (passed < a + b && cntb < b) {
                printf("Yes\n");
                passed++;
            }
            else {
                printf("No\n");
            }
            cntb++;
        }
        else {
            printf("No\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1e10;
ll w[105], v[105];
ll dp[300005];
ll a[200005];
ll b[200005];
int main() {
	ll n;
	cin >> n;
	ll max = -inf;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
		if (max < a[i]) {
			max = a[i];
		}
	}
	sort(a, a + n);
	ll ans = 0;
	ll count = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] != max) {
			ans = i;
			break;
		}
		else {
			count++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (b[i] != max) {
			cout << a[n - 1] << endl;
		}
		else {
			if (count == 1) {
				cout << a[ans] << endl;
			}
			else {
				cout << a[n - 1] << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 5632
// AtCoder ABC135: C - City Savers
// 2019.8.26 bal4u

#include <stdio.h>

typedef long long ll;

//// 高速入力
#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int a[100005];
int b[100005];

int main()
{
	int i, p, N; ll ans;
	
	N = in(); 
	for (i = 0; i <= N; i++) a[i] = in();
	for (i = 0; i <  N; i++) b[i] = in();
	ans = 0; p = 0;
	for (i = 0; i <= N; i++) {
		if (p >= a[i]) ans += a[i], p = b[i];
		else if (p+b[i] <= a[i]) ans += p+b[i], p = 0;
		else ans += a[i], p = b[i]-(a[i]-p);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
int main(void){
    int r,g,b,num;
    scanf("%d %d %d",&r,&g,&b);
    num=r*100+g*10+b;
    if(num%4==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const int NMAX = 111111;
ll minv[NMAX * 2];

int main(){
	int h, w, a, b; scanf("%d%d%d%d", &h, &w, &a, &b);

	minv[1] = 1;
	for (int i = 2; i < 2 * NMAX; i++)
		minv[i] = (MOD - (MOD / i)*minv[MOD%i] % MOD) % MOD;

	ll tot = 1;
	for (int i = 1; i <= w + h - 2; i++) tot = tot*i%MOD;
	for (int i = 1; i < w; i++) tot = tot*minv[i] % MOD;
	for (int i = 1; i < h; i++) tot = tot*minv[i] % MOD;

	ll s0 = 1, t0 = 1;
	for (int i = 1; i <= w - 1 + a - 1; i++) t0 = t0*i%MOD;
	for (int i = 1; i < w; i++) t0 = t0*minv[i] % MOD;
	for (int i = 1; i < a; i++)t0 = t0*minv[i] % MOD;

	ll ret = s0*t0%MOD;
	for (int i = 1; i < b; i++){
		s0 = s0*(h - a - 1 + i) % MOD;
		s0 = s0*minv[i] % MOD;

		t0 = t0*minv[w - 1 + a - 1 - i + 1] % MOD;
		t0 = t0*(w - 1 - i + 1) % MOD;
		ret = (ret + s0*t0%MOD) % MOD;
	}

	tot = (tot - ret + MOD) % MOD;
	printf("%lld", tot);
}

Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[15];
	scanf("%s", str);
	if (strlen(str) % 2 != 0) {
		printf("No");
		return 0;
	} 
	else {
		for (int i = 0; i < strlen(str); i+=2) {
			if (!(str[i] == 'h' && str[i + 1] == 'i')) {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b , c = 1;
    cin >> a >> b;
    cout << b * (int)pow( b - 1 , a - 1 );
}

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

int main(){
  int length, width;
  while(1){
    cin >> length >> width;
    if(length == 0 || width == 0){
      break;
    }
    for(int i = 0; i < length; i++){
      for(int j = 0; j < width; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n;
  cin >> n;
  
  map<int, double> mp;
  REP(i, n){
    int a;
    cin >> a;
    mp[a]++;
  }

  vector<vector<vector<double>>> dp(n+1, vector<vector<double>>(n+1, vector<double>(n+1, 0)));
  dp[0][0][0] = 0;

  REP(k, n+1){
    REP(j, n+1){
      REP(i, n+1){
        if(i == 0 && j == 0 && k == 0) continue;
        double p = 0;
        if(i > 0) p += dp[i-1][j][k] * i;
        if(i < n && j > 0) p += dp[i+1][j-1][k] * j;
        if(j < n && k > 0) p += dp[i][j+1][k-1] * k;
        p += n;
        p *= 1.0 / (i+j+k);
        dp[i][j][k] = p;
      }
    }
  }
  cout << fixed << setprecision(10) << dp[mp[1]][mp[2]][mp[3]] << endl;

  return 0;
}

Measured memory_bytes: 218880
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();

    let n: usize = {
        let mut n = String::new();
        stdin.read_line(&mut n).unwrap();
        n.trim().parse::<usize>().unwrap()
    };

    let mut s: Vec<Vec<char>> = Vec::with_capacity(n);
    for _ in 0..n {
        let mut input = String::with_capacity(10);
        stdin.read_line(&mut input).unwrap();
        let mut input = input.trim().chars().collect::<Vec<char>>();
        input.sort();
        
        s.push(input);
    }

    s.sort();

    let mut counter = Vec::new();
    let mut prev: i64 = 0;
    for i in 1..n {
        if s[i] == s[i-1] {
            prev += 1;
        } else {
            if prev > 0 { counter.push(prev); }
            prev = 0;
        }
    }
    counter.push(prev);
    
    println!("{}", counter.iter().map(|i| comb(i)).sum::<i64>() );
}

fn comb( i: &i64 ) -> i64 {
    if i == &0 { 0 } else {
        //let i = *i as i64;
        *i * (*i+1) / 2
    }
}


Measured memory_bytes: 14588
#![allow(unused)]

#[allow(unused_imports)]
use std::{cmp, collections, fmt, io, iter, ops, str};
use cmp::Ordering::*;
use collections::{HashMap, HashSet};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($arg: tt)*) => { eprintln!($fmt, $($arg)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt: expr) => {};
    ($fmt: expr, $($arg: tt)*) => {};
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    let _ = parse_line::<usize>();
    let a = parse_vec::<i32>();

    let n = *a.iter().max().unwrap();

    // min. |x - n / 2|
    let k = a.iter().max_by_key(|x| -(2 * *x - n).abs()).unwrap();

    println!("{} {}", n, k);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

//約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  int N;
  string S,T,ans;
  cin >> N >> S >> T;
  rep(i,N){
    ans.push_back(S[i]);
    ans.push_back(T[i]);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    a.sort()
    check = [i+1 - (i+n)%2 for i in range(n)]
    if a != check:
        print(0)
        return
    else:
        ans = pow(2, n//2, mod)
        print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 20556
# ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
# from math import gcd


def divisors(n: int) -> set:
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i), div.add(n // i)
    return sorted(div)


def main():
    A, B = map(int, input().split())
    divs = divisors(gcd(A, B))
    divs.pop(0)  # 1 divides all numbers -> pop
    groups = set()
    for i in divs:
        if all(i % x for x in groups):
            groups.add(i)  # coprime to all numbers in "groups"
    ans = len(groups) + 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5844
use proconio::input;

fn main() {
    input! {
        n: usize,
        v: [u64; n], // v_1 v_2 ... v_n
    }

    let mut flag1 = false;
    for &a in v.iter() {
        if a == 0 {
            flag1 = true;
        }
    }

    let mut ans = 1;
    let mut flag2 = false;
    if !flag1 {
        for &a in v.iter() {
            if ans as f64 > (1000000000000000000.0 as f64/a as f64) {
                flag2 = true;
                break;
            }
            ans *= a;
        }

    }
 
    if flag1 {
        println!("0")
    } else if flag2 || (ans > 1000000000000000000) {
        println!("-1")
    } else {
        println!("{}",ans)
    }
}

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

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

    int ans = 0, count = 0;
    string input;
    cin >> input;

    for(int i = 0; i < input.length(); ++i){
        if(input[i] == 'A' || input[i] == 'C' || input[i] == 'G' || input[i] == 'T'){
            count++;
        }
        else{
            count = 0;
        }
        ans = max(ans, count);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int N = 3e5 + 50;
int mod = 998244353;
ll n, a, b;
ll f[N], inv[N];
ll k;
ll power(ll b, ll p)
{
	ll res = 1;
	while(p)
	{
		if(p % 2)
			res = (res * b) % mod;
		b = (b * b) % mod;
		p /= 2;
	}
	return res % mod;
}
ll ncr(ll x, ll y)
{
    if(y > x)
        return 0;
    return ((f[x] * inv[y]) % mod * inv[x - y]) % mod;
}
int main()
{
	f[0] = 1;
	inv[0] = power(f[0], mod - 2);
	for(int i = 1; i < N; i++)
	{
		f[i] = (i * 1ll * f[i - 1]) % mod;
		inv[i] = power(f[i], mod - 2);
	}
	cin >> n >> a >> b >> k;
	ll ans = 0;
    for(int i = 0; i <= n; i++)
    {
        ll kk = k - i * a;
        if(kk < 0)
            break;
        if(kk % b)
            continue;
        if(kk / b > n)
            continue;
        ans = (ans + ncr(n, i) * ncr(n, kk / b)) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 200100;

int n,k;
int a[d5], f[d5];

//この判定は毎回書く
bool isOK(int key){
    //あるスコア以内に達成できるか
    int score=0;
    int t = k;
    for (int i = 0; i < n; i++)
    {
        int get = a[i] * f[i];
        if(f[i]>key){
            get = inf;
        }
        if(get>key){
            t -= a[i]-key/f[i];
            if(t<0){
                get = inf;
            }
            else{
                get = key / f[i] * f[i];
            }
        }
        score = max(score, get);
    }
    if(score>key)return false;
    else return true;
}

int meguru(){
    int low=-1;
    int high=inf;
    while(abs(high-low)>1){
        int mid=(high+low)/2;
        if(isOK(mid))high=mid;
        else low=mid;
    }
    return high;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for (int i = 0; i < n;i++)
        cin >> a[i];
    for (int i = 0; i < n;i++)
        cin >> f[i];
    sort(a,a+n);
    sort(f,f+n, greater<int>());
    cout << meguru() << endl;
}

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

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]) return false;
	else if (now == g)  return true;

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

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

	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == a[dice]){
				if (*it > 0){
					now = now + a[dice] + N[now + a[dice]];
					cout << 1 << endl;
				}
				else{
					now = now - a[dice] + N[now - a[dice]];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

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

void fnInput(string& rsColor)
{
  int nColorSiz;
  cin >> nColorSiz >> rsColor;
}

int fnColorCount(string sColor)
{
  int nColorCnt = 0;
  int nBgn = 0;

  while (nBgn < sColor.size())
  {
    char cColor = sColor[nBgn];
    nColorCnt++;

    int nFoward = nBgn + 1;
    while ( nFoward < sColor.size()  &&
            cColor == sColor[nFoward]  )
      nFoward++;

    nBgn = nFoward;
  }

  return nColorCnt;
}

int main()
{
  string sColor;

  fnInput(sColor);
  cout << fnColorCount(sColor) << endl;

  return 0;
}

Measured memory_bytes: 512
//13
#include<iostream>

using namespace std;

int main(){
  bool suc=false;
  for(int a,b;cin>>a>>b,a|b;){
    if(suc){
      cout<<endl;
    }
    suc=true;
    bool out=false;
    for(;a<=b;a++){
      if(a%400==0 || (a%4==0&&a%100)){
	cout<<a<<endl;
	out=true;
      }
    }
    if(!out){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}
    

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

int main()
{
	int a, b;
	while(cin >> a >> b&&a!=0&&b!=0){
		for (int i = 0; i < a; i++){
			for (int i = 0; i < b; i++){
				cout << '#';
			}
			cout << endl;
		}cout << endl;
	}
	return 0;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  string s; cin >> s;
  int black_count = 0;
  int ans = 0;
  REP(i,s.size()) {
    if(s[i] == 'B') ++black_count;
    else ans += black_count;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 640
from functools import reduce
from fractions import gcd
n,k= map(int,input().split())
a = list(map(int,input().split()))
if k in a:
  print('POSSIBLE')
  exit()
elif k > max(a):
  print('IMPOSSIBLE')
  exit()
    
m = reduce(gcd, a)
for i in a:
  if (i - k) % m == 0:
    print('POSSIBLE')
    break
else:
  print('IMPOSSIBLE')


Measured memory_bytes: 16304
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N = 0;
  string S, T;
  cin >> S >> T;
  /*rep(i,N){
    cout << A[i] << endl;
  }*/
  ll len = S.length();
  rep(i,len){
    if(S[i]!=T[i]) N++;
  }
  cout << N << endl;
  
}

Measured memory_bytes: 3808
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const string RIGHT = "yuiophjklnm";

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

	for ( string str; cin >> str, str != "#"; )
	{
		int res = -1, last = -1; // last := was right
		REP( i, 0, str.size() )
		{
			int isright = RIGHT.find( str[i] ) != string::npos;
			res += last != isright;
			last = isright;
		}
		cout << res << endl;
	}		

	return 0;
}

Measured memory_bytes: 1196
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	ll a, b, c, d; cin >> a >> b >> c >> d;
	vector<ll> v(4);
	v[0] = a * c;
	v[1] = a * d;
	v[2] = b * c;
	v[3] = b * d;
	sort(all(v));
	cout << v[3] << endl;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    S = [ list( map( int, list( input())[:-1])) for _ in range(N)]
    E = [[] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if S[i][j] == 1:
                E[i].append(j)
    
    d = deque([0])
    V = [-1]*N
    V[0] = 1
    
    while d:
        v = d.pop()
        now = V[v]
        for w in E[v]:
            if V[w] == -1:
                V[w] = now+1
                d.append(w)
                continue

            if (now + V[w])%2 == 1:
                continue
            print(-1)
            return
    ans = 2

    for i in range(N):
        d = deque([i])
        V = [-1]*N
        V[i] = 1
        check = True
        while d:
            v = d.popleft()
            now = V[v]
            for w in E[v]:
                if V[w] == -1:
                    V[w] = now+1
                    d.append(w)
                    continue
                if now+1 == V[w] or now-1 == V[w]:
                    continue
                check = False
                break
            if not check:
                break
        if not check:
            continue
        if max(V) > ans:
            ans = max(V)
    print(ans)
    
            
                
if __name__ == '__main__':
    main()


Measured memory_bytes: 43996
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

//# include <ext/pb_ds/assoc_container.hpp>
//# include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);



int main () {
	SpeedForce;
	cin >> k >> n;
	For (i, 1, n) {
		cin >> a[i];
	}

	ans = a[n] - a[1];
	for (int i = 2; i < n; ++i) {
		cur = a[n] - a[i+1];
		cur += a[i] + k - a[n];
		ans = min(ans, cur);
	}
	cout << ans << '\n';

	return Accepted;
}

// B...a

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

int main() {
	string s;
	cin >> s;

	int count = 0;

	for (int i = 0; i < 3; i++) {
		if (s.at(i) == s.at(i + 1))
			count++;
	}

	if (count >= 1)
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

main(){
    int n ,d,count=0;
    double sum;
    double x[11][11];
    cin >> n >> d;
    FOR(i,0,n){ 
        FOR(j,0,d){
            int xj;
            cin >> xj;
            x[i][j] = xj;
        }
    }

    FOR(k,0,n){
        FOR(l,k+1,n){
            sum = 0.0;
            FOR(m,0,d){
                sum += pow(x[l][m]-x[k][m],2);
            }
            double s = sqrt(sum);
            if(s==(double)((int)(s))){
                count += 1;
            }
        }
    }

    cout << count << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"YES"<<endl
#define CNO cout<<"NO"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  cin >> s;
  int c=0;
  rep(i,s.length()){
    if(s[i]=='x') c++;
  }
  if(c>7) CNO;
  else CYES;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define NMAX 102
#define WMAX 100002
typedef long long ll;
ll max(ll a,ll b){
    if(a>b) return a;
    else return b;
}
int main(){
    ll N,W;
    scanf("%lld %lld",&N,&W);
    ll w[NMAX],v[NMAX];
    for(ll i=1;i<=N;i++)
        scanf("%lld %lld",w+i,v+i);
    ll DP[NMAX][WMAX];
    memset(DP,0,sizeof(DP));
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=W;j++){
            if(j < w[i]) DP[i][j] = DP[i-1][j];
            else
                DP[i][j] = max(DP[i-1][j],DP[i-1][j-w[i]]+v[i]); 
        }
    }
    printf("%lld",DP[N][W]);
}


Measured memory_bytes: 79872
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 28 18:51:59 2019
ABC142D
@author: maezawa
"""
import collections

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

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

# making a prime number list
np = int(10**6+1) # prime number list less than np
is_prime = [True]*(np+1)

is_prime[0] = False
is_prime[1] = False

for i in range(2, np//2+1): # Sieve of Eratosthenes
    if is_prime[i] == True:
        for j in range(2*i,np+1,i):
            is_prime[j] = False

prime_numbers = [i for i in range(np+1) if is_prime[i]]

# prime factorization
num = gcdab#10**9+7 # a number to be factorized. 
# The maximum number to factrize is np**2. 

facts = [] # list of prime factors
for prime in prime_numbers:
    if prime > num//2:
        break
    dnum = num
    while dnum%prime == 0: 
        facts.append(prime)
        dnum = dnum//prime

mul = 1
for i in facts:
    mul *= i
if mul != num: # if large prime number (> np) is missing
    facts.append(num//mul) # append it

pfs = collections.Counter(facts)
print(len(pfs)+1)


Measured memory_bytes: 53212
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b / (1LL << i)) % 2LL == 1LL) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long N, K, dp[1 << 18];

int main() {
	cin >> N >> K;
	for (int i = K; i >= 1; i--) {
		dp[i] = modpow(K / i, N, mod);
		for (int j = 2 * i; j <= K; j += i) dp[i] -= dp[j];
		dp[i] = (dp[i] + mod * mod) % mod;
	}

	long long r = 0;
	for (int i = 1; i <= K; i++) r += 1LL * i * dp[i] % mod;
	cout << r % mod << endl;
	return 0;
}

Measured memory_bytes: 4332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			long X = in.nextInt();
			long[] x = new long[n];
			for (int i = 0; i < n; i++) {
				x[i] = in.nextInt();
			}

			long big = 1;
			for (int i = 0; i < n; i++) {
				big += x[i] + X + 4 * x[i] + X;
			}

			long[] s = new long[n + 1];
			for (int i = 0; i < n; i++) {
				s[i + 1] = s[i] + x[i];
			}

			long ans = big;
			for (int k = 1; k <= n; k++) {
				int groupId = 0;
				long cur = k * X;
				for (int i = n - 1; i >= 0; i -= k) {
					long cost = 5 + 2 * Math.max(0, groupId - 1);
					++groupId;

					int r = i;
					int l = Math.max(0, i - k + 1);
					cur = Math.min(big, cur + cost * (s[r + 1] - s[l]));
				}
				ans = Math.min(ans, cur);
			}

			out.println(ans + (long) n * X);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 47188
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     string s;
     cin >> s;
     int ans = 1000;
     for(int i = 0;i<s.size()-2;i++){
        int num = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans = min(ans,abs(753-num));
     }
     cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3656
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion





    /// <summary>
    /// 最大公約数
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns></returns>
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }



    public static Dictionary<int, int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
        Dictionary<int, int> d = new Dictionary<int, int>();

        while (i * i <= n) //※1
        {
            if (tmp % i == 0)
            {
                tmp /= i;
                if (d.ContainsKey(i)) d[i]++;
                else d.Add(i, 1);
            }
            else
            {
                i++;
            }
        }
        if (tmp != 1)
        {
            if (d.ContainsKey(tmp)) d[tmp]++;
            else d.Add(tmp, 1);
        }
        return d;
    }

    static void Main()
    {
        int N = ReadInt;
        int[] As = ReadInts;

        long g = As[0];
        long max = As.Max();

        for (int i = 1; i < N; i++)
        {
            g = Gcd(g, As[i]);
        }

        if(g != 1)
        {
            WriteLine("not coprime");
            return;
        }


        bool[] ans = new bool[max+1];


        for (int i = 0; i < N; i++)
        {
            if (As[i] == 1) continue;
            var d = PrimeFactors(As[i]);


            foreach (var item in d)
            {
                long m = item.Key;
                long n = item.Key;

                while (n <= max)
                {
                    if (!ans[n])
                    {
                        ans[n] = true;
                    }
                    else
                    {
                        WriteLine("setwise coprime ");
                        return;
                    }
                    n *= m;
                }


            }


          
        }
       WriteLine("pairwise coprime");
    }
}



Measured memory_bytes: 104824
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    string s;
    cin>>s;
    stack<char> S;
    for(int i=0;i<s.size();i++){
        if(s[i]!='m' && s[i]!='e' && s[i]!='w'){cout<<"Rabbit"<<endl; return 0;}
        if(s[i]=='w'){
            char m,e;
            if(S.empty()){cout<<"Rabbit"<<endl; return 0;}
            e=S.top(); S.pop();
            if(S.empty()){cout<<"Rabbit"<<endl; return 0;}
            m=S.top(); S.pop();
            if(e!='e' || m!='m'){cout<<"Rabbit"<<endl; return 0;}
            if(S.empty() && i+1!=s.size()){cout<<"Rabbit"<<endl; return 0;}
            else if(S.empty() && i+1==s.size()){cout<<"Cat"<<endl; return 0;}
            else if(i+1==s.size()){cout<<"Rabbit"<<endl; return 0;}
            else if(S.top()=='e' && s[i+1]!='w'){cout<<"Rabbit"<<endl; return 0;}
            else if(S.top()=='m' && s[i+1]!='e'){cout<<"Rabbit"<<endl; return 0;}
        }
        else{
            S.push(s[i]);
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3224
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for( int i=0; cin >> ch; i++){
		if(ch == '\\') S1.push(i);
		else if(ch == '/' && S1.size() > 0){
			int j= S1.top(); S1.pop();
			sum += i-j;
			int a = i-j;
			while(S2.size() > 0 && S2.top().first > j){
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}
	
	vector<int> ans;
	while( S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for(int i=0; i < ans.size(); i++){
		cout << " ";
		cout << ans[i];
	}
	cout << endl;
	
	return 0;
}

 	


Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        double in = Double.parseDouble(reader.readLine().replaceFirst(" ", ""));
        double sq = Math.floor(Math.sqrt(in));
        if (Double.compare(sq * sq, in) == 0)
            System.out.print("Yes");
        else
            System.out.print("No");
    }
}


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

#define int long long

signed main() {
  int n;
  while ( cin >> n, n ) {
    vector<string> w(n);
    for ( int i = 0; i < n; i++ ) cin >> w[i];

    for ( int i = 0; i < n; i++ ) {
      int id = 0;
      vector<int> tanku{5, 7, 5, 7, 7};      
      for ( int j = i; j < n; j++ ) {
	if ( tanku[id] == (int)w[j].size() ) {
	  id++;	  
	} else if ( tanku[id] > (int)w[j].size() ) {
	  tanku[id] -= (int)w[j].size();	  
	} else {
	  break;
	}
	if ( id == 5 ) break;	
      }

      if ( id == 5 ) {
	cout << i+1 << endl;
	break;	
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3176