akhauriyash/Code-Regression huggingface dataset:
object Main extends App {
  import scala.io.StdIn._


  val Array(k, a, b) = readLine.trim.split(' ').map(_.toLong)
  println(solve(k, a, b))
  def solve(k: Long, a: Long, b: Long): Long = {
    if (k < a) {
      k + 1
    }else {
      val restK = k - a + 1
      if (a + 2 < b) {
        a + restK / 2 * (b - a) + restK % 2
      }else {
        k + 1
      }
    }
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}

Measured memory_bytes: 27456
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n, k;
int w[100001];
int l = 0, r;

int main(){
	std::cin >> n >> k;
	rep(i, n)std::cin >> w[i], r += w[i];

	while (l <= r){
		int m = (l + r) / 2;

		bool f = true;
		int need = 1, sum = 0;
		rep(i, n){
			if (w[i] > m)f = false;

			if (sum + w[i] <= m)sum += w[i];
			else {
				++need;
				sum = w[i];
			}
		}
		if (!f || need > k)l = m + 1;
		else r = m - 1;
	}

	std::cout << r + 1 << std::endl;

	return 0;
}

Measured memory_bytes: 1548
import sys
sys.setrecursionlimit(10**8)

def sort(a):
	a.sort()

def rev(a):
	a.reverse()

def sd():
	return int(input())

def _sd():
	return map(int,input().split())

def sa():
	return list(map(int,input().split()))

def ss():
	return input()

def sf():
	return float(input())
 
def main():
	N,Z,W=_sd()
	a=sa()
	if(N>1):
		print(max(abs(a[N-1]-W),abs(a[N-2]-a[N-1])))
	else:
		print(abs(a[0]-W))
main()


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    int n,a,b,c,d;cin>>n;

        d=n%10;n/=10;
        c=n%10;n/=10;
        b=n%10;
        a=n/10;

    if(a+b+c+d==7){
        cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    }
    else if(a+b+c-d==7){
        cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    }
    else if(a+b-c+d==7){
        cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    }
    else if(a+b-c-d==7){
        cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    }
    else if(a-b+c+d==7){
        cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    }
    else if(a-b+c-d==7){
        cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    }
    else if(a-b-c+d==7){
        cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    }
    else if(a-b-c-d==7){
        cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    }

}

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

using namespace std;
using ll = long long;

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int dx = x2 - x1;
	int dy = y2 - y1;
	cout << x2 - dy << " " << y2 + dx << " ";
	cout << x1 - dy << " " << y1 + dx << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e9+5
ll c[110];
ll w[110];
ll dp[105][100005];
ll n;

ll fn(ll r, ll i)
{
    if(i==n)
    {
        return r==0?0:INT_MAX;
    }
    
    if(dp[i][r] != -1)
    {
        return dp[i][r];
    }
    
    ll ans =fn(r,i+1);
    
    if(c[i] <= r)
    {
        ans = min(w[i]+fn(r-c[i],i+1),ans);
    }
    
    return dp[i][r] = ans;
}

ll solve(ll sum, ll  w)
{
    for(ll i=sum ; i>=0; i--)
    {
        if(fn(i,0) <= w)
        {
            return i;
        }
    }
}
int main()
{
    ll i,j,k,t;
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
        cin>>w[i]>>c[i];
    }
    memset(dp,-1,sizeof(dp));
    ll sum=0;
    for(i=0; i<n; i++)
    {
        sum+=c[i];
    }
    ll ans = solve(sum,k);
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	string S, T; 
	cin >> S;
	cin >> T;

	int ans = 0;
	REP(i,S.length()){
		if(S[i] != T[i]) ans++;
	}

	cout << ans << endl;
	


	return 0;

}


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

