akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main()
{
	ll N; cin >> N;
	ll a[101];
	ll max = 0;
	ll min = 1 << 21;
	rep(i, 0, N) {
		cin >> a[i];
		if (max < a[i]) max = a[i];
		if (min > a[i]) min = a[i];
	}

	ll minsum = 1 << 21;
	repe(i, min, max) {
		ll sum = 0;
		rep(j, 0, N) {
			sum += (a[j] - i) * (a[j] - i);
		}
		if (minsum > sum) {
			minsum = sum;
		}
	}
	cout << minsum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int h,m,s,S;
    scanf("%d",&S);
    h=S/3600;
    S=S%3600;
    m=S/60;
    s=S%60;
    printf("%d:%d:%d\n",h,m,s);
       
    return 0;
}

Measured memory_bytes: 592
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
  tmp = 0
  if a[i]<=b[i]:
    tmp+=a[i]
    ba = b[i]-a[i]
    tmp_a = a[i+1]
    if ba<a[i+1]:
      a[i+1] = abs(ba-a[i+1])
    else:
      a[i+1] = 0
    tmp+=tmp_a-a[i+1]
  else:
    tmp+=b[i]
  ans+=tmp
print(ans)

Measured memory_bytes: 19156
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int ans = 0;
  if(s[0] == '1')
    ans++;
  if(s[1] == '1')
    ans++;
  if(s[2] == '1')
    ans++;
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
c = [0, 0]

for f in [0, 1]:
  sumA = 0
  for i, a in enumerate(A):
    sumA += a
    if i % 2 == f:
      if sumA < 1:
        d = 1 - sumA
        c[f] += d
        sumA += d
    else:
      if sumA > -1:
        d = 1 + sumA
        c[f] += d
        sumA -= d
      
print(min(c))

Measured memory_bytes: 14332
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> a(N,0);
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        x--;
        a[x]++;
    }

    sort(a.begin(),a.end());
    auto low=lower_bound(a.begin(),a.end(),1);

    int count=0;
    while(a.end()-low > K){
        count+=*low++;
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int digitSum(int n){
  int res=0;
  while(n>0){
    res+=n%10;
    n/=10;
  }
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  int min=n;
  int i;
  for(i=1;i<n;i++){
    min=MIN(min,digitSum(i)+digitSum(n-i));
  }
  printf("%d\n",min);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
int n, q;
string s;
int l, r;
char t[200010], d[200010];
signed main() {
	cin >> n >> q;
	cin >> s;
	rep(i, q) {
		cin >> t[i] >> d[i];
	}
	for (int i = q - 1; i >= 0; i--) {
		if (t[i] == s[l] && d[i] == 'L') {
			l++;
		}
		if (l) {
			if (t[i] == s[l - 1] && d[i] == 'R') {
				l--;
			}
		}
		if (t[i] == s[n - r - 1] && d[i] == 'R') {
			r++;
		}
		if (r) {
			if (t[i] == s[n - r] && d[i] == 'L') {
				r--;
			}
		}
	}
	cout << n - (l + r) << endl;
}


Measured memory_bytes: 900
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    vector<int> v;
    vector<int> c;
    rep(i, n){
        int vs; cin >> vs;
        v.push_back(vs);}
    rep(i, n){
        int cs; cin >> cs;
        c.push_back(cs);
        }

    int max=0;
    rep(i, n){
        if((v[i]-c[i])>0) max += v[i]-c[i];
    }

    out(max);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100000
#define LL long long int
const LL MOD = 1e9+7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a,b) << ' ' << max(0, a + b - n) << '\n';
  return 0;
}