int main(){
    int a,b,c,d,ans = 0;
    cin >> a >> b >> c >> d;
    if(a >= b){
        ans += b;
    }else{
        ans += a;
    }

    if(c >= d){
        ans += d;
    }else{
        ans += c;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n, tmpa, tmpb = gets.split.map(&:to_i)
a, b = [tmpa, tmpb].sort

cnt = 0
# 奇数だけ離れていると、一番上か下に行く必要がある
if (a - b).odd?
  # a のほうが端っこに近い場合
  if a - 1 < n - b
    p (b + a - 1) / 2
  else
    p (2*n - a - b + 1) / 2
  end
else
  # 偶数の場合、真ん中で落ち合えば良い
  p (b - a) / 2
end


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

int main()
{
	int32_t N, M, R;
	scanf("%d%d%d", &N, &M, &R);

	vector<int32_t> r(R);
	for (int32_t i = 0; i < R; i++) {
		scanf("%d", &r[i]);
		r[i]--;
	}
	sort(r.begin(), r.end());

	int32_t d[200][200];
	for (int32_t i = 0; i < N; i++)
		for (int32_t j = 0; j < N; j++)
			d[i][j] = i == j ? 0 : numeric_limits<int32_t>::max() / 2;

	for (int32_t i = 0; i < M; i++) {
		int32_t A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		A--;
		B--;
		d[A][B] = C;
		d[B][A] = C;
	}

	// warshall floyd
	for (int32_t k = 0; k < N; k++) {
		for (int32_t i = 0; i < N; i++) {
			for (int32_t j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	int32_t res = numeric_limits<int32_t>::max();
	do {
		int32_t total = 0;
		for (int32_t i = 0; i < R - 1; i++) {
			total += d[r[i]][r[i + 1]];
		}
		res = min(res, total);
	} while (next_permutation(r.begin(), r.end()));

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

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin >> n;
 vector<int>vec(250);
 for(int i=0;i<250;i++){
  cin >> vec.at(i);
 }
 int count = 0;
 while(true){
  bool jkjk = false;
    for(int i =0;i<250;i++){
	if(vec.at(i)%2 != 0){
		jkjk = true;
	}
   }
   if(jkjk){
	break;
     }
  for(int i = 0;i < 250;i++){
    vec.at(i) /=2;
   }
  count++;
 }
 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 all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

const int MAX = 100000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
   int N,M;cin >> N >> M;

    COMinit();
    int a = COM(N,2);
    int b = COM(M,2);

    cout << a+b << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>

int sosuu(int x){
  int i;
  if ( x < 2 )
    return 0;
  else if ( x == 2 )
    return 1;
  if ( x % 2 == 0 )
    return 0;
  for ( i = 3; i*i <= x; i+=2 ){
    if ( x % i == 0 )
      return 0;
  }
  return 1;
}

int main(){
  int n,x,i;
  int count = 0;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%d", &x);

    if ( sosuu(x) ) count++;
  }

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



Measured memory_bytes: 2104
import math
 
mod = 1000000007
 
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
n=int(input())
 
a = list(map(int,input().split()))
 
memo = a[0]
 
for i in range(1,n):
    memo = lcm(memo,a[i])
 
ans = 0
 
for i in range(n):
    ans += memo*pow(a[i], mod-2, mod)%mod
    ans %= mod
 
print(ans)

Measured memory_bytes: 73820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	vector<int> a(n);

	rep(i, k) {
		cin >> d.at(i);
		rep(j, d.at(i)) {
			int num = 0;
			cin >> num;
			a.at(num - 1)++;
		}
	}
	int ans = 0;

	rep(i, n) {
		if (a.at(i) == 0) {
			ans++;
		}
	}
	cout << ans << endl;



	
	return 0;
	
}



Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N,A,B,C,D; cin >> N >> A>>B>>C>>D;
    N--;
    LL dif = abs(A-B);
    bool ok = 0;
    for(LL i = 0; i <= N/2; i++){
        LL s = C*(N-2LL*i) - (D-C)*i;
        LL l = (D-C)*i + D * (N-2LL*i);
        if(s <= dif && dif <= l) ok = 1;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;


}


Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
a = A.copy()
b = A.copy()
for i in range(1, N):
  a[i] = gcd(a[i-1], a[i])
for i in range(N - 1, 0, -1):
  b[i - 1] = gcd(b[i], b[i-1])
r = 0
for i in range(1, N - 1):
  r = max(r, gcd(a[i-1], b[i+1]))
r = max(r, b[1], a[-2])
print(r)

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int imp;
    cin >>imp;
    int user[4][3][10];
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                user[i][j][k]=0;
            }
        }
    }
    for (int i = 0; i < imp; i++){
        int a,b,c,d;
        cin >>a>>b>>c>>d;
        user[a-1][b-1][c-1]+=d;
    
    }
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                cout<<' '<<user[i][j][k];
            }
            cout<<'\n';
        }
        if(i<3)cout<<"####################\n";
    }
}


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

int main() {
  
  int N; cin >> N;
  
  for (int i = 0; i < 10; i++) {
    
    int tmp = pow(2, i);
    
    if (N < tmp) {
      cout << int(pow(2, i - 1)) << endl;
      return 0;
    }
    
  }
  
}

Measured memory_bytes: 512
N, L = map(int, input().split())
A = list(range(1, N+1))
ans = 0
saisyo = float("inf")
saidai = -float("inf")
for i in range(N):
    x = A[i] + L-1 
    saisyo = min(x, saisyo)
    saidai  = max(x, saisyo)
    ans += x
if saidai < 0:
    print(ans-saidai)
elif saidai >= 0 and saisyo <= 0 :
    print(ans)
else:
    print(ans-saisyo)

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  long N;
  cin >> N;

  vector<long> A(N);
  for (long i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<long> S(N + 1, 0);

  for (long i = 1; i < N + 1; i++) {
    S[i] = S[i - 1] + A[i - 1];
  }

  sort(S.begin(), S.end());
  long ans = 0;

  long tmp = 0;
  for (int i = 1; i < N + 1; i++) {
    if (S[i] != S[i - 1]) {
      ans += tmp * (tmp + 1) / 2;
      tmp = 0;
    } else {
      tmp++;
    }
  }
  ans += tmp * (tmp + 1) / 2;

  cout << ans << endl;
}


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

using namespace std;

int N, M;

int main()
{
    scanf("%d%d", &N, &M);
    int y=0;
    for(int i=0; i<N; i++)
    {
        string s;
        cin>>s;
        for(int j=0; j<M; j++) if(s[j]=='#')
        {
            if(j>=y)
                y=j;
            else
                return printf("Impossible\n"), 0;
        }
    }
    printf("Possible\n");
    return 0;
}


Measured memory_bytes: 764
// フィボナッチ数列
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 44
// 無効な値の定義
const int INV = -1;

// フィボナッチ数列を保持する配列
int fib[MAX_N + 1];

int Fibonacci(int n);

int main(void)
{

    int n;

    cin >> n;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        fib[i] = INV;
    }

    fib[0] = 1;
    fib[1] = 1;

    // フィボナッチ数列の表示
    printf("%d\n", Fibonacci(n));

    return 0;
}