Measured memory_bytes: 256
def divs(n):
    res = []
    i = 1
    while i**2 <= n:
        if n%i == 0: 
            res.append(i)
            if i**2 != n:
                res.append(n//i)
        i+=1 
    return res


def main():
    n = int(input())
    al_0 = list(map(int, input().split()))
    if sum(al_0) == 0:
        print(0)
        return

    al = [0] + al_0
    divs_cnts = [0]*(n+1)
    ans = []
    for i in range(n,0,-1):
        if divs_cnts[i]%2 != al[i]%2:
            ans.append(i)
            div_l = divs(i)
            for d in div_l:
                divs_cnts[d] += 1

    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()

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

char g[1000][1000];
int dp[1000][1000];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%s", g[i]);
		rep(i, n)rep(j, n) {
			if (g[i][j] == '.')dp[i][j] = 1;
		}
		int Max = 0;
		for (int i = 1; i < n; i++)for (int j = 1; j < n; j++) {
			if (g[i][j] == '*')dp[i][j] = 0;
			else {
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i][j - 1], dp[i - 1][j])) + 1;
				Max = max(Max, dp[i][j]);
			}
		}
		printf("%d\n", Max);
	}
}

Measured memory_bytes: 8080
#include<iostream>
#include<cstdio>
#include<cmath>
#define reg register
#define LL long long
inline int read(){
	int x=0,y=1;
	char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
inline int roundd(double x){
	return (int)std::floor(x+0.5);
}
int main(){
    int a=read(),b=read();
    reg int max=b*100;
    for(reg int i=1;i<=max;i++){
    	if(std::floor(i*0.08)==a&&std::floor(i*0.1)==b)
			return std::printf("%d",i),0;
	}
	std::puts("-1");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int a, b, c;
  	cin >> a >> b >> c;
  	cout << c << " " << a << " " << b << endl;
    return 0;
}



Measured memory_bytes: 256
#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;

#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int A[200003];
double B[200003], pref[200003];

int main()
{
	// freopen("input.in", "r", stdin);

	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &A[i]);
		B[i] = (1.0*A[i]*(A[i]+1))/2.0/A[i];
		pref[i] = pref[i-1]+B[i];

	}

	double mx = 0;
	for(int i = 1; i+k-1 <= n; i++)
	{
		mx = max(mx, pref[i+k-1]-pref[i-1]);
	}
	printf("%.6lf\n", mx);
	
	
}

Measured memory_bytes: 4096
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.List hiding (insert)
import qualified Data.ByteString.Char8 as BS