// フィボナッチ数列を算出する関数
int Fibonacci(int n)
{

    if( n <= 1)
    {
        // n = 0, n = 1 の時
        return 1;
    }

    if( fib[n] != INV )
    {
        // 既に計算されている時は, 結果を返す
        return fib[n];
    }

    // フィボナッチ数列の算出の算出
    fib[n] = Fibonacci(n - 2) + Fibonacci(n - 1);

    return fib[n];
}



Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    map<int, int> m;
    int val = 0;
    vector<int> vs(n+1);
    ll aaa = 1;
    for (int i = n-1; i >= 0; --i) {
        val = (val + (s[i]-'0')*aaa)%2019;
        aaa = (aaa*10)%2019;
        m[val]++;
        vs[i] = val;
    }
    ll ans = 0;
    for (int i = n-1; i >= 0; --i) {
        ans += m[vs[i+1]];
        m[vs[i]]--;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4448
#include <bits/stdc++.h>
using namespace std;
int n, val[100009];
int sum(int r) {
	int ret = 0;
	while(r > 0) {
		ret += val[r];
		r -= r & -r;
	}
	return ret;
}
void add(int i, int x) {
	while(i <= n) {
		val[i] += x;
		i += i & -i;
	}
}
int q, tp, x, y;
int main() {
	scanf("%d%d", &n, &q);
	while(q--) {
		scanf("%d%d%d", &tp, &x, &y);
		if(tp == 0) add(x, y);
		else {
			int ret = sum(y) - sum(x - 1);
			printf("%d\n", ret);
		}
	}
	return 0;
}

Measured memory_bytes: 3548
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<'0');
	do{
		res=(res<<1)+(res<<3)+(c^48);
	}while(c=getchar(),c>='0');
}
int n,p,cnt1,cnt2;
ll C[55][55];
void Init(){
	for(int i=0;i<55;++i)C[i][0]=1;
	for(int i=1;i<55;++i){
		for(int j=1;j<=i;++j)C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int main(){
	Rd(n),Rd(p);
	Init();
	for(int i=1;i<=n;i++){
		int x;Rd(x);
		if(x&1)cnt1++;
		else cnt2++;
	}
	ll ans=0;
	if(p==1){
		for(int i=1;i<=cnt1;i+=2)
			ans+=(1LL<<cnt2)*C[cnt1][i];
	}else{
		for(int i=0;i<=cnt1;i+=2)
			ans+=(1LL<<cnt2)*C[cnt1][i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,M;
    cin >> N;
    rRep(i,sqrt(N)+1,1){
        if(N%i==0){
            M=N/i;
            break;
        }
    }
    ll T=0;
    while(M>0){
        T++;
        M/=10;
    }
    cout << T << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;

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

  if (a+w<b ) {
    cout << b-(a+w)<<endl;
  }
  else if (b+w <a) {
    cout << a-(b+w)<<endl;
  }
  else{
    cout << 0<<endl;
  }
}


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

using namespace std;

int n,m,x,a[13][13],v[13];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin>>n>>m>>x;

    for(int i=0;i<n;i++){
        cin>>a[i][0];
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    int ans=(1<<30);

    for(int mask=1;mask<(1<<n);mask++){

       memset(v,0,sizeof(v));

        int cost=0;

        for(int i=0;i<n;i++){
            if(mask&(1<<i)){
               cost+=a[i][0];
               for(int j=1;j<=m;j++){
                v[j]+=a[i][j];
               }
            }
        }
        for(int i=1;i<=m;i++){
            if(v[i]<x)cost=(1<<30);
        }
       ans=min(ans,cost);
    }
    if(ans==(1<<30))cout<<"-1"<<endl;
    else            cout<<ans<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  ll X;
  I(N);
  I(X);
  ret += 1;
  ll D = 0;
  ll L;
  REP(i, N) {
    I(L);
    D += L;
    if (D <= X) ret++;
  }

  P(ret);

}


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

int main()
{
    int H,W;
    cin >> H >> W;

    vector<vector<char>> HW(H,vector<char>(W));

    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin >> HW.at(i).at(j);
        }
    }

    int di[4] = {-1,1,0,0};
    int dj[4] = {0,0,1,-1};
    bool judge;

    for(int i = 0; i < H; i++)
    {
        
        for(int j = 0; j < W; j++)
        {
            if(HW[i][j] == '.')continue;
            for(int d = 0; d < 4; d++)
            {
                int ii = i + di[d];
                int jj = j + dj[d];

                if(ii < 0 || H <= ii)continue;
                if(jj < 0 || W <= jj)continue;

                if(HW[ii][jj] == '#')
                {
                    judge = true;
                    break;
                }
                judge = false;
            }
            if(judge == false)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]  

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

# return [g, x, y]
# g = gcd(a, b)
# x, y satisfies a x + b y = g
def extgcd(a, b):
    if b == 0:
        return [a, 1, 0]
    g, x, y = extgcd(b, a%b)
    return [g, y, x - a//b * y]

# eq0: x = a0 (mod m0)
# eq1: x = a1 (mod m1)
# returns [xt, mod] such that x = xt + k mod for integer k.
def crt(eq0, eq1):
    a0, m0 = eq0
    a1, m1 = eq1

    g = gcd(m0, m1)

    if a0 % g != a1 % g:
        return [-1, -1]
        #raise Exception("x doesn't exist.")

    if g > 1:
        m0 //= g
        m1 //= g

        while True:
            gt = gcd(m0, g)
            if gt == 1:
                break
            m0 *= gt
            g //= gt
        
        m1 *= g

        a0 %= m0
        a1 %= m1

    g, p, q = extgcd(m0, m1)
    
    x = a0 * q * m1 + a1 * p * m0
    mod = m0 * m1
    x = x % mod

    return [x, mod]

# 本処理
N = int(input())
divs = make_divisors(2*N)
"""
if N == 1:
  print(1)
  sys.exit()
"""

ans = INF = 10**20
for x in divs:
  y = 2*N // x
  xt, mod = crt([0,x], [-1,y])
  if x == 2*N or xt == -1:
    continue
  #print(x, y, xt)
  ans = min(ans, xt)
  
print(ans)
    
  

  

Measured memory_bytes: 77012
N,K = map(int, raw_input().split())
W = [int(raw_input()) for _ in range(N)]

if N == 1:
    print W[0]
    exit()

def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K

left = min(W)
right = sum(W)
mid = 0
while left < right:
    #print left, right
    mid = int((left + right) / 2)
    #print mid,
    if check(mid):
        right = mid
    else:
        left = mid + 1

print left



Measured memory_bytes: 10868
n, m, x = map(int,input().split())
a = list(map(int,input().split()))
ans1 = 0
ans2 = 0
if x == 1 or x == n:
    print(0)
else:
    for i in range(1, x):
        if len(a) != 0:
            if a[0] == i:
                ans1 += 1
                a.pop(0)
    if len(a) != 0:
        for i in range(x, n):
            if len(a) != 0:
                if a[0] == i:
                    ans2 += 1
                    a.pop(0)
    ans = min(ans1, ans2)
    print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int a, b, c; cin >> a >> b >> c;
	Cout(a + b + c);
}


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

int main() {
	map<string, int> f;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		f[s]++;
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		f[s]--;
	}

	int ans = 0;
	for (auto x : f) ans = max(ans, x.second);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[A[i]]++;
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  for (auto P : mp){
    pq.push(P);
  }
  for (int i = 0; i < M; i++){
    int B, C;
    cin >> B >> C;
    int total = 0;
    while (1){
      if (pq.empty()){
        break;
      }
      int num = pq.top().first;
      int cnt = pq.top().second;
      if (num >= C){
        break;
      }
      pq.pop();
      if (total + cnt <= B){
        total += cnt;
      } else {
        pq.push(make_pair(num, cnt - (B - total)));
        total = B;
        break;
      }
    }
    pq.push(make_pair(C, total));
  }
  long long ans = 0;
  while (!pq.empty()){
    ans += (long long) pq.top().first * pq.top().second;
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 6520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    ll n; cin>>n;
    int ans=100;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        ll a=i;
        ll b=n/a;
        ans=min(ans,(int)to_string(max(a,b)).size());
    }
    cout<<ans<<endl;
}


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

int n;


int linersearch(int x,int s[]){
	for(int i=0;i<n;i++){
		if(s[i]==x){return 1;
		}
	}
	return 0;
}

int main(){
	int s[10005];
	int t[505]; 
	int sum=0;
	cin>>n;
	int q;
	for(int i=0;i<n;i++)cin>>s[i];
	cin>>q; 
	for(int i=0;i<q;i++){
		int x;
		cin>>x;
		if(linersearch(x,s))sum++;
	} 
	cout<<sum<<endl;
} 


Measured memory_bytes: 3132
p_str = input().split()
p = [int(s) for s in p_str]
p_str = input().split()
p.extend([int(s) for s in p_str])
p_str = input().split()
p.extend([int(s) for s in p_str])
#print(p)
count_list = []
for i in range(4):
   count =  p.count(i+1)
   count_list.append(count)
#print(count_list)
if(count_list.count(1)==2 and count_list.count(2)==2):
   print("YES")
else:
   print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i = (s);i<(int)(n);i++)

int main(){
    int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}

Measured memory_bytes: 3636
n=int(input())
A,B=map(int, input().split())
P=list(map(int, input().split()))
s=[]
w=[]
t=[]
l=[s,w,t]
for i in range(n):
  if P[i]<=A:
    s.append(P[i])
  elif P[i]>=A+1 and P[i]<=B:
    w.append(P[i])
  else:
    t.append(P[i])
print(min(len(s),len(w),len(t)))



Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include <numeric>
#include<tuple>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define fi first
#define se second
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void Pvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Ps(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}



ll  d, n, m, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;



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

	ll a, p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;


	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let (x, y): (i64, i64) = get_pair();
    if (x-y).abs() < 2 {
        println!("Brown");
    } else {
        println!("Alice");
    }
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
  int n;
  sl(n);
  int arr[n];
  int avg=0;
  for(int i=0;i<n;i++){
	  sl(arr[i]);
	  avg+=arr[i];
  }
  if(avg%n==0){
	  int val=avg/n;
	  int sum=0;
	  for(int i=0;i<n;i++){
		  sum+=(arr[i]-val)*(arr[i]-val);
		 // sum2+=(arr[i]-val2)*(arr[i]-val2);
	  }
	  cout<<sum<<endl;
	  return 0;
	  
  }
  else{
	  int sum1=0,sum2=0;
	  int val1=avg/n;
	  int val2=val1+1;
	  for(int i=0;i<n;i++){
		  sum1+=(arr[i]-val1)*(arr[i]-val1);
		  sum2+=(arr[i]-val2)*(arr[i]-val2);
	  }
	  cout<<min(sum1,sum2)<<endl;
	  return 0;
  }
  
 
 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {
	int A, B, C;
	cin >> A >> B >> C ;
	if (A + B + C == 17)
	{ if ( ( A==5 && B==5 ) || ( C==5 && B==5 ) || ( C==5 && A==5 ) )
	{ cout << "YES" << '\n';
	return 0;}
	else{	cout << "NO" << '\n';
	return 0;}
	}
	else{	cout << "NO" << '\n';
	return 0;}
 }


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

int main(){
  int A,B,c=1;
  cin >> A >> B;
  for(int i=1; i<max(A,B); i++){
    if(max(A-i,i-A)==max(B-i,i-B)){
      cout << i << endl;
      c=0;
      break;
    }
  }
  if(c){
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <queue>

using namespace std;

#define INF 1<<29
#define MAX_H 1024
#define MAX_W 1024
#define MAX_V (MAX_H * MAX_W)

typedef pair<int, int>  P;

vector<P>G[MAX_V];

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

int d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + MAX_V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      P e = G[v][i];
      if(d[e.second] > d[v] + e.first){
	d[e.second] = d[v] + e.first;
	que.push(P(d[e.second], e.second));
      }
    }
  }
}


int main(){
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  auto vec2idx = [&](int i, int j){ return i*W + j; };
  auto get_i = [&](int idx){ return int(idx/W); };
  auto get_j = [&](int idx){ return idx%W; };
  auto is_out_of_stage = [&](int i, int j){
			   if(i < 0 || j < 0 || i >= H || j >= W) return 1;
			   return 0;
			 };
  int start, goal;
  string stage[1024];
  for(int i=0;i<H;i++){
    cin >> stage[i];
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(stage[i][j] == 'g'){
	goal = i*W + j;
      }
      if(stage[i][j] == 's'){
	start = i*W + j;
      }
      auto can_use_gift = [&](int a, int b){
			    int dy[] = {0, -1, 0, -1, 1, 0, 1, -1, 1};
			    int dx[] = {0, 0, -1, -1, 0, 1, 1, 1, -1};
			    for(int k=0;k<9;k++){
			      if(is_out_of_stage(a+dy[k], b+dx[k])) continue;
			      if(stage[a+dy[k]][b+dx[k]] == '*') return 0;
			    }
			    return 1;
			  };

      int idx = vec2idx(i, j);      
      if(can_use_gift(i, j)){
	//	cout << i << " " << j << endl;
	int di[] = {-1, 0, 1, 0};
	int dj[] = { 0, -1, 0, 1};
	for(int k=0;k<4;k++){
	  int next_i = i + di[k];
	  int next_j = j + dj[k];
	  if(is_out_of_stage(next_i, next_j)) continue;
	  int next_idx = vec2idx(next_i, next_j);
	  G[idx].push_back(make_pair(A + B, next_idx));
	}

	int ddi[] = {-1, 1, -1, 1};
	int ddj[] = {-1, -1, 1, 1};
	for(int k=0;k<4;k++){
	  int next_i = i + ddi[k];
	  int next_j = j + ddj[k];
	  if(is_out_of_stage(next_i, next_j)) continue;	  
	  int next_idx = vec2idx(next_i, next_j);
	  G[idx].push_back(make_pair(2*A + B, next_idx));
	  //	  cout << idx << " " << next_idx << " " << 2*A + B << endl;
	}
      }
      int di[] = {-1, 0, 1, 0};
      int dj[] = {0, -1, 0, 1};
      for(int k=0;k<4;k++){
	int next_i = i + di[k];
	int next_j = j + dj[k];
	if(is_out_of_stage(next_i, next_j)) continue;	
	if(stage[next_i][next_j] == '#') continue;
	int next_idx = vec2idx(next_i, next_j);
	G[idx].push_back(make_pair(A, next_idx));
      }
    }
  }
  for(int i=0;i<H*W;i++){
    for(int j=0;j<G[i].size();j++){
      //      cout << i << " " << G[i][j].second << " " << G[i][j].first << endl;
    }
  }
  dijkstra(start);
  if(d[goal] == INF){
    cout << "INF" << endl;
  }else{
    cout << d[goal] << endl;
  }
  return 0;
}



Measured memory_bytes: 111048
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int a, b, c;
    cin>>a>>b>>c;
    cout<<max(a, max(b, c))-min(a, min(b, c))<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>M;
	vector<int>v(N+1);
	for(int i=1;i<=N;i++){
		cin>>v[i];
	}
	UnionFind uf(N);
	for(int i=0;i<M;i++){
		cin>>L>>R;
		uf.Unite(L,R);
	}
	vector<vector<int>>index(N+1);
	for(int i=1;i<=N;i++){
		index[uf.Find(i)].push_back(i);
	}
	int ans=0;
	for(int i=1;i<=N;i++){
//	cout<<i<<endl<<endl;
		set<int>s;
		for(auto j:index[i]){
			s.insert(v[j]);
		//	cout<<v[j]<<endl;
		}
		for(auto j:index[i]){
			if(s.find(j)!=s.end()){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    int ss = s.size();
    int tt = t.size();
    rep(i, ss-tt+1){
        int cnt = 0;
        rep(j, tt){
            if(s[i+j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.floor

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (n, k) = nextListOfInt()
    val arr: MutableList<Int> = mutableListOf()
    for(i in 0 until k){
        val d = sc.nextInt()
        for(j in 0 until d){
            arr.add(sc.nextInt())
        }
    }
    val arrr = arr.toIntArray().distinct()
    var count = 0;
    for(i in 1..n){
        if(!arrr.contains(i)) count++
    }
    println(count)
}

fun abc000a(n:String) {
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n,m;
	int f[1024];
	while(scanf("%d %d",&n,&m),n|m){
		rep(i,n)scanf("%d",&f[i]);
		int cnt = 0;
		int now = 1;
		rep(i,m){
			int a; scanf("%d",&a);
			if( now<n ){
				now += a;
				now += f[now-1];
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

int main(void){
    int s;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    scanf("%d",&s);
    s=s*s*s;
    printf("%d",s);
    /*
    if(){
        printf("Bad");
    }else{
        printf("Good");
    }
    */
    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++)
using ll = long long;

int main (){
    ll N;
    cin >> N;
    string ans;

    while(N > 26){
        int mod = (N - 1) % 26;
        ans = (char)('a' + mod) + ans;
        N = (N - 1) / 26;
    }
    if(N != 0) ans = (char)('a' + N - 1) + ans;
    cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(" ");
            int X = int.Parse(input1[0]);
            int N = int.Parse(input1[1]);

            string input2_s = Console.ReadLine();
            string[] input2;
            int ans;
            if (!string.IsNullOrEmpty(input2_s))
            {
                input2 = input2_s.Split(" ");

                List<int> p = new List<int>();
                foreach (string element in input2)
                {
                    p.Add(int.Parse(element));
                }

                int ans_l = X;
                for (int i = X; i <= 101; i++)
                {
                    if (!p.Contains(i))
                    {
                        ans_l = i;
                        break;
                    }
                }

                int ans_s = X;
                for (int i = X; i >= 0; i--)
                {
                    if (!p.Contains(i))
                    {
                        ans_s = i;
                        break;
                    }
                }

                if (System.Math.Abs(ans_l - X) > System.Math.Abs(ans_s - X))
                {
                    ans = ans_s;
                }
                else if (System.Math.Abs(ans_l - X) < System.Math.Abs(X - ans_s))
                {
                    ans = ans_l;
                }
                else
                {
                    ans = ans_s;
                }

            }
            else
            {
                ans = X;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17700
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long lli;
#define int long long

signed main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector <int> ar(n);	
	for(int &x: ar) cin >> x;
	int res = 0;
	for(int i=0; i<n-1; ){
		int ctr=0;
		while(i<n-1 and ar[i] >= ar[++i]){
			ctr++;
		}
		res = max(res, ctr);
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 1024
while True:
    h,w = map(int, input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if (i+j)%2 == 0:
                print("#", end="")
            else:
                print(".", end="")
            if j == w-1:
                print()
        if i == h-1:
            print()

Measured memory_bytes: 9084
from heapq import heappush, heappop

INF = 10 ** 20

v_num, e_num= map(int, input().split())
edges_lst = [[] for _ in range(v_num)]
dist_lst = [INF for _ in range(v_num)]

min_dis = INF
for _ in range(e_num):
    s, t, dist = map(int, input().split())
    edges_lst[s].append((dist, t))
    edges_lst[t].append((dist, s))
    if min_dis > dist:
        min_dis = dist
        node1,node2 = s,t
    
if v_num==1:
    print(0)
else:
    que = []
    for v in edges_lst[node1]:
        heappush(que, v)
    for v in edges_lst[node2]:
        heappush(que, v)
        S = {node1,node2}
        ans = min_dis


    while len(S)!=v_num:
        dist, node = heappop(que)
        if node not in S:
            S.add(node)
            ans += dist
            for dist2 ,v in edges_lst[node]: 
                if v not in S:
                    heappush(que, (dist2, v))

    print(ans)


Measured memory_bytes: 37792