data Drink = Drink {-# UNPACK #-} !Int64 {-# UNPACK #-} !Int deriving (Eq,Ord)
data Tree = Empty
          | Bin {- key -} {-# UNPACK #-} !Int64 {- value -} {-# UNPACK #-} !Int Tree Tree

insert :: Int64 -> Int -> Tree -> Tree
insert !k !v Empty = Bin k v Empty Empty
insert !k !v (Bin k' v' s t) = case compare k k' of
                                 LT -> Bin k' v' (insert k v s) t
                                 EQ -> Bin k (v + v') s t
                                 GT -> Bin k' v' s (insert k v t)

toList :: Tree -> [(Int64,Int)]
toList = go []
  where
    go xs Empty = xs
    go xs (Bin k v s t) = go ((k,v) : go xs t) s

main = do
  [n,m] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  ab <- fmap (foldl' (flip $ uncurry insert) Empty) $ sequence $ replicate n $ do
    [a,b] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    return (a :: Int64, fromIntegral b :: Int) -- (a :: Int64, b :: Int)
  let solve !k !yen ((a,b) : xs) | k <= b = yen + a * fromIntegral k
                                 | otherwise = solve (k - b) (yen + a * fromIntegral b) xs
  print $ solve (fromIntegral m) 0 (toList ab)


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

int main(){
    // input
    string S;
    cin >> S;
    int N = S.length();

    // good step?
    bool ans = true;
    for( int n=0; n<N; n++){
        // odd
        if( n%2 == 1 ){
            if( S[n] == 'R' ){
                ans = false;
            }
        }else{
            if( S[n] == 'L' ){
                ans = false;
            }
        }
    }

    // output
    printf(ans ? "Yes" : "No");
} 

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int x, n;
    cin >> x >> n;
    if(n == 0){
        cout << x;
        return 0;
    }
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        vec[i] = a;
    }
    sort(vec.begin(), vec.end());
    int index;
    for(int i = 0; i < vec.size(); i++){
        if(vec[i] == x){
            index = i;
            break;
        }
    }
    int low= vec[0] - 1, high = vec[vec.size() - 1] + 1;
    
    for(int i = index + 1; i < vec.size(); i++){
        if( vec[i] -  vec[i - 1] != 1){
            high = vec[i - 1] + 1;
            break;
        }
    }
    for(int i = index - 1; i >= 0; i --){
        if(vec[i+1] - vec[i] != 1){
            low = vec[i+1] - 1;
            break;
        }
    }
    // cout << low << " " << high;
    int ans = x - low <= high - x ? low : high;
    cout << ans;
    
}









Measured memory_bytes: 3644
X = input()
p = X[0]
ls = []
cnt = 1
for c in X[1:]:
  if p!=c:
    ls.append(cnt)
    cnt = 1
    p = c
  else:
    cnt += 1
ls.append(cnt)
s = 0
t = 0
m = 0
if X[0]=='S':
  for i in range(len(ls)):
    if i%2==0:
      s += ls[i]
    else:
      t += ls[i]
    if s<t:
      m += t-s
      t = 0
      s = 0
  print(2*m)
else:
  for i in range(len(ls)):
    if i%2==0:
      t += ls[i]
    else:
      s += ls[i]
    if s<t:
      m += t-s
      t = 0
      s = 0
  print(2*m)

Measured memory_bytes: 4584
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    int score = 0;
    for(int i=0;i<n-1; i++){
        if(s[i] == s[i+1]){
            score++;
        }
    }

    cout << min(score + 2*k, n-1) << endl;
}

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

int main(){
  int N,K;
  string S,A,B,C,a,b,c;
  cin >> N >> K >> S;
  
  if (S.at(K-1) == 'A'){
    S.at(K-1) = 'a';
  }
  else if(S.at(K-1) == 'B'){
    S.at(K-1) = 'b';
  }
  else if(S.at(K-1) == 'C'){
    S.at(K-1) = 'c';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   /* string in;
    cin>>in;
    v32 ans;
    int iter=0;
    unordered_map<string, int> umap;
    forn(i,in.size()){
    	string buffer(1,in[i]);
    	string curr =buffer;
    	while(umap.find(buffer)!=umap.end()){
    		curr=buffer;
    		buffer += in[++i];
    		
    	}
       	umap[buffer]= ++iter;
    	ans.pb(umap[curr]);
    }
    forn(i,ans.size()){
    	cout<<ans[i]<<" ";
    }
    cout<<ln;*/
    //LZW encoder
     string a;
     cin>>a;
     forn(i,a.size()){
     	if(a[i]=='1'){
     		a[i]='9';
     	}else if(a[i]=='9'){
     		a[i]='1';
     	}
     }
     cout<<a;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int count = 0;
		for(int i = 0;i < S.length();i++) {
			if(S.charAt(i) != (T.charAt(i))) {
				count++;
			}
		}
		System.out.println(count);
  }
}

Measured memory_bytes: 41016
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1 << 30;

int n,a,b,c,d;

signed main(){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	for(int m=0;m<=n;m++){
		if(-m*d+(n-1-m)*c<=b-a&&b-a<=-m*c+(n-1-m)*d){
			return puts("YES"),0;
		}
	}
	puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll a, b, c;
  cin >> a >> b >> c;
  if (c > a + b && 4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

long ans;
long M, N, K;
long X, Y;
vector<long> A, B, C;
vector<long> P;
vector<vector<long>> S;

int main(void) {

    cin >> N;

    if (N % 1000) {
        cout << 1000 - N % 1000 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  ll N; cin >> N;
  ll ans = 0;
  if(N%2 == 0) {
    ll sub = 2;
    for(ll i=10; ; i*=5 ) {
      if(N/i == 0) break;
      ans += N/i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, i, b, g;
   char s[100000];

   scanf("%s",s);

   b=0; g=0;
   for(i=0;s[i]=='0'||s[i]=='1';i++){
        if(s[i]=='0') b=b+1;
        else if(s[i]=='1') g=g+1;
   }

   if(b>g) printf("%d\n",g*2);
   else    printf("%d\n",b*2);

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> vs;
    int a, b, c; cin >> a >> b >> c;
    vs.push_back(a);
    vs.push_back(b);
    vs.push_back(c);

    sort(vs.begin(), vs.end());

    cout << vs[0] + vs[1] << endl;

    return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var N, Q int;
	var S string;
	fmt.Scan(&N, &Q, &S);
	a := [100000]int{}
	for i := 1; i < N; i++ {
		if (S[i-1] == 'A' && S[i] == 'C') {
			a[i]++;
		}
	}
	for i := 1; i < N; i++ {
		a[i] += a[i-1];
	}
	for ; Q > 0; Q-- {
		var l, r int;
		fmt.Scan(&l, &r);
		l--;
		r--;
		fmt.Println(a[r] - a[l]);
	}
}

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

int main() {
long long  x;
cin >> x;
long long che =0;
long long i =1;
long long  a =0;
while(1){
    if(che>=x){
        break;
    }
    che+=i;
    i++;
    a++;
}
cout << min(x,a)<<endl;
}





Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;


int N;
const int MAXN=2e5+10;
int A[MAXN];

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++) scanf("%d",A+i);

    long long int res=0ll;
    for(int i=2;i<=N;i++){
        int diff=max(0,A[i-1]-A[i]);
        res+=diff;
        A[i]+=diff;
    }

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


    return 0;
}

Measured memory_bytes: 2512
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    fn gcd(a: i64, b: i64) -> i64 { if b == 0 { a } else { gcd(b, a % b) } }

    let g = A.iter().fold(0, |res, &a| gcd(res, a));
    let ans = if K % g == 0 && K <= *A.iter().max().unwrap() { "POSSIBLE" } else { "IMPOSSIBLE" };

    println!("{}", ans);
}

Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

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

map<string,int> mat;

int main()
{
	string s;
	mat["01234567"] = 0;
	queue<string> q;
	q.push(string("01234567"));
	while(!q.empty()){
		s = q.front();q.pop();
		int x = s.find("0");
		for(int i = 0; i < 4; ++i){
			int nx = x + dx[i];
			if(0 <= nx && nx < 8){
				if(x == 3 && nx == 4 || x == 4 && nx == 3)continue;
				string t = s;
				swap(t[x],t[nx]);
				if(mat.find(t) != mat.end())continue;
				q.push(t);mat[t] = mat[s] + 1;
			}
		}
	}
	
	while(getline(cin,s)){
		s.erase(remove(s.begin(),s.end(),' '),s.end());
		cout << mat[s] << endl;
	}
}

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

int main(){
    string s,t;
    int ans=0;
    cin >> s >> t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3928
N, K = map(int, input().split())
X = list(map(int, input().split()))

lis = []
for i in range(N-K+1):
    left = X[i]
    right = X[i+K-1]
    res = right - left
    abs_l, abs_r = abs(left), abs(right)
    if abs_l > abs_r: 
       res += abs_r
    else:
       res += abs_l
    lis.append(res)
print(min(lis))


Measured memory_bytes: 20064
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	string str;
	int A=0, W=0, T=0, R=0;
	for (int i = 0; i < N; i++) {
		cin >> str;
		switch (str[0]){
			case'A':
				A++;
				break;
			case'W':
				W++;
				break;
			case'T':
				T++;
				break;
			case'R':
				R++;
				break;
		}
	}
	printf("AC x %d\n",A);
	printf("WA x %d\n", W);
	printf("TLE x %d\n", T);
	printf("RE x %d\n", R);
	
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  for (int i = 0; i < N; i++)
    if (S[i] != S[K - 1])
      S[i] = '*';
  cout << S << endl;
}

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

int main() {
    string S, T;
    cin >> S >> T;

    vector<string> res;
    for (int i = 0; i < S.size(); i++) {
        string t = S;
        bool flag = true;
        if (S[i] == '?' || S[i] == T[0]) {
            for (int j = 0; j < T.size(); j++) {
                if (S[i + j] != '?' && S[i + j] != T[j]) {
                    flag = false;
                    break;
                }
                t[i + j] = T[j];
            }

            if (flag) {
                for (int j = 0; j < t.size(); j++) {
                    if (t[j] == '?') {
                        t[j] = 'a';
                    }
                }
                res.push_back(t);
            }
        }
    }

    if (res.empty()) {
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(res.begin(), res.end());
        cout << res[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

int power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

void raushan_kumar(){
	double n;cin>>n;
	double ans=n/3;
	ans=ans*ans*ans;
	printf("%.12f",ans);
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  
  if ((int)s.size() <= k) {
    cout << s << endl;
  }
  else {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    
    cout << "..." << endl;
  }
  
  return 0;
}

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

const int MOD = 1e9+7;
int main(){
	int n,m;
	cin>>n>>m;
    vector<string> maze;
    for(int i=0;i<n;i++){
        string row;
        cin>>row;
        maze.push_back(row);
    }
	int dp[n+1][m+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            dp[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++){
        for(int j=1;j<m+1;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }else if(i==1 && j==1){
                dp[i][j]=1;
            }else if(maze[i-1][j-1]=='#'){
                dp[i][j]=0;
            }else{
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
    }
    cout<<dp[n][m];
	return 0;
}


Measured memory_bytes: 8524
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

using namespace std;

int main() {
  int N,L;
  vector<string> S;
  string s;
  cin >> N >> L;
  for (int i=0; i < N; i++) {
    cin >> s;
    S.push_back(s);
  }
  sort(S.begin(), S.end());
  for (int i=0; i < N; i++) {
    cout << S[i];
  } cout << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
char c;
cin >> c;
if(c == 'a'||c == 'e'||c == 'i'||c == 'u'||c == 'o'){
cout << "vowel" << endl;
}else{
cout << "consonant" << endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 300005
#define ll long long
using namespace std;
ll mod=998244353;
ll fac[N],inv[N],k,f[N];
int n,a,b;
ll calc(int n,int m)
{
    if(m>n||m<0)return 0;
    return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
    fac[0]=inv[0]=inv[1]=1;
    for(int i=1;i<=N;i++)
	fac[i]=1ll*fac[i-1]*i%mod;
    for(int i=2;i<=N;i++)
	inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=N;i++)
	inv[i]=1ll*inv[i-1]*inv[i]%mod;
    cin>>n>>a>>b>>k;
    if(k==0)
	{
	cout<<"1"<<endl;
	return 0;
	}
    ll ans=0;
    for(int i=0;i<=n;i++)
        if((k-a*i)%b==0&&(k-a*i>=0))
        {
            int t=(k-a*i)/b;
            f[i]=(calc(n,i)*calc(n,t))%mod;
            ans=(ans+f[i])%mod;
        }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = 1000;
    for(int i=0;i+m-1<n;i++){
        int tmp = 0;
        for(int j=0;j<m;j++){
            // iから開始してjとの一致する回数を調べる
            if(s[i+j] != t[j])tmp++;
        }
        chmin(ans,tmp);
    }
    cout << ans << endl;
}

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

bool is_prime(int n) {
    if(n < 2) return false;
    else if(n == 2) return true;

    if(n % 2 == 0) return 0;
    for(int i=3; i*i<=n; i+=2) if(n % i == 0) return false;
    return true;
}

void solve(int a,int d,int n) {
    int cnt = 0;
    for(int k=0; ; k++) {
        if(is_prime(a + k*d)) ++cnt;
        if(cnt == n) {
            cout << a + k*d << "\n";
            return ;
        }
    }
    return ;
}

int main() {
    for(int a,d,n; cin>>a>>d>>n && a; ) solve(a,d,n);
    return 0;
}

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

int main(void){
    int x1=0, x2=0, y1=0, y2=0;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2-x1, b = y2-y1;
    cout << x2-b << " " << y2+a << " "  << x1-b << " "  << y1+a << endl;
}

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

int main() {
    int n;
    while(cin >> n, n) {
        map<char, char> m;
        for(int i=0; i<n; ++i) {
            char c1, c2;
            cin >> c1 >> c2;
            m[c1] = c2;
        }
        int n2;
        cin >> n2;
        for(int i=0; i<n2; ++i) {
            char c;
            cin >> c;
            if(m.count(c) != 0) {
                cout << m[c];
            } else {
                cout << c;
            }
        }
        cout << endl;
    }
}


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

int main(){
  int N;
  cin >>N;
  vector<int> a(N);
  for(int i=0;i<N;i++) cin >>a[i];
  
  int ans = 0;
  int cur = 1;
  
  for(int i=0;i<N;i++){
    if(a[i] == cur) cur ++;
    else ans ++;
  }
  
  if(ans == N) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003, M = 2003, mod = 1000000007, inv2 = (mod + 1) >> 1;
int n, a[N], b[N], maxa, maxb, dp[M << 1][M << 1], fac[N], inv[N], ans;
bool vis[M << 1][M << 1];
inline int DP(int x, int y){
	if(x < -maxa || y < -maxb) return 0;
	if(vis[x + M][y + M]) return dp[x + M][y + M];
	vis[x + M][y + M] = true;
	return dp[x + M][y + M] = (dp[x + M][y + M] + DP(x, y - 1) + DP(x - 1, y)) % mod;
}
inline void init(int m){
	fac[0] = 1;
	for(Rint i = 1;i <= m;i ++) fac[i] = (LL) i * fac[i - 1] % mod;
	inv[1] = 1;
	for(Rint i = 2;i <= m;i ++) inv[i] = (LL) (mod - mod / i) * inv[mod % i] % mod;
	inv[0] = 1;
	for(Rint i = 1;i <= m;i ++) inv[i] = (LL) inv[i] * inv[i - 1] % mod;
}
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;i ++){
		scanf("%d%d", a + i, b + i);
		maxa = max(maxa, a[i]);
		maxb = max(maxb, b[i]);
		++ dp[-a[i] + M][-b[i] + M];
	}
	init(maxa + maxb << 1);
	for(Rint i = 1;i <= n;i ++) ans = (ans + DP(a[i], b[i])) % mod;
	for(Rint i = 1;i <= n;i ++)
		ans = (ans - (LL) fac[a[i] + b[i] << 1] * inv[a[i] << 1] % mod * inv[b[i] << 1] % mod + mod) % mod;
	printf("%d", (LL) ans * inv2 % mod);
}

Measured memory_bytes: 82048
#include<stdio.h>
long long gcd(long long a,long long b){
	long long r;
	while(r=a%b,r){
		a=b;
		b=r;
	}
	return b;
}
int main(void){
	int n;
	long long s=0,t,ans=1;
	for(scanf("%d",&n);n;n--){
		scanf("%lld",&t);
		if(s!=0){
			ans=s/(t<s?gcd(s,t):gcd(t,s))*t;
		}
		s=s?ans:t;
	}
	printf("%lld",s==t?s:ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	int n;
	cin >> n;
	int mul[5] = {};
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		if(a%4 == 0) mul[4]++;
		else if(a%2 == 0) mul[2]++;
		else mul[0]++;
	}
	if(mul[4]>=mul[0] || (mul[4]+1==mul[0] && mul[2]==0)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    lint s;
    cin >> s;
    set<lint> se;
    while (!se.count(s)) se.insert(s), s = (s % 2 ? 3 * s + 1 : s / 2);
    cout << se.size() + 1 << endl;
    return 0;
}


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

int main(void) {
    string SA,SB,SC;cin>>SA>>SB>>SC;
    queue<char> qa,qb,qc;
    for (int i = 0; i < SA.size(); i++) qa.push(SA[i]);
    for (int i = 0; i < SB.size(); i++) qb.push(SB[i]);
    for (int i = 0; i < SC.size(); i++) qc.push(SC[i]);
    char cur = 'a';
    while (true) {
        switch (cur) {
            case 'a' :
            if (qa.size() == 0) {
                cout << "A" << endl;
                return 0;
            }
            cur = qa.front();
            qa.pop();
            break;
            case 'b' :
            if (qb.size() == 0) {
                cout << "B" << endl;
                return 0;
            }
            cur = qb.front();
            qb.pop();
            break;
            case 'c' :
            if (qc.size() == 0) {
                cout << "C" << endl;
                return 0;
            }
            cur = qc.front();
            qc.pop();
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
 
const int INF = 10000000;

int main(){
	int W, Q;
	int a, b;
	char c;
	bool f;
	while(cin>>W>>Q){
		if(W == 0 && Q == 0) break;
		vi v(W, -1);
		map<int,int> m;
		for(int i = 0; i < Q; i++){
			cin>>c;
			if(c == 's'){
				cin>>a>>b;
				f = false;
				for(int j = 0; j < W - b + 1; j++){
					for(int k = j; k < j + b; k++){
						if(v[k] != -1) break;
						if(k == j + b - 1){
							for(int l = j; l < j + b; l++){
								v[l] = b;
							}
							m[a] = j;
							cout<<j<<endl;
							f = true;
							break;
						}
					}
					if(f) break;
				}
				if(!f) cout<<"impossible"<<endl;
			}
			else{
				cin>>a;
				b = v[m[a]];
				for(int j = m[a]; j < m[a] + b; j++) v[j] = -1;
			}
		}
		cout<<"END"<<endl;
	}
	
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define fo(i,n) for(int i=1;i<=n;i++)
#define fo1(i,n) for(int i=0;i<n;i++)
#define llu long long int
#define vi vector <int>
#define pb push_back
#define mod 1000000007

using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int dp[n+1];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<=n;i++)
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	cout<<dp[n-1]<<"\n";
}


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

int main( void )
{
    string line;
    long long a, b, n;
    while ( getline( cin, line ) ) {
        istringstream is( line );
        is >> a >> b >> n;
        a %= b;
        
        long long sum = 0;
        for ( long long i = 0; i < n; i++ ) {
            a *= 10;
            sum += a / b;
            a = a % b;
        }
        cout << sum << endl;
    }
    return 0;
}

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

// #define NDEBUG
#include<assert.h>
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, k, d;
  cin >> x >> k >> d;
  ll times = 0;
  ll pos, neg;
  ll res;
  if(x >= 0) {
    pos = x % d;
    neg = pos - d;
    if(pos + neg > 0) {
        times += 1;
        res = neg;
    } else res = pos;
  } else {
    neg = x % d;
    pos = neg + d;
    if(pos + neg < 0) {
        times += 1;
        res = pos;
    } else res = neg;
  }
  times += abs(x) / d;
  if(k < times) {
    res = abs(x) - k * d;
  } else {
    if((k - times) & 1) {
      res = min(res + d, abs(res - d));
    }
  }
  cout << abs(res) << endl;
  return 0;
}

Measured memory_bytes: 3644
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]

N=int(input())
ans=0
for i in range(1,N+1,2):
    if len(make_divisors(i))==8:
        ans+=1
print(ans)

Measured memory_bytes: 9124
#include<stdio.h>
int main()
{
	char o[2];
	int a,b;
	
	scanf("%d%s%d",&a,&o,&b);
	
	if(o[0]=='+')printf("%d\n",a+b);
	else printf("%d\n",a-b);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

int main() {
  ll s,c;
  cin >> s >> c;
  ll total = 0;
  if(s*2 <= c) {
    total = s;
    c = c - 2*s;
    total += c/4;
  }
  else {
    total = c/2;
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

S = input()

ans = 0
tmp = 0
for si in S:
    if si == "A" or si == "T" or si == "C" or si == "G":
        tmp += 1
    else:
        if tmp > ans:
            ans = tmp

        tmp = 0
    if tmp > ans:
        ans = tmp

print(ans)

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

int main(){
    int A,B,i;
    int a,b,c,d;
    int count=0;

    cin >> A >> B;

    for(i=A;i<=B;i++){
        d=i%10;
        c=(i/10)%10;
        b=(i/1000)%10;
        a=(i/10000)%10;

        if(a==d){
            if(b==c){
                count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
    VI d(3);
    REP(i,3)RI(d[i]);
    sort(ALL(d));
    if(d[0]==d[1])printf("%d",d[2]);
    else printf("%d",d[0]);
    return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n, k, q, A[2006], o[2006];
ll fw[2006];
void update(ll x,ll nval) {
	for(;x<=n;x+=x&(-x)) fw[x]+=nval;
}
void update(ll x,ll y,ll nval) {
	update(x, nval);
	update(y+1, -nval);
}
ll sum(ll x) { // point sum
	ll ox=x;
	ll res=0; for(;x;x-=x&(-x)) res+=fw[x]; return ox-res;
}
int main()
{
	FAST
	cin>>n>>k>>q;
	FOR(i,1,n) cin>>A[i];
	FOR(i,1,n) o[i]=i;
	sort(o+1, o+n+1, [](ll x,ll y){return A[x]<A[y];});
	set<int> s;s.ins(0);s.ins(n+1);
	function<ll(ll)> ppl=[&](ll x) {
		return sum(*s.lower_bound(x)) - sum(*prev(s.lower_bound(x))) - 1;
	};
	ll ans=LLINF;
	FOR(i,1,n) {
		mmst(fw, 0);
		if(ppl(o[i]) < k) continue; 
		ll mx = A[o[i]];
		ll have = 1;
		update(o[i]+1, n, 1);
		FOR(j,i+1,n) if(have < q && ppl(o[j]) >= k) {
			++ have, mx=A[o[j]];
			update(o[j]+1, n, 1); 
		}
		s.ins(o[i]);
		if(have >= q) ans=min(ans, mx-A[o[i]]);
	}
	cout<<ans<<'\n';
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, gA, sA, bA, gB, sB, bB;
    cin >> N >> gA >> sA >> bA >> gB >> sB >> bB;

    ll max_nokori = 0;
    for(int i=0;i<=N;i++){
    	for(int j=0;j<=N;j++){
    		ll k = N - i*gA - j*sA;
    		if(k < 0) continue;
    		ll tmp = 0;
    		tmp += i*gB;
    		tmp += j*sB;
    		if(bA < bB){
    			tmp += (k/bA)*bB;
    			tmp += k % bA;
    		}else{
    			tmp += k;
    		}
    		max_nokori = max(tmp, max_nokori);
    	}
    }

    dump(max_nokori)

    ll res = 0;
    if(max_nokori > 5000){
    	vector<ll> from, to;
    	if(gA > gB) from.push_back(gB), to.push_back(gA);
    	if(sA > sB) from.push_back(sB), to.push_back(sA);
    	if(bA > bB) from.push_back(bB), to.push_back(bA);

    	if(from.size() == 0){
    		res = max_nokori;
    	}else if(from.size() == 1){
    		res += (max_nokori)/from[0] * to[0];
    		res += max_nokori - (max_nokori)/from[0]*from[0];
    	}else{
    		for(int i=0;i<=max_nokori;i++){
    			ll k = max_nokori - i*from[0];
    			if(k<0) continue;
    			ll tmp = 0;
    			tmp += i*to[0];
    			tmp += k/from[1] * to[1];
    			tmp += k%from[1];
    			res = max(res, tmp);
    		}
    	}
    }else{
    	for(int i=0;i<=max_nokori;i++){
	    	for(int j=0;j<=max_nokori;j++){
	    		ll k = max_nokori - i*gB - j*sB;
	    		if(k < 0) continue;
	    		ll tmp = 0;
	    		tmp += i*gA;
	    		tmp += j*sA;
	    		if(bA > bB){
	    			tmp += (k/bB)*bA;
	    			tmp += k - (k/bB)*bB;
	    		}else{
	    			tmp += k;
	    		}
	    		res = max(tmp, res);
	    	}
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def solve(A: int, B: int, C: int):
    if [5, 5, 7] == sorted([A, B, C]):
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064